# HG changeset patch # User Matti Hamalainen # Date 1530195990 -10800 # Node ID 410679d2fe8ac52d8d8a1b6c20c0e02501467b2f # Parent c048da352279f29dc580f9a44e59d30f9330dedb "Enable" the image->c64 bitmap conversion path in gfxconv. It does not work without the necessary bits elsewhere, though. Also add DMC64ImageConvSpec structure for delivering conversion parameters, though it is not yet used either. diff -r c048da352279 -r 410679d2fe8a tools/64vw.c --- a/tools/64vw.c Thu Jun 28 14:49:52 2018 +0300 +++ b/tools/64vw.c Thu Jun 28 17:26:30 2018 +0300 @@ -208,7 +208,8 @@ } -int dmDecodeC64Image(const DMC64Image *cimage, const DMC64ImageFormat *fmt, SDL_Surface *surf) +int dmDecodeC64Image(const DMC64Image *cimage, const DMC64ImageFormat *fmt, + SDL_Surface *surf, const DMC64ImageConvSpec *spec) { DMImage bmap; int ret; @@ -224,9 +225,9 @@ bmap.pal = dmDefaultC64Palette; if (fmt->format->convertFrom != NULL) - ret = fmt->format->convertFrom(&bmap, cimage, fmt); + ret = fmt->format->convertFrom(&bmap, cimage, fmt, spec); else - ret = dmC64ConvertGenericBMP2Image(&bmap, cimage, fmt); + ret = dmC64ConvertGenericBMP2Image(&bmap, cimage, fmt, spec); SDL_SetPaletteColors(surf->format->palette, (SDL_Color *) bmap.pal, 0, bmap.ncolors); @@ -236,17 +237,19 @@ int main(int argc, char *argv[]) { + const DMC64ImageFormat *forced; + DMC64ImageConvSpec spec; SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; SDL_Texture *texture = NULL; SDL_Surface *surf = NULL; BOOL initSDL = FALSE, exitFlag, needRedraw; - const DMC64ImageFormat *forced; size_t currIndex, prevIndex; int ret; dmC64InitializeFormats(); dmSetScaleFactor(2.0); + memset(&spec, 0, sizeof(spec)); dmInitProg("64vw", "Display some C64 bitmap graphics formats", "0.4", NULL, NULL); @@ -468,7 +471,7 @@ goto exit; } - if (dmDecodeC64Image(cimage, fmt, surf) == DMERR_OK) + if (dmDecodeC64Image(cimage, fmt, surf, &spec) == DMERR_OK) { title = dm_strdup_printf("%s - [%d / %d] %s (%dx%d @ %s)", dmProgName, diff -r c048da352279 -r 410679d2fe8a tools/gfxconv.c --- a/tools/gfxconv.c Thu Jun 28 14:49:52 2018 +0300 +++ b/tools/gfxconv.c Thu Jun 28 17:26:30 2018 +0300 @@ -1786,6 +1786,7 @@ int main(int argc, char *argv[]) { FILE *inFile = NULL; + DMC64ImageConvSpec imageSpecC64; const DMC64ImageFormat *inC64Fmt = NULL; DMConvFormat inFormat, outFormat; DMC64Image *inC64Image = NULL, *outC64Image = NULL; @@ -1797,6 +1798,9 @@ for (i = 0; i < C64_NCOLORS; i++) optColorMap[i] = i; + // Initialize c64 image conversion spec + memset(&imageSpecC64, 0, sizeof(imageSpecC64)); + // Initialize list of additional conversion formats dmC64InitializeFormats(); nconvFormatList = ndmImageFormatList + nbaseFormatList; @@ -1983,7 +1987,7 @@ case FFMT_IMAGE: case FFMT_CHAR: case FFMT_SPRITE: - res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt); + res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt, &imageSpecC64); if (res != DMERR_OK || outImage == NULL) { @@ -2069,7 +2073,36 @@ case FFMT_CHAR: case FFMT_SPRITE: - res = dmWriteSpritesAndChars(optOutFilename, inImage, optOutType, optInMulticolor); + res = dmWriteSpritesAndChars(optOutFilename, inImage, + optOutType, optInMulticolor); + break; + + case FFMT_BITMAP: + { + DMC64Image *tmpC64Image = NULL; + res = dmC64ConvertImage2BMP(&tmpC64Image, inImage, + &dmC64ImageFormats[optOutFormat], &imageSpecC64); + + if (res != DMERR_OK || tmpC64Image == NULL) + { + dmC64ImageFree(tmpC64Image); + dmErrorMsg("Error in image to bitmap conversion: %s\n", + dmErrorStr(res)); + goto error; + } + + if ((res = dmConvertC64Bitmap(&outC64Image, tmpC64Image, + &dmC64ImageFormats[optOutFormat], &dmC64ImageFormats[optOutFormat])) != DMERR_OK) + { + dmC64ImageFree(tmpC64Image); + dmErrorMsg("Error in bitmap format conversion: %s\n", + dmErrorStr(res)); + goto error; + } + + res = dmWriteBitmap(optOutFilename, outC64Image, &dmC64ImageFormats[optOutFormat]); + dmC64ImageFree(tmpC64Image); + } break; default: diff -r c048da352279 -r 410679d2fe8a tools/lib64fmts.c --- a/tools/lib64fmts.c Thu Jun 28 14:49:52 2018 +0300 +++ b/tools/lib64fmts.c Thu Jun 28 17:26:30 2018 +0300 @@ -930,12 +930,13 @@ } -static int fmtConvertECIBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt) +static int fmtConvertECIBMP2Image(DMImage *dst, const DMC64Image *src, + const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec) { if (!dmSetMixedColorC64Palette(dst)) return DMERR_MALLOC; - return dmC64ConvertGenericBMP2Image(dst, src, fmt); + return dmC64ConvertGenericBMP2Image(dst, src, fmt, spec); } diff -r c048da352279 -r 410679d2fe8a tools/lib64gfx.c --- a/tools/lib64gfx.c Thu Jun 28 14:49:52 2018 +0300 +++ b/tools/lib64gfx.c Thu Jun 28 17:26:30 2018 +0300 @@ -1230,12 +1230,13 @@ // 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) +int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, + const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec) { DMC64GetPixelFunc getPixel; // Sanity check arguments - if (dst == NULL || src == NULL) + if (dst == NULL || src == NULL || fmt == NULL || spec == NULL) return DMERR_NULLPTR; if (dst->width < src->width || dst->height < src->height) @@ -1358,12 +1359,13 @@ } -int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt) +int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, + const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec) { int res; DMImage *dst; - if (pdst == NULL || src == NULL) + if (pdst == NULL || src == NULL || fmt == NULL || spec == NULL) return DMERR_NULLPTR; // Allocate image structure @@ -1377,9 +1379,9 @@ // Convert if (fmt->format->convertFrom != NULL) - res = fmt->format->convertFrom(dst, src, fmt); + res = fmt->format->convertFrom(dst, src, fmt, spec); else - res = dmC64ConvertGenericBMP2Image(dst, src, fmt); + res = dmC64ConvertGenericBMP2Image(dst, src, fmt, spec); return res; } @@ -1433,16 +1435,18 @@ // Convert a generic bitmap image to DMC64Image -int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, const DMC64ImageFormat *fmt) +int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, + const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec) { - if (dst == NULL || src == NULL || fmt == NULL) + if (dst == NULL || src == NULL || fmt == NULL || spec == NULL) return DMERR_NULLPTR; return DMERR_OK; } -int dmC64ConvertImage2BMP(DMC64Image **pdst, const DMImage *src, const DMC64ImageFormat *fmt) +int dmC64ConvertImage2BMP(DMC64Image **pdst, const DMImage *src, + const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec) { int res; DMC64Image *dst; @@ -1456,9 +1460,9 @@ // Convert if (fmt->format->convertTo != NULL) - res = fmt->format->convertTo(dst, src, fmt); + res = fmt->format->convertTo(dst, src, fmt, spec); else - res = dmC64ConvertGenericImage2BMP(dst, src, fmt); + res = dmC64ConvertGenericImage2BMP(dst, src, fmt, spec); return res; } diff -r c048da352279 -r 410679d2fe8a tools/lib64gfx.h --- a/tools/lib64gfx.h Thu Jun 28 14:49:52 2018 +0300 +++ b/tools/lib64gfx.h Thu Jun 28 17:26:30 2018 +0300 @@ -78,6 +78,13 @@ }; +// Image <-> bitmap conversion dithering +enum +{ + D64_DITH_NONE = 0, // No dithering +}; + + // Different enc/dec operation types (op->type) enum { @@ -118,6 +125,13 @@ typedef struct { + int dither; // Dither mode (D64_DITH_*) + BOOL aspect; // Correct pixel aspect ratio? +} DMC64ImageConvSpec; + + +typedef struct +{ Uint8 *data; size_t size; } DMC64MemBlock; @@ -193,8 +207,8 @@ int width, height; // Width and height in pixels int chWidth, chHeight; // Width and height in charblocks - int (*convertFrom)(DMImage *, const DMC64Image *, const DMC64ImageFormat *fmt); - int (*convertTo)(DMC64Image *, const DMImage *, const DMC64ImageFormat *fmt); + int (*convertFrom)(DMImage *, const DMC64Image *, const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec); + int (*convertTo)(DMC64Image *, const DMImage *, const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec); DMC64GetPixelFunc getPixel; @@ -323,14 +337,14 @@ int dmC64DecodeGenericBMP(DMC64Image *img, const DMGrowBuf *buf, const DMC64ImageFormat *fmt); int dmC64EncodeGenericBMP(const BOOL allocate, DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt); -int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt); -int dmC64ConvertImage2BMP(DMC64Image **pdst, const DMImage *src, const DMC64ImageFormat *fmt); +int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec); +int dmC64ConvertImage2BMP(DMC64Image **pdst, const DMImage *src, const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec); int dmC64DecodeBMP(DMC64Image **img, const DMGrowBuf *buf, const size_t probeOffs, const size_t loadOffs, const DMC64ImageFormat **fmt, const DMC64ImageFormat *forced); int dmC64EncodeBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt); -int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt); -int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, const DMC64ImageFormat *fmt); +int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec); +int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec); void dmGenericRLEAnalyze(const DMGrowBuf *buf, DMCompParams *cfg);