From bca59d7745e4fa4ed5444da959d6b487cd14e994 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Fri, 24 May 2013 17:34:36 +0200 Subject: [PATCH] fade: fix slice sizes This more evenly distributes the load between threads This also fixes the chroma filtering where the filter was applied twice Signed-off-by: Michael Niedermayer --- libavfilter/vf_fade.c | 13 ++++----- tests/ref/fate/filter-fade | 56 +++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 35 deletions(-) diff --git a/libavfilter/vf_fade.c b/libavfilter/vf_fade.c index 60a690b9e9..5bdec1132e 100644 --- a/libavfilter/vf_fade.c +++ b/libavfilter/vf_fade.c @@ -163,9 +163,8 @@ static int filter_slice_luma(AVFilterContext *ctx, void *arg, int jobnr, { FadeContext *s = ctx->priv; AVFrame *frame = arg; - int slice_h = frame->height / nb_jobs; - int slice_start = jobnr * slice_h; - int slice_end = (jobnr == nb_jobs - 1) ? frame->height : (jobnr + 1) * slice_h; + int slice_start = (frame->height * jobnr ) / nb_jobs; + int slice_end = (frame->height * (jobnr+1)) / nb_jobs; int i, j; for (i = slice_start; i < slice_end; i++) { @@ -187,15 +186,15 @@ static int filter_slice_chroma(AVFilterContext *ctx, void *arg, int jobnr, { FadeContext *s = ctx->priv; AVFrame *frame = arg; - int slice_h = FFALIGN(frame->height / nb_jobs, 1 << s->vsub); - int slice_start = jobnr * slice_h; - int slice_end = (jobnr == nb_jobs - 1) ? frame->height : (jobnr + 1) * slice_h; int i, j, plane; const int width = FF_CEIL_RSHIFT(frame->width, s->hsub); + const int height= FF_CEIL_RSHIFT(frame->height, s->vsub); + int slice_start = (height * jobnr ) / nb_jobs; + int slice_end = (height * (jobnr+1)) / nb_jobs; for (plane = 1; plane < 3; plane++) { for (i = slice_start; i < slice_end; i++) { - uint8_t *p = frame->data[plane] + (i >> s->vsub) * frame->linesize[plane]; + uint8_t *p = frame->data[plane] + i * frame->linesize[plane]; for (j = 0; j < width; j++) { /* 8421367 = ((128 << 1) + 1) << 15. It is an integer * representation of 128.5. The .5 is for rounding diff --git a/tests/ref/fate/filter-fade b/tests/ref/fate/filter-fade index 446db77a52..9d691ce90d 100644 --- a/tests/ref/fate/filter-fade +++ b/tests/ref/fate/filter-fade @@ -5,20 +5,20 @@ 0, 3, 3, 1, 152064, 0xb4e6c735 0, 4, 4, 1, 152064, 0xb4e6c735 0, 5, 5, 1, 152064, 0xb4e6c735 -0, 6, 6, 1, 152064, 0x54bae320 -0, 7, 7, 1, 152064, 0x53b60b7e -0, 8, 8, 1, 152064, 0x8bed0304 -0, 9, 9, 1, 152064, 0x509c4b78 -0, 10, 10, 1, 152064, 0x4cf869a4 -0, 11, 11, 1, 152064, 0x958b7c66 -0, 12, 12, 1, 152064, 0x45841fbf -0, 13, 13, 1, 152064, 0xcfee57ea -0, 14, 14, 1, 152064, 0x979ff709 -0, 15, 15, 1, 152064, 0xf7ffd5e2 -0, 16, 16, 1, 152064, 0xc42f4370 -0, 17, 17, 1, 152064, 0x71ae098f -0, 18, 18, 1, 152064, 0x64146a42 -0, 19, 19, 1, 152064, 0xdb3068fd +0, 6, 6, 1, 152064, 0x1f3b0657 +0, 7, 7, 1, 152064, 0x6e7547e6 +0, 8, 8, 1, 152064, 0x1197524c +0, 9, 9, 1, 152064, 0xb4cdb293 +0, 10, 10, 1, 152064, 0xdd7cf1b8 +0, 11, 11, 1, 152064, 0x360b1005 +0, 12, 12, 1, 152064, 0x11a49918 +0, 13, 13, 1, 152064, 0xa10dd4f9 +0, 14, 14, 1, 152064, 0x78da71d7 +0, 15, 15, 1, 152064, 0x105e4cc0 +0, 16, 16, 1, 152064, 0x54bfa1c5 +0, 17, 17, 1, 152064, 0xd666559e +0, 18, 18, 1, 152064, 0xd93faa1c +0, 19, 19, 1, 152064, 0xb1af85ed 0, 20, 20, 1, 152064, 0xfc7bf570 0, 21, 21, 1, 152064, 0x9dc72412 0, 22, 22, 1, 152064, 0x445d1d59 @@ -30,20 +30,20 @@ 0, 28, 28, 1, 152064, 0x76d2a455 0, 29, 29, 1, 152064, 0x6dc3650e 0, 30, 30, 1, 152064, 0x0f9d6aca -0, 31, 31, 1, 152064, 0x11446a9b -0, 32, 32, 1, 152064, 0x00be684c -0, 33, 33, 1, 152064, 0xe5f9ee52 -0, 34, 34, 1, 152064, 0x21ecafb8 -0, 35, 35, 1, 152064, 0xd42c962c -0, 36, 36, 1, 152064, 0xe00a270d -0, 37, 37, 1, 152064, 0xc1b53878 -0, 38, 38, 1, 152064, 0xfc4e28dd -0, 39, 39, 1, 152064, 0x9c574e39 -0, 40, 40, 1, 152064, 0xdd25cf9d -0, 41, 41, 1, 152064, 0x32959e70 -0, 42, 42, 1, 152064, 0xac6498d5 -0, 43, 43, 1, 152064, 0xcd595d21 -0, 44, 44, 1, 152064, 0x2953ff74 +0, 31, 31, 1, 152064, 0xddae8141 +0, 32, 32, 1, 152064, 0x67cb8f24 +0, 33, 33, 1, 152064, 0xc7a72348 +0, 34, 34, 1, 152064, 0x0d7a1144 +0, 35, 35, 1, 152064, 0x39adfb3d +0, 36, 36, 1, 152064, 0x0ecc70d5 +0, 37, 37, 1, 152064, 0xf3a6805e +0, 38, 38, 1, 152064, 0xc3bd71ad +0, 39, 39, 1, 152064, 0xa9be9730 +0, 40, 40, 1, 152064, 0xab9af790 +0, 41, 41, 1, 152064, 0x4c3ccd25 +0, 42, 42, 1, 152064, 0xbc83c58a +0, 43, 43, 1, 152064, 0x94877df4 +0, 44, 44, 1, 152064, 0xa2360ea6 0, 45, 45, 1, 152064, 0xb4e6c735 0, 46, 46, 1, 152064, 0xb4e6c735 0, 47, 47, 1, 152064, 0xb4e6c735