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);
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);
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
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)