Skip to content

Commit bb93dc9

Browse files
committed
Add fuzzyCompareImages() test function
1 parent c1db5f0 commit bb93dc9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

test/common.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <QGuiApplication>
4+
#include <QImage>
45
#include <gtest/gtest.h>
56
#include <filesystem>
67
#include <fstream>
@@ -18,6 +19,23 @@ std::string readFileStr(const std::string &fileName)
1819
return buffer.str();
1920
}
2021

22+
double fuzzyCompareImages(const QImage &a, const QImage &b)
23+
{
24+
if (a.size() != b.size())
25+
return 1;
26+
27+
int x, y, c = 0;
28+
29+
for (y = 0; y < a.height(); y++) {
30+
for (x = 0; x < a.width(); x++) {
31+
if (a.pixel(x, y) != b.pixel(x, y))
32+
c++;
33+
}
34+
}
35+
36+
return c / static_cast<double>((a.width() * a.height()));
37+
}
38+
2139
int main(int argc, char **argv)
2240
{
2341
QGuiApplication a(argc, argv);

0 commit comments

Comments
 (0)