[ooo-build-commit] .: filter/source
Caolán McNamara
caolan at kemper.freedesktop.org
Thu Oct 7 03:05:34 PDT 2010
filter/source/graphicfilter/itiff/itiff.cxx | 61 +++++++++++++++++++++++++---
1 file changed, 56 insertions(+), 5 deletions(-)
New commits:
commit 40d8f06fd694368d4e87948110c0639c2ec054c5
Author: Caolán McNamara <caolanm at redhat.com>
Date: Wed Oct 6 16:43:41 2010 +0100
fdo#30472 implement import of alpha channel for RGBA .tiffs
diff --git a/filter/source/graphicfilter/itiff/itiff.cxx b/filter/source/graphicfilter/itiff/itiff.cxx
index d267896..0854fba 100644
--- a/filter/source/graphicfilter/itiff/itiff.cxx
+++ b/filter/source/graphicfilter/itiff/itiff.cxx
@@ -61,6 +61,8 @@ private:
SvStream* pTIFF; // Die einzulesende TIFF-Datei
Bitmap aBitmap;
BitmapWriteAccess* pAcc;
+ AlphaMask* pAlphaMask;
+ BitmapWriteAccess* pMaskAcc;
USHORT nDstBitsPerPixel;
ULONG nOrigPos; // Anfaengliche Position in pTIFF
@@ -129,10 +131,14 @@ private:
BOOL ConvertScanline( ULONG nY );
// Konvertiert eine Scanline in das Windows-BMP-Format
+ bool HasAlphaChannel() const;
public:
- TIFFReader() {}
- ~TIFFReader() {}
+ TIFFReader() : pAlphaMask(0), pMaskAcc(0) {}
+ ~TIFFReader()
+ {
+ delete pAlphaMask;
+ }
BOOL ReadTIFF( SvStream & rTIFF, Graphic & rGraphic );
};
@@ -744,12 +750,18 @@ BOOL TIFFReader::ConvertScanline( ULONG nY )
BYTE nLRed = 0;
BYTE nLGreen = 0;
BYTE nLBlue = 0;
+ BYTE nLAlpha = 0;
for ( nx = 0; nx < nImageWidth; nx++, pt += nSamplesPerPixel )
{
nLRed = nLRed + pt[ 0 ];
nLGreen = nLGreen + pt[ 1 ];
nLBlue = nLBlue + pt[ 2 ];
pAcc->SetPixel( nY, nx, Color( nLRed, nLGreen, nLBlue ) );
+ if (nSamplesPerPixel >= 4 && pMaskAcc)
+ {
+ nLAlpha = nLAlpha + pt[ 3 ];
+ pMaskAcc->SetPixel( nY, nx, ~nLAlpha );
+ }
}
}
else
@@ -757,6 +769,11 @@ BOOL TIFFReader::ConvertScanline( ULONG nY )
for ( nx = 0; nx < nImageWidth; nx++, pt += nSamplesPerPixel )
{
pAcc->SetPixel( nY, nx, Color( pt[0], pt[1], pt[2] ) );
+ if (nSamplesPerPixel >= 4 && pMaskAcc)
+ {
+ BYTE nAlpha = pt[3];
+ pMaskAcc->SetPixel( nY, nx, ~nAlpha );
+ }
}
}
}
@@ -1077,6 +1094,18 @@ void TIFFReader::ReadHeader()
bStatus = FALSE;
}
+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 TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
@@ -1219,7 +1248,8 @@ BOOL TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
else
nDstBitsPerPixel = 8;
- aBitmap = Bitmap( Size( nImageWidth, nImageLength ), nDstBitsPerPixel );
+ Size aTargetSize( nImageWidth, nImageLength );
+ aBitmap = Bitmap( aTargetSize, nDstBitsPerPixel );
pAcc = aBitmap.AcquireWriteAccess();
if ( pAcc )
{
@@ -1240,7 +1270,7 @@ BOOL TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
{
pMap[ j ] = new BYTE[ nBytesPerRow ];
}
- catch (std::bad_alloc)
+ catch (std::bad_alloc)
{
pMap[ j ] = NULL;
bStatus = FALSE;
@@ -1248,6 +1278,12 @@ BOOL TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
}
}
+ if (HasAlphaChannel())
+ {
+ pAlphaMask = new AlphaMask( aTargetSize );
+ pMaskAcc = pAlphaMask->AcquireWriteAccess();
+ }
+
if ( bStatus && ReadMap( 10, 60 ) )
{
nMaxPos = Max( pTIFF->Tell(), nMaxPos );
@@ -1260,9 +1296,24 @@ BOOL TIFFReader::ReadTIFF(SvStream & rTIFF, Graphic & rGraphic )
if( pAcc )
{
aBitmap.ReleaseAccess( pAcc );
+
+ if ( pMaskAcc )
+ {
+ if ( pAlphaMask )
+ pAlphaMask->ReleaseAccess( pMaskAcc );
+ pMaskAcc = NULL;
+ }
+
if ( bStatus )
{
- AnimationBitmap aAnimationBitmap( aBitmap, Point( 0, 0 ), aBitmap.GetSizePixel(),
+ BitmapEx aImage;
+
+ if (pAlphaMask)
+ aImage = BitmapEx( aBitmap, *pAlphaMask );
+ else
+ aImage = aBitmap;
+
+ AnimationBitmap aAnimationBitmap( aImage, Point( 0, 0 ), aBitmap.GetSizePixel(),
ANIMATION_TIMEOUT_ON_CLICK, DISPOSE_BACK );
aAnimation.Insert( aAnimationBitmap );
More information about the ooo-build-commit
mailing list