This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 0bdda94ccc8169aa1ea94d91ebf7eed89d8bb703
Author:     marcos ashton <[email protected]>
AuthorDate: Mon May 18 00:23:43 2026 +0100
Commit:     michaelni <[email protected]>
CommitDate: Mon May 25 21:18:34 2026 +0000

    tests/fate/libavutil: add FATE test for csp
    
    Test the five public functions not already covered by
    tests/color_utils: av_csp_luma_coeffs_from_avcsp,
    av_csp_primaries_desc_from_id, av_csp_primaries_id_from_desc,
    av_csp_approximate_trc_gamma, and av_csp_approximate_eotf_gamma.
    Iterates every AVCOL_SPC, AVCOL_PRI, and AVCOL_TRC value including
    the extended ranges, round-trips primaries via desc_eq so the
    canonical first-match (e.g. smpte170m for smpte240m) is accepted,
    checks that a garbage desc returns AVCOL_PRI_UNSPECIFIED, and that
    out-of-range enum values return NULL or 0.0 as documented. The
    trc/eotf gamma values come from static lookup tables so the
    floating point output is bitexact across platforms.
    
    Coverage for libavutil/csp.c: 88.50% -> 94.46%
---
 .forgejo/CODEOWNERS        |   2 +
 libavutil/Makefile         |   1 +
 libavutil/tests/.gitignore |   1 +
 libavutil/tests/csp.c      | 145 +++++++++++++++++++++++++++++++++++++++++++++
 tests/fate/libavutil.mak   |   4 ++
 tests/ref/fate/csp         | 131 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 284 insertions(+)

diff --git a/.forgejo/CODEOWNERS b/.forgejo/CODEOWNERS
index fa0c62218c..3ada7b3e18 100644
--- a/.forgejo/CODEOWNERS
+++ b/.forgejo/CODEOWNERS
@@ -234,12 +234,14 @@ doc/.* @GyanD
 tests/checkasm/riscv/.* @Courmisch
 libavutil/tests/ambient_viewing_environment.* @MarcosAsh
 libavutil/tests/buffer.* @MarcosAsh
+libavutil/tests/csp.* @MarcosAsh
 libavutil/tests/hdr_dynamic_vivid_metadata.* @MarcosAsh
 libavutil/tests/tdrdi.* @MarcosAsh
 libavutil/tests/timestamp.* @MarcosAsh
 tests/ref/.*drawvg.* @ayosec
 tests/ref/fate/ambient_viewing_environment @MarcosAsh
 tests/ref/fate/buffer @MarcosAsh
+tests/ref/fate/csp @MarcosAsh
 tests/ref/fate/hdr_dynamic_vivid_metadata @MarcosAsh
 tests/ref/fate/sub-mcc.* @programmerjake
 tests/ref/fate/tdrdi @MarcosAsh
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 3fe02936ef..aa381c88cb 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -271,6 +271,7 @@ TESTPROGS = adler32                                         
            \
             color_utils                                                 \
             cpu                                                         \
             crc                                                         \
+            csp                                                         \
             des                                                         \
             detection_bbox                                              \
             dict                                                        \
diff --git a/libavutil/tests/.gitignore b/libavutil/tests/.gitignore
index 47b319bb89..38aa09022b 100644
--- a/libavutil/tests/.gitignore
+++ b/libavutil/tests/.gitignore
@@ -16,6 +16,7 @@
 /cpu
 /cpu_init
 /crc
+/csp
 /des
 /detection_bbox
 /dict
