diff options
author | homeboy445 <akshitsan13@gmail.com> | 2021-07-12 20:26:35 +0530 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2021-08-12 13:44:39 +0200 |
commit | 260ebddf284b34336d6ab82b1726d01b2bacd66c (patch) | |
tree | 2fb555aa247d09953d72a15312d556938c985523 /vcl/backendtest | |
parent | 25b4e39309814325224193f3192e6e2d83e5f141 (diff) |
backendtest: Closed Bezier loop test using various drawing methods
Change-Id: Ib2ddc8475e2476ce377f3541caa0d48e7c57241a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118783
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/backendtest')
-rw-r--r-- | vcl/backendtest/GraphicsRenderTests.cxx | 42 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/common.cxx | 86 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/polygon.cxx | 12 | ||||
-rw-r--r-- | vcl/backendtest/outputdevice/polyline.cxx | 12 |
4 files changed, 152 insertions, 0 deletions
diff --git a/vcl/backendtest/GraphicsRenderTests.cxx b/vcl/backendtest/GraphicsRenderTests.cxx index 707938cb1902..987a28459f2e 100644 --- a/vcl/backendtest/GraphicsRenderTests.cxx +++ b/vcl/backendtest/GraphicsRenderTests.cxx @@ -1406,6 +1406,46 @@ void GraphicsRenderTests::testHalfEllipseWithPolygon() } } +void GraphicsRenderTests::testClosedBezierWithPolyline() +{ + vcl::test::OutputDeviceTestPolygon aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupClosedBezier(); + OUString aTestName = "testClosedBezierWithPolyline"; + if (!SHOULD_ASSERT) + { + appendTestResult(aTestName, "SKIPPED"); + return; + } + vcl::test::TestResult eResult = vcl::test::OutputDeviceTestCommon::checkClosedBezier(aBitmap); + appendTestResult(aTestName, returnTestStatus(eResult), + (m_aStoreResultantBitmap ? aBitmap : Bitmap())); + if (m_aStoreResultantBitmap) + { + BitmapEx aBitmapEx(aBitmap); + exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx); + } +} + +void GraphicsRenderTests::testClosedBezierWithPolygon() +{ + vcl::test::OutputDeviceTestPolygon aOutDevTest; + Bitmap aBitmap = aOutDevTest.setupClosedBezier(); + OUString aTestName = "testClosedBezierWithPolygon"; + if (!SHOULD_ASSERT) + { + appendTestResult(aTestName, "SKIPPED"); + return; + } + vcl::test::TestResult eResult = vcl::test::OutputDeviceTestCommon::checkClosedBezier(aBitmap); + appendTestResult(aTestName, returnTestStatus(eResult), + (m_aStoreResultantBitmap ? aBitmap : Bitmap())); + if (m_aStoreResultantBitmap) + { + BitmapEx aBitmapEx(aBitmap); + exportBitmapExToImage(m_aUserInstallPath + aTestName + ".png", aBitmapEx); + } +} + void GraphicsRenderTests::testHalfEllipseAAWithPolygon() { vcl::test::OutputDeviceTestPolygon aOutDevTest; @@ -1495,6 +1535,8 @@ void GraphicsRenderTests::runALLTests() testHalfEllipseAAWithPolyLineB2D(); testHalfEllipseWithPolygon(); testHalfEllipseAAWithPolygon(); + testClosedBezierWithPolyline(); + testClosedBezierWithPolygon(); } void GraphicsRenderTests::appendTestResult(OUString aTestName, OUString aTestStatus, diff --git a/vcl/backendtest/outputdevice/common.cxx b/vcl/backendtest/outputdevice/common.cxx index 570ddb49c544..b5654c5c45e3 100644 --- a/vcl/backendtest/outputdevice/common.cxx +++ b/vcl/backendtest/outputdevice/common.cxx @@ -141,6 +141,30 @@ std::map<Color, int> collectColors(Bitmap& bitmap, const tools::Rectangle& recta return colors; } +bool checkConvexHullProperty(Bitmap& bitmap, Color constLineColor, int nOffset) +{ + BitmapScopedWriteAccess pAccess(bitmap); + tools::Long thresholdWidth = pAccess->Width() - nOffset; + tools::Long thresholdHeight = pAccess->Height() - nOffset; + for (tools::Long y = 0; y < pAccess->Height(); ++y) + { + for (tools::Long x = 0; x < pAccess->Width(); ++x) + { + /* + If the shape exceeds the threshold limit of height or width or both, + this would indicate that the bezier curve is not within its convex polygon and + hence is faulty. + */ + if (pAccess->GetPixel(y, x) == constLineColor + && (thresholdHeight < y || thresholdWidth < x)) + { + return false; + } + } + } + return true; +} + TestResult checkRect(Bitmap& rBitmap, int aLayerNumber, Color aExpectedColor) { BitmapScopedWriteAccess pAccess(rBitmap); @@ -593,6 +617,28 @@ basegfx::B2DPolygon OutputDeviceTestCommon::createHalfEllipsePolygon() return aPolygon; } +tools::Polygon OutputDeviceTestCommon::createClosedBezierLoop(tools::Rectangle& rRect) +{ + tools::Long minX = rRect.Left(); + tools::Long maxX = rRect.Right() - 2; + tools::Long minY = rRect.Top(); + tools::Long maxY = rRect.Bottom() - 2; + + tools::Polygon aPolygon(4); + + aPolygon.SetPoint(Point((maxX / 2.0), maxY), 0); + aPolygon.SetFlags(0, PolyFlags::Normal); + aPolygon.SetPoint(Point(maxX, minY), 1); + aPolygon.SetFlags(1, PolyFlags::Control); + aPolygon.SetPoint(Point(minX, minY), 2); + aPolygon.SetFlags(2, PolyFlags::Control); + aPolygon.SetPoint(Point((maxX / 2.0), maxY), 3); + aPolygon.SetFlags(3, PolyFlags::Normal); + + aPolygon.Optimize(PolyOptimizeFlags::CLOSE); + + return aPolygon; +} TestResult OutputDeviceTestCommon::checkDropShape(Bitmap& rBitmap, bool aEnableAA) { @@ -723,6 +769,46 @@ TestResult OutputDeviceTestCommon::checkHalfEllipse(Bitmap& rBitmap, bool aEnabl return aResult; } +TestResult OutputDeviceTestCommon::checkClosedBezier(Bitmap& rBitmap) +{ + BitmapScopedWriteAccess pAccess(rBitmap); + + TestResult aResult = TestResult::Passed; + int nNumberOfQuirks = 0; + int nNumberOfErrors = 0; + + std::map<std::pair<tools::Long, tools::Long>, bool> SetPixels + = { { { 3, 8 }, true }, { { 3, 9 }, true }, { { 3, 10 }, true }, { { 4, 7 }, true }, + { { 4, 8 }, true }, { { 4, 9 }, true }, { { 4, 10 }, true }, { { 4, 11 }, true }, + { { 5, 7 }, true }, { { 5, 11 }, true }, { { 6, 6 }, true }, { { 6, 12 }, true }, + { { 7, 6 }, true }, { { 7, 12 }, true }, { { 8, 7 }, true }, { { 8, 11 }, true }, + { { 9, 7 }, true }, { { 9, 11 }, true }, { { 10, 7 }, true }, { { 10, 11 }, true }, + { { 11, 8 }, true }, { { 11, 9 }, true }, { { 11, 10 }, true }, { { 12, 8 }, true }, + { { 12, 9 }, true }, { { 12, 10 }, true }, { { 13, 9 }, true } }; + + for (tools::Long x = 0; x < pAccess->Width(); x++) + { + for (tools::Long y = 0; y < pAccess->Height(); ++y) + { + if (SetPixels[{ y, x }]) + { + checkValue(pAccess, x, y, constLineColor, nNumberOfQuirks, nNumberOfErrors, true); + } + else + { + checkValue(pAccess, x, y, constBackgroundColor, nNumberOfQuirks, nNumberOfErrors, + true); + } + } + } + + if (nNumberOfQuirks > 0) + aResult = TestResult::PassedWithQuirks; + if (nNumberOfErrors > 0 || !checkConvexHullProperty(rBitmap, constLineColor, 2)) + aResult = TestResult::Failed; + return aResult; +} + // Check 'count' pixels from (x,y) in (addX,addY) direction, the color values must not decrease. static bool checkGradient(BitmapScopedWriteAccess& pAccess, int x, int y, int count, int addX, int addY) { diff --git a/vcl/backendtest/outputdevice/polygon.cxx b/vcl/backendtest/outputdevice/polygon.cxx index 9562dfecb290..a94bf0a6f306 100644 --- a/vcl/backendtest/outputdevice/polygon.cxx +++ b/vcl/backendtest/outputdevice/polygon.cxx @@ -188,6 +188,18 @@ Bitmap OutputDeviceTestPolygon::setupHalfEllipse(bool aEnableAA) return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } + +Bitmap OutputDeviceTestPolygon::setupClosedBezier() +{ + initialSetup(21, 16, constBackgroundColor); + + mpVirtualDevice->SetLineColor(constLineColor); + mpVirtualDevice->SetFillColor(); + + mpVirtualDevice->DrawPolyLine(OutputDeviceTestCommon::createClosedBezierLoop(maVDRectangle)); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} } // end namespace vcl::test /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/backendtest/outputdevice/polyline.cxx b/vcl/backendtest/outputdevice/polyline.cxx index edaf1bf428c5..41468ccee263 100644 --- a/vcl/backendtest/outputdevice/polyline.cxx +++ b/vcl/backendtest/outputdevice/polyline.cxx @@ -173,6 +173,18 @@ Bitmap OutputDeviceTestPolyLine::setupHalfEllipse(bool aEnableAA) return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); } + +Bitmap OutputDeviceTestPolyLine::setupClosedBezier() +{ + initialSetup(21, 16, constBackgroundColor); + + mpVirtualDevice->SetLineColor(constLineColor); + mpVirtualDevice->SetFillColor(); + + mpVirtualDevice->DrawPolyLine(OutputDeviceTestCommon::createClosedBezierLoop(maVDRectangle)); + + return mpVirtualDevice->GetBitmap(maVDRectangle.TopLeft(), maVDRectangle.GetSize()); +} } // end namespace vcl::test /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |