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
Unified · Split
| @@ -227,22 +227,12 @@ static int query_formats(AVFilterContext *ctx) · 226 unmodified lines | |||
| 227 | 227 | ||
| 228 | static void slice_params(ZScaleContext *s, int out_h, int in_h) | 228 | static void slice_params(ZScaleContext *s, int out_h, int in_h) |
| 229 | { | 229 | { |
| 230 | int slice_size; | ||
| 231 | |||
| 232 | slice_size = (out_h + (s->nb_threads / 2)) / s->nb_threads; | ||
| 233 | if (slice_size % 2) | ||
| 234 | slice_size += 1; | ||
| 235 | s->out_slice_start[0] = 0; | 230 | s->out_slice_start[0] = 0; |
| 236 | s->out_slice_end[0] = FFMIN(out_h, slice_size); | 231 | for (int i = 1; i < s->nb_threads; i++) { |
| 237 | for (int i = 1; i < s->nb_threads - 1; i++) { | 232 | int slice_end = out_h * i / s->nb_threads; |
| 238 | s->out_slice_start[i] = s->out_slice_end[i-1]; | 233 | s->out_slice_end[i - 1] = s->out_slice_start[i] = FFALIGN(slice_end, 2); |
| 239 | s->out_slice_end[i] = s->out_slice_start[i] + slice_size; | ||
| 240 | } | ||
| 241 | |||
| 242 | if (s->nb_threads > 1) { | ||
| 243 | s->out_slice_start[s->nb_threads - 1] = s->out_slice_end[s->nb_threads - 2]; | ||
| 244 | s->out_slice_end[s->nb_threads - 1] = out_h; | ||
| 245 | } | 234 | } |
| 235 | s->out_slice_end[s->nb_threads - 1] = out_h; | ||
| 246 | 236 | ||
| 247 | for (int i = 0; i < s->nb_threads; i++) { | 237 | for (int i = 0; i < s->nb_threads; i++) { |
| 248 | s->in_slice_start[i] = s->out_slice_start[i] * in_h / (double)out_h; | 238 | s->in_slice_start[i] = s->out_slice_start[i] * in_h / (double)out_h; |