Commit 39ccb3ca12 for ffmpeg
commit 39ccb3ca120c0815c62c7f145a1aa1354f335680
Author: Kacper Michajłow <kasper93@gmail.com>
Date: Tue Nov 3 15:55:57 2026 +0100
avutil/csp: fix the negative segment of the BT.1361 transfer
See Rec. ITU-R BT.1361.
diff --git a/libavutil/csp.c b/libavutil/csp.c
index 5f37984429..2058297738 100644
--- a/libavutil/csp.c
+++ b/libavutil/csp.c
@@ -308,7 +308,7 @@ static double trc_bt1361(double Lc)
const double a = BT709_alpha;
const double b = BT709_beta;
- return (-0.0045 >= Lc) ? -(a * pow(-4.0 * Lc, 0.45) + (a - 1.0)) / 4.0
+ return (-0.0045 >= Lc) ? -(a * pow(-4.0 * Lc, 0.45) - (a - 1.0)) / 4.0
: ( b > Lc) ? 4.500 * Lc
: a * pow( Lc, 0.45) - (a - 1.0);
}
@@ -318,7 +318,7 @@ static double trc_bt1361_inv(double E)
const double a = BT709_alpha;
const double b = 4.500 * BT709_beta;
- return (-0.02025 >= E) ? -pow((-4.0 * E - (a - 1.0)) / a, 1.0 / 0.45) / 4.0
+ return (-0.02025 >= E) ? -pow((-4.0 * E + (a - 1.0)) / a, 1.0 / 0.45) / 4.0
: ( b > E) ? E / 4.500
: pow(( E + (a - 1.0)) / a, 1.0 / 0.45);
}
diff --git a/tests/ref/fate/color_utils b/tests/ref/fate/color_utils
index 07a61c313e..0f63bd8cea 100644
--- a/tests/ref/fate/color_utils
+++ b/tests/ref/fate/color_utils
@@ -169,9 +169,9 @@ trc=iec61966-2-4 calling func(15123.456700) expected=83.452916 roundtrip=15123.4
trc=iec61966-2-4 calling func(19845.889230) expected=94.321297 roundtrip=19845.889230
trc=iec61966-2-4 calling func(98678.423100) expected=194.219568 roundtrip=98678.423100
trc=iec61966-2-4 calling func(99999.899998) expected=195.386306 roundtrip=99999.899998
-trc=bt1361e calling func(-0.100000) expected=-0.206787 roundtrip=-0.100000
-trc=bt1361e calling func(-0.018054) expected=-0.109049 roundtrip=-0.018054
-trc=bt1361e calling func(-0.010000) expected=-0.089387 roundtrip=-0.010000
+trc=bt1361e calling func(-0.100000) expected=-0.157138 roundtrip=-0.100000
+trc=bt1361e calling func(-0.018054) expected=-0.059401 roundtrip=-0.018054
+trc=bt1361e calling func(-0.010000) expected=-0.039739 roundtrip=-0.010000
trc=bt1361e calling func(-0.004490) expected=-0.020205 roundtrip=-0.004490
trc=bt1361e calling func(0.000000) expected=0.000000 roundtrip=0.000000
trc=bt1361e calling func(0.003162) expected=0.014230 roundtrip=0.003162