Author: alg Date: Tue Oct 30 12:02:38 2012 New Revision: 1403676 URL: http://svn.apache.org/viewvc?rev=1403676&view=rev Log: #121233# some slight corrections/enhancements
Modified: incubator/ooo/trunk/main/drawinglayer/source/processor2d/vclhelperbitmaptransform.cxx incubator/ooo/trunk/main/vcl/inc/vcl/bitmap.hxx incubator/ooo/trunk/main/vcl/source/gdi/bitmap3.cxx Modified: incubator/ooo/trunk/main/drawinglayer/source/processor2d/vclhelperbitmaptransform.cxx URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/drawinglayer/source/processor2d/vclhelperbitmaptransform.cxx?rev=1403676&r1=1403675&r2=1403676&view=diff ============================================================================== --- incubator/ooo/trunk/main/drawinglayer/source/processor2d/vclhelperbitmaptransform.cxx (original) +++ incubator/ooo/trunk/main/drawinglayer/source/processor2d/vclhelperbitmaptransform.cxx Tue Oct 30 12:02:38 2012 @@ -117,78 +117,14 @@ namespace drawinglayer } } - void impSmoothIndex(BitmapColor& rValue, const basegfx::B2DPoint& rSource, sal_Int32 nIntX, sal_Int32 nIntY, BitmapReadAccess& rRead) + Bitmap impTransformBitmap( + const Bitmap& rSource, + const Size aDestinationSize, + const basegfx::B2DHomMatrix& rTransform, + bool bSmooth) { - double fDeltaX(rSource.getX() - nIntX); - double fDeltaY(rSource.getY() - nIntY); - sal_Int32 nIndX(0L); - sal_Int32 nIndY(0L); - - if(fDeltaX > 0.0 && nIntX + 1L < rRead.Width()) - { - nIndX++; - } - else if(fDeltaX < 0.0 && nIntX >= 1L) - { - fDeltaX = -fDeltaX; - nIndX--; - } - - if(fDeltaY > 0.0 && nIntY + 1L < rRead.Height()) - { - nIndY++; - } - else if(fDeltaY < 0.0 && nIntY >= 1L) - { - fDeltaY = -fDeltaY; - nIndY--; - } - - if(nIndX || nIndY) - { - const double fColorToReal(1.0 / 255.0); - double fVal(rValue.GetIndex() * fColorToReal); - double fValBottom(0.0); - - if(nIndX) - { - const double fMulA(fDeltaX * fColorToReal); - double fMulB(1.0 - fDeltaX); - const BitmapColor aTopPartner(rRead.GetPixel(nIntY, nIntX + nIndX)); - - fVal = (fVal * fMulB) + (aTopPartner.GetIndex() * fMulA); - - if(nIndY) - { - fMulB *= fColorToReal; - const BitmapColor aBottom(rRead.GetPixel(nIntY + nIndY, nIntX)); - const BitmapColor aBottomPartner(rRead.GetPixel(nIntY + nIndY, nIntX + nIndX)); - - fValBottom = (aBottom.GetIndex() * fMulB) + (aBottomPartner.GetIndex() * fMulA); - } - } - - if(nIndY) - { - if(!nIndX) - { - const BitmapColor aBottom(rRead.GetPixel(nIntY + nIndY, nIntX)); - - fValBottom = aBottom.GetIndex() * fColorToReal; - } - - const double fMulB(1.0 - fDeltaY); - - fVal = (fVal * fMulB) + (fValBottom * fDeltaY); - } - - rValue.SetIndex((sal_uInt8)(fVal * 255.0)); - } - } - - void impTransformBitmap(const Bitmap& rSource, Bitmap& rDestination, const basegfx::B2DHomMatrix& rTransform, bool bSmooth) - { - BitmapWriteAccess* pWrite = rDestination.AcquireWriteAccess(); + Bitmap aDestination(aDestinationSize, 24); + BitmapWriteAccess* pWrite = aDestination.AcquireWriteAccess(); if(pWrite) { @@ -197,9 +133,9 @@ namespace drawinglayer if(pRead) { - const Size aDestinationSizePixel(rDestination.GetSizePixel()); - bool bWorkWithIndex(rDestination.GetBitCount() <= 8); - BitmapColor aOutside(pRead->GetBestMatchingColor(BitmapColor(0xff, 0xff, 0xff))); + const Size aDestinationSizePixel(aDestination.GetSizePixel()); + bool bWorkWithIndex(rSource.GetBitCount() <= 8); + BitmapColor aOutside(BitmapColor(0xff, 0xff, 0xff)); for(sal_Int32 y(0L); y < aDestinationSizePixel.getHeight(); y++) { @@ -214,30 +150,25 @@ namespace drawinglayer if(nIntY >= 0L && nIntY < aContentSizePixel.getHeight()) { - if(bWorkWithIndex) - { - BitmapColor aValue(pRead->GetPixel(nIntY, nIntX)); - - if(bSmooth) - { - impSmoothIndex(aValue, aSourceCoor, nIntX, nIntY, *pRead); - } - - pWrite->SetPixel(y, x, aValue); - } - else - { - BitmapColor aValue(pRead->GetColor(nIntY, nIntX)); - - if(bSmooth) - { - impSmoothPoint(aValue, aSourceCoor, nIntX, nIntY, *pRead); - } + // inside pixel + BitmapColor aValue; - pWrite->SetPixel(y, x, aValue.IsIndex() ? aValue : pWrite->GetBestMatchingColor(aValue)); - } + if(bWorkWithIndex) + { + aValue = pRead->GetPaletteColor(pRead->GetPixelIndex(nIntY, nIntX)); + } + else + { + aValue = pRead->GetPixel(nIntY, nIntX); + } + + if(bSmooth) + { + impSmoothPoint(aValue, aSourceCoor, nIntX, nIntY, *pRead); + } - continue; + pWrite->SetPixel(y, x, aValue); + continue; } } @@ -254,29 +185,10 @@ namespace drawinglayer delete pWrite; } - } - Bitmap impCreateEmptyBitmapWithPattern(const Bitmap& rSource, const Size& aTargetSizePixel) - { - Bitmap aRetval; - BitmapReadAccess* pReadAccess = (const_cast< Bitmap& >(rSource)).AcquireReadAccess(); - - if(pReadAccess) - { - if(rSource.GetBitCount() <= 8) - { - BitmapPalette aPalette(pReadAccess->GetPalette()); - aRetval = Bitmap(aTargetSizePixel, rSource.GetBitCount(), &aPalette); - } - else - { - aRetval = Bitmap(aTargetSizePixel, rSource.GetBitCount()); - } - - delete pReadAccess; - } + rSource.AdaptBitCount(aDestination); - return aRetval; + return aDestination; } } // end of anonymous namespace } // end of namespace drawinglayer @@ -290,23 +202,20 @@ namespace drawinglayer { // force destination to 24 bit, we want to smooth output const Size aDestinationSize(rCroppedRectPixel.GetSize()); - Bitmap aDestination(impCreateEmptyBitmapWithPattern(rSource.GetBitmap(), aDestinationSize)); static bool bDoSmoothAtAll(true); - impTransformBitmap(rSource.GetBitmap(), aDestination, rTransform, bDoSmoothAtAll); + const Bitmap aDestination(impTransformBitmap(rSource.GetBitmap(), aDestinationSize, rTransform, bDoSmoothAtAll)); // create mask if(rSource.IsTransparent()) { if(rSource.IsAlpha()) { - Bitmap aAlpha(impCreateEmptyBitmapWithPattern(rSource.GetAlpha().GetBitmap(), aDestinationSize)); - impTransformBitmap(rSource.GetAlpha().GetBitmap(), aAlpha, rTransform, bDoSmoothAtAll); + const Bitmap aAlpha(impTransformBitmap(rSource.GetAlpha().GetBitmap(), aDestinationSize, rTransform, bDoSmoothAtAll)); return BitmapEx(aDestination, AlphaMask(aAlpha)); } else { - Bitmap aMask(impCreateEmptyBitmapWithPattern(rSource.GetMask(), aDestinationSize)); - impTransformBitmap(rSource.GetMask(), aMask, rTransform, false); + const Bitmap aMask(impTransformBitmap(rSource.GetMask(), aDestinationSize, rTransform, false)); return BitmapEx(aDestination, aMask); } } Modified: incubator/ooo/trunk/main/vcl/inc/vcl/bitmap.hxx URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/vcl/inc/vcl/bitmap.hxx?rev=1403676&r1=1403675&r2=1403676&view=diff ============================================================================== --- incubator/ooo/trunk/main/vcl/inc/vcl/bitmap.hxx (original) +++ incubator/ooo/trunk/main/vcl/inc/vcl/bitmap.hxx Tue Oct 30 12:02:38 2012 @@ -397,7 +397,7 @@ public: BitmapWriteAccess& rAcc, sal_Bool bRLE4 ); SAL_DLLPRIVATE static sal_Bool ImplWriteRLE( SvStream& rOStm, BitmapReadAccess& rAcc, sal_Bool bRLE4 ); - SAL_DLLPRIVATE void ImplAdaptBitCount(Bitmap& rNew); + SAL_DLLPRIVATE void ImplAdaptBitCount(Bitmap& rNew) const; SAL_DLLPRIVATE sal_Bool ImplScaleFast( const double& rScaleX, const double& rScaleY ); SAL_DLLPRIVATE sal_Bool ImplScaleInterpolate( const double& rScaleX, const double& rScaleY ); SAL_DLLPRIVATE sal_Bool ImplScaleSuper( const double& rScaleX, const double& rScaleY ); @@ -668,6 +668,10 @@ public: */ sal_Bool Scale( const double& rScaleX, const double& rScaleY, sal_uLong nScaleFlag = BMP_SCALE_FASTESTINTERPOLATE ); + // Adapt the BitCount of rNew to BitCount of lolal, including grey or color paltette + // Can be used to create alpha/mask bitmaps after their processing in 24bit + void AdaptBitCount(Bitmap& rNew) const; + /** Rotate bitmap by the specified angle @param nAngle10 Modified: incubator/ooo/trunk/main/vcl/source/gdi/bitmap3.cxx URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/vcl/source/gdi/bitmap3.cxx?rev=1403676&r1=1403675&r2=1403676&view=diff ============================================================================== --- incubator/ooo/trunk/main/vcl/source/gdi/bitmap3.cxx (original) +++ incubator/ooo/trunk/main/vcl/source/gdi/bitmap3.cxx Tue Oct 30 12:02:38 2012 @@ -1032,7 +1032,14 @@ sal_Bool Bitmap::Scale( const Size& rNew // ------------------------------------------------------------------------ -void Bitmap::ImplAdaptBitCount(Bitmap& rNew) +void Bitmap::AdaptBitCount(Bitmap& rNew) const +{ + ImplAdaptBitCount(rNew); +} + +// ------------------------------------------------------------------------ + +void Bitmap::ImplAdaptBitCount(Bitmap& rNew) const { // aNew is the result of some operation; adapt it's BitCount to the original (this) if(GetBitCount() != rNew.GetBitCount()) @@ -1195,73 +1202,52 @@ sal_Bool Bitmap::ImplScaleInterpolate( c pLutFrac[ nX ] = (long) ( fTemp * 1024. ); } - if( pReadAcc->HasPalette() ) + for( nY = 0L; nY < nHeight; nY++ ) { - for( nY = 0L; nY < nHeight; nY++ ) + if( 1 == nWidth ) { - if( 1 == nWidth ) - { - aCol0 = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nY, 0 ) ); - - for( nX = 0L; nX < nNewWidth; nX++ ) - pWriteAcc->SetPixel( nY, nX, aCol0 ); - } - else - { - for( nX = 0L; nX < nNewWidth; nX++ ) - { - nTemp = pLutInt[ nX ]; - - aCol0 = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nY, nTemp++ ) ); - aCol1 = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nY, nTemp ) ); - - nTemp = pLutFrac[ nX ]; - - lXR1 = aCol1.GetRed() - ( lXR0 = aCol0.GetRed() ); - lXG1 = aCol1.GetGreen() - ( lXG0 = aCol0.GetGreen() ); - lXB1 = aCol1.GetBlue() - ( lXB0 = aCol0.GetBlue() ); - - aCol0.SetRed( (sal_uInt8) ( ( lXR1 * nTemp + ( lXR0 << 10 ) ) >> 10 ) ); - aCol0.SetGreen( (sal_uInt8) ( ( lXG1 * nTemp + ( lXG0 << 10 ) ) >> 10 ) ); - aCol0.SetBlue( (sal_uInt8) ( ( lXB1 * nTemp + ( lXB0 << 10 ) ) >> 10 ) ); + if( pReadAcc->HasPalette() ) + { + aCol0 = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nY, 0 ) ); + } + else + { + aCol0 = pReadAcc->GetPixel( nY, 0 ); + } - pWriteAcc->SetPixel( nY, nX, aCol0 ); - } - } + for( nX = 0L; nX < nNewWidth; nX++ ) + { + pWriteAcc->SetPixel( nY, nX, aCol0 ); + } } - } - else - { - for( nY = 0L; nY < nHeight; nY++ ) + else { - if( 1 == nWidth ) - { - aCol0 = pReadAcc->GetPixel( nY, 0 ); - - for( nX = 0L; nX < nNewWidth; nX++ ) - pWriteAcc->SetPixel( nY, nX, aCol0 ); - } - else + for( nX = 0L; nX < nNewWidth; nX++ ) { - for( nX = 0L; nX < nNewWidth; nX++ ) - { - nTemp = pLutInt[ nX ]; + nTemp = pLutInt[ nX ]; + if( pReadAcc->HasPalette() ) + { + aCol0 = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nY, nTemp++ ) ); + aCol1 = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nY, nTemp ) ); + } + else + { aCol0 = pReadAcc->GetPixel( nY, nTemp++ ); aCol1 = pReadAcc->GetPixel( nY, nTemp ); + } - nTemp = pLutFrac[ nX ]; + nTemp = pLutFrac[ nX ]; - lXR1 = aCol1.GetRed() - ( lXR0 = aCol0.GetRed() ); - lXG1 = aCol1.GetGreen() - ( lXG0 = aCol0.GetGreen() ); - lXB1 = aCol1.GetBlue() - ( lXB0 = aCol0.GetBlue() ); + lXR1 = aCol1.GetRed() - ( lXR0 = aCol0.GetRed() ); + lXG1 = aCol1.GetGreen() - ( lXG0 = aCol0.GetGreen() ); + lXB1 = aCol1.GetBlue() - ( lXB0 = aCol0.GetBlue() ); - aCol0.SetRed( (sal_uInt8) ( ( lXR1 * nTemp + ( lXR0 << 10 ) ) >> 10 ) ); - aCol0.SetGreen( (sal_uInt8) ( ( lXG1 * nTemp + ( lXG0 << 10 ) ) >> 10 ) ); - aCol0.SetBlue( (sal_uInt8) ( ( lXB1 * nTemp + ( lXB0 << 10 ) ) >> 10 ) ); + aCol0.SetRed( (sal_uInt8) ( ( lXR1 * nTemp + ( lXR0 << 10 ) ) >> 10 ) ); + aCol0.SetGreen( (sal_uInt8) ( ( lXG1 * nTemp + ( lXG0 << 10 ) ) >> 10 ) ); + aCol0.SetBlue( (sal_uInt8) ( ( lXB1 * nTemp + ( lXB0 << 10 ) ) >> 10 ) ); - pWriteAcc->SetPixel( nY, nX, aCol0 ); - } + pWriteAcc->SetPixel( nY, nX, aCol0 ); } } } @@ -1277,10 +1263,9 @@ sal_Bool Bitmap::ImplScaleInterpolate( c if( bRet ) { bRet = sal_False; - ImplAdaptBitCount(aNewBmp); - ImplAssignWithSize( aNewBmp ); - pReadAcc = AcquireReadAccess(); + *this = aNewBmp; aNewBmp = Bitmap( Size( nNewWidth, nNewHeight ), 24 ); + pReadAcc = AcquireReadAccess(); pWriteAcc = aNewBmp.AcquireWriteAccess(); if( pReadAcc && pWriteAcc ) @@ -1300,73 +1285,40 @@ sal_Bool Bitmap::ImplScaleInterpolate( c pLutFrac[ nY ] = (long) ( fTemp * 1024. ); } - if( pReadAcc->HasPalette() ) + // after 1st step, bitmap *is* 24bit format (see above) + OSL_ENSURE(!pReadAcc->HasPalette(), "OOps, somehow ImplScaleInterpolate in-between format has palette, should not happen (!)"); + + for( nX = 0L; nX < nNewWidth; nX++ ) { - for( nX = 0L; nX < nNewWidth; nX++ ) + if( 1 == nHeight ) { - if( 1 == nHeight ) - { - aCol0 = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( 0, nX ) ); - - for( nY = 0L; nY < nNewHeight; nY++ ) - pWriteAcc->SetPixel( nY, nX, aCol0 ); - } - else - { - for( nY = 0L; nY < nNewHeight; nY++ ) - { - nTemp = pLutInt[ nY ]; - - aCol0 = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nTemp++, nX ) ); - aCol1 = pReadAcc->GetPaletteColor( pReadAcc->GetPixelIndex( nTemp, nX ) ); - - nTemp = pLutFrac[ nY ]; - - lXR1 = aCol1.GetRed() - ( lXR0 = aCol0.GetRed() ); - lXG1 = aCol1.GetGreen() - ( lXG0 = aCol0.GetGreen() ); - lXB1 = aCol1.GetBlue() - ( lXB0 = aCol0.GetBlue() ); + aCol0 = pReadAcc->GetPixel( 0, nX ); - aCol0.SetRed( (sal_uInt8) ( ( lXR1 * nTemp + ( lXR0 << 10 ) ) >> 10 ) ); - aCol0.SetGreen( (sal_uInt8) ( ( lXG1 * nTemp + ( lXG0 << 10 ) ) >> 10 ) ); - aCol0.SetBlue( (sal_uInt8) ( ( lXB1 * nTemp + ( lXB0 << 10 ) ) >> 10 ) ); - - pWriteAcc->SetPixel( nY, nX, aCol0 ); - } - } + for( nY = 0L; nY < nNewHeight; nY++ ) + { + pWriteAcc->SetPixel( nY, nX, aCol0 ); + } } - } - else - { - for( nX = 0L; nX < nNewWidth; nX++ ) + else { - if( 1 == nHeight ) + for( nY = 0L; nY < nNewHeight; nY++ ) { - aCol0 = pReadAcc->GetPixel( 0, nX ); + nTemp = pLutInt[ nY ]; - for( nY = 0L; nY < nNewHeight; nY++ ) - pWriteAcc->SetPixel( nY, nX, aCol0 ); - } - else - { - for( nY = 0L; nY < nNewHeight; nY++ ) - { - nTemp = pLutInt[ nY ]; - - aCol0 = pReadAcc->GetPixel( nTemp++, nX ); - aCol1 = pReadAcc->GetPixel( nTemp, nX ); + aCol0 = pReadAcc->GetPixel( nTemp++, nX ); + aCol1 = pReadAcc->GetPixel( nTemp, nX ); - nTemp = pLutFrac[ nY ]; + nTemp = pLutFrac[ nY ]; - lXR1 = aCol1.GetRed() - ( lXR0 = aCol0.GetRed() ); - lXG1 = aCol1.GetGreen() - ( lXG0 = aCol0.GetGreen() ); - lXB1 = aCol1.GetBlue() - ( lXB0 = aCol0.GetBlue() ); + lXR1 = aCol1.GetRed() - ( lXR0 = aCol0.GetRed() ); + lXG1 = aCol1.GetGreen() - ( lXG0 = aCol0.GetGreen() ); + lXB1 = aCol1.GetBlue() - ( lXB0 = aCol0.GetBlue() ); - aCol0.SetRed( (sal_uInt8) ( ( lXR1 * nTemp + ( lXR0 << 10 ) ) >> 10 ) ); - aCol0.SetGreen( (sal_uInt8) ( ( lXG1 * nTemp + ( lXG0 << 10 ) ) >> 10 ) ); - aCol0.SetBlue( (sal_uInt8) ( ( lXB1 * nTemp + ( lXB0 << 10 ) ) >> 10 ) ); + aCol0.SetRed( (sal_uInt8) ( ( lXR1 * nTemp + ( lXR0 << 10 ) ) >> 10 ) ); + aCol0.SetGreen( (sal_uInt8) ( ( lXG1 * nTemp + ( lXG0 << 10 ) ) >> 10 ) ); + aCol0.SetBlue( (sal_uInt8) ( ( lXB1 * nTemp + ( lXB0 << 10 ) ) >> 10 ) ); - pWriteAcc->SetPixel( nY, nX, aCol0 ); - } + pWriteAcc->SetPixel( nY, nX, aCol0 ); } } } @@ -1382,13 +1334,15 @@ sal_Bool Bitmap::ImplScaleInterpolate( c if( bRet ) { ImplAdaptBitCount(aNewBmp); - ImplAssignWithSize( aNewBmp ); + *this = aNewBmp; } } } if( !bRet ) + { bRet = ImplScaleFast( rScaleX, rScaleY ); + } return bRet; }