1 #include <glm/gtc/color_space.hpp>
2 #include <glm/gtc/epsilon.hpp>
3 #include <glm/gtc/constants.hpp>
4
5 namespace srgb
6 {
test()7 int test()
8 {
9 int Error(0);
10
11 glm::vec3 const ColorSourceRGB(1.0, 0.5, 0.0);
12
13 {
14 glm::vec3 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGB);
15 glm::vec3 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
16 Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
17 }
18
19 {
20 glm::vec3 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGB, 2.8f);
21 glm::vec3 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
22 Error += glm::all(glm::epsilonEqual(ColorSourceRGB, ColorRGB, 0.00001f)) ? 0 : 1;
23 }
24
25 glm::vec4 const ColorSourceRGBA(1.0, 0.5, 0.0, 1.0);
26
27 {
28 glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA);
29 glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
30 Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
31 }
32
33 {
34 glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceRGBA, 2.8f);
35 glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB, 2.8f);
36 Error += glm::all(glm::epsilonEqual(ColorSourceRGBA, ColorRGB, 0.00001f)) ? 0 : 1;
37 }
38
39 glm::vec4 const ColorSourceGNI = glm::vec4(107, 107, 104, 131) / glm::vec4(255);
40
41 {
42 glm::vec4 const ColorGNA = glm::convertSRGBToLinear(ColorSourceGNI) * glm::vec4(255);
43 glm::vec4 const ColorGNE = glm::convertLinearToSRGB(ColorSourceGNI) * glm::vec4(255);
44 glm::vec4 const ColorSRGB = glm::convertLinearToSRGB(ColorSourceGNI);
45 glm::vec4 const ColorRGB = glm::convertSRGBToLinear(ColorSRGB);
46 Error += glm::all(glm::epsilonEqual(ColorSourceGNI, ColorRGB, 0.00001f)) ? 0 : 1;
47 }
48
49 return Error;
50 }
51 }//namespace srgb
52
53 namespace srgb_lowp
54 {
test()55 int test()
56 {
57 int Error(0);
58
59 for(float Color = 0.0f; Color < 1.0f; Color += 0.01f)
60 {
61 glm::highp_vec3 const HighpSRGB = glm::convertLinearToSRGB(glm::highp_vec3(Color));
62 glm::lowp_vec3 const LowpSRGB = glm::convertLinearToSRGB(glm::lowp_vec3(Color));
63 Error += glm::all(glm::epsilonEqual(glm::abs(HighpSRGB - glm::highp_vec3(LowpSRGB)), glm::highp_vec3(0), 0.1f)) ? 0 : 1;
64 }
65
66 return Error;
67 }
68 }//namespace srgb_lowp
69
main()70 int main()
71 {
72 int Error(0);
73
74 Error += srgb::test();
75 Error += srgb_lowp::test();
76
77 return Error;
78 }
79