diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-07-22 15:44:12 +0100 |
---|---|---|
committer | Michael Stahl <Michael.Stahl@cib.de> | 2019-07-23 13:17:13 +0200 |
commit | fda86dd781a80703f06ae1b6056439bafed190a8 (patch) | |
tree | a8182aae9018544b48afc23adf792f8319290feb /filter | |
parent | fad14c70bec997bf99818ee3c08e83ba968c1b0f (diff) |
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@cib.de>
Diffstat (limited to 'filter')
-rw-r--r-- | filter/source/graphicfilter/itiff/itiff.cxx | 53 |
1 files changed, 40 insertions, 13 deletions
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++; |