summaryrefslogtreecommitdiff
path: root/vcl/qa
diff options
context:
space:
mode:
authorChris Sherlock <chris.sherlock79@gmail.com>2021-09-03 16:24:19 +1000
committerMike Kaganski <mike.kaganski@collabora.com>2021-09-05 06:18:10 +0200
commitdca138469467a7935550cf1af34b630b3dd7fd60 (patch)
treed4ea141392e0cac3ac90b6267b2781ab641876ef /vcl/qa
parent567aa49969e0e947f109e465c2006fa8451d7a58 (diff)
vcl: unit tests for Bitmap::Crop() and Bitmap::GetDownsampledBitmap()
Bitmap::Crop() test: - If crop rectangle is fully outside of the bitmap, then return false and don't change the bitmap. - If crop rectangle is same size as bitmap, then return false - If crop rectangle is larger than the bitmap, then return false - If crop rectangle partially overlaps the bitmap, return true and crop the bitmap - If crop rectangle is fully within the bitmap, then return true and crop the bitmap Bitmap::GetDownsampledBitmap() tested to check when empty or not. Change-Id: Id2a6f739fdb1961748ce218862e628dfa8512122 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121546 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'vcl/qa')
-rw-r--r--vcl/qa/cppunit/BitmapTest.cxx41
-rw-r--r--vcl/qa/cppunit/outdev.cxx71
2 files changed, 112 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/BitmapTest.cxx b/vcl/qa/cppunit/BitmapTest.cxx
index 45e1bdfa1d73..25630ea9cabb 100644
--- a/vcl/qa/cppunit/BitmapTest.cxx
+++ b/vcl/qa/cppunit/BitmapTest.cxx
@@ -45,6 +45,7 @@ class BitmapTest : public CppUnit::TestFixture
void testEmptyAccess();
void testDitherSize();
void testMirror();
+ void testCrop();
CPPUNIT_TEST_SUITE(BitmapTest);
CPPUNIT_TEST(testCreation);
@@ -61,6 +62,7 @@ class BitmapTest : public CppUnit::TestFixture
CPPUNIT_TEST(testEmptyAccess);
CPPUNIT_TEST(testDitherSize);
CPPUNIT_TEST(testMirror);
+ CPPUNIT_TEST(testCrop);
CPPUNIT_TEST_SUITE_END();
};
@@ -685,6 +687,45 @@ void BitmapTest::testMirror()
}
}
+void BitmapTest::testCrop()
+{
+ Bitmap aBitmap(Bitmap(Size(16, 16), vcl::PixelFormat::N24_BPP));
+
+ {
+ Bitmap aCroppedBmp(aBitmap);
+ CPPUNIT_ASSERT_MESSAGE("Crop was fully outside of bitmap bounds",
+ !aCroppedBmp.Crop(tools::Rectangle(Point(20, 20), Size(5, 5))));
+ CPPUNIT_ASSERT_EQUAL(Size(16, 16), aCroppedBmp.GetSizePixel());
+ }
+
+ {
+ Bitmap aCroppedBmp(aBitmap);
+ CPPUNIT_ASSERT_MESSAGE("Crop same size as bitmap",
+ !aCroppedBmp.Crop(tools::Rectangle(Point(0, 0), Size(16, 16))));
+ CPPUNIT_ASSERT_EQUAL(Size(16, 16), aCroppedBmp.GetSizePixel());
+ }
+
+ {
+ Bitmap aCroppedBmp(aBitmap);
+ CPPUNIT_ASSERT_MESSAGE("Crop larger than bitmap",
+ !aCroppedBmp.Crop(tools::Rectangle(Point(0, 0), Size(100, 100))));
+ CPPUNIT_ASSERT_EQUAL(Size(16, 16), aCroppedBmp.GetSizePixel());
+ }
+
+ {
+ Bitmap aCroppedBmp(aBitmap);
+ CPPUNIT_ASSERT_MESSAGE("Crop partially overcrops bitmap",
+ aCroppedBmp.Crop(tools::Rectangle(Point(10, 10), Size(100, 100))));
+ CPPUNIT_ASSERT_EQUAL(Size(6, 6), aCroppedBmp.GetSizePixel());
+ }
+
+ {
+ Bitmap aCroppedBmp(aBitmap);
+ CPPUNIT_ASSERT_MESSAGE("Crop inside bitmap",
+ aCroppedBmp.Crop(tools::Rectangle(Point(5, 5), Size(10, 10))));
+ CPPUNIT_ASSERT_EQUAL(Size(10, 10), aCroppedBmp.GetSizePixel());
+ }
+}
} // namespace
CPPUNIT_TEST_SUITE_REGISTRATION(BitmapTest);
diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx
index 1857b4555c8a..2df0df7d8a69 100644
--- a/vcl/qa/cppunit/outdev.cxx
+++ b/vcl/qa/cppunit/outdev.cxx
@@ -44,6 +44,7 @@ public:
void testDrawScalePartBitmap();
void testDrawTransformedBitmapEx();
void testDrawTransformedBitmapExFlip();
+ void testCroppedDownsampledBitmap();
void testRTL();
void testRTLGuard();
void testDefaultFillColor();
@@ -76,6 +77,7 @@ public:
CPPUNIT_TEST(testGetReadableFontColorWindow);
CPPUNIT_TEST(testDrawTransformedBitmapEx);
CPPUNIT_TEST(testDrawTransformedBitmapExFlip);
+ CPPUNIT_TEST(testCroppedDownsampledBitmap);
CPPUNIT_TEST(testRTL);
CPPUNIT_TEST(testRTLGuard);
CPPUNIT_TEST(testDefaultFillColor);
@@ -510,6 +512,75 @@ void VclOutdevTest::testDrawTransformedBitmapExFlip()
CPPUNIT_ASSERT_EQUAL_MESSAGE(ss.str(), COL_BLACK, Color(aColor));
}
+namespace
+{
+class DownsampleBitmapTester : public OutputDevice
+{
+public:
+ DownsampleBitmapTester()
+ : OutputDevice(OUTDEV_VIRDEV)
+ , maBitmap(Bitmap(Size(16, 16), vcl::PixelFormat::N24_BPP))
+ {
+ SetDPIX(96);
+ SetDPIY(96);
+ }
+
+ bool AcquireGraphics() const { return true; }
+ void ReleaseGraphics(bool) {}
+ bool UsePolyPolygonForComplexGradient() { return false; }
+
+ Bitmap testCropFullyOutsideBounds()
+ {
+ return GetDownsampledBitmap(Size(10, 10), Point(20, 20), Size(5, 5), maBitmap, 72, 72);
+ }
+
+ Bitmap testCropSameSize()
+ {
+ return GetDownsampledBitmap(Size(10, 10), Point(0, 0), maBitmap.GetSizePixel(), maBitmap,
+ 72, 72);
+ }
+
+ Bitmap testFullyOvercrop()
+ {
+ return GetDownsampledBitmap(Size(10, 10), Point(0, 0), Size(100, 100), maBitmap, 72, 72);
+ }
+
+ Bitmap testPartiallyOvercrop()
+ {
+ return GetDownsampledBitmap(Size(10, 10), Point(10, 10), Size(100, 100), maBitmap, 72, 72);
+ }
+
+private:
+ Bitmap maBitmap;
+};
+}
+
+void VclOutdevTest::testCroppedDownsampledBitmap()
+{
+ ScopedVclPtrInstance<DownsampleBitmapTester> pTester;
+
+ {
+ Bitmap aDownsampledBmp(pTester->testCropFullyOutsideBounds());
+ CPPUNIT_ASSERT_MESSAGE("Crop was fully outside of bitmap bounds",
+ aDownsampledBmp.IsEmpty());
+ }
+
+ {
+ Bitmap aDownsampledBmp(pTester->testCropSameSize());
+ CPPUNIT_ASSERT_MESSAGE("Crop same size as bitmap", !aDownsampledBmp.IsEmpty());
+ }
+
+ {
+ Bitmap aDownsampledBmp(pTester->testFullyOvercrop());
+ CPPUNIT_ASSERT_MESSAGE("Crop larger than bitmap", !aDownsampledBmp.IsEmpty());
+ }
+
+ {
+ Bitmap aDownsampledBmp(pTester->testPartiallyOvercrop());
+ CPPUNIT_ASSERT_MESSAGE("Crop partially overcrops bitmap", !aDownsampledBmp.IsEmpty());
+ }
+}
+
void VclOutdevTest::testRTL()
{
ScopedVclPtrInstance<vcl::Window> pWindow(nullptr, WB_APP | WB_STDWORK);