Makefile should now be in .gitignore.
[movit] / gamma_compression_effect_test.cpp
1 // Unit tests for GammaCompressionEffect.
2 //
3 // Pretty much the inverse of the GammaExpansionEffect tests;
4 // EffectChainTest tests that they are actually inverses.
5
6 #include <GL/glew.h>
7 #include "gtest/gtest.h"
8 #include "image_format.h"
9 #include "test_util.h"
10
11 TEST(GammaCompressionEffectTest, sRGB_KeyValues) {
12         float data[] = {
13                 0.0f, 1.0f,
14                 0.00309f, 0.00317f,   // On either side of the discontinuity.
15         };
16         float expected_data[] = {
17                 0.0f, 1.0f,
18                 0.040f, 0.041f,
19         };
20         float out_data[4];
21         EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
22         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB);
23
24         expect_equal(expected_data, out_data, 2, 2);
25 }
26
27 TEST(GammaCompressionEffectTest, sRGB_RampAlwaysIncreases) {
28         float data[256], out_data[256];
29         for (unsigned i = 0; i < 256; ++i) {
30                 data[i] = i / 255.0f;
31         }
32         EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
33         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB);
34
35         for (unsigned i = 1; i < 256; ++i) {
36                 EXPECT_GT(out_data[i], out_data[i - 1])
37                    << "No increase between " << i-1 << " and " << i;
38         }
39 }
40
41 TEST(GammaCompressionEffectTest, Rec709_KeyValues) {
42         float data[] = {
43                 0.0f, 1.0f,
44                 0.017778f, 0.018167f,  // On either side of the discontinuity.
45         };
46         float expected_data[] = {
47                 0.0f, 1.0f,
48                 0.080f, 0.082f,
49         };
50         float out_data[4];
51         EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
52         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
53
54         expect_equal(expected_data, out_data, 2, 2);
55 }
56
57 TEST(GammaCompressionEffectTest, Rec709_RampAlwaysIncreases) {
58         float data[256], out_data[256];
59         for (unsigned i = 0; i < 256; ++i) {
60                 data[i] = i / 255.0f;
61         }
62         EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
63         tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
64
65         for (unsigned i = 1; i < 256; ++i) {
66                 EXPECT_GT(out_data[i], out_data[i - 1])
67                    << "No increase between " << i-1 << " and " << i;
68         }
69 }