33 return fabs(
a -
b) <= epsilon;
36 #define TEST_EOTF(func, input, ref) do \
38 const double _b[3] = { (ref)[0], (ref)[1], (ref)[2] }; \
39 double _a[3] = { (input)[0], (input)[1], (input)[2] }; \
41 for (int _i = 0; _i < 3; _i++) { \
42 if (!fuzzy_equal(_a[_i], _b[_i])) { \
43 printf("FAIL: trc=%s %s(%g, %g, %s) != %s\n" \
44 " expected {%g, %g, %g}, got {%g, %g, %g}\n", \
45 trc_name, #func, Lw, Lb, #input, #ref, \
46 _b[0], _b[1], _b[2], _a[0], _a[1], _a[2]); \
52 int main(
int argc,
char *argv[])
55 -0.1, -0.018053968510807, -0.01, -0.00449, 0.0, 0.00316227760, 0.005,
56 0.009, 0.015, 0.1, 1.0, 52.37, 125.098765, 1999.11123, 6945.443,
57 15123.4567, 19845.88923, 98678.4231, 99999.899998
69 double roundtrip = func_inv(
result);
70 printf(
"trc=%s calling func(%f) expected=%f roundtrip=%f\n",
92 const struct {
double E_xyz[3];
double luma; }
tests[] = {
93 #define XYZ(X, Y, Z) { X / 4095.0, Y / 4095.0, Z / 4095.0 }
94 {
XYZ( 379, 396, 389), 0.14 },
95 {
XYZ( 759, 792, 778), 0.75 },
96 {
XYZ(1138, 1188, 1167), 2.12 },
97 {
XYZ(1518, 1584, 1556), 4.45 },
98 {
XYZ(1897, 1980, 1945), 7.94 },
99 {
XYZ(2276, 2376, 2334), 12.74 },
100 {
XYZ(2656, 2772, 2723), 19.01 },
101 {
XYZ(3035, 3168, 3112), 26.89 },
102 {
XYZ(3415, 3564, 3501), 36.52 },
103 {
XYZ(3794, 3960, 3890), 48.02 },
106 const double luminance = 48.00;
107 const double contrast = 2000;
109 const double Lb = luminance / (contrast - 1);
110 const double Lw = Lb + luminance;
114 memcpy(L_xyz,
tests[
i].E_xyz,
sizeof(L_xyz));
116 printf(
"trc=%s EOTF(%g, %g, {%g, %g, %g}) = {%g, %g %g}, expected Y=%f\n",
119 L_xyz[0], L_xyz[1], L_xyz[2],
tests[
i].luma);
128 static const double black_points[] = { 0.0, 1e-6, 0.1, 1.5 };
129 static const double white_points[] = { 50.0, 100.0, 203.0, 1000.0, 10000.0 };
133 const double Lb = black_points[
i];
134 const double Lw = white_points[j];
135 const double all0[3] = { 0.0, 0.0, 0.0 };
136 const double all1[3] = { 1.0, 1.0, 1.0 };
137 const double black[3] = { Lb, Lb, Lb };
138 const double white[3] = { Lw, Lw, Lw };
147 for (
double x = 0.0; x < 1.0; x += 0.1) {
148 const double E[3] = { x, x, x };
149 double L[3] = { x, x, x };
152 printf(
"trc=%s EOTF(%g, %g, {%g}) = {%g}\n",
153 trc_name, Lw, Lb,
E[1],
L[1]);
156 if (x > 0.0 &&
L[1] <= L_prev) {
157 printf(
" FAIL: non-monotonic!\n");