From patchwork Fri Oct 13 14:22:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 44238 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:4b15:b0:15d:8365:d4b8 with SMTP id fp21csp1036254pzb; Fri, 13 Oct 2023 07:22:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWhfoDwtjtPWwOUK4TzJsoqUkgXtcYzOmJcaK25ylkPFiNmSbusZJZ4lmH1BDfzjgJRj+s X-Received: by 2002:a17:907:3da5:b0:9ae:614f:b159 with SMTP id he37-20020a1709073da500b009ae614fb159mr226974ejc.36.1697206938429; Fri, 13 Oct 2023 07:22:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697206938; cv=none; d=google.com; s=arc-20160816; b=XRKAC5KNsMdakiraxCYChUHJzOil0hfPCFTNzUK6QYDrD6Yx6+FHQHcClV9WodHoRM jcwUL0HHPU94I/H0jvR6lezAS9f7r/J3hNcJAHbU1OD/8zFS0AT9tFMHnvzCs6mBxcEq ZzV40ZdJFgZVi0uzF9A/vK/XS2SywPeWa7OMx1nu/6EeQCnf+as8j87WdwP99t34P4sK r4t8EU1Bs3jFNL6PxuWyhMRe9sgnXoOSZQWRHVCV3eDrW4KTMFiluCygV/99EnwcjbH7 b2p2JNHmDAlCfyI/TJlvAEsfdBMwfmLpTJnLC3yEk7CaKUSBmfnTlWoeeirtBRf/y+7j Cp7Q== 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=iyE/YsltWlj7l+9yTsnMkbHP9BBcv9MBXk2t7HltFG8=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=wYShkPVKu/uk799cZrT9+0AdRqrZ3i+j6aPiuPj0++MTJ6RFtHj40s/f4ehBXtlISX vi3KGdWnjsJ2Ni7JpUOPLfbQ9ElAEHNpKYf3dZH/D6JhX6p++7/u90Lc+7CVzeSjA5v2 01Tn7fe/FJX03PyNjTmBxjnJFw8Sc7lM5auPPdL+R9ySMCog3DCcQVWcWu5JjN5/L81F yWQzOvS5XRntKfnd8D4BUJFbgTCvieerW/dn3B4bR7UtK1wO0em6mkLs/dzug8OEjmEa QnXljYnSpUnLOxluka9JZKhm/rwIZmuZXfxC0K+EiwH3m8Tf+1OCZCKz/HUXgxOgdfm8 t56w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=Zjk9BHZF; 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 k24-20020a17090646d800b009aa1b8dafa1si8837346ejs.191.2023.10.13.07.22.17; Fri, 13 Oct 2023 07:22:18 -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=Zjk9BHZF; 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 DB86C68C93C; Fri, 13 Oct 2023 17:22:14 +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 6B76F68C733 for ; Fri, 13 Oct 2023 17:22:08 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 2C67A41EC3; Fri, 13 Oct 2023 16:22:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1697206928; bh=D7IxcvCCNlBapsf9uGanoZfVoc0O+diPnJA93a8dxuo=; h=From:To:Cc:Subject:Date:From; b=Zjk9BHZFKCyj1PBEZ+rIu/OEPGJX1rm4SKUZzU+eXyghrGx9f+TUnAQV4Wl3lGYqc dyalUWAQ3P6FP+HDtVKgvvI0fOjOBeZ6/p1BGmixW3+IhE1WV0eTthSY++8lY3l7Jj GBl8Ak+VWww73ZBsNUR8+wSr8bOrvYS/lV6ur0fc= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Fri, 13 Oct 2023 16:22:05 +0200 Message-ID: <20231013142205.60658-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_scale: fix interlaced chroma for other formats 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: 6emS8t5TsKCX From: Niklas Haas This logic only covers the case of yuv420p. Extend this logic to cover *all* vertically subsampled YUV formats, which require the same interlaced scaling logic. Fortunately, we can get away with re-using the same code for both JPEG and MPEG range YUV, because the only difference here is the horizontal alignment. (To be fixed in a separate commit) --- libavfilter/vf_scale.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index b0221e8538..23335cef4b 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -518,6 +518,7 @@ static int config_props(AVFilterLink *outlink) outlink->src->inputs[0]; enum AVPixelFormat outfmt = outlink->format; const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); + const AVPixFmtDescriptor *outdesc = av_pix_fmt_desc_get(outfmt); ScaleContext *scale = ctx->priv; uint8_t *flags_val = NULL; int ret; @@ -588,14 +589,15 @@ static int config_props(AVFilterLink *outlink) av_opt_set_int(s, "dst_range", scale->out_range == AVCOL_RANGE_JPEG, 0); - /* Override YUV420P default settings to have the correct (MPEG-2) chroma positions - * MPEG-2 chroma positions are used by convention - * XXX: support other 4:2:0 pixel formats */ - if (inlink0->format == AV_PIX_FMT_YUV420P && scale->in_v_chr_pos == -513) { + /* Override chroma location default settings to have the correct + * chroma positions. MPEG chroma positions are used by convention. + * Note that this works for both MPEG-1/JPEG and MPEG-2/4 chroma + * locations, since they share a vertical alignment */ + if (desc->log2_chroma_h == 1 && scale->in_v_chr_pos == -513) { in_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192; } - if (outlink->format == AV_PIX_FMT_YUV420P && scale->out_v_chr_pos == -513) { + if (outdesc->log2_chroma_h == 1 && scale->out_v_chr_pos == -513) { out_v_chr_pos = (i == 0) ? 128 : (i == 1) ? 64 : 192; }