* 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
| 105 | * In the last case, it uses QCOMPARE to output the pixel values. |
| 106 | */ |
| 107 | QPoint 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 |
no test coverage detected