diff --git a/libavutil/tests/csp.c b/libavutil/tests/csp.c
new file mode 100644
index 0000000000..f21966452e
--- /dev/null
+++ b/libavutil/tests/csp.c
@@ -0,0 +1,145 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <stdio.h>
+
+#include "libavutil/csp.h"
+#include "libavutil/pixdesc.h"
+#include "libavutil/pixfmt.h"
+
+static void print_cie(const char *label, AVCIExy xy)
+{
+    printf("  %s=(%d/%d, %d/%d)\n", label,
+           xy.x.num, xy.x.den, xy.y.num, xy.y.den);
+}
+
+static int cie_eq(AVCIExy a, AVCIExy b)
+{
+    return av_cmp_q(a.x, b.x) == 0 && av_cmp_q(a.y, b.y) == 0;
+}
+
+static int desc_eq(const AVColorPrimariesDesc *a, const AVColorPrimariesDesc 
*b)
+{
+    return cie_eq(a->wp,     b->wp)     &&
+           cie_eq(a->prim.r, b->prim.r) &&
+           cie_eq(a->prim.g, b->prim.g) &&
+           cie_eq(a->prim.b, b->prim.b);
+}
+
+int main(void)
+{
+    /* av_csp_luma_coeffs_from_avcsp: iterate every defined colorspace */
+    printf("Testing av_csp_luma_coeffs_from_avcsp()\n");
+    for (enum AVColorSpace csp = 0; csp < AVCOL_SPC_NB; csp++) {
+        const AVLumaCoefficients *c = av_csp_luma_coeffs_from_avcsp(csp);
+        const char *name = av_color_space_name(csp);
+        if (!c) {
+            printf("csp=%-16s -> NULL\n", name ? name : "?");
+            continue;
+        }
+        printf("csp=%-16s -> cr=%d/%d cg=%d/%d cb=%d/%d\n",
+               name ? name : "?",
+               c->cr.num, c->cr.den,
+               c->cg.num, c->cg.den,
+               c->cb.num, c->cb.den);
+    }
+    /* out-of-range enum */
+    printf("csp=AVCOL_SPC_NB         -> %s\n",
+           av_csp_luma_coeffs_from_avcsp(AVCOL_SPC_NB) ? "FAIL" : "NULL");
+
+    /* av_csp_primaries_desc_from_id + av_csp_primaries_id_from_desc */
+    printf("\nTesting av_csp_primaries_desc_from_id() round trip\n");
+    for (enum AVColorPrimaries prm = 0; prm < AVCOL_PRI_EXT_NB; prm++) {
+        const AVColorPrimariesDesc *d;
+        const AVColorPrimariesDesc *d_back;
+        enum AVColorPrimaries back;
+        const char *name, *back_name, *status;
+
+        if (prm == AVCOL_PRI_NB)
+            prm = AVCOL_PRI_EXT_BASE;
+
+        d    = av_csp_primaries_desc_from_id(prm);
+        name = av_color_primaries_name(prm);
+        if (!d) {
+            printf("prm=%-16s -> NULL\n", name ? name : "?");
+            continue;
+        }
+        printf("prm=%-16s ->\n", name ? name : "?");
+        print_cie("wp ", d->wp);
+        print_cie("r  ", d->prim.r);
+        print_cie("g  ", d->prim.g);
+        print_cie("b  ", d->prim.b);
+
+        /* For colorspaces with identical primaries (e.g. smpte170m and
+         * smpte240m), the canonical first match may differ from the input
+         * enum, so compare descs not enums.  id_from_desc only searches
+         * the base AVCOL_PRI_* range and returns UNSPECIFIED for
+         * extended-range inputs that have no base match. */
+        back      = av_csp_primaries_id_from_desc(d);
+        d_back    = av_csp_primaries_desc_from_id(back);
+        back_name = av_color_primaries_name(back);
+        if (back == AVCOL_PRI_UNSPECIFIED)
+            status = prm >= AVCOL_PRI_EXT_BASE ? "ext-no-base-match"
+                                               : "MISMATCH";
+        else
+            status = d_back && desc_eq(d, d_back) ? "OK" : "MISMATCH";
+        printf("  round-trip id=%-16s desc=%s\n",
+               back_name ? back_name : "?", status);
+    }
+    /* out-of-range enum */
+    printf("prm=AVCOL_PRI_NB         -> %s\n",
+           av_csp_primaries_desc_from_id(AVCOL_PRI_NB) ? "FAIL" : "NULL");
+
+    /* id_from_desc on a garbage description returns UNSPECIFIED */
+    {
+        AVColorPrimariesDesc garbage = {
+            .wp   = { { 0, 1 }, { 0, 1 } },
+            .prim = {
+                .r = { { 0, 1 }, { 0, 1 } },
+                .g = { { 0, 1 }, { 0, 1 } },
+                .b = { { 0, 1 }, { 0, 1 } },
+            },
+        };
+        enum AVColorPrimaries back = av_csp_primaries_id_from_desc(&garbage);
+        printf("garbage desc -> %s (expect AVCOL_PRI_UNSPECIFIED)\n",
+               av_color_primaries_name(back) ? av_color_primaries_name(back) : 
"?");
+    }
+
+    /* av_csp_approximate_trc_gamma + av_csp_approximate_eotf_gamma:
+     * both return values from static tables, so output is bitexact. */
+    printf("\nTesting av_csp_approximate_{trc,eotf}_gamma()\n");
+    for (enum AVColorTransferCharacteristic trc = 0; trc < AVCOL_TRC_EXT_NB; 
trc++) {
+        const char *name;
+        double g_trc, g_eotf;
+
+        if (trc == AVCOL_TRC_NB)
+            trc = AVCOL_TRC_EXT_BASE;
+
+        name   = av_color_transfer_name(trc);
+        g_trc  = av_csp_approximate_trc_gamma(trc);
+        g_eotf = av_csp_approximate_eotf_gamma(trc);
+        printf("trc=%-16s trc_gamma=%.6f eotf_gamma=%.6f\n",
+               name ? name : "?", g_trc, g_eotf);
+    }
+    /* out-of-range enum: both must return 0.0 */
+    printf("trc=AVCOL_TRC_NB         trc_gamma=%.6f eotf_gamma=%.6f\n",
+           av_csp_approximate_trc_gamma(AVCOL_TRC_NB),
+           av_csp_approximate_eotf_gamma(AVCOL_TRC_NB));
+
+    return 0;
+}
diff --git a/tests/fate/libavutil.mak b/tests/fate/libavutil.mak
index 166c0d8c64..a2ea57d939 100644
--- a/tests/fate/libavutil.mak
+++ b/tests/fate/libavutil.mak
@@ -73,6 +73,10 @@ FATE_LIBAVUTIL += fate-color_utils
 fate-color_utils: libavutil/tests/color_utils$(EXESUF)
 fate-color_utils: CMD = run libavutil/tests/color_utils$(EXESUF)
 
