From patchwork Wed Jan 31 11:17:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45925 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp2756701pzb; Wed, 31 Jan 2024 03:17:30 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUP7XpSQo0Y08HmwRLlQAwWYMyGit1NOGSgAO0J73CaZq7ci1Cue+8VlGcf+ofK0wcXO0pWWEiRPWTNEcAB7mPxhRniSQ45i4Jqiw== X-Google-Smtp-Source: AGHT+IFRD+T5h12B/2Rdb+ZHcJ7CJlQLJPN71L6ExXcHZp2H1gZGAchL/YLjTOGBYOg3NYwZuIFa X-Received: by 2002:a2e:4c02:0:b0:2cc:e68b:ee59 with SMTP id z2-20020a2e4c02000000b002cce68bee59mr891013lja.1.1706699850055; Wed, 31 Jan 2024 03:17:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706699850; cv=none; d=google.com; s=arc-20160816; b=nLTN6BQnpd2sbBw/tBiZGidEWFec1fX8gA+5ErYoEGOsZ6QoOLBGXbH9QH7NAtJ8x8 EN6xwFqsj3oibd1ppXWvfRQUG60hQQmd2IxOwwFatl1wG/DCkHUyuZ8eUuMrsqf9AKvp QZr+gkmoxy8FmORgbqcK3209Xnj4R1QnLIENTKmw58yyZKtlvyHrmewwgGsSyd/MvluJ 6tRXvSv/hPakg5SiB/7kziMIRpl6EefH3sTRP0B0X1rtj5a3FUqI+uVfOaYHYNCllw9z w51W9tzVf6K8AXLrC3VDnzkLhVLIs1V7dyQdHrRSQZu/j5tCNKGtjDdWhYC/9ApRetR0 jJ4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=sA2kAtkFHHh2jl0V36LvE1tBClofnfY0NuH5f6YEzU8=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=rOxSMTxqzD4Mmw0di65wk1WP9E8fOaPhb07dJ6Rf2wKYWyoo3aRZ6tqbRV/TIWF5xM l6PtoHmRTOca+6D4nYGrE8sRM0NpOAWYmFADRBZLmX22vJXYoFwg6EhoU7EwbIj6mkT8 ob6muhURqnSbrmu53oN5YG1NxGJN0zdQVb238lnWWZANGra8KKi5xEGXxBTEIrnNCaa6 lSPLEE9ULvHUp2PYouQvI6Nb1dHqdDT1oVWDePSybVK/DpW3j8dboUNE61W2m+wYqLy0 KCPRKaFlyrCiQUTbFU792Kv0nVl5QuA+QqoJZY9eHo0Mc+VzcYCFdoP9BMG4f4NTcy1D TRjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=To0n3Ick; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b102-20020a509f6f000000b0055f85a066d5si546639edf.274.2024.01.31.03.17.29; Wed, 31 Jan 2024 03:17:30 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=To0n3Ick; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 05FC168D146; Wed, 31 Jan 2024 13:17:16 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 64A1F68C2FE for ; Wed, 31 Jan 2024 13:17:08 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 9A57F42E41; Wed, 31 Jan 2024 12:17:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1706699827; bh=vUZS5DK9d4Y7FXZ8Af3tIkAkfGAxXgxOKcSPxkiQRMQ=; h=From:To:Cc:Subject:Date:From; b=To0n3IckW02aXhMsUbr3b3ybqN48SYp4JPamio11FKpdanH9e50bBliS397MuY/vE JvAW/onCdPmpOQWZ07ZYjWHAihBSMryoi5xIO+x5KmhPxCC403nexGGzktBgDDkgpG JMrBh0mXsbZrIFj/UBgANV9G3q0+SQrsuPCFhkGI= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Jan 2024 12:17:03 +0100 Message-ID: <20240131111704.44140-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avfilter: pass link YUV colorspace to ff_draw_init2 X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: UIvLRUpewtTX From: Niklas Haas This makes all ff_draw_* based filters aware of YUV colorspaces and ranges. Needed for YUVJ removal. Also fixes a bug where e.g. vf_pad would generate a limited range background even after conversion to full-scale grayscale. The FATE changes were a consequence of the aforementioned bugfix - the gray scale files are output as full range (due to conversion by libswscale, which hard-codes gray = full), and appropriately tagged as such, but before this change the padded version incorrectly used a limited range (16) black background for these formats. --- libavfilter/qrencode.c | 8 +++++--- libavfilter/src_avsynctest.c | 2 +- libavfilter/vf_datascope.c | 2 +- libavfilter/vf_drawtext.c | 2 +- libavfilter/vf_pad.c | 2 +- libavfilter/vf_rotate.c | 2 +- libavfilter/vf_shear.c | 2 +- libavfilter/vf_stack.c | 3 ++- libavfilter/vf_subtitles.c | 3 ++- libavfilter/vf_tile.c | 2 +- libavfilter/vf_tinterlace.c | 2 +- libavfilter/vf_tpad.c | 2 +- libavfilter/vsrc_testsrc.c | 9 ++++++--- tests/ref/fate/filter-pixfmts-pad | 16 ++++++++-------- 14 files changed, 32 insertions(+), 25 deletions(-) diff --git a/libavfilter/qrencode.c b/libavfilter/qrencode.c index 09af8dfb4e..6b86e01f57 100644 --- a/libavfilter/qrencode.c +++ b/libavfilter/qrencode.c @@ -638,7 +638,7 @@ static int qrencodesrc_config_props(AVFilterLink *outlink) ff_draw_color(&qr->draw, &qr->draw_foreground_color, (const uint8_t *)&qr->foreground_color); ff_draw_color(&qr->draw, &qr->draw_background_color, (const uint8_t *)&qr->background_color); - ff_draw_init(&qr->draw0, outlink->format, FF_DRAW_PROCESS_ALPHA); + ff_draw_init2(&qr->draw0, outlink->format, outlink->colorspace, outlink->color_range, FF_DRAW_PROCESS_ALPHA); ff_draw_color(&qr->draw0, &qr->draw0_background_color, (const uint8_t *)&qr->background_color); outlink->w = qr->rendered_padded_qrcode_width; @@ -730,7 +730,8 @@ static int qrencode_config_input(AVFilterLink *inlink) qr->is_source = 0; - ff_draw_init(&qr->draw, inlink->format, FF_DRAW_PROCESS_ALPHA); + ff_draw_init2(&qr->draw, inlink->format, inlink->colorspace, inlink->color_range, + FF_DRAW_PROCESS_ALPHA); V(W) = V(main_w) = inlink->w; V(H) = V(main_h) = inlink->h; @@ -759,7 +760,8 @@ static int qrencode_config_input(AVFilterLink *inlink) PARSE_EXPR(rendered_qrcode_width); PARSE_EXPR(rendered_padded_qrcode_width); - ff_draw_init(&qr->draw, inlink->format, FF_DRAW_PROCESS_ALPHA); + ff_draw_init2(&qr->draw, inlink->format, inlink->colorspace, inlink->color_range, + FF_DRAW_PROCESS_ALPHA); ff_draw_color(&qr->draw, &qr->draw_foreground_color, (const uint8_t *)&qr->foreground_color); ff_draw_color(&qr->draw, &qr->draw_background_color, (const uint8_t *)&qr->background_color); diff --git a/libavfilter/src_avsynctest.c b/libavfilter/src_avsynctest.c index a0fef7a1cb..9fd0b590c1 100644 --- a/libavfilter/src_avsynctest.c +++ b/libavfilter/src_avsynctest.c @@ -160,7 +160,7 @@ static av_cold int config_props(AVFilterLink *outlink) s->dir = 1; s->prev_intpart = INT64_MIN; - ff_draw_init(&s->draw, outlink->format, 0); + ff_draw_init2(&s->draw, outlink->format, outlink->colorspace, outlink->color_range, 0); ff_draw_color(&s->draw, &s->fg, s->rgba[0]); ff_draw_color(&s->draw, &s->bg, s->rgba[1]); diff --git a/libavfilter/vf_datascope.c b/libavfilter/vf_datascope.c index 89b59f2510..4845c9918d 100644 --- a/libavfilter/vf_datascope.c +++ b/libavfilter/vf_datascope.c @@ -383,7 +383,7 @@ static int config_input(AVFilterLink *inlink) uint8_t alpha = s->opacity * 255; s->nb_planes = av_pix_fmt_count_planes(inlink->format); - ff_draw_init(&s->draw, inlink->format, 0); + ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); ff_draw_color(&s->draw, &s->white, (uint8_t[]){ 255, 255, 255, 255} ); ff_draw_color(&s->draw, &s->black, (uint8_t[]){ 0, 0, 0, alpha} ); ff_draw_color(&s->draw, &s->yellow, (uint8_t[]){ 255, 255, 0, 255} ); diff --git a/libavfilter/vf_drawtext.c b/libavfilter/vf_drawtext.c index fe7e6ace27..37110bc32f 100644 --- a/libavfilter/vf_drawtext.c +++ b/libavfilter/vf_drawtext.c @@ -1152,7 +1152,7 @@ static int config_input(AVFilterLink *inlink) char *expr; int ret; - ff_draw_init(&s->dc, inlink->format, FF_DRAW_PROCESS_ALPHA); + ff_draw_init(&s->dc, inlink->format, inlink->colorspace, inlink->color_range, FF_DRAW_PROCESS_ALPHA); ff_draw_color(&s->dc, &s->fontcolor, s->fontcolor.rgba); ff_draw_color(&s->dc, &s->shadowcolor, s->shadowcolor.rgba); ff_draw_color(&s->dc, &s->bordercolor, s->bordercolor.rgba); diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index e52f7284d4..240b6b929d 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -111,7 +111,7 @@ static int config_input(AVFilterLink *inlink) double var_values[VARS_NB], res; char *expr; - ff_draw_init(&s->draw, inlink->format, 0); + ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); ff_draw_color(&s->draw, &s->color, s->rgba_color); var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; diff --git a/libavfilter/vf_rotate.c b/libavfilter/vf_rotate.c index 96c250a459..3adde22c09 100644 --- a/libavfilter/vf_rotate.c +++ b/libavfilter/vf_rotate.c @@ -288,7 +288,7 @@ static int config_props(AVFilterLink *outlink) double res; char *expr; - ff_draw_init(&rot->draw, inlink->format, 0); + ff_draw_init2(&rot->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); ff_draw_color(&rot->draw, &rot->color, rot->fillcolor); rot->hsub = pixdesc->log2_chroma_w; diff --git a/libavfilter/vf_shear.c b/libavfilter/vf_shear.c index 760caa5011..5d43809ccd 100644 --- a/libavfilter/vf_shear.c +++ b/libavfilter/vf_shear.c @@ -260,7 +260,7 @@ static int config_output(AVFilterLink *outlink) s->planeheight[1] = s->planeheight[2] = AV_CEIL_RSHIFT(ctx->inputs[0]->h, desc->log2_chroma_h); s->planeheight[0] = s->planeheight[3] = ctx->inputs[0]->h; - ff_draw_init(&s->draw, outlink->format, 0); + ff_draw_init2(&s->draw, outlink->format, outlink->colorspace, outlink->color_range, 0); ff_draw_color(&s->draw, &s->color, s->fillcolor); s->filter_slice[0] = s->depth <= 8 ? filter_slice_nn8 : filter_slice_nn16; diff --git a/libavfilter/vf_stack.c b/libavfilter/vf_stack.c index 331dc7b3e3..2bb3d9b1d2 100644 --- a/libavfilter/vf_stack.c +++ b/libavfilter/vf_stack.c @@ -304,7 +304,8 @@ static int config_output(AVFilterLink *outlink) int inw, inh, size; if (s->fillcolor_enable) { - ff_draw_init(&s->draw, ctx->inputs[0]->format, 0); + const AVFilterLink *inlink = ctx->inputs[0]; + ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); ff_draw_color(&s->draw, &s->color, s->fillcolor); } diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c index ef5f9cd866..366c0bf39e 100644 --- a/libavfilter/vf_subtitles.c +++ b/libavfilter/vf_subtitles.c @@ -148,7 +148,8 @@ static int config_input(AVFilterLink *inlink) { AssContext *ass = inlink->dst->priv; - ff_draw_init(&ass->draw, inlink->format, ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0); + ff_draw_init2(&ass->draw, inlink->format, inlink->colorspace, inlink->color_range, + ass->alpha ? FF_DRAW_PROCESS_ALPHA : 0); ass_set_frame_size (ass->renderer, inlink->w, inlink->h); if (ass->original_w && ass->original_h) { diff --git a/libavfilter/vf_tile.c b/libavfilter/vf_tile.c index ca2397fb18..b45e739bb6 100644 --- a/libavfilter/vf_tile.c +++ b/libavfilter/vf_tile.c @@ -139,7 +139,7 @@ static int config_props(AVFilterLink *outlink) outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; outlink->frame_rate = av_mul_q(inlink->frame_rate, av_make_q(1, tile->nb_frames - tile->overlap)); - ff_draw_init(&tile->draw, inlink->format, 0); + ff_draw_init2(&tile->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); ff_draw_color(&tile->draw, &tile->blank, tile->rgba_color); return 0; diff --git a/libavfilter/vf_tinterlace.c b/libavfilter/vf_tinterlace.c index e221a6f941..8ff0aa8b4b 100644 --- a/libavfilter/vf_tinterlace.c +++ b/libavfilter/vf_tinterlace.c @@ -225,7 +225,7 @@ static int config_out_props(AVFilterLink *outlink) if (tinterlace->mode == MODE_PAD) { uint8_t black[4] = { 0, 0, 0, 16 }; - ff_draw_init(&tinterlace->draw, outlink->format, 0); + ff_draw_init2(&tinterlace->draw, outlink->format, outlink->colorspace, outlink->color_range, 0); ff_draw_color(&tinterlace->draw, &tinterlace->color, black); /* limited range */ if (!ff_fmt_is_in(outlink->format, full_scale_yuvj_pix_fmts)) { diff --git a/libavfilter/vf_tpad.c b/libavfilter/vf_tpad.c index 1efe4ec479..9ef5956eac 100644 --- a/libavfilter/vf_tpad.c +++ b/libavfilter/vf_tpad.c @@ -203,7 +203,7 @@ static int config_input(AVFilterLink *inlink) TPadContext *s = ctx->priv; if (needs_drawing(s)) { - ff_draw_init(&s->draw, inlink->format, 0); + ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, inlink->color_range, 0); ff_draw_color(&s->draw, &s->color, s->rgba_color); } diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c index 3b5536badc..73a61bfa45 100644 --- a/libavfilter/vsrc_testsrc.c +++ b/libavfilter/vsrc_testsrc.c @@ -263,7 +263,8 @@ static int color_config_props(AVFilterLink *inlink) TestSourceContext *test = ctx->priv; int ret; - ff_draw_init(&test->draw, inlink->format, 0); + ff_draw_init2(&test->draw, inlink->format, inlink->colorspace, + inlink->color_range, 0); ff_draw_color(&test->draw, &test->color, test->color_rgba); test->w = ff_draw_round_to_sub(&test->draw, 0, -1, test->w); @@ -944,7 +945,8 @@ static int test2_config_props(AVFilterLink *inlink) AVFilterContext *ctx = inlink->src; TestSourceContext *s = ctx->priv; - av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0); + av_assert0(ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, + inlink->color_range, 0) >= 0); s->w = ff_draw_round_to_sub(&s->draw, 0, -1, s->w); s->h = ff_draw_round_to_sub(&s->draw, 1, -1, s->h); if (av_image_check_size(s->w, s->h, 0, ctx) < 0) @@ -1964,7 +1966,8 @@ static int colorchart_config_props(AVFilterLink *inlink) AVFilterContext *ctx = inlink->src; TestSourceContext *s = ctx->priv; - av_assert0(ff_draw_init(&s->draw, inlink->format, 0) >= 0); + av_assert0(ff_draw_init2(&s->draw, inlink->format, inlink->colorspace, + inlink->color_range, 0) >= 0); if (av_image_check_size(s->w, s->h, 0, ctx) < 0) return AVERROR(EINVAL); return config_props(inlink); diff --git a/tests/ref/fate/filter-pixfmts-pad b/tests/ref/fate/filter-pixfmts-pad index b4d236d408..73ae9d0f96 100644 --- a/tests/ref/fate/filter-pixfmts-pad +++ b/tests/ref/fate/filter-pixfmts-pad @@ -17,12 +17,12 @@ gbrp12le 91fdad0d1edf7bfa2805e2041e8da3cd gbrp14le deb2c3af6b48faa52f6a1f6590a0cdf7 gbrp16le a6156d1a37e05ee621b2a343fb158bd6 gbrp9le 9e827f438e081d334a6cae7e282698b0 -gray ddc663a0491df3959d9c5795dceaa72e -gray10le e6559c1c8c05ce89f44b465573db44e7 -gray12le b066dd276b1698ee77d0c7eb95ff78c5 -gray14le 6d6b293b5d50944c5aa422245987c78e -gray16le 2734ce1793a2216c5be30816689cd2fe -gray9le f8f3dfe31ca5fcba828285bceefdab9a +gray 2b9652a8b136316fada371d03ee252bc +gray10le 0efebad19b92c6d6d915971c17ab55c4 +gray12le f03613250550d9dc253d46778f6d4bd6 +gray14le dbac6524c3793469c64fc0ee98d017fd +gray16le 7b6db54ec8b4d9a8344443a3b3f50377 +gray9le 2d2bc7bd35c48fa61860162cf18a4dcf nv12 381574979cb04be10c9168540310afad nv16 d3a50501d2ea8535489fd5ec49e7866d nv21 0fdeb2cdd56cf5a7147dc273456fa217 @@ -43,8 +43,8 @@ rgb48le ed08db9b1aa50d69b8c3d73db93e390e rgba b157c90191463d34fb3ce77b36c96386 vuya 44368c0a758ee68e24ce976e3b1b8535 vuyx bc7c4f693a22cd1ac95e33d473086474 -ya16le 8dbfcb586abf626da7d1aca887a581b9 -ya8 495daaca2dcb4f7aeba7652768b41ced +ya16le dfc900a8130a7c5e64201557cbaef50a +ya8 5d25e9a7975805d3f0dac516a6132b6e yuv410p cb871dcc1e84a7ef1d21f9237b88cf6e yuv411p aec2c1740de9a62db0d41f4dda9121b0 yuv420p 4398e408fc35436ce4b20468946f58b6 From patchwork Wed Jan 31 11:17:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 45926 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:8786:b0:199:de12:6fa6 with SMTP id ph6csp2756780pzb; Wed, 31 Jan 2024 03:17:39 -0800 (PST) X-Google-Smtp-Source: AGHT+IGp0Z3LWDDrl/xZ/NlvZdrcQT0qQ9jL5EyZDbZ7IGxOZTahjo+YaKkMwyOHsScdwzBmrV1R X-Received: by 2002:a17:906:d154:b0:a31:7eec:36a5 with SMTP id br20-20020a170906d15400b00a317eec36a5mr911956ejb.49.1706699859099; Wed, 31 Jan 2024 03:17:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1706699859; cv=none; d=google.com; s=arc-20160816; b=09RU59IPKePznM7k+Nm7iZimyd2n/mVSjRfDZoXKECl7/n4VmXirgty391vQ23CYcl 7VGxehxptosrKSxcYjphKWrMiIXUsxHRWelXHeFy5ez6dPioXiS1ejFv82U+B0xFcagD st8sWPY9+mE53hFfNGqHStc4XBZE2DVhpq/Bp+C2ZEPcvUPGKdsNsu7LwxRDNf1mmDWd Q6/mAdXZNz7qtl2curgX87oJq/BXzuJqE3IUl+/5GPBcMeF5n1G6OLMFoGSyw7GYUuc3 tgggn6w66VX4Raq7mRwe/S4NJqYUYV7r8WwnXv8Q6SWl1Sei1EPoTXTD4wxSLNurBesD 7NSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:delivered-to; bh=vvSVlyvD8I70y7MWcXTp5x2SFvxcqQ1p1LBg0nAcNsk=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=IZLw8zHnGV1hkKXbH+tarDvzY+DNbKesV6JAizCfvcJL1GvSUaPmwgw1De7Oc/h1a3 gYbmA9crS5WW0mdTchmU2am2rFUH4KFVqKqrnylYRouEQLymtOwSisPNVmVjP3fpezCH 36htks/rMnf2v5w3lQSPYGs+kelJMuhM2vVP1QiyuNhctzgeVQOK0enf+qu55iTMsqOK sZdgnL2/e5jiFpTu0+yVoMZEMqFF9OXplU4hiIoavQOad1GDWrELRN8tS4q4Le+k+CT7 rU5UxMiCH+gKUMnDsWJlS9Jjppd/Ovpm9pBuuK5z7mVo1y4SjGsSwESyKKwTcAENNGEE ah/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=vkb6XyA7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f5-20020a17090631c500b00a35e59b27e4si2436609ejf.487.2024.01.31.03.17.18; Wed, 31 Jan 2024 03:17:39 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=vkb6XyA7; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ACFA768D139; Wed, 31 Jan 2024 13:17:14 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 61BA268AB9C for ; Wed, 31 Jan 2024 13:17:08 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id D7FDB43F85; Wed, 31 Jan 2024 12:17:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1706699827; bh=tQ2sVUzLV41WIBwbQGV0wdHQr31G8hOd6cl3l1AQs1k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vkb6XyA7qNfzEJxHqaVhR26f9dSyIyhyGjlcYk0ZMG4iT3tMxtBdVX3miKE2bZhf8 +z/Sh8zz96ApqQuDyhJMA2HHzOyZGD8+ZAEC5xJiudNg6uyhD6WOUAzBLRM0AFHdno XnX+BR+9q5Kswdz8wUNX1PoIlPUrMG//zGEBw5Ik= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Wed, 31 Jan 2024 12:17:04 +0100 Message-ID: <20240131111704.44140-2-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240131111704.44140-1-ffmpeg@haasn.xyz> References: <20240131111704.44140-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] avfilter/vsrc_testsrc: switch to YUV colorspace negotiation API X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: iOabs9rL3bSU From: Niklas Haas Instead of overriding the frame properties in fill_picture(), advertise the supported YUV colorspace and range at format negotiation time. (The correct metadata will now be set automatically by ff_get_video_buffer) --- libavfilter/vsrc_testsrc.c | 47 +++++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/libavfilter/vsrc_testsrc.c b/libavfilter/vsrc_testsrc.c index 73a61bfa45..c51ba46c97 100644 --- a/libavfilter/vsrc_testsrc.c +++ b/libavfilter/vsrc_testsrc.c @@ -1418,6 +1418,24 @@ static const enum AVPixelFormat smptebars_pix_fmts[] = { AV_PIX_FMT_NONE, }; +static int smptebars_query_formats(AVFilterContext *ctx) +{ + enum AVColorSpace csp; + int ret; + + if (!strcmp(ctx->name, "smptehdbars")) { + csp = AVCOL_SPC_BT709; + } else { + csp = AVCOL_SPC_BT470BG; + } + + if ((ret = ff_set_common_color_spaces(ctx, ff_make_formats_list_singleton(csp)))) + return ret; + if ((ret = ff_set_common_color_ranges(ctx, ff_make_formats_list_singleton(AVCOL_RANGE_MPEG)))) + return ret; + return ff_set_common_formats_from_list(ctx, smptebars_pix_fmts); +} + AVFILTER_DEFINE_CLASS_EXT(palbars, "pal(75|100)bars", options); #if CONFIG_PAL75BARS_FILTER @@ -1428,9 +1446,6 @@ static void pal75bars_fill_picture(AVFilterContext *ctx, AVFrame *picref) int r_w, i, x = 0; const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format); - picref->color_range = AVCOL_RANGE_MPEG; - picref->colorspace = AVCOL_SPC_BT470BG; - r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w); draw_bar(test, white, x, 0, r_w, test->h, picref); @@ -1461,7 +1476,7 @@ const AVFilter ff_vsrc_pal75bars = { .activate = activate, .inputs = NULL, FILTER_OUTPUTS(outputs), - FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts), + FILTER_QUERY_FUNC(smptebars_query_formats), }; #endif /* CONFIG_PAL75BARS_FILTER */ @@ -1474,9 +1489,6 @@ static void pal100bars_fill_picture(AVFilterContext *ctx, AVFrame *picref) int r_w, i, x = 0; const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format); - picref->color_range = AVCOL_RANGE_MPEG; - picref->colorspace = AVCOL_SPC_BT470BG; - r_w = FFALIGN((test->w + 7) / 8, 1 << pixdesc->log2_chroma_w); for (i = 0; i < 7; i++) { @@ -1505,7 +1517,7 @@ const AVFilter ff_vsrc_pal100bars = { .activate = activate, .inputs = NULL, FILTER_OUTPUTS(outputs), - FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts), + FILTER_QUERY_FUNC(smptebars_query_formats), }; #endif /* CONFIG_PAL100BARS_FILTER */ @@ -1520,8 +1532,6 @@ static void smptebars_fill_picture(AVFilterContext *ctx, AVFrame *picref) int r_w, r_h, w_h, p_w, p_h, i, tmp, x = 0; const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format); - picref->colorspace = AVCOL_SPC_BT470BG; - r_w = FFALIGN((test->w + 6) / 7, 1 << pixdesc->log2_chroma_w); r_h = FFALIGN(test->h * 2 / 3, 1 << pixdesc->log2_chroma_h); w_h = FFALIGN(test->h * 3 / 4 - r_h, 1 << pixdesc->log2_chroma_h); @@ -1572,7 +1582,7 @@ const AVFilter ff_vsrc_smptebars = { .activate = activate, .inputs = NULL, FILTER_OUTPUTS(outputs), - FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts), + FILTER_QUERY_FUNC(smptebars_query_formats), }; #endif /* CONFIG_SMPTEBARS_FILTER */ @@ -1585,8 +1595,6 @@ static void smptehdbars_fill_picture(AVFilterContext *ctx, AVFrame *picref) int d_w, r_w, r_h, l_w, i, tmp, x = 0, y = 0; const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(picref->format); - picref->colorspace = AVCOL_SPC_BT709; - d_w = FFALIGN(test->w / 8, 1 << pixdesc->log2_chroma_w); r_h = FFALIGN(test->h * 7 / 12, 1 << pixdesc->log2_chroma_h); draw_bar(test, gray40, x, 0, d_w, r_h, picref); @@ -1675,7 +1683,7 @@ const AVFilter ff_vsrc_smptehdbars = { .activate = activate, .inputs = NULL, FILTER_OUTPUTS(outputs), - FILTER_PIXFMTS_ARRAY(smptebars_pix_fmts), + FILTER_QUERY_FUNC(smptebars_query_formats), }; #endif /* CONFIG_SMPTEHDBARS_FILTER */ @@ -2138,7 +2146,6 @@ ZONEPLATE_SLICE(16, uint16_t) static void zoneplate_fill_picture(AVFilterContext *ctx, AVFrame *frame) { TestSourceContext *test = ctx->priv; - frame->color_range = AVCOL_RANGE_JPEG; ff_filter_execute(ctx, test->fill_slice_fn, frame, NULL, FFMIN(frame->height, ff_filter_get_nb_threads(ctx))); } @@ -2194,6 +2201,14 @@ static const enum AVPixelFormat zoneplate_pix_fmts[] = { AV_PIX_FMT_NONE, }; +static int zoneplate_query_formats(AVFilterContext *ctx) +{ + int ret; + if ((ret = ff_set_common_color_ranges(ctx, ff_make_formats_list_singleton(AVCOL_RANGE_JPEG)))) + return ret; + return ff_set_common_formats_from_list(ctx, zoneplate_pix_fmts); +} + static const AVFilterPad avfilter_vsrc_zoneplate_outputs[] = { { .name = "default", @@ -2212,7 +2227,7 @@ const AVFilter ff_vsrc_zoneplate = { .activate = activate, .inputs = NULL, FILTER_OUTPUTS(avfilter_vsrc_zoneplate_outputs), - FILTER_PIXFMTS_ARRAY(zoneplate_pix_fmts), + FILTER_QUERY_FUNC(zoneplate_query_formats), .flags = AVFILTER_FLAG_SLICE_THREADS, .process_command = ff_filter_process_command, };