summaryrefslogtreecommitdiffstats
path: root/kimgio
diff options
context:
space:
mode:
authormio <stigma@disroot.org>2024-09-12 18:30:19 +1000
committerMichele Calgaro <michele.calgaro@yahoo.it>2024-09-15 14:33:00 +0900
commite2732d386688e613c36aa16951b676349efa8d62 (patch)
tree990d47ef5014431f944eb0d048ce8a003c4fae72 /kimgio
parent269661fa811c8efbbf014bf2ce039eeb1313af47 (diff)
downloadtdelibs-e2732d386688e613c36aa16951b676349efa8d62.tar.gz
tdelibs-e2732d386688e613c36aa16951b676349efa8d62.zip
kimgio: Support TIFF transparency
See: https://mirror.git.trinitydesktop.org/gitea/TDE/tdelibs/issues/282 Signed-off-by: mio <stigma@disroot.org> (cherry picked from commit 6adcd877982eeb335361e53da9392aa4bfdbd86c)
Diffstat (limited to 'kimgio')
-rw-r--r--kimgio/tiffr.cpp28
1 files changed, 25 insertions, 3 deletions
diff --git a/kimgio/tiffr.cpp b/kimgio/tiffr.cpp
index 7f7b13ea6..79f890bfe 100644
--- a/kimgio/tiffr.cpp
+++ b/kimgio/tiffr.cpp
@@ -6,6 +6,7 @@
#include <tiffio.h>
+#include <kdebug.h>
#include <tqimage.h>
#include <tqfile.h>
#include <tdelibs_export.h>
@@ -66,6 +67,9 @@ TDE_EXPORT void kimgio_tiff_read( TQImageIO *io )
uint32 width, height;
uint32 *data;
+ uint16_t extra_samples_count;
+ uint16_t *extra_samples;
+
// FIXME: use qdatastream
// open file
@@ -79,9 +83,12 @@ TDE_EXPORT void kimgio_tiff_read( TQImageIO *io )
}
// create image with loaded dimensions
- if( TIFFGetField( tiff, TIFFTAG_IMAGEWIDTH, &width ) != 1
- || TIFFGetField( tiff, TIFFTAG_IMAGELENGTH, &height ) != 1 )
- return;
+ if ((TIFFGetField(tiff, TIFFTAG_IMAGEWIDTH, &width) != 1) ||
+ (TIFFGetField(tiff, TIFFTAG_IMAGELENGTH, &height) != 1))
+ {
+ TIFFClose(tiff);
+ return;
+ }
TQImage image( width, height, 32 );
if( image.isNull()) {
@@ -128,6 +135,21 @@ TDE_EXPORT void kimgio_tiff_read( TQImageIO *io )
// swap rows
}
+ // Extra Samples
+ if (TIFFGetField(tiff, TIFFTAG_EXTRASAMPLES, &extra_samples_count, &extra_samples) == 1)
+ {
+ kdDebug(399) << "TIFF image has " << extra_samples_count << " extra sample(s)." << endl;
+ for (uint16_t i = 0; i < extra_samples_count; i++)
+ {
+ if ((extra_samples[i] == EXTRASAMPLE_ASSOCALPHA) ||
+ (extra_samples[i] == EXTRASAMPLE_UNASSALPHA))
+ {
+ image.setAlphaBuffer(true);
+ break;
+ }
+ }
+ }
+
// set channel order to Qt order
// FIXME: Right now they are the same, but will it change?