[gimp] Issue #2997 - Error importing PCX



commit 11defa4271d518f1233972a86505037a4d8f6287
Author: Ell <ell_se yahoo com>
Date:   Fri Feb 22 11:51:30 2019 -0500

    Issue #2997 - Error importing PCX
    
    Commit dc069e424ab0c38c3f4ed0d91630a4d3768ae457 removed the
    assumption that 1-bpp PCX files are B&W, in favor of using the
    provided palette, which is (supposedly?) the correct behavior.
    However, there are evidently B&W files that do not specify a
    palette, resulting in an all-black image (i.e., a 2-color indexed
    image, whose both palette entries are black).  Since other
    software, including older versions of GIMP, load such files
    "correctly", let's fix this by falling back to a B&W palette when
    the provded palette is uniform.

 plug-ins/common/file-pcx.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/plug-ins/common/file-pcx.c b/plug-ins/common/file-pcx.c
index f21bdf3b41..9d5d9d992b 100644
--- a/plug-ins/common/file-pcx.c
+++ b/plug-ins/common/file-pcx.c
@@ -469,6 +469,7 @@ load_image (const gchar  *filename,
 
   if (pcx_header.planes == 1 && pcx_header.bpp == 1)
     {
+      const guint8 *colormap = pcx_header.colormap;
       dest = g_new (guchar, ((gsize) width) * height);
       load_1 (fd, width, height, dest, bytesperline);
       /* Monochrome does not mean necessarily B&W. Therefore we still
@@ -481,7 +482,20 @@ load_image (const gchar  *filename,
        * find counter-examples.
        * See bug 159947, comment 21 and 23.
        */
-      gimp_image_set_colormap (image, pcx_header.colormap, 2);
+      /* ... Actually, there *are* files out there with a zeroed 1-bit palette,
+       * which are supposed to be displayed as B&W (see issue #2997.)  These
+       * files *might* be in the wrong (who knows...) but the fact is that
+       * other software, including older versions of GIMP, do display them
+       * "correctly", so let's follow suit: if the two palette colors are
+       * equal, use a B&W palette instead.
+       */
+      if (! memcmp (colormap, colormap + 3, 3))
+        {
+          static const guint8 bw_colormap[6] = {  0,   0,   0,
+                                                255, 255, 255};
+          colormap = bw_colormap;
+        }
+      gimp_image_set_colormap (image, colormap, 2);
     }
   else if (pcx_header.bpp == 1 && pcx_header.planes == 2)
     {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]