diff mbox series

[FFmpeg-devel,2/3] avfilter/vf_zscale: simplify and fix slice_params calculations

Message ID 20220707222931.16118-2-cus@passwd.hu
State Accepted
Commit a6f0e641bcde6d8475c5d5473ac9b4de89618fc5
Headers show
Series [FFmpeg-devel,1/3] avfilter/vf_zscale: remove some unneeded initializations | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Marton Balint July 7, 2022, 10:29 p.m. UTC
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 <cus@passwd.hu>
---
 libavfilter/vf_zscale.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
diff mbox series

Patch

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;