From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id C43B2448CC for ; Mon, 26 Sep 2022 17:14:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A929768BBC1; Mon, 26 Sep 2022 20:14:31 +0300 (EEST) Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F3DBD68B64C for ; Mon, 26 Sep 2022 20:14:25 +0300 (EEST) Received: by mail-pl1-f201.google.com with SMTP id k2-20020a170902c40200b001782bd6c416so4827993plk.20 for ; Mon, 26 Sep 2022 10:14:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=g+2dxxhuW5MtfSqpaROnk3q+D4v23zzi9SiTxFIpXE4=; b=Ut6egGcQFLz3y1NTdSFdanJW8jW6KXGon8lz6X86/3fDrhnv1ZP0NM/7aoT+za1vPm ZL9kmhkb/0TBQke/Iw8jSH3A6yeNrlk7BMi6UtEjKwbUa0uOfszdb5RD3tjd12xEe9Ma 0o9irPTIeTPgucAZuHmItCLg2ck2uykTsYUf4QDg7CBSIJeHwuWvWP9mTEnvVE+KZY2c mouBdp55zEo0pGQsZWYlFua0eWJxU1wP4Pq1vk8BTabIatqT3A0eycmVdO5F7b4epJbM DmryRLv3PwO3dnPKtHCWaBch3oSsXATgSdBCBvN1Pi2w5Kp0C7+RAI9dDQNLUzmy3M6p r9Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=g+2dxxhuW5MtfSqpaROnk3q+D4v23zzi9SiTxFIpXE4=; b=dkTnZkm/d1gKg7gBQ8lCvJpVeFat/oUVIHr4SJ7PSNsjfuiHiUOOspMtLns2VywqWb bhKfRekwubqWAlE2eyo+U4oVgYeZ9tzicLApIKFs0IeUl/iKesUiuUEY+v75R8WwHVDW y4Rw5lT+sVlvEBRwzj3z8vO+1nLXS0zlb7Ii6ohR0TxHWIQOOwJMoCGeR0dAcnWqsmIl KZKp9Ek+fmqDJ6Er5JTZ57hOkSBD39rdiD+wT/KXLVv1L3q20F97P3nxVFrr1olA4SJB ok9oRhpbJo9SKlZ2ARCJCC8l0/tD2c4ev0PAyGx5Nb/mmHXIHuFustI8c5SO9iljZpGc kiwA== X-Gm-Message-State: ACrzQf3tBInpT39yK4QkJcE/m1ehFlySZJ3n61wPcMq/0r0QdYUeeWBo qoZRdOqb3zeRg82XlT6M+jzvw/ZTuoBbNlKCEVdsmrAV1qlXY8WEehTgapZIJaLuonTgSL8ABW1 OeyAySgyJHNknmNvggOyRpPGZecZq05tHSbwNeVYFNPEux6/UXKIKwtJCUL2rdyhT+d9rxeZwGl o= X-Google-Smtp-Source: AMsMyM4UrKDtYyszCPnmXhABzUvsyt3pMnr0WXpj0YrHSqB96XukNf61elY3C1+I6zskwerwirXHhUKYElzlvpbGrA== X-Received: from tschmelcher-cloudtop2.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:436c]) (user=tschmelcher job=sendgmr) by 2002:a17:903:186:b0:178:2ca7:fae5 with SMTP id z6-20020a170903018600b001782ca7fae5mr22870626plg.173.1664212463750; Mon, 26 Sep 2022 10:14:23 -0700 (PDT) Date: Mon, 26 Sep 2022 17:14:09 +0000 In-Reply-To: <20220919164237.312664-1-tschmelcher@google.com> Mime-Version: 1.0 References: <20220919164237.312664-1-tschmelcher@google.com> X-Mailer: git-send-email 2.37.3.998.g577e59143f-goog Message-ID: <20220926171409.2782171-1-tschmelcher@google.com> From: Tristan Schmelcher To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH] avfilter/scale_eval: Reduce rounding error. 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: Tristan Schmelcher , Thierry Foucu Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: When force_original_aspect_ratio and force_divisible_by are both used, dimensions are now rounded to the nearest allowed multiple of force_divisible_by rather than first rounding to the nearest integer and then rounding in a static direction. This results in less distortion of the aspect ratio. Reviewed-by: Thierry Foucu Signed-off-by: Tristan Schmelcher --- libavfilter/scale_eval.c | 11 +++++++---- libavfilter/scale_eval.h | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/libavfilter/scale_eval.c b/libavfilter/scale_eval.c index dfec081e15..75ed503f15 100644 --- a/libavfilter/scale_eval.c +++ b/libavfilter/scale_eval.c @@ -148,14 +148,17 @@ int ff_scale_adjust_dimensions(AVFilterLink *inlink, * dimensions so that it is not divisible by the set factors anymore * unless force_divisible_by is defined as well */ if (force_original_aspect_ratio) { - int tmp_w = av_rescale(h, inlink->w, inlink->h); - int tmp_h = av_rescale(w, inlink->h, inlink->w); + // Including force_divisible_by here rounds to the nearest multiple of it. + int tmp_w = av_rescale(h, inlink->w, inlink->h * (int64_t)force_divisible_by) + * force_divisible_by; + int tmp_h = av_rescale(w, inlink->h, inlink->w * (int64_t)force_divisible_by) + * force_divisible_by; if (force_original_aspect_ratio == 1) { w = FFMIN(tmp_w, w); h = FFMIN(tmp_h, h); if (force_divisible_by > 1) { - // round down + // round down in case provided w or h is not divisible. w = w / force_divisible_by * force_divisible_by; h = h / force_divisible_by * force_divisible_by; } @@ -163,7 +166,7 @@ int ff_scale_adjust_dimensions(AVFilterLink *inlink, w = FFMAX(tmp_w, w); h = FFMAX(tmp_h, h); if (force_divisible_by > 1) { - // round up + // round up in case provided w or h is not divisible. w = (w + force_divisible_by - 1) / force_divisible_by * force_divisible_by; h = (h + force_divisible_by - 1) / force_divisible_by * force_divisible_by; } diff --git a/libavfilter/scale_eval.h b/libavfilter/scale_eval.h index fceb023fec..2eb6970aad 100644 --- a/libavfilter/scale_eval.h +++ b/libavfilter/scale_eval.h @@ -38,7 +38,8 @@ int ff_scale_eval_dimensions(void *ctx, * Transform evaluated width and height obtained from ff_scale_eval_dimensions * into actual target width and height for scaling. Adjustment can occur if one * or both of the evaluated values are of the form '-n' or if - * force_original_aspect_ratio is set. + * force_original_aspect_ratio is set. force_divisible_by is used only when + * force_original_aspect_ratio is set and must be at least 1. * * Returns 0. */ -- 2.37.3.998.g577e59143f-goog _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".