[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - filter/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 23 11:18:00 UTC 2019


 filter/source/graphicfilter/itiff/itiff.cxx |   53 +++++++++++++++++++++-------
 1 file changed, 40 insertions(+), 13 deletions(-)

New commits:
commit fda86dd781a80703f06ae1b6056439bafed190a8
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Jul 22 15:44:12 2019 +0100
Commit:     Michael Stahl <Michael.Stahl at cib.de>
CommitDate: Tue Jul 23 13:17:13 2019 +0200

    Resolves: tdf#126460 implement reading grayscale+alpha tiff format
    
    Change-Id: I3300ae21c74f5a25c767ce643e93d2232f3b9381
    Reviewed-on: https://gerrit.libreoffice.org/76124
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>

diff --git a/filter/source/graphicfilter/itiff/itiff.cxx b/filter/source/graphicfilter/itiff/itiff.cxx
index 7509777b6122..0e1241a9484a 100644
--- a/filter/source/graphicfilter/itiff/itiff.cxx
+++ b/filter/source/graphicfilter/itiff/itiff.cxx
@@ -1144,15 +1144,34 @@ bool TIFFReader::ConvertScanline(sal_Int32 nY)
         }
     }
     else if ( ( nSamplesPerPixel == 2 ) && ( nBitsPerSample == 8 ) &&
-        ( nPlanarConfiguration == 1 ) && aColorMap.empty() )               // grayscale
+        ( nPlanarConfiguration == 1 ) && aColorMap.empty() )               // grayscale + alpha
     {
         if ( nMaxSampleValue > nMinSampleValue )
         {
-            sal_uInt32 nMinMax = ( ( 1 << 8 /*nDstBitsPerPixel*/ ) - 1 ) / ( nMaxSampleValue - nMinSampleValue );
-            sal_uInt8*  pt = getMapData(0);
-            for (sal_Int32 nx = 0; nx < nImageWidth; nx++, pt += 2 )
+            sal_uInt8* pt = getMapData(0);
+
+            if (nPredictor == 2)
             {
-                SetPixel(nY, nx, static_cast<sal_uInt8>( (static_cast<sal_uInt32>(*pt) - nMinSampleValue) * nMinMax));
+                sal_uInt8 nLastPixel = 0;
+                sal_uInt8 nLastAlpha = 0;
+                for (sal_Int32 nx = 0; nx < nImageWidth; nx++, pt += 2)
+                {
+                    nLastPixel = (nLastPixel + pt[0]) & 0xFF;
+                    SetPixel(nY, nx, nLastPixel);
+
+                    nLastAlpha = (nLastAlpha + pt[1]) & 0xFF;
+                    SetPixelAlpha(nY, nx, ~nLastAlpha);
+                }
+            }
+            else
+            {
+                sal_uInt32 nMinMax = ( ( 1 << 8 /*nDstBitsPerPixel*/ ) - 1 ) / ( nMaxSampleValue - nMinSampleValue );
+                for (sal_Int32 nx = 0; nx < nImageWidth; nx++, pt += 2)
+                {
+                    SetPixel(nY, nx, static_cast<sal_uInt8>( (static_cast<sal_uInt32>(pt[0]) - nMinSampleValue) * nMinMax ));
+                    sal_uInt8 nAlpha = static_cast<sal_uInt8>( (static_cast<sal_uInt32>(pt[1]) - nMinSampleValue) * nMinMax );
+                    SetPixelAlpha(nY, nx, ~nAlpha);
+                }
             }
         }
     }
@@ -1235,13 +1254,21 @@ void TIFFReader::ReadHeader()
 bool TIFFReader::HasAlphaChannel() const
 {
     /*There are undoubtedly more variants we could support, but keep it simple for now*/
-    return (
-             nDstBitsPerPixel == 24 &&
-             nBitsPerSample == 8 &&
-             nSamplesPerPixel >= 4 &&
-             nPlanes == 1 &&
-             nPhotometricInterpretation == 2
-           );
+    bool bRGBA = nDstBitsPerPixel == 24 &&
+                 nBitsPerSample == 8 &&
+                 nSamplesPerPixel >= 4 &&
+                 nPlanes == 1 &&
+                 nPhotometricInterpretation == 2;
+    if (bRGBA)
+        return true;
+
+    // additionally support the format used in tdf#126460
+    bool bGrayScaleAlpha = nDstBitsPerPixel == 8 &&
+                           nBitsPerSample == 8 &&
+                           nSamplesPerPixel == 2 &&
+                           nPlanarConfiguration == 1;
+
+    return bGrayScaleAlpha;
 }
 
 namespace
@@ -1619,7 +1646,7 @@ bool TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
                         {
                             for (sal_Int32 nX = 0; nX < nImageWidth; ++nX)
                             {
-                                auto p = maBitmap.data() + ((maBitmapPixelSize.Width() * nY + nX) * 3);
+                                auto p = maBitmap.data() + ((maBitmapPixelSize.Width() * nY + nX) * (HasAlphaChannel() ? 4 : 3));
                                 auto c = SanitizePaletteIndex(*p, mvPalette);
                                 *p = c.GetRed();
                                 p++;


More information about the Libreoffice-commits mailing list