[gimp/gimp-2-10] plug-ins: fix #7566 Import Issues with Indexed .dds Images



commit 778f811e8ae57114f8d845fb6f00aa01310abcc3
Author: Jacob Boerema <jgboerema gmail com>
Date:   Wed Dec 1 15:01:26 2021 -0500

    plug-ins: fix #7566 Import Issues with Indexed .dds Images
    
    This proved to be both an import and export issue.
    Our import set expected format as RGB, causing garbled image output.
    Our export for indexed images converted to grayscale first, although the
    palette was correctly saved. This caused wrong palette indexes on import.
    
    For indexed images, on import, we request the actual indexed format after
    creating the layer with gimp_drawable_get_format, which gives us a correct
    indexed Babl format.
    Also added logic for indexed with alpha, although I have no sample images
    to test this.
    For indexed images on export we do the same: use gimp_drawable_get_format
    to get an actual indexed Babl format.
    
    (cherry picked from commit dec5ca22199103ec3c2f378894b97db637e8c62c)
    
    # Conflicts:
    #       plug-ins/file-dds/ddsread.c

 plug-ins/file-dds/ddsread.c  | 11 +++++++++--
 plug-ins/file-dds/ddswrite.c |  4 +++-
 2 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/plug-ins/file-dds/ddsread.c b/plug-ins/file-dds/ddsread.c
index 2e0de14dbf..beee6814f7 100644
--- a/plug-ins/file-dds/ddsread.c
+++ b/plug-ins/file-dds/ddsread.c
@@ -918,7 +918,6 @@ load_layer (FILE            *fp,
       if (hdr->pixelfmt.flags & DDPF_PALETTEINDEXED8)
         {
           type = GIMP_INDEXED_IMAGE;
-          bablfmt = babl_format ("R'G'B' u8");
         }
       else if (hdr->pixelfmt.rmask == 0xe0)
         {
@@ -937,7 +936,12 @@ load_layer (FILE            *fp,
         }
       break;
     case 2:
-      if (hdr->pixelfmt.amask == 0xf000) /* RGBA4 */
+      if ((hdr->pixelfmt.flags & (DDPF_PALETTEINDEXED8 + DDPF_ALPHA)) ==
+          DDPF_PALETTEINDEXED8 + DDPF_ALPHA)
+        {
+          type = GIMP_INDEXEDA_IMAGE;
+        }
+      else if (hdr->pixelfmt.amask == 0xf000) /* RGBA4 */
         {
           type = GIMP_RGBA_IMAGE;
           bablfmt = babl_format ("R'G'B'A u8");
@@ -971,6 +975,9 @@ load_layer (FILE            *fp,
 
   gimp_image_insert_layer (image, layer, 0, *l);
 
+  if (type == GIMP_INDEXED_IMAGE || type == GIMP_INDEXEDA_IMAGE)
+    bablfmt = gimp_drawable_get_format (GIMP_DRAWABLE (layer));
+
   if ((*l)++) gimp_item_set_visible (layer, FALSE);
 
   buffer = gimp_drawable_get_buffer (layer);
diff --git a/plug-ins/file-dds/ddswrite.c b/plug-ins/file-dds/ddswrite.c
index cf6a3413a2..6631970dc8 100644
--- a/plug-ins/file-dds/ddswrite.c
+++ b/plug-ins/file-dds/ddswrite.c
@@ -887,7 +887,9 @@ write_layer (FILE   *fp,
 
   src = g_malloc (w * h * bpp);
 
-  if (bpp == 1)
+  if (basetype == GIMP_INDEXED)
+    format = gimp_drawable_get_format (drawable);
+  else if (bpp == 1)
     format = babl_format ("Y' u8");
   else if (bpp == 2)
     format = babl_format ("Y'A u8");


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