+FATE_LIBAVUTIL += fate-csp
+fate-csp: libavutil/tests/csp$(EXESUF)
+fate-csp: CMD = run libavutil/tests/csp$(EXESUF)
+
 FATE_LIBAVUTIL += fate-des
 fate-des: libavutil/tests/des$(EXESUF)
 fate-des: CMD = run libavutil/tests/des$(EXESUF)
diff --git a/tests/ref/fate/csp b/tests/ref/fate/csp
new file mode 100644
index 0000000000..bc36bc66ba
--- /dev/null
+++ b/tests/ref/fate/csp
@@ -0,0 +1,131 @@
+Testing av_csp_luma_coeffs_from_avcsp()
+csp=gbr              -> cr=100000/100000 cg=100000/100000 cb=100000/100000
+csp=bt709            -> cr=21260/100000 cg=71520/100000 cb=7220/100000
+csp=unknown          -> NULL
+csp=reserved         -> NULL
+csp=fcc              -> cr=30000/100000 cg=59000/100000 cb=11000/100000
+csp=bt470bg          -> cr=29900/100000 cg=58700/100000 cb=11400/100000
+csp=smpte170m        -> cr=29900/100000 cg=58700/100000 cb=11400/100000
+csp=smpte240m        -> cr=21200/100000 cg=70100/100000 cb=8700/100000
+csp=ycgco            -> cr=25000/100000 cg=50000/100000 cb=25000/100000
+csp=bt2020nc         -> cr=26270/100000 cg=67800/100000 cb=5930/100000
+csp=bt2020c          -> cr=26270/100000 cg=67800/100000 cb=5930/100000
+csp=smpte2085        -> NULL
+csp=chroma-derived-nc -> NULL
+csp=chroma-derived-c -> NULL
+csp=ictcp            -> NULL
+csp=ipt-c2           -> NULL
+csp=ycgco-re         -> NULL
+csp=ycgco-ro         -> NULL
+csp=AVCOL_SPC_NB         -> NULL
+
+Testing av_csp_primaries_desc_from_id() round trip
+prm=reserved         -> NULL
+prm=bt709            ->
+  wp =(31270/100000, 32900/100000)
+  r  =(64000/100000, 33000/100000)
+  g  =(30000/100000, 60000/100000)
+  b  =(15000/100000, 6000/100000)
+  round-trip id=bt709            desc=OK
+prm=unknown          -> NULL
+prm=reserved         -> NULL
+prm=bt470m           ->
+  wp =(31000/100000, 31600/100000)
+  r  =(67000/100000, 33000/100000)
+  g  =(21000/100000, 71000/100000)
+  b  =(14000/100000, 8000/100000)
+  round-trip id=bt470m           desc=OK
+prm=bt470bg          ->
+  wp =(31270/100000, 32900/100000)
+  r  =(64000/100000, 33000/100000)
+  g  =(29000/100000, 60000/100000)
+  b  =(15000/100000, 6000/100000)
+  round-trip id=bt470bg          desc=OK
+prm=smpte170m        ->
+  wp =(31270/100000, 32900/100000)
+  r  =(63000/100000, 34000/100000)
+  g  =(31000/100000, 59500/100000)
+  b  =(15500/100000, 7000/100000)
+  round-trip id=smpte170m        desc=OK
+prm=smpte240m        ->
+  wp =(31270/100000, 32900/100000)
+  r  =(63000/100000, 34000/100000)
+  g  =(31000/100000, 59500/100000)
+  b  =(15500/100000, 7000/100000)
+  round-trip id=smpte170m        desc=OK
+prm=film             ->
+  wp =(31000/100000, 31600/100000)
+  r  =(68100/100000, 31900/100000)
+  g  =(24300/100000, 69200/100000)
+  b  =(14500/100000, 4900/100000)
+  round-trip id=film             desc=OK
+prm=bt2020           ->
+  wp =(31270/100000, 32900/100000)
+  r  =(70800/100000, 29200/100000)
+  g  =(17000/100000, 79700/100000)
+  b  =(13100/100000, 4600/100000)
+  round-trip id=bt2020           desc=OK
+prm=smpte428         ->
+  wp =(1/3, 1/3)
+  r  =(73500/100000, 26500/100000)
+  g  =(27400/100000, 71800/100000)
+  b  =(16700/100000, 900/100000)
+  round-trip id=smpte428         desc=OK
+prm=smpte431         ->
+  wp =(31400/100000, 35100/100000)
+  r  =(68000/100000, 32000/100000)
+  g  =(26500/100000, 69000/100000)
+  b  =(15000/100000, 6000/100000)
+  round-trip id=smpte431         desc=OK
+prm=smpte432         ->
+  wp =(31270/100000, 32900/100000)
+  r  =(68000/100000, 32000/100000)
+  g  =(26500/100000, 69000/100000)
+  b  =(15000/100000, 6000/100000)
+  round-trip id=smpte432         desc=OK
+prm=?                -> NULL
+prm=?                -> NULL
+prm=?                -> NULL
+prm=?                -> NULL
+prm=?                -> NULL
+prm=?                -> NULL
+prm=?                -> NULL
+prm=?                -> NULL
+prm=?                -> NULL
+prm=ebu3213          ->
+  wp =(31270/100000, 32900/100000)
+  r  =(63000/100000, 34000/100000)
+  g  =(29500/100000, 60500/100000)
+  b  =(15500/100000, 7700/100000)
+  round-trip id=ebu3213          desc=OK
+prm=vgamut           ->
+  wp =(31270/100000, 32900/100000)
+  r  =(73000/100000, 28000/100000)
+  g  =(16500/100000, 84000/100000)
+  b  =(10000/100000, -2999/100000)
+  round-trip id=unknown          desc=ext-no-base-match
+prm=AVCOL_PRI_NB         -> NULL
+garbage desc -> unknown (expect AVCOL_PRI_UNSPECIFIED)
+
+Testing av_csp_approximate_{trc,eotf}_gamma()
+trc=reserved         trc_gamma=0.000000 eotf_gamma=0.000000
+trc=bt709            trc_gamma=1.961000 eotf_gamma=2.200000
+trc=unknown          trc_gamma=0.000000 eotf_gamma=0.000000
+trc=reserved         trc_gamma=0.000000 eotf_gamma=0.000000
+trc=bt470m           trc_gamma=2.200000 eotf_gamma=2.200000
+trc=bt470bg          trc_gamma=2.800000 eotf_gamma=2.800000
+trc=smpte170m        trc_gamma=1.961000 eotf_gamma=2.200000
+trc=smpte240m        trc_gamma=1.961000 eotf_gamma=2.200000
+trc=linear           trc_gamma=1.000000 eotf_gamma=1.000000
+trc=log100           trc_gamma=0.000000 eotf_gamma=0.000000
+trc=log316           trc_gamma=0.000000 eotf_gamma=0.000000
+trc=iec61966-2-4     trc_gamma=0.000000 eotf_gamma=0.000000
+trc=bt1361e          trc_gamma=1.961000 eotf_gamma=2.200000
+trc=iec61966-2-1     trc_gamma=2.200000 eotf_gamma=2.200000
+trc=bt2020-10        trc_gamma=1.961000 eotf_gamma=2.200000
+trc=bt2020-12        trc_gamma=1.961000 eotf_gamma=2.200000
+trc=smpte2084        trc_gamma=0.000000 eotf_gamma=0.000000
+trc=smpte428         trc_gamma=2.600000 eotf_gamma=2.600000
+trc=arib-std-b67     trc_gamma=0.000000 eotf_gamma=0.000000
+trc=vlog             trc_gamma=2.200000 eotf_gamma=2.200000
+trc=AVCOL_TRC_NB         trc_gamma=0.000000 eotf_gamma=0.000000

_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to