vcl/source/filter/webp/writer.cxx |   58 +++++++++-----------------------------
 1 file changed, 15 insertions(+), 43 deletions(-)

New commits:
commit f6f626f6eee29b9b6330f6c87c97b4b8ae36cef9
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Aug 8 12:55:20 2025 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Aug 8 21:45:04 2025 +0200

    BitmapEx->Bitmap in writeWebp
    
    now that Bitmap can handle transparency
    
    Change-Id: I7c968e85552657dfd793e7232495768afd6f0d17
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189183
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    Tested-by: Jenkins

diff --git a/vcl/source/filter/webp/writer.cxx 
b/vcl/source/filter/webp/writer.cxx
index f17b612a1198..fc80dd565668 100644
--- a/vcl/source/filter/webp/writer.cxx
+++ b/vcl/source/filter/webp/writer.cxx
@@ -48,7 +48,7 @@ static WebPPreset presetToValue(std::u16string_view preset)
     return WEBP_PRESET_DEFAULT;
 }
 
-static bool writeWebp(SvStream& rStream, const BitmapEx& bitmapEx, bool 
lossless,
+static bool writeWebp(SvStream& rStream, const Bitmap& bitmap, bool lossless,
                       std::u16string_view preset, int quality)
 {
     WebPConfig config;
@@ -76,8 +76,8 @@ static bool writeWebp(SvStream& rStream, const BitmapEx& 
bitmapEx, bool lossless
     // Here various parts of 'config' can be altered if wanted.
     assert(WebPValidateConfig(&config));
 
-    const int width = bitmapEx.GetSizePixel().Width();
-    const int height = bitmapEx.GetSizePixel().Height();
+    const int width = bitmap.GetSizePixel().Width();
+    const int height = bitmap.GetSizePixel().Height();
 
     WebPPicture picture;
     if (!WebPPictureInit(&picture))
@@ -92,14 +92,9 @@ static bool writeWebp(SvStream& rStream, const BitmapEx& 
bitmapEx, bool lossless
 
     // Apparently libwebp needs the entire image data at once in WebPPicture,
     // so allocate it and copy there.
-    const Bitmap& bitmap(bitmapEx.GetBitmap());
-    AlphaMask bitmapAlpha;
-    if (bitmapEx.IsAlpha())
-        bitmapAlpha = bitmapEx.GetAlphaMask();
     BitmapScopedReadAccess access(bitmap);
-    BitmapScopedReadAccess accessAlpha(bitmapAlpha);
     bool dataDone = false;
-    if (!access->IsBottomUp() && bitmapAlpha.IsEmpty())
+    if (!access->IsBottomUp() && !bitmap.HasAlpha())
     {
         // Try to directly copy the bitmap data.
         switch (access->GetScanlineFormat())
@@ -138,41 +133,18 @@ static bool writeWebp(SvStream& rStream, const BitmapEx& 
bitmapEx, bool lossless
         std::vector<uint8_t> data;
         const int bpp = 4;
         data.resize(width * height * bpp);
-        if (!bitmapAlpha.IsEmpty())
+        for (tools::Long y = 0, nHeight = access->Height(); y < nHeight; ++y)
         {
-            for (tools::Long y = 0, nHeight = access->Height(); y < nHeight; 
++y)
+            unsigned char* dst = data.data() + width * bpp * y;
+            const sal_uInt8* src = access->GetScanline(y);
+            for (tools::Long x = 0, nWidth = access->Width(); x < nWidth; ++x)
             {
-                unsigned char* dst = data.data() + width * bpp * y;
-                const sal_uInt8* srcB = access->GetScanline(y);
-                const sal_uInt8* srcA = accessAlpha->GetScanline(y);
-                for (tools::Long x = 0, nWidth = access->Width(); x < nWidth; 
++x)
-                {
-                    BitmapColor color = access->GetPixelFromData(srcB, x);
-                    BitmapColor alpha = accessAlpha->GetPixelFromData(srcA, x);
-                    color.SetAlpha(alpha.GetIndex());
-                    dst[0] = color.GetRed();
-                    dst[1] = color.GetGreen();
-                    dst[2] = color.GetBlue();
-                    dst[3] = color.GetAlpha();
-                    dst += bpp;
-                }
-            }
-        }
-        else
-        {
-            for (tools::Long y = 0, nHeight = access->Height(); y < nHeight; 
++y)
-            {
-                unsigned char* dst = data.data() + width * bpp * y;
-                const sal_uInt8* src = access->GetScanline(y);
-                for (tools::Long x = 0, nWidth = access->Width(); x < nWidth; 
++x)
-                {
-                    Color color = access->GetPixelFromData(src, x);
-                    dst[0] = color.GetRed();
-                    dst[1] = color.GetGreen();
-                    dst[2] = color.GetBlue();
-                    dst[3] = color.GetAlpha();
-                    dst += bpp;
-                }
+                BitmapColor color = access->GetPixelFromData(src, x);
+                dst[0] = color.GetRed();
+                dst[1] = color.GetGreen();
+                dst[2] = color.GetBlue();
+                dst[3] = color.GetAlpha();
+                dst += bpp;
             }
         }
         // And now import from the temporary data. Use the import function 
rather
@@ -193,7 +165,7 @@ static bool writeWebp(SvStream& rStream, const BitmapEx& 
bitmapEx, bool lossless
 bool ExportWebpGraphic(SvStream& rStream, const Graphic& rGraphic,
                        FilterConfigItem* pFilterConfigItem)
 {
-    BitmapEx bitmap = rGraphic.GetBitmapEx();
+    Bitmap bitmap(rGraphic.GetBitmapEx());
     // If lossless, neither presets nor quality matter.
     bool lossless = pFilterConfigItem->ReadBool(u"Lossless"_ustr, true);
     // Preset is WebPPreset values.

Reply via email to