diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2019-10-10 09:49:29 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2019-10-10 13:35:24 +0200 |
commit | 55b4d5ea9e1a42edf71d2eef6028830983dbc11c (patch) | |
tree | 9c2bbdf69591d6575440d50fd0f452bd776803d8 /vcl/qa/cppunit/BitmapExTest.cxx | |
parent | 91c586e10c816340523bf1c4df910dd2538c9fee (diff) |
vcl: only smooth bitmap transform when needed
If you have a very small bitmap and you rotate it by 90 degrees, then
smoothing is not needed, but the result will be blurry. So in case
scaling / shear doesn't need it and we do 90/180/270 rotation, avoid
smoothing.
Change-Id: I4b8fad4b0b70516d35eaecfa70a707e6e8362d18
Reviewed-on: https://gerrit.libreoffice.org/80589
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'vcl/qa/cppunit/BitmapExTest.cxx')
-rw-r--r-- | vcl/qa/cppunit/BitmapExTest.cxx | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/BitmapExTest.cxx b/vcl/qa/cppunit/BitmapExTest.cxx index 3a89441b9604..23f40f0013cd 100644 --- a/vcl/qa/cppunit/BitmapExTest.cxx +++ b/vcl/qa/cppunit/BitmapExTest.cxx @@ -12,6 +12,7 @@ #include <cppunit/extensions/HelperMacros.h> #include <vcl/bitmapex.hxx> +#include <basegfx/matrix/b2dhommatrix.hxx> #include <bitmapwriteaccess.hxx> #include <svdata.hxx> #include <salinst.hxx> @@ -22,10 +23,12 @@ class BitmapExTest : public CppUnit::TestFixture { void testGetPixelColor24_8(); void testGetPixelColor32(); + void testTransformBitmapEx(); CPPUNIT_TEST_SUITE(BitmapExTest); CPPUNIT_TEST(testGetPixelColor24_8); CPPUNIT_TEST(testGetPixelColor32); + CPPUNIT_TEST(testTransformBitmapEx); CPPUNIT_TEST_SUITE_END(); }; @@ -66,6 +69,43 @@ void BitmapExTest::testGetPixelColor32() CPPUNIT_ASSERT_EQUAL(Color(0xAA, 0x00, 0xFF, 0x00), aBitmapEx.GetPixelColor(0, 0)); } +void BitmapExTest::testTransformBitmapEx() +{ + Bitmap aBitmap(Size(16, 16), 24); + { + BitmapScopedWriteAccess pWriteAccess(aBitmap); + pWriteAccess->Erase(COL_WHITE); + for (int i = 0; i < 8; ++i) + { + for (int j = 0; j < 8; ++j) + { + pWriteAccess->SetPixel(i, j, COL_BLACK); + } + } + } + BitmapEx aBitmapEx(aBitmap); + + basegfx::B2DHomMatrix aMatrix; + aMatrix.rotate(M_PI / 2); + BitmapEx aTransformed = aBitmapEx.TransformBitmapEx(16, 16, aMatrix); + aBitmap = aTransformed.GetBitmap(); + Bitmap::ScopedReadAccess pAccess(aBitmap); + for (int i = 0; i < 16; ++i) + { + for (int j = 0; j < 16; ++j) + { + BitmapColor aColor = pAccess->GetPixel(i, j); + std::stringstream ss; + ss << "Color is expected to be white or black, is '" << aColor.AsRGBHexString() << "'"; + // Without the accompanying fix in place, this test would have failed with: + // - Expression: aColor == COL_WHITE || aColor == COL_BLACK + // - Color is expected to be white or black, is 'bfbfbf' + // i.e. smoothing introduced noise for a simple 90 deg rotation. + CPPUNIT_ASSERT_MESSAGE(ss.str(), aColor == COL_WHITE || aColor == COL_BLACK); + } + } +} + } // namespace CPPUNIT_TEST_SUITE_REGISTRATION(BitmapExTest); |