Mercurial > hg > dmlib
diff tools/lib64gfx.c @ 2265:48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
our purposes, but better now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 17 Jun 2019 02:03:35 +0300 |
parents | 5db6e0b63b35 |
children | cd266022e4a8 |
line wrap: on
line diff
--- 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