summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorofftkp <parisoplop@gmail.com>2022-07-21 02:19:33 +0300
committerTomaž Vajngerl <quikee@gmail.com>2022-07-28 16:25:49 +0200
commita697296097a55a03189e97f93ce540819f42057a (patch)
treeca5242385e7c5fdd89785478a86c2eb7323a19ff
parent2732115080036e4333fd025ca00396b3ff48c624 (diff)
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 <quikee@gmail.com>
-rw-r--r--vcl/source/filter/png/PngImageWriter.cxx32
1 files changed, 14 insertions, 18 deletions
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);