[Libreoffice-commits] core.git: include/vcl vcl/qa
Chris Sherlock (via logerrit)
logerrit at kemper.freedesktop.org
Sun Sep 5 04:18:45 UTC 2021
include/vcl/outdev.hxx | 26 +++++++--------
vcl/qa/cppunit/BitmapTest.cxx | 41 ++++++++++++++++++++++++
vcl/qa/cppunit/outdev.cxx | 71 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 125 insertions(+), 13 deletions(-)
New commits:
commit dca138469467a7935550cf1af34b630b3dd7fd60
Author: Chris Sherlock <chris.sherlock79 at gmail.com>
AuthorDate: Fri Sep 3 16:24:19 2021 +1000
Commit: Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Sun Sep 5 06:18:10 2021 +0200
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 at collabora.com>
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 720cdefd1c75..26376fedc9e2 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -1413,6 +1413,19 @@ protected:
basegfx::B2DRange &aVisibleRange,
double &fMaximumArea);
+ /** Retrieve downsampled and cropped bitmap
+
+ @attention This method ignores negative rDstSz values, thus
+ mirroring must happen outside this method (e.g. in DrawBitmap)
+ */
+ Bitmap GetDownsampledBitmap(
+ const Size& rDstSz,
+ const Point& rSrcPt,
+ const Size& rSrcSz,
+ const Bitmap& rBmp,
+ tools::Long nMaxBmpDPIX,
+ tools::Long nMaxBmpDPIY );
+
private:
SAL_DLLPRIVATE void DrawDeviceAlphaBitmap(
@@ -1460,19 +1473,6 @@ private:
const tools::Long* pMapX,
const tools::Long* pMapY );
- /** Retrieve downsampled and cropped bitmap
-
- @attention This method ignores negative rDstSz values, thus
- mirroring must happen outside this method (e.g. in DrawBitmap)
- */
- SAL_DLLPRIVATE Bitmap GetDownsampledBitmap(
- const Size& rDstSz,
- const Point& rSrcPt,
- const Size& rSrcSz,
- const Bitmap& rBmp,
- tools::Long nMaxBmpDPIX,
- tools::Long nMaxBmpDPIY );
-
///@}
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);
More information about the Libreoffice-commits
mailing list