vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx |   12 ++++++------
 vcl/qa/cppunit/pdfexport/pdfexport2.cxx            |    6 +++++-
 vcl/source/filter/webp/reader.cxx                  |    4 ++--
 vcl/source/gdi/pdfwriter_impl.cxx                  |   14 ++++++++++----
 4 files changed, 23 insertions(+), 13 deletions(-)

New commits:
commit 1e8ac8b7c865d63014c6655e2e7e77979927c4f7
Author:     Noel Grandin <[email protected]>
AuthorDate: Mon Apr 22 14:52:32 2024 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Apr 26 13:24:04 2024 +0200

    tdf#160431 Inverts webp file image when inserted
    
    regression from
        commit 81994cb2b8b32453a92bcb011830fcb884f22ff3
        Author: Noel Grandin <[email protected]>
        Date:   Fri Apr 16 20:33:10 2021 +0200
        Convert internal vcl bitmap formats transparency->alpha (II)
    
    Change-Id: I3b2959c99a2e18c3972920f8ca86072566d54225
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166450
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>
    (cherry picked from commit c503b6eef32055f75dc9cf761bd20eda4f161dd4)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166434
    Reviewed-by: Adolfo Jayme Barrientos <[email protected]>
    (cherry picked from commit 414d58e8fe8ecf545549dc960e1599b1035b7564)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166510
    Reviewed-by: Xisco Fauli <[email protected]>
    Tested-by: Noel Grandin <[email protected]>

diff --git a/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx 
b/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx
index d3c43f48191f..cbc23315ca30 100644
--- a/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx
+++ b/vcl/qa/cppunit/graphicfilter/filters-webp-test.cxx
@@ -141,10 +141,10 @@ void WebpFilterTest::testRoundtrip(bool lossy)
         }
         AlphaMask tmpAlpha = aResultBitmap.GetAlphaMask();
         BitmapScopedReadAccess pAccessAlpha(tmpAlpha);
-        CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), pAccessAlpha->GetPixelIndex(0, 0));
-        CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), pAccessAlpha->GetPixelIndex(0, 19));
-        CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), pAccessAlpha->GetPixelIndex(19, 0));
-        CPPUNIT_ASSERT_EQUAL(sal_uInt8(64), pAccessAlpha->GetPixelIndex(19, 
19));
+        CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), pAccessAlpha->GetPixelIndex(0, 
0));
+        CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), pAccessAlpha->GetPixelIndex(0, 
19));
+        CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), pAccessAlpha->GetPixelIndex(19, 
0));
+        CPPUNIT_ASSERT_EQUAL(sal_uInt8(191), pAccessAlpha->GetPixelIndex(19, 
19));
     }
 
     aStream.Seek(STREAM_SEEK_TO_BEGIN);
@@ -192,8 +192,8 @@ void WebpFilterTest::testRead(std::u16string_view rName, 
bool lossy, bool alpha)
         {
             AlphaMask tmpAlpha = aResultBitmap.GetAlphaMask();
             BitmapScopedReadAccess pAccessAlpha(tmpAlpha);
-            CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), pAccessAlpha->GetPixelIndex(0, 
0));
-            CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), 
pAccessAlpha->GetPixelIndex(0, 9));
+            CPPUNIT_ASSERT_EQUAL(sal_uInt8(255), 
pAccessAlpha->GetPixelIndex(0, 0));
+            CPPUNIT_ASSERT_EQUAL(sal_uInt8(0), pAccessAlpha->GetPixelIndex(0, 
9));
         }
     }
 }
diff --git a/vcl/source/filter/webp/reader.cxx 
b/vcl/source/filter/webp/reader.cxx
index 1d75ff79e8d1..200331247644 100644
--- a/vcl/source/filter/webp/reader.cxx
+++ b/vcl/source/filter/webp/reader.cxx
@@ -241,7 +241,7 @@ static bool readWebp(SvStream& stream, Graphic& graphic)
                 for (tools::Long x = 0; x < access->Width(); ++x)
                 {
                     memcpy(dstB, src, 3);
-                    *dstA = 255 - *(src + 3);
+                    *dstA = *(src + 3);
                     src += 4;
                     dstB += 3;
                     dstA += 1;
@@ -273,7 +273,7 @@ static bool readWebp(SvStream& stream, Graphic& graphic)
                     for (tools::Long x = 0; x < accessAlpha->Width(); ++x)
                     {
                         sal_uInt8 a = src[3];
-                        accessAlpha->SetPixelIndex(y, x, 255 - a);
+                        accessAlpha->SetPixelIndex(y, x, a);
                         src += 4;
                     }
                 }
