BitmapEx->Bitmap in convertMetafileToBitmap

now that Bitmap can handle transparency

Change-Id: Iba7fc9164e7dfc0c84a5c13f8336cba0820a3ce7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188967
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2025-08-05 21:07:44 +02:00
parent 0dd4b24405
commit 282c6ade09
7 changed files with 52 additions and 67 deletions
+2 -2
View File
@@ -65,10 +65,10 @@ public:
class SdrPaintWindow;
/**
* Helper to convert any GDIMetaFile to a good quality BitmapEx,
* Helper to convert any GDIMetaFile to a good quality Bitmap,
* using default parameters and graphic::XPrimitive2DRenderer
*/
BitmapEx convertMetafileToBitmapEx(
Bitmap convertMetafileToBitmap(
const GDIMetaFile& rMtf,
const basegfx::B2DRange& rTargetRange,
const sal_uInt32 nMaximumQuadraticPixels);
+1 -1
View File
@@ -68,7 +68,7 @@ VCL_DLLPUBLIC ::Bitmap CanvasTransformBitmap( const ::Bitmap& rBitmap,
::basegfx::B2DRectangle const & rDestRect,
::basegfx::B2DHomMatrix const & rLocalTransform );
VCL_DLLPUBLIC void DrawAlphaBitmapAndAlphaGradient(BitmapEx & rBitmapEx, bool bFixedTransparence, float fTransparence, const AlphaMask & rNewMask);
VCL_DLLPUBLIC void DrawAlphaBitmapAndAlphaGradient(Bitmap & rBitmap, bool bFixedTransparence, float fTransparence, const AlphaMask & rNewMask);
VCL_DLLPUBLIC void DrawAndClipBitmap(const Point& rPos, const Size& rSize, const BitmapEx& rBitmap, BitmapEx & aBmpEx, basegfx::B2DPolyPolygon const & rClipPath);
+2 -2
View File
@@ -21,14 +21,14 @@
#include <sal/config.h>
#include <vcl/bitmapex.hxx>
#include <vcl/bitmap.hxx>
#include <vcl/graph.hxx>
class Size;
class GDIMetaFile;
class SdrObject;
BitmapEx GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize);
Bitmap GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize);
Graphic SvxGetGraphicForShape(SdrObject& rShape);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
+9 -9
View File
@@ -1513,9 +1513,9 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction const & rAct)
const tools::Rectangle aRect(rAct.GetPoint(),rAct.GetSize());
// convert metafile sub-content to BitmapEx
BitmapEx aBitmapEx(
convertMetafileToBitmapEx(
// convert metafile sub-content to Bitmap
Bitmap aBitmap(
convertMetafileToBitmap(
rMtf,
vcl::unotools::b2DRectangleFromRectangle(aRect),
125000));
@@ -1569,7 +1569,7 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction const & rAct)
// gradient transparence
ScopedVclPtrInstance< VirtualDevice > pVDev;
pVDev->SetOutputSizePixel(aBitmapEx.GetBitmap().GetSizePixel());
pVDev->SetOutputSizePixel(aBitmap.GetSizePixel());
pVDev->DrawGradient(tools::Rectangle(Point(0, 0), pVDev->GetOutputSizePixel()), rGradient);
aNewMask = AlphaMask(pVDev->GetBitmap(Point(0, 0), pVDev->GetOutputSizePixel()));
@@ -1582,28 +1582,28 @@ void ImpSdrGDIMetaFileImport::DoAction(MetaFloatTransparentAction const & rAct)
if(bHasNewMask || bFixedTransparence)
{
if(!aBitmapEx.IsAlpha())
if(!aBitmap.HasAlpha())
{
// no transparence yet, apply new one
if(bFixedTransparence)
{
sal_uInt8 nTransparence(basegfx::fround(fTransparence * 255.0));
aNewMask = AlphaMask(aBitmapEx.GetBitmap().GetSizePixel(), &nTransparence);
aNewMask = AlphaMask(aBitmap.GetSizePixel(), &nTransparence);
}
aBitmapEx = BitmapEx(aBitmapEx.GetBitmap(), aNewMask);
aBitmap = Bitmap(BitmapEx(BitmapEx(aBitmap).GetBitmap(), aNewMask));
}
else
{
vcl::bitmap::DrawAlphaBitmapAndAlphaGradient(aBitmapEx, bFixedTransparence, fTransparence, aNewMask);
vcl::bitmap::DrawAlphaBitmapAndAlphaGradient(aBitmap, bFixedTransparence, fTransparence, aNewMask);
}
}
// create and add object
rtl::Reference<SdrGrafObj> pGraf = new SdrGrafObj(
*mpModel,
aBitmapEx,
aBitmap,
aRect);
// for MetaFloatTransparentAction, do not use SetAttributes(...)
+5 -5
View File
@@ -104,12 +104,12 @@ SvxViewChangedHint::SvxViewChangedHint() : SfxHint(SfxHintId::SvxViewChanged)
}
BitmapEx convertMetafileToBitmapEx(
Bitmap convertMetafileToBitmap(
const GDIMetaFile& rMtf,
const basegfx::B2DRange& rTargetRange,
const sal_uInt32 nMaximumQuadraticPixels)
{
BitmapEx aBitmapEx;
Bitmap aBitmap;
if(rMtf.GetActionSize())
{
@@ -119,13 +119,13 @@ BitmapEx convertMetafileToBitmapEx(
rTargetRange.getRange(),
rTargetRange.getMinimum()),
rMtf));
aBitmapEx = drawinglayer::convertPrimitive2DContainerToBitmapEx(
aBitmap = Bitmap(drawinglayer::convertPrimitive2DContainerToBitmapEx(
drawinglayer::primitive2d::Primitive2DContainer { aMtf },
rTargetRange,
nMaximumQuadraticPixels);
nMaximumQuadraticPixels));
}
return aBitmapEx;
return aBitmap;
}
SdrPaintView::SdrPaintView(SdrModel& rSdrModel, OutputDevice* pOut)
+2 -2
View File
@@ -1271,7 +1271,7 @@ Sequence< OUString > SAL_CALL GraphicExporter::getSupportedMimeTypeNames( )
/** creates a bitmap that is optionally transparent from a metafile
*/
BitmapEx GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize)
Bitmap GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize)
{
// use new primitive conversion tooling
basegfx::B2DRange aRange(basegfx::B2DPoint(0.0, 0.0));
@@ -1302,7 +1302,7 @@ BitmapEx GetBitmapFromMetaFile(const GDIMetaFile& rMtf, const Size* pSize)
nMaximumQuadraticPixels = 2048 * 2048;
}
return convertMetafileToBitmapEx(rMtf, aRange, nMaximumQuadraticPixels);
return convertMetafileToBitmap(rMtf, aRange, nMaximumQuadraticPixels);
}
Graphic SvxGetGraphicForShape( SdrObject& rShape )
+31 -46
View File
@@ -520,67 +520,52 @@ Bitmap CanvasTransformBitmap( const Bitmap& rSrcBitmap,
return aDstBitmap;
}
void DrawAlphaBitmapAndAlphaGradient(BitmapEx & rBitmapEx, bool bFixedTransparence, float fTransparence, const AlphaMask & rNewMask)
// mix existing and new alpha mask
void DrawAlphaBitmapAndAlphaGradient(Bitmap & rBitmap, bool bFixedTransparence, float fTransparence, const AlphaMask & rNewMask)
{
// mix existing and new alpha mask
AlphaMask aOldMask;
const double fFactor(1.0 / 255.0);
BitmapScopedWriteAccess pOld(rBitmap);
assert(pOld && "Got no access to old alpha mask (!)");
if(rBitmapEx.IsAlpha())
if(bFixedTransparence)
{
aOldMask = rBitmapEx.GetAlphaMask();
}
const double fOpNew(1.0 - fTransparence);
{
BitmapScopedWriteAccess pOld(aOldMask);
assert(pOld && "Got no access to old alpha mask (!)");
const double fFactor(1.0 / 255.0);
if(bFixedTransparence)
for(tools::Long y(0),nHeight(pOld->Height()); y < nHeight; y++)
{
const double fOpNew(1.0 - fTransparence);
for(tools::Long y(0),nHeight(pOld->Height()); y < nHeight; y++)
Scanline pScanline = pOld->GetScanline( y );
for(tools::Long x(0),nWidth(pOld->Width()); x < nWidth; x++)
{
Scanline pScanline = pOld->GetScanline( y );
for(tools::Long x(0),nWidth(pOld->Width()); x < nWidth; x++)
{
const double fOpOld(pOld->GetIndexFromData(pScanline, x) * fFactor);
const sal_uInt8 aCol(basegfx::fround((fOpOld * fOpNew) * 255.0));
BitmapColor aCol = pOld->GetPixelFromData(pScanline, x);
const double fOpOld(aCol.GetAlpha() * fFactor);
aCol.SetAlpha(basegfx::fround((fOpOld * fOpNew) * 255.0));
pOld->SetPixelOnData(pScanline, x, BitmapColor(aCol));
}
pOld->SetPixelOnData(pScanline, x, aCol);
}
}
else
}
else
{
BitmapScopedReadAccess pNew(rNewMask);
assert(pNew && "Got no access to new alpha mask (!)");
assert(pOld->Width() == pNew->Width() && pOld->Height() == pNew->Height() &&
"Alpha masks have different sizes (!)");
for(tools::Long y(0),nHeight(pOld->Height()); y < nHeight; y++)
{
BitmapScopedReadAccess pNew(rNewMask);
assert(pNew && "Got no access to new alpha mask (!)");
assert(pOld->Width() == pNew->Width() && pOld->Height() == pNew->Height() &&
"Alpha masks have different sizes (!)");
for(tools::Long y(0),nHeight(pOld->Height()); y < nHeight; y++)
Scanline pScanline = pOld->GetScanline( y );
for(tools::Long x(0),nWidth(pOld->Width()); x < nWidth; x++)
{
Scanline pScanline = pOld->GetScanline( y );
for(tools::Long x(0),nWidth(pOld->Width()); x < nWidth; x++)
{
const double fOpOld(pOld->GetIndexFromData(pScanline, x) * fFactor);
const double fOpNew(pNew->GetIndexFromData(pScanline, x) * fFactor);
const sal_uInt8 aCol(basegfx::fround((fOpOld * fOpNew) * 255.0));
BitmapColor aCol = pOld->GetPixelFromData(pScanline, x);
const double fOpOld(aCol.GetAlpha() * fFactor);
const double fOpNew(pNew->GetIndexFromData(pScanline, x) * fFactor);
aCol.SetAlpha(basegfx::fround((fOpOld * fOpNew) * 255.0));
pOld->SetPixelOnData(pScanline, x, BitmapColor(aCol));
}
pOld->SetPixelOnData(pScanline, x, aCol);
}
}
}
// apply combined bitmap as mask
rBitmapEx = BitmapEx(rBitmapEx.GetBitmap(), aOldMask);
}