From patchwork Fri Oct 13 14:24:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44242 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4b15:b0:15d:8365:d4b8 with SMTP id fp21csp1039450pzb; Fri, 13 Oct 2023 07:27:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFN6y3cy2hC39KvBGkkt4g23OTMlmc+siYvjWdPyGeEMny1iM51G3NdaA1b3hyP7jP6+t8S X-Received: by 2002:a17:906:76d4:b0:9b7:37de:600d with SMTP id q20-20020a17090676d400b009b737de600dmr23781411ejn.62.1697207277572; Fri, 13 Oct 2023 07:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697207277; cv=none; d=google.com; s=arc-20160816; b=T0Ieqr4a6M+Qb3zNbYGTq7JXnJpOFeubPDnMKQWhYEl4roR+l5VwSrslkn7rrmo6zX g9161apOAZfeQLuQFCTR3MdkTY9xt6sWnohxlMlqvGEGYs4aHfFQ/Rg2AWoyrROU1kSc dvYuHVP4luZd1G/ASAH+V1zOKGYh/i2OLU63BF6KgVAzbMjvyeT+q9VWs6iADIhfuKxb VMS8jrruNgjCr0xGd7nPHbu3tjbtsmQnMUoq9qfq5u+E8oV9jm4Q9KIUmGQNfkO6afDt HE3VtNPhiw4jvQAVbIjvMPqSIjb1XebkJUJjKxJ9nojUyBOvjwkbyBTNXVV8Rpzr8aW7 js7A== 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=nRC3erC/FvaGPEOimJNMjJhEdlXHNPEoglSxykp2Iqo=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=HJTph2QU7TUZPL2+B71xxozHfwqRbbPnbRXAC3rhKq1xAV+JyRDk+rAsSzD/h+c/jy 1Yepn5cV4oBUXA2fqrrEWSStvDGiok4sfDk6Atv9uWCvxafkE0YNRmnJW453WcmApVyJ CRG2L3q+XD+3UPTPzv6GeXn/VumR+Ij7VfS3my+xF1KOk89/23CKKbDUEViG+7csDcHC vN/RpPqWHbu6u0UTLxWYx/50U+PooJtDdV1IJ+eN4z0zqGU7QzcA95T+sM7D4QATGN41 rDhmzqW2FlB3CtWax2Eaejwmvedi3Qi7dUSWExAj7wPbmQMmW/RDchyhac3P2Cmp3L24 9v3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b="t8bBiu/3"; 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 v20-20020a1709063bd400b009b9b3370c09si8630362ejf.542.2023.10.13.07.27.55; Fri, 13 Oct 2023 07:27:57 -0700 (PDT) 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="t8bBiu/3"; 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 68F7468C9E2; Fri, 13 Oct 2023 17:27:21 +0300 (EEST) 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 764BE68C901 for ; Fri, 13 Oct 2023 17:27:11 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 371684BBF9; Fri, 13 Oct 2023 16:27:11 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1697207231; bh=HQfQLDRMaXyPnzCCv4g1KCIZup0ZfXI1Y3bMGPPR6TA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t8bBiu/3A+zxBKqcZtVeWNSHjYbaJDrvl/rE20yyu8epCkdwNqcgZqCISnPJCkOk3 H7cJWsaQhfY5zAUPCYX8U/O2F1IAEytjbft2mB7n2GdQuk6obQgJTAZ8932W857kWB fWHt6ec217qCVXI7YCjKjYupmLyfngrIvrnjSeMw= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 13 Oct 2023 16:24:42 +0200 Message-ID: <20231013142706.23971-5-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231013142706.23971-1-ffmpeg@haasn.xyz> References: <20231013142706.23971-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 04/13] lavfi/vf_colorspace: support prim/trc/csp passthrough 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: dfWIF9DL0sI5 From: Niklas Haas Setting the output range/primaries/colorspace to unspecified now infers the value from the input signal. If the input signal also has unknown prim/trc, and no specific output is requested, enable passthrough mode. As a technical implementation detail, define a static const sentinel struct to represent "unknown" values. This is to avoid reconfiguring the filter on every frame (which is guarded by s->out_primaries etc. being NULL), as well as make the memcmp NOOP check succeed. --- libavfilter/vf_colorspace.c | 71 ++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/libavfilter/vf_colorspace.c b/libavfilter/vf_colorspace.c index 2a30434401..5ab5266ef0 100644 --- a/libavfilter/vf_colorspace.c +++ b/libavfilter/vf_colorspace.c @@ -442,29 +442,23 @@ static int create_filtergraph(AVFilterContext *ctx, if (s->user_iprm != AVCOL_PRI_UNSPECIFIED) s->in_prm = s->user_iprm; s->in_primaries = av_csp_primaries_desc_from_id(s->in_prm); - if (!s->in_primaries) { + s->out_prm = out->color_primaries; + s->out_primaries = av_csp_primaries_desc_from_id(s->out_prm); + if (s->out_prm == AVCOL_PRI_UNSPECIFIED || s->fast_mode) { + static const AVColorPrimariesDesc unknown = {0}; + s->in_primaries = s->out_primaries = &unknown; /* force passthrough */ + } else if (!s->in_primaries) { av_log(ctx, AV_LOG_ERROR, "Unsupported input primaries %d (%s)\n", s->in_prm, av_color_primaries_name(s->in_prm)); return AVERROR(EINVAL); - } - s->out_prm = out->color_primaries; - s->out_primaries = av_csp_primaries_desc_from_id(s->out_prm); - if (!s->out_primaries) { - if (s->out_prm == AVCOL_PRI_UNSPECIFIED) { - if (s->user_all == CS_UNSPECIFIED) { - av_log(ctx, AV_LOG_ERROR, "Please specify output primaries\n"); - } else { - av_log(ctx, AV_LOG_ERROR, - "Unsupported output color property %d\n", s->user_all); - } - } else { - av_log(ctx, AV_LOG_ERROR, - "Unsupported output primaries %d (%s)\n", - s->out_prm, av_color_primaries_name(s->out_prm)); - } + } else if (!s->out_primaries) { + av_log(ctx, AV_LOG_ERROR, + "Unsupported output primaries %d (%s)\n", + s->out_prm, av_color_primaries_name(s->out_prm)); return AVERROR(EINVAL); } + s->lrgb2lrgb_passthrough = !memcmp(s->in_primaries, s->out_primaries, sizeof(*s->in_primaries)); if (!s->lrgb2lrgb_passthrough) { @@ -505,38 +499,33 @@ static int create_filtergraph(AVFilterContext *ctx, if (s->user_itrc != AVCOL_TRC_UNSPECIFIED) s->in_trc = s->user_itrc; s->in_txchr = get_transfer_characteristics(s->in_trc); - if (!s->in_txchr) { - av_log(ctx, AV_LOG_ERROR, - "Unsupported input transfer characteristics %d (%s)\n", - s->in_trc, av_color_transfer_name(s->in_trc)); - return AVERROR(EINVAL); - } } if (!s->out_txchr) { av_freep(&s->lin_lut); s->out_trc = out->color_trc; s->out_txchr = get_transfer_characteristics(s->out_trc); - if (!s->out_txchr) { - if (s->out_trc == AVCOL_TRC_UNSPECIFIED) { - if (s->user_all == CS_UNSPECIFIED) { - av_log(ctx, AV_LOG_ERROR, - "Please specify output transfer characteristics\n"); - } else { - av_log(ctx, AV_LOG_ERROR, - "Unsupported output color property %d\n", s->user_all); - } - } else { - av_log(ctx, AV_LOG_ERROR, - "Unsupported output transfer characteristics %d (%s)\n", - s->out_trc, av_color_transfer_name(s->out_trc)); - } - return AVERROR(EINVAL); - } } - s->rgb2rgb_passthrough = s->fast_mode || (s->lrgb2lrgb_passthrough && - !memcmp(s->in_txchr, s->out_txchr, sizeof(*s->in_txchr))); + if ((s->out_trc == AVCOL_TRC_UNSPECIFIED && s->lrgb2lrgb_passthrough) || s->fast_mode) { + static const struct TransferCharacteristics unknown = {0}; + s->in_txchr = s->out_txchr = &unknown; /* force passthrough */ + } else if (!s->in_txchr) { + av_log(ctx, AV_LOG_ERROR, + "Unsupported input transfer characteristics %d (%s)\n", + s->in_trc, av_color_transfer_name(s->in_trc)); + return AVERROR(EINVAL); + } else if (s->out_trc == AVCOL_TRC_UNSPECIFIED) { + s->out_txchr = s->in_txchr; + } else if (!s->out_txchr) { + av_log(ctx, AV_LOG_ERROR, + "Unsupported output transfer characteristics %d (%s)\n", + s->out_trc, av_color_transfer_name(s->out_trc)); + return AVERROR(EINVAL); + } + + s->rgb2rgb_passthrough = s->lrgb2lrgb_passthrough && + !memcmp(s->in_txchr, s->out_txchr, sizeof(*s->in_txchr)); if (!s->rgb2rgb_passthrough && !s->lin_lut) { res = fill_gamma_table(s); if (res < 0)