| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include <math.h> |
| 26 |
#include <stdio.h> |
| 27 |
#include <stdlib.h> |
| 28 |
|
| 29 |
#include "level9.h" |
| 30 |
|
| 31 |
extern Bitmap* bitmap; |
| 32 |
|
| 33 |
L9UINT32 filelength(FILE *f); |
| 34 |
void L9Allocate(L9BYTE **ptr,L9UINT32 Size); |
| 35 |
|
| 36 |
L9BYTE* bitmap_load(char* file, L9UINT32* size) |
| 37 |
{ |
| 38 |
L9BYTE* data = NULL; |
| 39 |
FILE* f = fopen(file,"rb"); |
| 40 |
if (f) |
| 41 |
{ |
| 42 |
*size = filelength(f); |
| 43 |
L9Allocate(&data,*size); |
| 44 |
if (fread(data,1,*size,f) != *size) |
| 45 |
{ |
| 46 |
free(data); |
| 47 |
data = NULL; |
| 48 |
} |
| 49 |
fclose(f); |
| 50 |
} |
| 51 |
return data; |
| 52 |
} |
| 53 |
|
| 54 |
Bitmap* bitmap_alloc(int x, int y) |
| 55 |
{ |
| 56 |
Bitmap* bitmap = NULL; |
| 57 |
L9Allocate((L9BYTE**)&bitmap,sizeof(Bitmap)+(x*y)); |
| 58 |
|
| 59 |
bitmap->width = x; |
| 60 |
bitmap->height = y; |
| 61 |
bitmap->bitmap = ((L9BYTE*)bitmap)+sizeof(Bitmap); |
| 62 |
bitmap->npalette = 0; |
| 63 |
return bitmap; |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
Colour bitmap_pcst_colour(int big, int small) |
| 75 |
{ |
| 76 |
Colour col; |
| 77 |
L9UINT32 r = big & 0xF; |
| 78 |
L9UINT32 g = (small >> 4) & 0xF; |
| 79 |
L9UINT32 b = small & 0xF; |
| 80 |
|
| 81 |
r *= 0x49; r >>= 1; |
| 82 |
g *= 0x49; g >>= 1; |
| 83 |
b *= 0x49; b >>= 1; |
| 84 |
|
| 85 |
col.red = (L9BYTE)(r&0xFF); |
| 86 |
col.green = (L9BYTE)(g&0xFF); |
| 87 |
col.blue = (L9BYTE)(b&0xFF); |
| 88 |
return col; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
L9UINT32 bitmap_st1_decode_pixels(L9BYTE* bitmap, L9BYTE* data, L9UINT32 count, L9UINT32 pixels) |
| 114 |
{ |
| 115 |
L9UINT32 bitplane_length = count / 4; |
| 116 |
L9BYTE *bitplane0 = data; |
| 117 |
L9BYTE *bitplane1 = data + (bitplane_length); |
| 118 |
L9BYTE *bitplane2 = data + (bitplane_length * 2); |
| 119 |
L9BYTE *bitplane3 = data + (bitplane_length * 3); |
| 120 |
L9UINT32 bitplane_index, pixel_index = 0; |
| 121 |
|
| 122 |
for (bitplane_index = 0; bitplane_index < bitplane_length; bitplane_index++) |
| 123 |
{ |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
bitmap[pixel_index] = ((bitplane3[bitplane_index] >> 4) & 0x08) |
| 128 |
+ ((bitplane2[bitplane_index] >> 5) & 0x04) |
| 129 |
+ ((bitplane1[bitplane_index] >> 6) & 0x02) |
| 130 |
+ ((bitplane0[bitplane_index] >> 7) & 0x01); |
| 131 |
if (pixels == ++pixel_index) |
| 132 |
break; |
| 133 |
|
| 134 |
|
| 135 |
bitmap[pixel_index] = ((bitplane3[bitplane_index] >> 3) & 0x08) |
| 136 |
+ ((bitplane2[bitplane_index] >> 4) & 0x04) |
| 137 |
+ ((bitplane1[bitplane_index] >> 5) & 0x02) |
| 138 |
+ ((bitplane0[bitplane_index] >> 6) & 0x01); |
| 139 |
if (pixels == ++pixel_index) |
| 140 |
break; |
| 141 |
|
| 142 |
|
| 143 |
bitmap[pixel_index] = ((bitplane3[bitplane_index] >> 2) & 0x08) |
| 144 |
+ ((bitplane2[bitplane_index] >> 3) & 0x04) |
| 145 |
+ ((bitplane1[bitplane_index] >> 4) & 0x02) |
| 146 |
+ ((bitplane0[bitplane_index] >> 5) & 0x01); |
| 147 |
if (pixels == ++pixel_index) |
| 148 |
break; |
| 149 |
|
| 150 |
|
| 151 |
bitmap[pixel_index] = ((bitplane3[bitplane_index] >> 1) & 0x08) |
| 152 |
+ ((bitplane2[bitplane_index] >> 2) & 0x04) |
| 153 |
+ ((bitplane1[bitplane_index] >> 3) & 0x02) |
| 154 |
+ ((bitplane0[bitplane_index] >> 4) & 0x01); |
| 155 |
if (pixels == ++pixel_index) |
| 156 |
break; |
| 157 |
|
| 158 |
|
| 159 |
bitmap[pixel_index] = ((bitplane3[bitplane_index]) & 0x08) |
| 160 |
+ ((bitplane2[bitplane_index] >> 1) & 0x04) |
| 161 |
+ ((bitplane1[bitplane_index] >> 2) & 0x02) |
| 162 |
+ ((bitplane0[bitplane_index] >> 3) & 0x01); |
| 163 |
if (pixels == ++pixel_index) |
| 164 |
break; |
| 165 |
|
| 166 |
|
| 167 |
bitmap[pixel_index] = ((bitplane3[bitplane_index] << 1) & 0x08) |
| 168 |
+ ((bitplane2[bitplane_index]) & 0x04) |
| 169 |
+ ((bitplane1[bitplane_index] >> 1) & 0x02) |
| 170 |
+ ((bitplane0[bitplane_index] >> 2) & 0x01); |
| 171 |
if (pixels == ++pixel_index) |
| 172 |
break; |
| 173 |
|
| 174 |
|
| 175 |
bitmap[pixel_index] = ((bitplane3[bitplane_index] << 2) & 0x08) |
| 176 |
+ ((bitplane2[bitplane_index] << 1) & 0x04) |
| 177 |
+ ((bitplane1[bitplane_index]) & 0x02) |
| 178 |
+ ((bitplane0[bitplane_index] >> 1) & 0x01); |
| 179 |
if (pixels == ++pixel_index) |
| 180 |
break; |
| 181 |
|
| 182 |
|
| 183 |
bitmap[pixel_index] = ((bitplane3[bitplane_index] << 3) & 0x08) |
| 184 |
+ ((bitplane2[bitplane_index] << 2) & 0x04) |
| 185 |
+ ((bitplane1[bitplane_index] << 1) & 0x02) |
| 186 |
+ ((bitplane0[bitplane_index]) & 0x01); |
| 187 |
if (pixels == ++pixel_index) |
| 188 |
break; |
| 189 |
} |
| 190 |
|
| 191 |
return pixel_index; |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
L9BOOL bitmap_st1_decode(char* file, int x, int y) |
| 264 |
{ |
| 265 |
L9BYTE* data = NULL; |
| 266 |
int i, xi, yi, max_x, max_y, last_block; |
| 267 |
int bitplanes_row, bitmaps_row, pixel_count, get_pixels; |
| 268 |
|
| 269 |
L9UINT32 size; |
| 270 |
data = bitmap_load(file,&size); |
| 271 |
if (data == NULL) |
| 272 |
return FALSE; |
| 273 |
|
| 274 |
bitplanes_row = data[35]+data[34]*256; |
| 275 |
bitmaps_row = bitplanes_row/4; |
| 276 |
max_x = bitplanes_row*4; |
| 277 |
max_y = data[39]+data[38]*256; |
| 278 |
last_block = data[43]+data[42]*256; |
| 279 |
|
| 280 |
|
| 281 |
if (last_block != 0xFFFF) |
| 282 |
{ |
| 283 |
|
| 284 |
int i = 0; |
| 285 |
while ((0x0001 & last_block) == 0) |
| 286 |
{ |
| 287 |
last_block >>= 1; |
| 288 |
i++; |
| 289 |
} |
| 290 |
max_x = max_x - i; |
| 291 |
} |
| 292 |
|
| 293 |
if (max_x > MAX_BITMAP_WIDTH || max_y > MAX_BITMAP_HEIGHT) |
| 294 |
{ |
| 295 |
free(data); |
| 296 |
return FALSE; |
| 297 |
} |
| 298 |
|
| 299 |
if ((x == 0) && (y == 0)) |
| 300 |
{ |
| 301 |
if (bitmap) |
| 302 |
free(bitmap); |
| 303 |
bitmap = bitmap_alloc(max_x,max_y); |
| 304 |
} |
| 305 |
if (bitmap == NULL) |
| 306 |
{ |
| 307 |
free(data); |
| 308 |
return FALSE; |
| 309 |
} |
| 310 |
|
| 311 |
if (x+max_x > bitmap->width) |
| 312 |
max_x = bitmap->width-x; |
| 313 |
if (y+max_y > bitmap->height) |
| 314 |
max_y = bitmap->height-y; |
| 315 |
|
| 316 |
for (yi = 0; yi < max_y; yi++) |
| 317 |
{ |
| 318 |
pixel_count = 0; |
| 319 |
for (xi = 0; xi < bitmaps_row; xi++) |
| 320 |
{ |
| 321 |
if ((max_x - pixel_count) < 16) |
| 322 |
get_pixels = max_x - pixel_count; |
| 323 |
else |
| 324 |
get_pixels = 16; |
| 325 |
|
| 326 |
pixel_count += bitmap_st1_decode_pixels( |
| 327 |
bitmap->bitmap+((y+yi)*bitmap->width)+x+(xi*16), |
| 328 |
data+44+(yi*bitplanes_row*2)+(xi*8),8,get_pixels); |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
bitmap->npalette = 16; |
| 333 |
for (i = 0; i < 16; i++) |
| 334 |
bitmap->palette[i] = bitmap_pcst_colour(data[(i*2)],data[1+(i*2)]); |
| 335 |
|
| 336 |
free(data); |
| 337 |
return TRUE; |
| 338 |
} |
| 339 |
|
| 340 |
void bitmap_st2_name(int num, char* dir, char* out) |
| 341 |
{ |
| 342 |
|
| 343 |
if (num == 0) |
| 344 |
num = 30; |
| 345 |
sprintf(out,"%s%d.squ",dir,num); |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
void bitmap_pc_name(int num, char* dir, char* out) |
| 360 |
{ |
| 361 |
|
| 362 |
if (num == 0) |
| 363 |
num = 30; |
| 364 |
sprintf(out,"%s%d.pic",dir,num); |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
Colour bitmap_pc1_colour(int i) |
| 382 |
{ |
| 383 |
Colour col; |
| 384 |
col.red = (((i&4)>>1) | ((i&0x20)>>5)) * 0x55; |
| 385 |
col.green = ((i&2) | ((i&0x10)>>4)) * 0x55; |
| 386 |
col.blue = (((i&1)<<1) | ((i&8)>>3)) * 0x55; |
| 387 |
return col; |
| 388 |
} |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
L9BOOL bitmap_pc1_decode(char* file, int x, int y) |
| 407 |
{ |
| 408 |
L9BYTE* data = NULL; |
| 409 |
int i, xi, yi, max_x, max_y; |
| 410 |
|
| 411 |
L9UINT32 size; |
| 412 |
data = bitmap_load(file,&size); |
| 413 |
if (data == NULL) |
| 414 |
return FALSE; |
| 415 |
|
| 416 |
max_x = data[2]+data[3]*256; |
| 417 |
max_y = data[4]+data[5]*256; |
| 418 |
if (max_x > MAX_BITMAP_WIDTH || max_y > MAX_BITMAP_HEIGHT) |
| 419 |
{ |
| 420 |
free(data); |
| 421 |
return FALSE; |
| 422 |
} |
| 423 |
|
| 424 |
if ((x == 0) && (y == 0)) |
| 425 |
{ |
| 426 |
if (bitmap) |
| 427 |
free(bitmap); |
| 428 |
bitmap = bitmap_alloc(max_x,max_y); |
| 429 |
} |
| 430 |
if (bitmap == NULL) |
| 431 |
{ |
| 432 |
free(data); |
| 433 |
return FALSE; |
| 434 |
} |
| 435 |
|
| 436 |
if (x+max_x > bitmap->width) |
| 437 |
max_x = bitmap->width-x; |
| 438 |
if (y+max_y > bitmap->height) |
| 439 |
max_y = bitmap->height-y; |
| 440 |
|
| 441 |
for (yi = 0; yi < max_y; yi++) |
| 442 |
{ |
| 443 |
for (xi = 0; xi < max_x; xi++) |
| 444 |
{ |
| 445 |
bitmap->bitmap[(bitmap->width*(y+yi))+(x+xi)] = |
| 446 |
(data[23+((yi*max_x)/2)+(xi/2)]>>((1-(xi&1))*4)) & 0x0f; |
| 447 |
} |
| 448 |
} |
| 449 |
|
| 450 |
bitmap->npalette = 16; |
| 451 |
for (i = 0; i < 16; i++) |
| 452 |
bitmap->palette[i] = bitmap_pc1_colour(data[6+i]); |
| 453 |
|
| 454 |
free(data); |
| 455 |
return TRUE; |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
L9BOOL bitmap_pc2_decode(char* file, int x, int y) |
| 608 |
{ |
| 609 |
L9BYTE* data = NULL; |
| 610 |
int i, xi, yi, max_x, max_y; |
| 611 |
|
| 612 |
L9BYTE theNewPixel, theNewPixelIndex; |
| 613 |
L9BYTE theBufferBitCounter, theNewPixelIndexSelector, theBufferBitStripCount; |
| 614 |
L9UINT16 theBitStreamBuffer, theImageDataIndex; |
| 615 |
L9BYTE* theImageFileData; |
| 616 |
|
| 617 |
L9UINT32 size; |
| 618 |
data = bitmap_load(file,&size); |
| 619 |
if (data == NULL) |
| 620 |
return FALSE; |
| 621 |
|
| 622 |
max_x = data[37]+data[36]*256; |
| 623 |
max_y = data[39]+data[38]*256; |
| 624 |
if (max_x > MAX_BITMAP_WIDTH || max_y > MAX_BITMAP_HEIGHT) |
| 625 |
{ |
| 626 |
free(data); |
| 627 |
return FALSE; |
| 628 |
} |
| 629 |
|
| 630 |
if ((x == 0) && (y == 0)) |
| 631 |
{ |
| 632 |
if (bitmap) |
| 633 |
free(bitmap); |
| 634 |
bitmap = bitmap_alloc(max_x,max_y); |
| 635 |
} |
| 636 |
if (bitmap == NULL) |
| 637 |
{ |
| 638 |
free(data); |
| 639 |
return FALSE; |
| 640 |
} |
| 641 |
|
| 642 |
if (x+max_x > bitmap->width) |
| 643 |
max_x = bitmap->width-x; |
| 644 |
if (y+max_y > bitmap->height) |
| 645 |
max_y = bitmap->height-y; |
| 646 |
|
| 647 |
|
| 648 |
theNewPixel = data[40]; |
| 649 |
|
| 650 |
theImageDataIndex = 0; |
| 651 |
|
| 652 |
theImageFileData = data+570; |
| 653 |
theBitStreamBuffer = theImageFileData[theImageDataIndex++]; |
| 654 |
theBitStreamBuffer = theBitStreamBuffer + |
| 655 |
(0x100 * theImageFileData[theImageDataIndex++]); |
| 656 |
|
| 657 |
theBufferBitCounter = 8; |
| 658 |
|
| 659 |
for (yi = 0; yi < max_y; yi++) |
| 660 |
{ |
| 661 |
for (xi = 0; xi < max_x; xi++) |
| 662 |
{ |
| 663 |
theNewPixelIndexSelector = (theBitStreamBuffer & 0x00FF); |
| 664 |
if (theNewPixelIndexSelector != 0xFF) |
| 665 |
{ |
| 666 |
|
| 667 |
theNewPixelIndex = (data+314)[theNewPixelIndexSelector]; |
| 668 |
|
| 669 |
theBufferBitStripCount = (data+298)[theNewPixelIndex]; |
| 670 |
|
| 671 |
while (theBufferBitStripCount > 0) |
| 672 |
{ |
| 673 |
theBitStreamBuffer = theBitStreamBuffer >> 1; |
| 674 |
theBufferBitStripCount--; |
| 675 |
theBufferBitCounter--; |
| 676 |
if (theBufferBitCounter == 0) |
| 677 |
{ |
| 678 |
|
| 679 |
theBitStreamBuffer = theBitStreamBuffer + |
| 680 |
(0x100 * theImageFileData[theImageDataIndex++]); |
| 681 |
|
| 682 |
theBufferBitCounter = 8; |
| 683 |
} |
| 684 |
} |
| 685 |
} |
| 686 |
else |
| 687 |
{ |
| 688 |
|
| 689 |
theBufferBitStripCount = 8; |
| 690 |
while (theBufferBitStripCount > 0) |
| 691 |
{ |
| 692 |
theBitStreamBuffer = theBitStreamBuffer >> 1; |
| 693 |
theBufferBitStripCount--; |
| 694 |
theBufferBitCounter--; |
| 695 |
if (theBufferBitCounter == 0) |
| 696 |
{ |
| 697 |
|
| 698 |
theBitStreamBuffer = theBitStreamBuffer + |
| 699 |
(0x100 * theImageFileData[theImageDataIndex++]); |
| 700 |
|
| 701 |
theBufferBitCounter = 8; |
| 702 |
} |
| 703 |
} |
| 704 |
|
| 705 |
theNewPixelIndex = (0x000F & theBitStreamBuffer); |
| 706 |
theBufferBitStripCount = 4; |
| 707 |
|
| 708 |
while (theBufferBitStripCount > 0) |
| 709 |
{ |
| 710 |
theBitStreamBuffer = theBitStreamBuffer >> 1; |
| 711 |
theBufferBitStripCount--; |
| 712 |
theBufferBitCounter--; |
| 713 |
if (theBufferBitCounter == 0) |
| 714 |
{ |
| 715 |
|
| 716 |
theBitStreamBuffer = theBitStreamBuffer + |
| 717 |
(0x100 * theImageFileData[theImageDataIndex++]); |
| 718 |
|
| 719 |
theBufferBitCounter = 8; |
| 720 |
} |
| 721 |
} |
| 722 |
} |
| 723 |
|
| 724 |
|
| 725 |
theNewPixel = (0xF0 & (theNewPixel << 4)); |
| 726 |
|
| 727 |
theNewPixel = theNewPixel + theNewPixelIndex; |
| 728 |
|
| 729 |
theNewPixel = (data+42)[theNewPixel]; |
| 730 |
|
| 731 |
bitmap->bitmap[(bitmap->width*(y+yi))+(x+xi)] = theNewPixel; |
| 732 |
} |
| 733 |
} |
| 734 |
|
| 735 |
bitmap->npalette = 16; |
| 736 |
for (i = 0; i < 16; i++) |
| 737 |
bitmap->palette[i] = bitmap_pcst_colour(data[4+(i*2)],data[5+(i*2)]); |
| 738 |
|
| 739 |
free(data); |
| 740 |
return TRUE; |
| 741 |
} |
| 742 |
|
| 743 |
BitmapType bitmap_pc_type(char* file) |
| 744 |
{ |
| 745 |
BitmapType type = PC2_BITMAPS; |
| 746 |
|
| 747 |
FILE* f = fopen(file,"rb"); |
| 748 |
if (f != NULL) |
| 749 |
{ |
| 750 |
L9BYTE data[6]; |
| 751 |
int x, y; |
| 752 |
|
| 753 |
if(fread(data,1,sizeof data,f) != sizeof data && !feof(f)) return NO_BITMAPS; |
| 754 |
fclose(f); |
| 755 |
|
| 756 |
x = data[2]+data[3]*256; |
| 757 |
y = data[4]+data[5]*256; |
| 758 |
|
| 759 |
if ((x == 0x0140) && (y == 0x0087)) |
| 760 |
type = PC1_BITMAPS; |
| 761 |
if ((x == 0x00E0) && (y == 0x0074)) |
| 762 |
type = PC1_BITMAPS; |
| 763 |
if ((x == 0x0140) && (y == 0x0087)) |
| 764 |
type = PC1_BITMAPS; |
| 765 |
if ((x == 0x00E1) && (y == 0x0076)) |
| 766 |
type = PC1_BITMAPS; |
| 767 |
} |
| 768 |
|
| 769 |
return type; |
| 770 |
} |
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
void bitmap_noext_name(int num, char* dir, char* out) |
| 777 |
{ |
| 778 |
if (num == 0) |
| 779 |
{ |
| 780 |
FILE* f; |
| 781 |
|
| 782 |
sprintf(out,"%stitle",dir); |
| 783 |
f = fopen(out,"rb"); |
| 784 |
if (f != NULL) |
| 785 |
{ |
| 786 |
fclose(f); |
| 787 |
return; |
| 788 |
} |
| 789 |
else |
| 790 |
num = 30; |
| 791 |
} |
| 792 |
|
| 793 |
sprintf(out,"%s%d",dir,num); |
| 794 |
} |
| 795 |
|
| 796 |
int bitmap_amiga_intensity(int col) |
| 797 |
{ |
| 798 |
return (int)(pow((double)col/15,1.0/0.8) * 0xff); |
| 799 |
} |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
Colour bitmap_amiga_colour(int i1, int i2) |
| 807 |
{ |
| 808 |
Colour col; |
| 809 |
col.red = bitmap_amiga_intensity(i1&0xf); |
| 810 |
col.green = bitmap_amiga_intensity(i2>>4); |
| 811 |
col.blue = bitmap_amiga_intensity(i2&0xf); |
| 812 |
return col; |
| 813 |
} |
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
L9BOOL bitmap_amiga_decode(char* file, int x, int y) |
| 842 |
{ |
| 843 |
L9BYTE* data = NULL; |
| 844 |
int i, xi, yi, max_x, max_y, p, b; |
| 845 |
|
| 846 |
L9UINT32 size; |
| 847 |
data = bitmap_load(file,&size); |
| 848 |
if (data == NULL) |
| 849 |
return FALSE; |
| 850 |
|
| 851 |
max_x = (((((data[64]<<8)|data[65])<<8)|data[66])<<8)|data[67]; |
| 852 |
max_y = (((((data[68]<<8)|data[69])<<8)|data[70])<<8)|data[71]; |
| 853 |
if (max_x > MAX_BITMAP_WIDTH || max_y > MAX_BITMAP_HEIGHT) |
| 854 |
{ |
| 855 |
free(data); |
| 856 |
return FALSE; |
| 857 |
} |
| 858 |
|
| 859 |
if ((x == 0) && (y == 0)) |
| 860 |
{ |
| 861 |
if (bitmap) |
| 862 |
free(bitmap); |
| 863 |
bitmap = bitmap_alloc(max_x,max_y); |
| 864 |
} |
| 865 |
if (bitmap == NULL) |
| 866 |
{ |
| 867 |
free(data); |
| 868 |
return FALSE; |
| 869 |
} |
| 870 |
|
| 871 |
if (x+max_x > bitmap->width) |
| 872 |
max_x = bitmap->width-x; |
| 873 |
if (y+max_y > bitmap->height) |
| 874 |
max_y = bitmap->height-y; |
| 875 |
|
| 876 |
for (yi = 0; yi < max_y; yi++) |
| 877 |
{ |
| 878 |
for (xi = 0; xi < max_x; xi++) |
| 879 |
{ |
| 880 |
p = 0; |
| 881 |
for (b = 0; b < 5; b++) |
| 882 |
p |= ((data[72+(max_x/8)*(max_y*b+yi)+xi/8]>>(7-(xi%8)))&1)<<b; |
| 883 |
bitmap->bitmap[(bitmap->width*(y+yi))+(x+xi)] = p; |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
bitmap->npalette = 32; |
| 888 |
for (i = 0; i < 32; i++) |
| 889 |
bitmap->palette[i] = bitmap_amiga_colour(data[i*2],data[i*2+1]); |
| 890 |
|
| 891 |
free(data); |
| 892 |
return TRUE; |
| 893 |
} |
| 894 |
|
| 895 |
BitmapType bitmap_noext_type(char* file) |
| 896 |
{ |
| 897 |
FILE* f = fopen(file,"rb"); |
| 898 |
if (f != NULL) |
| 899 |
{ |
| 900 |
L9BYTE data[72]; |
| 901 |
int x, y; |
| 902 |
|
| 903 |
if(fread(data,1,sizeof data,f) != sizeof data && !feof(f)) return NO_BITMAPS; |
| 904 |
fclose(f); |
| 905 |
|
| 906 |
x = data[67]+data[66]*256; |
| 907 |
y = data[71]+data[70]*256; |
| 908 |
|
| 909 |
if ((x == 0x0140) && (y == 0x0088)) |
| 910 |
return AMIGA_BITMAPS; |
| 911 |
if ((x == 0x0140) && (y == 0x0087)) |
| 912 |
return AMIGA_BITMAPS; |
| 913 |
if ((x == 0x00E0) && (y == 0x0075)) |
| 914 |
return AMIGA_BITMAPS; |
| 915 |
if ((x == 0x00E4) && (y == 0x0075)) |
| 916 |
return AMIGA_BITMAPS; |
| 917 |
if ((x == 0x00E0) && (y == 0x0076)) |
| 918 |
return AMIGA_BITMAPS; |
| 919 |
if ((x == 0x00DB) && (y == 0x0076)) |
| 920 |
return AMIGA_BITMAPS; |
| 921 |
|
| 922 |
x = data[3]+data[2]*256; |
| 923 |
y = data[7]+data[6]*256; |
| 924 |
|
| 925 |
if ((x == 0x0200) && (y == 0x00D8)) |
| 926 |
return MAC_BITMAPS; |
| 927 |
if ((x == 0x0168) && (y == 0x00BA)) |
| 928 |
return MAC_BITMAPS; |
| 929 |
if ((x == 0x0168) && (y == 0x00BC)) |
| 930 |
return MAC_BITMAPS; |
| 931 |
if ((x == 0x0200) && (y == 0x00DA)) |
| 932 |
return MAC_BITMAPS; |
| 933 |
if ((x == 0x0168) && (y == 0x00DA)) |
| 934 |
return MAC_BITMAPS; |
| 935 |
|
| 936 |
x = data[35]+data[34]*256; |
| 937 |
y = data[39]+data[38]*256; |
| 938 |
|
| 939 |
if ((x == 0x0050) && (y == 0x0087)) |
| 940 |
return ST1_BITMAPS; |
| 941 |
if ((x == 0x0038) && (y == 0x0074)) |
| 942 |
return ST1_BITMAPS; |
| 943 |
} |
| 944 |
|
| 945 |
return NO_BITMAPS; |
| 946 |
} |
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
L9BOOL bitmap_mac_decode(char* file, int x, int y) |
| 971 |
{ |
| 972 |
L9BYTE* data = NULL; |
| 973 |
int xi, yi, max_x, max_y; |
| 974 |
|
| 975 |
L9UINT32 size; |
| 976 |
data = bitmap_load(file,&size); |
| 977 |
if (data == NULL) |
| 978 |
return FALSE; |
| 979 |
|
| 980 |
max_x = data[3]+data[2]*256; |
| 981 |
max_y = data[7]+data[6]*256; |
| 982 |
if (max_x > MAX_BITMAP_WIDTH || max_y > MAX_BITMAP_HEIGHT) |
| 983 |
{ |
| 984 |
free(data); |
| 985 |
return FALSE; |
| 986 |
} |
| 987 |
|
| 988 |
if (x > 0) |
| 989 |
x = 78; |
| 990 |
|
| 991 |
if ((x == 0) && (y == 0)) |
| 992 |
{ |
| 993 |
if (bitmap) |
| 994 |
free(bitmap); |
| 995 |
bitmap = bitmap_alloc(max_x,max_y); |
| 996 |
} |
| 997 |
if (bitmap == NULL) |
| 998 |
{ |
| 999 |
free(data); |
| 1000 |
return FALSE; |
| 1001 |
} |
| 1002 |
|
| 1003 |
if (x+max_x > bitmap->width) |
| 1004 |
max_x = bitmap->width-x; |
| 1005 |
if (y+max_y > bitmap->height) |
| 1006 |
max_y = bitmap->height-y; |
| 1007 |
|
| 1008 |
for (yi = 0; yi < max_y; yi++) |
| 1009 |
{ |
| 1010 |
for (xi = 0; xi < max_x; xi++) |
| 1011 |
{ |
| 1012 |
bitmap->bitmap[(bitmap->width*(y+yi))+(x+xi)] = |
| 1013 |
(data[10+(max_x/8)*yi+xi/8]>>(7-(xi%8)))&1; |
| 1014 |
} |
| 1015 |
} |
| 1016 |
|
| 1017 |
bitmap->npalette = 2; |
| 1018 |
bitmap->palette[0].red = 0; |
| 1019 |
bitmap->palette[0].green = 0; |
| 1020 |
bitmap->palette[0].blue = 0; |
| 1021 |
bitmap->palette[1].red = 0xff; |
| 1022 |
bitmap->palette[1].green = 0xff; |
| 1023 |
bitmap->palette[1].blue = 0xff; |
| 1024 |
|
| 1025 |
free(data); |
| 1026 |
return TRUE; |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
const Colour bitmap_c64_colours[] = { |
| 1035 |
{0x00, 0x00, 0x00 }, |
| 1036 |
{0xff, 0xff, 0xff }, |
| 1037 |
{0x89, 0x40, 0x36 }, |
| 1038 |
{0x7a, 0xbf, 0xc7 }, |
| 1039 |
{0x8a, 0x46, 0xae }, |
| 1040 |
{0x68, 0xa9, 0x41 }, |
| 1041 |
{0x3e, 0x31, 0xa2 }, |
| 1042 |
{0xd0, 0xdc, 0x71 }, |
| 1043 |
{0x90, 0x5f, 0x25 }, |
| 1044 |
{0x5c, 0x47, 0x00 }, |
| 1045 |
{0xbb, 0x77, 0x6d }, |
| 1046 |
{0x55, 0x55, 0x55 }, |
| 1047 |
{0x80, 0x80, 0x80 }, |
| 1048 |
{0xac, 0xea, 0x88 }, |
| 1049 |
{0x7c, 0x70, 0xda }, |
| 1050 |
{0xab, 0xab, 0xab }}; |
| 1051 |
|
| 1052 |
const Colour bitmap_bbc_colours[] = { |
| 1053 |
{0x00, 0x00, 0x00 }, |
| 1054 |
{0xff, 0x00, 0x00 }, |
| 1055 |
{0x00, 0xff, 0x00 }, |
| 1056 |
{0xff, 0xff, 0x00 }, |
| 1057 |
{0x00, 0x00, 0xff }, |
| 1058 |
{0xff, 0x00, 0xff }, |
| 1059 |
{0x00, 0xff, 0xff }, |
| 1060 |
{0xff, 0xff, 0xff }}; |
| 1061 |
|
| 1062 |
void bitmap_c64_name(int num, char* dir, char* out) |
| 1063 |
{ |
| 1064 |
if (num == 0) |
| 1065 |
sprintf(out,"%stitle mpic",dir); |
| 1066 |
else |
| 1067 |
sprintf(out,"%spic%d",dir,num); |
| 1068 |
} |
| 1069 |
|
| 1070 |
void bitmap_bbc_name(int num, char* dir, char* out) |
| 1071 |
{ |
| 1072 |
FILE* f; |
| 1073 |
|
| 1074 |
if (num == 0) |
| 1075 |
{ |
| 1076 |
sprintf(out,"%sP.Title",dir); |
| 1077 |
f = fopen(out,"rb"); |
| 1078 |
if (f != NULL) |
| 1079 |
{ |
| 1080 |
fclose(f); |
| 1081 |
return; |
| 1082 |
} |
| 1083 |
|
| 1084 |
sprintf(out,"%stitle",dir); |
| 1085 |
} |
| 1086 |
else |
| 1087 |
{ |
| 1088 |
sprintf(out,"%sP.Pic%d",dir,num); |
| 1089 |
f = fopen(out,"rb"); |
| 1090 |
if (f != NULL) |
| 1091 |
{ |
| 1092 |
fclose(f); |
| 1093 |
return; |
| 1094 |
} |
| 1095 |
|
| 1096 |
sprintf(out,"%spic%d",dir,num); |
| 1097 |
} |
| 1098 |
} |
| 1099 |
|
| 1100 |
void bitmap_cpc_name(int num, char* dir, char* out) |
| 1101 |
{ |
| 1102 |
if (num == 0) |
| 1103 |
sprintf(out,"%stitle.pic",dir); |
| 1104 |
else if (num == 1) |
| 1105 |
sprintf(out,"%s1.pic",dir); |
| 1106 |
else |
| 1107 |
sprintf(out,"%sallpics.pic",dir); |
| 1108 |
} |
| 1109 |
|
| 1110 |
BitmapType bitmap_c64_type(char* file) |
| 1111 |
{ |
| 1112 |
BitmapType type = C64_BITMAPS; |
| 1113 |
|
| 1114 |
FILE* f = fopen(file,"rb"); |
| 1115 |
if (f != NULL) |
| 1116 |
{ |
| 1117 |
L9UINT32 size = filelength(f); |
| 1118 |
fclose(f); |
| 1119 |
|
| 1120 |
if (size == 10048) |
| 1121 |
type = BBC_BITMAPS; |
| 1122 |
if (size == 6494) |
| 1123 |
type = BBC_BITMAPS; |
| 1124 |
} |
| 1125 |
|
| 1126 |
return type; |
| 1127 |
} |
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
L9BOOL bitmap_c64_decode(char* file, BitmapType type, int num) |
| 1168 |
{ |
| 1169 |
L9BYTE* data = NULL; |
| 1170 |
int i, xi, yi, max_x, max_y, cx, cy, px, py, p; |
| 1171 |
int off, off_scr, off_col, off_bg, col_comp; |
| 1172 |
|
| 1173 |
L9UINT32 size; |
| 1174 |
data = bitmap_load(file,&size); |
| 1175 |
if (data == NULL) |
| 1176 |
return FALSE; |
| 1177 |
|
| 1178 |
if (type == C64_BITMAPS) |
| 1179 |
{ |
| 1180 |
if (size == 10018) |
| 1181 |
{ |
| 1182 |
max_x = 320; |
| 1183 |
max_y = 200; |
| 1184 |
off = 2; |
| 1185 |
off_scr = 8002; |
| 1186 |
off_bg = 9003; |
| 1187 |
off_col = 9018; |
| 1188 |
col_comp = 0; |
| 1189 |
} |
| 1190 |
else if (size == 6464) |
| 1191 |
{ |
| 1192 |
max_x = 320; |
| 1193 |
max_y = 136; |
| 1194 |
off = 2; |
| 1195 |
off_scr = 5442; |
| 1196 |
off_col = 6122; |
| 1197 |
off_bg = 6463; |
| 1198 |
col_comp = 1; |
| 1199 |
} |
| 1200 |
else |
| 1201 |
return FALSE; |
| 1202 |
} |
| 1203 |
else if (type == BBC_BITMAPS) |
| 1204 |
{ |
| 1205 |
if (size == 10058) |
| 1206 |
{ |
| 1207 |
max_x = 320; |
| 1208 |
max_y = 200; |
| 1209 |
off = 10; |
| 1210 |
off_scr = 8010; |
| 1211 |
off_bg = 9011; |
| 1212 |
off_col = 9026; |
| 1213 |
col_comp = 0; |
| 1214 |
} |
| 1215 |
else if (size == 10048) |
| 1216 |
{ |
| 1217 |
max_x = 320; |
| 1218 |
max_y = 200; |
| 1219 |
off = 0; |
| 1220 |
off_scr = 8000; |
| 1221 |
off_bg = 9001; |
| 1222 |
off_col = 9016; |
| 1223 |
col_comp = 0; |
| 1224 |
} |
| 1225 |
else if (size == 6504) |
| 1226 |
{ |
| 1227 |
max_x = 320; |
| 1228 |
max_y = 136; |
| 1229 |
off = 10; |
| 1230 |
off_scr = 5450; |
| 1231 |
off_col = 6130; |
| 1232 |
off_bg = 6471; |
| 1233 |
col_comp = 1; |
| 1234 |
} |
| 1235 |
else if (size == 6494) |
| 1236 |
{ |
| 1237 |
max_x = 320; |
| 1238 |
max_y = 136; |
| 1239 |
off = 0; |
| 1240 |
off_scr = 5440; |
| 1241 |
off_col = 6120; |
| 1242 |
off_bg = 6461; |
| 1243 |
col_comp = 1; |
| 1244 |
} |
| 1245 |
else |
| 1246 |
return FALSE; |
| 1247 |
} |
| 1248 |
else if (type == CPC_BITMAPS) |
| 1249 |
{ |
| 1250 |
if (num == 0) |
| 1251 |
{ |
| 1252 |
max_x = 320; |
| 1253 |
max_y = 200; |
| 1254 |
off = 128; |
| 1255 |
off_scr = 8128; |
| 1256 |
off_bg = 9128; |
| 1257 |
off_col = 9144; |
| 1258 |
col_comp = 0; |
| 1259 |
} |
| 1260 |
else if (num == 1) |
| 1261 |
{ |
| 1262 |
max_x = 320; |
| 1263 |
max_y = 136; |
| 1264 |
off = 128; |
| 1265 |
off_scr = 5568; |
| 1266 |
off_col = 6248; |
| 1267 |
off_bg = 6588; |
| 1268 |
col_comp = 1; |
| 1269 |
} |
| 1270 |
else if (num >= 2 && num <= 29) |
| 1271 |
{ |
| 1272 |
max_x = 320; |
| 1273 |
max_y = 136; |
| 1274 |
off = ((num-2)*6462); |
| 1275 |
off_scr = 5440+((num-2)*6462); |
| 1276 |
off_col = 6120+((num-2)*6462); |
| 1277 |
off_bg = 6460+((num-2)*6462); |
| 1278 |
col_comp = 1; |
| 1279 |
} |
| 1280 |
else |
| 1281 |
return FALSE; |
| 1282 |
} |
| 1283 |
|
| 1284 |
if (bitmap) |
| 1285 |
free(bitmap); |
| 1286 |
bitmap = bitmap_alloc(max_x,max_y); |
| 1287 |
if (bitmap == NULL) |
| 1288 |
{ |
| 1289 |
free(data); |
| 1290 |
return FALSE; |
| 1291 |
} |
| 1292 |
|
| 1293 |
for (yi = 0; yi < max_y; yi++) |
| 1294 |
{ |
| 1295 |
for (xi = 0; xi < max_x/2; xi++) |
| 1296 |
{ |
| 1297 |
cx = xi/4; |
| 1298 |
px = xi%4; |
| 1299 |
cy = yi/8; |
| 1300 |
py = yi%8; |
| 1301 |
|
| 1302 |
p = data[off+(cy*40+cx)*8+py]; |
| 1303 |
p = (p>>((3-px)*2))&3; |
| 1304 |
|
| 1305 |
switch (p) |
| 1306 |
{ |
| 1307 |
case 0: |
| 1308 |
i = data[off_bg] & 0x0f; |
| 1309 |
break; |
| 1310 |
case 1: |
| 1311 |
i = data[off_scr+cy*40+cx] >> 4; |
| 1312 |
break; |
| 1313 |
case 2: |
| 1314 |
i = data[off_scr+cy*40+cx] & 0x0f; |
| 1315 |
break; |
| 1316 |
case 3: |
| 1317 |
if (col_comp) |
| 1318 |
i = (data[off_col+(cy*40+cx)/2]>>((1-(cx%2))*4)) & 0x0f; |
| 1319 |
else |
| 1320 |
i = data[off_col+(cy*40+cx)] & 0x0f; |
| 1321 |
break; |
| 1322 |
} |
| 1323 |
|
| 1324 |
bitmap->bitmap[(bitmap->width*yi)+(xi*2)] = i; |
| 1325 |
bitmap->bitmap[(bitmap->width*yi)+(xi*2)+1] = i; |
| 1326 |
} |
| 1327 |
} |
| 1328 |
|
| 1329 |
bitmap->npalette = 16; |
| 1330 |
for (i = 0; i < 16; i++) |
| 1331 |
bitmap->palette[i] = bitmap_c64_colours[i]; |
| 1332 |
|
| 1333 |
free(data); |
| 1334 |
return TRUE; |
| 1335 |
} |
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
|
| 1392 |
|
| 1393 |
|
| 1394 |
|
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
|
| 1402 |
|
| 1403 |
|
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
|
| 1411 |
L9BOOL bitmap_bbc_decode(char* file, BitmapType type, int num) |
| 1412 |
{ |
| 1413 |
unsigned char patRowData[32]; |
| 1414 |
unsigned char patArray[16][2][2]; |
| 1415 |
FILE* f; |
| 1416 |
int i,j,k,isOddColumn,isOddRow; |
| 1417 |
L9BYTE pixel; |
| 1418 |
|
| 1419 |
if (bitmap_c64_decode(file,type,num) == FALSE) |
| 1420 |
return FALSE; |
| 1421 |
|
| 1422 |
f = fopen(file,"rb"); |
| 1423 |
if (f == NULL) |
| 1424 |
return FALSE; |
| 1425 |
|
| 1426 |
|
| 1427 |
fseek(f,filelength(f)-32,SEEK_SET); |
| 1428 |
if(fread(patRowData,sizeof (L9BYTE),32,f) != 32 && !feof(f)) return FALSE; |
| 1429 |
fclose(f); |
| 1430 |
|
| 1431 |
|
| 1432 |
i = 0; |
| 1433 |
for (k = 0; k < 2; k++) |
| 1434 |
{ |
| 1435 |
for (j = 0; j < 16; j++) |
| 1436 |
{ |
| 1437 |
|
| 1438 |
patArray[j][k][0] = |
| 1439 |
((patRowData[i] >> 4) & 0x8) + ((patRowData[i] >> 3) & 0x4) + |
| 1440 |
((patRowData[i] >> 2) & 0x2) + ((patRowData[i] >> 1) & 0x1); |
| 1441 |
|
| 1442 |
patArray[j][k][1] = |
| 1443 |
((patRowData[i] >> 3) & 0x8) + ((patRowData[i] >> 2) & 0x4) + |
| 1444 |
((patRowData[i] >> 1) & 0x2) + (patRowData[i] & 0x1); |
| 1445 |
i++; |
| 1446 |
} |
| 1447 |
} |
| 1448 |
|
| 1449 |
|
| 1450 |
i = 0; |
| 1451 |
isOddRow = 0; |
| 1452 |
for (j = 0; j < bitmap->height; j++) |
| 1453 |
{ |
| 1454 |
isOddColumn = 0; |
| 1455 |
for (k = 0; k < bitmap->width/2; k++) |
| 1456 |
{ |
| 1457 |
pixel = bitmap->bitmap[i]; |
| 1458 |
bitmap->bitmap[i] = patArray[pixel][isOddColumn][isOddRow]; |
| 1459 |
bitmap->bitmap[i+1] = patArray[pixel][isOddColumn][isOddRow]; |
| 1460 |
isOddColumn ^= 1; |
| 1461 |
i += 2; |
| 1462 |
} |
| 1463 |
isOddRow ^= 1; |
| 1464 |
} |
| 1465 |
|
| 1466 |
bitmap->npalette = 8; |
| 1467 |
for (i = 0; i < 8; i++) |
| 1468 |
bitmap->palette[i] = bitmap_bbc_colours[i]; |
| 1469 |
|
| 1470 |
return TRUE; |
| 1471 |
} |
| 1472 |
|
| 1473 |
BitmapType DetectBitmaps(char* dir) |
| 1474 |
{ |
| 1475 |
char file[MAX_PATH]; |
| 1476 |
|
| 1477 |
bitmap_noext_name(2,dir,file); |
| 1478 |
if (os_find_file(file)) |
| 1479 |
return bitmap_noext_type(file); |
| 1480 |
|
| 1481 |
bitmap_pc_name(2,dir,file); |
| 1482 |
if (os_find_file(file)) |
| 1483 |
return bitmap_pc_type(file); |
| 1484 |
|
| 1485 |
bitmap_c64_name(2,dir,file); |
| 1486 |
if (os_find_file(file)) |
| 1487 |
return bitmap_c64_type(file); |
| 1488 |
|
| 1489 |
bitmap_bbc_name(2,dir,file); |
| 1490 |
if (os_find_file(file)) |
| 1491 |
return BBC_BITMAPS; |
| 1492 |
|
| 1493 |
bitmap_cpc_name(2,dir,file); |
| 1494 |
if (os_find_file(file)) |
| 1495 |
return CPC_BITMAPS; |
| 1496 |
|
| 1497 |
bitmap_st2_name(2,dir,file); |
| 1498 |
if (os_find_file(file)) |
| 1499 |
return ST2_BITMAPS; |
| 1500 |
|
| 1501 |
return NO_BITMAPS; |
| 1502 |
} |
| 1503 |
|
| 1504 |
Bitmap* DecodeBitmap(char* dir, BitmapType type, int num, int x, int y) |
| 1505 |
{ |
| 1506 |
char file[MAX_PATH]; |
| 1507 |
|
| 1508 |
switch (type) |
| 1509 |
{ |
| 1510 |
case PC1_BITMAPS: |
| 1511 |
bitmap_pc_name(num,dir,file); |
| 1512 |
if (os_find_file(file)) |
| 1513 |
{ |
| 1514 |
if (bitmap_pc1_decode(file,x,y)) |
| 1515 |
return bitmap; |
| 1516 |
} |
| 1517 |
break; |
| 1518 |
|
| 1519 |
case PC2_BITMAPS: |
| 1520 |
bitmap_pc_name(num,dir,file); |
| 1521 |
if (os_find_file(file)) |
| 1522 |
{ |
| 1523 |
if (bitmap_pc2_decode(file,x,y)) |
| 1524 |
return bitmap; |
| 1525 |
} |
| 1526 |
break; |
| 1527 |
|
| 1528 |
case AMIGA_BITMAPS: |
| 1529 |
bitmap_noext_name(num,dir,file); |
| 1530 |
if (os_find_file(file)) |
| 1531 |
{ |
| 1532 |
if (bitmap_amiga_decode(file,x,y)) |
| 1533 |
return bitmap; |
| 1534 |
} |
| 1535 |
break; |
| 1536 |
|
| 1537 |
case C64_BITMAPS: |
| 1538 |
bitmap_c64_name(num,dir,file); |
| 1539 |
if (os_find_file(file)) |
| 1540 |
{ |
| 1541 |
if (bitmap_c64_decode(file,type,num)) |
| 1542 |
return bitmap; |
| 1543 |
} |
| 1544 |
break; |
| 1545 |
|
| 1546 |
case BBC_BITMAPS: |
| 1547 |
bitmap_bbc_name(num,dir,file); |
| 1548 |
if (os_find_file(file)) |
| 1549 |
{ |
| 1550 |
if (bitmap_bbc_decode(file,type,num)) |
| 1551 |
return bitmap; |
| 1552 |
} |
| 1553 |
break; |
| 1554 |
|
| 1555 |
case CPC_BITMAPS: |
| 1556 |
bitmap_cpc_name(num,dir,file); |
| 1557 |
if (os_find_file(file)) |
| 1558 |
{ |
| 1559 |
if (bitmap_c64_decode(file,type,num)) |
| 1560 |
return bitmap; |
| 1561 |
} |
| 1562 |
break; |
| 1563 |
|
| 1564 |
case MAC_BITMAPS: |
| 1565 |
bitmap_noext_name(num,dir,file); |
| 1566 |
if (os_find_file(file)) |
| 1567 |
{ |
| 1568 |
if (bitmap_mac_decode(file,x,y)) |
| 1569 |
return bitmap; |
| 1570 |
} |
| 1571 |
break; |
| 1572 |
|
| 1573 |
case ST1_BITMAPS: |
| 1574 |
bitmap_noext_name(num,dir,file); |
| 1575 |
if (os_find_file(file)) |
| 1576 |
{ |
| 1577 |
if (bitmap_st1_decode(file,x,y)) |
| 1578 |
return bitmap; |
| 1579 |
} |
| 1580 |
break; |
| 1581 |
|
| 1582 |
case ST2_BITMAPS: |
| 1583 |
bitmap_st2_name(num,dir,file); |
| 1584 |
if (os_find_file(file)) |
| 1585 |
{ |
| 1586 |
if (bitmap_pc2_decode(file,x,y)) |
| 1587 |
return bitmap; |
| 1588 |
} |
| 1589 |
break; |
| 1590 |
} |
| 1591 |
|
| 1592 |
return NULL; |
| 1593 |
} |
| 1594 |
|