]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/imagtiff.cpp
reverting part of r58797, otherwise wxClientDC get no graphics context at all
[wxWidgets.git] / src / common / imagtiff.cpp
index 5a5c6cb5f991c9e9d0dbb1f50ac671a9bc014022..4994a0ae2450acd16b95d2f03b6d0d76f81b4993 100644 (file)
@@ -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
@@ -635,7 +645,7 @@ bool wxTIFFHandler::DoCanRead( wxInputStream& stream )
         micro;
 
     const wxString ver(::TIFFGetVersion());
-    if ( wxSscanf(ver, "LIBTIFF, Version %d.%d.%d", &major, &micro, &micro) != 3 )
+    if ( wxSscanf(ver, "LIBTIFF, Version %d.%d.%d", &major, &minor, &micro) != 3 )
     {
         wxLogDebug("Unrecognized libtiff version string \"%s\"", ver);