[Libreoffice-commits] core.git: Branch 'libreoffice-6-4' - vcl/qa vcl/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Nov 26 11:58:23 UTC 2019


 vcl/qa/cppunit/outdev.cxx    |   53 +++++++++++++++++++++++++++++++++++++++++++
 vcl/source/outdev/bitmap.cxx |    3 +-
 2 files changed, 55 insertions(+), 1 deletion(-)

New commits:
commit de0924073824e1e38d35f78f5f8de2a4feceae8e
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Nov 25 20:07:02 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Nov 26 12:57:34 2019 +0100

    tdf#128629 vcl DrawTransformedBitmapEx: do scaling for flipped bitmaps
    
    Regression from commit dd4a67084853a030bf4b9f1f85d728620e0604a5 (vcl:
    avoid downscale && upscale in DrawTransformedBitmapEx(), 2019-10-08),
    the original problem to be solved was that in case you downscale a
    bitmap and upscale it later, then you get blurry result, so we try to
    avoid touching the pixels and just scale during rendering of the bitmap.
    
    However, here the problem is that scaling is also (mis)used for flip
    purposes, so go back to the original behavior for negative scaling.
    
    This keeps the original problem fixed and solves the loss of flip as
    well.
    
    (cherry picked from commit 8dde8f9768f0dab97cdd30e3116f7e4d737c482f)
    
    Change-Id: Ic9a6eb49d55f2fb8ccf18d982e574398f010cabd
    Reviewed-on: https://gerrit.libreoffice.org/83732
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index f4a27b0b0558..8b2dd7c3a841 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -31,6 +31,7 @@ public:
     void testGetReadableFontColorPrinter();
     void testGetReadableFontColorWindow();
     void testDrawTransformedBitmapEx();
+    void testDrawTransformedBitmapExFlip();
 
     CPPUNIT_TEST_SUITE(VclOutdevTest);
     CPPUNIT_TEST(testVirtualDevice);
@@ -40,6 +41,7 @@ public:
     CPPUNIT_TEST(testGetReadableFontColorPrinter);
     CPPUNIT_TEST(testGetReadableFontColorWindow);
     CPPUNIT_TEST(testDrawTransformedBitmapEx);
+    CPPUNIT_TEST(testDrawTransformedBitmapExFlip);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -201,6 +203,57 @@ void VclOutdevTest::testDrawTransformedBitmapEx()
     }
 }
 
+void VclOutdevTest::testDrawTransformedBitmapExFlip()
+{
+    // Create a virtual device, and connect a metafile to it.
+    // Also create a 16x16 bitmap.
+    ScopedVclPtrInstance<VirtualDevice> pVDev;
+    Bitmap aBitmap(Size(16, 16), 24);
+    {
+        // Fill the top left quarter with black.
+        BitmapScopedWriteAccess pWriteAccess(aBitmap);
+        pWriteAccess->Erase(COL_WHITE);
+        for (int i = 0; i < 8; ++i)
+        {
+            for (int j = 0; j < 8; ++j)
+            {
+                pWriteAccess->SetPixel(j, i, COL_BLACK);
+            }
+        }
+    }
+    BitmapEx aBitmapEx(aBitmap);
+    basegfx::B2DHomMatrix aMatrix;
+    // Negative y scale: bitmap should be upside down, so the black part goes to the bottom left.
+    aMatrix.scale(8, -8);
+    // Rotate 90 degrees clockwise, so the black part goes back to the top left.
+    aMatrix.rotate(M_PI / 2);
+    GDIMetaFile aMtf;
+    aMtf.Record(pVDev.get());
+
+    // Draw the scaled and rotated bitmap on the vdev.
+    pVDev->DrawTransformedBitmapEx(aMatrix, aBitmapEx);
+    CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aMtf.GetActionSize());
+    MetaAction* pAction = aMtf.GetAction(0);
+    CPPUNIT_ASSERT_EQUAL(MetaActionType::BMPEXSCALE, pAction->GetType());
+    auto pBitmapAction = static_cast<MetaBmpExScaleAction*>(pAction);
+    const BitmapEx& rBitmapEx = pBitmapAction->GetBitmapEx();
+
+    aBitmap = rBitmapEx.GetBitmap();
+    Bitmap::ScopedReadAccess pAccess(aBitmap);
+    int nX = 8 * 0.25;
+    int nY = 8 * 0.25;
+    BitmapColor aColor = pAccess->GetPixel(nY, nX);
+    std::stringstream ss;
+    ss << "Color is expected to be black, is " << aColor.AsRGBHexString();
+    ss << " (row " << nY << ", col " << nX << ")";
+    // Without the accompanying fix in place, this test would have failed with:
+    // - Expected: c[00000000]
+    // - Actual  : c[ffffff00]
+    // - Color is expected to be black, is ffffff (row 2, col 2)
+    // i.e. the top left quarter of the image was not black, due to a missing flip.
+    CPPUNIT_ASSERT_EQUAL_MESSAGE(ss.str(), COL_BLACK, Color(aColor));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(VclOutdevTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/outdev/bitmap.cxx b/vcl/source/outdev/bitmap.cxx
index f0a20db1a41e..5db64d06dc40 100644
--- a/vcl/source/outdev/bitmap.cxx
+++ b/vcl/source/outdev/bitmap.cxx
@@ -1277,7 +1277,8 @@ void OutputDevice::DrawTransformedBitmapEx(
             basegfx::B2DVector aFullScale, aFullTranslate;
             double fFullRotate, fFullShearX;
             aFullTransform.decompose(aFullScale, aFullTranslate, fFullRotate, fFullShearX);
-            if (aFullScale.getX() != 0 && aFullScale.getY() != 0)
+            // Require positive scaling, negative scaling would loose horizontal or vertical flip.
+            if (aFullScale.getX() > 0 && aFullScale.getY() > 0)
             {
                 basegfx::B2DHomMatrix aTransform = basegfx::utils::createScaleB2DHomMatrix(
                     rOriginalSizePixel.getWidth() / aFullScale.getX(),


More information about the Libreoffice-commits mailing list