]> git.sesse.net Git - movit/blob - gamma_compression_effect_test.cpp
In the demo application, reset the FPS counter every hundred frames.
[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 }
70
71 TEST(GammaCompressionEffectTest, Rec2020_12BitIsVeryCloseToRec709) {
72         float data[256];
73         for (unsigned i = 0; i < 256; ++i) {
74                 data[i] = i / 255.0f;
75         }
76         float out_data_709[256];
77         float out_data_2020[256];
78
79         EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
80         tester.run(out_data_709, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
81         EffectChainTester tester2(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
82         tester2.run(out_data_2020, GL_RED, COLORSPACE_sRGB, GAMMA_REC_2020_12_BIT);
83
84         double sqdiff = 0.0;
85         for (unsigned i = 0; i < 256; ++i) {
86                 EXPECT_NEAR(out_data_709[i], out_data_2020[i], 1e-3);
87                 sqdiff += (out_data_709[i] - out_data_2020[i]) * (out_data_709[i] - out_data_2020[i]);
88         }
89         EXPECT_GT(sqdiff, 1e-6);
90 }