From dacae40a4bbb542b0f02ba32ca558d318c7b7db0 Mon Sep 17 00:00:00 2001 From: Limin Wang Date: Fri, 5 Jun 2020 21:58:01 +0800 Subject: [PATCH] avfilter/vf_overlay: add yuv420p10 and yuv422p10 10bit format support Signed-off-by: Limin Wang --- doc/filters.texi | 6 +++ libavfilter/vf_overlay.c | 79 ++++++++++++++++++++++++++++++++++++++++ libavfilter/vf_overlay.h | 2 + 3 files changed, 87 insertions(+) diff --git a/doc/filters.texi b/doc/filters.texi index 84567dec16..5f0eb28f76 100644 --- a/doc/filters.texi +++ b/doc/filters.texi @@ -14342,9 +14342,15 @@ It accepts the following values: @item yuv420 force YUV420 output +@item yuv420p10 +force YUV420p10 output + @item yuv422 force YUV422 output +@item yuv422p10 +force YUV422p10 output + @item yuv444 force YUV444 output diff --git a/libavfilter/vf_overlay.c b/libavfilter/vf_overlay.c index 5c986c3bd3..b3a1ac1a09 100644 --- a/libavfilter/vf_overlay.c +++ b/libavfilter/vf_overlay.c @@ -154,6 +154,7 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar static const enum AVPixelFormat alpha_pix_fmts[] = { AV_PIX_FMT_YUVA420P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA444P, + AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, AV_PIX_FMT_GBRAP, AV_PIX_FMT_NONE }; @@ -172,6 +173,14 @@ static int query_formats(AVFilterContext *ctx) AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE }; + static const enum AVPixelFormat main_pix_fmts_yuv420p10[] = { + AV_PIX_FMT_YUV420P10, AV_PIX_FMT_YUVA420P10, + AV_PIX_FMT_NONE + }; + static const enum AVPixelFormat overlay_pix_fmts_yuv420p10[] = { + AV_PIX_FMT_YUVA420P10, AV_PIX_FMT_NONE + }; + static const enum AVPixelFormat main_pix_fmts_yuv422[] = { AV_PIX_FMT_YUV422P, AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_NONE }; @@ -179,6 +188,13 @@ static int query_formats(AVFilterContext *ctx) AV_PIX_FMT_YUVA422P, AV_PIX_FMT_NONE }; + static const enum AVPixelFormat main_pix_fmts_yuv422p10[] = { + AV_PIX_FMT_YUV422P10, AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_NONE + }; + static const enum AVPixelFormat overlay_pix_fmts_yuv422p10[] = { + AV_PIX_FMT_YUVA422P10, AV_PIX_FMT_NONE + }; + static const enum AVPixelFormat main_pix_fmts_yuv444[] = { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE }; @@ -217,6 +233,13 @@ static int query_formats(AVFilterContext *ctx) goto fail; } break; + case OVERLAY_FORMAT_YUV420P10: + if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv420p10)) || + !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv420p10))) { + ret = AVERROR(ENOMEM); + goto fail; + } + break; case OVERLAY_FORMAT_YUV422: if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv422)) || !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv422))) { @@ -224,6 +247,13 @@ static int query_formats(AVFilterContext *ctx) goto fail; } break; + case OVERLAY_FORMAT_YUV422P10: + if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv422p10)) || + !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv422p10))) { + ret = AVERROR(ENOMEM); + goto fail; + } + break; case OVERLAY_FORMAT_YUV444: if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv444)) || !(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv444))) { @@ -566,6 +596,7 @@ static av_always_inline void blend_plane_##depth##_##nbits##bits(AVFilterContext } \ } DEFINE_BLEND_PLANE(8, 8); +DEFINE_BLEND_PLANE(16, 10); #define DEFINE_ALPHA_COMPOSITE(depth, nbits) \ static inline void alpha_composite_##depth##_##nbits##bits(const AVFrame *src, const AVFrame *dst, \ @@ -617,6 +648,7 @@ static inline void alpha_composite_##depth##_##nbits##bits(const AVFrame *src, c } \ } DEFINE_ALPHA_COMPOSITE(8, 8); +DEFINE_ALPHA_COMPOSITE(16, 10); #define DEFINE_BLEND_SLICE_YUV(depth, nbits) \ static av_always_inline void blend_slice_yuv_##depth##_##nbits##bits(AVFilterContext *ctx, \ @@ -648,6 +680,7 @@ static av_always_inline void blend_slice_yuv_##depth##_##nbits##bits(AVFilterCon jobnr, nb_jobs); \ } DEFINE_BLEND_SLICE_YUV(8, 8); +DEFINE_BLEND_SLICE_YUV(16, 10); static av_always_inline void blend_slice_planar_rgb(AVFilterContext *ctx, AVFrame *dst, const AVFrame *src, @@ -694,6 +727,38 @@ static int blend_slice_yuva420(AVFilterContext *ctx, void *arg, int jobnr, int n return 0; } +static int blend_slice_yuv420p10(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) +{ + OverlayContext *s = ctx->priv; + ThreadData *td = arg; + blend_slice_yuv_16_10bits(ctx, td->dst, td->src, 1, 1, 0, s->x, s->y, 1, jobnr, nb_jobs); + return 0; +} + +static int blend_slice_yuva420p10(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) +{ + OverlayContext *s = ctx->priv; + ThreadData *td = arg; + blend_slice_yuv_16_10bits(ctx, td->dst, td->src, 1, 1, 1, s->x, s->y, 1, jobnr, nb_jobs); + return 0; +} + +static int blend_slice_yuv422p10(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) +{ + OverlayContext *s = ctx->priv; + ThreadData *td = arg; + blend_slice_yuv_16_10bits(ctx, td->dst, td->src, 1, 0, 0, s->x, s->y, 1, jobnr, nb_jobs); + return 0; +} + +static int blend_slice_yuva422p10(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) +{ + OverlayContext *s = ctx->priv; + ThreadData *td = arg; + blend_slice_yuv_16_10bits(ctx, td->dst, td->src, 1, 0, 1, s->x, s->y, 1, jobnr, nb_jobs); + return 0; +} + static int blend_slice_yuv422(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { OverlayContext *s = ctx->priv; @@ -857,9 +922,15 @@ static int config_input_main(AVFilterLink *inlink) case OVERLAY_FORMAT_YUV420: s->blend_slice = s->main_has_alpha ? blend_slice_yuva420 : blend_slice_yuv420; break; + case OVERLAY_FORMAT_YUV420P10: + s->blend_slice = s->main_has_alpha ? blend_slice_yuva420p10 : blend_slice_yuv420p10; + break; case OVERLAY_FORMAT_YUV422: s->blend_slice = s->main_has_alpha ? blend_slice_yuva422 : blend_slice_yuv422; break; + case OVERLAY_FORMAT_YUV422P10: + s->blend_slice = s->main_has_alpha ? blend_slice_yuva422p10 : blend_slice_yuv422p10; + break; case OVERLAY_FORMAT_YUV444: s->blend_slice = s->main_has_alpha ? blend_slice_yuva444 : blend_slice_yuv444; break; @@ -874,9 +945,15 @@ static int config_input_main(AVFilterLink *inlink) case AV_PIX_FMT_YUVA420P: s->blend_slice = blend_slice_yuva420; break; + case AV_PIX_FMT_YUVA420P10: + s->blend_slice = blend_slice_yuva420p10; + break; case AV_PIX_FMT_YUVA422P: s->blend_slice = blend_slice_yuva422; break; + case AV_PIX_FMT_YUVA422P10: + s->blend_slice = blend_slice_yuva422p10; + break; case AV_PIX_FMT_YUVA444P: s->blend_slice = blend_slice_yuva444; break; @@ -1028,7 +1105,9 @@ static const AVOption overlay_options[] = { { "shortest", "force termination when the shortest input terminates", OFFSET(fs.opt_shortest), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, FLAGS }, { "format", "set output format", OFFSET(format), AV_OPT_TYPE_INT, {.i64=OVERLAY_FORMAT_YUV420}, 0, OVERLAY_FORMAT_NB-1, FLAGS, "format" }, { "yuv420", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV420}, .flags = FLAGS, .unit = "format" }, + { "yuv420p10", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV420P10}, .flags = FLAGS, .unit = "format" }, { "yuv422", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV422}, .flags = FLAGS, .unit = "format" }, + { "yuv422p10", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV422P10}, .flags = FLAGS, .unit = "format" }, { "yuv444", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_YUV444}, .flags = FLAGS, .unit = "format" }, { "rgb", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_RGB}, .flags = FLAGS, .unit = "format" }, { "gbrp", "", 0, AV_OPT_TYPE_CONST, {.i64=OVERLAY_FORMAT_GBRP}, .flags = FLAGS, .unit = "format" }, diff --git a/libavfilter/vf_overlay.h b/libavfilter/vf_overlay.h index 98b06eaacf..30a1a7371c 100644 --- a/libavfilter/vf_overlay.h +++ b/libavfilter/vf_overlay.h @@ -41,7 +41,9 @@ enum var_name { enum OverlayFormat { OVERLAY_FORMAT_YUV420, + OVERLAY_FORMAT_YUV420P10, OVERLAY_FORMAT_YUV422, + OVERLAY_FORMAT_YUV422P10, OVERLAY_FORMAT_YUV444, OVERLAY_FORMAT_RGB, OVERLAY_FORMAT_GBRP,