-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
93 lines (77 loc) · 2.4 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
#include <stdio.h>
#include <RGBConverter.h>
#include <gtest/gtest.h>
#define RGB_R 65
#define RGB_G 100
#define RGB_B 37
TEST(UnitCoversion, IntToDouble_single) {
double x = .0000000, x_res;
unsigned int color = 0;
double step = 1/255.;
for(; color < 256; color++) {
RGBConverter::rgbIntToDouble_single(color, &x_res);
EXPECT_NEAR(x, x_res, .0000001);
x+=step;
}
}
TEST(UnitConversion, DoubleToInt_single) {
double x = .0000000;
unsigned int x_res;
unsigned int color = 0;
double step = 1/255.;
for(; color < 256; color++) {
RGBConverter::rgbDoubleToInt_single(x, &x_res);
EXPECT_EQ(color, x_res);
x+=step;
}
}
TEST(UnitCoversion, IntToDouble_full) {
double x = .0000000, r_res, g_res, b_res;
unsigned int color = 0;
double step = 1/255.;
for(; color < 256; color++) {
RGBConverter::rgbIntToDouble(color, color, color, &r_res, &g_res, &b_res);
EXPECT_NEAR(x, r_res, .0000001);
EXPECT_NEAR(x, g_res, .0000001);
EXPECT_NEAR(x, b_res, .0000001);
x+=step;
}
}
TEST(UnitConversion, DoubleToInt_full) {
double x = .0000000;
unsigned int r_res, g_res, b_res;
unsigned int color = 0;
double step = 1/255.;
for(; color < 256; color++) {
RGBConverter::rgbDoubleToInt(x, x, x, &r_res, &g_res, &b_res);
EXPECT_EQ(color, r_res);
EXPECT_EQ(color, g_res);
EXPECT_EQ(color, b_res);
x+=step;
}
}
// Add hsl unit conversions
// Add color conversion test cases
int main(int argc, char** argv) {
// Small demo
double r, g, b;
unsigned int _r, _g, _b;
double h, s, l, _h, _s, _l;
RGBConverter::rgbIntToDouble(RGB_R, RGB_G, RGB_B, &r, &g, &b);
printf("RGB(unsigned int) -> RGB(double) -> HSL -> RGB(double) -> RGB(unsigned int)\n");
printf("RGB: %d %d %d\n", RGB_R, RGB_G, RGB_B);
printf("RGB: %.2f %.2f %.2f\n", r, g, b);
RGBConverter::rgbToHsl(r, g, b, &h, &s, &l);
printf("HSL: %.2f %.2f %.2f\n", h, s, l);
RGBConverter::hslIntervalZeroOneToDegAndPercentage(h, s, l, &_h, &_s, &_l);
printf("HSL: %.2f\u00B0 %.2f%% %.2f%%\n", _h, _s, _l);
RGBConverter::hslDegAndPercentageToIntervalZeroOne(_h, _s, _l, &h, &s, &l);
printf("HSL: %.2f %.2f %.2f\n", h, s, l);
RGBConverter::hslToRgb(h, s, l, &r, &g, &b);
printf("RGB: %.2f %.2f %.2f\n", r, g, b);
RGBConverter::rgbDoubleToInt(r, g, b, &_r, &_g, &_b);
printf("RGB: %d %d %d\n", _r, _g, _b);
// Tests
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}