From 676024b001340dce6c854efc3b74bdc8db1e2a3b Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 9 Mar 2018 15:30:53 +0200 Subject: 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 Tested-by: Jenkins --- canvas/source/vcl/canvasbitmaphelper.cxx | 257 +------------------------------ 1 file changed, 5 insertions(+), 252 deletions(-) (limited to 'canvas/source/vcl') 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 #include #include +#include #include #include @@ -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; - yGetScanlineFormat() ) - { - case ScanlineFormat::N8BitPal: - { - Scanline pScan = pWriteAccess->GetScanline( y ); - Scanline pAScan = pAlphaWriteAccess->GetScanline( y ); - - for( long x=rect.X1; - x(pWriteAccess->GetBestPaletteIndex( - BitmapColor( data[ nCurrPos ], - data[ nCurrPos+1 ], - data[ nCurrPos+2 ] ) )); - - nCurrPos += 3; - - // cast to unsigned byte, for correct subtraction result - *pAScan++ = static_cast(255 - - static_cast(data[ nCurrPos++ ])); - } - } - break; - - case ScanlineFormat::N24BitTcBgr: - { - Scanline pScan = pWriteAccess->GetScanline( y ); - Scanline pAScan = pAlphaWriteAccess->GetScanline( y ); - - for( long x=rect.X1; - x(255 - - static_cast(data[ nCurrPos++ ])); - } - } - break; - - case ScanlineFormat::N24BitTcRgb: - { - Scanline pScan = pWriteAccess->GetScanline( y ); - Scanline pAScan = pAlphaWriteAccess->GetScanline( y ); - - for( long x=rect.X1; - x(255 - - static_cast(data[ nCurrPos++ ])); - } - } - break; - - default: - { - Scanline pScan = pWriteAccess->GetScanline( y ); - Scanline pAScan = pAlphaWriteAccess->GetScanline( y ); - - for( long x=rect.X1; - xSetPixelOnData( 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(255 - - static_cast(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(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; - xGetScanline( y ); - - for( long x=rect.X1; - xGetScanline( y ); - - for( long x=rect.X1; - xSetPixelOnData( 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, -- cgit