Mercurial > hg > dmlib
comparison tools/lib64fmts.c @ 1579:4288b21e97b9
Improve and simplify Fun Paint 2 format support.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 13 May 2018 10:07:25 +0300 |
parents | fb60abb09a65 |
children | 5aa1c3ec91d5 |
comparison
equal
deleted
inserted
replaced
1578:fb60abb09a65 | 1579:4288b21e97b9 |
---|---|
96 int res; | 96 int res; |
97 DMGrowBuf mem; | 97 DMGrowBuf mem; |
98 DMCompParams cfg; | 98 DMCompParams cfg; |
99 | 99 |
100 cfg.type = DM_COMP_RLE_MARKER1; | 100 cfg.type = DM_COMP_RLE_MARKER1; |
101 cfg.rleMarker = *(buf + 0x0d); | 101 cfg.rleMarker = buf[0x0d]; |
102 | 102 |
103 if ((res = dmDecodeGenericRLEAlloc(&mem, buf + 0x0e, buf + len, &cfg)) != DMERR_OK) | 103 if ((res = dmDecodeGenericRLEAlloc(&mem, buf + 0x0e, buf + len, &cfg)) != DMERR_OK) |
104 goto out; | 104 goto out; |
105 | 105 |
106 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); | 106 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); |
330 | 330 |
331 #define FUNPAINT2_HEADER_SIZE (0x10) | 331 #define FUNPAINT2_HEADER_SIZE (0x10) |
332 static const char *fmtFunPaint2MagicID = "FUNPAINT (MT) "; | 332 static const char *fmtFunPaint2MagicID = "FUNPAINT (MT) "; |
333 | 333 |
334 | 334 |
335 static BOOL fmtProbeFunPaint2Header(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 335 static int fmtProbeFunPaint2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
336 { | 336 { |
337 return | 337 if (len > 30 && |
338 len > 30 && | |
339 dmCompareAddr16(buf, 0, fmt->addr) && | 338 dmCompareAddr16(buf, 0, fmt->addr) && |
340 strncmp((const char *) (buf + 2), fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) == 0; | 339 strncmp((const char *) (buf + 2), fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) == 0) |
341 } | |
342 | |
343 | |
344 static int fmtProbeFunPaint2Unpacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | |
345 { | |
346 if (fmtProbeFunPaint2Header(buf, len, fmt) && | |
347 buf[2 + 14] == 0) | |
348 return DM_PROBE_SCORE_MAX; | 340 return DM_PROBE_SCORE_MAX; |
349 else | 341 else |
350 return DM_PROBE_SCORE_FALSE; | 342 return DM_PROBE_SCORE_FALSE; |
351 } | 343 } |
352 | 344 |
353 | 345 |
354 static int fmtProbeFunPaint2Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 346 static int fmtDecodeFunPaint2(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
355 { | 347 { |
356 if (fmtProbeFunPaint2Header(buf, len, fmt) && | 348 int res; |
357 buf[2 + 14] != 0) | 349 |
358 return DM_PROBE_SCORE_MAX; | 350 // Check if the data is compressed |
351 if (buf[14]) | |
352 { | |
353 DMGrowBuf mem; | |
354 DMCompParams cfg; | |
355 | |
356 cfg.type = DM_COMP_RLE_MARKER1; | |
357 cfg.rleMarker = buf[15]; | |
358 | |
359 if ((res = dmDecodeGenericRLEAlloc(&mem, buf + FUNPAINT2_HEADER_SIZE, | |
360 buf + len + 1, // XXX TODO: nasty +1 | |
361 &cfg)) == DMERR_OK) | |
362 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); | |
363 | |
364 dmGrowBufFree(&mem); | |
365 } | |
359 else | 366 else |
360 return DM_PROBE_SCORE_FALSE; | 367 { |
361 } | 368 res = dmC64DecodeGenericBMP(img, buf + FUNPAINT2_HEADER_SIZE, len - FUNPAINT2_HEADER_SIZE, fmt); |
362 | 369 } |
363 | 370 |
364 static int fmtDecodeFunPaint2Unpacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | |
365 { | |
366 return dmC64DecodeGenericBMP(img, buf + FUNPAINT2_HEADER_SIZE, len - FUNPAINT2_HEADER_SIZE, fmt); | |
367 } | |
368 | |
369 | |
370 static int fmtDecodeFunPaint2Packed(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | |
371 { | |
372 int res; | |
373 DMGrowBuf mem; | |
374 DMCompParams cfg; | |
375 | |
376 cfg.type = DM_COMP_RLE_MARKER1; | |
377 cfg.rleMarker = *(buf + 15); | |
378 if ((res = dmDecodeGenericRLEAlloc(&mem, buf + FUNPAINT2_HEADER_SIZE, buf + len, &cfg)) != DMERR_OK) | |
379 goto out; | |
380 | |
381 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); | |
382 | |
383 out: | |
384 dmGrowBufFree(&mem); | |
385 return res; | 371 return res; |
386 } | 372 } |
387 | 373 |
388 | 374 |
389 static int fmtEncodeFunPaint2Unpacked(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt) | 375 static int fmtEncodeFunPaint2Unpacked(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt) |
879 { | 865 { |
880 D64_FMT_MC | D64_FMT_FLI | D64_FMT_ILACE, | 866 D64_FMT_MC | D64_FMT_FLI | D64_FMT_ILACE, |
881 "fp2", "FunPaint II (unpacked)", 0x3ff0, 33694, DM_FMT_RD, | 867 "fp2", "FunPaint II (unpacked)", 0x3ff0, 33694, DM_FMT_RD, |
882 C64_SCR_WIDTH, C64_SCR_HEIGHT, | 868 C64_SCR_WIDTH, C64_SCR_HEIGHT, |
883 C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT, | 869 C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT, |
884 fmtProbeFunPaint2Unpacked, | 870 fmtProbeFunPaint2, |
885 fmtDecodeFunPaint2Unpacked, fmtEncodeFunPaint2Unpacked, | 871 fmtDecodeFunPaint2, fmtEncodeFunPaint2Unpacked, |
886 NULL, NULL, | 872 NULL, NULL, |
887 fmtGetPixelFunPaint2, | 873 fmtGetPixelFunPaint2, |
888 { | 874 { |
889 DEF_SCREEN_RAMS_8( 0x0000, 0, 0x400) | 875 DEF_SCREEN_RAMS_8( 0x0000, 0, 0x400) |
890 { DT_BITMAP, 0x2000, 0, 0, NULL, NULL }, | 876 { DT_BITMAP, 0x2000, 0, 0, NULL, NULL }, |
900 { | 886 { |
901 D64_FMT_MC | D64_FMT_FLI | D64_FMT_ILACE, | 887 D64_FMT_MC | D64_FMT_FLI | D64_FMT_ILACE, |
902 "fp2p", "FunPaint II (packed)", 0x3ff0, 0, DM_FMT_RD, | 888 "fp2p", "FunPaint II (packed)", 0x3ff0, 0, DM_FMT_RD, |
903 C64_SCR_WIDTH, C64_SCR_HEIGHT, | 889 C64_SCR_WIDTH, C64_SCR_HEIGHT, |
904 C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT, | 890 C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT, |
905 fmtProbeFunPaint2Packed, | 891 NULL, |
906 fmtDecodeFunPaint2Packed, fmtEncodeFunPaint2Packed, | 892 fmtDecodeFunPaint2, fmtEncodeFunPaint2Packed, |
907 NULL, NULL, | 893 NULL, NULL, |
908 fmtGetPixelFunPaint2, | 894 fmtGetPixelFunPaint2, |
909 { | 895 { |
910 DEF_SCREEN_RAMS_8( 0x0000, 0, 0x400) | 896 DEF_SCREEN_RAMS_8( 0x0000, 0, 0x400) |
911 { DT_BITMAP, 0x2000, 0, 0, NULL, NULL }, | 897 { DT_BITMAP, 0x2000, 0, 0, NULL, NULL }, |