Mercurial > hg > dmlib
comparison tools/lib64fmts.c @ 2129:2129d4ac6f45
Refactor c64 image rendering completely to be more flexible.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 27 May 2019 11:29:37 +0300 |
parents | c1a9519a619f |
children | 3b5be00759ed |
comparison
equal
deleted
inserted
replaced
2128:a8f5295ab2e7 | 2129:2129d4ac6f45 |
---|---|
263 buf->data[op->offs] = (img->laceType == D64_ILACE_RES) ? 1 : 0; | 263 buf->data[op->offs] = (img->laceType == D64_ILACE_RES) ? 1 : 0; |
264 return DMERR_OK; | 264 return DMERR_OK; |
265 } | 265 } |
266 | 266 |
267 | 267 |
268 static int fmtGetPixelDrazLace(Uint8 *col, | |
269 const DMC64Image *img, const int rasterX, const int rasterY) | |
270 { | |
271 const int | |
272 x = rasterX / 8, | |
273 y = rasterY / 8, | |
274 yoffs = y * img->fmt->chWidth, | |
275 bmoffs = yoffs * 8 + (rasterY & 7) + (x * 8), | |
276 scroffs = yoffs + x, | |
277 vshift = 6 - (rasterX & 6); | |
278 | |
279 return dmC64GetGenericMCPixel(col, img, | |
280 bmoffs, scroffs, vshift, | |
281 0, rasterX & 1, 0, img->bgcolor); | |
282 } | |
283 | |
284 | |
268 static const char *fmtBDP5MagicID = "BDP 5.00"; | 285 static const char *fmtBDP5MagicID = "BDP 5.00"; |
269 | 286 |
270 static int fmtProbeBDP5Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) | 287 static int fmtProbeBDP5Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
271 { | 288 { |
272 if (buf->len > 20 && | 289 if (buf->len > 20 && |
472 | 489 |
473 return DM_PROBE_SCORE_FALSE; | 490 return DM_PROBE_SCORE_FALSE; |
474 } | 491 } |
475 | 492 |
476 | 493 |
477 static Uint8 fmtGetPixelFLIDesigner( | 494 static int fmtGetPixelFLIDesigner(Uint8 *col, |
478 const DMC64Image *img, const int bmoffs, const int scroffs, | 495 const DMC64Image *img, const int rasterX, const int rasterY) |
479 const int shiftX, const int bitmap, const int rasterX, const int rasterY) | 496 { |
480 { | 497 DM_C64_GENERIC_MC_PIXEL_DEFS(img) |
481 (void) rasterX; | 498 |
482 return dmC64GetGenericMCPixel(img, bmoffs, scroffs, shiftX, rasterY & 7, bitmap, 0, img->bgcolor); | 499 //return dmC64GetGenericMCPixel( img, bmoffs, scroffs, vshift, rasterY & 7, bitmap, 0, img->bgcolor); |
500 return dmC64GetGenericMCPixel(col, img, bmoffs, scroffs, vshift, rasterY & 7, 0, 0, img->bgcolor); | |
483 } | 501 } |
484 | 502 |
485 | 503 |
486 static int fmtProbeBlackMailFLIPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) | 504 static int fmtProbeBlackMailFLIPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
487 { | 505 { |
563 dmGrowBufFree(&tmp2); | 581 dmGrowBufFree(&tmp2); |
564 return res; | 582 return res; |
565 } | 583 } |
566 | 584 |
567 | 585 |
568 static Uint8 fmtGetPixelBlackMailFLI( | 586 static int fmtGetPixelBlackMailFLI(Uint8 *col, |
569 const DMC64Image *img, const int bmoffs, const int scroffs, | 587 const DMC64Image *img, const int rasterX, const int rasterY) |
570 const int shiftX, const int bitmap, const int rasterX, const int rasterY) | 588 { |
571 { | 589 DM_C64_GENERIC_MC_PIXEL_DEFS(img) |
572 const int vbank = rasterY & 7; | 590 |
573 (void) rasterX; | 591 Uint8 bgcol = (unsigned) rasterY < img->extraData[0].size ? |
574 | 592 img->extraData[0].data[rasterY] : img->bgcolor; |
575 return dmC64GetGenericMCPixel( | 593 |
576 img, bmoffs, scroffs, shiftX, | 594 return dmC64GetGenericMCPixel(col, img, |
577 vbank, bitmap, 0, | 595 bmoffs, scroffs, vshift, rasterY & 7, 0, 0, |
578 img->extraData[0].data[rasterY] & 15); | 596 bgcol & 15); |
579 } | 597 } |
580 | 598 |
581 | 599 |
582 static int fmtTruePaintGetLaceType(const DMC64EncDecOp *op, DMC64Image *img, | 600 static int fmtTruePaintGetLaceType(const DMC64EncDecOp *op, DMC64Image *img, |
583 const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt) | 601 const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt) |
588 img->laceType = D64_ILACE_RES; | 606 img->laceType = D64_ILACE_RES; |
589 return DMERR_OK; | 607 return DMERR_OK; |
590 } | 608 } |
591 | 609 |
592 | 610 |
593 static Uint8 fmtGetPixelTruePaint( | 611 static int fmtGetPixelTruePaint(Uint8 *col, |
594 const DMC64Image *img, const int bmoffs, const int scroffs, | 612 const DMC64Image *img, const int rasterX, const int rasterY) |
595 const int shiftX, const int bitmap, const int rasterX, const int rasterY) | 613 { |
596 { | 614 const int |
597 (void) rasterX; | 615 x = rasterX / 8, |
598 (void) rasterY; | 616 y = rasterY / 8, |
599 return dmC64GetGenericMCPixel(img, bmoffs, scroffs, shiftX, 0, bitmap, 0, img->bgcolor); | 617 yoffs = y * img->fmt->chWidth, |
618 bmoffs = yoffs * 8 + (rasterY & 7) + (x * 8), | |
619 scroffs = yoffs + x, | |
620 vshift = 6 - (rasterX & 6); | |
621 | |
622 return dmC64GetGenericMCPixel(col, img, | |
623 bmoffs, scroffs, vshift, 0, rasterX & 1, 0, img->bgcolor); | |
600 } | 624 } |
601 | 625 |
602 | 626 |
603 static int fmtProbeTruePaintPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) | 627 static int fmtProbeTruePaintPacked(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
604 { | 628 { |
889 dmGrowBufFree(&mem); | 913 dmGrowBufFree(&mem); |
890 return res; | 914 return res; |
891 } | 915 } |
892 | 916 |
893 | 917 |
894 static Uint8 fmtGetPixelFunPaint2( | 918 static int fmtGetPixelFunPaint2(Uint8 *col, |
895 const DMC64Image *img, const int bmoffs, const int scroffs, | 919 const DMC64Image *img, const int rasterX, const int rasterY) |
896 const int shiftX, const int bitmap, const int rasterX, const int rasterY) | 920 { |
897 { | 921 const int |
898 const int vbank = (rasterY & 7) + (bitmap * 8); | 922 x = rasterX / 8, |
899 (void) rasterX; | 923 y = rasterY / 8, |
900 | 924 yb = rasterY & 7, |
901 return dmC64GetGenericMCPixel( | 925 yoffs = y * img->fmt->chWidth, |
902 img, bmoffs, scroffs, shiftX, | 926 bmoffs = yoffs * 8 + yb + (x * 8), |
903 vbank, bitmap, 0, | 927 scroffs = yoffs + x, |
904 img->extraData[0].data[rasterY] & 15); | 928 vshift = 6 - (rasterX & 6), |
905 } | 929 bitmap = rasterX & 1, |
906 | 930 vbank = yb + (bitmap * 8); |
907 | 931 |
908 static Uint8 fmtGetPixelBFLI( | 932 Uint8 bgcol = (unsigned) rasterY < img->extraData[0].size ? |
909 const DMC64Image *img, const int bmoffs, const int scroffs, | 933 img->extraData[0].data[rasterY] : img->bgcolor; |
910 const int shiftX, const int bitmap, const int rasterX, const int rasterY) | 934 |
911 { | 935 return dmC64GetGenericMCPixel(col, img, |
936 bmoffs, scroffs, vshift, | |
937 vbank, bitmap, 0, bgcol & 15); | |
938 } | |
939 | |
940 | |
941 static int fmtGetPixelBFLI(Uint8 *col, | |
942 const DMC64Image *img, const int rasterX, const int rasterY) | |
943 { | |
944 DM_C64_GENERIC_MC_PIXEL_DEFS(img) | |
912 const int vbb = rasterY < 200 ? 0 : 1; | 945 const int vbb = rasterY < 200 ? 0 : 1; |
913 const int vbank = (rasterY & 7) + (vbb * 8); | 946 const int vbank = (rasterY & 7) + (vbb * 8); |
914 (void) bitmap; | 947 |
915 (void) rasterX; | 948 return dmC64GetGenericMCPixel(col, |
916 | |
917 return dmC64GetGenericMCPixel( | |
918 img, bmoffs & 0x1fff, scroffs & 0x3ff, | 949 img, bmoffs & 0x1fff, scroffs & 0x3ff, |
919 shiftX, vbank, vbb, 0, img->bgcolor); | 950 vshift, vbank, vbb, 0, img->bgcolor); |
920 } | 951 } |
921 | 952 |
922 | 953 |
923 static Uint8 fmtGetPixelPentelPaint( | 954 static int fmtGetPixelPentelPaint(Uint8 *col, |
924 const DMC64Image *img, const int bmoffs, const int scroffs, | 955 const DMC64Image *img, const int rasterX, const int rasterY) |
925 const int shiftX, const int bitmap, const int rasterX, const int rasterY) | 956 { |
926 { | 957 DM_C64_GENERIC_SC_PIXEL_DEFS(img) |
927 const int ry = rasterY / D64_SPR_HEIGHT_PX; | 958 const int ry = rasterY / D64_SPR_HEIGHT_PX; |
928 const int yd = rasterY % D64_SPR_HEIGHT_PX; | 959 const int yd = rasterY % D64_SPR_HEIGHT_PX; |
929 const int rx = rasterX / D64_SPR_WIDTH_PX; | 960 const int rx = rasterX / D64_SPR_WIDTH_PX; |
930 const int xd = rasterX % D64_SPR_WIDTH_PX; | 961 const int xd = rasterX % D64_SPR_WIDTH_PX; |
931 const int offs = (ry * 8 + rx) * D64_SPR_SIZE + (yd * D64_SPR_WIDTH_UT) + (xd / 8); | 962 const int offs = (ry * 8 + rx) * D64_SPR_SIZE + (yd * D64_SPR_WIDTH_UT) + (xd / 8); |
932 const int mask = 1 << (7 - (rasterX & 7)); | 963 const int mask = 1 << (7 - (rasterX & 7)); |
933 | 964 |
934 Uint8 color1 = dmC64GetGenericSCPixel(img, bmoffs, scroffs, shiftX, 0, bitmap, 0); | 965 Uint8 color1, |
935 Uint8 color2 = img->extraData[0].data[offs] & mask ? 0x0f : 0; | 966 color2 = img->extraData[0].data[offs] & mask ? 0x0f : 0, |
936 Uint8 color3 = img->extraData[0].data[offs + D64_SPR_SIZE * 155] & mask ? img->d022 : 0; | 967 color3 = img->extraData[0].data[offs + D64_SPR_SIZE * 155] & mask ? img->d022 : 0; |
937 | 968 |
938 return color3 ? color3 : ( color2 ? color2 : color1 ); | 969 int res; |
939 } | 970 |
940 | 971 if ((res = dmC64GetGenericSCPixel(&color1, img, bmoffs, scroffs, vshift, 0, 0)) != DMERR_OK) |
941 | 972 return res; |
942 static Uint8 fmtGetPixelHCB( | 973 |
943 const DMC64Image *img, const int bmoffs, const int scroffs, | 974 *col = color3 ? color3 : ( color2 ? color2 : color1 ); |
944 const int shiftX, const int bitmap, const int rasterX, const int rasterY) | 975 return DMERR_OK; |
945 { | 976 } |
977 | |
978 | |
979 static int fmtGetPixelHCB(Uint8 *col, | |
980 const DMC64Image *img, const int rasterX, const int rasterY) | |
981 { | |
982 DM_C64_GENERIC_MC_PIXEL_DEFS(img) | |
946 const int vbank = (rasterY / 4) & 1; | 983 const int vbank = (rasterY / 4) & 1; |
947 (void) bitmap; | 984 const int ry = rasterY / 5; |
948 (void) rasterX; | 985 |
949 | 986 Uint8 bgcol = (unsigned) ry < img->extraData[0].size ? |
950 return dmC64GetGenericMCPixel( | 987 img->extraData[0].data[ry] : img->bgcolor; |
951 img, bmoffs, scroffs, | 988 |
952 shiftX, vbank, 0, vbank, | 989 return dmC64GetGenericMCPixel(col, img, |
953 img->extraData[0].data[rasterY / 5] & 15); | 990 bmoffs, scroffs, |
954 } | 991 vshift, vbank, 0, vbank, bgcol & 15); |
955 | 992 } |
956 | 993 |
957 static Uint8 fmtGetPixelCrestHIFLIorCDHM( | 994 |
958 const DMC64Image *img, const int bmoffs, const int scroffs, | 995 static int fmtGetPixelCrestHIFLIorCDHM(Uint8 *col, |
959 const int shiftX, const int bitmap, const int rasterX, const int rasterY) | 996 const DMC64Image *img, const int rasterX, const int rasterY) |
960 { | 997 { |
961 (void) rasterX; | 998 DM_C64_GENERIC_SC_PIXEL_DEFS(img) |
962 return dmC64GetGenericSCPixel(img, bmoffs, scroffs, shiftX, rasterY & 7, bitmap, 0); | 999 return dmC64GetGenericSCPixel(col, img, bmoffs, scroffs, vshift, rasterY & 7, 0); |
963 } | 1000 } |
964 | 1001 |
965 | 1002 |
966 static int fmtECIGetLaceType(const DMC64EncDecOp *op, DMC64Image *img, | 1003 static int fmtECIGetLaceType(const DMC64EncDecOp *op, DMC64Image *img, |
967 const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt) | 1004 const DMGrowBuf *buf, const DMC64ImageCommonFormat *fmt) |
972 img->laceType = D64_ILACE_COLOR; | 1009 img->laceType = D64_ILACE_COLOR; |
973 return DMERR_OK; | 1010 return DMERR_OK; |
974 } | 1011 } |
975 | 1012 |
976 | 1013 |
977 static Uint8 fmtGetPixelECI( | 1014 static int fmtGetPixelECI(Uint8 *col, |
978 const DMC64Image *img, const int bmoffs, const int scroffs, | 1015 const DMC64Image *img, const int rasterX, const int rasterY) |
979 const int shiftX, const int bitmap, const int rasterX, const int rasterY) | 1016 { |
980 { | 1017 DM_C64_GENERIC_SC_PIXEL_DEFS(img) |
981 const int vbank = rasterY & 7; | 1018 const int vbank = rasterY & 7; |
982 Uint8 | 1019 Uint8 color1, color2; |
983 c1 = dmC64GetGenericSCPixel(img, bmoffs, scroffs, shiftX, vbank , 0, 0), | 1020 int res; |
984 c2 = dmC64GetGenericSCPixel(img, bmoffs, scroffs, shiftX, vbank + 8, 1, 0); | 1021 |
985 | 1022 if ((res = dmC64GetGenericSCPixel(&color1, img, bmoffs, scroffs, vshift, vbank , 0)) != DMERR_OK || |
986 (void) bitmap; | 1023 (res = dmC64GetGenericSCPixel(&color2, img, bmoffs, scroffs, vshift, vbank + 8, 1)) != DMERR_OK) |
987 (void) rasterX; | 1024 return res; |
988 return (c1 * D64_NCOLORS) + c2; | 1025 |
1026 *col = (color1 * D64_NCOLORS) + color2; | |
1027 return DMERR_OK; | |
989 } | 1028 } |
990 | 1029 |
991 | 1030 |
992 static int fmtConvertECIBMP2Image(DMImage *dst, const DMC64Image *src, | 1031 static int fmtConvertECIBMP2Image(DMImage *dst, const DMC64Image *src, |
993 const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec) | 1032 const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec) |
1196 D64_FMT_MC | D64_FMT_ILACE, | 1235 D64_FMT_MC | D64_FMT_ILACE, |
1197 D64_SCR_WIDTH , D64_SCR_HEIGHT, | 1236 D64_SCR_WIDTH , D64_SCR_HEIGHT, |
1198 D64_SCR_CH_WIDTH, D64_SCR_CH_HEIGHT, | 1237 D64_SCR_CH_WIDTH, D64_SCR_CH_HEIGHT, |
1199 1, 1, | 1238 1, 1, |
1200 NULL, NULL, | 1239 NULL, NULL, |
1201 NULL, | 1240 fmtGetPixelDrazLace, |
1202 { | 1241 { |
1203 { DO_COPY , DS_COLOR_RAM , 0x0000, 0, 0, 0, NULL, NULL }, | 1242 { DO_COPY , DS_COLOR_RAM , 0x0000, 0, 0, 0, NULL, NULL }, |
1204 { DO_COPY , DS_BITMAP_RAM , 0x0800, 0, 0, 0, NULL, NULL }, | 1243 { DO_COPY , DS_BITMAP_RAM , 0x0800, 0, 0, 0, NULL, NULL }, |
1205 { DO_COPY , DS_SCREEN_RAM , 0x0400, 0, 0, 0, NULL, NULL }, | 1244 { DO_COPY , DS_SCREEN_RAM , 0x0400, 0, 0, 0, NULL, NULL }, |
1206 { DO_SET_MEM_LO , DS_BGCOL , 0x2740, 0, 0, 0, NULL, NULL }, | 1245 { DO_SET_MEM_LO , DS_BGCOL , 0x2740, 0, 0, 0, NULL, NULL }, |