Mercurial > hg > dmlib
comparison lib64gfx.c @ 410:e4b2f689aff6
Stdint -> SDL types conversion.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 03 Nov 2012 02:41:15 +0200 |
parents | 59244a7ae37f |
children | 936bc27a79d6 |
comparison
equal
deleted
inserted
replaced
409:b529b7e8ff83 | 410:e4b2f689aff6 |
---|---|
59 if (img == NULL) | 59 if (img == NULL) |
60 return NULL; | 60 return NULL; |
61 | 61 |
62 img->width = img->pitch = width; | 62 img->width = img->pitch = width; |
63 img->height = height; | 63 img->height = height; |
64 img->data = dmMalloc(width * height * sizeof(uint8_t)); | 64 img->data = dmMalloc(width * height * sizeof(Uint8)); |
65 if (img->data == NULL) | 65 if (img->data == NULL) |
66 { | 66 { |
67 dmFree(img); | 67 dmFree(img); |
68 return NULL; | 68 return NULL; |
69 } | 69 } |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 | 101 |
102 int dmC64ConvertCSData(DMImage *img, | 102 int dmC64ConvertCSData(DMImage *img, |
103 int xoffs, int yoffs, const uint8_t *buf, | 103 int xoffs, int yoffs, const Uint8 *buf, |
104 int width, int height, BOOL multicolor, int *colors) | 104 int width, int height, BOOL multicolor, int *colors) |
105 { | 105 { |
106 int yc, widthpx = width * 8; | 106 int yc, widthpx = width * 8; |
107 uint8_t *dp; | 107 Uint8 *dp; |
108 | 108 |
109 if (img == NULL) | 109 if (img == NULL) |
110 return -1; | 110 return -1; |
111 if (xoffs < 0 || yoffs < 0) | 111 if (xoffs < 0 || yoffs < 0) |
112 return -2; | 112 return -2; |
120 { | 120 { |
121 for (yc = 0; yc < height; yc++) | 121 for (yc = 0; yc < height; yc++) |
122 { | 122 { |
123 const int offs = yc * width; | 123 const int offs = yc * width; |
124 int xc; | 124 int xc; |
125 uint8_t *d = dp; | 125 Uint8 *d = dp; |
126 | 126 |
127 for (xc = 0; xc < widthpx / 2; xc++) | 127 for (xc = 0; xc < widthpx / 2; xc++) |
128 { | 128 { |
129 const int b = buf[offs + (xc / 4)]; | 129 const int b = buf[offs + (xc / 4)]; |
130 const int v = 6 - ((xc * 2) & 6); | 130 const int v = 6 - ((xc * 2) & 6); |
131 const uint8_t c = colors[(b >> v) & 3]; | 131 const Uint8 c = colors[(b >> v) & 3]; |
132 | 132 |
133 *d++ = c; | 133 *d++ = c; |
134 *d++ = c; | 134 *d++ = c; |
135 } | 135 } |
136 | 136 |
141 { | 141 { |
142 for (yc = 0; yc < height; yc++) | 142 for (yc = 0; yc < height; yc++) |
143 { | 143 { |
144 const int offs = yc * width; | 144 const int offs = yc * width; |
145 int xc; | 145 int xc; |
146 uint8_t *d = dp; | 146 Uint8 *d = dp; |
147 | 147 |
148 for (xc = 0; xc < widthpx; xc++) | 148 for (xc = 0; xc < widthpx; xc++) |
149 { | 149 { |
150 const int b = buf[offs + (xc / 8)]; | 150 const int b = buf[offs + (xc / 8)]; |
151 const int v = 7 - (xc & 7); | 151 const int v = 7 - (xc & 7); |
152 const uint8_t c = colors[(b >> v) & 1]; | 152 const Uint8 c = colors[(b >> v) & 1]; |
153 | 153 |
154 *d++ = c; | 154 *d++ = c; |
155 } | 155 } |
156 | 156 |
157 dp += img->pitch; | 157 dp += img->pitch; |
160 | 160 |
161 return 0; | 161 return 0; |
162 } | 162 } |
163 | 163 |
164 | 164 |
165 static int fmtProbeDrazPaint(const uint8_t *buf, const size_t len) | 165 static int fmtProbeDrazPaint(const Uint8 *buf, const size_t len) |
166 { | 166 { |
167 if (len == 10051 && buf[0] == 0x00 && buf[1] == 0x58) | 167 if (len == 10051 && buf[0] == 0x00 && buf[1] == 0x58) |
168 return DM_PROBE_SCORE_GOOD; | 168 return DM_PROBE_SCORE_GOOD; |
169 | 169 |
170 return DM_PROBE_SCORE_FALSE; | 170 return DM_PROBE_SCORE_FALSE; |
171 } | 171 } |
172 | 172 |
173 | 173 |
174 static int fmtProbeDrazPaint20Packed(const uint8_t *buf, const size_t len) | 174 static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len) |
175 { | 175 { |
176 const char *ident = (const char *) buf + 2; | 176 const char *ident = (const char *) buf + 2; |
177 if (len > 22 && buf[0] == 0x00 && buf[1] == 0x58 && | 177 if (len > 22 && buf[0] == 0x00 && buf[1] == 0x58 && |
178 strncmp(ident, "DRAZPAINT ", 10) == 0 && | 178 strncmp(ident, "DRAZPAINT ", 10) == 0 && |
179 ident[11] == '.' && ( | 179 ident[11] == '.' && ( |
184 | 184 |
185 return DM_PROBE_SCORE_FALSE; | 185 return DM_PROBE_SCORE_FALSE; |
186 } | 186 } |
187 | 187 |
188 | 188 |
189 static int fmtDecodeDrazPaintPacked(DMC64Image *img, const uint8_t *buf, const size_t len, const DMC64ImageFormat *fmt) | 189 static int fmtDecodeDrazPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
190 { | 190 { |
191 int res; | 191 int res; |
192 uint8_t rleMarker; | 192 Uint8 rleMarker; |
193 uint8_t *mem, *dst, *dstEnd; | 193 Uint8 *mem, *dst, *dstEnd; |
194 const uint8_t *src, *srcEnd; | 194 const Uint8 *src, *srcEnd; |
195 | 195 |
196 if ((mem = dmMalloc(C64_RAM_SIZE)) == NULL) | 196 if ((mem = dmMalloc(C64_RAM_SIZE)) == NULL) |
197 return -1; | 197 return -1; |
198 | 198 |
199 rleMarker = *(buf + 0x0d); | 199 rleMarker = *(buf + 0x0d); |
222 | 222 |
223 return res; | 223 return res; |
224 } | 224 } |
225 | 225 |
226 | 226 |
227 static int fmtProbeDrazLace10(const uint8_t *buf, const size_t len) | 227 static int fmtProbeDrazLace10(const Uint8 *buf, const size_t len) |
228 { | 228 { |
229 if (len == 18242 && buf[0] == 0x00 && buf[1] == 0x58) | 229 if (len == 18242 && buf[0] == 0x00 && buf[1] == 0x58) |
230 return DM_PROBE_SCORE_GOOD; | 230 return DM_PROBE_SCORE_GOOD; |
231 return DM_PROBE_SCORE_FALSE; | 231 return DM_PROBE_SCORE_FALSE; |
232 } | 232 } |
233 | 233 |
234 | 234 |
235 static int fmtProbeDrazLace10Packed(const uint8_t *buf, const size_t len) | 235 static int fmtProbeDrazLace10Packed(const Uint8 *buf, const size_t len) |
236 { | 236 { |
237 const char *ident = (const char *) buf + 2; | 237 const char *ident = (const char *) buf + 2; |
238 if (len > 22 && buf[0] == 0x00 && buf[1] == 0x58 && | 238 if (len > 22 && buf[0] == 0x00 && buf[1] == 0x58 && |
239 strncmp(ident, "DRAZLACE! 1.0", 13) == 0) | 239 strncmp(ident, "DRAZLACE! 1.0", 13) == 0) |
240 return DM_PROBE_SCORE_MAX; | 240 return DM_PROBE_SCORE_MAX; |
241 | 241 |
242 return DM_PROBE_SCORE_FALSE; | 242 return DM_PROBE_SCORE_FALSE; |
243 } | 243 } |
244 | 244 |
245 | 245 |
246 static BOOL fmtDrazLaceSetLaceType(DMC64Image *img, const struct _DMDecodeOp *op, const uint8_t *buf, const size_t len) | 246 static BOOL fmtDrazLaceSetLaceType(DMC64Image *img, const struct _DMDecodeOp *op, const Uint8 *buf, const size_t len) |
247 { | 247 { |
248 img->laceType = buf[op->offs] ? DM_C64ILACE_RES : DM_C64ILACE_COLOR; | 248 img->laceType = buf[op->offs] ? DM_C64ILACE_RES : DM_C64ILACE_COLOR; |
249 img->laceBank2 = 0; | 249 img->laceBank2 = 0; |
250 return TRUE; | 250 return TRUE; |
251 } | 251 } |
252 | 252 |
253 | 253 |
254 #define AMICA_DM_PROBE_SIZE 1024 | 254 #define AMICA_DM_PROBE_SIZE 1024 |
255 static int fmtProbeAmicaPaintPacked(const uint8_t *buf, const size_t len) | 255 static int fmtProbeAmicaPaintPacked(const Uint8 *buf, const size_t len) |
256 { | 256 { |
257 int i, n; | 257 int i, n; |
258 if (len < AMICA_DM_PROBE_SIZE || buf[0] != 0x00 || buf[1] != 0x40) | 258 if (len < AMICA_DM_PROBE_SIZE || buf[0] != 0x00 || buf[1] != 0x40) |
259 return DM_PROBE_SCORE_FALSE; | 259 return DM_PROBE_SCORE_FALSE; |
260 | 260 |
268 | 268 |
269 return DM_PROBE_SCORE_MAYBE; | 269 return DM_PROBE_SCORE_MAYBE; |
270 } | 270 } |
271 | 271 |
272 | 272 |
273 static int fmtDecodeAmicaPaintPacked(DMC64Image *img, const uint8_t *buf, const size_t len, const DMC64ImageFormat *fmt) | 273 static int fmtDecodeAmicaPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
274 { | 274 { |
275 int res; | 275 int res; |
276 uint8_t *mem, *dst, *dstEnd; | 276 Uint8 *mem, *dst, *dstEnd; |
277 const uint8_t *src, *srcEnd; | 277 const Uint8 *src, *srcEnd; |
278 | 278 |
279 if ((mem = dmMalloc(C64_RAM_SIZE)) == NULL) | 279 if ((mem = dmMalloc(C64_RAM_SIZE)) == NULL) |
280 return -1; | 280 return -1; |
281 | 281 |
282 src = buf; | 282 src = buf; |
304 | 304 |
305 return res; | 305 return res; |
306 } | 306 } |
307 | 307 |
308 | 308 |
309 static int fmtProbeKoalaPaint(const uint8_t *buf, const size_t len) | 309 static int fmtProbeKoalaPaint(const Uint8 *buf, const size_t len) |
310 { | 310 { |
311 if (len == 10003 && buf[0] == 0x00 && buf[1] == 0x60) | 311 if (len == 10003 && buf[0] == 0x00 && buf[1] == 0x60) |
312 return DM_PROBE_SCORE_AVG; | 312 return DM_PROBE_SCORE_AVG; |
313 return DM_PROBE_SCORE_FALSE; | 313 return DM_PROBE_SCORE_FALSE; |
314 } | 314 } |
315 | 315 |
316 | 316 |
317 static int fmtProbeTruePaint(const uint8_t *buf, const size_t len) | 317 static int fmtProbeTruePaint(const Uint8 *buf, const size_t len) |
318 { | 318 { |
319 if (len == 19434 && buf[0] == 0x00 && buf[1] == 0x9c) | 319 if (len == 19434 && buf[0] == 0x00 && buf[1] == 0x9c) |
320 return DM_PROBE_SCORE_GOOD; | 320 return DM_PROBE_SCORE_GOOD; |
321 return DM_PROBE_SCORE_FALSE; | 321 return DM_PROBE_SCORE_FALSE; |
322 } | 322 } |
323 | 323 |
324 | 324 |
325 static BOOL fmtTruePaintSetLaceType(DMC64Image *img, const struct _DMDecodeOp *op, const uint8_t *buf, const size_t len) | 325 static BOOL fmtTruePaintSetLaceType(DMC64Image *img, const struct _DMDecodeOp *op, const Uint8 *buf, const size_t len) |
326 { | 326 { |
327 img->laceType = DM_C64ILACE_RES; | 327 img->laceType = DM_C64ILACE_RES; |
328 img->laceBank2 = 1; | 328 img->laceBank2 = 1; |
329 return TRUE; | 329 return TRUE; |
330 } | 330 } |
426 }; | 426 }; |
427 | 427 |
428 const int ndmC64ImageFormats = sizeof(dmC64ImageFormats) / sizeof(dmC64ImageFormats[0]); | 428 const int ndmC64ImageFormats = sizeof(dmC64ImageFormats) / sizeof(dmC64ImageFormats[0]); |
429 | 429 |
430 | 430 |
431 int dmC64ProbeGeneric(const uint8_t *buf, const size_t len, | 431 int dmC64ProbeGeneric(const Uint8 *buf, const size_t len, |
432 DMC64ImageFormat **pfmt) | 432 DMC64ImageFormat **pfmt) |
433 { | 433 { |
434 int i, scoreMax = 0, scoreIndex = -1; | 434 int i, scoreMax = 0, scoreIndex = -1; |
435 | 435 |
436 for (i = 0; i < ndmC64ImageFormats; i++) | 436 for (i = 0; i < ndmC64ImageFormats; i++) |
452 else | 452 else |
453 return 0; | 453 return 0; |
454 } | 454 } |
455 | 455 |
456 | 456 |
457 int dmC64DecodeGenericBMP(DMC64Image *img, const uint8_t *buf, | 457 int dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf, |
458 const size_t len, const DMC64ImageFormat *fmt) | 458 const size_t len, const DMC64ImageFormat *fmt) |
459 { | 459 { |
460 int i; | 460 int i; |
461 | 461 |
462 memset(img, 0, sizeof(*img)); | 462 memset(img, 0, sizeof(*img)); |
463 img->type = fmt->type; | 463 img->type = fmt->type; |
464 | 464 |
465 for (i = 0; i < fmt->ndecodeOps; i++) | 465 for (i = 0; i < fmt->ndecodeOps; i++) |
466 { | 466 { |
467 const DMDecodeOp *op = &fmt->decodeOps[i]; | 467 const DMDecodeOp *op = &fmt->decodeOps[i]; |
468 const uint8_t *src; | 468 const Uint8 *src; |
469 size_t size; | 469 size_t size; |
470 | 470 |
471 if (op->bank < 0 || op->bank >= C64_SCR_MAX_BANK) | 471 if (op->bank < 0 || op->bank >= C64_SCR_MAX_BANK) |
472 { | 472 { |
473 dmError("Invalid bank %d definition in generic decode operator %d @ #%d.\n", | 473 dmError("Invalid bank %d definition in generic decode operator %d @ #%d.\n", |
522 | 522 |
523 | 523 |
524 static int dmC64ConvertHiResBMP(DMImage *screen, const DMC64Image *img) | 524 static int dmC64ConvertHiResBMP(DMImage *screen, const DMC64Image *img) |
525 { | 525 { |
526 int yc; | 526 int yc; |
527 uint8_t *dp = screen->data; | 527 Uint8 *dp = screen->data; |
528 | 528 |
529 for (yc = 0; yc < C64_SCR_HEIGHT; yc++) | 529 for (yc = 0; yc < C64_SCR_HEIGHT; yc++) |
530 { | 530 { |
531 uint8_t *d = dp; | 531 Uint8 *d = dp; |
532 const int y = yc / 8, yb = yc & 7; | 532 const int y = yc / 8, yb = yc & 7; |
533 const int scroffsy = y * C64_SCR_CH_WIDTH; | 533 const int scroffsy = y * C64_SCR_CH_WIDTH; |
534 const int bmoffsy = y * C64_SCR_WIDTH; | 534 const int bmoffsy = y * C64_SCR_WIDTH; |
535 int xc; | 535 int xc; |
536 | 536 |
538 { | 538 { |
539 const int x = xc / 8; | 539 const int x = xc / 8; |
540 const int scroffs = scroffsy + x; | 540 const int scroffs = scroffsy + x; |
541 const int b = img->bitmap[0][bmoffsy + (x * 8) + yb]; | 541 const int b = img->bitmap[0][bmoffsy + (x * 8) + yb]; |
542 const int v = 7 - (xc & 7); | 542 const int v = 7 - (xc & 7); |
543 uint8_t c; | 543 Uint8 c; |
544 | 544 |
545 if ((b >> v) & 1) | 545 if ((b >> v) & 1) |
546 c = img->screen[0][scroffs] & 15; | 546 c = img->screen[0][scroffs] & 15; |
547 else | 547 else |
548 c = img->screen[0][scroffs] >> 4; | 548 c = img->screen[0][scroffs] >> 4; |
558 | 558 |
559 | 559 |
560 static int dmC64ConvertMultiColorBMP(DMImage *screen, const DMC64Image *img) | 560 static int dmC64ConvertMultiColorBMP(DMImage *screen, const DMC64Image *img) |
561 { | 561 { |
562 int yc; | 562 int yc; |
563 uint8_t *dp = screen->data; | 563 Uint8 *dp = screen->data; |
564 | 564 |
565 for (yc = 0; yc < C64_SCR_HEIGHT; yc++) | 565 for (yc = 0; yc < C64_SCR_HEIGHT; yc++) |
566 { | 566 { |
567 uint8_t *d = dp; | 567 Uint8 *d = dp; |
568 const int y = yc / 8, yb = yc & 7; | 568 const int y = yc / 8, yb = yc & 7; |
569 const int scroffsy = y * C64_SCR_CH_WIDTH; | 569 const int scroffsy = y * C64_SCR_CH_WIDTH; |
570 const int bmoffsy = y * C64_SCR_WIDTH; | 570 const int bmoffsy = y * C64_SCR_WIDTH; |
571 int xc; | 571 int xc; |
572 | 572 |
574 { | 574 { |
575 const int x = xc / 4; | 575 const int x = xc / 4; |
576 const int scroffs = scroffsy + x; | 576 const int scroffs = scroffsy + x; |
577 const int b = img->bitmap[0][bmoffsy + (x * 8) + yb]; | 577 const int b = img->bitmap[0][bmoffsy + (x * 8) + yb]; |
578 const int v = 6 - ((xc * 2) & 6); | 578 const int v = 6 - ((xc * 2) & 6); |
579 uint8_t c; | 579 Uint8 c; |
580 | 580 |
581 switch ((b >> v) & 3) | 581 switch ((b >> v) & 3) |
582 { | 582 { |
583 case 0: c = img->bgcolor; break; | 583 case 0: c = img->bgcolor; break; |
584 case 1: c = img->screen[0][scroffs] >> 4; break; | 584 case 1: c = img->screen[0][scroffs] >> 4; break; |
598 | 598 |
599 | 599 |
600 static int dmC64ConvertLaceMultiColorBMP(DMImage *screen, const DMC64Image *img) | 600 static int dmC64ConvertLaceMultiColorBMP(DMImage *screen, const DMC64Image *img) |
601 { | 601 { |
602 int yc; | 602 int yc; |
603 uint8_t *dp = screen->data; | 603 Uint8 *dp = screen->data; |
604 | 604 |
605 for (yc = 0; yc < C64_SCR_HEIGHT; yc++) | 605 for (yc = 0; yc < C64_SCR_HEIGHT; yc++) |
606 { | 606 { |
607 uint8_t *d = dp; | 607 Uint8 *d = dp; |
608 const int y = yc / 8, yb = yc & 7; | 608 const int y = yc / 8, yb = yc & 7; |
609 const int scroffsy = y * C64_SCR_CH_WIDTH; | 609 const int scroffsy = y * C64_SCR_CH_WIDTH; |
610 const int bmoffsy = y * C64_SCR_WIDTH; | 610 const int bmoffsy = y * C64_SCR_WIDTH; |
611 int xc; | 611 int xc; |
612 | 612 |
616 const int scroffs = scroffsy + x; | 616 const int scroffs = scroffsy + x; |
617 const int bmoffs = bmoffsy + (x * 8) + yb; | 617 const int bmoffs = bmoffsy + (x * 8) + yb; |
618 const int v = 6 - ((xc * 2) & 6); | 618 const int v = 6 - ((xc * 2) & 6); |
619 const int b1 = (img->bitmap[0][bmoffs] >> v) & 3; | 619 const int b1 = (img->bitmap[0][bmoffs] >> v) & 3; |
620 const int b2 = (img->bitmap[1][bmoffs] >> v) & 3; | 620 const int b2 = (img->bitmap[1][bmoffs] >> v) & 3; |
621 uint8_t c1, c2; | 621 Uint8 c1, c2; |
622 | 622 |
623 switch (b1) | 623 switch (b1) |
624 { | 624 { |
625 case 0: c1 = img->bgcolor; break; | 625 case 0: c1 = img->bgcolor; break; |
626 case 1: c1 = img->screen[0][scroffs] >> 4; break; | 626 case 1: c1 = img->screen[0][scroffs] >> 4; break; |
667 | 667 |
668 | 668 |
669 #define BUF_SIZE_INITIAL (16*1024) | 669 #define BUF_SIZE_INITIAL (16*1024) |
670 #define BUF_SIZE_GROW (2*1024) | 670 #define BUF_SIZE_GROW (2*1024) |
671 | 671 |
672 int dmReadDataFile(const char *filename, uint8_t **pbuf, size_t *pbufSize) | 672 int dmReadDataFile(const char *filename, Uint8 **pbuf, size_t *pbufSize) |
673 { | 673 { |
674 FILE *f; | 674 FILE *f; |
675 uint8_t *dataBuf = NULL, *dataPtr; | 675 Uint8 *dataBuf = NULL, *dataPtr; |
676 size_t bufSize, readSize, dataSize; | 676 size_t bufSize, readSize, dataSize; |
677 | 677 |
678 if (filename == NULL) | 678 if (filename == NULL) |
679 f = stdin; | 679 f = stdin; |
680 else | 680 else |