Mercurial > hg > dmlib
changeset 1376:67ae449cf9e1
More work on making various FLI etc. format decoding more flexible.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 24 Sep 2017 17:47:48 +0300 |
parents | f5368c13a872 |
children | e274a7e6dff9 |
files | tools/lib64gfx.c tools/lib64gfx.h tools/view64.c |
diffstat | 3 files changed, 85 insertions(+), 109 deletions(-) [+] |
line wrap: on
line diff
--- a/tools/lib64gfx.c Sun Sep 24 16:01:17 2017 +0300 +++ b/tools/lib64gfx.c Sun Sep 24 17:47:48 2017 +0300 @@ -214,12 +214,47 @@ } -static BOOL fmtSetFLIType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len) +static inline Uint8 dmC64GetGenericSCPixel( + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbank, const int vbitmap, const int cbank) +{ + (void) cbank; + if ((img->bitmap[vbitmap][bmoffs] >> vshift) & 1) + return img->screen[vbank][scroffs] >> 4; + else + return img->screen[vbank][scroffs] & 15; +} + + +static inline Uint8 dmC64GetGenericMCPixel( + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbank, const int vbitmap, const int cbank) { - (void) buf; - (void) len; - img->fliType = op->bank; - return TRUE; + switch ((img->bitmap[vbitmap][bmoffs] >> vshift) & 3) + { + case 0: return img->bgcolor; break; + case 1: return img->screen[vbank][scroffs] >> 4; break; + case 2: return img->screen[vbank][scroffs] & 15; break; + default: return img->color[cbank][scroffs] & 15; break; + } +} + + +static inline Uint8 fmtGetGenericSCPixel( + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbitmap, const int raster) +{ + (void) raster; + return dmC64GetGenericSCPixel(img, bmoffs, scroffs, vshift, 0, vbitmap, 0); +} + + +static inline Uint8 fmtGetGenericMCPixel( + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbitmap, const int raster) +{ + (void) raster; + return dmC64GetGenericMCPixel(img, bmoffs, scroffs, vshift, 0, vbitmap, 0); } @@ -273,7 +308,6 @@ (void) len; img->laceType = buf[op->offs] ? D64_ILACE_RES : D64_ILACE_COLOR; - img->laceBank1 = img->laceBank2 = 0; return TRUE; } @@ -325,12 +359,19 @@ (void) buf; (void) len; img->laceType = D64_ILACE_RES; - img->laceBank1 = 0; - img->laceBank2 = 1; return TRUE; } +static Uint8 fmtGetPixelTruePaint( + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbitmap, const int raster) +{ + (void) raster; + return dmC64GetGenericMCPixel(img, bmoffs, scroffs, vshift, 0, vbitmap, 0); +} + + #define XX2_MIN_SIZE 4000 static int fmtProbeFormatXX2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) @@ -362,6 +403,27 @@ } +static Uint8 fmtGetPixelBMFLI( + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbitmap, const int raster) +{ + const int flibank = raster & 7; + switch ((img->bitmap[vbitmap][bmoffs] >> vshift) & 3) + { + case 0: return img->extraData[0][raster]; break; + case 1: return img->screen[flibank][scroffs] >> 4; break; + case 2: return img->screen[flibank][scroffs] & 15; break; + default: return img->color[0][scroffs] & 15; break; + } +} + + +static Uint8 fmtGetPixelFLIDesigner( + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbitmap, const int raster) +{ + return dmC64GetGenericMCPixel(img, bmoffs, scroffs, vshift, raster & 7, vbitmap, 0); +} // @@ -438,7 +500,7 @@ C64_SCR_WIDTH , C64_SCR_HEIGHT, C64_SCR_CH_WIDTH, C64_SCR_CH_HEIGHT, NULL, NULL, - NULL, NULL, NULL, NULL, + NULL, NULL, NULL, fmtGetPixelTruePaint, { { DT_SCREEN_RAM, 0x0000, 0, 0, NULL, NULL }, { DT_COLOR_REG, 0x03e8, 0, DC_BGCOL, NULL, NULL }, @@ -569,8 +631,9 @@ C64_SCR_WIDTH / 2, C64_SCR_HEIGHT, C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT, NULL, NULL, - NULL, NULL, NULL, NULL, + NULL, NULL, NULL, fmtGetPixelBMFLI, { + { DT_EXTRA_DATA, 0x0000, 0, 200, NULL, NULL }, { DT_COLOR_RAM, 0x0100, 0, 0, NULL, NULL }, { DT_SCREEN_RAM, 0x0500, 0, 0, NULL, NULL }, @@ -584,17 +647,16 @@ { DT_SCREEN_RAM, 0x2100, 7, 0, NULL, NULL }, { DT_BITMAP, 0x2500, 0, 0, NULL, NULL }, - { DT_DEC_FUNCTION, 0x0000, D64_FLI_8BANK, 0, fmtSetFLIType, NULL }, { DT_LAST, 0, 0, 0, NULL, NULL }, } }, { - D64_FMT_MC | D64_FMT_FLI, "fli", "FLI Designer (unpacked)", 0x3c00, 17409, + D64_FMT_MC | D64_FMT_FLI, "fli", "FLI Designer 1 (unpacked)", 0x3c00, 17409, C64_SCR_WIDTH / 2, C64_SCR_HEIGHT, C64_SCR_CH_WIDTH , C64_SCR_CH_HEIGHT, NULL, NULL, - NULL, NULL, NULL, NULL, + NULL, NULL, NULL, fmtGetPixelFLIDesigner, { { DT_COLOR_RAM, 0x0000, 0, 0, NULL, NULL }, { DT_SCREEN_RAM, 0x0400, 0, 0, NULL, NULL }, @@ -606,7 +668,6 @@ { DT_SCREEN_RAM, 0x1c00, 6, 0, NULL, NULL }, { DT_SCREEN_RAM, 0x2000, 7, 0, NULL, NULL }, { DT_BITMAP, 0x2400, 0, 0, NULL, NULL }, - { DT_DEC_FUNCTION, 0x0000, D64_FLI_8BANK, 0, fmtSetFLIType, NULL }, { DT_LAST, 0, 0, 0, NULL, NULL }, } }, @@ -1080,61 +1141,6 @@ } -static inline Uint8 dmC64GetSCPixel( - const DMC64Image *img, const int bmoffs, const int vshift, - const int vbank, const int scroffs, const int raster) -{ - (void) raster; - if ((img->bitmap[vbank][bmoffs] >> vshift) & 1) - return img->screen[vbank][scroffs] >> 4; - else - return img->screen[vbank][scroffs] & 15; -} - - -static inline Uint8 dmC64GetMCColor( - const DMC64Image *img, - const int bits, const int cbank, const int vbank, - const int scroffs, const int raster) -{ - (void) raster; - switch (bits) - { - case 0: return img->bgcolor; break; - case 1: return img->screen[vbank][scroffs] >> 4; break; - case 2: return img->screen[vbank][scroffs] & 15; break; - default: return img->color[cbank][scroffs] & 15; break; - } -} - - -static inline Uint8 dmC64GetMCPixel( - const DMC64Image *img, const int bmoffs, const int vshift, - const int vbank, const int scroffs, const int raster) -{ - if (img->type & D64_FMT_FLI) - { - const int yb = raster & 7; - int vbank = 0; - switch (img->fliType) - { - case D64_FLI_2BANK: - vbank = yb / 4; - break; - case D64_FLI_4BANK: - vbank = yb / 2; - break; - case D64_FLI_8BANK: - vbank = yb; - break; - } - return dmC64GetMCColor(img, (img->bitmap[0][bmoffs] >> vshift) & 3, 0, vbank, scroffs, raster); - } - else - return dmC64GetMCColor(img, (img->bitmap[0][bmoffs] >> vshift) & 3, 0, vbank, scroffs, raster); -} - - // Convert a generic "C64" format bitmap in DMC64Image struct to // a indexed/paletted bitmap image. int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt) @@ -1156,7 +1162,7 @@ if (fmt->getPixel != NULL) getPixel = fmt->getPixel; else - getPixel = (fmt->type & D64_FMT_MC) ? dmC64GetMCPixel : dmC64GetSCPixel; + getPixel = (fmt->type & D64_FMT_MC) ? fmtGetGenericMCPixel : fmtGetGenericSCPixel; // Resolution interlaced pics need to halve the source width int rwidth = src->width; @@ -1248,8 +1254,8 @@ switch (src->laceType) { case D64_ILACE_RES: - *d++ = getPixel(src, bmoffs, vshift, src->laceBank1, scroffs, yc); - *d++ = getPixel(src, bmoffs, vshift, src->laceBank2, scroffs, yc); + *d++ = getPixel(src, bmoffs, scroffs, vshift, 0, yc); + *d++ = getPixel(src, bmoffs, scroffs, vshift, 1, yc); break; default: @@ -1258,7 +1264,7 @@ } else { - *d++ = getPixel(src, bmoffs, vshift, 0, scroffs, yc); + *d++ = getPixel(src, bmoffs, scroffs, vshift, 0, yc); } } }
--- a/tools/lib64gfx.h Sun Sep 24 16:01:17 2017 +0300 +++ b/tools/lib64gfx.h Sun Sep 24 17:47:48 2017 +0300 @@ -64,14 +64,6 @@ }; -// Number of video banks -enum -{ - D64_FLI_2BANK, - D64_FLI_4BANK, - D64_FLI_8BANK, -}; - enum { D64_ILACE_COLOR, @@ -110,10 +102,7 @@ typedef struct _DMC64Image { int type, // Image type (D64_FMT_*) - fliType, // FLI type (if FLI used) - laceType, // Interlace type (D64_ILACE_*) - laceBank1, // Interlace video bank indices - laceBank2; + laceType; // Interlace type (D64_ILACE_*) int width, height; // Width and height in pixels int ch_width, ch_height; // Width and height in charblocks @@ -127,14 +116,14 @@ d020, bgcolor, d022, d023, d024; size_t extraDataSizes[C64_MAX_EXTRA_DATA]; + DMC64Sprite sprites[C64_MAX_SPRITES]; } DMC64Image; typedef Uint8 (*DMC64GetPixelFunc)( - const DMC64Image *img, - const int bits, const int cbank, const int vbank, - const int scroffs, const int raster); + const DMC64Image *img, const int bmoffs, const int scroffs, + const int vshift, const int vbitmap, const int raster); enum {
--- a/tools/view64.c Sun Sep 24 16:01:17 2017 +0300 +++ b/tools/view64.c Sun Sep 24 17:47:48 2017 +0300 @@ -161,26 +161,10 @@ ((img->type & D64_FMT_CHAR) ? " CHAR" : "") ); - dmPrint(0, "Type : %s\n", typeStr); - if (img->type & D64_FMT_FLI) - { - char *tmps; - switch(img->fliType) - { - case D64_FLI_2BANK: tmps = "2 bank"; break; - case D64_FLI_4BANK: tmps = "4 bank"; break; - case D64_FLI_8BANK: tmps = "8 bank"; break; - default: tmps = "ERROR"; break; - } - dmPrint(0, - "FLI type : %s\n", - tmps); - } - if (img->type & D64_FMT_ILACE) { char *tmps; @@ -191,11 +175,8 @@ default: tmps = "ERROR"; break; } dmPrint(0, - "Interlace type : %s\n" - "Interlace banks : %d, %d\n", - tmps, - img->laceBank1, - img->laceBank2); + "Interlace type : %s\n", + tmps); } dmPrint(0,