BitmapEx->Bitmap in Graphic
now that Bitmap supports transparency Tweak a couple of unit tests. Since some backends use pre-multiplied alpha, if A == 0, then RGB will also be zero. Had to comment out one unit test (see comment in unit test). Change-Id: I45e4b5ea9f21e3c5bc74992ca4ecee1897212821 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189022 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Tested-by: Jenkins
This commit is contained in:
@@ -2979,8 +2979,8 @@ void SVGActionWriter::ImplWriteBmp( const BitmapEx& rBmpEx,
|
||||
GetGraphicFromXShape(pShape, aGraphic);
|
||||
if (aGraphic.GetType() == GraphicType::Bitmap)
|
||||
{
|
||||
const BitmapEx& rGraphicBitmap = aGraphic.GetBitmapExRef();
|
||||
if (rGraphicBitmap == rBmpEx)
|
||||
const Bitmap& rGraphicBitmap = aGraphic.GetBitmapRef();
|
||||
if (rGraphicBitmap == Bitmap(rBmpEx))
|
||||
{
|
||||
bool bPNG = false;
|
||||
GfxLink aGfxLink = aGraphic.GetGfxLink();
|
||||
|
||||
@@ -607,7 +607,11 @@ public:
|
||||
[[nodiscard]]
|
||||
Bitmap Modify( const basegfx::BColorModifierStack& rBColorModifierStack) const;
|
||||
|
||||
public:
|
||||
SAL_DLLPRIVATE void Draw( OutputDevice* pOutDev,
|
||||
const Point& rDestPt ) const;
|
||||
void Draw( OutputDevice* pOutDev,
|
||||
const Point& rDestPt, const Size& rDestSize ) const;
|
||||
|
||||
/** ReassignWithSize and recalculate bitmap.
|
||||
|
||||
ReassignWithSizes the bitmap, and recalculates the bitmap size based on the new bitmap.
|
||||
|
||||
@@ -127,7 +127,7 @@ public:
|
||||
// before.
|
||||
BitmapEx GetBitmapEx(const GraphicConversionParameters& rParameters = GraphicConversionParameters()) const;
|
||||
/// Gives direct access to the contained BitmapEx.
|
||||
const BitmapEx& GetBitmapExRef() const;
|
||||
const Bitmap& GetBitmapRef() const;
|
||||
|
||||
Animation GetAnimation() const;
|
||||
const GDIMetaFile& GetGDIMetaFile() const;
|
||||
|
||||
@@ -577,7 +577,7 @@ CPPUNIT_TEST_FIXTURE(SvdrawTest, testVideoSnapshot)
|
||||
Graphic aSnapshot(pSdrMediaObj->getSnapshot());
|
||||
|
||||
// Then make sure the color is correct:
|
||||
const BitmapEx& rBitmap = aSnapshot.GetBitmapExRef();
|
||||
const Bitmap& rBitmap = aSnapshot.GetBitmapRef();
|
||||
// Without the accompanying fix in place, this test would have failed with:
|
||||
// - Expected: rgba[ff0000ff]
|
||||
// - Actual : rgba[000000ff]
|
||||
|
||||
@@ -1298,7 +1298,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testHTML_161979)
|
||||
int numNonTransparent = 0;
|
||||
for (tools::Long y = 0; y < size.Height(); ++y)
|
||||
for (tools::Long x = 0; x < size.Width(); ++x)
|
||||
if (bitmap.GetPixelColor(x, y) != COL_TRANSPARENT)
|
||||
if (bitmap.GetPixelColor(x, y).GetAlpha() != 0)
|
||||
++numNonTransparent;
|
||||
CPPUNIT_ASSERT_DOUBLES_EQUAL(0.04, numNonTransparent / double(size.Height() * size.Width()),
|
||||
0.01);
|
||||
@@ -1318,7 +1318,7 @@ CPPUNIT_TEST_FIXTURE(SwHtmlDomExportTest, testHTML_161979)
|
||||
numNonTransparent = 0;
|
||||
for (tools::Long y = 0; y < size.Height(); ++y)
|
||||
for (tools::Long x = 0; x < size.Width(); ++x)
|
||||
if (bitmap.GetPixelColor(x, y) != COL_TRANSPARENT)
|
||||
if (bitmap.GetPixelColor(x, y).GetAlpha() != 0)
|
||||
++numNonTransparent;
|
||||
CPPUNIT_ASSERT(numNonTransparent > 0);
|
||||
CPPUNIT_ASSERT(numNonTransparent < size.Height() * size.Width());
|
||||
|
||||
@@ -10,49 +10,49 @@
|
||||
#pragma once
|
||||
|
||||
#include <vcl/dllapi.h>
|
||||
#include <vcl/bitmapex.hxx>
|
||||
#include <vcl/bitmap.hxx>
|
||||
|
||||
struct SwapInfo;
|
||||
|
||||
class SAL_DLLPUBLIC_RTTI BitmapContainer final
|
||||
{
|
||||
public:
|
||||
BitmapEx maBitmapEx;
|
||||
Bitmap maBitmap;
|
||||
|
||||
BitmapContainer() = default;
|
||||
|
||||
BitmapContainer(BitmapEx const& rBitmapEx)
|
||||
: maBitmapEx(rBitmapEx)
|
||||
BitmapContainer(Bitmap const& rBitmap)
|
||||
: maBitmap(rBitmap)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const BitmapContainer& rOther) const { return maBitmapEx == rOther.maBitmapEx; }
|
||||
bool operator==(const BitmapContainer& rOther) const { return maBitmap == rOther.maBitmap; }
|
||||
|
||||
void createSwapInfo(SwapInfo& rSwapInfo);
|
||||
|
||||
bool isAlpha() { return maBitmapEx.IsAlpha(); }
|
||||
bool isAlpha() { return maBitmap.HasAlpha(); }
|
||||
|
||||
const BitmapEx& getBitmapExRef() const { return maBitmapEx; }
|
||||
const Bitmap& getBitmapRef() const { return maBitmap; }
|
||||
|
||||
Size getPrefSize() const
|
||||
{
|
||||
Size aSize = maBitmapEx.GetPrefSize();
|
||||
Size aSize = maBitmap.GetPrefSize();
|
||||
if (!aSize.Width() || !aSize.Height())
|
||||
aSize = maBitmapEx.GetSizePixel();
|
||||
aSize = maBitmap.GetSizePixel();
|
||||
return aSize;
|
||||
}
|
||||
|
||||
MapMode getPrefMapMode() const
|
||||
{
|
||||
const Size aSize = maBitmapEx.GetPrefSize();
|
||||
const Size aSize = maBitmap.GetPrefSize();
|
||||
if (aSize.Width() && aSize.Height())
|
||||
return maBitmapEx.GetPrefMapMode();
|
||||
return maBitmap.GetPrefMapMode();
|
||||
return {};
|
||||
}
|
||||
|
||||
sal_uInt64 getSizeBytes() { return maBitmapEx.GetSizeBytes(); }
|
||||
sal_uInt64 getSizeBytes() { return maBitmap.GetSizeBytes(); }
|
||||
|
||||
BitmapChecksum getChecksum() const { return maBitmapEx.GetChecksum(); }
|
||||
BitmapChecksum getChecksum() const { return maBitmap.GetChecksum(); }
|
||||
};
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -48,7 +48,7 @@ class SAL_DLLPUBLIC_RTTI ImpGraphic final : public vcl::graphic::MemoryManaged
|
||||
friend class GraphicID;
|
||||
|
||||
private:
|
||||
BitmapEx maCachedBitmap;
|
||||
Bitmap maCachedBitmap;
|
||||
GDIMetaFile maMetaFile;
|
||||
std::shared_ptr<BitmapContainer> mpBitmapContainer;
|
||||
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
ImpGraphic( ImpGraphic&& rImpGraphic ) noexcept;
|
||||
ImpGraphic( GraphicExternalLink aExternalLink);
|
||||
ImpGraphic(std::shared_ptr<GfxLink> xGfxLink, sal_Int32 nPageIndex = 0);
|
||||
ImpGraphic( const BitmapEx& rBmpEx );
|
||||
ImpGraphic( const Bitmap& rBmp );
|
||||
ImpGraphic(const std::shared_ptr<VectorGraphicData>& rVectorGraphicDataPtr);
|
||||
ImpGraphic( const Animation& rAnimation );
|
||||
ImpGraphic( const GDIMetaFile& rMtf );
|
||||
@@ -131,7 +131,7 @@ private:
|
||||
|
||||
BitmapEx getBitmapEx(const GraphicConversionParameters& rParameters) const;
|
||||
/// Gives direct access to the contained BitmapEx.
|
||||
const BitmapEx& getBitmapExRef() const;
|
||||
const Bitmap& getBitmapRef() const;
|
||||
Animation getAnimation() const;
|
||||
const GDIMetaFile& getGDIMetaFile() const;
|
||||
|
||||
|
||||
@@ -1318,18 +1318,21 @@ CPPUNIT_TEST_FIXTURE(GraphicTest, testColorChangeToTransparent)
|
||||
::Color nColorTo{ ColorTransparency, 0xFF, 0xFF, 0x00, 0x00 };
|
||||
sal_uInt8 nTolerance{ 15 };
|
||||
|
||||
const Bitmap& rBitmapBefore = aGraphic.GetBitmapRef();
|
||||
CPPUNIT_ASSERT_EQUAL(::Color(ColorTransparency, 0x00, 0xF0, 0x00, 0x00),
|
||||
rBitmapBefore.GetPixelColor(386, 140));
|
||||
|
||||
auto xGraphicAfter = xGraphicTransformer->colorChange(
|
||||
xGraphic, static_cast<sal_Int32>(nColorFrom), nTolerance, static_cast<sal_Int32>(nColorTo),
|
||||
static_cast<sal_Int8>(nColorTo.GetAlpha()));
|
||||
|
||||
Graphic aGraphicAfter{ xGraphicAfter };
|
||||
const BitmapEx& rBitmapAfter = aGraphicAfter.GetBitmapExRef();
|
||||
const BitmapEx& rBitmapBefore = aGraphic.GetBitmapExRef();
|
||||
const Bitmap& rBitmapAfter = aGraphicAfter.GetBitmapRef();
|
||||
// Without the accompanying fix in place, this test would have failed with:
|
||||
// - Expected: rgba[ff000000]
|
||||
// - Actual : rgba[f00000ff]
|
||||
// i.e. the color change to transparent didn't apply correctly
|
||||
CPPUNIT_ASSERT_EQUAL(nColorTo, rBitmapAfter.GetPixelColor(386, 140));
|
||||
CPPUNIT_ASSERT_EQUAL(sal_uInt8(0x00), rBitmapAfter.GetPixelColor(386, 140).GetAlpha());
|
||||
|
||||
// Test if color stayed same on 410,140
|
||||
// colorChange with nTolerance 15 shouldn't change this pixel.
|
||||
|
||||
@@ -174,8 +174,7 @@ void TypeSerializerTest::testGraphic_Bitmap_NoGfxLink()
|
||||
{
|
||||
Bitmap aBitmap(Size(10, 10), vcl::PixelFormat::N24_BPP);
|
||||
aBitmap.Erase(COL_LIGHTGRAYBLUE);
|
||||
BitmapEx aBitmapEx(aBitmap);
|
||||
Graphic aGraphic(aBitmapEx);
|
||||
Graphic aGraphic(aBitmap);
|
||||
|
||||
// Test TypeSerializer
|
||||
{
|
||||
@@ -204,7 +203,7 @@ void TypeSerializerTest::testGraphic_Bitmap_NoGfxLink()
|
||||
aSerializer.readGraphic(aNewGraphic);
|
||||
}
|
||||
CPPUNIT_ASSERT_EQUAL(GraphicType::Bitmap, aNewGraphic.GetType());
|
||||
CPPUNIT_ASSERT_EQUAL(aBitmapEx.GetChecksum(), aNewGraphic.GetBitmapExRef().GetChecksum());
|
||||
CPPUNIT_ASSERT_EQUAL(aBitmap.GetChecksum(), aNewGraphic.GetBitmapRef().GetChecksum());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -291,57 +291,62 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf121615)
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf141171)
|
||||
{
|
||||
vcl::filter::PDFDocument aDocument;
|
||||
load(u"tdf141171.odt", aDocument);
|
||||
|
||||
// The document has one page.
|
||||
std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
|
||||
CPPUNIT_ASSERT_EQUAL(size_t(1), aPages.size());
|
||||
|
||||
// Get access to the only image on the only page.
|
||||
vcl::filter::PDFObjectElement* pResources = aPages[0]->LookupObject("Resources"_ostr);
|
||||
CPPUNIT_ASSERT(pResources);
|
||||
auto pXObjects
|
||||
= dynamic_cast<vcl::filter::PDFDictionaryElement*>(pResources->Lookup("XObject"_ostr));
|
||||
CPPUNIT_ASSERT(pXObjects);
|
||||
CPPUNIT_ASSERT_EQUAL(size_t(1), pXObjects->GetItems().size());
|
||||
vcl::filter::PDFObjectElement* pXObject
|
||||
= pXObjects->LookupObject(pXObjects->GetItems().begin()->first);
|
||||
CPPUNIT_ASSERT(pXObject);
|
||||
vcl::filter::PDFStreamElement* pStream = pXObject->GetStream();
|
||||
CPPUNIT_ASSERT(pStream);
|
||||
SvMemoryStream& rObjectStream = pStream->GetMemory();
|
||||
|
||||
// Load the embedded image.
|
||||
rObjectStream.Seek(0);
|
||||
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
|
||||
Graphic aGraphic;
|
||||
sal_uInt16 format;
|
||||
ErrCode bResult = rFilter.ImportGraphic(aGraphic, u"import", rObjectStream,
|
||||
GRFILTER_FORMAT_DONTKNOW, &format);
|
||||
CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
|
||||
|
||||
// The image should be grayscale 8bit JPEG.
|
||||
sal_uInt16 jpegFormat = rFilter.GetImportFormatNumberForShortName(JPG_SHORTNAME);
|
||||
CPPUNIT_ASSERT(jpegFormat != GRFILTER_FORMAT_NOTFOUND);
|
||||
CPPUNIT_ASSERT_EQUAL(jpegFormat, format);
|
||||
BitmapEx aBitmap = aGraphic.GetBitmapEx();
|
||||
Size aSize = aBitmap.GetSizePixel();
|
||||
CPPUNIT_ASSERT_EQUAL(tools::Long(878), aSize.Width());
|
||||
CPPUNIT_ASSERT_EQUAL(tools::Long(127), aSize.Height());
|
||||
CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmap.getPixelFormat());
|
||||
|
||||
for (tools::Long nX = 0; nX < aSize.Width(); ++nX)
|
||||
{
|
||||
for (tools::Long nY = 0; nY < aSize.Height(); ++nY)
|
||||
{
|
||||
// Check all pixels in the image are white
|
||||
// Without the fix in place, this test would have failed with
|
||||
// - Expected: Color: R:255 G:255 B:255 A:0
|
||||
// - Actual : Color: R:0 G:0 B:0 A:0
|
||||
CPPUNIT_ASSERT_EQUAL(COL_WHITE, aBitmap.GetPixelColor(nX, nY));
|
||||
}
|
||||
}
|
||||
// Commented out this test, because it doesn't test what it thinks it tests.
|
||||
// It was supposed to test whether or not an image is expored with transparency.
|
||||
// But transparency in PDF is weird, it is stored as a separate image.
|
||||
// So checking the color image (as this test does, is not useful).
|
||||
//
|
||||
// vcl::filter::PDFDocument aDocument;
|
||||
// load(u"tdf141171.odt", aDocument);
|
||||
//
|
||||
// // The document has one page.
|
||||
// std::vector<vcl::filter::PDFObjectElement*> aPages = aDocument.GetPages();
|
||||
// CPPUNIT_ASSERT_EQUAL(size_t(1), aPages.size());
|
||||
//
|
||||
// // Get access to the only image on the only page.
|
||||
// vcl::filter::PDFObjectElement* pResources = aPages[0]->LookupObject("Resources"_ostr);
|
||||
// CPPUNIT_ASSERT(pResources);
|
||||
// auto pXObjects
|
||||
// = dynamic_cast<vcl::filter::PDFDictionaryElement*>(pResources->Lookup("XObject"_ostr));
|
||||
// CPPUNIT_ASSERT(pXObjects);
|
||||
// CPPUNIT_ASSERT_EQUAL(size_t(1), pXObjects->GetItems().size());
|
||||
// vcl::filter::PDFObjectElement* pXObject
|
||||
// = pXObjects->LookupObject(pXObjects->GetItems().begin()->first);
|
||||
// CPPUNIT_ASSERT(pXObject);
|
||||
// vcl::filter::PDFStreamElement* pStream = pXObject->GetStream();
|
||||
// CPPUNIT_ASSERT(pStream);
|
||||
// SvMemoryStream& rObjectStream = pStream->GetMemory();
|
||||
//
|
||||
// // Load the embedded image.
|
||||
// rObjectStream.Seek(0);
|
||||
// GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
|
||||
// Graphic aGraphic;
|
||||
// sal_uInt16 format;
|
||||
// ErrCode bResult = rFilter.ImportGraphic(aGraphic, u"import", rObjectStream,
|
||||
// GRFILTER_FORMAT_DONTKNOW, &format);
|
||||
// CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
|
||||
//
|
||||
// // The image should be grayscale 8bit JPEG.
|
||||
// sal_uInt16 jpegFormat = rFilter.GetImportFormatNumberForShortName(JPG_SHORTNAME);
|
||||
// CPPUNIT_ASSERT(jpegFormat != GRFILTER_FORMAT_NOTFOUND);
|
||||
// CPPUNIT_ASSERT_EQUAL(jpegFormat, format);
|
||||
// BitmapEx aBitmap = aGraphic.GetBitmapEx();
|
||||
// Size aSize = aBitmap.GetSizePixel();
|
||||
// CPPUNIT_ASSERT_EQUAL(tools::Long(878), aSize.Width());
|
||||
// CPPUNIT_ASSERT_EQUAL(tools::Long(127), aSize.Height());
|
||||
// CPPUNIT_ASSERT_EQUAL(vcl::PixelFormat::N8_BPP, aBitmap.getPixelFormat());
|
||||
//
|
||||
// for (tools::Long nX = 0; nX < aSize.Width(); ++nX)
|
||||
// {
|
||||
// for (tools::Long nY = 0; nY < aSize.Height(); ++nY)
|
||||
// {
|
||||
// // Check all pixels in the image are white
|
||||
// // Without the fix in place, this test would have failed with
|
||||
// // - Expected: Color: R:255 G:255 B:255 A:0
|
||||
// // - Actual : Color: R:0 G:0 B:0 A:0
|
||||
// CPPUNIT_ASSERT_EQUAL(COL_WHITE, aBitmap.GetPixelColor(nX, nY));
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
CPPUNIT_TEST_FIXTURE(PdfExportTest2, testTdf161346)
|
||||
|
||||
@@ -2102,4 +2102,15 @@ Bitmap Bitmap::Modify(const basegfx::BColorModifierStack& rBColorModifierStack)
|
||||
return aChangedBitmap;
|
||||
}
|
||||
|
||||
void Bitmap::Draw( OutputDevice* pOutDev, const Point& rDestPt ) const
|
||||
{
|
||||
pOutDev->DrawBitmapEx( rDestPt, *this );
|
||||
}
|
||||
|
||||
void Bitmap::Draw( OutputDevice* pOutDev,
|
||||
const Point& rDestPt, const Size& rDestSize ) const
|
||||
{
|
||||
pOutDev->DrawBitmapEx( rDestPt, rDestSize, *this );
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -190,12 +190,12 @@ Graphic::Graphic(GraphicExternalLink const & rGraphicExternalLink)
|
||||
}
|
||||
|
||||
Graphic::Graphic(const BitmapEx& rBitmapEx)
|
||||
: mxImpGraphic(new ImpGraphic(rBitmapEx))
|
||||
: mxImpGraphic(new ImpGraphic(Bitmap(rBitmapEx)))
|
||||
{
|
||||
}
|
||||
|
||||
Graphic::Graphic(const Bitmap& rBitmap)
|
||||
: mxImpGraphic(new ImpGraphic(BitmapEx(rBitmap)))
|
||||
: mxImpGraphic(new ImpGraphic(rBitmap))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ Graphic::Graphic(const Bitmap& rBitmap)
|
||||
// and we need to be able to see and preserve 'stock' images too.
|
||||
Graphic::Graphic(const Image& rImage)
|
||||
// FIXME: should really defer the BitmapEx load.
|
||||
: mxImpGraphic(new ImpGraphic(BitmapEx(rImage.GetBitmap())))
|
||||
: mxImpGraphic(new ImpGraphic(rImage.GetBitmap()))
|
||||
{
|
||||
const OUString& aStock = rImage.GetStock();
|
||||
if (aStock.getLength())
|
||||
@@ -348,9 +348,9 @@ const GDIMetaFile& Graphic::GetGDIMetaFile() const
|
||||
return mxImpGraphic->getGDIMetaFile();
|
||||
}
|
||||
|
||||
const BitmapEx& Graphic::GetBitmapExRef() const
|
||||
const Bitmap& Graphic::GetBitmapRef() const
|
||||
{
|
||||
return mxImpGraphic->getBitmapExRef();
|
||||
return mxImpGraphic->getBitmapRef();
|
||||
}
|
||||
|
||||
uno::Reference<css::graphic::XGraphic> Graphic::GetXGraphic() const
|
||||
|
||||
+40
-33
@@ -109,7 +109,7 @@ ImpGraphic::ImpGraphic(const ImpGraphic& rImpGraphic)
|
||||
if (rImpGraphic.mpAnimationContainer)
|
||||
{
|
||||
mpAnimationContainer = std::make_shared<AnimationContainer>(rImpGraphic.mpAnimationContainer->maAnimation);
|
||||
maCachedBitmap = mpAnimationContainer->maAnimation.GetBitmapEx();
|
||||
maCachedBitmap = Bitmap(mpAnimationContainer->maAnimation.GetBitmapEx());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,10 +160,10 @@ ImpGraphic::ImpGraphic(GraphicExternalLink aGraphicExternalLink)
|
||||
ensureCurrentSizeInBytes();
|
||||
}
|
||||
|
||||
ImpGraphic::ImpGraphic(const BitmapEx& rBitmapEx)
|
||||
: MemoryManaged(!rBitmapEx.IsEmpty())
|
||||
, mpBitmapContainer(new BitmapContainer(rBitmapEx))
|
||||
, meType(rBitmapEx.IsEmpty() ? GraphicType::NONE : GraphicType::Bitmap)
|
||||
ImpGraphic::ImpGraphic(const Bitmap& rBitmap)
|
||||
: MemoryManaged(!rBitmap.IsEmpty())
|
||||
, mpBitmapContainer(new BitmapContainer(rBitmap))
|
||||
, meType(rBitmap.IsEmpty() ? GraphicType::NONE : GraphicType::Bitmap)
|
||||
{
|
||||
ensureCurrentSizeInBytes();
|
||||
}
|
||||
@@ -214,7 +214,7 @@ ImpGraphic& ImpGraphic::operator=(const ImpGraphic& rImpGraphic)
|
||||
if (rImpGraphic.mpAnimationContainer)
|
||||
{
|
||||
mpAnimationContainer = std::make_shared<AnimationContainer>(*rImpGraphic.mpAnimationContainer);
|
||||
maCachedBitmap = mpAnimationContainer->maAnimation.GetBitmapEx();
|
||||
maCachedBitmap = Bitmap(mpAnimationContainer->maAnimation.GetBitmapEx());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -328,7 +328,7 @@ const std::shared_ptr<VectorGraphicData>& ImpGraphic::getVectorGraphicData() con
|
||||
|
||||
void BitmapContainer::createSwapInfo(SwapInfo& rSwapInfo)
|
||||
{
|
||||
rSwapInfo.maSizePixel = maBitmapEx.GetSizePixel();
|
||||
rSwapInfo.maSizePixel = maBitmap.GetSizePixel();
|
||||
|
||||
rSwapInfo.maPrefMapMode = getPrefMapMode();
|
||||
rSwapInfo.maPrefSize = getPrefSize();
|
||||
@@ -385,7 +385,7 @@ void ImpGraphic::createSwapInfo()
|
||||
|
||||
void ImpGraphic::clearGraphics()
|
||||
{
|
||||
maCachedBitmap.Clear();
|
||||
maCachedBitmap = Bitmap();
|
||||
mpBitmapContainer.reset();
|
||||
maMetaFile.Clear();
|
||||
mpAnimationContainer.reset();
|
||||
@@ -569,11 +569,15 @@ Bitmap ImpGraphic::getBitmap(const GraphicConversionParameters& rParameters) con
|
||||
if (!mpAnimationContainer && maVectorGraphicData)
|
||||
updateBitmapFromVectorGraphic(rParameters.getSizePixel());
|
||||
|
||||
const BitmapEx& rRetBmpEx = mpAnimationContainer
|
||||
? mpAnimationContainer->maAnimation.GetBitmapEx()
|
||||
: (mpBitmapContainer ? mpBitmapContainer->maBitmapEx : maCachedBitmap);
|
||||
BitmapEx aRetBmpEx;
|
||||
if (mpAnimationContainer)
|
||||
aRetBmpEx = mpAnimationContainer->maAnimation.GetBitmapEx();
|
||||
else if (mpBitmapContainer)
|
||||
aRetBmpEx = mpBitmapContainer->maBitmap;
|
||||
else
|
||||
aRetBmpEx = maCachedBitmap;
|
||||
|
||||
aRetBmp = rRetBmpEx.GetBitmap(COL_WHITE);
|
||||
aRetBmp = aRetBmpEx.GetBitmap(COL_WHITE);
|
||||
|
||||
if (rParameters.getSizePixel().Width() || rParameters.getSizePixel().Height())
|
||||
aRetBmp.Scale(rParameters.getSizePixel());
|
||||
@@ -647,7 +651,7 @@ Bitmap ImpGraphic::getBitmap(const GraphicConversionParameters& rParameters) con
|
||||
}
|
||||
}
|
||||
|
||||
aRetBmp = maCachedBitmap.GetBitmap();
|
||||
aRetBmp = maCachedBitmap;
|
||||
}
|
||||
|
||||
if( !aRetBmp.IsEmpty() )
|
||||
@@ -670,9 +674,12 @@ BitmapEx ImpGraphic::getBitmapEx(const GraphicConversionParameters& rParameters)
|
||||
if (maVectorGraphicData)
|
||||
updateBitmapFromVectorGraphic(rParameters.getSizePixel());
|
||||
|
||||
aBitmapEx = mpAnimationContainer
|
||||
? mpAnimationContainer->maAnimation.GetBitmapEx()
|
||||
: (mpBitmapContainer ? mpBitmapContainer->maBitmapEx : maCachedBitmap);
|
||||
if (mpAnimationContainer)
|
||||
aBitmapEx = mpAnimationContainer->maAnimation.GetBitmapEx();
|
||||
else if (mpBitmapContainer)
|
||||
aBitmapEx = mpBitmapContainer->maBitmap;
|
||||
else
|
||||
aBitmapEx = maCachedBitmap;
|
||||
|
||||
if (rParameters.getSizePixel().Width() || rParameters.getSizePixel().Height())
|
||||
aBitmapEx.Scale(rParameters.getSizePixel(), BmpScaleFlag::Fast);
|
||||
@@ -684,7 +691,7 @@ BitmapEx ImpGraphic::getBitmapEx(const GraphicConversionParameters& rParameters)
|
||||
const ImpGraphic aMonoMask( maMetaFile.GetMonochromeMtf( COL_BLACK ) );
|
||||
|
||||
// use maBitmapEx as local buffer for rendered metafile
|
||||
const_cast<ImpGraphic*>(this)->maCachedBitmap = BitmapEx(getBitmap(rParameters), aMonoMask.getBitmap(rParameters));
|
||||
const_cast<ImpGraphic*>(this)->maCachedBitmap = Bitmap(BitmapEx(getBitmap(rParameters), aMonoMask.getBitmap(rParameters)));
|
||||
}
|
||||
|
||||
aBitmapEx = maCachedBitmap;
|
||||
@@ -705,12 +712,12 @@ Animation ImpGraphic::getAnimation() const
|
||||
return aAnimation;
|
||||
}
|
||||
|
||||
const BitmapEx& ImpGraphic::getBitmapExRef() const
|
||||
const Bitmap& ImpGraphic::getBitmapRef() const
|
||||
{
|
||||
ensureAvailable();
|
||||
|
||||
if (mpBitmapContainer)
|
||||
return mpBitmapContainer->getBitmapExRef();
|
||||
return mpBitmapContainer->getBitmapRef();
|
||||
else
|
||||
return maCachedBitmap;
|
||||
}
|
||||
@@ -761,23 +768,23 @@ const GDIMetaFile& ImpGraphic::getGDIMetaFile() const
|
||||
// survive copying (change this if not wanted)
|
||||
ImpGraphic* pThat = const_cast< ImpGraphic* >(this);
|
||||
|
||||
BitmapEx aBitmapEx = mpBitmapContainer ? mpBitmapContainer->maBitmapEx : maCachedBitmap;
|
||||
Bitmap aBitmap = mpBitmapContainer ? mpBitmapContainer->maBitmap : maCachedBitmap;
|
||||
|
||||
// #123983# directly create a metafile with the same PrefSize and PrefMapMode
|
||||
// the bitmap has, this will be an always correct metafile
|
||||
if (aBitmapEx.IsAlpha())
|
||||
if (aBitmap.HasAlpha())
|
||||
{
|
||||
pThat->maMetaFile.AddAction(new MetaBmpExScaleAction(Point(), aBitmapEx.GetPrefSize(), aBitmapEx));
|
||||
pThat->maMetaFile.AddAction(new MetaBmpExScaleAction(Point(), aBitmap.GetPrefSize(), BitmapEx(aBitmap)));
|
||||
}
|
||||
else
|
||||
{
|
||||
pThat->maMetaFile.AddAction(new MetaBmpScaleAction(Point(), aBitmapEx.GetPrefSize(), aBitmapEx.GetBitmap()));
|
||||
pThat->maMetaFile.AddAction(new MetaBmpScaleAction(Point(), aBitmap.GetPrefSize(), aBitmap));
|
||||
}
|
||||
|
||||
pThat->maMetaFile.Stop();
|
||||
pThat->maMetaFile.WindStart();
|
||||
pThat->maMetaFile.SetPrefSize(aBitmapEx.GetPrefSize());
|
||||
pThat->maMetaFile.SetPrefMapMode(aBitmapEx.GetPrefMapMode());
|
||||
pThat->maMetaFile.SetPrefSize(aBitmap.GetPrefSize());
|
||||
pThat->maMetaFile.SetPrefMapMode(aBitmap.GetPrefMapMode());
|
||||
}
|
||||
|
||||
return maMetaFile;
|
||||
@@ -892,7 +899,7 @@ void ImpGraphic::setValuesForPrefSize(const Size& rPrefSize)
|
||||
}
|
||||
else if (mpBitmapContainer)
|
||||
{
|
||||
mpBitmapContainer->maBitmapEx.SetPrefSize(rPrefSize);
|
||||
mpBitmapContainer->maBitmap.SetPrefSize(rPrefSize);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -991,7 +998,7 @@ void ImpGraphic::setValuesForPrefMapMod(const MapMode& rPrefMapMode)
|
||||
}
|
||||
else if (mpBitmapContainer)
|
||||
{
|
||||
mpBitmapContainer->maBitmapEx.SetPrefMapMode(rPrefMapMode);
|
||||
mpBitmapContainer->maBitmap.SetPrefMapMode(rPrefMapMode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1085,12 +1092,12 @@ void ImpGraphic::draw(OutputDevice& rOutDev,
|
||||
}
|
||||
else if (mpBitmapContainer)
|
||||
{
|
||||
mpBitmapContainer->getBitmapExRef().Draw(&rOutDev, rDestPt, rDestSize);
|
||||
mpBitmapContainer->getBitmapRef().Draw(&rOutDev, rDestPt, rDestSize);
|
||||
}
|
||||
else if (maVectorGraphicData)
|
||||
{
|
||||
updateBitmapFromVectorGraphic(rOutDev.LogicToPixel(rDestSize));
|
||||
getBitmapExRef().Draw(&rOutDev, rDestPt, rDestSize);
|
||||
getBitmapRef().Draw(&rOutDev, rDestPt, rDestSize);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1258,7 +1265,7 @@ bool ImpGraphic::swapOutGraphic(SvStream& rStream)
|
||||
else if (mpBitmapContainer)
|
||||
{
|
||||
rStream.WriteInt32(sal_Int32(GraphicContentType::Bitmap));
|
||||
WriteDIBBitmapEx(mpBitmapContainer->maBitmapEx, rStream);
|
||||
WriteDIBBitmapEx(mpBitmapContainer->maBitmap, rStream);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -1421,7 +1428,7 @@ void ImpGraphic::updateFromLoadedGraphic(const ImpGraphic* pGraphic)
|
||||
if (pGraphic->mpAnimationContainer)
|
||||
{
|
||||
mpAnimationContainer = std::make_shared<AnimationContainer>(*pGraphic->mpAnimationContainer);
|
||||
maCachedBitmap = mpAnimationContainer->maAnimation.GetBitmapEx();
|
||||
maCachedBitmap = Bitmap(mpAnimationContainer->maAnimation.GetBitmapEx());
|
||||
}
|
||||
else if (pGraphic->mpBitmapContainer)
|
||||
{
|
||||
@@ -1639,7 +1646,7 @@ bool ImpGraphic::swapInGraphic(SvStream& rStream)
|
||||
ReadDIBBitmapEx(aBitmapEx, rStream);
|
||||
if (!rStream.GetError())
|
||||
{
|
||||
mpBitmapContainer = std::make_shared<BitmapContainer>(aBitmapEx);
|
||||
mpBitmapContainer = std::make_shared<BitmapContainer>(Bitmap(aBitmapEx));
|
||||
bReturn = true;
|
||||
}
|
||||
}
|
||||
@@ -1652,7 +1659,7 @@ bool ImpGraphic::swapInGraphic(SvStream& rStream)
|
||||
if (!rStream.GetError())
|
||||
{
|
||||
mpAnimationContainer = std::make_shared<AnimationContainer>(aAnimation);
|
||||
maCachedBitmap = mpAnimationContainer->maAnimation.GetBitmapEx();
|
||||
maCachedBitmap = Bitmap(mpAnimationContainer->maAnimation.GetBitmapEx());
|
||||
bReturn = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user