changeset 1481:e967e8e3b8c3

Sanitize dmWriteBitmap().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 May 2018 02:49:28 +0300
parents c3eba254bcc2
children df6dacb48970
files tools/gfxconv.c
diffstat 1 files changed, 9 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- 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: