diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-16 15:40:29 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-03-19 07:36:28 +0100 |
commit | 09cf2f4242250ac8d1ec6440c46dc85ba1a8dc09 (patch) | |
tree | bd5d8a73eccd3f765c75da2fe0fdfb2e8000b13e /vcl | |
parent | 62275a93e3b13a20aa1de7945a32a0d25582c1ca (diff) |
move bitmap copy code from CanvasBitmapHelper to vcl
part of making GetAlpha/GetMask an internal detail of vcl
Change-Id: Ie1740df3d6435d9f0f2de3297e7f224d2c6b3cc5
Reviewed-on: https://gerrit.libreoffice.org/51436
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/bitmap/BitmapTools.cxx | 53 |
1 files changed, 53 insertions, 0 deletions
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: */ |