diff options
-rw-r--r-- | canvas/source/vcl/canvasbitmaphelper.cxx | 49 | ||||
-rw-r--r-- | include/vcl/BitmapTools.hxx | 2 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapTools.cxx | 53 |
3 files changed, 57 insertions, 47 deletions
diff --git a/canvas/source/vcl/canvasbitmaphelper.cxx b/canvas/source/vcl/canvasbitmaphelper.cxx index eef6258dded3..3d99a3bcbe6e 100644 --- a/canvas/source/vcl/canvasbitmaphelper.cxx +++ b/canvas/source/vcl/canvasbitmaphelper.cxx @@ -117,60 +117,15 @@ namespace vclcanvas return uno::Sequence< sal_Int8 >(); // we're disposed rLayout = getMemoryLayout(); - Bitmap aBitmap( mpBackBuffer->getBitmapReference().GetBitmap() ); - Bitmap aAlpha( mpBackBuffer->getBitmapReference().GetAlpha().GetBitmap() ); - - Bitmap::ScopedReadAccess pReadAccess( aBitmap ); - Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha.IsEmpty() ? - nullptr : aAlpha.AcquireReadAccess(), - aAlpha ); - - ENSURE_OR_THROW( pReadAccess.get() != nullptr, - "Could not acquire read access to bitmap" ); // TODO(F1): Support more formats. - const Size aBmpSize( aBitmap.GetSizePixel() ); + const Size aBmpSize( mpBackBuffer->getBitmapReference().GetSizePixel() ); 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( long y=rect.Y1; - y<aBmpSize.Height() && y<rect.Y2; - ++y ) - { - Scanline pScanlineReadAlpha = pAlphaReadAccess->GetScanline( y ); - if( pAlphaReadAccess.get() != nullptr ) - { - for( long x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetRed(); - pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetGreen(); - pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetBlue(); - pRes[ nCurrPos++ ] = pAlphaReadAccess->GetIndexFromData( pScanlineReadAlpha, x ); - } - } - else - { - for( long x=rect.X1; - x<aBmpSize.Width() && x<rect.X2; - ++x ) - { - 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); - } - } - } - + uno::Sequence< sal_Int8 > aRes = vcl::bitmap::CanvasExtractBitmapData(mpBackBuffer->getBitmapReference(), rect); return aRes; } diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx index 9c347d275f4b..43f0d07579f7 100644 --- a/include/vcl/BitmapTools.hxx +++ b/include/vcl/BitmapTools.hxx @@ -104,6 +104,8 @@ VCL_DLLPUBLIC css::uno::Sequence< sal_Int8 > GetMaskDIB(BitmapEx const & aBmpEx) **/ VCL_DLLPUBLIC void CanvasCairoExtractBitmapData( BitmapEx & rBmpEx, Bitmap & rBitmap, unsigned char*& data, bool& bHasAlpha ); +VCL_DLLPUBLIC css::uno::Sequence< sal_Int8 > CanvasExtractBitmapData(BitmapEx & rBitmapEx, const css::geometry::IntegerRectangle2D& rect); + }} // end vcl::bitmap #endif // INCLUDED_VCL_BITMAP_TOOLS_HXX diff --git a/vcl/source/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx index 816bad119e13..7a722a699043 100644 --- a/vcl/source/bitmap/BitmapTools.cxx +++ b/vcl/source/bitmap/BitmapTools.cxx @@ -939,6 +939,59 @@ void CanvasCairoExtractBitmapData( BitmapEx & aBmpEx, Bitmap & aBitmap, unsigned } + uno::Sequence< sal_Int8 > CanvasExtractBitmapData(BitmapEx & rBitmapEx, const geometry::IntegerRectangle2D& rect) + { + Bitmap aBitmap( rBitmapEx.GetBitmap() ); + Bitmap aAlpha( rBitmapEx.GetAlpha().GetBitmap() ); + + Bitmap::ScopedReadAccess pReadAccess( aBitmap ); + Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha.IsEmpty() ? + nullptr : aAlpha.AcquireReadAccess(), + aAlpha ); + + assert( pReadAccess ); + + // TODO(F1): Support more formats. + const Size aBmpSize( aBitmap.GetSizePixel() ); + + // 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( long y=rect.Y1; + y<aBmpSize.Height() && y<rect.Y2; + ++y ) + { + Scanline pScanlineReadAlpha = pAlphaReadAccess->GetScanline( y ); + if( pAlphaReadAccess.get() != nullptr ) + { + for( long x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) + { + pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetRed(); + pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetGreen(); + pRes[ nCurrPos++ ] = pReadAccess->GetColor( y, x ).GetBlue(); + pRes[ nCurrPos++ ] = pAlphaReadAccess->GetIndexFromData( pScanlineReadAlpha, x ); + } + } + else + { + for( long x=rect.X1; + x<aBmpSize.Width() && x<rect.X2; + ++x ) + { + 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; + } + }} // end vcl::bitmap /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |