]> git.sesse.net Git - movit/commitdiff
Add some sRGB conversion functions to test_util.{h,cpp}.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 27 Feb 2016 23:28:31 +0000 (00:28 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 27 Feb 2016 23:28:31 +0000 (00:28 +0100)
gamma_compression_effect_test.cpp
gamma_expansion_effect_test.cpp
test_util.cpp
test_util.h

index 1c8768096b6485d5b6d260ae13ca0e49235dd967..db2023457142411415a4a2ad5aa57916458a774b 100644 (file)
@@ -54,13 +54,7 @@ TEST(GammaCompressionEffectTest, sRGB_Accuracy) {
                double x = i / 255.0;
 
                expected_data[i] = x;
                double x = i / 255.0;
 
                expected_data[i] = x;
-
-               // From the Wikipedia article on sRGB.
-               if (x < 0.04045) {
-                       data[i] = x / 12.92;
-               } else {
-                       data[i] = pow((x + 0.055) / 1.055, 2.4);
-               }
+               data[i] = srgb_to_linear(x);
        }
 
        EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, GL_RGBA32F);
        }
 
        EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_LINEAR, GL_RGBA32F);
index 499a0d47caba00a71cdc068a9fb956d7759df292..1e399dc87be126e0059d78f1872a0228e0df04bc 100644 (file)
@@ -62,13 +62,7 @@ TEST(GammaExpansionEffectTest, sRGB_Accuracy) {
                double x = i / 255.0;
 
                data[i] = x;
                double x = i / 255.0;
 
                data[i] = x;
-
-               // From the Wikipedia article on sRGB.
-               if (x < 0.04045) {
-                       expected_data[i] = x / 12.92;
-               } else {
-                       expected_data[i] = pow((x + 0.055) / 1.055, 2.4);
-               }
+               expected_data[i] = srgb_to_linear(x);
        }
 
        EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB, GL_RGBA32F);
        }
 
        EffectChainTester tester(data, 256, 1, FORMAT_GRAYSCALE, COLORSPACE_sRGB, GAMMA_sRGB, GL_RGBA32F);
index b377309638114057f2d99a56c852ee010bebb18f..05eac31451f833687eff9b552abd098dbfcbbcc6 100644 (file)
@@ -351,4 +351,24 @@ void test_accuracy(const float *expected, const float *result, unsigned num_valu
        EXPECT_LT(rms, rms_limit);
 }
 
        EXPECT_LT(rms, rms_limit);
 }
 
+double srgb_to_linear(double x)
+{
+       // From the Wikipedia article on sRGB.
+       if (x < 0.04045) {
+               return x / 12.92;
+       } else {
+               return pow((x + 0.055) / 1.055, 2.4);
+       }
+}
+
+double linear_to_srgb(double x)
+{
+       // From the Wikipedia article on sRGB.
+       if (x < 0.0031308) {
+               return 12.92 * x;
+       } else {
+               return 1.055 * pow(x, 1.0 / 2.4) - 0.055;
+       }
+}
+
 }  // namespace movit
 }  // namespace movit
index 69efe358b10d60b0e0556751b7d1d6ea313cee1f..43d0216f032774d985cbb0da2c791479cec7470e 100644 (file)
@@ -48,6 +48,14 @@ void expect_equal(const float *ref, const float *result, unsigned width, unsigne
 void expect_equal(const unsigned char *ref, const unsigned char *result, unsigned width, unsigned height, unsigned largest_difference_limit = 1, float rms_limit = 0.2);
 void test_accuracy(const float *expected, const float *result, unsigned num_values, double absolute_error_limit, double relative_error_limit, double local_relative_error_limit, double rms_limit);
 
 void expect_equal(const unsigned char *ref, const unsigned char *result, unsigned width, unsigned height, unsigned largest_difference_limit = 1, float rms_limit = 0.2);
 void test_accuracy(const float *expected, const float *result, unsigned num_values, double absolute_error_limit, double relative_error_limit, double local_relative_error_limit, double rms_limit);
 
+// Convert an sRGB encoded value (0.0 to 1.0, inclusive) to linear light.
+// Undefined for values outside 0.0..1.0.
+double srgb_to_linear(double x);
+
+// Convert a value in linear light (0.0 to 1.0, inclusive) to sRGB.
+// Undefined for values outside 0.0..1.0.
+double linear_to_srgb(double x);
+
 }  // namespace movit
 
 #endif  // !defined(_MOVIT_TEST_UTIL_H)
 }  // namespace movit
 
 #endif  // !defined(_MOVIT_TEST_UTIL_H)