1 // Unit tests for GammaCompressionEffect.
3 // Pretty much the inverse of the GammaExpansionEffect tests;
4 // EffectChainTest tests that they are actually inverses.
7 #include "gtest/gtest.h"
8 #include "image_format.h"
11 TEST(GammaCompressionEffectTest, sRGB_KeyValues) {
14 0.00309f, 0.00317f, // On either side of the discontinuity.
16 float expected_data[] = {
21 EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
22 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB);
24 expect_equal(expected_data, out_data, 2, 2);
27 TEST(GammaCompressionEffectTest, sRGB_RampAlwaysIncreases) {
28 float data[256], out_data[256];
29 for (unsigned i = 0; i < 256; ++i) {
32 EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
33 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_sRGB);
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;
41 TEST(GammaCompressionEffectTest, Rec709_KeyValues) {
44 0.017778f, 0.018167f, // On either side of the discontinuity.
46 float expected_data[] = {
51 EffectChainTester tester(data, 2, 2, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
52 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
54 expect_equal(expected_data, out_data, 2, 2);
57 TEST(GammaCompressionEffectTest, Rec709_RampAlwaysIncreases) {
58 float data[256], out_data[256];
59 for (unsigned i = 0; i < 256; ++i) {
62 EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR);
63 tester.run(out_data, GL_RED, COLORSPACE_sRGB, GAMMA_REC_709);
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;
71 TEST(GammaCompressionEffectTest, Rec2020_12BitIsVeryCloseToRec709) {
73 for (unsigned i = 0; i < 256; ++i) {
76 float out_data_709[256];
77 float out_data_2020[256];
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);
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]);
89 EXPECT_GT(sqdiff, 1e-6);