diff options
author | Kurt Zenker <kz@openoffice.org> | 2008-06-24 09:55:44 +0000 |
---|---|---|
committer | Kurt Zenker <kz@openoffice.org> | 2008-06-24 09:55:44 +0000 |
commit | 75ed1f796ed2fbc2dd7ba13b4f0e1e9948bfdf32 (patch) | |
tree | c35eade9af2e5663e134e9b7317e260953933035 /canvas/source | |
parent | 8d4cd9ae66019d4fd30cd865dfc0208da697e31d (diff) |
INTEGRATION: CWS canvas05 (1.10.24); FILE MERGED
2008/05/21 13:32:04 thb 1.10.24.5: Made vcl and cairo canvas work with emf+ patches; smoothed out internal cairo makefile changes; corrected cairocanvas sprite update
2008/04/21 07:28:26 thb 1.10.24.4: RESYNC: (1.11-1.12); FILE MERGED
2008/01/22 00:51:17 thb 1.10.24.3: RESYNC: (1.10-1.11); FILE MERGED
2007/12/20 22:18:59 thb 1.10.24.2: #i81092# #i78888# #i78925# #i79258# #i79437# #i84784# Large canvas rework, completing various areas such as color spaces, bitmap data access, true sprite and non-sprite implementations, and upstreaming the canvas parts of rodos emf+ rendering
2007/10/01 13:02:03 thb 1.10.24.1: #i78888# #i78925# #i79258# #i79437# Merge from CWS picom
Diffstat (limited to 'canvas/source')
-rw-r--r-- | canvas/source/vcl/canvasbitmaphelper.cxx | 563 |
1 files changed, 270 insertions, 293 deletions
diff --git a/canvas/source/vcl/canvasbitmaphelper.cxx b/canvas/source/vcl/canvasbitmaphelper.cxx index 0e3236dafd5e..5656e4ba2429 100644 --- a/canvas/source/vcl/canvasbitmaphelper.cxx +++ b/canvas/source/vcl/canvasbitmaphelper.cxx @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: canvasbitmaphelper.cxx,v $ - * $Revision: 1.12 $ + * $Revision: 1.13 $ * * This file is part of OpenOffice.org. * @@ -32,9 +32,9 @@ #include "precompiled_canvas.hxx" #include <canvas/debug.hxx> +#include <tools/diagnose_ex.h> -#include <com/sun/star/rendering/IntegerBitmapFormat.hpp> -#include <com/sun/star/rendering/Endianness.hpp> +#include <com/sun/star/util/Endianness.hpp> #include <rtl/logfile.hxx> #include <rtl/math.hxx> @@ -61,36 +61,35 @@ using namespace ::com::sun::star; namespace vclcanvas { CanvasBitmapHelper::CanvasBitmapHelper() : - mpBackBuffer() + mpBackBuffer(), + mpOutDevReference() { } void CanvasBitmapHelper::setBitmap( const BitmapEx& rBitmap ) { - ENSURE_AND_THROW( mpDevice && mpDevice->getOutDev(), - "CanvasBitmapHelper::setBitmap(): Invalid reference device" ); + ENSURE_OR_THROW( mpOutDev, + "Invalid reference device" ); mpBackBuffer.reset( new BitmapBackBuffer( rBitmap, - *mpDevice->getOutDev() ) ); + mpOutDev->getOutDev() ) ); // tell canvas helper about the new target OutDev (don't // protect state, it's our own VirDev, anyways) setOutDev( mpBackBuffer, false ); } - void CanvasBitmapHelper::init( const BitmapEx& rBitmap, - SpriteCanvas& rSpriteCanvas ) + void CanvasBitmapHelper::init( const BitmapEx& rBitmap, + rendering::XGraphicDevice& rDevice, + const OutDevProviderSharedPtr& rOutDevReference ) { - ENSURE_AND_THROW( rSpriteCanvas.getOutDev(), - "CanvasBitmapHelper::setBitmap(): Invalid reference device" ); - - mpBackBuffer.reset( new BitmapBackBuffer( rBitmap, - *rSpriteCanvas.getOutDev() ) ); + mpOutDevReference = rOutDevReference; + mpBackBuffer.reset( new BitmapBackBuffer( rBitmap, rOutDevReference->getOutDev() )); // forward new settings to base class (ref device, output // surface, no protection (own backbuffer), alpha depends on // whether BmpEx is transparent or not) - CanvasHelper::init( rSpriteCanvas, + CanvasHelper::init( rDevice, mpBackBuffer, false, rBitmap.IsTransparent() ); @@ -99,6 +98,7 @@ namespace vclcanvas void CanvasBitmapHelper::disposing() { mpBackBuffer.reset(); + mpOutDevReference.reset(); // forward to base class CanvasHelper::disposing(); @@ -112,15 +112,22 @@ namespace vclcanvas return ::vcl::unotools::integerSize2DFromSize( mpBackBuffer->getBitmapReference().GetSizePixel() ); } + void CanvasBitmapHelper::clear() + { + // are we disposed? + if( mpBackBuffer ) + mpBackBuffer->clear(); // alpha vdev needs special treatment + } + uno::Reference< rendering::XBitmap > CanvasBitmapHelper::getScaledBitmap( const geometry::RealSize2D& newSize, sal_Bool beFast ) { - ENSURE_AND_THROW( mpDevice, - "CanvasBitmapHelper::getScaledBitmap(): disposed CanvasHelper" ); + ENSURE_OR_THROW( mpDevice, + "disposed CanvasHelper" ); RTL_LOGFILE_CONTEXT( aLog, "::vclcanvas::CanvasBitmapHelper::getScaledBitmap()" ); - if( !mpBackBuffer ) + if( !mpBackBuffer || mpDevice ) return uno::Reference< rendering::XBitmap >(); // we're disposed BitmapEx aRes( mpBackBuffer->getBitmapReference() ); @@ -129,10 +136,10 @@ namespace vclcanvas beFast ? BMP_SCALE_FAST : BMP_SCALE_INTERPOLATE ); return uno::Reference< rendering::XBitmap >( - new CanvasBitmap( aRes, mpDevice ) ); + new CanvasBitmap( aRes, *mpDevice, mpOutDevReference ) ); } - uno::Sequence< sal_Int8 > CanvasBitmapHelper::getData( rendering::IntegerBitmapLayout& aLayout, + uno::Sequence< sal_Int8 > CanvasBitmapHelper::getData( rendering::IntegerBitmapLayout& rLayout, const geometry::IntegerRectangle2D& rect ) { RTL_LOGFILE_CONTEXT( aLog, "::vclcanvas::CanvasBitmapHelper::getData()" ); @@ -140,24 +147,7 @@ namespace vclcanvas if( !mpBackBuffer ) return uno::Sequence< sal_Int8 >(); // we're disposed - const sal_Int32 nWidth( rect.X2 - rect.X1 ); - const sal_Int32 nHeight( rect.Y2 - rect.Y1 ); - aLayout.ScanLines = nHeight; - aLayout.ScanLineBytes = nWidth*4; - aLayout.ScanLineStride = aLayout.ScanLineBytes; - aLayout.PlaneStride = 0; - aLayout.ColorSpace.set( mpDevice ); - aLayout.NumComponents = 4; - aLayout.ComponentMasks.realloc(4); - aLayout.ComponentMasks[0] = 0x00FF0000; - aLayout.ComponentMasks[1] = 0x0000FF00; - aLayout.ComponentMasks[2] = 0x000000FF; - aLayout.ComponentMasks[3] = 0xFF000000; - aLayout.Palette.clear(); - aLayout.Endianness = rendering::Endianness::LITTLE; - aLayout.Format = rendering::IntegerBitmapFormat::CHUNKY_32BIT; - aLayout.IsMsbFirst = sal_False; - + rLayout = getMemoryLayout(); Bitmap aBitmap( mpBackBuffer->getBitmapReference().GetBitmap() ); Bitmap aAlpha( mpBackBuffer->getBitmapReference().GetAlpha().GetBitmap() ); @@ -167,54 +157,56 @@ namespace vclcanvas (BitmapReadAccess*)NULL : aAlpha.AcquireReadAccess(), aAlpha ); - if( pReadAccess.get() != NULL ) - { - // TODO(F1): Support more formats. - const Size aBmpSize( aBitmap.GetSizePixel() ); + ENSURE_OR_THROW( pReadAccess.get() != NULL, + "Could not acquire read access to bitmap" ); - // for the time being, always return as BGRA - uno::Sequence< sal_Int8 > aRes( 4*aBmpSize.Width()*aBmpSize.Height() ); - sal_Int8* pRes = aRes.getArray(); + // TODO(F1): Support more formats. + const Size aBmpSize( aBitmap.GetSizePixel() ); - int nCurrPos(0); - for( int y=rect.Y1; - y<aBmpSize.Height() && y<rect.Y2; - ++y ) + rLayout.ScanLines = aBmpSize.Height(); + rLayout.ScanLineBytes = aBmpSize.Width()*4; + rLayout.ScanLineStride = rLayout.ScanLineBytes; + + // for the time being, always return as BGRA + uno::Sequence< sal_Int8 > aRes( 4*aBmpSize.Width()*aBmpSize.Height() ); + sal_Int8* pRes = aRes.getArray(); + + int nCurrPos(0); + for( int y=rect.Y1; + y<aBmpSize.Height() && y<rect.Y2; + ++y ) + { + if( pAlphaReadAccess.get() != NULL ) { - if( pAlphaReadAccess.get() != NULL ) + for( int x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) { - for( int x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetBlue(); - pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetGreen(); - pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetRed(); - pRes[ nCurrPos++ ] = pAlphaReadAccess->GetPixel( y, x ).GetIndex(); - } + pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetRed(); + pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetGreen(); + pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetBlue(); + pRes[ nCurrPos++ ] = pAlphaReadAccess->GetPixel( y, x ).GetIndex(); } - else + } + else + { + for( int x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) { - for( int x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetBlue(); - pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetGreen(); - pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetRed(); - pRes[ nCurrPos++ ] = sal_uInt8(255); - } + pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetRed(); + pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetGreen(); + pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetBlue(); + pRes[ nCurrPos++ ] = sal_uInt8(255); } } - - return aRes; } - return uno::Sequence< sal_Int8 >(); + return aRes; } void CanvasBitmapHelper::setData( const uno::Sequence< sal_Int8 >& data, - const rendering::IntegerBitmapLayout& , + const rendering::IntegerBitmapLayout& rLayout, const geometry::IntegerRectangle2D& rect ) { RTL_LOGFILE_CONTEXT( aLog, "::vclcanvas::CanvasBitmapHelper::setData()" ); @@ -222,6 +214,13 @@ namespace vclcanvas if( !mpBackBuffer ) return; // we're disposed + const rendering::IntegerBitmapLayout aRefLayout( getMemoryLayout() ); + ENSURE_ARG_OR_THROW( aRefLayout.PlaneStride != rLayout.PlaneStride || + aRefLayout.ColorSpace != rLayout.ColorSpace || + aRefLayout.Palette != rLayout.Palette || + aRefLayout.IsMsbFirst != rLayout.IsMsbFirst, + "Mismatching memory layout" ); + // retrieve local copies from the BitmapEx, which are later // stored back. Unfortunately, the BitmapEx does not permit // in-place modifications, as they are necessary here. @@ -242,188 +241,188 @@ namespace vclcanvas { DBG_ASSERT( pAlphaWriteAccess->GetScanlineFormat() == BMP_FORMAT_8BIT_PAL || pAlphaWriteAccess->GetScanlineFormat() == BMP_FORMAT_8BIT_TC_MASK, - "CanvasBitmapHelper::setData(): non-8bit alpha not supported!" ); + "non-8bit alpha not supported!" ); } - if( pWriteAccess.get() != NULL ) + ENSURE_OR_THROW( pWriteAccess.get() != NULL, + "Could not acquire write access to bitmap" ); + + // TODO(F1): Support more formats. + const Size aBmpSize( aBitmap.GetSizePixel() ); + + // for the time being, always read as BGRA + int x, y, nCurrPos(0); + for( y=rect.Y1; + y<aBmpSize.Height() && y<rect.Y2; + ++y ) { - // TODO(F1): Support more formats. - const Size aBmpSize( aBitmap.GetSizePixel() ); - - // for the time being, always read as BGRA - int x, y, nCurrPos(0); - for( y=rect.Y1; - y<aBmpSize.Height() && y<rect.Y2; - ++y ) + if( pAlphaWriteAccess.get() != NULL ) { - if( pAlphaWriteAccess.get() != NULL ) + switch( pWriteAccess->GetScanlineFormat() ) { - switch( pWriteAccess->GetScanlineFormat() ) + case BMP_FORMAT_8BIT_PAL: { - case BMP_FORMAT_8BIT_PAL: + Scanline pScan = pWriteAccess->GetScanline( y ); + Scanline pAScan = pAlphaWriteAccess->GetScanline( y ); + + for( x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) { - Scanline pScan = pWriteAccess->GetScanline( y ); - Scanline pAScan = pAlphaWriteAccess->GetScanline( y ); - - for( x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - *pScan++ = (BYTE)pWriteAccess->GetBestPaletteIndex( - BitmapColor( data[ nCurrPos+2 ], - data[ nCurrPos+1 ], - data[ nCurrPos ] ) ); - - nCurrPos += 3; - - // cast to unsigned byte, for correct subtraction result - *pAScan++ = static_cast<BYTE>(255 - - static_cast<sal_uInt8>(data[ nCurrPos++ ])); - } + *pScan++ = (BYTE)pWriteAccess->GetBestPaletteIndex( + BitmapColor( data[ nCurrPos ], + data[ nCurrPos+1 ], + data[ nCurrPos+2 ] ) ); + + nCurrPos += 3; + + // cast to unsigned byte, for correct subtraction result + *pAScan++ = static_cast<BYTE>(255 - + static_cast<sal_uInt8>(data[ nCurrPos++ ])); } - break; + } + break; - case BMP_FORMAT_24BIT_TC_BGR: + case BMP_FORMAT_24BIT_TC_BGR: + { + Scanline pScan = pWriteAccess->GetScanline( y ); + Scanline pAScan = pAlphaWriteAccess->GetScanline( y ); + + for( x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) { - Scanline pScan = pWriteAccess->GetScanline( y ); - Scanline pAScan = pAlphaWriteAccess->GetScanline( y ); - - for( x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - *pScan++ = data[ nCurrPos ]; - *pScan++ = data[ nCurrPos+1 ]; - *pScan++ = data[ nCurrPos+2 ]; - - nCurrPos += 3; - - // cast to unsigned byte, for correct subtraction result - *pAScan++ = static_cast<BYTE>(255 - - static_cast<sal_uInt8>(data[ nCurrPos++ ])); - } + *pScan++ = data[ nCurrPos+2 ]; + *pScan++ = data[ nCurrPos+1 ]; + *pScan++ = data[ nCurrPos ]; + + nCurrPos += 3; + + // cast to unsigned byte, for correct subtraction result + *pAScan++ = static_cast<BYTE>(255 - + static_cast<sal_uInt8>(data[ nCurrPos++ ])); } - break; + } + break; - case BMP_FORMAT_24BIT_TC_RGB: + case BMP_FORMAT_24BIT_TC_RGB: + { + Scanline pScan = pWriteAccess->GetScanline( y ); + Scanline pAScan = pAlphaWriteAccess->GetScanline( y ); + + for( x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) { - Scanline pScan = pWriteAccess->GetScanline( y ); - Scanline pAScan = pAlphaWriteAccess->GetScanline( y ); - - for( x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - *pScan++ = data[ nCurrPos+2 ]; - *pScan++ = data[ nCurrPos+1 ]; - *pScan++ = data[ nCurrPos ]; - - nCurrPos += 3; - - // cast to unsigned byte, for correct subtraction result - *pAScan++ = static_cast<BYTE>(255 - - static_cast<sal_uInt8>(data[ nCurrPos++ ])); - } + *pScan++ = data[ nCurrPos ]; + *pScan++ = data[ nCurrPos+1 ]; + *pScan++ = data[ nCurrPos+2 ]; + + nCurrPos += 3; + + // cast to unsigned byte, for correct subtraction result + *pAScan++ = static_cast<BYTE>(255 - + static_cast<sal_uInt8>(data[ nCurrPos++ ])); } - break; + } + break; - default: + default: + { + for( x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) { - for( x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - pWriteAccess->SetPixel( y, x, BitmapColor( data[ nCurrPos+2 ], - data[ nCurrPos+1 ], - data[ nCurrPos ] ) ); - nCurrPos += 3; - - // cast to unsigned byte, for correct subtraction result - pAlphaWriteAccess->SetPixel( y, x, - BitmapColor( - static_cast<BYTE>(255 - - static_cast<sal_uInt8>(data[ nCurrPos++ ])) ) ); - } + pWriteAccess->SetPixel( y, x, BitmapColor( data[ nCurrPos ], + data[ nCurrPos+1 ], + data[ nCurrPos+2 ] ) ); + nCurrPos += 3; + + // cast to unsigned byte, for correct subtraction result + pAlphaWriteAccess->SetPixel( y, x, + BitmapColor( + static_cast<BYTE>(255 - + static_cast<sal_uInt8>(data[ nCurrPos++ ])) ) ); } - break; } + break; } - else + } + else + { + // TODO(Q3): This is copy'n'pasted from + // canvashelper.cxx, unify! + switch( pWriteAccess->GetScanlineFormat() ) { - // TODO(Q3): This is copy'n'pasted from - // canvashelper.cxx, unify! - switch( pWriteAccess->GetScanlineFormat() ) + case BMP_FORMAT_8BIT_PAL: { - case BMP_FORMAT_8BIT_PAL: + Scanline pScan = pWriteAccess->GetScanline( y ); + + for( x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) { - Scanline pScan = pWriteAccess->GetScanline( y ); - - for( x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - *pScan++ = (BYTE)pWriteAccess->GetBestPaletteIndex( - BitmapColor( data[ nCurrPos+2 ], - data[ nCurrPos+1 ], - data[ nCurrPos ] ) ); - - nCurrPos += 4; // skip three colors, _plus_ alpha - } + *pScan++ = (BYTE)pWriteAccess->GetBestPaletteIndex( + BitmapColor( data[ nCurrPos ], + data[ nCurrPos+1 ], + data[ nCurrPos+2 ] ) ); + + nCurrPos += 4; // skip three colors, _plus_ alpha } - break; + } + break; + + case BMP_FORMAT_24BIT_TC_BGR: + { + Scanline pScan = pWriteAccess->GetScanline( y ); - case BMP_FORMAT_24BIT_TC_BGR: + for( x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) { - Scanline pScan = pWriteAccess->GetScanline( y ); - - for( x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - *pScan++ = data[ nCurrPos ]; - *pScan++ = data[ nCurrPos+1 ]; - *pScan++ = data[ nCurrPos+2 ]; - - nCurrPos += 4; // skip three colors, _plus_ alpha - } + *pScan++ = data[ nCurrPos+2 ]; + *pScan++ = data[ nCurrPos+1 ]; + *pScan++ = data[ nCurrPos ]; + + nCurrPos += 4; // skip three colors, _plus_ alpha } - break; + } + break; - case BMP_FORMAT_24BIT_TC_RGB: + case BMP_FORMAT_24BIT_TC_RGB: + { + Scanline pScan = pWriteAccess->GetScanline( y ); + + for( x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) { - Scanline pScan = pWriteAccess->GetScanline( y ); - - for( x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - *pScan++ = data[ nCurrPos+2 ]; - *pScan++ = data[ nCurrPos+1 ]; - *pScan++ = data[ nCurrPos ]; - - nCurrPos += 4; // skip three colors, _plus_ alpha - } + *pScan++ = data[ nCurrPos ]; + *pScan++ = data[ nCurrPos+1 ]; + *pScan++ = data[ nCurrPos+2 ]; + + nCurrPos += 4; // skip three colors, _plus_ alpha } - break; + } + break; - default: + default: + { + for( x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) { - for( x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - pWriteAccess->SetPixel( y, x, BitmapColor( data[ nCurrPos+2 ], - data[ nCurrPos+1 ], - data[ nCurrPos ] ) ); - nCurrPos += 4; // skip three colors, _plus_ alpha - } + pWriteAccess->SetPixel( y, x, BitmapColor( data[ nCurrPos ], + data[ nCurrPos+1 ], + data[ nCurrPos+2 ] ) ); + nCurrPos += 4; // skip three colors, _plus_ alpha } - break; } + break; } - - bCopyBack = true; } + + bCopyBack = true; } } @@ -439,9 +438,9 @@ namespace vclcanvas } } - void CanvasBitmapHelper::setPixel( const uno::Sequence< sal_Int8 >& color, - const rendering::IntegerBitmapLayout& , - const geometry::IntegerPoint2D& pos ) + void CanvasBitmapHelper::setPixel( const uno::Sequence< sal_Int8 >& color, + const rendering::IntegerBitmapLayout& rLayout, + const geometry::IntegerPoint2D& pos ) { RTL_LOGFILE_CONTEXT( aLog, "::vclcanvas::CanvasBitmapHelper::setPixel()" ); @@ -450,12 +449,19 @@ namespace vclcanvas const Size aBmpSize( mpBackBuffer->getBitmapReference().GetSizePixel() ); - CHECK_AND_THROW( pos.X >= 0 && pos.X < aBmpSize.Width(), - "CanvasBitmapHelper::setPixel: X coordinate out of bounds" ); - CHECK_AND_THROW( pos.Y >= 0 && pos.Y < aBmpSize.Height(), - "CanvasBitmapHelper::setPixel: Y coordinate out of bounds" ); - CHECK_AND_THROW( color.getLength() > 3, - "CanvasBitmapHelper::setPixel: not enough color components" ); + ENSURE_ARG_OR_THROW( pos.X >= 0 && pos.X < aBmpSize.Width(), + "X coordinate out of bounds" ); + ENSURE_ARG_OR_THROW( pos.Y >= 0 && pos.Y < aBmpSize.Height(), + "Y coordinate out of bounds" ); + ENSURE_ARG_OR_THROW( color.getLength() > 3, + "not enough color components" ); + + const rendering::IntegerBitmapLayout aRefLayout( getMemoryLayout() ); + ENSURE_ARG_OR_THROW( aRefLayout.PlaneStride != rLayout.PlaneStride || + aRefLayout.ColorSpace != rLayout.ColorSpace || + aRefLayout.Palette != rLayout.Palette || + aRefLayout.IsMsbFirst != rLayout.IsMsbFirst, + "Mismatching memory layout" ); // retrieve local copies from the BitmapEx, which are later // stored back. Unfortunately, the BitmapEx does not permit @@ -473,17 +479,17 @@ namespace vclcanvas (BitmapWriteAccess*)NULL : aAlpha.AcquireWriteAccess(), aAlpha ); - if( pWriteAccess.get() != NULL ) - { - pWriteAccess->SetPixel( pos.Y, pos.X, BitmapColor( color[ 2 ], - color[ 1 ], - color[ 0 ] ) ); + ENSURE_OR_THROW( pWriteAccess.get() != NULL, + "Could not acquire write access to bitmap" ); - if( pAlphaWriteAccess.get() != NULL ) - pAlphaWriteAccess->SetPixel( pos.Y, pos.X, BitmapColor( 255 - color[ 3 ] ) ); + pWriteAccess->SetPixel( pos.Y, pos.X, BitmapColor( color[ 0 ], + color[ 1 ], + color[ 2 ] ) ); - bCopyBack = true; - } + if( pAlphaWriteAccess.get() != NULL ) + pAlphaWriteAccess->SetPixel( pos.Y, pos.X, BitmapColor( 255 - color[ 3 ] ) ); + + bCopyBack = true; } // copy back only here, since the BitmapAccessors must be @@ -498,7 +504,7 @@ namespace vclcanvas } } - uno::Sequence< sal_Int8 > CanvasBitmapHelper::getPixel( rendering::IntegerBitmapLayout& , + uno::Sequence< sal_Int8 > CanvasBitmapHelper::getPixel( rendering::IntegerBitmapLayout& rLayout, const geometry::IntegerPoint2D& pos ) { RTL_LOGFILE_CONTEXT( aLog, "::vclcanvas::CanvasBitmapHelper::getPixel()" ); @@ -506,12 +512,17 @@ namespace vclcanvas if( !mpBackBuffer ) return uno::Sequence< sal_Int8 >(); // we're disposed + rLayout = getMemoryLayout(); + rLayout.ScanLines = 1; + rLayout.ScanLineBytes = 4; + rLayout.ScanLineStride = rLayout.ScanLineBytes; + const Size aBmpSize( mpBackBuffer->getBitmapReference().GetSizePixel() ); - CHECK_AND_THROW( pos.X >= 0 && pos.X < aBmpSize.Width(), - "CanvasBitmapHelper::getPixel: X coordinate out of bounds" ); - CHECK_AND_THROW( pos.Y >= 0 && pos.Y < aBmpSize.Height(), - "CanvasBitmapHelper::getPixel: Y coordinate out of bounds" ); + ENSURE_ARG_OR_THROW( pos.X >= 0 && pos.X < aBmpSize.Width(), + "X coordinate out of bounds" ); + ENSURE_ARG_OR_THROW( pos.Y >= 0 && pos.Y < aBmpSize.Height(), + "Y coordinate out of bounds" ); Bitmap aBitmap( mpBackBuffer->getBitmapReference().GetBitmap() ); Bitmap aAlpha( mpBackBuffer->getBitmapReference().GetAlpha().GetBitmap() ); @@ -521,65 +532,31 @@ namespace vclcanvas ScopedBitmapReadAccess pAlphaReadAccess( aAlpha.IsEmpty() ? (BitmapReadAccess*)NULL : aAlpha.AcquireReadAccess(), aAlpha ); + ENSURE_OR_THROW( pReadAccess.get() != NULL, + "Could not acquire read access to bitmap" ); - if( pReadAccess.get() != NULL ) - { - // for the time being, always return as BGRA - uno::Sequence< sal_Int8 > aRes( 4 ); - sal_Int8* pRes = aRes.getArray(); - - const BitmapColor aColor( pReadAccess->GetColor( pos.Y, pos.X ) ); - pRes[ 3 ] = aColor.GetRed(); - pRes[ 2 ] = aColor.GetGreen(); - pRes[ 1 ] = aColor.GetBlue(); - - if( pAlphaReadAccess.get() != NULL ) - pRes[ 3 ] = pAlphaReadAccess->GetPixel( pos.Y, pos.X ).GetIndex(); - else - pRes[ 3 ] = sal_uInt8(255); + uno::Sequence< sal_Int8 > aRes( 4 ); + sal_Int8* pRes = aRes.getArray(); - return aRes; - } + const BitmapColor aColor( pReadAccess->GetColor( pos.Y, pos.X ) ); + pRes[ 0 ] = aColor.GetRed(); + pRes[ 1 ] = aColor.GetGreen(); + pRes[ 2 ] = aColor.GetBlue(); - return uno::Sequence< sal_Int8 >(); - } + if( pAlphaReadAccess.get() != NULL ) + pRes[ 3 ] = pAlphaReadAccess->GetPixel( pos.Y, pos.X ).GetIndex(); + else + pRes[ 3 ] = sal_uInt8(255); - uno::Reference< rendering::XBitmapPalette > CanvasBitmapHelper::getPalette() - { - // TODO(F1): Provide palette support - return uno::Reference< rendering::XBitmapPalette >(); + return aRes; } rendering::IntegerBitmapLayout CanvasBitmapHelper::getMemoryLayout() { - // TODO(F1): finish that one - rendering::IntegerBitmapLayout aLayout; + if( !mpOutDev.get() ) + return rendering::IntegerBitmapLayout(); // we're disposed - if( !mpBackBuffer ) - return aLayout; // we're disposed - - const BitmapEx& rBmpEx( mpBackBuffer->getBitmapReference() ); - const Size aBmpSize( rBmpEx.GetSizePixel() ); - - aLayout.ScanLines = aBmpSize.Height(); - aLayout.ScanLineBytes = aBmpSize.Width()*4; - aLayout.ScanLineStride = aLayout.ScanLineBytes; - aLayout.PlaneStride = 0; - // cast away const, need to change refcount (as this is - // ~invisible to client code, still logically const) - aLayout.ColorSpace.set( mpDevice ); - aLayout.NumComponents = 4; - aLayout.ComponentMasks.realloc(4); - aLayout.ComponentMasks[0] = 0x00FF0000; - aLayout.ComponentMasks[1] = 0x0000FF00; - aLayout.ComponentMasks[2] = 0x000000FF; - aLayout.ComponentMasks[3] = 0xFF000000; - aLayout.Palette.clear(); - aLayout.Endianness = rendering::Endianness::LITTLE; - aLayout.Format = rendering::IntegerBitmapFormat::CHUNKY_32BIT; - aLayout.IsMsbFirst = sal_False; - - return aLayout; + return ::canvas::tools::getStdMemoryLayout(getSize()); } BitmapEx CanvasBitmapHelper::getBitmap() const |