summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-07-22 15:44:12 +0100
committerCaolán McNamara <caolanm@redhat.com>2019-07-23 11:05:59 +0200
commit09ad0e78129d4f85fd1b847b35409fd5440ed23c (patch)
tree404e308b97709a4b329d8f2cda16860fa41e0da1 /filter
parent91b344b0346347ac40d2d6fa03a03e92d2e9f252 (diff)
Resolves: tdf#126460 implement reading grayscale+alpha tiff format
Change-Id: I3300ae21c74f5a25c767ce643e93d2232f3b9381 Reviewed-on: https://gerrit.libreoffice.org/76123 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'filter')
-rw-r--r--filter/source/graphicfilter/itiff/itiff.cxx53
1 files changed, 40 insertions, 13 deletions
diff --git a/filter/source/graphicfilter/itiff/itiff.cxx b/filter/source/graphicfilter/itiff/itiff.cxx
index 15a4fe3d3b43..31f91c10eb3e 100644
--- a/filter/source/graphicfilter/itiff/itiff.cxx
+++ b/filter/source/graphicfilter/itiff/itiff.cxx
@@ -1148,15 +1148,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);
+ }
}
}
}
@@ -1239,13 +1258,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
@@ -1623,7 +1650,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++;