[gimp/gimp-2-10] plug-ins: fix incorrect dds BC5 images saved by GIMP.



commit c82c995bd31709cb1547c7dc52754c3dd290a764
Author: Jacob Boerema <jgboerema gmail com>
Date:   Tue Jan 5 17:48:35 2021 -0500

    plug-ins: fix incorrect dds BC5 images saved by GIMP.
    
    Since older versions of our GIMP dds file exporter incorrectly
    saved BC5 dds images with the red and green channels
    swapped we should fix that. Since the exporter already
    wrote the plug-ins version number and that it is written by
    GIMP we can check for these incorrect images.
    
    To enable that we increase the plug-ins revision in this
    commit and swap red and green channels for images
    that have an older version number and are of the
    correct type.
    
    (cherry picked from commit a4cc8b707067254558b02841a30697977f2fbf77)
    
    # Conflicts:
    #       plug-ins/file-dds/dds.h

 plug-ins/file-dds/ddsplugin.h |  2 +-
 plug-ins/file-dds/ddsread.c   | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/plug-ins/file-dds/ddsplugin.h b/plug-ins/file-dds/ddsplugin.h
index 67478943b5..257e621cf3 100644
--- a/plug-ins/file-dds/ddsplugin.h
+++ b/plug-ins/file-dds/ddsplugin.h
@@ -23,7 +23,7 @@
 
 #define DDS_PLUGIN_VERSION_MAJOR     3
 #define DDS_PLUGIN_VERSION_MINOR     9
-#define DDS_PLUGIN_VERSION_REVISION  90
+#define DDS_PLUGIN_VERSION_REVISION  91
 
 #define DDS_PLUGIN_VERSION  \
    ((unsigned int)(DDS_PLUGIN_VERSION_MAJOR << 16) | \
diff --git a/plug-ins/file-dds/ddsread.c b/plug-ins/file-dds/ddsread.c
index 4f962df9ec..9d0caa015b 100644
--- a/plug-ins/file-dds/ddsread.c
+++ b/plug-ins/file-dds/ddsread.c
@@ -1129,6 +1129,30 @@ load_layer (FILE            *fp,
       dxt_decompress (dst, buf, format, size, width, height, d->gimp_bpp,
                       hdr->pixelfmt.flags & DDPF_NORMAL);
 
+      if (format == DDS_COMPRESS_BC5 &&
+          hdr->reserved.gimp_dds_special.magic1 == FOURCC ('G','I','M','P') &&
+          hdr->reserved.gimp_dds_special.version > 0 &&
+          hdr->reserved.gimp_dds_special.version <= 199002)
+        {
+          /* GIMP dds plug-in versions before 199002 == 3.9.90 wrote
+           * the red and green channels reversed. We will fix that here.
+           */
+          g_printerr ("Switching incorrect red and green channels in BC5 dds "
+                      "written by an older version of GIMP's dds plug-in.\n");
+
+          for (y = 0; y < height; ++y)
+            for (x = 0; x < width; ++x)
+              {
+                guchar tmpG;
+                guint  pix_width = width * d->gimp_bpp;
+                guint  x_width   = x * d->gimp_bpp;
+
+                tmpG = dst[y * pix_width + x_width];
+                dst[y * pix_width + x_width] = dst[y * pix_width + x_width + 1];
+                dst[y * pix_width + x_width + 1] = tmpG;
+              }
+        }
+
       z = 0;
       for (y = 0, n = 0; y < height; ++y, ++n)
         {


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