From 33c0ff957b5a37c1d59069ee414282bb45d21298 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tomas=20H=C3=A4rdin?= <git@haerdin.se>
Date: Fri, 3 Feb 2023 15:00:05 +0100
Subject: [PATCH 1/2] lavfi/vf_colorspace: Add support for 14- and 16-bit YUV
---
libavfilter/colorspacedsp.c | 36 +++++++++++++++++++++++++++-
libavfilter/colorspacedsp.h | 2 ++
libavfilter/colorspacedsp_template.c | 8 +++++++
libavfilter/vf_colorspace.c | 10 +++++++-
4 files changed, 54 insertions(+), 2 deletions(-)
@@ -39,6 +39,14 @@
#define BIT_DEPTH 12
#include "colorspacedsp_template.c"
+#undef BIT_DEPTH
+#define BIT_DEPTH 14
+#include "colorspacedsp_template.c"
+
+#undef BIT_DEPTH
+#define BIT_DEPTH 16
+#include "colorspacedsp_template.c"
+
#undef SS_W
#undef SS_H
@@ -57,6 +65,14 @@
#define BIT_DEPTH 12
#include "colorspacedsp_template.c"
+#undef BIT_DEPTH
+#define BIT_DEPTH 14
+#include "colorspacedsp_template.c"
+
+#undef BIT_DEPTH
+#define BIT_DEPTH 16
+#include "colorspacedsp_template.c"
+
#undef SS_W
#undef SS_H
@@ -75,6 +91,14 @@
#define BIT_DEPTH 12
#include "colorspacedsp_template.c"
+#undef BIT_DEPTH
+#define BIT_DEPTH 14
+#include "colorspacedsp_template.c"
+
+#undef BIT_DEPTH
+#define BIT_DEPTH 16
+#include "colorspacedsp_template.c"
+
static void multiply3x3_c(int16_t *buf[3], ptrdiff_t stride,
int w, int h, const int16_t m[3][3][8])
{
@@ -109,6 +133,8 @@ void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
init_yuv2rgb_fn( 8);
init_yuv2rgb_fn(10);
init_yuv2rgb_fn(12);
+ init_yuv2rgb_fn(14);
+ init_yuv2rgb_fn(16);
#define init_rgb2yuv_fn(bit) \
dsp->rgb2yuv[BPP_##bit][SS_444] = rgb2yuv_444p##bit##_c; \
@@ -118,6 +144,8 @@ void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
init_rgb2yuv_fn( 8);
init_rgb2yuv_fn(10);
init_rgb2yuv_fn(12);
+ init_rgb2yuv_fn(14);
+ init_rgb2yuv_fn(16);
#define init_rgb2yuv_fsb_fn(bit) \
dsp->rgb2yuv_fsb[BPP_##bit][SS_444] = rgb2yuv_fsb_444p##bit##_c; \
@@ -127,6 +155,8 @@ void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
init_rgb2yuv_fsb_fn( 8);
init_rgb2yuv_fsb_fn(10);
init_rgb2yuv_fsb_fn(12);
+ init_rgb2yuv_fsb_fn(14);
+ init_rgb2yuv_fsb_fn(16);
#define init_yuv2yuv_fn(idx1, bit1, bit2) \
dsp->yuv2yuv[idx1][BPP_##bit2][SS_444] = yuv2yuv_444p##bit1##to##bit2##_c; \
@@ -135,11 +165,15 @@ void ff_colorspacedsp_init(ColorSpaceDSPContext *dsp)
#define init_yuv2yuv_fns(bit1) \
init_yuv2yuv_fn(BPP_##bit1, bit1, 8); \
init_yuv2yuv_fn(BPP_##bit1, bit1, 10); \
- init_yuv2yuv_fn(BPP_##bit1, bit1, 12)
+ init_yuv2yuv_fn(BPP_##bit1, bit1, 12); \
+ init_yuv2yuv_fn(BPP_##bit1, bit1, 14); \
+ init_yuv2yuv_fn(BPP_##bit1, bit1, 16)
init_yuv2yuv_fns( 8);
init_yuv2yuv_fns(10);
init_yuv2yuv_fns(12);
+ init_yuv2yuv_fns(14);
+ init_yuv2yuv_fns(16);
dsp->multiply3x3 = multiply3x3_c;
@@ -46,6 +46,8 @@ enum BitDepthIndex {
BPP_8,
BPP_10,
BPP_12,
+ BPP_14,
+ BPP_16,
NB_BPP,
};
@@ -340,3 +340,11 @@ static void fn(rgb2yuv_fsb)(uint8_t *_yuv[3], const ptrdiff_t yuv_stride[3],
#undef IN_BIT_DEPTH
#define IN_BIT_DEPTH 12
#include "colorspacedsp_yuv2yuv_template.c"
+
+#undef IN_BIT_DEPTH
+#define IN_BIT_DEPTH 14
+#include "colorspacedsp_yuv2yuv_template.c"
+
+#undef IN_BIT_DEPTH
+#define IN_BIT_DEPTH 16
+#include "colorspacedsp_yuv2yuv_template.c"
@@ -402,7 +402,7 @@ static int create_filtergraph(AVFilterContext *ctx,
const AVPixFmtDescriptor *out_desc = av_pix_fmt_desc_get(out->format);
int emms = 0, m, n, o, res, fmt_identical, redo_yuv2rgb = 0, redo_rgb2yuv = 0;
-#define supported_depth(d) ((d) == 8 || (d) == 10 || (d) == 12)
+#define supported_depth(d) ((d) == 8 || (d) == 10 || (d) == 12 || (d) == 14 || (d) == 16)
#define supported_subsampling(lcw, lch) \
(((lcw) == 0 && (lch) == 0) || ((lcw) == 1 && (lch) == 0) || ((lcw) == 1 && (lch) == 1))
#define supported_format(d) \
@@ -842,6 +842,8 @@ static int query_formats(AVFilterContext *ctx)
AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUV444P,
AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUV444P10,
AV_PIX_FMT_YUV420P12, AV_PIX_FMT_YUV422P12, AV_PIX_FMT_YUV444P12,
+ AV_PIX_FMT_YUV420P14, AV_PIX_FMT_YUV422P14, AV_PIX_FMT_YUV444P14,
+ AV_PIX_FMT_YUV420P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV444P16,
AV_PIX_FMT_YUVJ420P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
AV_PIX_FMT_NONE
};
@@ -961,12 +963,18 @@ static const AVOption colorspace_options[] = {
ENUM("yuv420p", AV_PIX_FMT_YUV420P, "fmt"),
ENUM("yuv420p10", AV_PIX_FMT_YUV420P10, "fmt"),
ENUM("yuv420p12", AV_PIX_FMT_YUV420P12, "fmt"),
+ ENUM("yuv420p14", AV_PIX_FMT_YUV420P14, "fmt"),
+ ENUM("yuv420p16", AV_PIX_FMT_YUV420P16, "fmt"),
ENUM("yuv422p", AV_PIX_FMT_YUV422P, "fmt"),
ENUM("yuv422p10", AV_PIX_FMT_YUV422P10, "fmt"),
ENUM("yuv422p12", AV_PIX_FMT_YUV422P12, "fmt"),
+ ENUM("yuv422p14", AV_PIX_FMT_YUV422P14, "fmt"),
+ ENUM("yuv422p16", AV_PIX_FMT_YUV422P16, "fmt"),
ENUM("yuv444p", AV_PIX_FMT_YUV444P, "fmt"),
ENUM("yuv444p10", AV_PIX_FMT_YUV444P10, "fmt"),
ENUM("yuv444p12", AV_PIX_FMT_YUV444P12, "fmt"),
+ ENUM("yuv444p14", AV_PIX_FMT_YUV444P14, "fmt"),
+ ENUM("yuv444p16", AV_PIX_FMT_YUV444P16, "fmt"),
{ "fast", "Ignore primary chromaticity and gamma correction",
OFFSET(fast_mode), AV_OPT_TYPE_BOOL, { .i64 = 0 },
--
2.30.2