Mercurial > hg > dmlib
diff tools/lib64gfx.c @ 1775:4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 12 Jun 2018 17:12:48 +0300 |
parents | 88354355b8e1 |
children | 5ea4713e9e0f |
line wrap: on
line diff
--- a/tools/lib64gfx.c Tue Jun 12 15:36:00 2018 +0300 +++ b/tools/lib64gfx.c Tue Jun 12 17:12:48 2018 +0300 @@ -52,7 +52,7 @@ { char typeStr[64], typeStr2[64]; - dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->type, TRUE); + dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE); if (fmt != NULL) { @@ -89,9 +89,9 @@ "Width x Height : %d x %d [%d x %d]\n" "CHwidth x CHheight : %d x %d [%d x %d]\n", img->width, img->height, - fmt->width, fmt->height, + fmt->format->width, fmt->format->height, img->chWidth, img->chHeight, - fmt->chWidth, fmt->chHeight); + fmt->format->chWidth, fmt->format->chHeight); } else { @@ -100,8 +100,8 @@ "Width x Height : %d x %d\n" "CHwidth x CHheight : %d x %d\n", typeStr, - fmt->width, fmt->height, - fmt->chWidth, fmt->chHeight); + fmt->format->width, fmt->format->height, + fmt->format->chWidth, fmt->format->chHeight); } } @@ -205,11 +205,11 @@ return NULL; // Initialize image information - img->type = fmt->type; - img->width = fmt->width; - img->height = fmt->height; - img->chWidth = fmt->chWidth; - img->chHeight = fmt->chHeight; + img->type = fmt->format->type; + img->width = fmt->format->width; + img->height = fmt->format->height; + img->chWidth = fmt->format->chWidth; + img->chHeight = fmt->format->chHeight; img->nbanks = dmC64ImageGetNumBanks(fmt); // Allocate banks @@ -734,11 +734,11 @@ { case DS_SCREEN_RAM: case DS_COLOR_RAM: - *size = fmt->chHeight * fmt->chWidth; + *size = fmt->format->chHeight * fmt->format->chWidth; break; case DS_BITMAP_RAM: - *size = fmt->chHeight * fmt->chWidth * 8; + *size = fmt->format->chHeight * fmt->format->chWidth * 8; break; case DS_CHAR_DATA: @@ -790,11 +790,11 @@ return DMERR_NULLPTR; // Clear the image structure, set basics - img->type = fmt->type; - img->width = fmt->width; - img->height = fmt->height; - img->chWidth = fmt->chWidth; - img->chHeight = fmt->chHeight; + img->type = fmt->format->type; + img->width = fmt->format->width; + img->height = fmt->format->height; + img->chWidth = fmt->format->chWidth; + img->chHeight = fmt->format->chHeight; img->nbanks = dmC64ImageGetNumBanks(fmt); // Perform decoding @@ -935,7 +935,7 @@ case D64_CHCFG_LINEAR: for (int bank = 0; bank < img->nbanks; bank++) { - for (int offs = 0; offs < fmt->chHeight * fmt->chWidth; offs++) + for (int offs = 0; offs < fmt->format->chHeight * fmt->format->chWidth; offs++) img->screen[bank].data[offs] = offs & 0xff; } break; @@ -968,7 +968,7 @@ } // Sanity check certain things .. - if ((fmt->type & D64_FMT_ILACE) && img->laceType == D64_ILACE_NONE) + if ((fmt->format->type & D64_FMT_ILACE) && img->laceType == D64_ILACE_NONE) { return dmError(DMERR_INTERNAL, "Format '%s' (%s) has interlace flag set, but interlace type is not set.\n", @@ -1178,10 +1178,10 @@ dmMemset(dst->data, 0, dst->size); // Check pixel getter function - if (fmt->getPixel != NULL) - getPixel = fmt->getPixel; + if (fmt->format->getPixel != NULL) + getPixel = fmt->format->getPixel; else - getPixel = (fmt->type & D64_FMT_MC) ? fmtGetGenericMCPixel : fmtGetGenericSCPixel; + getPixel = (fmt->format->type & D64_FMT_MC) ? fmtGetGenericMCPixel : fmtGetGenericSCPixel; // Resolution interlaced pics need to halve the source width int rwidth = src->width; @@ -1313,8 +1313,8 @@ dst->pal = dmDefaultC64Palette; // Convert - if (fmt->convertFrom != NULL) - res = fmt->convertFrom(dst, src, fmt); + if (fmt->format->convertFrom != NULL) + res = fmt->format->convertFrom(dst, src, fmt); else res = dmC64ConvertGenericBMP2Image(dst, src, fmt); @@ -1392,8 +1392,8 @@ return DMERR_MALLOC; // Convert - if (fmt->convertTo != NULL) - res = fmt->convertTo(dst, src, fmt); + if (fmt->format->convertTo != NULL) + res = fmt->format->convertTo(dst, src, fmt); else res = dmC64ConvertGenericImage2BMP(dst, src, fmt); @@ -1474,3 +1474,14 @@ else return DM_PROBE_SCORE_FALSE; } + + +void dmC64InitializeFormats(void) +{ + for (int i = 0; i < ndmC64ImageFormats; i++) + { + DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; + if (fmt->format == NULL) + fmt->format = &fmt->formatDef; + } +}