commit f15ac9bb71266a9c1c058a782e6752129aa4d0b3
Author:     Patrick Luby <[email protected]>
AuthorDate: Mon Apr 22 19:36:14 2024 -0400
Commit:     Noel Grandin <[email protected]>
CommitDate: Fri Apr 26 13:23:57 2024 +0200

    tdf#160714 use crop box for bounds of embedded PDF object
    
    If there is no crop box, fallback to the media box just to be safe.
    
    Change-Id: I29f99a43e550cf09a1534c0aa01ffd6a55536fb7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166544
    Tested-by: Jenkins
    Reviewed-by: Patrick Luby <[email protected]>
    (cherry picked from commit 4b31f87e918c38a7eb30ceb85563a5c98b426da5)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166671
    Tested-by: Noel Grandin <[email protected]>
    Reviewed-by: Noel Grandin <[email protected]>
    Reviewed-by: Adolfo Jayme Barrientos <[email protected]>

diff --git a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
index 38e3629497fa..a464798076ed 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport2.cxx
@@ -40,6 +40,7 @@
 #include <o3tl/string_view.hxx>
 
 #include <vcl/filter/PDFiumLibrary.hxx>
+#include <vcl/pdfread.hxx>
 #include <comphelper/propertyvalue.hxx>
 #include <cmath>
 
@@ -4580,7 +4581,10 @@ CPPUNIT_TEST_FIXTURE(PdfExportTest2, 
testRexportMediaBoxOrigin)
         = { // Rotation by $   heta$ $cos(     heta), sin(     heta), -sin(    
heta), cos(     heta)$
             0, -1, 1, 0,
             // Translate x,y
-            -aOrigin[1] - aSize[1] / 2 + aSize[0] / 2, aOrigin[0] + aSize[0] / 
2 + aSize[1] / 2
+            -aOrigin[1] - aSize[1] / vcl::PDF_INSERT_MAGIC_SCALE_FACTOR / 2
+                + aSize[0] / vcl::PDF_INSERT_MAGIC_SCALE_FACTOR / 2,
+            aOrigin[0] + aSize[0] / vcl::PDF_INSERT_MAGIC_SCALE_FACTOR / 2
+                + aSize[1] / vcl::PDF_INSERT_MAGIC_SCALE_FACTOR / 2
           };
 
     for (sal_Int32 nIdx = 0; nIdx < 6; ++nIdx)
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index fba7a85db430..ff7383d7be99 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -9125,9 +9125,15 @@ void PDFWriterImpl::writeReferenceXObject(const 
ReferenceXObjectEmit& rEmit)
         }
 
         double aOrigin[2] = { 0.0, 0.0 };
-        if (auto* pArray = 
dynamic_cast<filter::PDFArrayElement*>(pPage->Lookup("MediaBox"_ostr)))
+
+        // tdf#160714 use crop box for bounds of embedded PDF object
+        // If there is no crop box, fallback to the media box just to be safe.
+        auto* pBoundsArray = 
dynamic_cast<filter::PDFArrayElement*>(pPage->Lookup("CropBox"_ostr));
+        if (!pBoundsArray)
+            pBoundsArray = 
dynamic_cast<filter::PDFArrayElement*>(pPage->Lookup("MediaBox"_ostr));
+        if (pBoundsArray)
         {
-            const auto& rElements = pArray->GetElements();
+            const auto& rElements = pBoundsArray->GetElements();
             if (rElements.size() >= 4)
             {
                 // get x1, y1 of the rectangle.
@@ -9240,9 +9246,9 @@ void PDFWriterImpl::writeReferenceXObject(const 
ReferenceXObjectEmit& rEmit)
             // Now transform the object: rotate around the center and make 
sure that the rotation
             // doesn't affect the aspect ratio.
             basegfx::B2DHomMatrix aMat;
-            aMat.translate(-0.5 * aBBox.getWidth() - aOrigin[0], -0.5 * 
aBBox.getHeight() - aOrigin[1]);
+            aMat.translate((-0.5 * aBBox.getWidth() / fMagicScaleFactor) - 
aOrigin[0], (-0.5 * aBBox.getHeight() / fMagicScaleFactor) - aOrigin[1]);
             aMat.rotate(basegfx::deg2rad(nAngle));
-            aMat.translate(0.5 * nWidth, 0.5 * nHeight);
+            aMat.translate(0.5 * nWidth / fMagicScaleFactor, 0.5 * nHeight / 
fMagicScaleFactor);
 
             aLine.append(" /Matrix [ ");
             aLine.append(aMat.a());

Reply via email to