MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / fuzzyDifference

Function fuzzyDifference

test/symbol_t.cpp:107–136  ·  view source on GitHub ↗

* Tests if the images are different, ignoring edges which differ in location by one pixel. * * Returns { -1, -1 } when the images are equal, * the minimum width and height when the images have different sizes, * or the coordinates of the first pixel which does not match (fuzzily). * In the second case, it uses QCOMPARE to output the sizes. * In the last case, it uses QCOMPARE to output the

Source from the content-addressed store, hash-verified

105 * In the last case, it uses QCOMPARE to output the pixel values.
106 */
107QPoint fuzzyDifference(const QImage& lhs, const QImage& rhs)
108{
109 if (lhs.size() != rhs.size())
110 {
111 auto actual_image = lhs.size();
112 auto expected_image = rhs.size();
113 [actual_image, expected_image](){ QCOMPARE(actual_image, expected_image); }();
114 return { qMin(lhs.width(), rhs.width()), qMin(lhs.height(), rhs.height()) };
115 }
116
117 for (auto y = 0; y < lhs.height(); ++y)
118 {
119 const auto* left = reinterpret_cast<const quint32*>(lhs.scanLine(y));
120 const auto* right = reinterpret_cast<const quint32*>(rhs.scanLine(y));
121 for (auto x = 0; x < lhs.width(); ++x)
122 {
123 if (Q_UNLIKELY(left[x] != right[x])
124 && !fuzzyComparePixel(lhs, qMax(x-1, 0), qMax(y-1, 0), qMin(x+2, lhs.width()), qMin(y+2, lhs.height()), right[x]))
125 {
126 auto actual = QString::number(left[x], 16).toLatin1();
127 auto actual_rgb = actual.constData();
128 auto expected = QString::number(right[x], 16).toLatin1();
129 auto expected_rgb = expected.constData();
130 [actual_rgb, expected_rgb](){ QCOMPARE(actual_rgb, expected_rgb); }();
131 return { x, y };
132 }
133 }
134 }
135 return { -1, -1 };
136}
137
138
139} // namespace

Callers 1

renderTestMethod · 0.85

Calls 4

fuzzyComparePixelFunction · 0.85
sizeMethod · 0.45
widthMethod · 0.45
heightMethod · 0.45

Tested by

no test coverage detected