diff tools/libgfx.c @ 2065:451980580189

Refactor how paletted/indexed formats are handled in libgfx.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Dec 2018 13:33:03 +0200
parents 3617ef01c1de
children 430c010d97c1
line wrap: on
line diff
--- a/tools/libgfx.c	Wed Dec 05 13:31:59 2018 +0200
+++ b/tools/libgfx.c	Wed Dec 05 13:33:03 2018 +0200
@@ -303,7 +303,7 @@
 
 int dmWriteIFFMasterRAWHeader(
     DMResource *fp, const char *filename, const char *prefix,
-    const DMImage *img, const DMImageConvSpec *spec, const int fmtid)
+    const DMImage *img, const DMImageConvSpec *spec)
 {
     if (dmfprintf(fp,
         "%s_width: dw.w %d\n"
@@ -314,7 +314,7 @@
         prefix, spec->nplanes) < 0)
         return dmferror(fp);
 
-    if (fmtid == DM_IMGFMT_ARAW)
+    if (spec->fmtid == DM_IMGFMT_ARAW)
     {
         if (dmfprintf(fp,
             "%s_ncolors: dw.w %d\n"
@@ -999,13 +999,13 @@
     spec.planar = TRUE;
 
     // XXX: 24bit PCX does not work yet ..
-    if (!spec.paletted)
+    if (spec.format != DM_COLFMT_PALETTE)
     {
         return dmError(DMERR_NOT_SUPPORTED,
             "24bit PCX not supported yet.\n");
     }
 
-    if (spec.paletted && img->pal == NULL)
+    if (spec.format == DM_COLFMT_PALETTE && img->pal == NULL)
     {
         return dmError(DMERR_NULLPTR,
             "Image spec says paletted/indexed image, but palette pointer is NULL.\n");
@@ -1018,7 +1018,7 @@
 
     // Create PCX header
     dmMemset(&hdr, 0, sizeof(hdr));
-    if (spec.paletted)
+    if (spec.format == DM_COLFMT_PALETTE)
     {
         const int ncolors = img->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->ncolors;
         for (int i = 0; i < ncolors; i++)
@@ -1055,9 +1055,9 @@
         hdr.hres, hdr.vres,
         hdr.hScreenSize, hdr.vScreenSize);
 
-    dmMsg(2, "PCX: nplanes=%d, bpp=%d, bpl=%d, isPaletted=%s, planar=%s\n",
+    dmMsg(2, "PCX: nplanes=%d, bpp=%d, bpl=%d, colfmt=%d, planar=%s\n",
         hdr.nplanes, hdr.bitsPerPlane, hdr.bpl,
-        spec.paletted ? "yes" : "no",
+        spec.format,
         spec.planar ? "yes" : "no"
         );
 
@@ -1118,7 +1118,7 @@
     res = dmWriteImageData(img, (void *) &pcx, dmWritePCXRow, &spec);
 
     // Write VGA palette
-    if (spec.paletted)
+    if (spec.format == DM_COLFMT_PALETTE)
     {
         int i;
         dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->ncolors);
@@ -2199,22 +2199,22 @@
     Uint8 *buf = NULL;
     size_t bufLen;
     int res = DMERR_OK;
-    //DMImageConvSpec pspec, *spec = &pspec;
-
-    //memcpy(&pspec, cpspec, sizeof(DMImageConvSpec));
 
     // XXX: Non-paletted IFF not supported!
-    if (!spec->paletted)
+    if (spec->format != DM_COLFMT_PALETTE)
     {
         return dmError(DMERR_NOT_SUPPORTED,
             "Non-paletted IFF is not supported.\n");
     }
 
-    switch (spec->format)
+    switch (spec->fmtid)
     {
         case DM_IMGFMT_IFF_ILBM: iff.idsig = IFF_ID_ILBM; iff.idstr = "ILBM"; break;
         case DM_IMGFMT_IFF_PBM : iff.idsig = IFF_ID_PBM; iff.idstr = "PBM"; break;
         case DM_IMGFMT_IFF_ACBM: iff.idsig = IFF_ID_ACBM; iff.idstr = "ACBM"; break;
+        default:
+            return dmError(DMERR_NOT_SUPPORTED,
+                "Invalid IFF format.\n");
     }
 
     // Setup headers
@@ -2277,7 +2277,7 @@
     //
     // CMAP
     //
-    if (img->ncolors > 0 && spec->paletted)
+    if (img->ncolors > 0 && spec->format == DM_COLFMT_PALETTE)
     {
         if ((res = dmWriteIFFChunkHdr(fp, &iff.chCMAP, IFF_ID_CMAP)) != DMERR_OK)
             goto out;