BitmapEx->Bitmap in DiscreteShadow

now that Bitmap supports transparency

Change-Id: Ic8ea9d519378b73e7b97c2fbca3f50c53be29a70
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189071
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2025-08-08 09:02:21 +02:00
parent 2cb59865f7
commit 0e45308b44
4 changed files with 75 additions and 75 deletions
@@ -29,25 +29,25 @@
namespace drawinglayer::primitive2d
{
DiscreteShadow::DiscreteShadow(const BitmapEx& rBitmapEx)
: maBitmapEx(rBitmapEx)
DiscreteShadow::DiscreteShadow(const Bitmap& rBitmap)
: maBitmap(rBitmap)
{
maBitmapEx.Invert(); // convert transparency to alpha
const Size& rBitmapSize = getBitmapEx().GetSizePixel();
maBitmap.Invert(); // convert transparency to alpha
const Size aBitmapSize = getBitmap().GetSizePixel();
if(rBitmapSize.Width() != rBitmapSize.Height() || rBitmapSize.Width() < 7)
if(aBitmapSize.Width() != aBitmapSize.Height() || aBitmapSize.Width() < 7)
{
OSL_ENSURE(false, "DiscreteShadowPrimitive2D: wrong bitmap format (!)");
maBitmapEx = BitmapEx();
maBitmap = Bitmap();
}
}
const BitmapEx& DiscreteShadow::getTopLeft() const
const Bitmap& DiscreteShadow::getTopLeft() const
{
if(maTopLeft.IsEmpty())
{
const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maTopLeft = getBitmapEx();
const sal_Int32 nQuarter((getBitmap().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maTopLeft = getBitmap();
const_cast< DiscreteShadow* >(this)->maTopLeft.Crop(
::tools::Rectangle(Point(0, 0), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
}
@@ -55,12 +55,12 @@ namespace drawinglayer::primitive2d
return maTopLeft;
}
const BitmapEx& DiscreteShadow::getTop() const
const Bitmap& DiscreteShadow::getTop() const
{
if(maTop.IsEmpty())
{
const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maTop = getBitmapEx();
const sal_Int32 nQuarter((getBitmap().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maTop = getBitmap();
const_cast< DiscreteShadow* >(this)->maTop.Crop(
::tools::Rectangle(Point((nQuarter * 2) + 1, 0), Size(1, nQuarter)));
}
@@ -68,12 +68,12 @@ namespace drawinglayer::primitive2d
return maTop;
}
const BitmapEx& DiscreteShadow::getTopRight() const
const Bitmap& DiscreteShadow::getTopRight() const
{
if(maTopRight.IsEmpty())
{
const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maTopRight = getBitmapEx();
const sal_Int32 nQuarter((getBitmap().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maTopRight = getBitmap();
const_cast< DiscreteShadow* >(this)->maTopRight.Crop(
::tools::Rectangle(Point((nQuarter * 2) + 2, 0), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
}
@@ -81,12 +81,12 @@ namespace drawinglayer::primitive2d
return maTopRight;
}
const BitmapEx& DiscreteShadow::getRight() const
const Bitmap& DiscreteShadow::getRight() const
{
if(maRight.IsEmpty())
{
const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maRight = getBitmapEx();
const sal_Int32 nQuarter((getBitmap().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maRight = getBitmap();
const_cast< DiscreteShadow* >(this)->maRight.Crop(
::tools::Rectangle(Point((nQuarter * 3) + 3, (nQuarter * 2) + 1), Size(nQuarter, 1)));
}
@@ -94,12 +94,12 @@ namespace drawinglayer::primitive2d
return maRight;
}
const BitmapEx& DiscreteShadow::getBottomRight() const
const Bitmap& DiscreteShadow::getBottomRight() const
{
if(maBottomRight.IsEmpty())
{
const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maBottomRight = getBitmapEx();
const sal_Int32 nQuarter((getBitmap().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maBottomRight = getBitmap();
const_cast< DiscreteShadow* >(this)->maBottomRight.Crop(
::tools::Rectangle(Point((nQuarter * 2) + 2, (nQuarter * 2) + 2), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
}
@@ -107,12 +107,12 @@ namespace drawinglayer::primitive2d
return maBottomRight;
}
const BitmapEx& DiscreteShadow::getBottom() const
const Bitmap& DiscreteShadow::getBottom() const
{
if(maBottom.IsEmpty())
{
const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maBottom = getBitmapEx();
const sal_Int32 nQuarter((getBitmap().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maBottom = getBitmap();
const_cast< DiscreteShadow* >(this)->maBottom.Crop(
::tools::Rectangle(Point((nQuarter * 2) + 1, (nQuarter * 3) + 3), Size(1, nQuarter)));
}
@@ -120,12 +120,12 @@ namespace drawinglayer::primitive2d
return maBottom;
}
const BitmapEx& DiscreteShadow::getBottomLeft() const
const Bitmap& DiscreteShadow::getBottomLeft() const
{
if(maBottomLeft.IsEmpty())
{
const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maBottomLeft = getBitmapEx();
const sal_Int32 nQuarter((getBitmap().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maBottomLeft = getBitmap();
const_cast< DiscreteShadow* >(this)->maBottomLeft.Crop(
::tools::Rectangle(Point(0, (nQuarter * 2) + 2), Size((nQuarter * 2) + 1, (nQuarter * 2) + 1)));
}
@@ -133,12 +133,12 @@ namespace drawinglayer::primitive2d
return maBottomLeft;
}
const BitmapEx& DiscreteShadow::getLeft() const
const Bitmap& DiscreteShadow::getLeft() const
{
if(maLeft.IsEmpty())
{
const sal_Int32 nQuarter((getBitmapEx().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maLeft = getBitmapEx();
const sal_Int32 nQuarter((getBitmap().GetSizePixel().Width() - 3) >> 2);
const_cast< DiscreteShadow* >(this)->maLeft = getBitmap();
const_cast< DiscreteShadow* >(this)->maLeft.Crop(
::tools::Rectangle(Point(0, (nQuarter * 2) + 1), Size(nQuarter, 1)));
}
@@ -155,10 +155,10 @@ namespace drawinglayer::primitive2d
{
Primitive2DContainer xRetval;
if(getDiscreteShadow().getBitmapEx().IsEmpty())
if(getDiscreteShadow().getBitmap().IsEmpty())
return nullptr;
const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2);
const sal_Int32 nQuarter((getDiscreteShadow().getBitmap().GetSizePixel().Width() - 3) >> 2);
const basegfx::B2DVector aScale(getTransform() * basegfx::B2DVector(1.0, 1.0));
const double fSingleX(getDiscreteUnit() / aScale.getX());
const double fSingleY(getDiscreteUnit() / aScale.getY());
@@ -172,7 +172,7 @@ namespace drawinglayer::primitive2d
// TopLeft
xRetval[0] =
new BitmapPrimitive2D(
getDiscreteShadow().getTopLeft(),
BitmapEx(getDiscreteShadow().getTopLeft()),
basegfx::utils::createScaleTranslateB2DHomMatrix(
fBigLenX,
fBigLenY,
@@ -182,7 +182,7 @@ namespace drawinglayer::primitive2d
// Top
xRetval[1] =
new BitmapPrimitive2D(
getDiscreteShadow().getTop(),
BitmapEx(getDiscreteShadow().getTop()),
basegfx::utils::createScaleTranslateB2DHomMatrix(
1.0 - (2.0 * (fBorderX + fSingleX)) + fSingleX,
fBorderY,
@@ -192,7 +192,7 @@ namespace drawinglayer::primitive2d
// TopRight
xRetval[2] =
new BitmapPrimitive2D(
getDiscreteShadow().getTopRight(),
BitmapEx(getDiscreteShadow().getTopRight()),
basegfx::utils::createScaleTranslateB2DHomMatrix(
fBigLenX,
fBigLenY,
@@ -202,7 +202,7 @@ namespace drawinglayer::primitive2d
// Right
xRetval[3] =
new BitmapPrimitive2D(
getDiscreteShadow().getRight(),
BitmapEx(getDiscreteShadow().getRight()),
basegfx::utils::createScaleTranslateB2DHomMatrix(
fBorderX,
1.0 - (2.0 * (fBorderY + fSingleY)) + fSingleY,
@@ -212,7 +212,7 @@ namespace drawinglayer::primitive2d
// BottomRight
xRetval[4] =
new BitmapPrimitive2D(
getDiscreteShadow().getBottomRight(),
BitmapEx(getDiscreteShadow().getBottomRight()),
basegfx::utils::createScaleTranslateB2DHomMatrix(
fBigLenX,
fBigLenY,
@@ -222,7 +222,7 @@ namespace drawinglayer::primitive2d
// Bottom
xRetval[5] =
new BitmapPrimitive2D(
getDiscreteShadow().getBottom(),
BitmapEx(getDiscreteShadow().getBottom()),
basegfx::utils::createScaleTranslateB2DHomMatrix(
1.0 - (2.0 * (fBorderX + fSingleX)) + fSingleX,
fBorderY,
@@ -232,7 +232,7 @@ namespace drawinglayer::primitive2d
// BottomLeft
xRetval[6] =
new BitmapPrimitive2D(
getDiscreteShadow().getBottomLeft(),
BitmapEx(getDiscreteShadow().getBottomLeft()),
basegfx::utils::createScaleTranslateB2DHomMatrix(
fBigLenX,
fBigLenY,
@@ -242,7 +242,7 @@ namespace drawinglayer::primitive2d
// Left
xRetval[7] =
new BitmapPrimitive2D(
getDiscreteShadow().getLeft(),
BitmapEx(getDiscreteShadow().getLeft()),
basegfx::utils::createScaleTranslateB2DHomMatrix(
fBorderX,
1.0 - (2.0 * (fBorderY + fSingleY)) + fSingleY,
@@ -279,7 +279,7 @@ namespace drawinglayer::primitive2d
basegfx::B2DRange DiscreteShadowPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
{
if(getDiscreteShadow().getBitmapEx().IsEmpty())
if(getDiscreteShadow().getBitmap().IsEmpty())
{
// no graphics without valid bitmap definition
return basegfx::B2DRange();
@@ -292,7 +292,7 @@ namespace drawinglayer::primitive2d
// extract discrete shadow size and grow
const basegfx::B2DVector aScale(rViewInformation.getViewTransformation() * basegfx::B2DVector(1.0, 1.0));
const sal_Int32 nQuarter((getDiscreteShadow().getBitmapEx().GetSizePixel().Width() - 3) >> 2);
const sal_Int32 nQuarter((getDiscreteShadow().getBitmap().GetSizePixel().Width() - 3) >> 2);
const double fGrowX((1.0 / aScale.getX()) * nQuarter);
const double fGrowY((1.0 / aScale.getY()) * nQuarter);
aRetval.grow(std::max(fGrowX, fGrowY));
@@ -22,7 +22,7 @@
#include <drawinglayer/drawinglayerdllapi.h>
#include <drawinglayer/primitive2d/primitivetools2d.hxx>
#include <vcl/bitmapex.hxx>
#include <vcl/bitmap.hxx>
#include <basegfx/matrix/b2dhommatrix.hxx>
@@ -36,41 +36,41 @@ namespace drawinglayer::primitive2d
class DRAWINGLAYER_DLLPUBLIC DiscreteShadow
{
private:
/// the original shadow BitmapEx in a special form
BitmapEx maBitmapEx;
/// the original shadow Bitmap in a special form
Bitmap maBitmap;
/// buffered extracted parts of CombinedShadow for easier usage
BitmapEx maTopLeft;
BitmapEx maTop;
BitmapEx maTopRight;
BitmapEx maRight;
BitmapEx maBottomRight;
BitmapEx maBottom;
BitmapEx maBottomLeft;
BitmapEx maLeft;
Bitmap maTopLeft;
Bitmap maTop;
Bitmap maTopRight;
Bitmap maRight;
Bitmap maBottomRight;
Bitmap maBottom;
Bitmap maBottomLeft;
Bitmap maLeft;
public:
/// constructor
explicit DiscreteShadow(const BitmapEx& rBitmapEx);
explicit DiscreteShadow(const Bitmap& rBitmap);
/// data read access
const BitmapEx& getBitmapEx() const { return maBitmapEx; }
const Bitmap& getBitmap() const { return maBitmap; }
/// compare operator
bool operator==(const DiscreteShadow& rCompare) const
{
return getBitmapEx() == rCompare.getBitmapEx();
return getBitmap() == rCompare.getBitmap();
}
/// helper accesses which create on-demand needed segments
const BitmapEx& getTopLeft() const;
const BitmapEx& getTop() const;
const BitmapEx& getTopRight() const;
const BitmapEx& getRight() const;
const BitmapEx& getBottomRight() const;
const BitmapEx& getBottom() const;
const BitmapEx& getBottomLeft() const;
const BitmapEx& getLeft() const;
const Bitmap& getTopLeft() const;
const Bitmap& getTop() const;
const Bitmap& getTopRight() const;
const Bitmap& getRight() const;
const Bitmap& getBottomRight() const;
const Bitmap& getBottom() const;
const Bitmap& getBottomLeft() const;
const Bitmap& getLeft() const;
};
/** DiscreteShadowPrimitive2D class
@@ -137,7 +137,7 @@ void ViewContactOfPageShadow::createViewIndependentPrimitive2DSequence(drawingla
else
{
static tools::DeleteOnDeinit< drawinglayer::primitive2d::DiscreteShadow > aDiscreteShadow((
BitmapEx(SIP_SA_PAGESHADOW35X35)));
Bitmap(BitmapEx(SIP_SA_PAGESHADOW35X35))));
if(aDiscreteShadow.get())
{
+10 -10
View File
@@ -6371,8 +6371,8 @@ static void lcl_paintBitmapExToRect(vcl::RenderContext *pOut, const Point& aPoin
SwTaggedPDFHelper aTaggedPDFHelper( nullptr, nullptr, nullptr, *_pViewShell->GetOut() );
static tools::DeleteOnDeinit<drawinglayer::primitive2d::DiscreteShadow> shadowMaskObj(
BitmapEx(vcl::bitmap::loadFromName(BMP_PAGE_SHADOW_MASK,
ImageLoadFlags::IgnoreDarkTheme | ImageLoadFlags::IgnoreScalingFactor)));
vcl::bitmap::loadFromName(BMP_PAGE_SHADOW_MASK,
ImageLoadFlags::IgnoreDarkTheme | ImageLoadFlags::IgnoreScalingFactor));
drawinglayer::primitive2d::DiscreteShadow& shadowMask = *shadowMaskObj.get();
static tools::DeleteOnDeinit< BitmapEx > aPageTopRightShadowObj {};
@@ -6401,42 +6401,42 @@ static void lcl_paintBitmapExToRect(vcl::RenderContext *pOut, const Point& aPoin
{
aShadowColor = _pViewShell->GetViewOptions()->GetShadowColor();
AlphaMask aMask( shadowMask.getBottomRight().GetBitmap() );
AlphaMask aMask( BitmapEx(shadowMask.getBottomRight()).GetBitmap() );
Bitmap aFilledSquare(aMask.GetSizePixel(), vcl::PixelFormat::N24_BPP);
aFilledSquare.Erase( aShadowColor );
aPageBottomRightShadow = BitmapEx( aFilledSquare, aMask );
aMask = AlphaMask( shadowMask.getBottomLeft().GetBitmap() );
aMask = AlphaMask( BitmapEx(shadowMask.getBottomLeft()).GetBitmap() );
aFilledSquare = Bitmap(aMask.GetSizePixel(), vcl::PixelFormat::N24_BPP);
aFilledSquare.Erase( aShadowColor );
aPageBottomLeftShadow = BitmapEx( aFilledSquare, aMask );
aMask = AlphaMask( shadowMask.getBottom().GetBitmap() );
aMask = AlphaMask( BitmapEx(shadowMask.getBottom()).GetBitmap() );
aFilledSquare = Bitmap(aMask.GetSizePixel(), vcl::PixelFormat::N24_BPP);
aFilledSquare.Erase( aShadowColor );
aPageBottomShadow = BitmapEx( aFilledSquare, aMask );
aMask = AlphaMask( shadowMask.getTop().GetBitmap() );
aMask = AlphaMask( BitmapEx(shadowMask.getTop()).GetBitmap() );
aFilledSquare = Bitmap(aMask.GetSizePixel(), vcl::PixelFormat::N24_BPP);
aFilledSquare.Erase( aShadowColor );
aPageTopShadow = BitmapEx( aFilledSquare, aMask );
aMask = AlphaMask( shadowMask.getTopRight().GetBitmap() );
aMask = AlphaMask( BitmapEx(shadowMask.getTopRight()).GetBitmap() );
aFilledSquare = Bitmap(aMask.GetSizePixel(), vcl::PixelFormat::N24_BPP);
aFilledSquare.Erase( aShadowColor );
aPageTopRightShadow = BitmapEx( aFilledSquare, aMask );
aMask = AlphaMask( shadowMask.getRight().GetBitmap() );
aMask = AlphaMask( BitmapEx(shadowMask.getRight()).GetBitmap() );
aFilledSquare = Bitmap(aMask.GetSizePixel(), vcl::PixelFormat::N24_BPP);
aFilledSquare.Erase( aShadowColor );
aPageRightShadow = BitmapEx( aFilledSquare, aMask );
aMask = AlphaMask( shadowMask.getTopLeft().GetBitmap() );
aMask = AlphaMask( BitmapEx(shadowMask.getTopLeft()).GetBitmap() );
aFilledSquare = Bitmap(aMask.GetSizePixel(), vcl::PixelFormat::N24_BPP);
aFilledSquare.Erase( aShadowColor );
aPageTopLeftShadow = BitmapEx( aFilledSquare, aMask );
aMask = AlphaMask( shadowMask.getLeft().GetBitmap() );
aMask = AlphaMask( BitmapEx(shadowMask.getLeft()).GetBitmap() );
aFilledSquare = Bitmap(aMask.GetSizePixel(), vcl::PixelFormat::N24_BPP);
aFilledSquare.Erase( aShadowColor );
aPageLeftShadow = BitmapEx( aFilledSquare, aMask );