From: Marton Balint <cus@passwd.hu> To: ffmpeg-devel@ffmpeg.org Cc: Marton Balint <cus@passwd.hu> Subject: [FFmpeg-devel] [PATCH 2/3] avfilter/vf_zscale: simplify and fix slice_params calculations Date: Fri, 8 Jul 2022 00:29:30 +0200 Message-ID: <20220707222931.16118-2-cus@passwd.hu> (raw) In-Reply-To: <20220707222931.16118-1-cus@passwd.hu> 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 --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; -- 2.35.3 _______________________________________________ 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".
next prev parent reply other threads:[~2022-07-07 22:30 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-07 22:29 [FFmpeg-devel] [PATCH 1/3] avfilter/vf_zscale: remove some unneeded initializations Marton Balint 2022-07-07 22:29 ` Marton Balint [this message] 2022-07-07 22:29 ` [FFmpeg-devel] [PATCH 3/3] avfilter/vf_zscake: enable AVX512 zscale functions Marton Balint 2022-07-10 20:46 ` [FFmpeg-devel] [PATCH 1/3] avfilter/vf_zscale: remove some unneeded initializations Marton Balint 2022-07-10 21:51 ` Paul B Mahol
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220707222931.16118-2-cus@passwd.hu \ --to=cus@passwd.hu \ --cc=ffmpeg-devel@ffmpeg.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel This inbox may be cloned and mirrored by anyone: git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \ ffmpegdev@gitmailbox.com public-inbox-index ffmpegdev Example config snippet for mirrors. AGPL code for this site: git clone https://public-inbox.org/public-inbox.git