changeset 1296:228cab109c6a

More work on PCX reader.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 19 Aug 2017 01:32:46 +0300
parents 7a986f33895e
children 5bd64397453b
files src/libgfx.c
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/libgfx.c	Fri Aug 18 23:11:08 2017 +0300
+++ b/src/libgfx.c	Sat Aug 19 01:32:46 2017 +0300
@@ -1171,10 +1171,13 @@
                 "PCX: Error decoding RLE compressed data.\n");
             goto error;
         }
-
+        
         // Decode bitplanes
         switch (hdr.bitsPerPlane)
         {
+            case 32:
+            case 24:
+            case 16:
             case 8:
                 {
                     // Actually bytes and bits per plane per pixel ..
@@ -1190,17 +1193,21 @@
                 }
                 break;
 
-/*
             case 1:
+                memset(dp, 0, img->width);
+
                 for (int nplane = 0; nplane < hdr.nplanes; nplane++)
                 {
-                    Uint8 *dptr = dp,
-                          *sptr = pcx.buf + (hdr.bpl * nplane);
+                    Uint8 *sptr = pcx.buf + (hdr.bpl * nplane);
 
                     for (int xc = 0; xc < img->width; xc++)
+                    {
+                        const int qx = xc * 2;
+                        const int px = 7 - (qx & 7);
+                        dp[xc] |= (sptr[qx / 8] & (1 << px)) >> (px - nplane);
+                    }
                 }
                 break;
-*/
 
             default:
                 res = dmError(DMERR_NOT_SUPPORTED,
@@ -1222,7 +1229,7 @@
         if (!dm_fread_byte(fp, &tmpb) || tmpb != 0x0C)
         {
             read = FALSE;
-            ncolors = DMPCX_PAL_COLORS;
+            ncolors = 256; // KLUDGE
         }
         else
         {
@@ -1240,6 +1247,7 @@
         if (read)
         {
             // Okay, attempt to read the palette data
+            dmMsg(2, "PCX: Reading palette of %d colors\n", ncolors);
             if (!dmReadPaletteData(fp, img->pal, ncolors))
             {
                 res = dmError(DMERR_FREAD,
@@ -1251,6 +1259,7 @@
         {
             // If the extra palette is not available, copy the colors from
             // the header palette to our internal palette structure.
+            dmMsg(2, "PCX: Initializing palette from header of %d colors\n", ncolors);
             for (int i = 0; i < (img->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->ncolors); i++)
             {
                 img->pal[i].r = hdr.colorMap[i].r;