summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@collabora.com>2019-11-25 20:07:02 +0100
committerMiklos Vajna <vmiklos@collabora.com>2019-11-26 09:03:44 +0100
commit8dde8f9768f0dab97cdd30e3116f7e4d737c482f (patch)
tree70740440b55839c6830ebf52205b4069ca9c3de4 /vcl/qa
parentb68ba6929d3df9ed5bf999e14c4ef7083ac35e46 (diff)
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. Change-Id: Ic9a6eb49d55f2fb8ccf18d982e574398f010cabd Reviewed-on: https://gerrit.libreoffice.org/83711 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/outdev.cxx53
1 files changed, 53 insertions, 0 deletions
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();