From patchwork Wed Oct 27 22:20:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Jan_Ekstr=C3=B6m?= X-Patchwork-Id: 31238 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2084:0:0:0:0 with SMTP id a4csp487243ioa; Wed, 27 Oct 2021 15:21:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjMBc1LyMO8dcCOk+s0dxSxBT7QBS31jodnRqorKXwPQopmp0LcV8SyQeGHb5AdCwLkhoX X-Received: by 2002:a17:906:8a7b:: with SMTP id hy27mr421067ejc.308.1635373264729; Wed, 27 Oct 2021 15:21:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635373264; cv=none; d=google.com; s=arc-20160816; b=JkTO58Wl6+MDSXWMUeZwr4FLADqxnLvcB8WHPWdMfq7QNC1bUYi+1eFKiOXhChLHlt pizziDExFXc3MppcxbK9SDiGhnZEOAWDwktd4J2HheYWJ57FYeIrX+nYkHUnOA+bLADv yxQjRg7BsoPGMPQVyxDV+ESh8w7fk10CsI1YDPlT+Y1sozSe+HO7BOGRJltRNOsomf+8 W6WFrrWE/ZAGWnd3E0UZ62zt541Aeldvcq2RIRdrHBPXckWHG+VY2mqVPmDEuTIoEKsS DXDl8mbKrquOk0HEYYGJrC7iIWfimeyHPCRJOkPxSKWeel6yU/e3h/BtGqdANWlobCtT QoOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding: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=mPYh7Jss7Zfl5+lkiY2Q1sKe+m+Xh7kry26tvpM8Hx4=; b=XftrUhSwL6siIeTev0cf+2ikkU4WgQq4TjwULxqhujKsaDVznxGDg+JmqaGI13JdOw uiNwfTGinF+K5g2Y/ZaORPRajhJMeAVb3Shh1lyDr+PNf5dO+KLJvgTLxKR1prFVGJmx Uz2V7l4AD+KDa6VB3UbK5RoCo9n6l28hc6vLRfqjNE4h+qvz/WUdUMs0IbqSnbRBp6fj DkXuwm9k8b8OLCy/ONzNo6eAVeJ914MohxUlB1+Gfqv4s2nOdj8qbtnZMe5xbd9tIJE2 uxOrQ0PZMxbJ8Kq2nMOJAzdKPNZDkvJRS2OWd9FTBs2x/Jk50hIuUDgrdNuIwN5TZzHF lssg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=NiZgCIQ1; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hc7si1460938ejc.170.2021.10.27.15.20.41; Wed, 27 Oct 2021 15:21:04 -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=@gmail.com header.s=20210112 header.b=NiZgCIQ1; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2AE1D68AA5C; Thu, 28 Oct 2021 01:20:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 640EC68A1CC for ; Thu, 28 Oct 2021 01:20:31 +0300 (EEST) Received: by mail-lf1-f43.google.com with SMTP id b32so6086434lfv.0 for ; Wed, 27 Oct 2021 15:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=IFzVu+0BTQ2uWozgGpStkvKB0RIvlH0a94W1vZ8CMbI=; b=NiZgCIQ1zEeWQQ6wF16S4MCmPB7FhZHJQbVGXkW9nwMHVy3PNL2dbSsQ0BYTLlmqh2 qwr6g3Ux1dlzwSAhKDwGID+jxI8LJTdXTWtiGg6Y4sEz/JrfV55YvFeRPzj63GM1A9dB nHxKco3SGoKIqitqL23zPVfkkDuQ082R7kzRILW/ZgrcGmbMrRJsFuKSs+etMvsOWcmj NuB4iBE27k5EUqorV1A3RZtD7N9X/G5yCWdrCLQFX83vBnFHT/ZiTDhdC047OmitTDpH XDcCgNGvg9G1h5u1VEsd3fULxc13INLLgXvrR4XH7P0RVAc39t3hQhJomP4T3nf2Pv53 kAbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=IFzVu+0BTQ2uWozgGpStkvKB0RIvlH0a94W1vZ8CMbI=; b=Sa/gZSMQE4ENPVzNWeQRmE0LYXPIo2Tliq3NC+OVEEmIgrvr5xzcsOWoZZWVTu9CQI C6527CVMPX5oG0K2Vlu4d17aC7QFmn65vz56PpG4NppPH8IelPYgaJocwiIlye9C9iPA IhVrwlPvWMKkzlNhA1N/MIj+n+t3obz+/ltaH1LJfmMw5ELOOrx0qtxtPeahorVOSSkv +mKoph+YzwFiEYE7WOyKrIHAoyJmCAE1DbexNTAYdb4uglwBYKs+xo+wjaV6RuTURb7R 7Rc1mGvVUWSGOwon1z8wQps8NTvzbbksZbkfMcXPMqm81lsWVQKthyAthu/eaBl4cbTR Tppw== X-Gm-Message-State: AOAM532fqawo9xjm+5lihislaX/e10GbObsk7Hw2aAyl7wEEGFiWgE56 +B0MrJYuUno/pQ9eq+WI9w78V1cOS6Q= X-Received: by 2002:a05:6512:3401:: with SMTP id i1mr404865lfr.336.1635373229986; Wed, 27 Oct 2021 15:20:29 -0700 (PDT) Received: from localhost.localdomain (91-159-194-103.elisa-laajakaista.fi. [91.159.194.103]) by smtp.gmail.com with ESMTPSA id z6sm115692lfq.195.2021.10.27.15.20.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Oct 2021 15:20:29 -0700 (PDT) From: =?utf-8?q?Jan_Ekstr=C3=B6m?= To: ffmpeg-devel@ffmpeg.org Date: Thu, 28 Oct 2021 01:20:23 +0300 Message-Id: <20211027222024.53018-1-jeebjp@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/2] avfilter/vf_zscale: deduplicate output color information setting 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nBlOSHVlxltH This way a piece of logic is not missed in one location or the other, such as the case with chroma location outside the if. --- libavfilter/vf_zscale.c | 45 ++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c index 3f7dba489a..439c0c8548 100644 --- a/libavfilter/vf_zscale.c +++ b/libavfilter/vf_zscale.c @@ -554,6 +554,24 @@ fail: return ret; } +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; + + if (s->chromal != -1) + frame->chroma_location = (int)s->dst_format.chroma_location - 1; +} + static int filter_frame(AVFilterLink *link, AVFrame *in) { ZScaleContext *s = link->dst->priv; @@ -621,20 +639,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) format_init(&s->dst_format, out, odesc, s->colorspace, s->primaries, s->trc, s->range, s->chromal); - if (s->colorspace != -1) - out->colorspace = (int)s->dst_format.matrix_coefficients; - - if (s->primaries != -1) - out->color_primaries = (int)s->dst_format.color_primaries; - - if (s->range != -1) - out->color_range = convert_range_from_zimg(s->dst_format.pixel_range); - - if (s->trc != -1) - out->color_trc = (int)s->dst_format.transfer_characteristics; - - if (s->chromal != -1) - out->chroma_location = (int)s->dst_format.chroma_location - 1; + update_output_color_information(s, out); ret = graph_build(&s->graph, &s->params, &s->src_format, &s->dst_format, &s->tmp, &s->tmp_size); @@ -680,17 +685,7 @@ static int filter_frame(AVFilterLink *link, AVFrame *in) } } - if (s->colorspace != -1) - out->colorspace = (int)s->dst_format.matrix_coefficients; - - if (s->primaries != -1) - out->color_primaries = (int)s->dst_format.color_primaries; - - if (s->range != -1) - out->color_range = convert_range_from_zimg(s->dst_format.pixel_range); - - if (s->trc != -1) - out->color_trc = (int)s->dst_format.transfer_characteristics; + update_output_color_information(s, out); av_reduce(&out->sample_aspect_ratio.num, &out->sample_aspect_ratio.den, (int64_t)in->sample_aspect_ratio.num * outlink->h * link->w,