summaryrefslogtreecommitdiff
path: root/canvas
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-03-09 15:30:53 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-03-10 12:04:19 +0100
commit676024b001340dce6c854efc3b74bdc8db1e2a3b (patch)
tree732dc17462b9b6f5316d942e39c18370894e1347 /canvas
parent5b2fc10f0cc9f15525c7723764a1feebeceb0d5e (diff)
move canvas helper code into vcl
part of making BitmapWriteAccess an internal feature of vcl Change-Id: Iee94f47e120d82a23e57342952d04e9b2792cd1a Reviewed-on: https://gerrit.libreoffice.org/50999 Reviewed-by: Michael Meeks <michael.meeks@collabora.com> Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'canvas')
-rw-r--r--canvas/source/vcl/canvasbitmaphelper.cxx257
1 files changed, 5 insertions, 252 deletions
diff --git a/canvas/source/vcl/canvasbitmaphelper.cxx b/canvas/source/vcl/canvasbitmaphelper.cxx
index 869957546498..20b823f32cc3 100644
--- a/canvas/source/vcl/canvasbitmaphelper.cxx
+++ b/canvas/source/vcl/canvasbitmaphelper.cxx
@@ -30,6 +30,7 @@
#include <tools/poly.hxx>
#include <vcl/bitmapex.hxx>
#include <vcl/bitmapaccess.hxx>
+#include <vcl/BitmapTools.hxx>
#include <vcl/canvastools.hxx>
#include <vcl/window.hxx>
@@ -205,222 +206,9 @@ namespace vclcanvas
// 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.
- Bitmap aBitmap( mpBackBuffer->getBitmapReference().GetBitmap() );
- Bitmap aAlpha( mpBackBuffer->getBitmapReference().GetAlpha().GetBitmap() );
-
- bool bCopyBack( false ); // only copy something back, if we
- // actually changed a pixel
-
- {
- Bitmap::ScopedWriteAccess pWriteAccess( aBitmap );
- Bitmap::ScopedWriteAccess pAlphaWriteAccess( aAlpha.IsEmpty() ?
- nullptr : aAlpha.AcquireWriteAccess(),
- aAlpha );
-
- if( pAlphaWriteAccess.get() )
- {
- DBG_ASSERT( pAlphaWriteAccess->GetScanlineFormat() == ScanlineFormat::N8BitPal ||
- pAlphaWriteAccess->GetScanlineFormat() == ScanlineFormat::N8BitTcMask,
- "non-8bit alpha not supported!" );
- }
-
- ENSURE_OR_THROW( pWriteAccess.get() != nullptr,
- "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 nCurrPos(0);
- for( long y=rect.Y1;
- y<aBmpSize.Height() && y<rect.Y2;
- ++y )
- {
- if( pAlphaWriteAccess.get() != nullptr )
- {
- switch( pWriteAccess->GetScanlineFormat() )
- {
- case ScanlineFormat::N8BitPal:
- {
- Scanline pScan = pWriteAccess->GetScanline( y );
- Scanline pAScan = pAlphaWriteAccess->GetScanline( y );
-
- for( long x=rect.X1;
- x<aBmpSize.Width() && x<rect.X2;
- ++x )
- {
- *pScan++ = static_cast<sal_uInt8>(pWriteAccess->GetBestPaletteIndex(
- BitmapColor( data[ nCurrPos ],
- data[ nCurrPos+1 ],
- data[ nCurrPos+2 ] ) ));
-
- nCurrPos += 3;
-
- // cast to unsigned byte, for correct subtraction result
- *pAScan++ = static_cast<sal_uInt8>(255 -
- static_cast<sal_uInt8>(data[ nCurrPos++ ]));
- }
- }
- break;
-
- case ScanlineFormat::N24BitTcBgr:
- {
- Scanline pScan = pWriteAccess->GetScanline( y );
- Scanline pAScan = pAlphaWriteAccess->GetScanline( y );
-
- for( long 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<sal_uInt8>(255 -
- static_cast<sal_uInt8>(data[ nCurrPos++ ]));
- }
- }
- break;
-
- case ScanlineFormat::N24BitTcRgb:
- {
- Scanline pScan = pWriteAccess->GetScanline( y );
- Scanline pAScan = pAlphaWriteAccess->GetScanline( y );
-
- for( long 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<sal_uInt8>(255 -
- static_cast<sal_uInt8>(data[ nCurrPos++ ]));
- }
- }
- break;
-
- default:
- {
- Scanline pScan = pWriteAccess->GetScanline( y );
- Scanline pAScan = pAlphaWriteAccess->GetScanline( y );
-
- for( long x=rect.X1;
- x<aBmpSize.Width() && x<rect.X2;
- ++x )
- {
- pWriteAccess->SetPixelOnData( pScan, x, BitmapColor( data[ nCurrPos ],
- data[ nCurrPos+1 ],
- data[ nCurrPos+2 ] ) );
- nCurrPos += 3;
-
- // cast to unsigned byte, for correct subtraction result
- pAlphaWriteAccess->SetPixelOnData( pAScan, x,
- BitmapColor(
- static_cast<sal_uInt8>(255 -
- static_cast<sal_uInt8>(data[ nCurrPos++ ])) ) );
- }
- }
- break;
- }
- }
- else
- {
- // TODO(Q3): This is copy'n'pasted from
- // canvashelper.cxx, unify!
- switch( pWriteAccess->GetScanlineFormat() )
- {
- case ScanlineFormat::N8BitPal:
- {
- Scanline pScan = pWriteAccess->GetScanline( y );
-
- for( long x=rect.X1;
- x<aBmpSize.Width() && x<rect.X2;
- ++x )
- {
- *pScan++ = static_cast<sal_uInt8>(pWriteAccess->GetBestPaletteIndex(
- BitmapColor( data[ nCurrPos ],
- data[ nCurrPos+1 ],
- data[ nCurrPos+2 ] ) ));
-
- nCurrPos += 4; // skip three colors, _plus_ alpha
- }
- }
- break;
-
- case ScanlineFormat::N24BitTcBgr:
- {
- Scanline pScan = pWriteAccess->GetScanline( y );
-
- for( long 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
- }
- }
- break;
-
- case ScanlineFormat::N24BitTcRgb:
- {
- Scanline pScan = pWriteAccess->GetScanline( y );
-
- for( long 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
- }
- }
- break;
-
- default:
- {
- Scanline pScan = pWriteAccess->GetScanline( y );
-
- for( long x=rect.X1;
- x<aBmpSize.Width() && x<rect.X2;
- ++x )
- {
- pWriteAccess->SetPixelOnData( pScan, x, BitmapColor( data[ nCurrPos ],
- data[ nCurrPos+1 ],
- data[ nCurrPos+2 ] ) );
- nCurrPos += 4; // skip three colors, _plus_ alpha
- }
- }
- break;
- }
- }
-
- bCopyBack = true;
- }
- }
- // copy back only here, since the BitmapAccessors must be
- // destroyed beforehand
- if( bCopyBack )
- {
- if( aAlpha.IsEmpty() )
- setBitmap( BitmapEx( aBitmap ) );
- else
- setBitmap( BitmapEx( aBitmap,
- AlphaMask( aAlpha ) ) );
- }
+ BitmapEx newBitmap = vcl::bitmap::CanvasBitmapHelperSetData(data, rect, mpBackBuffer->getBitmapReference());
+ setBitmap( newBitmap );
}
void CanvasBitmapHelper::setPixel( const uno::Sequence< sal_Int8 >& color,
@@ -448,44 +236,9 @@ namespace vclcanvas
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.
- Bitmap aBitmap( mpBackBuffer->getBitmapReference().GetBitmap() );
- Bitmap aAlpha( mpBackBuffer->getBitmapReference().GetAlpha().GetBitmap() );
-
- bool bCopyBack( false ); // only copy something back, if we
- // actually changed a pixel
- {
- Bitmap::ScopedWriteAccess pWriteAccess( aBitmap );
- Bitmap::ScopedWriteAccess pAlphaWriteAccess( aAlpha.IsEmpty() ?
- nullptr : aAlpha.AcquireWriteAccess(),
- aAlpha );
-
- ENSURE_OR_THROW( pWriteAccess.get() != nullptr,
- "Could not acquire write access to bitmap" );
-
- pWriteAccess->SetPixel( pos.Y, pos.X, BitmapColor( color[ 0 ],
- color[ 1 ],
- color[ 2 ] ) );
-
- if( pAlphaWriteAccess.get() != nullptr )
- pAlphaWriteAccess->SetPixel( pos.Y, pos.X, BitmapColor( 255 - color[ 3 ] ) );
-
- bCopyBack = true;
- }
-
- // copy back only here, since the BitmapAccessors must be
- // destroyed beforehand
- if( bCopyBack )
- {
- if( aAlpha.IsEmpty() )
- setBitmap( BitmapEx( aBitmap ) );
- else
- setBitmap( BitmapEx( aBitmap,
- AlphaMask( aAlpha ) ) );
- }
+ BitmapEx newBitmapEx = vcl::bitmap::CanvasBitmapHelperSetPixel(color, pos, mpBackBuffer->getBitmapReference());
+ setBitmap( newBitmapEx );
}
uno::Sequence< sal_Int8 > CanvasBitmapHelper::getPixel( rendering::IntegerBitmapLayout& rLayout,