include/vcl/bitmapex.hxx | 2 ++ vcl/qa/cppunit/png/PngFilterTest.cxx | 16 ++++++++++++++++ vcl/source/bitmap/BitmapEx.cxx | 12 ++++++++++++ 3 files changed, 30 insertions(+)
New commits: commit 53603317af854a352e75fd2c5f0f0eeaacc5293c Author: Miklos Vajna <vmik...@collabora.com> AuthorDate: Wed Jan 11 20:17:58 2023 +0100 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Jan 12 06:54:30 2023 +0000 vcl: introduce a BitmapEx::DumpAsPng() This is mostly useful for ad-hoc debugging, so you don't need to manually create an SvFileStream, a vcl::PngImageWriter & connect them, but you can step through code in the debugger and call DumpAsPng() at random code locations. The filename type is intentionally a 'const char*', so you can call DumpAsPng(0) from gdb; that would not be possible for a 'const OUString&' parameter type. Change-Id: I7e6c9bfe8410892969a1cbd1f827e2d62f409400 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145361 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> 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: */