vcl/source/filter/png/PngImageWriter.cxx | 32 +++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-)
New commits: commit a697296097a55a03189e97f93ce540819f42057a Author: offtkp <parisop...@gmail.com> AuthorDate: Thu Jul 21 02:19:33 2022 +0300 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Jul 28 16:25:49 2022 +0200 Use bitmap width instead of scanline size in combineScanlineChannels Change-Id: I9f5de7ed1bdcd39e5d6e580a2edbd5c0dd2027e0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137278 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/vcl/source/filter/png/PngImageWriter.cxx b/vcl/source/filter/png/PngImageWriter.cxx index d18c410d1359..fd5ba3c84e8e 100644 --- a/vcl/source/filter/png/PngImageWriter.cxx +++ b/vcl/source/filter/png/PngImageWriter.cxx @@ -15,19 +15,16 @@ namespace { -void combineScanlineChannels(Scanline pRGBScanline, Scanline pAlphaScanline, Scanline pResult, - sal_uInt32 nSize) +void combineScanlineChannels(Scanline pRGBScanline, Scanline pAlphaScanline, + std::vector<std::remove_pointer_t<Scanline>>& pResult, + sal_uInt32 nBitmapWidth) { - assert(pRGBScanline && "RGB scanline is null"); - assert(pAlphaScanline && "Alpha scanline is null"); - - auto const width = nSize / 3; - for (sal_uInt32 i = 0; i < width; ++i) + for (sal_uInt32 i = 0; i < nBitmapWidth; ++i) { - *pResult++ = *pRGBScanline++; // R - *pResult++ = *pRGBScanline++; // G - *pResult++ = *pRGBScanline++; // B - *pResult++ = *pAlphaScanline++; // A + pResult[i * 4] = *pRGBScanline++; // R + pResult[i * 4 + 1] = *pRGBScanline++; // G + pResult[i * 4 + 2] = *pRGBScanline++; // B + pResult[i * 4 + 3] = *pAlphaScanline++; // A } } } @@ -221,16 +218,15 @@ static bool pngWrite(SvStream& rStream, const BitmapEx& rBitmapEx, int nCompress std::vector<std::remove_pointer_t<Scanline>> aCombinedChannels; if (bCombineChannels) { - // Check that there's at least an alpha channel per 3 color/RGB channels - assert(((pAlphaAccess->GetScanlineSize() * 3) >= pAccess->GetScanlineSize()) - && "RGB and alpha channel size mismatch"); + auto nBitmapWidth = pAccess->Width(); // Allocate enough size to fit all 4 channels - aCombinedChannels.resize(pAlphaAccess->GetScanlineSize() - + pAccess->GetScanlineSize()); + aCombinedChannels.resize(nBitmapWidth * 4); Scanline pAlphaPointer = pAlphaAccess->GetScanline(y); + if (!pSourcePointer || !pAlphaPointer) + return false; // Combine RGB and alpha channels - combineScanlineChannels(pSourcePointer, pAlphaPointer, aCombinedChannels.data(), - pAccess->GetScanlineSize()); + combineScanlineChannels(pSourcePointer, pAlphaPointer, aCombinedChannels, + nBitmapWidth); pFinalPointer = aCombinedChannels.data(); // Invert alpha channel (255 - a) png_set_invert_alpha(pPng);