canvas/source/vcl/bitmapbackbuffer.cxx | 6 +-- canvas/source/vcl/bitmapbackbuffer.hxx | 6 +-- canvas/source/vcl/canvasbitmap.cxx | 8 ++-- canvas/source/vcl/canvasbitmap.hxx | 4 +- canvas/source/vcl/canvasbitmaphelper.cxx | 12 +++--- canvas/source/vcl/canvasbitmaphelper.hxx | 4 +- canvas/source/vcl/canvashelper.cxx | 43 ++++++++++----------- canvas/source/vcl/canvashelper_texturefill.cxx | 11 ++--- canvas/source/vcl/impltools.cxx | 17 ++++---- canvas/source/vcl/impltools.hxx | 8 ++-- include/vcl/BitmapTools.hxx | 2 - include/vcl/outdev.hxx | 4 ++ vcl/source/bitmap/BitmapTools.cxx | 50 +++++++++---------------- vcl/source/outdev/bitmapex.cxx | 8 ++++ 14 files changed, 89 insertions(+), 94 deletions(-)
New commits: commit 00f16b7c79f4c32302d673fd693e54438ecbd2c0 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Aug 5 11:16:34 2025 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Aug 5 15:50:51 2025 +0200 BitmapEx->Bitmap in canvas now that Bitmap can handle transparency Change-Id: I8e8e48cd5e81b1506871aebf1f70a754c4772c49 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188944 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/canvas/source/vcl/bitmapbackbuffer.cxx b/canvas/source/vcl/bitmapbackbuffer.cxx index 95f36c744f14..af80984bd95f 100644 --- a/canvas/source/vcl/bitmapbackbuffer.cxx +++ b/canvas/source/vcl/bitmapbackbuffer.cxx @@ -28,7 +28,7 @@ namespace vclcanvas { - BitmapBackBuffer::BitmapBackBuffer( const BitmapEx& rBitmap, + BitmapBackBuffer::BitmapBackBuffer( const ::Bitmap& rBitmap, const OutputDevice& rRefDevice ) : maBitmap( rBitmap ), mpVDev( nullptr ), @@ -67,7 +67,7 @@ namespace vclcanvas getBitmapReference().Erase(COL_TRANSPARENT); } - BitmapEx& BitmapBackBuffer::getBitmapReference() + ::Bitmap& BitmapBackBuffer::getBitmapReference() { OSL_ENSURE( !mbBitmapContentIsCurrent || !mbVDevContentIsCurrent, "BitmapBackBuffer::getBitmapReference(): Both bitmap and VDev are valid?!" ); @@ -111,7 +111,7 @@ namespace vclcanvas // VDev not yet created, do it now. Create an alpha-VDev, // if bitmap has transparency. - mpVDev = maBitmap->IsAlpha() ? + mpVDev = maBitmap->HasAlpha() ? VclPtr<VirtualDevice>::Create( mrRefDevice, DeviceFormat::WITH_ALPHA ) : VclPtr<VirtualDevice>::Create( mrRefDevice ); diff --git a/canvas/source/vcl/bitmapbackbuffer.hxx b/canvas/source/vcl/bitmapbackbuffer.hxx index 9098e7e93813..b12aafa9a6f1 100644 --- a/canvas/source/vcl/bitmapbackbuffer.hxx +++ b/canvas/source/vcl/bitmapbackbuffer.hxx @@ -40,7 +40,7 @@ namespace vclcanvas public: /** Create a backbuffer for given reference device */ - BitmapBackBuffer( const BitmapEx& rBitmap, + BitmapBackBuffer( const ::Bitmap& rBitmap, const OutputDevice& rRefDevice ); virtual ~BitmapBackBuffer() override; @@ -56,14 +56,14 @@ namespace vclcanvas @internal */ - BitmapEx& getBitmapReference(); + ::Bitmap& getBitmapReference(); Size getBitmapSizePixel() const; private: void createVDev() const; void updateVDev() const; - ::canvas::vcltools::VCLObject<BitmapEx> maBitmap; + ::canvas::vcltools::VCLObject<::Bitmap> maBitmap; mutable VclPtr<VirtualDevice> mpVDev; // created only on demand const OutputDevice& mrRefDevice; diff --git a/canvas/source/vcl/canvasbitmap.cxx b/canvas/source/vcl/canvasbitmap.cxx index 193afd62c6b2..2e20ebc534b2 100644 --- a/canvas/source/vcl/canvasbitmap.cxx +++ b/canvas/source/vcl/canvasbitmap.cxx @@ -49,19 +49,19 @@ namespace vclcanvas { AlphaMask aAlpha ( rSize ); - maCanvasHelper.init( BitmapEx( aBitmap, aAlpha ), + maCanvasHelper.init( Bitmap(BitmapEx( aBitmap, aAlpha )), rDevice, rOutDevProvider ); } else { - maCanvasHelper.init( BitmapEx( aBitmap ), + maCanvasHelper.init( aBitmap, rDevice, rOutDevProvider ); } } - CanvasBitmap::CanvasBitmap( const BitmapEx& rBitmap, + CanvasBitmap::CanvasBitmap( const ::Bitmap& rBitmap, rendering::XGraphicDevice& rDevice, const OutDevProviderSharedPtr& rOutDevProvider ) { @@ -84,7 +84,7 @@ namespace vclcanvas return { u"com.sun.star.rendering.CanvasBitmap"_ustr }; } - BitmapEx CanvasBitmap::getBitmap() const + Bitmap CanvasBitmap::getBitmap() const { SolarMutexGuard aGuard; diff --git a/canvas/source/vcl/canvasbitmap.hxx b/canvas/source/vcl/canvasbitmap.hxx index 1a95ce8c632c..cec7c6345545 100644 --- a/canvas/source/vcl/canvasbitmap.hxx +++ b/canvas/source/vcl/canvasbitmap.hxx @@ -73,7 +73,7 @@ namespace vclcanvas const OutDevProviderSharedPtr& rOutDevProvider ); /// Must be called with locked Solar mutex - CanvasBitmap( const BitmapEx& rBitmap, + CanvasBitmap( const ::Bitmap& rBitmap, css::rendering::XGraphicDevice& rDevice, const OutDevProviderSharedPtr& rOutDevProvider ); @@ -91,7 +91,7 @@ namespace vclcanvas const GraphicAttr& rAttr ) const override; /// Not threadsafe! Returned object is shared! - BitmapEx getBitmap() const; + ::Bitmap getBitmap() const; // XFastPropertySet // used to retrieve BitmapEx pointer or X Pixmap handles for this bitmap diff --git a/canvas/source/vcl/canvasbitmaphelper.cxx b/canvas/source/vcl/canvasbitmaphelper.cxx index 99b9831cabf6..90bd4714161d 100644 --- a/canvas/source/vcl/canvasbitmaphelper.cxx +++ b/canvas/source/vcl/canvasbitmaphelper.cxx @@ -38,7 +38,7 @@ namespace vclcanvas { } - void CanvasBitmapHelper::init( const BitmapEx& rBitmap, + void CanvasBitmapHelper::init( const ::Bitmap& rBitmap, rendering::XGraphicDevice& rDevice, const OutDevProviderSharedPtr& rOutDevReference ) { @@ -51,7 +51,7 @@ namespace vclcanvas CanvasHelper::init( rDevice, mpBackBuffer, false, - rBitmap.IsAlpha() ); + rBitmap.HasAlpha() ); } void CanvasBitmapHelper::disposing() @@ -89,7 +89,7 @@ namespace vclcanvas if( !mpBackBuffer || mpDevice ) return uno::Reference< rendering::XBitmap >(); // we're disposed - BitmapEx aRes( mpBackBuffer->getBitmapReference() ); + ::Bitmap aRes( mpBackBuffer->getBitmapReference() ); aRes.Scale( vcl::unotools::sizeFromRealSize2D(newSize), beFast ? BmpScaleFlag::Default : BmpScaleFlag::BestQuality ); @@ -115,7 +115,7 @@ namespace vclcanvas rLayout.ScanLineBytes = aBmpSize.Width()*4; rLayout.ScanLineStride = rLayout.ScanLineBytes; - uno::Sequence< sal_Int8 > aRes = vcl::bitmap::CanvasExtractBitmapData(mpBackBuffer->getBitmapReference(), rect); + uno::Sequence< sal_Int8 > aRes = vcl::bitmap::CanvasExtractBitmapData(BitmapEx(mpBackBuffer->getBitmapReference()), rect); return aRes; } @@ -163,10 +163,10 @@ namespace vclcanvas return aBitmapLayout; } - BitmapEx CanvasBitmapHelper::getBitmap() const + ::Bitmap CanvasBitmapHelper::getBitmap() const { if( !mpBackBuffer ) - return BitmapEx(); // we're disposed + return ::Bitmap(); // we're disposed else return mpBackBuffer->getBitmapReference(); } diff --git a/canvas/source/vcl/canvasbitmaphelper.hxx b/canvas/source/vcl/canvasbitmaphelper.hxx index 7e75f92e82d6..2dae57bdb506 100644 --- a/canvas/source/vcl/canvasbitmaphelper.hxx +++ b/canvas/source/vcl/canvasbitmaphelper.hxx @@ -65,7 +65,7 @@ namespace vclcanvas @param rOutDevProvider Reference output device. Used to create matching bitmap. */ - void init( const BitmapEx& rBitmap, + void init( const ::Bitmap& rBitmap, css::rendering::XGraphicDevice& rDevice, const OutDevProviderSharedPtr& rOutDevProvider ); @@ -94,7 +94,7 @@ namespace vclcanvas css::rendering::IntegerBitmapLayout getMemoryLayout() const; /// @internal - BitmapEx getBitmap() const; + ::Bitmap getBitmap() const; private: diff --git a/canvas/source/vcl/canvashelper.cxx b/canvas/source/vcl/canvashelper.cxx index 3c798c8a7158..373f0d4dcd7e 100644 --- a/canvas/source/vcl/canvashelper.cxx +++ b/canvas/source/vcl/canvashelper.cxx @@ -653,7 +653,7 @@ namespace vclcanvas ::basegfx::B2DPoint aOutputPos( 0.0, 0.0 ); aOutputPos *= aMatrix; - BitmapEx aBmpEx( tools::bitmapExFromXBitmap(xBitmap) ); + ::Bitmap aBmp( tools::bitmapFromXBitmap(xBitmap) ); // TODO(F2): Implement modulation again for other color // channels (currently, works only for alpha). Note: this @@ -681,7 +681,7 @@ namespace vclcanvas // optimized case: identity matrix, or only // translational components. mpOutDevProvider->getOutDev().DrawBitmapEx( vcl::unotools::pointFromB2DPoint( aOutputPos ), - aBmpEx ); + aBmp ); if( mp2ndOutDevProvider ) { @@ -689,13 +689,13 @@ namespace vclcanvas // actually what mp2ndOutDev is... well, here we do & // assume a 1bpp target - everything beyond 97% // transparency is fully transparent - if( aBmpEx.IsAlpha() && !SkiaHelper::isVCLSkiaEnabled()) + if( aBmp.HasAlpha() && !SkiaHelper::isVCLSkiaEnabled()) { - BitmapFilter::Filter(aBmpEx, BitmapAlphaClampFilter(253)); + BitmapFilter::Filter(aBmp, BitmapAlphaClampFilter(253)); } mp2ndOutDevProvider->getOutDev().DrawBitmapEx( vcl::unotools::pointFromB2DPoint( aOutputPos ), - aBmpEx ); + aBmp ); } // Returning a cache object is not useful, the XBitmap @@ -705,23 +705,23 @@ namespace vclcanvas else if( mpOutDevProvider->getOutDev().HasFastDrawTransformedBitmap()) { ::basegfx::B2DHomMatrix aSizeTransform; - aSizeTransform.scale( aBmpEx.GetSizePixel().Width(), aBmpEx.GetSizePixel().Height() ); + aSizeTransform.scale( aBmp.GetSizePixel().Width(), aBmp.GetSizePixel().Height() ); aMatrix = aMatrix * aSizeTransform; const double fAlpha = bModulateColors ? renderState.DeviceColor[3] : 1.0; - mpOutDevProvider->getOutDev().DrawTransformedBitmapEx( aMatrix, aBmpEx, fAlpha ); + mpOutDevProvider->getOutDev().DrawTransformedBitmapEx( aMatrix, aBmp, fAlpha ); if( mp2ndOutDevProvider ) { - if( aBmpEx.IsAlpha() ) + if( aBmp.HasAlpha() ) { // tdf#157790 invert alpha mask // Due to commit 81994cb2b8b32453a92bcb011830fcb884f22ff3, // the alpha mask needs to be inverted. Note: when // testing tdf#157790, this code only gets executed // when Skia is enabled. - AlphaMask aAlpha( aBmpEx.GetAlphaMask() ); + AlphaMask aAlpha( BitmapEx(aBmp).GetAlphaMask() ); aAlpha.Invert(); - aBmpEx = BitmapEx( aBmpEx.GetBitmap(), aAlpha ); + aBmp = Bitmap(BitmapEx( BitmapEx(aBmp).GetBitmap(), aAlpha )); // HACK. Normally, CanvasHelper does not care about // actually what mp2ndOutDev is... well, here we do & @@ -729,11 +729,11 @@ namespace vclcanvas // transparency is fully transparent if( !SkiaHelper::isVCLSkiaEnabled()) { - BitmapFilter::Filter(aBmpEx, BitmapAlphaClampFilter(253)); + BitmapFilter::Filter(aBmp, BitmapAlphaClampFilter(253)); } } - mp2ndOutDevProvider->getOutDev().DrawTransformedBitmapEx( aMatrix, aBmpEx ); + mp2ndOutDevProvider->getOutDev().DrawTransformedBitmapEx( aMatrix, aBmp ); } return uno::Reference< rendering::XCachedPrimitive >(nullptr); } @@ -750,7 +750,7 @@ namespace vclcanvas GraphicAttr aGrfAttr; GraphicObjectSharedPtr pGrfObj; - ::Size aBmpSize( aBmpEx.GetSizePixel() ); + ::Size aBmpSize( aBmp.GetSizePixel() ); // setup alpha modulation if( bModulateColors ) @@ -788,7 +788,7 @@ namespace vclcanvas const double nAngleInTenthOfDegrees (3600.0 - basegfx::rad2deg<10>(nRotate)); aGrfAttr.SetRotation( Degree10(::basegfx::fround(nAngleInTenthOfDegrees)) ); - pGrfObj = std::make_shared<GraphicObject>( aBmpEx ); + pGrfObj = std::make_shared<GraphicObject>( aBmp ); } else { @@ -807,17 +807,16 @@ namespace vclcanvas // complex transformation, use generic affine bitmap // transformation - aBmpEx = tools::transformBitmap( aBmpEx, - aMatrix ); + aBmp = tools::transformBitmap( aBmp, aMatrix ); - pGrfObj = std::make_shared<GraphicObject>( aBmpEx ); + pGrfObj = std::make_shared<GraphicObject>( aBmp ); // clear scale values, generated bitmap already // contains scaling aScale.setX( 1.0 ); aScale.setY( 1.0 ); // update bitmap size, bitmap has changed above. - aBmpSize = aBmpEx.GetSizePixel(); + aBmpSize = aBmp.GetSizePixel(); } // output GraphicObject @@ -833,16 +832,16 @@ namespace vclcanvas if( mp2ndOutDevProvider ) { GraphicObjectSharedPtr p2ndGrfObj = pGrfObj; - if( aBmpEx.IsAlpha() ) + if( aBmp.HasAlpha() ) { // tdf#157790 invert alpha mask // Due to commit 81994cb2b8b32453a92bcb011830fcb884f22ff3, // the alpha mask needs to be inverted. Note: when // testing tdf#157790, this code only gets executed // when Skia is disabled. - AlphaMask aAlpha( aBmpEx.GetAlphaMask() ); + AlphaMask aAlpha( BitmapEx(aBmp).GetAlphaMask() ); aAlpha.Invert(); - BitmapEx a2ndBmpEx( aBmpEx.GetBitmap(), aAlpha ); + BitmapEx a2ndBmpEx( BitmapEx(aBmp).GetBitmap(), aAlpha ); p2ndGrfObj = std::make_shared<GraphicObject>( a2ndBmpEx ); } @@ -922,7 +921,7 @@ namespace vclcanvas const Point aEmptyPoint(0,0); const Size aBmpSize( rOutDev.GetOutputSizePixel() ); - BitmapEx aBitmap( rOutDev.GetBitmap(aEmptyPoint, aBmpSize) ); + ::Bitmap aBitmap( rOutDev.GetBitmap(aEmptyPoint, aBmpSize) ); aBitmap.Scale( vcl::unotools::sizeFromRealSize2D(newSize), beFast ? BmpScaleFlag::Default : BmpScaleFlag::BestQuality ); diff --git a/canvas/source/vcl/canvashelper_texturefill.cxx b/canvas/source/vcl/canvashelper_texturefill.cxx index 1e4251ca0d3e..aa94de3f1d0f 100644 --- a/canvas/source/vcl/canvashelper_texturefill.cxx +++ b/canvas/source/vcl/canvashelper_texturefill.cxx @@ -748,7 +748,7 @@ namespace vclcanvas // texturing parameters // =========================================== - BitmapEx aBmpEx( tools::bitmapExFromXBitmap( textures[0].Bitmap ) ); + ::Bitmap aBmp( tools::bitmapFromXBitmap( textures[0].Bitmap ) ); // scale down bitmap to [0,1]x[0,1] rect, as required // from the XCanvas interface. @@ -797,7 +797,7 @@ namespace vclcanvas const double nAngleInTenthOfDegrees (3600.0 - basegfx::rad2deg<10>(nRotate)); aGrfAttr.SetRotation( Degree10(::basegfx::fround(nAngleInTenthOfDegrees)) ); - pGrfObj = std::make_shared<GraphicObject>( aBmpEx ); + pGrfObj = std::make_shared<GraphicObject>( aBmp ); } else { @@ -816,17 +816,16 @@ namespace vclcanvas // complex transformation, use generic affine bitmap // transformation - aBmpEx = tools::transformBitmap( aBmpEx, - aTotalTransform); + aBmp = tools::transformBitmap( aBmp, aTotalTransform); - pGrfObj = std::make_shared<GraphicObject>( aBmpEx ); + pGrfObj = std::make_shared<GraphicObject>( aBmp ); // clear scale values, generated bitmap already // contains scaling aScale.setX( 1.0 ); aScale.setY( 1.0 ); // update bitmap size, bitmap has changed above. - aBmpSize = vcl::unotools::integerSize2DFromSize(aBmpEx.GetSizePixel()); + aBmpSize = vcl::unotools::integerSize2DFromSize(aBmp.GetSizePixel()); } diff --git a/canvas/source/vcl/impltools.cxx b/canvas/source/vcl/impltools.cxx index aa6c04f62b80..e54d737c19ba 100644 --- a/canvas/source/vcl/impltools.cxx +++ b/canvas/source/vcl/impltools.cxx @@ -46,7 +46,7 @@ using namespace ::com::sun::star; namespace vclcanvas::tools { - ::BitmapEx bitmapExFromXBitmap( const uno::Reference< rendering::XBitmap >& xBitmap ) + ::Bitmap bitmapFromXBitmap( const uno::Reference< rendering::XBitmap >& xBitmap ) { // TODO(F3): CanvasCustomSprite should also be tunnelled // through (also implements XIntegerBitmap interface) @@ -64,24 +64,23 @@ namespace vclcanvas::tools // TODO(F3): mind the plain Canvas impl. Consolidate with CWS canvas05 const ::OutputDevice& rDev( pCanvasImpl->getBackBuffer()->getOutDev() ); const ::Point aEmptyPoint; - return BitmapEx(rDev.GetBitmap( aEmptyPoint, - rDev.GetOutputSizePixel() )); + return rDev.GetBitmap( aEmptyPoint, rDev.GetOutputSizePixel() ); } // TODO(F2): add support for floating point bitmap formats uno::Reference< rendering::XIntegerReadOnlyBitmap > xIntBmp( xBitmap, uno::UNO_QUERY_THROW ); - ::BitmapEx aBmpEx = vcl::unotools::bitmapExFromXBitmap( xIntBmp ); - if( !aBmpEx.IsEmpty() ) - return aBmpEx; + ::Bitmap aBmp = vcl::unotools::bitmapFromXBitmap( xIntBmp ); + if( !aBmp.IsEmpty() ) + return aBmp; // TODO(F1): extract pixel from XBitmap interface ENSURE_OR_THROW( false, "bitmapExFromXBitmap(): could not extract bitmap" ); } - return ::BitmapEx(); + return ::Bitmap(); } bool setupFontTransform( ::Point& o_rPoint, @@ -212,8 +211,8 @@ namespace vclcanvas::tools return ::tools::PolyPolygon( aTemp ); } - ::BitmapEx transformBitmap( const BitmapEx& rBitmap, - const ::basegfx::B2DHomMatrix& rTransform ) + ::Bitmap transformBitmap( const ::Bitmap& rBitmap, + const ::basegfx::B2DHomMatrix& rTransform ) { SAL_INFO( "canvas.vcl", "::vclcanvas::tools::transformBitmap()" ); SAL_INFO( "canvas.vcl", "::vclcanvas::tools::transformBitmap: 0x" << std::hex << &rBitmap ); @@ -240,7 +239,7 @@ namespace vclcanvas::tools aSrcRect, rTransform ); - return BitmapEx(vcl::bitmap::CanvasTransformBitmap(Bitmap(rBitmap), rTransform, aDestRect, aLocalTransform)); + return vcl::bitmap::CanvasTransformBitmap(rBitmap, rTransform, aDestRect, aLocalTransform); } void SetDefaultDeviceAntiAliasing( OutputDevice* pDevice ) diff --git a/canvas/source/vcl/impltools.hxx b/canvas/source/vcl/impltools.hxx index 4a25585ec2b9..26b5a8cbf05e 100644 --- a/canvas/source/vcl/impltools.hxx +++ b/canvas/source/vcl/impltools.hxx @@ -51,8 +51,8 @@ namespace vclcanvas { namespace tools { - ::BitmapEx - bitmapExFromXBitmap( const css::uno::Reference< + ::Bitmap + bitmapFromXBitmap( const css::uno::Reference< css::rendering::XBitmap >& ); /** Setup VCL font and output position @@ -149,8 +149,8 @@ namespace vclcanvas const css::rendering::ViewState& rViewState, const css::rendering::RenderState& rRenderState ); - ::BitmapEx transformBitmap( const BitmapEx& rBitmap, - const ::basegfx::B2DHomMatrix& rTransform ); + ::Bitmap transformBitmap( const ::Bitmap& rBitmap, + const ::basegfx::B2DHomMatrix& rTransform ); void SetDefaultDeviceAntiAliasing( OutputDevice* pDevice ); } diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx index 9f9b04b34e93..d136e259cddd 100644 --- a/include/vcl/outdev.hxx +++ b/include/vcl/outdev.hxx @@ -1402,6 +1402,10 @@ public: const basegfx::B2DHomMatrix& rTransformation, const BitmapEx& rBitmapEx, double fAlpha = 1.0); + void DrawTransformedBitmapEx( + const basegfx::B2DHomMatrix& rTransformation, + const Bitmap& rBitmap, + double fAlpha = 1.0); /** Return true if DrawTransformedBitmapEx() is fast. diff --git a/vcl/source/outdev/bitmapex.cxx b/vcl/source/outdev/bitmapex.cxx index 1fc131575595..fd97b1afe415 100644 --- a/vcl/source/outdev/bitmapex.cxx +++ b/vcl/source/outdev/bitmapex.cxx @@ -440,6 +440,14 @@ struct LocalTimeTest }; #endif +void OutputDevice::DrawTransformedBitmapEx( + const basegfx::B2DHomMatrix& rTransformation, + const Bitmap& rBitmap, + double fAlpha) +{ + DrawTransformedBitmapEx(rTransformation, BitmapEx(rBitmap), fAlpha); +} + void OutputDevice::DrawTransformedBitmapEx( const basegfx::B2DHomMatrix& rTransformation, const BitmapEx& rBitmapEx, commit ab83cea313cfc97cabb8fe4e7613d3f0d21aaafe Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Aug 5 12:12:22 2025 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Aug 5 15:50:42 2025 +0200 BitmapEx->Bitmap in CanvasTransformBitmap now that Bitmap can handle transparency Change-Id: I09c2f4a5a22c6e8162c325bd7f364dfcd808e3e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188943 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/canvas/source/vcl/impltools.cxx b/canvas/source/vcl/impltools.cxx index 3506cb6a0d11..aa6c04f62b80 100644 --- a/canvas/source/vcl/impltools.cxx +++ b/canvas/source/vcl/impltools.cxx @@ -240,7 +240,7 @@ namespace vclcanvas::tools aSrcRect, rTransform ); - return vcl::bitmap::CanvasTransformBitmap(rBitmap, rTransform, aDestRect, aLocalTransform); + return BitmapEx(vcl::bitmap::CanvasTransformBitmap(Bitmap(rBitmap), rTransform, aDestRect, aLocalTransform)); } void SetDefaultDeviceAntiAliasing( OutputDevice* pDevice ) diff --git a/include/vcl/BitmapTools.hxx b/include/vcl/BitmapTools.hxx index 15d731b02da0..b2cbc868d995 100644 --- a/include/vcl/BitmapTools.hxx +++ b/include/vcl/BitmapTools.hxx @@ -63,7 +63,7 @@ Bitmap VCL_DLLPUBLIC CreateFromData( RawBitmap && data ); VCL_DLLPUBLIC BitmapEx* CreateFromCairoSurface(Size size, cairo_surface_t* pSurface); #endif -VCL_DLLPUBLIC BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap, +VCL_DLLPUBLIC ::Bitmap CanvasTransformBitmap( const ::Bitmap& rBitmap, const ::basegfx::B2DHomMatrix& rTransform, ::basegfx::B2DRectangle const & rDestRect, ::basegfx::B2DHomMatrix const & rLocalTransform ); diff --git a/vcl/source/bitmap/BitmapTools.cxx b/vcl/source/bitmap/BitmapTools.cxx index a6753c809993..a48270bab507 100644 --- a/vcl/source/bitmap/BitmapTools.cxx +++ b/vcl/source/bitmap/BitmapTools.cxx @@ -393,7 +393,7 @@ BitmapEx* CreateFromCairoSurface(Size aSize, cairo_surface_t * pSurface) } #endif -BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap, +Bitmap CanvasTransformBitmap( const Bitmap& rSrcBitmap, const ::basegfx::B2DHomMatrix& rTransform, ::basegfx::B2DRectangle const & rDestRect, ::basegfx::B2DHomMatrix const & rLocalTransform ) @@ -402,25 +402,16 @@ BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap, ::basegfx::fround<tools::Long>( rDestRect.getHeight() ) ); if( aDestBmpSize.IsEmpty() ) - return BitmapEx(); + return Bitmap(); - const Size aBmpSize( rBitmap.GetSizePixel() ); - const Bitmap& aSrcBitmap( rBitmap.GetBitmap() ); - Bitmap aSrcAlpha; + const Size aBmpSize( rSrcBitmap.GetSizePixel() ); // differentiate mask and alpha channel (on-off // vs. multi-level transparency) - if( rBitmap.IsAlpha() ) - { - aSrcAlpha = rBitmap.GetAlphaMask().GetBitmap(); - } - BitmapScopedReadAccess pReadAccess( aSrcBitmap ); - BitmapScopedReadAccess pAlphaReadAccess; - if (rBitmap.IsAlpha()) - pAlphaReadAccess = aSrcAlpha; + BitmapScopedReadAccess pReadAccess( rSrcBitmap ); - if( !pReadAccess || (!pAlphaReadAccess && rBitmap.IsAlpha()) ) + if( !pReadAccess ) { // TODO(E2): Error handling! ENSURE_OR_THROW( false, @@ -432,7 +423,7 @@ BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap, // paletted 1-bit masks). sal_uInt8 aAlphaMap[256]; - if( rBitmap.IsAlpha() ) + if( rSrcBitmap.HasAlpha() ) { // source already has alpha channel - 1:1 mapping, // i.e. aAlphaMap[0]=0,...,aAlphaMap[255]=255. @@ -444,8 +435,7 @@ BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap, } // else: mapping table is not used - Bitmap aDstBitmap(aDestBmpSize, aSrcBitmap.getPixelFormat(), &pReadAccess->GetPalette()); - Bitmap aDstAlpha( AlphaMask( aDestBmpSize ).GetBitmap() ); + Bitmap aDstBitmap(aDestBmpSize, rSrcBitmap.getPixelFormat(), &pReadAccess->GetPalette()); { // just to be on the safe side: let the @@ -454,11 +444,8 @@ BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap, // rule out the possibility that cached accessor data // is not yet written back. BitmapScopedWriteAccess pWriteAccess( aDstBitmap ); - BitmapScopedWriteAccess pAlphaWriteAccess( aDstAlpha ); - if( pWriteAccess.get() != nullptr && - pAlphaWriteAccess.get() != nullptr && rTransform.isInvertible() ) { // we're doing inverse mapping here, i.e. mapping @@ -472,10 +459,9 @@ BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap, { // differentiate mask and alpha channel (on-off // vs. multi-level transparency) - if( rBitmap.IsAlpha() ) + if( rSrcBitmap.HasAlpha() ) { Scanline pScan = pWriteAccess->GetScanline( y ); - Scanline pScanAlpha = pAlphaWriteAccess->GetScanline( y ); // Handling alpha and mask just the same... for( tools::Long x=0; x<aDestBmpSize.Width(); ++x ) { @@ -487,20 +473,20 @@ BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap, if( nSrcX < 0 || nSrcX >= aBmpSize.Width() || nSrcY < 0 || nSrcY >= aBmpSize.Height() ) { - pAlphaWriteAccess->SetPixelOnData( pScanAlpha, x, BitmapColor(0) ); + pWriteAccess->SetPixelOnData( pScan, x, BitmapColor(ColorAlpha, 0, 0, 0, 0) ); } else { - const sal_uInt8 cAlphaIdx = pAlphaReadAccess->GetPixelIndex( nSrcY, nSrcX ); - pAlphaWriteAccess->SetPixelOnData( pScanAlpha, x, BitmapColor(aAlphaMap[ cAlphaIdx ]) ); - pWriteAccess->SetPixelOnData( pScan, x, pReadAccess->GetPixel( nSrcY, nSrcX ) ); + BitmapColor aCol = pReadAccess->GetPixel( nSrcY, nSrcX ); + const sal_uInt8 cAlphaIdx = aCol.GetAlpha(); + aCol.SetAlpha(aAlphaMap[ cAlphaIdx ]); + pWriteAccess->SetPixelOnData( pScan, x, aCol ); } } } else { Scanline pScan = pWriteAccess->GetScanline( y ); - Scanline pScanAlpha = pAlphaWriteAccess->GetScanline( y ); for( tools::Long x=0; x<aDestBmpSize.Width(); ++x ) { ::basegfx::B2DPoint aPoint(x,y); @@ -511,13 +497,13 @@ BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap, if( nSrcX < 0 || nSrcX >= aBmpSize.Width() || nSrcY < 0 || nSrcY >= aBmpSize.Height() ) { - pAlphaWriteAccess->SetPixelOnData( pScanAlpha, x, BitmapColor(0) ); + pWriteAccess->SetPixelOnData( pScan, x, BitmapColor(ColorAlpha, 0, 0, 0, 0) ); } else { - pAlphaWriteAccess->SetPixelOnData( pScanAlpha, x, BitmapColor(255) ); - pWriteAccess->SetPixelOnData( pScan, x, pReadAccess->GetPixel( nSrcY, - nSrcX ) ); + BitmapColor aCol = pReadAccess->GetPixel( nSrcY, nSrcX ); + aCol.SetAlpha(255); + pWriteAccess->SetPixelOnData( pScan, x, aCol ); } } } @@ -531,7 +517,7 @@ BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap, } } - return BitmapEx(aDstBitmap, AlphaMask(aDstAlpha)); + return aDstBitmap; } void DrawAlphaBitmapAndAlphaGradient(BitmapEx & rBitmapEx, bool bFixedTransparence, float fTransparence, const AlphaMask & rNewMask)