vcl/source/filter/itiff/itiff.cxx |    7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

New commits:
commit bd1d0967920655ef85a2352259332f99fef6876e
Author:     Julien Nabet <serval2...@yahoo.fr>
AuthorDate: Thu Apr 21 11:54:49 2022 +0200
Commit:     Julien Nabet <serval2...@yahoo.fr>
CommitDate: Thu Apr 28 12:40:21 2022 +0200

    tdf#74331: 16bit "min-is-black" tiff not loaded correctly
    
    Since 16 bits part is well taken into account for photometric 
interpretation "RGB",
    just consider greyscale as subcase of rgb since greys are just "RGB" colors 
with same value for red, green and blue
    Finally, in ConvertScanline, nPhotometricInterpretation <= 1 (so "min is 
white" and "min is black") with nSamplesPerPixel = 1
    corresponds to nDstBitsPerPixel = 8 here, so consider this specific case in 
the same block.
    
    The last piece to adjust is when calling SetPixel:
    nPhotometricInterpretation = 1 corresponds to the same case as 
nPhotometricInterpretation = 2
    since RGB black is 0, nPhotometricInterpretation = 1 is minisblack so here 
too black is 0
    
    Change-Id: I5c8e420f851ed6e31998c0698d86300aaa7c4b19
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133251
    Tested-by: Jenkins
    Reviewed-by: Julien Nabet <serval2...@yahoo.fr>

diff --git a/vcl/source/filter/itiff/itiff.cxx 
b/vcl/source/filter/itiff/itiff.cxx
index 7fa66b746c5d..c9f73a742875 100644
--- a/vcl/source/filter/itiff/itiff.cxx
+++ b/vcl/source/filter/itiff/itiff.cxx
@@ -859,7 +859,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
     sal_uInt32  nRed, nGreen, nBlue, ns, nVal;
     sal_uInt8   nByteVal;
 
-    if ( nDstBitsPerPixel == 24 )
+    if ( nDstBitsPerPixel == 24 || (nDstBitsPerPixel == 8 && 
nPhotometricInterpretation <= 1 && nSamplesPerPixel == 1) )
     {
         if ( nBitsPerSample == 8 && nSamplesPerPixel >= 3 &&
              nPlanes == 1 && nPhotometricInterpretation == 2 )
@@ -904,7 +904,8 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
         }
         else if (
                ( nPhotometricInterpretation == 2 && nSamplesPerPixel >= 3 ) ||
-               ( nPhotometricInterpretation == 5 && nSamplesPerPixel == 3 )
+               ( nPhotometricInterpretation == 5 && nSamplesPerPixel == 3 ) ||
+               ( nPhotometricInterpretation <= 1 && nSamplesPerPixel == 1 )
         )
         {
             if ( nMaxSampleValue > nMinSampleValue )
@@ -924,7 +925,7 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
                         nGreen = GetBits( getMapData(1), nx * nBitsPerSample, 
nBitsPerSample );
                         nBlue = GetBits( getMapData(2), nx * nBitsPerSample, 
nBitsPerSample );
                     }
-                    if (nPhotometricInterpretation == 2)
+                    if (nPhotometricInterpretation == 1 || 
nPhotometricInterpretation == 2)
                         SetPixel(nY, nx, Color(static_cast<sal_uInt8>(nRed - 
nMinMax), static_cast<sal_uInt8>(nGreen - nMinMax), 
static_cast<sal_uInt8>(nBlue - nMinMax)));
                     else
                         SetPixel(nY, nx, Color(255 - 
static_cast<sal_uInt8>(nRed - nMinMax), 255 - static_cast<sal_uInt8>(nGreen - 
nMinMax), 255 - static_cast<sal_uInt8>(nBlue - nMinMax)));

Reply via email to