# HG changeset patch # User Matti Hamalainen # Date 1558945777 -10800 # Node ID 2129d4ac6f45aed0f7ea1018c1e19f34a1f5a65e # Parent a8f5295ab2e70bb81d96ef172101c12674dbd3fa Refactor c64 image rendering completely to be more flexible. diff -r a8f5295ab2e7 -r 2129d4ac6f45 tools/lib64fmts.c --- a/tools/lib64fmts.c Mon May 27 11:28:19 2019 +0300 +++ b/tools/lib64fmts.c Mon May 27 11:29:37 2019 +0300 @@ -265,6 +265,23 @@ } +static int fmtGetPixelDrazLace(Uint8 *col, + const DMC64Image *img, const int rasterX, const int rasterY) +{ + const int + x = rasterX / 8, + y = rasterY / 8, + yoffs = y * img->fmt->chWidth, + bmoffs = yoffs * 8 + (rasterY & 7) + (x * 8), + scroffs = yoffs + x, + vshift = 6 - (rasterX & 6); + + return dmC64GetGenericMCPixel(col, img, + bmoffs, scroffs, vshift, + 0, rasterX & 1, 0, img->bgcolor); +} + + static const char *fmtBDP5MagicID = "BDP 5.00"; static int fmtProbeBDP5Packed(const DMGrowBuf *buf, const DMC64ImageFormat *fmt) @@ -474,12 +491,13 @@ } -static Uint8 fmtGetPixelFLIDesigner( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) +static int fmtGetPixelFLIDesigner(Uint8 *col, + const DMC64Image *img, const int rasterX, const int rasterY) { - (void) rasterX; - return dmC64GetGenericMCPixel(img, bmoffs, scroffs, shiftX, rasterY & 7, bitmap, 0, img->bgcolor); + DM_C64_GENERIC_MC_PIXEL_DEFS(img) + + //return dmC64GetGenericMCPixel( img, bmoffs, scroffs, vshift, rasterY & 7, bitmap, 0, img->bgcolor); + return dmC64GetGenericMCPixel(col, img, bmoffs, scroffs, vshift, rasterY & 7, 0, 0, img->bgcolor); } @@ -565,17 +583,17 @@ } -static Uint8 fmtGetPixelBlackMailFLI( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) +static int fmtGetPixelBlackMailFLI(Uint8 *col, + const DMC64Image *img, const int rasterX, const int rasterY) { - const int vbank = rasterY & 7; - (void) rasterX; + DM_C64_GENERIC_MC_PIXEL_DEFS(img) - return dmC64GetGenericMCPixel( - img, bmoffs, scroffs, shiftX, - vbank, bitmap, 0, - img->extraData[0].data[rasterY] & 15); + Uint8 bgcol = (unsigned) rasterY < img->extraData[0].size ? + img->extraData[0].data[rasterY] : img->bgcolor; + + return dmC64GetGenericMCPixel(col, img, + bmoffs, scroffs, vshift, rasterY & 7, 0, 0, + bgcol & 15); } @@ -590,13 +608,19 @@ } -static Uint8 fmtGetPixelTruePaint( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) +static int fmtGetPixelTruePaint(Uint8 *col, + const DMC64Image *img, const int rasterX, const int rasterY) { - (void) rasterX; - (void) rasterY; - return dmC64GetGenericMCPixel(img, bmoffs, scroffs, shiftX, 0, bitmap, 0, img->bgcolor); + const int + x = rasterX / 8, + y = rasterY / 8, + yoffs = y * img->fmt->chWidth, + bmoffs = yoffs * 8 + (rasterY & 7) + (x * 8), + scroffs = yoffs + x, + vshift = 6 - (rasterX & 6); + + return dmC64GetGenericMCPixel(col, img, + bmoffs, scroffs, vshift, 0, rasterX & 1, 0, img->bgcolor); } @@ -891,39 +915,46 @@ } -static Uint8 fmtGetPixelFunPaint2( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) +static int fmtGetPixelFunPaint2(Uint8 *col, + const DMC64Image *img, const int rasterX, const int rasterY) { - const int vbank = (rasterY & 7) + (bitmap * 8); - (void) rasterX; + const int + x = rasterX / 8, + y = rasterY / 8, + yb = rasterY & 7, + yoffs = y * img->fmt->chWidth, + bmoffs = yoffs * 8 + yb + (x * 8), + scroffs = yoffs + x, + vshift = 6 - (rasterX & 6), + bitmap = rasterX & 1, + vbank = yb + (bitmap * 8); - return dmC64GetGenericMCPixel( - img, bmoffs, scroffs, shiftX, - vbank, bitmap, 0, - img->extraData[0].data[rasterY] & 15); + Uint8 bgcol = (unsigned) rasterY < img->extraData[0].size ? + img->extraData[0].data[rasterY] : img->bgcolor; + + return dmC64GetGenericMCPixel(col, img, + bmoffs, scroffs, vshift, + vbank, bitmap, 0, bgcol & 15); } -static Uint8 fmtGetPixelBFLI( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) +static int fmtGetPixelBFLI(Uint8 *col, + const DMC64Image *img, const int rasterX, const int rasterY) { + DM_C64_GENERIC_MC_PIXEL_DEFS(img) const int vbb = rasterY < 200 ? 0 : 1; const int vbank = (rasterY & 7) + (vbb * 8); - (void) bitmap; - (void) rasterX; - return dmC64GetGenericMCPixel( + return dmC64GetGenericMCPixel(col, img, bmoffs & 0x1fff, scroffs & 0x3ff, - shiftX, vbank, vbb, 0, img->bgcolor); + vshift, vbank, vbb, 0, img->bgcolor); } -static Uint8 fmtGetPixelPentelPaint( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) +static int fmtGetPixelPentelPaint(Uint8 *col, + const DMC64Image *img, const int rasterX, const int rasterY) { + DM_C64_GENERIC_SC_PIXEL_DEFS(img) const int ry = rasterY / D64_SPR_HEIGHT_PX; const int yd = rasterY % D64_SPR_HEIGHT_PX; const int rx = rasterX / D64_SPR_WIDTH_PX; @@ -931,35 +962,41 @@ const int offs = (ry * 8 + rx) * D64_SPR_SIZE + (yd * D64_SPR_WIDTH_UT) + (xd / 8); const int mask = 1 << (7 - (rasterX & 7)); - Uint8 color1 = dmC64GetGenericSCPixel(img, bmoffs, scroffs, shiftX, 0, bitmap, 0); - Uint8 color2 = img->extraData[0].data[offs] & mask ? 0x0f : 0; - Uint8 color3 = img->extraData[0].data[offs + D64_SPR_SIZE * 155] & mask ? img->d022 : 0; + Uint8 color1, + color2 = img->extraData[0].data[offs] & mask ? 0x0f : 0, + color3 = img->extraData[0].data[offs + D64_SPR_SIZE * 155] & mask ? img->d022 : 0; + + int res; - return color3 ? color3 : ( color2 ? color2 : color1 ); + if ((res = dmC64GetGenericSCPixel(&color1, img, bmoffs, scroffs, vshift, 0, 0)) != DMERR_OK) + return res; + + *col = color3 ? color3 : ( color2 ? color2 : color1 ); + return DMERR_OK; } -static Uint8 fmtGetPixelHCB( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) +static int fmtGetPixelHCB(Uint8 *col, + const DMC64Image *img, const int rasterX, const int rasterY) { + DM_C64_GENERIC_MC_PIXEL_DEFS(img) const int vbank = (rasterY / 4) & 1; - (void) bitmap; - (void) rasterX; + const int ry = rasterY / 5; - return dmC64GetGenericMCPixel( - img, bmoffs, scroffs, - shiftX, vbank, 0, vbank, - img->extraData[0].data[rasterY / 5] & 15); + Uint8 bgcol = (unsigned) ry < img->extraData[0].size ? + img->extraData[0].data[ry] : img->bgcolor; + + return dmC64GetGenericMCPixel(col, img, + bmoffs, scroffs, + vshift, vbank, 0, vbank, bgcol & 15); } -static Uint8 fmtGetPixelCrestHIFLIorCDHM( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) +static int fmtGetPixelCrestHIFLIorCDHM(Uint8 *col, + const DMC64Image *img, const int rasterX, const int rasterY) { - (void) rasterX; - return dmC64GetGenericSCPixel(img, bmoffs, scroffs, shiftX, rasterY & 7, bitmap, 0); + DM_C64_GENERIC_SC_PIXEL_DEFS(img) + return dmC64GetGenericSCPixel(col, img, bmoffs, scroffs, vshift, rasterY & 7, 0); } @@ -974,18 +1011,20 @@ } -static Uint8 fmtGetPixelECI( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) +static int fmtGetPixelECI(Uint8 *col, + const DMC64Image *img, const int rasterX, const int rasterY) { + DM_C64_GENERIC_SC_PIXEL_DEFS(img) const int vbank = rasterY & 7; - Uint8 - c1 = dmC64GetGenericSCPixel(img, bmoffs, scroffs, shiftX, vbank , 0, 0), - c2 = dmC64GetGenericSCPixel(img, bmoffs, scroffs, shiftX, vbank + 8, 1, 0); + Uint8 color1, color2; + int res; - (void) bitmap; - (void) rasterX; - return (c1 * D64_NCOLORS) + c2; + if ((res = dmC64GetGenericSCPixel(&color1, img, bmoffs, scroffs, vshift, vbank , 0)) != DMERR_OK || + (res = dmC64GetGenericSCPixel(&color2, img, bmoffs, scroffs, vshift, vbank + 8, 1)) != DMERR_OK) + return res; + + *col = (color1 * D64_NCOLORS) + color2; + return DMERR_OK; } @@ -1198,7 +1237,7 @@ D64_SCR_CH_WIDTH, D64_SCR_CH_HEIGHT, 1, 1, NULL, NULL, - NULL, + fmtGetPixelDrazLace, { { DO_COPY , DS_COLOR_RAM , 0x0000, 0, 0, 0, NULL, NULL }, { DO_COPY , DS_BITMAP_RAM , 0x0800, 0, 0, 0, NULL, NULL }, diff -r a8f5295ab2e7 -r 2129d4ac6f45 tools/lib64gfx.h --- a/tools/lib64gfx.h Mon May 27 11:28:19 2019 +0300 +++ b/tools/lib64gfx.h Mon May 27 11:29:37 2019 +0300 @@ -202,9 +202,7 @@ typedef DMC64EncDecOp DMC64EncDecOpList[D64_MAX_ENCDEC_OPS]; -typedef Uint8 (*DMC64GetPixelFunc)( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY); +typedef int (*DMC64GetPixelFunc)(Uint8 *col, const DMC64Image *img, const int rasterX, const int rasterY); typedef struct _DMC64ImageCommonFormat @@ -370,51 +368,58 @@ // +// Macros for defining variables used in getpixel functions +// +#define DM_C64_GENERIC_SC_PIXEL_DEFS(ximg) \ + const int \ + x = rasterX / 8, \ + y = rasterY / 8, \ + yoffs = y * ximg->fmt->chWidth, \ + bmoffs = yoffs * 8 + (rasterY & 7) + (x * 8), \ + scroffs = yoffs + x, \ + vshift = 7 - (rasterX & 7); + + +#define DM_C64_GENERIC_MC_PIXEL_DEFS(ximg) \ + const int \ + x = rasterX / 4, \ + y = rasterY / 8, \ + yoffs = y * (ximg)->fmt->chWidth, \ + bmoffs = yoffs * 8 + (rasterY & 7) + (x * 8), \ + scroffs = yoffs + x, \ + vshift = 6 - ((rasterX * 2) & 6); + + +// // Inline helper functions for pixel format decoding // -static inline Uint8 dmC64GetGenericSCPixel( +static inline int dmC64GetGenericSCPixel(Uint8 *col, const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int vbank, const int bitmap, const int cbank) + const int vshift, const int vbank, const int bitmap) { - (void) cbank; - if ((img->bitmap[bitmap].data[bmoffs] >> shiftX) & 1) - return img->screen[vbank].data[scroffs] >> 4; + if ((img->bitmap[bitmap].data[bmoffs] >> vshift) & 1) + *col = img->screen[vbank].data[scroffs] >> 4; else - return img->screen[vbank].data[scroffs] & 15; + *col = img->screen[vbank].data[scroffs] & 15; + + return DMERR_OK; } -static inline Uint8 dmC64GetGenericMCPixel( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int vbank, const int bitmap, const int cbank, const int bgcolor) -{ - switch ((img->bitmap[bitmap].data[bmoffs] >> shiftX) & 3) - { - case 0: return bgcolor; - case 1: return img->screen[vbank].data[scroffs] >> 4; - case 2: return img->screen[vbank].data[scroffs] & 15; - default: return img->color[cbank].data[scroffs] & 15; - } -} - - -static inline Uint8 fmtGetGenericSCPixel( +static inline int dmC64GetGenericMCPixel(Uint8 *col, const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) + const int vshift, const int vbank, const int bitmap, + const int cbank, const int bgcolor) { - (void) rasterX; - (void) rasterY; - return dmC64GetGenericSCPixel(img, bmoffs, scroffs, shiftX, 0, bitmap, 0); -} - + switch ((img->bitmap[bitmap].data[bmoffs] >> vshift) & 3) + { + case 0: *col = bgcolor; break; + case 1: *col = img->screen[vbank].data[scroffs] >> 4; break; + case 2: *col = img->screen[vbank].data[scroffs] & 15; break; + default: *col = img->color[cbank].data[scroffs] & 15; break; + } -static inline Uint8 fmtGetGenericMCPixel( - const DMC64Image *img, const int bmoffs, const int scroffs, - const int shiftX, const int bitmap, const int rasterX, const int rasterY) -{ - (void) rasterX; - (void) rasterY; - return dmC64GetGenericMCPixel(img, bmoffs, scroffs, shiftX, 0, bitmap, 0, img->bgcolor); + return DMERR_OK; }