-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
203 lines (138 loc) · 4.7 KB
/
main.cpp
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* File: main.cpp
* --------------
* Sample QT project
*/
//#include <iostream>
#include "console.h"
#include "testing/SimpleTest.h"
#include "image.h"
#include "grayscale.h"
#include "illini.h"
#include "gwindow.h"
#include "catch.h"
#include "spotlight.h"
using namespace std;
/*
* This sample main brings up testing menu.
*/
int main() {
if (runSimpleTests(SELECTED_TESTS)) {
return 0;
}
cout << "All done, exiting" << endl;
return 0;
}
Image createRainbowImage() {
Image png;
png.resize(360, 100);
for (unsigned x = 0; x < png.width(); x++) {
for (unsigned y = 0; y < png.height(); y++) {
HSLAPixel & pixel = png.getPixel(x, y);
pixel.h = x;
pixel.s = y / 100.0;
pixel.l = y / 100.0;
}
}
return png;
}
PROVIDED_TEST("Image : lighten1")
{
//Creating an RainBowImage
Image img = createRainbowImage();
// Augmenting the light
Image result = createRainbowImage();
result.lighten();
EXPECT_EQUAL(img.getPixel(10, 10).l + 0.1 , result.getPixel(10, 10).l );
}
PROVIDED_TEST("Image lighten() does not lighten a pixel above 1.0")
{
Image img = createRainbowImage();
Image result = createRainbowImage();
result.lighten();
EXPECT_EQUAL( 1.0 , result.getPixel(10, 95).l );
}
PROVIDED_TEST("Image darken(0.2) darkens pixels by 0.2") {
Image img = createRainbowImage();
Image result = createRainbowImage();
result.lighten(-0.2);
EXPECT_EQUAL( img.getPixel(50, 50).l - 0.2 , result.getPixel(50, 50).l );
}
PROVIDED_TEST("Image darken(0.2) does not darken a pixel below 0.0") {
Image img = createRainbowImage();
Image result = createRainbowImage();
result.lighten(-0.2);
EXPECT_EQUAL( 0 , result.getPixel(5, 5).l );
}
PROVIDED_TEST("Image saturate() saturates a pixels by 0.1") {
Image img = createRainbowImage();
Image result = createRainbowImage();
result.saturate(0.1);
EXPECT_EQUAL(img.getPixel(10, 10).s + 0.1 , result.getPixel(10, 10).s );
}
PROVIDED_TEST("Image rotateColor(double) rotates the color") {
Image img = createRainbowImage();
Image result = createRainbowImage();
result.rotateColor(90);
EXPECT_EQUAL( img.getPixel(90, 90).h + 90 , result.getPixel(90, 90).h );
}
PROVIDED_TEST("Image rotateColor(double) keeps the hue in the range [0, 360]" ) {
Image img = createRainbowImage();
Image result = createRainbowImage();
result.rotateColor(90);
EXPECT_EQUAL( result.getPixel(340, 90).h , 70 );
result.rotateColor(-180);
EXPECT_EQUAL( result.getPixel(10, 90).h , 280 );
}
PROVIDED_TEST("Grayscale Image " ) {
Grayscale Img("res/haikyuu.png");
EXPECT_EQUAL(Img.getPixel(25, 23).s, 0.0);
}
PROVIDED_TEST("illini") {
Illini result("res/ranbow.png");
for (unsigned x = 0; x < result.width(); x++) {
for (unsigned y = 0; y < result.height(); y++) {
EXPECT(result.getPixel(x, y).h == 11 || result.getPixel(x, y).h == 216);
}
}
}
PROVIDED_TEST("Pixels closest to blue become blue") {
Illini result("res/ranbow.png");
EXPECT_EQUAL( result.getPixel(200, 4).h , 216 );
EXPECT_EQUAL( result.getPixel(210, 12).h , 216 );
EXPECT_EQUAL( result.getPixel(220, 23).h , 216 );
EXPECT_EQUAL( result.getPixel(230, 44).h , 216 );
}
PROVIDED_TEST("Pixels closest to orange become orange") {
Illini result("res/ranbow.png");
EXPECT_EQUAL( result.getPixel(10, 4).h , 11 );
EXPECT_EQUAL( result.getPixel(30, 12).h , 11 );
EXPECT_EQUAL( result.getPixel(40, 23).h , 11 );
EXPECT_EQUAL( result.getPixel(40, 44).h , 11 );
}
PROVIDED_TEST("Hue wrap-arounds are correct (remember: h=359 is closer to orange than blue)") {
Illini result("res/ranbow.png");
EXPECT_EQUAL( result.getPixel(330, 4).h , 11 );
EXPECT_EQUAL( result.getPixel(340, 12).h , 11 );
EXPECT_EQUAL( result.getPixel(350, 23).h , 11 );
}
PROVIDED_TEST("Spotlight does not modify the center pixel") {
Spotlight result("res/ranbow.png",100, 50);
Image png("res/ranbow.png");
EXPECT_EQUAL( png.getPixel(100, 50).l , result.getPixel(100, 50).l );
}
PROVIDED_TEST("Spotlight creates an 80% dark pixel >160 pixels away") {
Spotlight result("res/ranbow.png",100, 50);
Image png("res/ranbow.png");
EXPECT(fabs(png.getPixel(320,50).l *0.2 - result.getPixel(320,50).l) <= 1E-6);
}
PROVIDED_TEST("Spotlight is correct at 20 pixels away from center") {
Spotlight result("res/ranbow.png",100, 50);
Image png("res/ranbow.png");
EXPECT_EQUAL( png.getPixel(100, 50 + 20).l * 0.9 , result.getPixel(100, 50 + 20).l );
}
PROVIDED_TEST("Spotlight is correct at 5 pixels away from center") {
Spotlight result("res/ranbow.png",100, 50);
Image png("res/ranbow.png");
EXPECT_EQUAL( png.getPixel(100 + 3, 50 + 4).l * 0.975 , result.getPixel(100 + 3, 50 + 4).l );
}