diff options
author | Mark Hung <marklh9@gmail.com> | 2020-04-14 00:05:37 +0800 |
---|---|---|
committer | Mark Hung <marklh9@gmail.com> | 2020-06-03 16:18:28 +0200 |
commit | 4ce833e4ffa440d2f6970e94346c2745dffc3ebf (patch) | |
tree | 06873796e6204ff9848f9699ffb25edd4b4ae433 /vcl | |
parent | 2c6cd66aa81cbdc45ed3bc72e4f8245cf8a5ed15 (diff) |
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@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/qa/cppunit/BitmapScaleTest.cxx | 47 | ||||
-rw-r--r-- | vcl/source/bitmap/BitmapFastScaleFilter.cxx | 3 |
2 files changed, 40 insertions, 10 deletions
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(); |