# HG changeset patch # User Matti Hamalainen # Date 1525996168 -10800 # Node ID e967e8e3b8c323953930bf3c83e489fd78f44e6c # Parent c3eba254bcc2177c402499688864386ce094e026 Sanitize dmWriteBitmap(). diff -r c3eba254bcc2 -r e967e8e3b8c3 tools/gfxconv.c --- a/tools/gfxconv.c Fri May 11 02:47:46 2018 +0300 +++ b/tools/gfxconv.c Fri May 11 02:49:28 2018 +0300 @@ -1026,56 +1026,23 @@ } -int dmWriteBitmap(const char *filename, const DMC64Image *image, const DMC64ImageFormat *fmt, const BOOL enableFixUps) +int dmWriteBitmap(const char *filename, const DMC64Image *image) { - FILE *outFile = NULL; - DMGrowBuf buf; int res = DMERR_OK; - - dmMsg(1, "Converting to %s format bitmap.\n", fmt->name); - if (image->type != fmt->type && enableFixUps) - { - // Try to do some simple fixups - if ((fmt->type & D64_FMT_FLI) && (image->type & D64_FMT_FLI) == 0) - { - dmMsg(1, "Upconverting multicolor to FLI.\n"); - int i; - for (i = 1; i < image->nbanks; i++) - { - memcpy(image->color[i], image->color[0], C64_SCR_COLOR_SIZE); - memcpy(image->screen[i], image->screen[0], C64_SCR_SCREEN_SIZE); - } - } - } + const DMC64ImageFormat *fmt = &dmC64ImageFormats[image->type]; + DMGrowBuf buf; - // Encode it! + // Encode to target format + dmMsg(1, "Encoding C64 bitmap data to format '%s'\n", fmt->name); if ((res = dmC64EncodeBMP(&buf, image, fmt)) != DMERR_OK) - { - dmError(res, "Error converting bitmap: %s\n", dmErrorStr(res)); goto error; - } - - dmMsg(2, "Result: %d bytes\n", buf.len); - if ((outFile = fopen(filename, "wb")) == NULL) - { - res = dmGetErrno(); - dmError(res, "Error opening output file '%s', %d: %s\n", - filename, res, dmErrorStr(res)); + // And output the file + dmMsg(1, "Writing output file '%s'\n", filename); + if ((res = dmWriteDataFile(NULL, filename, buf.data, buf.len)) != DMERR_OK) goto error; - } - - if (!dm_fwrite_str(outFile, buf.data, buf.len)) - { - res = dmGetErrno(); - dmError(res, "Error writing image data to '%s', %d: %s\n", - filename, res, dmErrorStr(res)); - } error: - if (outFile != NULL) - fclose(outFile); - dmGrowBufFree(&buf); return res; } @@ -1760,7 +1727,7 @@ break; case FFMT_BITMAP: - res = dmWriteBitmap(optOutFilename, inC64Image, &dmC64ImageFormats[optOutSubFormat], TRUE); + res = dmWriteBitmap(optOutFilename, inC64Image); break; case FFMT_CHAR: