From patchwork Thu Jul 7 22:29:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 36703 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp5187697pzh; Thu, 7 Jul 2022 15:30:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sa8VY3JZ7UpwiY3kPlzs3u/2Yv4me6mMOYLMLBf8UjfUHI1ocqAlvhU4gJIuAnF1PjPLID X-Received: by 2002:a05:6402:520b:b0:435:c2a4:f822 with SMTP id s11-20020a056402520b00b00435c2a4f822mr542571edd.198.1657233027419; Thu, 07 Jul 2022 15:30:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657233027; cv=none; d=google.com; s=arc-20160816; b=ANEIPyVke2SPunhoWdjPu7Goq74WISZNANAs5debDKD/P+3T2As9ZOVdLIyUe2qnCo LhDny/mClQdNksPngIYML2BIlUFwQaAxeaHwaiqM35mwJK3Zjcva381JiaZl864Ubgc6 xpB9rO5JJA2/8UIq3jEyn4pWdHwgYAKBUnr9qkS8XTLtERKu2PREEqkyZgcV+TseLr7m qEcPM4UAc0LCIpo03mEeaIgf4jZMBEUlZOhGVbVhBc/1Z+QKXYqcgUxmvYRDBOMlGeZb W5uXbxKF9eReWzMZb6WoB4pHsqpY+iq6Lk72YfIV+IhhYgzC+a0on8kFKWklqra72fVA RJZg== 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:delivered-to; bh=d1fQ82ao/8uax4K3n0hTv966q6xnRUxFei+K51IlVok=; b=d3TH55BtSqLxPV6/se6t7SZr9bIVOtLDVDUPgf6TiJfUtqnhpeBL64HcUhSyhuBSsj hAWM2YNo516mk0rOGbNu5EQVfyaDwO5SK13YHM3FUP089zi2cfO5a2lMBo0PuRyZNCPf KuuGNvmd/LaAy1ySTQpsNsJlSwWvJ44Dyk4BOc7SgKIIAulllv+BxUG9uUdT+ncEW+Rg auhK13hQ/wgXaPJQ3yEc1Vkutm9Bd/jnCycpDjmwL+wxOx4D+kvAdgNCXzWr4vMkoDot 6ynLVtnqTwpqhsXLw7+ZO6Ibl+SMQkW61MQub7trtkTBgzaiIuTPyb2+7+J2c1lvUxKS C+0A== ARC-Authentication-Results: i=1; mx.google.com; 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 ht8-20020a170907608800b007262a166933si2461167ejc.165.2022.07.07.15.30.27; Thu, 07 Jul 2022 15:30:27 -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; 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 C571268B8EB; Fri, 8 Jul 2022 01:30:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F20C068B83C for ; Fri, 8 Jul 2022 01:30:10 +0300 (EEST) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id E4D4DE7620; Fri, 8 Jul 2022 00:30:10 +0200 (CEST) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tJoJL7mw1lnR; Fri, 8 Jul 2022 00:29:42 +0200 (CEST) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 7C044E7622; Fri, 8 Jul 2022 00:29:42 +0200 (CEST) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Fri, 8 Jul 2022 00:29:30 +0200 Message-Id: <20220707222931.16118-2-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220707222931.16118-1-cus@passwd.hu> References: <20220707222931.16118-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/3] avfilter/vf_zscale: simplify and fix slice_params calculations 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: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: QGXk6VykE5gp Do not insist on a fixed slice height, because that can still cause overflows in corner cases as described in this comment: https://github.com/sekrit-twc/zimg/issues/177#issuecomment-1157734233 Signed-off-by: Marton Balint --- libavfilter/vf_zscale.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/libavfilter/vf_zscale.c b/libavfilter/vf_zscale.c index 6861eef278..8e50457c6b 100644 --- a/libavfilter/vf_zscale.c +++ b/libavfilter/vf_zscale.c @@ -227,22 +227,12 @@ static int query_formats(AVFilterContext *ctx) static void slice_params(ZScaleContext *s, int out_h, int in_h) { - int slice_size; - - slice_size = (out_h + (s->nb_threads / 2)) / s->nb_threads; - if (slice_size % 2) - slice_size += 1; s->out_slice_start[0] = 0; - s->out_slice_end[0] = FFMIN(out_h, slice_size); - for (int i = 1; i < s->nb_threads - 1; i++) { - s->out_slice_start[i] = s->out_slice_end[i-1]; - s->out_slice_end[i] = s->out_slice_start[i] + slice_size; - } - - if (s->nb_threads > 1) { - s->out_slice_start[s->nb_threads - 1] = s->out_slice_end[s->nb_threads - 2]; - s->out_slice_end[s->nb_threads - 1] = out_h; + for (int i = 1; i < s->nb_threads; i++) { + int slice_end = out_h * i / s->nb_threads; + s->out_slice_end[i - 1] = s->out_slice_start[i] = FFALIGN(slice_end, 2); } + s->out_slice_end[s->nb_threads - 1] = out_h; for (int i = 0; i < s->nb_threads; i++) { s->in_slice_start[i] = s->out_slice_start[i] * in_h / (double)out_h;