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



commit a4cc8b707067254558b02841a30697977f2fbf77
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.

 plug-ins/file-dds/dds.h     |  2 +-
 plug-ins/file-dds/ddsread.c | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)
---
diff --git a/plug-ins/file-dds/dds.h b/plug-ins/file-dds/dds.h
index ef65ea0776..89bbe90890 100644
--- a/plug-ins/file-dds/dds.h
+++ b/plug-ins/file-dds/dds.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 \
    ((guint) (DDS_PLUGIN_VERSION_MAJOR << 16) | \
diff --git a/plug-ins/file-dds/ddsread.c b/plug-ins/file-dds/ddsread.c
index e4df9d81c4..9687ef9447 100644
--- a/plug-ins/file-dds/ddsread.c
+++ b/plug-ins/file-dds/ddsread.c
@@ -1211,6 +1211,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]