From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 01EDA48092 for ; Thu, 9 Nov 2023 12:29:26 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9B99168CCD1; Thu, 9 Nov 2023 14:26:08 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id EF70968CBDF for ; Thu, 9 Nov 2023 14:25:41 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 57AA54BCEC; Thu, 9 Nov 2023 13:25:38 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1699532738; bh=ETro5w/gURgeWH4dcH7hBF3xkXy8DsXxYRbz84sVBw8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VPfVGOgW7S+ezycVJkw7RyrPFSA3i7OB0aZ8gLlglGzj8nmhUp+BqgDBRIDCZuR6p zS5Zxs4hXvqfOcr2kTPxFGlOXlWwrkSlvgm5IeTRLdFckDj5CL56nHaEY/I9fQNv/T WwSGMDoIFVAjSOQ1tIFmyyRxrBVtfZslCJRHhGO8= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Nov 2023 13:19:42 +0100 Message-ID: <20231109122534.124157-11-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231109122534.124157-1-ffmpeg@haasn.xyz> References: <20231109122534.124157-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 10/25] avfilter/vf_zscale: switch to 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Niklas Haas Following the same design as vf_scale. --- libavfilter/vf_zscale.c | 44 +++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c index f76c9954cd..3b14ce4f33 100644 --- a/libavfilter/vf_zscale.c +++ b/libavfilter/vf_zscale.c @@ -187,8 +187,12 @@ static av_cold int init(AVFilterContext *ctx) return 0; } +static enum AVColorRange convert_range_from_zimg(enum zimg_pixel_range_e color_range); + static int query_formats(AVFilterContext *ctx) { + ZScaleContext *s = ctx->priv; + AVFilterFormats *formats; static const enum AVPixelFormat pixel_fmts[] = { AV_PIX_FMT_YUV410P, AV_PIX_FMT_YUV411P, AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV422P, @@ -217,7 +221,27 @@ static int query_formats(AVFilterContext *ctx) ret = ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->inputs[0]->outcfg.formats); if (ret < 0) return ret; - return ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->outputs[0]->incfg.formats); + ret = ff_formats_ref(ff_make_format_list(pixel_fmts), &ctx->outputs[0]->incfg.formats); + if (ret < 0) + return ret; + + if ((ret = ff_formats_ref(ff_all_color_spaces(), &ctx->inputs[0]->outcfg.formats)) < 0 || + (ret = ff_formats_ref(ff_all_color_ranges(), &ctx->inputs[0]->outcfg.formats)) < 0) + return ret; + + formats = s->colorspace != ZIMG_MATRIX_UNSPECIFIED && s->colorspace > 0 + ? ff_make_formats_list_singleton(s->colorspace) + : ff_all_color_spaces(); + if ((ret = ff_formats_ref(formats, &ctx->outputs[0]->incfg.formats)) < 0) + return ret; + + formats = s->range != -1 + ? ff_make_formats_list_singleton(convert_range_from_zimg(s->range)) + : ff_all_color_ranges(); + if ((ret = ff_formats_ref(formats, &ctx->outputs[0]->incfg.formats)) < 0) + return ret; + + return 0; } static void slice_params(ZScaleContext *s, int out_h, int in_h) @@ -678,15 +702,9 @@ fail: static void update_output_color_information(ZScaleContext *s, AVFrame *frame) { - if (s->colorspace != -1) - frame->colorspace = (int)s->dst_format.matrix_coefficients; - if (s->primaries != -1) frame->color_primaries = (int)s->dst_format.color_primaries; - if (s->range != -1) - frame->color_range = convert_range_from_zimg(s->dst_format.pixel_range); - if (s->trc != -1) frame->color_trc = (int)s->dst_format.transfer_characteristics; @@ -775,6 +793,8 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) if ((link->format != outlink->format) || (link->w != outlink->w) || (link->h != outlink->h) || + (link->colorspace != outlink->colorspace) || + (link->color_range != outlink->color_range) || s->first_time || (s->src_format.chroma_location != s->dst_format.chroma_location) || (s->src_format.color_family !=s->dst_format.color_family) || @@ -796,6 +816,8 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) goto fail; av_frame_copy_props(out, in); + out->colorspace = outlink->colorspace; + out->color_range = outlink->color_range; if ((ret = realign_frame(desc, &in, 1)) < 0) goto fail; @@ -805,9 +827,11 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) snprintf(buf, sizeof(buf)-1, "%d", outlink->h); av_opt_set(s, "h", buf, 0); - link->dst->inputs[0]->format = in->format; - link->dst->inputs[0]->w = in->width; - link->dst->inputs[0]->h = in->height; + link->dst->inputs[0]->format = in->format; + link->dst->inputs[0]->w = in->width; + link->dst->inputs[0]->h = in->height; + link->dst->inputs[0]->colorspace = in->colorspace; + link->dst->inputs[0]->color_range = in->color_range; s->nb_threads = av_clip(FFMIN(ff_filter_get_nb_threads(ctx), FFMIN(link->h, outlink->h) / MIN_TILESIZE), 1, MAX_THREADS); slice_params(s, out->height, in->height); -- 2.42.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".