# HG changeset patch # User Matti Hamalainen # Date 1560726215 -10800 # Node ID 48b48251610a7551fed1d00379d902cc958d6995 # Parent e25fa516b53aed3e1bfb4f790b8b8451222307a8 Refactor how the image "mode/type" is handled. It is still not perfect for our purposes, but better now. diff -r e25fa516b53a -r 48b48251610a tools/64vw.c --- a/tools/64vw.c Mon Jun 17 01:44:54 2019 +0300 +++ b/tools/64vw.c Mon Jun 17 02:03:35 2019 +0300 @@ -224,7 +224,7 @@ bmap.width = surf->w; bmap.height = surf->h; - mixedPalette = (cimage->fmt->type & D64_FMT_ILACE) && + mixedPalette = (cimage->extraInfo[D64_EI_MODE] & D64_FMT_ILACE) && cimage->extraInfo[D64_EI_ILACE_TYPE] == D64_ILACE_COLOR; if ((res = dmC64SetImagePalette(&bmap, spec, mixedPalette)) != DMERR_OK) @@ -310,7 +310,7 @@ { forced = &dmC64ImageFormats[optForcedFormat]; dmMsg(0, "Forced %s format image, type %d, %s\n", - forced->name, forced->format->type, forced->fext); + forced->name, forced->format->mode, forced->fext); } else forced = NULL; diff -r e25fa516b53a -r 48b48251610a tools/gfxconv.c --- a/tools/gfxconv.c Mon Jun 17 01:44:54 2019 +0300 +++ b/tools/gfxconv.c Mon Jun 17 02:03:35 2019 +0300 @@ -1272,19 +1272,20 @@ dst->d024 = src->d024; // Try to do some simple fixups - if ((dst->fmt->type & D64_FMT_MODE_MASK) == D64_FMT_MC && - (src->fmt->type & D64_FMT_MODE_MASK) == D64_FMT_HIRES) + if ((dst->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == D64_FMT_MC && + (src->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == D64_FMT_HIRES) { dmC64MemBlockCopy(&dst->screen[0], &src->screen[0]); } else - if ((dst->fmt->type & D64_FMT_MODE_MASK) == D64_FMT_HIRES && - (src->fmt->type & D64_FMT_MODE_MASK) == D64_FMT_MC) + if ((dst->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == D64_FMT_HIRES && + (src->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == D64_FMT_MC) { // XXX TODO: Handle FLI mc->hires differently? } - if ((dst->fmt->type & D64_FMT_FLI) && (src->fmt->type & D64_FMT_FLI) == 0) + if ((dst->extraInfo[D64_EI_MODE] & D64_FMT_FLI) && + (src->extraInfo[D64_EI_MODE] & D64_FMT_FLI) == 0) { dmMsg(1, "Upconverting multicolor to FLI.\n"); for (int i = 0; i < dst->nblocks; i++) @@ -1300,7 +1301,8 @@ } } else - if ((src->fmt->type & D64_FMT_FLI) && (dst->fmt->type & D64_FMT_FLI) == 0) + if ((src->extraInfo[D64_EI_MODE] & D64_FMT_FLI) && + (dst->extraInfo[D64_EI_MODE] & D64_FMT_FLI) == 0) { dmMsg(1, "Downconverting FLI to multicolor.\n"); } @@ -2102,7 +2104,7 @@ { forced = &dmC64ImageFormats[optForcedInSubFormat]; dmMsg(0, "Forced '%s' format image, type %d, %s\n", - forced->name, forced->format->type, forced->fext); + forced->name, forced->format->mode, forced->fext); } res = dmC64DecodeBMP(&inC64Image, @@ -2112,7 +2114,7 @@ if (forced == NULL && inC64Fmt != NULL && res == DMERR_OK) { dmMsg(1, "Probed '%s' format image, type %d, %s\n", - inC64Fmt->name, inC64Fmt->format->type, inC64Fmt->fext); + inC64Fmt->name, inC64Fmt->format->mode, inC64Fmt->fext); optInType = FFMT_BITMAP; } @@ -2225,7 +2227,7 @@ case FFMT_CHAR: case FFMT_SPRITE: // Set character data if required - if ((inC64Fmt->format->type & D64_FMT_CHAR) && + if ((inC64Image->extraInfo[D64_EI_MODE] & D64_FMT_CHAR) && inC64Image->charData[0].data == NULL) { // Check character ROM filename diff -r e25fa516b53a -r 48b48251610a tools/lib64fmts.c --- a/tools/lib64fmts.c Mon Jun 17 01:44:54 2019 +0300 +++ b/tools/lib64fmts.c Mon Jun 17 02:03:35 2019 +0300 @@ -104,7 +104,7 @@ return DMERR_INVALID_DATA; } - img->extraInfo[D64_EI_CHAR_MODE] = D64_FMT_HIRES; + img->extraInfo[D64_EI_MODE] = D64_FMT_HIRES | D64_FMT_CHAR; img->extraInfo[D64_EI_CHAR_CUSTOM] = 0; return DMERR_OK; @@ -148,13 +148,13 @@ switch (data[0x0028 - 2]) { case 0x00: - img->extraInfo[D64_EI_CHAR_MODE] = D64_FMT_HIRES; + img->extraInfo[D64_EI_MODE] = D64_FMT_HIRES | D64_FMT_CHAR; img->d020 = data[0x001e - 2]; img->bgcolor = data[0x0023 - 2]; break; case 0xd8: - img->extraInfo[D64_EI_CHAR_MODE] = D64_FMT_MC; + img->extraInfo[D64_EI_MODE] = D64_FMT_MC | D64_FMT_CHAR; img->d020 = data[0x001e - 2]; img->bgcolor = data[0x0023 - 2]; img->d022 = data[0x002d - 2]; @@ -162,7 +162,7 @@ break; case 0x01: - img->extraInfo[D64_EI_CHAR_MODE] = D64_FMT_ECM; + img->extraInfo[D64_EI_MODE] = D64_FMT_ECM | D64_FMT_CHAR; img->d020 = data[0x001e - 2]; img->bgcolor = data[0x0023 - 2]; img->d022 = data[0x0028 - 2]; @@ -192,7 +192,7 @@ (void) buf; (void) fmt; - img->extraInfo[D64_EI_CHAR_MODE] = D64_FMT_HIRES; + img->extraInfo[D64_EI_MODE] = D64_FMT_HIRES | D64_FMT_CHAR; img->extraInfo[D64_EI_CHAR_CUSTOM] = 0; return DMERR_OK; @@ -347,7 +347,7 @@ int res; DMGrowBuf tmp; DMCompParams cfg; - const char *magicID = (fmt->format->type & D64_FMT_ILACE) ? "DRAZLACE! 1.0" : "DRAZPAINT 2.0"; + const char *magicID = (fmt->format->mode & D64_FMT_ILACE) ? "DRAZLACE! 1.0" : "DRAZPAINT 2.0"; // Encode the data to temp buffer if ((res = dmC64EncodeGenericBMP(TRUE, &tmp, img, fmt)) != DMERR_OK) diff -r e25fa516b53a -r 48b48251610a tools/lib64gfx.c --- a/tools/lib64gfx.c Mon Jun 17 01:44:54 2019 +0300 +++ b/tools/lib64gfx.c Mon Jun 17 02:03:35 2019 +0300 @@ -241,6 +241,16 @@ } +static void dmC64SetupImageData(DMC64Image *img, const DMC64ImageFormat *fmt) +{ + img->fmt = fmt->format; + img->nblocks = dmC64ImageGetNumBlocks(fmt); + + memset(img->extraInfo, 0, sizeof(img->extraInfo)); + img->extraInfo[D64_EI_MODE] = fmt->format->mode; +} + + DMC64Image *dmC64ImageAlloc(const DMC64ImageFormat *fmt) { DMC64Image *img = dmMalloc0(sizeof(DMC64Image)); @@ -249,8 +259,7 @@ return NULL; // Initialize image information - img->fmt = fmt->format; - img->nblocks = dmC64ImageGetNumBlocks(fmt); + dmC64SetupImageData(img, fmt); // Allocate banks if ((img->color = dmCalloc(img->nblocks, sizeof(DMC64MemBlock))) == NULL || @@ -886,8 +895,8 @@ "Extra data", "Character data", - "d020", - "d021/bgcol", + "d020 / border", + "d021 / background", "d022", "d023", "d024", @@ -944,8 +953,7 @@ if (buf == NULL || buf->data == NULL || img == NULL || fmt == NULL) return DMERR_NULLPTR; - // Clear the image structure, set basics - img->nblocks = dmC64ImageGetNumBlocks(fmt); + dmC64SetupImageData(img, fmt); // Perform decoding for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) @@ -1125,8 +1133,9 @@ } // Sanity check certain things .. - if ((fmt->format->type & D64_FMT_ILACE) && - img->extraInfo[D64_EI_ILACE_TYPE] == D64_ILACE_NONE) { + if ((img->extraInfo[D64_EI_MODE] & D64_FMT_ILACE) && + img->extraInfo[D64_EI_ILACE_TYPE] == D64_ILACE_NONE) + { return dmError(DMERR_INTERNAL, "Format '%s' (%s) has interlace flag set, but interlace type is not set.\n", fmt->name, fmt->fext); @@ -1354,7 +1363,7 @@ img->extraInfo[D64_EI_CHAR_CASE]) chr += 256; // lower case, so add 256 to char ROM offset - switch (img->extraInfo[D64_EI_CHAR_MODE]) + switch (img->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) { case D64_FMT_HIRES: return dmC64GetGenericCharSCPixel( @@ -1379,8 +1388,8 @@ default: return dmError(DMERR_INVALID_DATA, - "Invalid character map image type/fmt=0x%x.\n", - img->fmt->type); + "Invalid character map image mode=0x%x.\n", + img->extraInfo[D64_EI_MODE]); } } @@ -1408,17 +1417,17 @@ if (src->fmt->getPixel != NULL) getPixel = src->fmt->getPixel; else - if (src->fmt->type & D64_FMT_CHAR) + if (src->extraInfo[D64_EI_MODE] & D64_FMT_CHAR) getPixel = fmtGetGenericCharPixel; else - switch (src->fmt->type & D64_FMT_MODE_MASK) + switch (src->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) { case D64_FMT_MC : getPixel = fmtGetGenericMCPixel; break; case D64_FMT_HIRES : getPixel = fmtGetGenericSCPixel; break; default: return dmError(DMERR_INVALID_DATA, "Invalid bitmap image type/fmt=0x%x.\n", - src->fmt->type); + src->extraInfo[D64_EI_MODE]); } // Perform conversion @@ -1452,7 +1461,7 @@ return DMERR_MALLOC; // Set palette information - mixed = (src->fmt->type & D64_FMT_ILACE) && + mixed = (src->extraInfo[D64_EI_MODE] & D64_FMT_ILACE) && src->extraInfo[D64_EI_ILACE_TYPE] == D64_ILACE_COLOR; if ((res = dmC64SetImagePalette(dst, spec, mixed)) != DMERR_OK) @@ -1662,7 +1671,7 @@ *fmta = *(DMC64ImageFormat **) va, *fmtb = *(DMC64ImageFormat **) vb; - int res = fmta->format->type - fmtb->format->type; + int res = fmta->format->mode - fmtb->format->mode; if (res == 0) return strcmp(fmta->name, fmtb->name); else diff -r e25fa516b53a -r 48b48251610a tools/lib64gfx.h --- a/tools/lib64gfx.h Mon Jun 17 01:44:54 2019 +0300 +++ b/tools/lib64gfx.h Mon Jun 17 02:03:35 2019 +0300 @@ -96,8 +96,9 @@ // Various extra settings (see DMC64Image::extraInfo[]) enum { - D64_EI_CHAR_CASE = 0, - D64_EI_CHAR_MODE, + D64_EI_MODE = 0, // Actual mode, if the format supports several + + D64_EI_CHAR_CASE, D64_EI_CHAR_CUSTOM, D64_EI_FLI_TYPE, @@ -253,7 +254,7 @@ typedef struct _DMC64ImageCommonFormat { - int type, // Type flags, see D64_FMT_* + int mode, // Format mode/type flags, see D64_FMT_* width, height, // Width and height in pixels chWidth, chHeight, // Width and height in charblocks aspectX, aspectY; // Pixel aspectX/Y @@ -275,7 +276,7 @@ size_t addr; // Loading address (0 if no loading address) size_t size; // Size, including loading address. Only used in probing and encoding. - int flags; // DM_FMT_* flags, see libgfx.h + int flags; // DM_FMT_* flags (read/write/broken/etc.), see libgfx.h int (*probe)(const DMGrowBuf *buf, const DMC64ImageFormat *fmt); diff -r e25fa516b53a -r 48b48251610a tools/lib64util.c --- a/tools/lib64util.c Mon Jun 17 01:44:54 2019 +0300 +++ b/tools/lib64util.c Mon Jun 17 02:03:35 2019 +0300 @@ -59,7 +59,7 @@ if (img != NULL) { - dmC64GetImageTypeString(typeStr, sizeof(typeStr), img->fmt->type, TRUE); + dmC64GetImageTypeString(typeStr, sizeof(typeStr), img->extraInfo[D64_EI_MODE], TRUE); dmC64ImageDumpLine(fh, indent, "Type", "%s", typeStr); @@ -67,7 +67,7 @@ dmC64ImageDumpLine(fh, indent, "Internal blocks", "%d", img->nblocks); - if (img->fmt->type & D64_FMT_ILACE) + if (img->extraInfo[D64_EI_MODE] & D64_FMT_ILACE) { char *tmps; switch (img->extraInfo[D64_EI_ILACE_TYPE]) @@ -80,7 +80,7 @@ "Interlace type", "%s", tmps); } - if (img->fmt->type & D64_FMT_FLI) + if (img->extraInfo[D64_EI_MODE] & D64_FMT_FLI) { dmC64ImageDumpLine(fh, indent, "FLI type", "%d", @@ -103,9 +103,9 @@ "d021 / background", "%d ($%02x)", img->bgcolor, img->bgcolor); - if (img->fmt->type & D64_FMT_CHAR) + if (img->extraInfo[D64_EI_MODE] & D64_FMT_CHAR) { - if ((img->fmt->type & D64_FMT_MODE_MASK) == (D64_FMT_MC | D64_FMT_ECM)) + if ((img->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == (D64_FMT_MC | D64_FMT_ECM)) { dmC64ImageDumpLine(fh, indent, "d022", "%d ($%02x)", @@ -115,7 +115,7 @@ img->d023, img->d023); } - if ((img->fmt->type & D64_FMT_MODE_MASK) == D64_FMT_ECM) + if ((img->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == D64_FMT_ECM) { dmC64ImageDumpLine(fh, indent, "d024", "%d ($%02x)", @@ -126,7 +126,7 @@ else if (fmt != NULL) { - dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE); + dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->mode, TRUE); dmC64ImageDumpLine(fh, indent, "Type", "%s", typeStr);