[Libreoffice-commits] core.git: vcl/qa vcl/source
Mark Hung (via logerrit)
logerrit at kemper.freedesktop.org
Wed Jun 3 14:19:01 UTC 2020
vcl/qa/cppunit/BitmapScaleTest.cxx | 47 +++++++++++++++++++++++-----
vcl/source/bitmap/BitmapFastScaleFilter.cxx | 3 -
2 files changed, 40 insertions(+), 10 deletions(-)
New commits:
commit 4ce833e4ffa440d2f6970e94346c2745dffc3ebf
Author: Mark Hung <marklh9 at gmail.com>
AuthorDate: Tue Apr 14 00:05:37 2020 +0800
Commit: Mark Hung <marklh9 at gmail.com>
CommitDate: Wed Jun 3 16:18:28 2020 +0200
vcl: allow BitmapFastScaleFilter for 1xN or Nx1 cases.
Limiting both side to be at least 2px is not necessary,
so check for 1px and add test cases.
Change-Id: I3c6f6ed5c8842bf24e7983bd8ed27fb8bb9568c8
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92117
Tested-by: Jenkins
Reviewed-by: Mark Hung <marklh9 at gmail.com>
diff --git a/vcl/qa/cppunit/BitmapScaleTest.cxx b/vcl/qa/cppunit/BitmapScaleTest.cxx
index b804cd1bf6d3..f73d54f6174d 100644
--- a/vcl/qa/cppunit/BitmapScaleTest.cxx
+++ b/vcl/qa/cppunit/BitmapScaleTest.cxx
@@ -110,7 +110,11 @@ void BitmapScaleTest::testScale()
{ Size(14, 18), Size(16, 30) },
// ratio larger than 16 (triggers different paths in some OpenGL algorithms)
{ Size(18 * 20, 18 * 20), Size(14, 14) },
- { Size(14, 14), Size(18 * 20, 18 * 20) }
+ { Size(14, 14), Size(18 * 20, 18 * 20) },
+ // Boundary cases.
+ { Size(1, 1), Size(1, 1) },
+ { Size(16, 1), Size(12, 1) },
+ { Size(1, 16), Size(1, 12) }
};
for (const ScaleSize& scaleSize : scaleSizes)
{
@@ -125,16 +129,18 @@ void BitmapScaleTest::testScale()
BitmapScopedWriteAccess writeAccess(bitmap);
const int halfW = scaleSize.srcSize.getWidth() / 2;
const int halfH = scaleSize.srcSize.getHeight() / 2;
+ const Size aSize(std::max(halfW, 1), std::max(halfH, 1));
+
writeAccess->SetFillColor(COL_GREEN);
- writeAccess->FillRect(Rectangle(Point(0, 0), Size(halfW, halfH)));
+ writeAccess->FillRect(Rectangle(Point(0, 0), aSize));
writeAccess->SetFillColor(COL_RED);
- writeAccess->FillRect(Rectangle(Point(0, halfH), Size(halfW, halfH)));
+ writeAccess->FillRect(Rectangle(Point(0, halfH), aSize));
writeAccess->SetFillColor(COL_YELLOW);
- writeAccess->FillRect(Rectangle(Point(halfW, 0), Size(halfW, halfH)));
+ writeAccess->FillRect(Rectangle(Point(halfW, 0), aSize));
writeAccess->SetFillColor(COL_BLACK);
- writeAccess->FillRect(Rectangle(Point(halfW, halfH), Size(halfW, halfH)));
+ writeAccess->FillRect(Rectangle(Point(halfW, halfH), aSize));
writeAccess->SetFillColor(COL_BLUE);
- writeAccess->FillRect(Rectangle(Point(halfW / 2, halfH / 2), Size(halfW, halfH)));
+ writeAccess->FillRect(Rectangle(Point(halfW / 2, halfH / 2), aSize));
}
if (bExportBitmap)
{
@@ -150,13 +156,24 @@ void BitmapScaleTest::testScale()
rFilter.compressAsPNG(bitmap, aStream);
}
CPPUNIT_ASSERT_EQUAL(scaleSize.destSize, bitmap.GetSizePixel());
+ const int lastW = scaleSize.destSize.getWidth() - 1;
+ const int lastH = scaleSize.destSize.getHeight() - 1;
+ if (scaleSize.srcSize.getWidth() == 1 && scaleSize.srcSize.getHeight() == 1)
+ {
+ BitmapReadAccess readAccess(bitmap);
+ assertColorsAreSimilar(2, __LINE__, COL_BLUE, readAccess.GetColor(0, 0));
+ assertColorsAreSimilar(2, __LINE__, COL_BLUE, readAccess.GetColor(lastH, 0));
+ assertColorsAreSimilar(2, __LINE__, COL_BLUE, readAccess.GetColor(0, lastW));
+ assertColorsAreSimilar(2, __LINE__, COL_BLUE, readAccess.GetColor(lastH, lastW));
+ assertColorsAreSimilar(2, __LINE__, COL_BLUE,
+ readAccess.GetColor(lastH / 2, lastW / 2));
+ }
+ else if (lastW && lastH)
{
// Scaling should keep each quarter of the resulting bitmap have the same color,
// so check that color in each corner of the result bitmap is the same color,
// or reasonably close (some algorithms may alter the color very slightly).
BitmapReadAccess readAccess(bitmap);
- const int lastW = scaleSize.destSize.getWidth() - 1;
- const int lastH = scaleSize.destSize.getHeight() - 1;
assertColorsAreSimilar(2, __LINE__, COL_GREEN, readAccess.GetColor(0, 0));
assertColorsAreSimilar(2, __LINE__, COL_RED, readAccess.GetColor(lastH, 0));
assertColorsAreSimilar(2, __LINE__, COL_YELLOW, readAccess.GetColor(0, lastW));
@@ -164,6 +181,20 @@ void BitmapScaleTest::testScale()
assertColorsAreSimilar(2, __LINE__, COL_BLUE,
readAccess.GetColor(lastH / 2, lastW / 2));
}
+ else if (lastW)
+ {
+ BitmapReadAccess readAccess(bitmap);
+ assertColorsAreSimilar(2, __LINE__, COL_RED, readAccess.GetColor(0, 0));
+ assertColorsAreSimilar(2, __LINE__, COL_BLACK, readAccess.GetColor(0, lastW));
+ assertColorsAreSimilar(2, __LINE__, COL_BLUE, readAccess.GetColor(0, lastW / 2));
+ }
+ else if (lastH)
+ {
+ BitmapReadAccess readAccess(bitmap);
+ assertColorsAreSimilar(2, __LINE__, COL_YELLOW, readAccess.GetColor(0, 0));
+ assertColorsAreSimilar(2, __LINE__, COL_BLACK, readAccess.GetColor(lastH, 0));
+ assertColorsAreSimilar(2, __LINE__, COL_BLUE, readAccess.GetColor(lastH / 2, 0));
+ }
}
}
}
diff --git a/vcl/source/bitmap/BitmapFastScaleFilter.cxx b/vcl/source/bitmap/BitmapFastScaleFilter.cxx
index cff8f3148980..a48f9e193beb 100644
--- a/vcl/source/bitmap/BitmapFastScaleFilter.cxx
+++ b/vcl/source/bitmap/BitmapFastScaleFilter.cxx
@@ -52,10 +52,9 @@ BitmapEx BitmapFastScaleFilter::execute(BitmapEx const& rBitmapEx) const
if (pWriteAcc)
{
const long nScanlineSize = pWriteAcc->GetScanlineSize();
- const long nNewWidth1 = nNewWidth - 1;
const long nNewHeight1 = nNewHeight - 1;
- if (nNewWidth1 && nNewHeight1)
+ if (nNewWidth && nNewHeight)
{
const double nWidth = pReadAcc->Width();
const double nHeight = pReadAcc->Height();
More information about the Libreoffice-commits
mailing list