Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 925:23b14d62bf67
Cosmetics.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 25 Feb 2015 15:30:53 +0200 |
parents | 732787cccca8 |
children | db495f421242 |
comparison
equal
deleted
inserted
replaced
924:732787cccca8 | 925:23b14d62bf67 |
---|---|
108 for (xc = 0; xc < widthpx / 2; xc++) | 108 for (xc = 0; xc < widthpx / 2; xc++) |
109 { | 109 { |
110 const int b = buf[offs + (xc / 4)]; | 110 const int b = buf[offs + (xc / 4)]; |
111 const int v = 6 - ((xc * 2) & 6); | 111 const int v = 6 - ((xc * 2) & 6); |
112 const Uint8 c = colors[(b >> v) & 3]; | 112 const Uint8 c = colors[(b >> v) & 3]; |
113 | 113 |
114 *d++ = c; | 114 *d++ = c; |
115 *d++ = c; | 115 *d++ = c; |
116 } | 116 } |
117 | 117 |
118 dp += img->pitch; | 118 dp += img->pitch; |
129 for (xc = 0; xc < widthpx; xc++) | 129 for (xc = 0; xc < widthpx; xc++) |
130 { | 130 { |
131 const int b = buf[offs + (xc / 8)]; | 131 const int b = buf[offs + (xc / 8)]; |
132 const int v = 7 - (xc & 7); | 132 const int v = 7 - (xc & 7); |
133 const Uint8 c = colors[(b >> v) & 1]; | 133 const Uint8 c = colors[(b >> v) & 1]; |
134 | 134 |
135 *d++ = c; | 135 *d++ = c; |
136 } | 136 } |
137 | 137 |
138 dp += img->pitch; | 138 dp += img->pitch; |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 return DMERR_OK; | 142 return DMERR_OK; |
143 } | 143 } |
144 | 144 |
145 | 145 |
146 static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 146 static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
164 { | 164 { |
165 Uint8 *dst, *dstEnd; | 165 Uint8 *dst, *dstEnd; |
166 | 166 |
167 if ((*mem = dmMalloc(C64_RAM_SIZE)) == NULL) | 167 if ((*mem = dmMalloc(C64_RAM_SIZE)) == NULL) |
168 return DMERR_MALLOC; | 168 return DMERR_MALLOC; |
169 | 169 |
170 dst = *mem; | 170 dst = *mem; |
171 dstEnd = *mem + C64_RAM_SIZE; | 171 dstEnd = *mem + C64_RAM_SIZE; |
172 | 172 |
173 while (src <= srcEnd && dst <= dstEnd) | 173 while (src <= srcEnd && dst <= dstEnd) |
174 { | 174 { |
211 const char *ident = (const char *) buf + 2; | 211 const char *ident = (const char *) buf + 2; |
212 if (len > 22 && | 212 if (len > 22 && |
213 dmCompareAddr16(buf, 0, fmt->addr) && | 213 dmCompareAddr16(buf, 0, fmt->addr) && |
214 strncmp(ident, "DRAZLACE! 1.0", 13) == 0) | 214 strncmp(ident, "DRAZLACE! 1.0", 13) == 0) |
215 return DM_PROBE_SCORE_MAX; | 215 return DM_PROBE_SCORE_MAX; |
216 | 216 |
217 return DM_PROBE_SCORE_FALSE; | 217 return DM_PROBE_SCORE_FALSE; |
218 } | 218 } |
219 | 219 |
220 | 220 |
221 static BOOL fmtDrazLaceSetLaceType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len) | 221 static BOOL fmtDrazLaceSetLaceType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len) |
232 static int fmtProbeAmicaPaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 232 static int fmtProbeAmicaPaintPacked(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
233 { | 233 { |
234 size_t i, n; | 234 size_t i, n; |
235 if (len < AMICA_DM_PROBE_SIZE || !dmCompareAddr16(buf, 0, fmt->addr)) | 235 if (len < AMICA_DM_PROBE_SIZE || !dmCompareAddr16(buf, 0, fmt->addr)) |
236 return DM_PROBE_SCORE_FALSE; | 236 return DM_PROBE_SCORE_FALSE; |
237 | 237 |
238 // Interpaint Hi-Res gives a false positive | 238 // Interpaint Hi-Res gives a false positive |
239 if (len == 9002) | 239 if (len == 9002) |
240 return DM_PROBE_SCORE_FALSE; | 240 return DM_PROBE_SCORE_FALSE; |
241 | 241 |
242 for (n = 0, i = 2; i < len; i++) | 242 for (n = 0, i = 2; i < len; i++) |
243 if (buf[i] == 0xC2) n++; | 243 if (buf[i] == 0xC2) n++; |
244 | 244 |
245 if (n > 50) | 245 if (n > 50) |
246 return DM_PROBE_SCORE_GOOD; | 246 return DM_PROBE_SCORE_GOOD; |
247 if (n > 25) | 247 if (n > 25) |
248 return DM_PROBE_SCORE_AVG; | 248 return DM_PROBE_SCORE_AVG; |
249 if (n > 10) | 249 if (n > 10) |
259 | 259 |
260 if ((res = dmDecodeGenericRLE(&mem, &dstEnd, buf, buf + len, 0xC2)) != DMERR_OK) | 260 if ((res = dmDecodeGenericRLE(&mem, &dstEnd, buf, buf + len, 0xC2)) != DMERR_OK) |
261 goto out; | 261 goto out; |
262 | 262 |
263 res = dmC64DecodeGenericBMP(img, mem, dstEnd - mem + 1, fmt); | 263 res = dmC64DecodeGenericBMP(img, mem, dstEnd - mem + 1, fmt); |
264 | 264 |
265 out: | 265 out: |
266 dmFree(mem); | 266 dmFree(mem); |
267 return res; | 267 return res; |
268 } | 268 } |
269 | 269 |
320 { DT_COLOR_REG, 0x2740, 0, DC_BGCOL, NULL, NULL }, | 320 { DT_COLOR_REG, 0x2740, 0, DC_BGCOL, NULL, NULL }, |
321 { DT_BITMAP, 0x2800, 1, 0, NULL, NULL }, | 321 { DT_BITMAP, 0x2800, 1, 0, NULL, NULL }, |
322 { DT_DEC_FUNCTION, 0x2742, 0, 1, fmtDrazLaceSetLaceType, NULL }, | 322 { DT_DEC_FUNCTION, 0x2742, 0, 1, fmtDrazLaceSetLaceType, NULL }, |
323 } | 323 } |
324 }, | 324 }, |
325 | 325 |
326 { | 326 { |
327 D64_FMT_MC, "drp", "DrazPaint (unpacked)", 0x5800, 10051, | 327 D64_FMT_MC, "drp", "DrazPaint (unpacked)", 0x5800, 10051, |
328 C64_SCR_WIDTH , C64_SCR_HEIGHT, | 328 C64_SCR_WIDTH , C64_SCR_HEIGHT, |
329 C64_SCR_CH_WIDTH, C64_SCR_CH_HEIGHT, | 329 C64_SCR_CH_WIDTH, C64_SCR_CH_HEIGHT, |
330 NULL, NULL, | 330 NULL, NULL, |
352 { DT_COLOR_REG, 0x2740, 0, DC_BGCOL, NULL, NULL }, | 352 { DT_COLOR_REG, 0x2740, 0, DC_BGCOL, NULL, NULL }, |
353 { DT_BITMAP, 0x2800, 1, 0, NULL, NULL }, | 353 { DT_BITMAP, 0x2800, 1, 0, NULL, NULL }, |
354 { DT_DEC_FUNCTION, 0x2742, 0, 1, fmtDrazLaceSetLaceType, NULL }, | 354 { DT_DEC_FUNCTION, 0x2742, 0, 1, fmtDrazLaceSetLaceType, NULL }, |
355 } | 355 } |
356 }, | 356 }, |
357 | 357 |
358 { | 358 { |
359 D64_FMT_MC | D64_FMT_ILACE, "mci", "Truepaint (unpacked)", 0x9c00, 19434, | 359 D64_FMT_MC | D64_FMT_ILACE, "mci", "Truepaint (unpacked)", 0x9c00, 19434, |
360 C64_SCR_WIDTH , C64_SCR_HEIGHT, | 360 C64_SCR_WIDTH , C64_SCR_HEIGHT, |
361 C64_SCR_CH_WIDTH, C64_SCR_CH_HEIGHT, | 361 C64_SCR_CH_WIDTH, C64_SCR_CH_HEIGHT, |
362 NULL, NULL, | 362 NULL, NULL, |
370 { DT_SCREEN_RAM, 0x4400, 1, 0, NULL, NULL }, | 370 { DT_SCREEN_RAM, 0x4400, 1, 0, NULL, NULL }, |
371 { DT_COLOR_RAM, 0x4800, 0, 0, NULL, NULL }, | 371 { DT_COLOR_RAM, 0x4800, 0, 0, NULL, NULL }, |
372 { DT_DEC_FUNCTION, 0x0000, 0, 0, fmtTruePaintSetLaceType, NULL }, | 372 { DT_DEC_FUNCTION, 0x0000, 0, 0, fmtTruePaintSetLaceType, NULL }, |
373 } | 373 } |
374 }, | 374 }, |
375 | 375 |
376 { | 376 { |
377 D64_FMT_MC, "kla", "Koala Paint (unpacked)", 0x6000, 10003, | 377 D64_FMT_MC, "kla", "Koala Paint (unpacked)", 0x6000, 10003, |
378 C64_SCR_WIDTH , C64_SCR_HEIGHT, | 378 C64_SCR_WIDTH , C64_SCR_HEIGHT, |
379 C64_SCR_CH_WIDTH, C64_SCR_CH_HEIGHT, | 379 C64_SCR_CH_WIDTH, C64_SCR_CH_HEIGHT, |
380 NULL, NULL, | 380 NULL, NULL, |
652 { | 652 { |
653 dmError("Invalid number of enc/dec ops in format. Internal error.\n"); | 653 dmError("Invalid number of enc/dec ops in format. Internal error.\n"); |
654 return DMERR_INTERNAL; | 654 return DMERR_INTERNAL; |
655 } | 655 } |
656 | 656 |
657 // Clear the image structure | 657 // Clear the image structure, set basics |
658 memset(img, 0, sizeof(*img)); | 658 memset(img, 0, sizeof(*img)); |
659 img->type = fmt->type; | 659 img->type = fmt->type; |
660 | 660 |
661 // Perform decoding | 661 // Perform decoding |
662 for (i = 0; i < fmt->nencdecOps; i++) | 662 for (i = 0; i < fmt->nencdecOps; i++) |
667 int res; | 667 int res; |
668 | 668 |
669 // Check operation validity | 669 // Check operation validity |
670 if ((res = dmC64SanityCheckEncDecOp(i, op)) != DMERR_OK) | 670 if ((res = dmC64SanityCheckEncDecOp(i, op)) != DMERR_OK) |
671 return res; | 671 return res; |
672 | 672 |
673 // Check size | 673 // Check size |
674 size = (op->size == 0) ? dmC64DefaultSizes[op->type] : op->size; | 674 size = (op->size == 0) ? dmC64DefaultSizes[op->type] : op->size; |
675 | 675 |
676 // Do we need to reallocate some more space? | 676 // Do we need to reallocate some more space? |
677 if (op->offs + size > len) | 677 if (op->offs + size > len) |
701 case DC_D021: img->bgcolor = *src; break; | 701 case DC_D021: img->bgcolor = *src; break; |
702 case DC_D022: img->d022 = *src; break; | 702 case DC_D022: img->d022 = *src; break; |
703 case DC_D023: img->d023 = *src; break; | 703 case DC_D023: img->d023 = *src; break; |
704 case DC_D024: img->d024 = *src; break; | 704 case DC_D024: img->d024 = *src; break; |
705 default: | 705 default: |
706 dmError("Unhandled DT_COLOR_REG mode %d in ", | 706 dmError("Unhandled DT_COLOR_REG mode %d in ", |
707 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", | 707 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
708 op->size, i, op->offs, op->offs, op->bank, size, size, len, len); | 708 op->size, i, op->offs, op->offs, op->bank, size, size, len, len); |
709 return DMERR_INTERNAL; | 709 return DMERR_INTERNAL; |
710 } | 710 } |
711 break; | 711 break; |
718 case DC_D021: img->bgcolor = op->offs; break; | 718 case DC_D021: img->bgcolor = op->offs; break; |
719 case DC_D022: img->d022 = op->offs; break; | 719 case DC_D022: img->d022 = op->offs; break; |
720 case DC_D023: img->d023 = op->offs; break; | 720 case DC_D023: img->d023 = op->offs; break; |
721 case DC_D024: img->d024 = op->offs; break; | 721 case DC_D024: img->d024 = op->offs; break; |
722 default: | 722 default: |
723 dmError("Unhandled DT_COLOR_SET mode %d in ", | 723 dmError("Unhandled DT_COLOR_SET mode %d in ", |
724 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", | 724 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
725 op->size, i, op->offs, op->offs, op->bank, size, size, len, len); | 725 op->size, i, op->offs, op->offs, op->bank, size, size, len, len); |
726 return DMERR_INTERNAL; | 726 return DMERR_INTERNAL; |
727 } | 727 } |
728 break; | 728 break; |
741 img->screen[bank][offs] = offs & 0xff; | 741 img->screen[bank][offs] = offs & 0xff; |
742 } | 742 } |
743 break; | 743 break; |
744 | 744 |
745 default: | 745 default: |
746 dmError("Unhandled DT_CHAR_CONFIG mode %d in ", | 746 dmError("Unhandled DT_CHAR_CONFIG mode %d in ", |
747 "op #%d, bank=%d, size=%d ($%04x) @ %d ($%04x)\n", | 747 "op #%d, bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
748 op->offs, i, op->bank, size, size, len, len); | 748 op->offs, i, op->bank, size, size, len, len); |
749 return DMERR_INTERNAL; | 749 return DMERR_INTERNAL; |
750 } | 750 } |
751 break; | 751 break; |
853 case DC_D021: *dst = img->bgcolor; break; | 853 case DC_D021: *dst = img->bgcolor; break; |
854 case DC_D022: *dst = img->d022; break; | 854 case DC_D022: *dst = img->d022; break; |
855 case DC_D023: *dst = img->d023; break; | 855 case DC_D023: *dst = img->d023; break; |
856 case DC_D024: *dst = img->d024; break; | 856 case DC_D024: *dst = img->d024; break; |
857 default: | 857 default: |
858 dmError("Unhandled DT_COLOR_REG mode %d in ", | 858 dmError("Unhandled DT_COLOR_REG mode %d in ", |
859 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", | 859 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
860 op->size, i, op->offs, op->offs, op->bank, size, size, *plen, *plen); | 860 op->size, i, op->offs, op->offs, op->bank, size, size, *plen, *plen); |
861 return DMERR_INTERNAL; | 861 return DMERR_INTERNAL; |
862 } | 862 } |
863 break; | 863 break; |
957 const int x = xc / 4; | 957 const int x = xc / 4; |
958 const int scroffs = scroffsy + x; | 958 const int scroffs = scroffsy + x; |
959 const int chr = src->screen[0][scroffs]; | 959 const int chr = src->screen[0][scroffs]; |
960 const int v = 6 - ((xc * 2) & 6); | 960 const int v = 6 - ((xc * 2) & 6); |
961 Uint8 c; | 961 Uint8 c; |
962 | 962 |
963 switch ((src->charmem[chr][yb] >> v) & 3) | 963 switch ((src->charmem[chr][yb] >> v) & 3) |
964 { | 964 { |
965 case 0: c = src->bgcolor; break; | 965 case 0: c = src->bgcolor; break; |
966 case 1: c = src->d022; break; | 966 case 1: c = src->d022; break; |
967 case 2: c = src->d023; break; | 967 case 2: c = src->d023; break; |