From bd1d0967920655ef85a2352259332f99fef6876e Mon Sep 17 00:00:00 2001 From: Julien Nabet Date: Thu, 21 Apr 2022 11:54:49 +0200 Subject: 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 --- vcl/source/filter/itiff/itiff.cxx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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(nRed - nMinMax), static_cast(nGreen - nMinMax), static_cast(nBlue - nMinMax))); else SetPixel(nY, nx, Color(255 - static_cast(nRed - nMinMax), 255 - static_cast(nGreen - nMinMax), 255 - static_cast(nBlue - nMinMax))); -- cgit