Mercurial > hg > dmlib
comparison tools/lib64fmts.c @ 1780:5ea4713e9e0f
Change c64 format probing API to use DMGrowBuf.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 12 Jun 2018 20:37:53 +0300 |
parents | 20bf4140eaa1 |
children | 04e13949b314 |
comparison
equal
deleted
inserted
replaced
1779:20bf4140eaa1 | 1780:5ea4713e9e0f |
---|---|
8 */ | 8 */ |
9 #include "lib64gfx.h" | 9 #include "lib64gfx.h" |
10 | 10 |
11 | 11 |
12 | 12 |
13 static int fmtProbeKoalaPaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 13 static int fmtProbeKoalaPaintPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
14 { | 14 { |
15 // Attempt to prevent misprobes of unpacked Koala and Run Paint | 15 // Attempt to prevent misprobes of unpacked Koala and Run Paint |
16 if (len > 30 && | 16 if (buf->len > 30 && |
17 len != 10006 && | 17 buf->len != 10006 && |
18 len != 10003 && | 18 buf->len != 10003 && |
19 dmCompareAddr16(buf, 0, fmt->addr)) | 19 dmCompareAddr16(buf, 0, fmt->addr)) |
20 return DM_PROBE_SCORE_GOOD; | 20 return DM_PROBE_SCORE_GOOD; |
21 | 21 |
22 return DM_PROBE_SCORE_FALSE; | 22 return DM_PROBE_SCORE_FALSE; |
23 } | 23 } |
68 dmGrowBufFree(&tmp); | 68 dmGrowBufFree(&tmp); |
69 return res; | 69 return res; |
70 } | 70 } |
71 | 71 |
72 | 72 |
73 static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 73 static int fmtProbeDrazPaint20Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
74 { | 74 { |
75 const Uint8 *ident = buf + 2; | 75 const Uint8 *ident = buf->data + 2; |
76 if (len > 22 && | 76 if (buf->len > 22 && |
77 dmCompareAddr16(buf, 0, fmt->addr) && | 77 dmCompareAddr16(buf, 0, fmt->addr) && |
78 memcmp(ident, "DRAZPAINT ", 10) == 0 && | 78 memcmp(ident, "DRAZPAINT ", 10) == 0 && |
79 ident[11] == '.' && ( | 79 ident[11] == '.' && ( |
80 (ident[10] == '1' && ident[12] == '4') || | 80 (ident[10] == '1' && ident[12] == '4') || |
81 (ident[10] == '2' && ident[12] == '0') | 81 (ident[10] == '2' && ident[12] == '0') |
144 dmGrowBufFree(&tmp); | 144 dmGrowBufFree(&tmp); |
145 return res; | 145 return res; |
146 } | 146 } |
147 | 147 |
148 | 148 |
149 static int fmtProbeDrazLace10Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 149 static int fmtProbeDrazLace10Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
150 { | 150 { |
151 if (len > 22 && | 151 if (buf->len > 22 && |
152 dmCompareAddr16(buf, 0, fmt->addr) && | 152 dmCompareAddr16(buf, 0, fmt->addr) && |
153 memcmp(buf + 2, "DRAZLACE! 1.0", 13) == 0) | 153 memcmp(buf->data + 2, "DRAZLACE! 1.0", 13) == 0) |
154 return DM_PROBE_SCORE_MAX; | 154 return DM_PROBE_SCORE_MAX; |
155 | 155 |
156 return DM_PROBE_SCORE_FALSE; | 156 return DM_PROBE_SCORE_FALSE; |
157 } | 157 } |
158 | 158 |
175 } | 175 } |
176 | 176 |
177 | 177 |
178 static const char *fmtBDP5MagicID = "BDP 5.00"; | 178 static const char *fmtBDP5MagicID = "BDP 5.00"; |
179 | 179 |
180 static int fmtProbeBDP5Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 180 static int fmtProbeBDP5Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
181 { | 181 { |
182 if (len > 20 && | 182 if (buf->len > 20 && |
183 dmCompareAddr16(buf, 0, fmt->addr) && | 183 dmCompareAddr16(buf, 0, fmt->addr) && |
184 memcmp(buf + 2, fmtBDP5MagicID, strlen(fmtBDP5MagicID)) == 0) | 184 memcmp(buf->data + 2, fmtBDP5MagicID, strlen(fmtBDP5MagicID)) == 0) |
185 return DM_PROBE_SCORE_MAX; | 185 return DM_PROBE_SCORE_MAX; |
186 | 186 |
187 return DM_PROBE_SCORE_FALSE; | 187 return DM_PROBE_SCORE_FALSE; |
188 } | 188 } |
189 | 189 |
253 | 253 |
254 static const char *fmtGunPaintMagicID = "GUNPAINT (JZ) "; | 254 static const char *fmtGunPaintMagicID = "GUNPAINT (JZ) "; |
255 #define fmtGunPaintMagicLen (14) | 255 #define fmtGunPaintMagicLen (14) |
256 #define fmtGunPaintMagicOffs (0x3e8) | 256 #define fmtGunPaintMagicOffs (0x3e8) |
257 | 257 |
258 static int fmtProbeGunPaint(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 258 static int fmtProbeGunPaint(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
259 { | 259 { |
260 if (len > 0x400 && | 260 if (buf->len > 0x400 && |
261 dmCompareAddr16(buf, 0, fmt->addr) && | 261 dmCompareAddr16(buf, 0, fmt->addr) && |
262 memcmp(buf + fmtGunPaintMagicOffs + 2, fmtGunPaintMagicID, fmtGunPaintMagicLen) == 0) | 262 memcmp(buf->data + fmtGunPaintMagicOffs + 2, fmtGunPaintMagicID, fmtGunPaintMagicLen) == 0) |
263 return DM_PROBE_SCORE_MAX; | 263 return DM_PROBE_SCORE_MAX; |
264 | 264 |
265 return DM_PROBE_SCORE_FALSE; | 265 return DM_PROBE_SCORE_FALSE; |
266 } | 266 } |
267 | 267 |
275 memcpy(buf->data + fmtGunPaintMagicOffs, fmtGunPaintMagicID, fmtGunPaintMagicLen); | 275 memcpy(buf->data + fmtGunPaintMagicOffs, fmtGunPaintMagicID, fmtGunPaintMagicLen); |
276 return TRUE; | 276 return TRUE; |
277 } | 277 } |
278 | 278 |
279 | 279 |
280 static int fmtProbeAmicaPaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 280 static int fmtProbeAmicaPaintPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
281 { | 281 { |
282 size_t i, n; | 282 size_t i, n; |
283 | 283 |
284 if (len < 256 || !dmCompareAddr16(buf, 0, fmt->addr)) | 284 if (buf->len < 256 || !dmCompareAddr16(buf, 0, fmt->addr)) |
285 return DM_PROBE_SCORE_FALSE; | 285 return DM_PROBE_SCORE_FALSE; |
286 | 286 |
287 // Interpaint Hi-Res gives a false positive | 287 // Interpaint Hi-Res gives a false positive |
288 // as do some GunPaint images .. | 288 // as do some GunPaint images .. |
289 if (len == 9002 || fmtProbeGunPaint(buf, len, fmt) > DM_PROBE_SCORE_GOOD) | 289 if (buf->len == 9002 || |
290 fmtProbeGunPaint(buf, fmt) > DM_PROBE_SCORE_GOOD) | |
290 return DM_PROBE_SCORE_FALSE; | 291 return DM_PROBE_SCORE_FALSE; |
291 | 292 |
292 for (n = 0, i = 2; i < len; i++) | 293 for (n = 0, i = 2; i < buf->len; i++) |
293 if (buf[i] == 0xC2) n++; | 294 if (buf->data[i] == 0xC2) n++; |
294 | 295 |
295 if (n > 50) | 296 if (n > 50) |
296 return DM_PROBE_SCORE_GOOD; | 297 return DM_PROBE_SCORE_GOOD; |
297 if (n > 25) | 298 if (n > 25) |
298 return DM_PROBE_SCORE_AVG; | 299 return DM_PROBE_SCORE_AVG; |
359 dmGrowBufFree(&mem); | 360 dmGrowBufFree(&mem); |
360 return res; | 361 return res; |
361 } | 362 } |
362 | 363 |
363 | 364 |
364 static int fmtProbeSaracenPaint(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 365 static int fmtProbeSaracenPaint(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
365 { | 366 { |
366 if ((len == 10219 || len == 10220) && | 367 if ((buf->len == 10219 || buf->len == 10220) && |
367 dmCompareAddr16(buf, 0, fmt->addr)) | 368 dmCompareAddr16(buf, 0, fmt->addr)) |
368 return DM_PROBE_SCORE_GOOD; | 369 return DM_PROBE_SCORE_GOOD; |
369 | 370 |
370 return DM_PROBE_SCORE_FALSE; | 371 return DM_PROBE_SCORE_FALSE; |
371 } | 372 } |
372 | 373 |
373 | 374 |
374 static int fmtProbeFLIDesigner(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 375 static int fmtProbeFLIDesigner(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
375 { | 376 { |
376 if (len == fmt->size && | 377 if (buf->len == fmt->size && |
377 (dmCompareAddr16(buf, 0, 0x3c00) || dmCompareAddr16(buf, 0, 0x3ff0))) | 378 (dmCompareAddr16(buf, 0, 0x3c00) || dmCompareAddr16(buf, 0, 0x3ff0))) |
378 return DM_PROBE_SCORE_GOOD; | 379 return DM_PROBE_SCORE_GOOD; |
379 | 380 |
380 return DM_PROBE_SCORE_FALSE; | 381 return DM_PROBE_SCORE_FALSE; |
381 } | 382 } |
400 (void) rasterY; | 401 (void) rasterY; |
401 return dmC64GetGenericMCPixel(img, bmoffs, scroffs, shift, 0, bitmap, 0, img->bgcolor); | 402 return dmC64GetGenericMCPixel(img, bmoffs, scroffs, shift, 0, bitmap, 0, img->bgcolor); |
402 } | 403 } |
403 | 404 |
404 | 405 |
405 static int fmtProbeTruePaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 406 static int fmtProbeTruePaintPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
406 { | 407 { |
407 // The beginning/un-changing part of the BASIC bootstrap and | 408 // The beginning/un-changing part of the BASIC bootstrap and |
408 // relocation of decompression code | 409 // relocation of decompression code |
409 static const Uint8 magicID[] = { | 410 static const Uint8 magicID[] = { |
410 0x0b, 0x08, 0x09, 0x00, 0x9e, 0x32, 0x30, 0x35, | 411 0x0b, 0x08, 0x09, 0x00, 0x9e, 0x32, 0x30, 0x35, |
412 0x9d, 0xf5, 0x00, 0xe8, 0xd0, 0xf7, 0xe6, 0x01, | 413 0x9d, 0xf5, 0x00, 0xe8, 0xd0, 0xf7, 0xe6, 0x01, |
413 0x4c, 0x01, 0x01, 0xa5, 0xfe, 0xd0, 0x02, 0xc6, | 414 0x4c, 0x01, 0x01, 0xa5, 0xfe, 0xd0, 0x02, 0xc6, |
414 0xff, 0xc6, 0xfe | 415 0xff, 0xc6, 0xfe |
415 }; | 416 }; |
416 | 417 |
417 if (len >= 512 && dmCompareAddr16(buf, 0, fmt->addr) && | 418 if (buf->len >= 512 && dmCompareAddr16(buf, 0, fmt->addr) && |
418 memcmp(buf + 2, magicID, sizeof(magicID)) == 0) | 419 memcmp(buf->data + 2, magicID, sizeof(magicID)) == 0) |
419 return DM_PROBE_SCORE_MAX; | 420 return DM_PROBE_SCORE_MAX; |
420 | 421 |
421 return DM_PROBE_SCORE_FALSE; | 422 return DM_PROBE_SCORE_FALSE; |
422 } | 423 } |
423 | 424 |
536 #define XX2_HEIGHT_CH 10 | 537 #define XX2_HEIGHT_CH 10 |
537 #define XX2_SIZE (XX2_WIDTH_CH * XX2_HEIGHT_CH) | 538 #define XX2_SIZE (XX2_WIDTH_CH * XX2_HEIGHT_CH) |
538 #define XX2_BSIZE (XX2_SIZE * 8) | 539 #define XX2_BSIZE (XX2_SIZE * 8) |
539 | 540 |
540 | 541 |
541 static int fmtProbeFormatXX2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 542 static int fmtProbeFormatXX2(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
542 { | 543 { |
543 if (len >= XX2_MIN_SIZE && len <= XX2_MIN_SIZE + 8 && | 544 if (buf->len >= XX2_MIN_SIZE && |
545 buf->len <= XX2_MIN_SIZE + 8 && | |
544 dmCompareAddr16(buf, 0, fmt->addr)) | 546 dmCompareAddr16(buf, 0, fmt->addr)) |
545 return DM_PROBE_SCORE_MAYBE; | 547 return DM_PROBE_SCORE_MAYBE; |
546 | 548 |
547 return DM_PROBE_SCORE_FALSE; | 549 return DM_PROBE_SCORE_FALSE; |
548 } | 550 } |
569 | 571 |
570 #define FUNPAINT2_HEADER_SIZE (0x10) | 572 #define FUNPAINT2_HEADER_SIZE (0x10) |
571 static const char *fmtFunPaint2MagicID = "FUNPAINT (MT) "; | 573 static const char *fmtFunPaint2MagicID = "FUNPAINT (MT) "; |
572 | 574 |
573 | 575 |
574 static int fmtProbeFunPaint2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 576 static int fmtProbeFunPaint2(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
575 { | 577 { |
576 if (len > 30 && | 578 if (buf->len > 30 && |
577 dmCompareAddr16(buf, 0, fmt->addr) && | 579 dmCompareAddr16(buf, 0, fmt->addr) && |
578 memcmp(buf + 2, fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) == 0) | 580 memcmp(buf->data + 2, fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) == 0) |
579 { | 581 { |
580 // Unpacked variant | 582 // Unpacked variant |
581 if (fmt->size != 0 && buf[14 + 2] == 0) | 583 if (fmt->size != 0 && buf->data[14 + 2] == 0) |
582 return DM_PROBE_SCORE_MAX; | 584 return DM_PROBE_SCORE_MAX; |
583 | 585 |
584 // Packed variant | 586 // Packed variant |
585 if (fmt->size == 0 && buf[14 + 2] != 0) | 587 if (fmt->size == 0 && buf->data[14 + 2] != 0) |
586 return DM_PROBE_SCORE_MAX; | 588 return DM_PROBE_SCORE_MAX; |
587 } | 589 } |
588 | 590 |
589 return DM_PROBE_SCORE_FALSE; | 591 return DM_PROBE_SCORE_FALSE; |
590 } | 592 } |
809 | 811 |
810 return dmC64ConvertGenericBMP2Image(dst, src, fmt); | 812 return dmC64ConvertGenericBMP2Image(dst, src, fmt); |
811 } | 813 } |
812 | 814 |
813 | 815 |
814 static int fmtProbeECIPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 816 static int fmtProbeECIPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
815 { | 817 { |
816 size_t i, n; | 818 size_t i, n; |
817 | 819 |
818 // XXX TODO: Perhaps count statistics about used byte values | 820 // XXX TODO: Perhaps count statistics about used byte values |
819 // and compare to value in buf[2] which is the RLE marker | 821 // and compare to value in buf[2] which is the RLE marker |
820 if (len < 128 || | 822 if (buf->len < 128 || |
821 !dmCompareAddr16(buf, 0, fmt->addr) || | 823 !dmCompareAddr16(buf, 0, fmt->addr) || |
822 // Try to avoid misprobe of Crest Hires FLI Designer and Cosmos Design format | 824 // Try to avoid misprobe of Crest Hires FLI Designer and Cosmos Design format |
823 len == 16386 || len == 16385) | 825 buf->len == 16386 || buf->len == 16385) |
824 return DM_PROBE_SCORE_FALSE; | 826 return DM_PROBE_SCORE_FALSE; |
825 | 827 |
826 for (n = 0, i = 3; i < len; i++) | 828 for (n = 0, i = 3; i < buf->len; i++) |
827 if (buf[i] == buf[2]) n++; | 829 if (buf->data[i] == buf->data[2]) n++; |
828 | 830 |
829 if (n > 50) | 831 if (n > 50) |
830 return DM_PROBE_SCORE_GOOD; | 832 return DM_PROBE_SCORE_GOOD; |
831 if (n > 25) | 833 if (n > 25) |
832 return DM_PROBE_SCORE_AVG; | 834 return DM_PROBE_SCORE_AVG; |