diff tools/lib64gfx.c @ 2094:4276b8c0fef0

Revamp how the DMImage palette system and color formats work, as preparation for future work on supporting non-indexed/paletted images. It is still messy.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Mar 2019 09:56:47 +0200
parents 221a95caa91e
children 5f8f170f8774
line wrap: on
line diff
--- a/tools/lib64gfx.c	Thu Feb 28 12:32:07 2019 +0200
+++ b/tools/lib64gfx.c	Tue Mar 05 09:56:47 2019 +0200
@@ -108,19 +108,23 @@
 }
 
 
-void dmSetDefaultC64Palette(DMImage *img)
+int dmSetDefaultC64Palette(DMImage *img)
 {
-    img->constpal = TRUE;
-    img->pal      = dmDefaultC64Palette;
-    img->ncolors  = C64_NCOLORS;
-    img->ctransp  = 255;
+    int res;
+    if ((res = dmPaletteAlloc(&(img->pal), C64_NCOLORS, 255)) != DMERR_OK)
+        return res;
+
+    memcpy(img->pal->colors, dmDefaultC64Palette, img->pal->ncolors * sizeof(DMColor));
+
+    return DMERR_OK;
 }
 
 
-BOOL dmSetMixedColorC64Palette(DMImage *img)
+int dmSetMixedColorC64Palette(DMImage *img)
 {
-    if (!dmImagePaletteAlloc(img, C64_NCOLORS * C64_NCOLORS, -1))
-        return FALSE;
+    int res;
+    if ((res = dmPaletteAlloc(&(img->pal), C64_NCOLORS * C64_NCOLORS, -1)) != DMERR_OK)
+        return res;
 
     int n = 0;
     for (int n1 = 0; n1 < C64_NCOLORS; n1++)
@@ -129,14 +133,14 @@
         for (int n2 = 0; n2 < C64_NCOLORS; n2++)
         {
             const DMColor *col2 = &dmDefaultC64Palette[n2];
-            img->pal[n].r = (col1->r + col2->r) / 2;
-            img->pal[n].g = (col1->g + col2->g) / 2;
-            img->pal[n].b = (col1->b + col2->b) / 2;
+            img->pal->colors[n].r = (col1->r + col2->r) / 2;
+            img->pal->colors[n].g = (col1->g + col2->g) / 2;
+            img->pal->colors[n].b = (col1->b + col2->b) / 2;
             n++;
         }
     }
 
-    return TRUE;
+    return DMERR_OK;
 }
 
 
@@ -1401,9 +1405,8 @@
         return DMERR_MALLOC;
 
     // Set partial palette information
-    dst->ncolors  = C64_NCOLORS;
-    dst->constpal = TRUE;
-    dst->pal      = dmDefaultC64Palette;
+    if ((res = dmSetDefaultC64Palette(dst)) != DMERR_OK)
+        return res;
 
     // Convert
     if (fmt->format->convertFrom != NULL)