Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Schmelcher <tschmelcher@google.com>2022-09-26 20:14:09 +0300
committerMichael Niedermayer <michael@niedermayer.cc>2022-09-27 01:07:43 +0300
commit179830108dbeb1c6b73105ae2234cf04874728b4 (patch)
tree6a2e97cb5667d9a322d1bfd1f61082244a786811 /libavfilter/scale_eval.c
parent543a46b4b2ff0f02fa85e45d7b7bcda19d3be9b4 (diff)
avfilter/scale_eval: Reduce rounding error.
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 <tfoucu@google.com> Signed-off-by: Tristan Schmelcher <tschmelcher@google.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavfilter/scale_eval.c')
-rw-r--r--libavfilter/scale_eval.c11
1 files changed, 7 insertions, 4 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;
}