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 a4cc8b7070)

# Conflicts:
#	plug-ins/file-dds/dds.h
This commit is contained in:
Jacob Boerema
2021-01-05 17:48:35 -05:00
parent 204c6fa8a5
commit c82c995bd3
2 changed files with 25 additions and 1 deletions

View File

@ -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) | \

View File

@ -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)
{