summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/vcl/bitmapex.hxx2
-rw-r--r--vcl/qa/cppunit/png/PngFilterTest.cxx16
-rw-r--r--vcl/source/bitmap/BitmapEx.cxx12
3 files changed, 30 insertions, 0 deletions
diff --git a/include/vcl/bitmapex.hxx b/include/vcl/bitmapex.hxx
index 45f54d016a74..5838ef8d6e40 100644
--- a/include/vcl/bitmapex.hxx
+++ b/include/vcl/bitmapex.hxx
@@ -449,6 +449,8 @@ public:
SAL_DLLPRIVATE std::shared_ptr<SalBitmap> const & ImplGetBitmapSalBitmap() const { return maBitmap.ImplGetSalBitmap(); }
+ /// Dumps the pixels as PNG in bitmap.png.
+ void DumpAsPng(const char* pFileName = nullptr) const;
private:
friend class ImpGraphic;
diff --git a/vcl/qa/cppunit/png/PngFilterTest.cxx b/vcl/qa/cppunit/png/PngFilterTest.cxx
index fd5747d8e9c8..dae007eb7898 100644
--- a/vcl/qa/cppunit/png/PngFilterTest.cxx
+++ b/vcl/qa/cppunit/png/PngFilterTest.cxx
@@ -176,6 +176,7 @@ public:
void testPngRoundtrip24_8();
void testPngRoundtrip32();
void testPngWrite8BitRGBPalette();
+ void testDump();
CPPUNIT_TEST_SUITE(PngFilterTest);
CPPUNIT_TEST(testPng);
@@ -186,6 +187,7 @@ public:
CPPUNIT_TEST(testPngRoundtrip24_8);
CPPUNIT_TEST(testPngRoundtrip32);
CPPUNIT_TEST(testPngWrite8BitRGBPalette);
+ CPPUNIT_TEST(testDump);
CPPUNIT_TEST_SUITE_END();
};
@@ -1956,6 +1958,20 @@ void PngFilterTest::testPngWrite8BitRGBPalette()
}
}
+void PngFilterTest::testDump()
+{
+ utl::TempFileNamed aTempFile;
+ Bitmap aBitmap(Size(1, 1), vcl::PixelFormat::N24_BPP);
+ {
+ BitmapScopedWriteAccess pWriteAccessBitmap(aBitmap);
+ pWriteAccessBitmap->SetPixel(0, 0, BitmapColor());
+ }
+ BitmapEx aBitmapEx(aBitmap);
+ aBitmapEx.DumpAsPng(aTempFile.GetURL().toUtf8().getStr());
+ SvStream* pStream = aTempFile.GetStream(StreamMode::READ);
+ CPPUNIT_ASSERT_GREATER(static_cast<sal_uInt64>(0), pStream->remainingSize());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(PngFilterTest);
CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/bitmap/BitmapEx.cxx b/vcl/source/bitmap/BitmapEx.cxx
index b8f96acbcfbd..cc3988abf333 100644
--- a/vcl/source/bitmap/BitmapEx.cxx
+++ b/vcl/source/bitmap/BitmapEx.cxx
@@ -41,6 +41,8 @@
#include <bitmap/BitmapMaskToAlphaFilter.hxx>
#include <o3tl/any.hxx>
+#include <tools/stream.hxx>
+#include <vcl/filter/PngImageWriter.hxx>
#include <com/sun/star/beans/XFastPropertySet.hpp>
@@ -1482,4 +1484,14 @@ void BitmapEx::GetColorModel(css::uno::Sequence< sal_Int32 >& rRGBPalette,
rnBitCount = pReadAccess->GetBitCount();
}
+void BitmapEx::DumpAsPng(const char* pFileName) const
+{
+ SvFileStream aStream(pFileName ? OUString::fromUtf8(pFileName)
+ : OUString("file:///tmp/bitmap.png"),
+ StreamMode::STD_READWRITE | StreamMode::TRUNC);
+ assert(aStream.good());
+ vcl::PngImageWriter aWriter(aStream);
+ aWriter.write(*this);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */