summaryrefslogtreecommitdiff
path: root/canvas
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2021-02-27 15:50:37 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-04-26 12:51:58 +0200
commitddd2639a482befb4a3bf1f75a88e66c21a691b67 (patch)
tree2d2a2a0695dce2b8b065f107368ef0412807fa73 /canvas
parent9c4e0c35d70659097b235028047efcb80dcfb10d (diff)
drop mask from BitmapEx
So that we have fewer cases to deal with when we transition to 32-bit bitmaps. (*) rename maMask to maAlphaMask, since now it is only being used for alpha duties. (*) drop mbAlpha and mbTransparent to simplify state management, the only thing we need to check for alpha is if maAlphaMask is non-empty. Change-Id: I06252e38e950e846a94b4c2ba8ea763be17801fe Reviewed-on: https://gerrit.libreoffice.org/c/core/+/111679 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'canvas')
-rw-r--r--canvas/source/cairo/cairo_canvashelper.cxx2
-rw-r--r--canvas/source/directx/dx_vcltools.cxx220
-rw-r--r--canvas/source/vcl/bitmapbackbuffer.cxx2
-rw-r--r--canvas/source/vcl/canvasbitmaphelper.cxx2
-rw-r--r--canvas/source/vcl/spritehelper.cxx27
5 files changed, 48 insertions, 205 deletions
diff --git a/canvas/source/cairo/cairo_canvashelper.cxx b/canvas/source/cairo/cairo_canvashelper.cxx
index 9d9a8bdf9bb8..8e96fe5f9994 100644
--- a/canvas/source/cairo/cairo_canvashelper.cxx
+++ b/canvas/source/cairo/cairo_canvashelper.cxx
@@ -351,7 +351,7 @@ namespace cairocanvas
// there's no pixmap for alpha bitmap. we might still
// use rgb pixmap and only access alpha pixels the
// slow way. now we just speedup rgb bitmaps
- if( !aBmpEx.IsTransparent() && !aBmpEx.IsAlpha() )
+ if( !aBmpEx.IsAlpha() )
{
pSurface = rSurfaceProvider->createSurface( aBitmap );
data = nullptr;
diff --git a/canvas/source/directx/dx_vcltools.cxx b/canvas/source/directx/dx_vcltools.cxx
index 5ed07159aba8..912adf8b0af2 100644
--- a/canvas/source/directx/dx_vcltools.cxx
+++ b/canvas/source/directx/dx_vcltools.cxx
@@ -131,7 +131,7 @@ namespace dxcanvas::tools
return false;
}
- /** Create a chunk of raw RGBA data GDI+ Bitmap from VCL BbitmapEX
+ /** Create a chunk of raw RGBA data GDI+ Bitmap from VCL BitmapEx
*/
RawRGBABitmap bitmapFromVCLBitmapEx( const ::BitmapEx& rBmpEx )
{
@@ -141,9 +141,9 @@ namespace dxcanvas::tools
// make the local bitmap copy unique, effectively
// duplicating the memory used)
- ENSURE_OR_THROW( rBmpEx.IsTransparent(),
+ ENSURE_OR_THROW( rBmpEx.IsAlpha(),
"::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
- "BmpEx not transparent" );
+ "BmpEx has no alpha" );
// convert transparent bitmap to 32bit RGBA
// ========================================
@@ -166,43 +166,41 @@ namespace dxcanvas::tools
"::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
"Unable to acquire read access to bitmap" );
- if (rBmpEx.IsAlpha() || rBmpEx.GetMask().getPixelFormat() == vcl::PixelFormat::N8_BPP)
- {
- Bitmap aAlpha( rBmpEx.IsAlpha() ? rBmpEx.GetAlpha().GetBitmap() : rBmpEx.GetMask());
+ Bitmap aAlpha( rBmpEx.GetAlpha().GetBitmap() );
- Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha );
+ Bitmap::ScopedReadAccess pAlphaReadAccess( aAlpha );
- // By convention, the access buffer always has
- // one of the following formats:
+ // By convention, the access buffer always has
+ // one of the following formats:
- // ScanlineFormat::N1BitMsbPal
- // ScanlineFormat::N8BitPal
- // ScanlineFormat::N24BitTcBgr
- // ScanlineFormat::N32BitTcMask
+ // ScanlineFormat::N1BitMsbPal
+ // ScanlineFormat::N8BitPal
+ // ScanlineFormat::N24BitTcBgr
+ // ScanlineFormat::N32BitTcMask
- // and is always ScanlineFormat::BottomUp
+ // and is always ScanlineFormat::BottomUp
- // This is the way
- // WinSalBitmap::AcquireBuffer() sets up the
- // buffer
+ // This is the way
+ // WinSalBitmap::AcquireBuffer() sets up the
+ // buffer
- ENSURE_OR_THROW( pAlphaReadAccess.get() != nullptr,
- "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
- "Unable to acquire read access to alpha" );
+ ENSURE_OR_THROW( pAlphaReadAccess.get() != nullptr,
+ "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
+ "Unable to acquire read access to alpha" );
- ENSURE_OR_THROW( pAlphaReadAccess->GetScanlineFormat() == ScanlineFormat::N8BitPal,
- "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
- "Unsupported alpha scanline format" );
+ ENSURE_OR_THROW( pAlphaReadAccess->GetScanlineFormat() == ScanlineFormat::N8BitPal,
+ "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
+ "Unsupported alpha scanline format" );
- BitmapColor aCol;
- sal_uInt8* pCurrOutput(aBmpData.maBitmapData.data());
- int x, y;
+ BitmapColor aCol;
+ sal_uInt8* pCurrOutput(aBmpData.maBitmapData.data());
+ int x, y;
- for( y=0; y<nHeight; ++y )
+ for( y=0; y<nHeight; ++y )
+ {
+ switch( pReadAccess->GetScanlineFormat() )
{
- switch( pReadAccess->GetScanlineFormat() )
- {
- case ScanlineFormat::N8BitPal:
+ case ScanlineFormat::N8BitPal:
{
Scanline pScan = pReadAccess->GetScanline( y );
Scanline pAScan = pAlphaReadAccess->GetScanline( y );
@@ -223,7 +221,7 @@ namespace dxcanvas::tools
}
break;
- case ScanlineFormat::N24BitTcBgr:
+ case ScanlineFormat::N24BitTcBgr:
{
Scanline pScan = pReadAccess->GetScanline( y );
Scanline pAScan = pAlphaReadAccess->GetScanline( y );
@@ -246,8 +244,8 @@ namespace dxcanvas::tools
// TODO(P2): Might be advantageous
// to hand-formulate the following
// formats, too.
- case ScanlineFormat::N1BitMsbPal:
- case ScanlineFormat::N32BitTcMask:
+ case ScanlineFormat::N1BitMsbPal:
+ case ScanlineFormat::N32BitTcMask:
{
Scanline pAScan = pAlphaReadAccess->GetScanline( y );
@@ -270,149 +268,17 @@ namespace dxcanvas::tools
}
break;
- case ScanlineFormat::N1BitLsbPal:
- case ScanlineFormat::N24BitTcRgb:
- case ScanlineFormat::N32BitTcAbgr:
- case ScanlineFormat::N32BitTcArgb:
- case ScanlineFormat::N32BitTcBgra:
- case ScanlineFormat::N32BitTcRgba:
- default:
- ENSURE_OR_THROW( false,
- "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
- "Unexpected scanline format - has "
- "WinSalBitmap::AcquireBuffer() changed?" );
- }
- }
- }
- else
- {
- Bitmap aMask( rBmpEx.GetMask() );
-
- Bitmap::ScopedReadAccess pMaskReadAccess( aMask );
-
- // By convention, the access buffer always has
- // one of the following formats:
-
- // ScanlineFormat::N1BitMsbPal
- // ScanlineFormat::N8BitPal
- // ScanlineFormat::N24BitTcBgr
- // ScanlineFormat::N32BitTcMask
-
- // and is always ScanlineFormat::BottomUp
-
- // This is the way
- // WinSalBitmap::AcquireBuffer() sets up the
- // buffer
-
- ENSURE_OR_THROW( pMaskReadAccess.get() != nullptr,
- "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
- "Unable to acquire read access to mask" );
-
- ENSURE_OR_THROW( pMaskReadAccess->GetScanlineFormat() == ScanlineFormat::N1BitMsbPal,
- "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
- "Unsupported mask scanline format" );
-
- BitmapColor aCol;
- int nCurrBit;
- const int nMask( 1 );
- const int nInitialBit(7);
- sal_uInt8* pCurrOutput(aBmpData.maBitmapData.data());
- int x, y;
-
- // mapping table, to get from mask index color to
- // alpha value (which depends on the mask's palette)
- sal_uInt8 aColorMap[2];
-
- const BitmapColor& rCol0( pMaskReadAccess->GetPaletteColor( 0 ) );
- const BitmapColor& rCol1( pMaskReadAccess->GetPaletteColor( 1 ) );
-
- // shortcut for true luminance calculation
- // (assumes that palette is grey-level). Note the
- // swapped the indices here, to account for the
- // fact that VCL's notion of alpha is inverted to
- // the rest of the world's.
- aColorMap[0] = rCol1.GetRed();
- aColorMap[1] = rCol0.GetRed();
-
- for( y=0; y<nHeight; ++y )
- {
- switch( pReadAccess->GetScanlineFormat() )
- {
- case ScanlineFormat::N8BitPal:
- {
- Scanline pScan = pReadAccess->GetScanline( y );
- Scanline pMScan = pMaskReadAccess->GetScanline( y );
-
- for( x=0, nCurrBit=nInitialBit; x<nWidth; ++x )
- {
- aCol = pReadAccess->GetPaletteColor( *pScan++ );
-
- *pCurrOutput++ = aCol.GetBlue();
- *pCurrOutput++ = aCol.GetGreen();
- *pCurrOutput++ = aCol.GetRed();
-
- *pCurrOutput++ = aColorMap[ (pMScan[ (x & ~7) >> 3 ] >> nCurrBit ) & nMask ];
- nCurrBit = ((nCurrBit - 1) % 8) & 7;
- }
- }
- break;
-
- case ScanlineFormat::N24BitTcBgr:
- {
- Scanline pScan = pReadAccess->GetScanline( y );
- Scanline pMScan = pMaskReadAccess->GetScanline( y );
-
- for( x=0, nCurrBit=nInitialBit; x<nWidth; ++x )
- {
- // store as RGBA
- *pCurrOutput++ = *pScan++;
- *pCurrOutput++ = *pScan++;
- *pCurrOutput++ = *pScan++;
-
- *pCurrOutput++ = aColorMap[ (pMScan[ (x & ~7) >> 3 ] >> nCurrBit ) & nMask ];
- nCurrBit = ((nCurrBit - 1) % 8) & 7;
- }
- }
- break;
-
- // TODO(P2): Might be advantageous
- // to hand-formulate the following
- // formats, too.
- case ScanlineFormat::N1BitMsbPal:
- case ScanlineFormat::N32BitTcMask:
- {
- Scanline pMScan = pMaskReadAccess->GetScanline( y );
-
- // using fallback for those
- // seldom formats
- for( x=0, nCurrBit=nInitialBit; x<nWidth; ++x )
- {
- // yes. x and y are swapped on Get/SetPixel
- aCol = pReadAccess->GetColor(y,x);
-
- // store as RGBA
- *pCurrOutput++ = aCol.GetBlue();
- *pCurrOutput++ = aCol.GetGreen();
- *pCurrOutput++ = aCol.GetRed();
-
- *pCurrOutput++ = aColorMap[ (pMScan[ (x & ~7) >> 3 ] >> nCurrBit ) & nMask ];
- nCurrBit = ((nCurrBit - 1) % 8) & 7;
- }
- }
- break;
-
- case ScanlineFormat::N1BitLsbPal:
- case ScanlineFormat::N24BitTcRgb:
- case ScanlineFormat::N32BitTcAbgr:
- case ScanlineFormat::N32BitTcArgb:
- case ScanlineFormat::N32BitTcBgra:
- case ScanlineFormat::N32BitTcRgba:
- default:
- ENSURE_OR_THROW( false,
- "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
- "Unexpected scanline format - has "
- "WinSalBitmap::AcquireBuffer() changed?" );
- }
+ case ScanlineFormat::N1BitLsbPal:
+ case ScanlineFormat::N24BitTcRgb:
+ case ScanlineFormat::N32BitTcAbgr:
+ case ScanlineFormat::N32BitTcArgb:
+ case ScanlineFormat::N32BitTcBgra:
+ case ScanlineFormat::N32BitTcRgba:
+ default:
+ ENSURE_OR_THROW( false,
+ "::dxcanvas::tools::bitmapFromVCLBitmapEx(): "
+ "Unexpected scanline format - has "
+ "WinSalBitmap::AcquireBuffer() changed?" );
}
}
@@ -422,7 +288,7 @@ namespace dxcanvas::tools
bool drawVCLBitmapEx( const std::shared_ptr< Gdiplus::Graphics >& rGraphics,
const ::BitmapEx& rBmpEx )
{
- if( !rBmpEx.IsTransparent() )
+ if( !rBmpEx.IsAlpha() )
{
Bitmap aBmp( rBmpEx.GetBitmap() );
return drawVCLBitmap( rGraphics, aBmp );
diff --git a/canvas/source/vcl/bitmapbackbuffer.cxx b/canvas/source/vcl/bitmapbackbuffer.cxx
index 337e0bae7c2e..d6f87e3c0e00 100644
--- a/canvas/source/vcl/bitmapbackbuffer.cxx
+++ b/canvas/source/vcl/bitmapbackbuffer.cxx
@@ -111,7 +111,7 @@ namespace vclcanvas
// VDev not yet created, do it now. Create an alpha-VDev,
// if bitmap has transparency.
- mpVDev = maBitmap->IsTransparent() ?
+ mpVDev = maBitmap->IsAlpha() ?
VclPtr<VirtualDevice>::Create( mrRefDevice, DeviceFormat::DEFAULT, DeviceFormat::DEFAULT ) :
VclPtr<VirtualDevice>::Create( mrRefDevice );
diff --git a/canvas/source/vcl/canvasbitmaphelper.cxx b/canvas/source/vcl/canvasbitmaphelper.cxx
index dd1898486e8a..00dc8bf03734 100644
--- a/canvas/source/vcl/canvasbitmaphelper.cxx
+++ b/canvas/source/vcl/canvasbitmaphelper.cxx
@@ -53,7 +53,7 @@ namespace vclcanvas
CanvasHelper::init( rDevice,
mpBackBuffer,
false,
- rBitmap.IsTransparent() );
+ rBitmap.IsAlpha() );
}
void CanvasBitmapHelper::disposing()
diff --git a/canvas/source/vcl/spritehelper.cxx b/canvas/source/vcl/spritehelper.cxx
index 7f7035769db2..57b38a9a2815 100644
--- a/canvas/source/vcl/spritehelper.cxx
+++ b/canvas/source/vcl/spritehelper.cxx
@@ -81,10 +81,8 @@ namespace vclcanvas
void SpriteHelper::redraw( OutputDevice& rTargetSurface,
const ::basegfx::B2DPoint& rPos,
bool& io_bSurfacesDirty,
- bool bBufferedUpdate ) const
+ bool /*bBufferedUpdate*/ ) const
{
- (void)bBufferedUpdate; // not used on every platform
-
if( !mpBackBuffer ||
!mpBackBufferMask )
{
@@ -145,31 +143,10 @@ namespace vclcanvas
BitmapEx aMask( mpBackBufferMask->getOutDev().GetBitmapEx( aEmptyPoint,
aOutputSize ) );
- // bitmasks are much faster than alphamasks on some platforms
- // so convert to bitmask if useful
- bool convertTo1Bpp = aMask.getPixelFormat() != vcl::PixelFormat::N1_BPP;
-#ifdef MACOSX
- convertTo1Bpp = false;
-#endif
- if( SkiaHelper::isVCLSkiaEnabled())
- convertTo1Bpp = false;
-
- if( convertTo1Bpp )
- {
- OSL_FAIL("CanvasCustomSprite::redraw(): Mask bitmap is not "
- "monochrome (performance!)");
- BitmapEx aMaskEx(aMask);
- BitmapFilter::Filter(aMaskEx, BitmapMonochromeFilter(255));
- aMask = aMaskEx.GetBitmap();
- }
-
// Note: since we retrieved aBmp and aMask
// directly from an OutDev, it's already a
// 'display bitmap' on windows.
- if (aMask.getPixelFormat() == vcl::PixelFormat::N1_BPP)
- maContent = BitmapEx( aBmp.GetBitmap(), aMask.GetBitmap() );
- else
- maContent = BitmapEx( aBmp.GetBitmap(), AlphaMask( aMask.GetBitmap()) );
+ maContent = BitmapEx( aBmp.GetBitmap(), AlphaMask( aMask.GetBitmap()) );
}
}