History

avfilter/vf_zscale: simplify and fix slice_params calculations

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

Marton Balint committed 4 years ago

Commit a6f0e641 parent 68fdc9d1 file · +4 −14Browse files

Unified · Split

libavfilter/vf_zscale.c+4−14
@@ -227,22 +227,12 @@ static int query_formats(AVFilterContext *ctx) · 226 unmodified lines
227227
228228 static void slice_params(ZScaleContext *s, int out_h, int in_h)
229229 {
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;
235230 s->out_slice_start[0] = 0;
236− s->out_slice_end[0] = FFMIN(out_h, slice_size);
237− for (int i = 1; i < s->nb_threads - 1; i++) {
238− s->out_slice_start[i] = s->out_slice_end[i-1];
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;
231+ for (int i = 1; i < s->nb_threads; i++) {
232+ int slice_end = out_h * i / s->nb_threads;
233+ s->out_slice_end[i - 1] = s->out_slice_start[i] = FFALIGN(slice_end, 2);
245234 }
235+ s->out_slice_end[s->nb_threads - 1] = out_h;
246236
247237 for (int i = 0; i < s->nb_threads; i++) {
248238 s->in_slice_start[i] = s->out_slice_start[i] * in_h / (double)out_h;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t