From patchwork Thu Jul 4 14:31:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 50334 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:cc64:0:b0:482:c625:d099 with SMTP id k4csp3754960vqv; Thu, 4 Jul 2024 07:32:14 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUzdRmdosimUxkOpv7eH0KdpHWBESQoZsLWAz4qyVtwxR7PyBMbagQSYyB/wBBL0hBEgn5duR4mCdai2WKJVhwCGMsNJeTAjW/myw== X-Google-Smtp-Source: AGHT+IGPaTcs6UQyxaVC5bDEU7nCAQbwX1TJM7sZlhXzkDYlBthk35KIGyYGVVAW78RFu/PBNrJD X-Received: by 2002:a05:6402:84b:b0:57c:a7fe:d275 with SMTP id 4fb4d7f45d1cf-58e5b5a6320mr1492183a12.32.1720103533821; Thu, 04 Jul 2024 07:32:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720103533; cv=none; d=google.com; s=arc-20160816; b=womEaR3wMVWu8tcD+qDNWBFBBZ61PDzFOLHGiywEskQnR6bbL9hBY5YsPz0rZK/I4A /DFwzv4ogpWdW174z8w9+wYO239qrOfEponBisS88gYwFh1pfQiJPP/IJJGim87C3Gx9 bXt9fr4/zc3pVZippRQy/sVRf3G8A7aR2dEayLJmqr5bh2SIfrnS3seozRF4lN+BVX0r um8Ibgq9wSIF36b+Mr8z4V5RQFgkNUsygtDca2JLYBZpzSexzE4oaBVsNNaDIE3c4Sj0 pY7Y0U6zgPZ9XMVudNHIXRTU0bJJGwjwosTJ9bH7oqyLHFpEn6DrzWalK19DPcfsrgk8 Nxhw== 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=fgYpKfPdBGSzs+6g+mdPSbav3TGvLY90oy36qeZXlGc=; fh=xmAeKtysnShNOmkhiJmYkS30uw4Fu2hvBJ7qlIwukxQ=; b=npPjK7tbudvHsKU9uU92mJnAFVo+HTn7AMpjwAZd1frcVkm4ZS2I9avQcHO+hm/bLz GL7Magz5UdtbkgL8s/TVa8loxmU3johRssWyKLG8nKzYUAhB8zbXtLRmMBP9H9Wzp+1c q3zBIB13S3nagmsvOpt7HzKxLQ5563O0217Russ75l0M0a1VWEB//s6QwRuzTtHRwkzZ wUHPflxy1TXQpYR8addMhZajX8jOC7IERUtF8CtAqsDDlCTXxm6ImmJ5l67coC903uhf doYOrG75a23O/NQsxVeQ0COQ8aKVPfPKRs/3hlJ4NSLNDvJT6cPZacdB64Ub/IVcZEKj M1nA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=El9KHwA1; 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 4fb4d7f45d1cf-58c44d1a72esi2385210a12.79.2024.07.04.07.32.13; Thu, 04 Jul 2024 07:32:13 -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=El9KHwA1; 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 C4A0868DA26; Thu, 4 Jul 2024 17:31:24 +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 609DA68D9FC for ; Thu, 4 Jul 2024 17:31:12 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1720103468; bh=2khgc9946s96WOy2dLPxdNHKKZN53lzbELU1p0FVRiU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=El9KHwA1of6JoIzshou/g0VP++UthnujzGRyxDQM8b67PWp9gGfmfRd0Yj3oEY0Tj 0Eyz1HmA7K66Z5t7nKT7yhcEHhdopKZVpB9VAGF0auf9l9QEVyiPAI+8KXBssX+dgo 3YZt+Vh4127SbYc5flIl+d+1Dv32YGfnR9VSsgpA= Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id F26B041F18; Thu, 4 Jul 2024 16:31:07 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Thu, 4 Jul 2024 16:31:02 +0200 Message-ID: <20240704143104.1821386-6-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240704143104.1821386-1-ffmpeg@haasn.xyz> References: <20240704143104.1821386-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2 6/8] avfilter/vf_scale: fix 4:1:0 interlaced chroma pos 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: qlSOcI7icpKo From: Niklas Haas The current logic hard-coded a check for v_sub == 1. We can extend this logic slightly to cover the case of interlaced 4:1:0 (which has v_sub == 2). Here is a diagram explaining this scenario (with center-siting): a a a a a a a a b b b b b b b b X X a a a a a a a a b b b b b b b b a a a a a a a a b b b b b b b b Y Y a a a a a a a a b b b b b b b b a = even luma rows b = odd luma rows X = even chroma sample Y = odd chroma sample In progressive mode, the chroma samples sit at (384, 384) respectively. Relative to the 8x4 grid of even luma samples (a), the X sample sits at: h_chr_pos = 384 v_chr_pos = 192 Relative to the 8x4 grid of odd luma samples (b), the Y sample sits at: h_chr_pos = 384 v_chr_pos = 576 The new code calculates the correct values in all circumstances. --- libavfilter/vf_scale.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_scale.c b/libavfilter/vf_scale.c index b2c9d0b187..2d82141b70 100644 --- a/libavfilter/vf_scale.c +++ b/libavfilter/vf_scale.c @@ -642,9 +642,19 @@ static void calc_chroma_pos(int *h_pos_out, int *v_pos_out, int chroma_loc, v_pos = v_pos_override; /* Fix vertical chroma position for interlaced frames */ - if (v_sub == 1 && index > 0) { - v_pos += 256 * (index == 2); /* offset by one luma row for odd rows */ - v_pos >>= 1; /* double luma row distance */ + if (v_sub && index > 0) { + /* When vertically subsampling, chroma samples are effectively only + * placed next to even rows. To access them from the odd field, we need + * to account for this shift by offsetting the distance of one luma row. + * + * For 4x vertical subsampling (v_sub == 2), they are only placed + * next to every *other* even row, so we need to shift by three luma + * rows to get to the chroma sample. */ + if (index == 2) + v_pos += (256 << v_sub) - 256; + + /* Luma row distance is doubled for fields, so halve offsets */ + v_pos >>= 1; } /* Explicitly strip chroma offsets when not subsampling, because it