-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlgorithmExhaustiveRgb.cpp
More file actions
78 lines (63 loc) · 2.04 KB
/
AlgorithmExhaustiveRgb.cpp
File metadata and controls
78 lines (63 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "AlgorithmExhaustiveRgb.h"
#include <iostream>
AlgorithmExhaustiveRgb::AlgorithmExhaustiveRgb(QObject *parent)
: AlgorithmBase{parent}
{
}
QString AlgorithmExhaustiveRgb::GetName()
{
return "Exhaustive Pixel R, G & B error";
}
QString AlgorithmExhaustiveRgb::GetDescription()
{
return "<p>TODO</p>";
}
void AlgorithmExhaustiveRgb::Iterate()
{
struct OnExit {
std::function<void()> onExit;
~OnExit()
{
onExit();
}
};
// Do a block of repeats in one go for efficiency
const int repeats = 100000;
auto exigGuard = OnExit{[&]()
{
iterations_ += repeats;
emit onIterationsChanged(iterations_);
emit onImprovementsChanged(improvements_);
}};
int repeat = 0;
for (; outerX < allRgb_.width(); ++outerX) {
for (; outerY < allRgb_.height(); ++outerY) {
for (; innerX < allRgb_.width(); ++innerX) {
for (; innerY < allRgb_.height(); ++innerY) {
QPoint aLoc{ outerX, outerY };
QPoint bLoc{ innerX, innerY };
QRgb a = allRgb_.pixel(aLoc);
QRgb b = allRgb_.pixel(bLoc);
int aDifference = ColourDifference(a, target_.pixel(aLoc));
int bDifference = ColourDifference(b, target_.pixel(bLoc));
int aSwappedDifference = ColourDifference(a, target_.pixel(bLoc));
int bSwappedDifference = ColourDifference(b, target_.pixel(aLoc));
if ((aDifference + bDifference) > (aSwappedDifference + bSwappedDifference)) {
allRgb_.setPixel(aLoc, b);
allRgb_.setPixel(bLoc, a);
++improvements_;
goto next;
}
if (++repeat > repeats) {
return;
}
}
innerY = 0;
}
innerX = 0;
next:;
}
outerY = 0;
}
outerX = 0;
}