X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9c1f960facd309385710af076b1f579aad9a28ef..801423ee3454d200581cd51d35fbcdad19f2208a:/src/common/imagtiff.cpp diff --git a/src/common/imagtiff.cpp b/src/common/imagtiff.cpp index 5d8476daec..4994a0ae24 100644 --- a/src/common/imagtiff.cpp +++ b/src/common/imagtiff.cpp @@ -296,13 +296,23 @@ bool wxTIFFHandler::LoadFile( wxImage *image, wxInputStream& stream, bool verbos TIFFGetField( tif, TIFFTAG_IMAGEWIDTH, &w ); TIFFGetField( tif, TIFFTAG_IMAGELENGTH, &h ); + uint16 photometric; + uint16 samplesPerPixel; uint16 extraSamples; uint16* samplesInfo; + TIFFGetFieldDefaulted(tif, TIFFTAG_SAMPLESPERPIXEL, &samplesPerPixel); TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, &extraSamples, &samplesInfo); - const bool hasAlpha = (extraSamples == 1 && - (samplesInfo[0] == EXTRASAMPLE_ASSOCALPHA || - samplesInfo[0] == EXTRASAMPLE_UNASSALPHA)); + if (!TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric)) + { + photometric = PHOTOMETRIC_MINISWHITE; + } + const bool hasAlpha = (extraSamples >= 1 + && ((samplesInfo[0] == EXTRASAMPLE_UNSPECIFIED && samplesPerPixel > 3) + || samplesInfo[0] == EXTRASAMPLE_ASSOCALPHA + || samplesInfo[0] == EXTRASAMPLE_UNASSALPHA)) + || (extraSamples == 0 && samplesPerPixel == 4 + && photometric == PHOTOMETRIC_RGB); // guard against integer overflow during multiplication which could result // in allocating a too small buffer and then overflowing it