From patchwork Sat Mar 23 15:30:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 47375 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c889:b0:1a3:b6bb:3029 with SMTP id hb9csp275044pzb; Sat, 23 Mar 2024 08:30:45 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUqRz0Jjw4XCXXHrT716+nh2xVahMYyqqn1ANdy8S8ctgsCgPdlcbCR9tp7kGE/77xe4tks3NFGpbPKeNt3fk+JiRCe4Eunv0Is1w== X-Google-Smtp-Source: AGHT+IHCZHZQq3z+/sNCUz0tQwuc8C/f/BvgoJdq4QVma/9THhsdj7I8O7DSMsQBJgDg1B+m0jKb X-Received: by 2002:a19:5f5a:0:b0:513:af26:8cd0 with SMTP id a26-20020a195f5a000000b00513af268cd0mr1551386lfj.68.1711207845331; Sat, 23 Mar 2024 08:30:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1711207845; cv=none; d=google.com; s=arc-20160816; b=LKm7TySRoirielcVteQI71I1WaVKxsi/pD/kLnxAsJgedvb8kStJD80HQNp2q1rM/9 EBKX+uP+qZjWuStGmkU1P5QlShucqlIezRZK6xNtUezOxgimMXK7Ei8a+36H2Op9LW/p RfG3/7D7jCiA2eWrNdd9AyMf3qB1mTcmgaJ/zAIg91TbU4u7xpgFYg8eMZhSCsyeIVcc 4ambjaBRO8Hwi5Q3s3aOdAGiVEQVJAvkstV17RU/CHBjUfGIP3LguvYCk+Ng7bMLOEFg r3lgyNUgtALHZYOh+1zGN3kIIUzzJC2WaNRFKwntsPmiKr8ImpQ7YX9Ja3JuRlt7vFXf D/rA== 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=4Qo2ORb1p4iN5Cm6/BZJQ/gjtYXSkivogiEmnonGdB4=; fh=LnlYe9qYwgML7nWWXqAumr7YCmPjjpEPjQf6GasgJC0=; b=t803NGBzUqgD2iWE88PQcTO6IoVrlbxnsUI69+976RLk3PwXRgYFF57IBojEyaa1pZ mkRrAfGqoevzNniePFWch/ibu/XFSqzFOJ5ECx+M9qnmXboHlOZ9SMp4gWFacqGa/48V UoCYXykKRDlpNmVwt3gZBHvcXq1LU2CWoiDgdWFBcAVWz5ovrsx68qUkpKbc4KqhJFKz 57x7HbGMkJrpIPrmPm1w+a/uuS/RAUhSkE+N5E25sjloYsZPGUmj2WnlnrdYVSWBmpSC 4oJ2a9hTzNNTpv8QY03X6+GeHcxzA3SELwsGf3vdjKzgRgqZP1KrcgDnkQL7gH3eFPBU PY2g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=L+Hf2Rcl; 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=NONE dis=NONE) header.from=rothenpieler.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id hk23-20020a170906c9d700b00a469608d95fsi903542ejb.504.2024.03.23.08.30.44; Sat, 23 Mar 2024 08:30:45 -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=@rothenpieler.org header.s=mail header.b=L+Hf2Rcl; 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=NONE dis=NONE) header.from=rothenpieler.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2EDBF68D3DC; Sat, 23 Mar 2024 17:30:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [144.76.60.213]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8094D68D39B for ; Sat, 23 Mar 2024 17:30:35 +0200 (EET) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id 7EC4928A8E33A; Sat, 23 Mar 2024 16:30:34 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1711207834; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zDdNcmFMWXIXMrOtE7CmEzkFGb8yM59KJKVsU+/AlBw=; b=L+Hf2RclSsWI876thbpQAK1oJuizHWUt9cTG1aS5z737Oon2QYFbHSZt/nFyZ2dIP0LG4A y1Pmf5BAzmNoEnbvL8GUxxltLdW98hAUpC8PJXfJu8HYnBMgrBF2oax+CQx3zxwznVYG1k aaVV2vB8y9x9Ofj5r040RgUttt2WLzTqItKsteMuoCBFDb6Kz0u9I4vSx2OFcj++rzqwRu wULDeEOrI8/n91kcgMbQKXtVw7Dgl9eLO8ybpBsB1FSlAoq1I7ny/e5XfhXr2N/vUM6QUz cmxC0iDPw7Pnk8uE3+Y71osfPsOZVZOwGArNS3l4LmZ9vxFrKofeMyBm/7hzZg== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Sat, 23 Mar 2024 16:30:26 +0100 Message-Id: <20240323153026.1848-1-timo@rothenpieler.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/vf_stack: round down internal item heights 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: Timo Rothenpieler Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: 0SmddbNqgJJ3 Following situation: Someone wants to stack two yuv420p frames of the size 3x3 pixel each. Now the various AV_CEIL_RSHIFT() calculations calculate a height of 2 pixel for each items subsampled planes. However, for example in case of a vstack, the output frames will have a height of 6, so the subsampled planes one of 3. When the filter now tries to stack two items with a rounded-up height of 2 into a frame with a height of 3, it'll write an entire extra line past the end of a buffer. This patch instead rounds down all the item heights, to avoid this situation. It's not ideal either, since now lines might be missed. But that is definitely preferable over writing past the end of the bufferThis patch instead rounds down all the item heights, to avoid this situation. It's not ideal either, since now lines might be missed. But that is definitely preferable over writing past the end of the buffer. --- libavfilter/vf_stack.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/libavfilter/vf_stack.c b/libavfilter/vf_stack.c index 2bb3d9b1d2..46e7d6b7f5 100644 --- a/libavfilter/vf_stack.c +++ b/libavfilter/vf_stack.c @@ -220,11 +220,11 @@ static int config_output(AVFilterLink *outlink) return ret; } - item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); + item->height[1] = item->height[2] = inlink->h / (1 << s->desc->log2_chroma_h); item->height[0] = item->height[3] = inlink->h; if (i) { - item->y[1] = item->y[2] = AV_CEIL_RSHIFT(height, s->desc->log2_chroma_h); + item->y[1] = item->y[2] = height / (1 << s->desc->log2_chroma_h); item->y[0] = item->y[3] = height; height += ctx->inputs[i]->h; @@ -244,7 +244,7 @@ static int config_output(AVFilterLink *outlink) return ret; } - item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); + item->height[1] = item->height[2] = inlink->h / (1 << s->desc->log2_chroma_h); item->height[0] = item->height[3] = inlink->h; if (i) { @@ -278,14 +278,14 @@ static int config_output(AVFilterLink *outlink) return ret; } - item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); + item->height[1] = item->height[2] = inlink->h / (1 << s->desc->log2_chroma_h); item->height[0] = item->height[3] = inlink->h; if ((ret = av_image_fill_linesizes(item->x, inlink->format, inw)) < 0) { return ret; } - item->y[1] = item->y[2] = AV_CEIL_RSHIFT(inh, s->desc->log2_chroma_h); + item->y[1] = item->y[2] = inh / (1 << s->desc->log2_chroma_h); item->y[0] = item->y[3] = inh; inw += ctx->inputs[k]->w; } @@ -322,7 +322,7 @@ static int config_output(AVFilterLink *outlink) return ret; } - item->height[1] = item->height[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h); + item->height[1] = item->height[2] = inlink->h / (1 << s->desc->log2_chroma_h); item->height[0] = item->height[3] = inlink->h; p2 = arg; @@ -370,7 +370,7 @@ static int config_output(AVFilterLink *outlink) return ret; } - item->y[1] = item->y[2] = AV_CEIL_RSHIFT(inh, s->desc->log2_chroma_h); + item->y[1] = item->y[2] = inh / (1 << s->desc->log2_chroma_h); item->y[0] = item->y[3] = inh; width = FFMAX(width, inlink->w + inw);