include/vcl/bitmapex.hxx | 1 + vcl/source/bitmap/BitmapEx.cxx | 5 +++++ vcl/source/filter/png/PngImageWriter.cxx | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-)
New commits: commit 7588c1f33cdaab58a6b84f4f4e75922c5d4a8a7f Author: Paris Oplopoios <paris.oplopo...@collabora.com> AuthorDate: Sat Jun 10 21:33:39 2023 +0300 Commit: Paris Oplopoios <parisop...@gmail.com> CommitDate: Sun Jun 11 01:13:39 2023 +0200 tdf#154168 Export no transparency PNGs correctly When bTranslucent was false the function would simply return, causing a 0 byte png. Now we just remove the alpha channel. Change-Id: Ie2578185ac12fb38b6f1b674758e564721e3973f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152840 Tested-by: Jenkins Reviewed-by: Paris Oplopoios <parisop...@gmail.com> diff --git a/include/vcl/bitmapex.hxx b/include/vcl/bitmapex.hxx index 5838ef8d6e40..9d7a104264ef 100644 --- a/include/vcl/bitmapex.hxx +++ b/include/vcl/bitmapex.hxx @@ -56,6 +56,7 @@ public: bool IsEmpty() const; void SetEmpty(); void Clear(); + void ClearAlpha(); void Draw( OutputDevice* pOutDev, const Point& rDestPt ) const; diff --git a/vcl/source/bitmap/BitmapEx.cxx b/vcl/source/bitmap/BitmapEx.cxx index af712a0561a5..ad4adca6319e 100644 --- a/vcl/source/bitmap/BitmapEx.cxx +++ b/vcl/source/bitmap/BitmapEx.cxx @@ -190,6 +190,11 @@ void BitmapEx::Clear() SetEmpty(); } +void BitmapEx::ClearAlpha() +{ + maAlphaMask.SetEmpty(); +} + bool BitmapEx::IsAlpha() const { return !maAlphaMask.IsEmpty(); diff --git a/vcl/source/filter/png/PngImageWriter.cxx b/vcl/source/filter/png/PngImageWriter.cxx index 914302223d6a..e68c6155826b 100644 --- a/vcl/source/filter/png/PngImageWriter.cxx +++ b/vcl/source/filter/png/PngImageWriter.cxx @@ -60,8 +60,6 @@ static bool pngWrite(SvStream& rStream, const BitmapEx& rBitmapEx, int nCompress bool bInterlaced, bool bTranslucent, const std::vector<PngChunk>& aAdditionalChunks) { - if (rBitmapEx.IsAlpha() && !bTranslucent) - return false; if (rBitmapEx.IsEmpty()) return false; @@ -88,6 +86,12 @@ static bool pngWrite(SvStream& rStream, const BitmapEx& rBitmapEx, int nCompress aBitmapEx = rBitmapEx; } + if (!bTranslucent) + { + // Clear alpha channel + aBitmapEx.ClearAlpha(); + } + Bitmap aBitmap; AlphaMask aAlphaMask; Bitmap::ScopedReadAccess pAccess;