Re: [FFmpeg-devel] [PATCH] vf_blend: Use integers for divide mode
2016-02-23 0:22 GMT+01:00 Ganesh Ajjanagadde: > On Fri, Feb 19, 2016 at 1:06 PM, Martin Vignali > wrote: > > Hello, > > > > Is it necessary to clip value, if B == 0 ? > > Well, integer division by 0 is undefined... > > > > > > > Martin > > > > 2016-02-19 18:47 GMT+01:00 Timothy Gu : > > > [...] > Yes, but in that case, zero division can't happen, because B == 0 is tested. For now, this is the line av_clip_uint8(B == 0 ? 255 : 255 * A / B)) I think something like this can be enough : B == 0 ? 255 : av_clip_uint8(255 * A / B)) Martin ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] vf_blend: Use integers for divide mode
On Fri, Feb 19, 2016 at 1:06 PM, Martin Vignaliwrote: > Hello, > > Is it necessary to clip value, if B == 0 ? Well, integer division by 0 is undefined... > > > Martin > > 2016-02-19 18:47 GMT+01:00 Timothy Gu : > [...] ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] vf_blend: Use integers for divide mode
Hello, Is it necessary to clip value, if B == 0 ? Martin 2016-02-19 18:47 GMT+01:00 Timothy Gu: > On Sun, Feb 14, 2016 at 10:41:04AM +0100, Paul B Mahol wrote: > > > > ok > > Pushed (last week). Thanks. > > Timothy > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] vf_blend: Use integers for divide mode
On Sun, Feb 14, 2016 at 10:41:04AM +0100, Paul B Mahol wrote: > > ok Pushed (last week). Thanks. Timothy ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Re: [FFmpeg-devel] [PATCH] vf_blend: Use integers for divide mode
On 2/14/16, Timothy Guwrote: > 2.5x faster for 8-bit mode without autovectorization in GCC, 2x > slower with it on x86. However, since the platforms we enable GCC > autovectorization on most probably has support for SSE2 > optimization (added in the subsequent commit), this commit should > in general do good. > --- > libavfilter/vf_blend.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c > index 2b734b4..b9e5add 100644 > --- a/libavfilter/vf_blend.c > +++ b/libavfilter/vf_blend.c > @@ -240,7 +240,7 @@ DEFINE_BLEND8(hardlight, (B < 128) ? MULTIPLY(2, B, A) > : SCREEN(2, B, A)) > DEFINE_BLEND8(hardmix,(A < (255 - B)) ? 0: 255) > DEFINE_BLEND8(darken, FFMIN(A, B)) > DEFINE_BLEND8(lighten,FFMAX(A, B)) > -DEFINE_BLEND8(divide, av_clip_uint8(((float)A / ((float)B) * 255))) > +DEFINE_BLEND8(divide, av_clip_uint8(B == 0 ? 255 : 255 * A / B)) > DEFINE_BLEND8(dodge, DODGE(A, B)) > DEFINE_BLEND8(burn, BURN(A, B)) > DEFINE_BLEND8(softlight, (A > 127) ? B + (255 - B) * (A - 127.5) / 127.5 * > (0.5 - fabs(B - 127.5) / 255): B - B * ((127.5 - A) / 127.5) * (0.5 - fabs(B > - 127.5)/255)) > @@ -280,7 +280,7 @@ DEFINE_BLEND16(hardlight, (B < 32768) ? MULTIPLY(2, B, > A) : SCREEN(2, B, A)) > DEFINE_BLEND16(hardmix,(A < (65535 - B)) ? 0: 65535) > DEFINE_BLEND16(darken, FFMIN(A, B)) > DEFINE_BLEND16(lighten,FFMAX(A, B)) > -DEFINE_BLEND16(divide, av_clip_uint16(((float)A / ((float)B) * 65535))) > +DEFINE_BLEND16(divide, av_clip_uint16(B == 0 ? 65535 : 65535 * A / B)) > DEFINE_BLEND16(dodge, DODGE(A, B)) > DEFINE_BLEND16(burn, BURN(A, B)) > DEFINE_BLEND16(softlight, (A > 32767) ? B + (65535 - B) * (A - 32767.5) / > 32767.5 * (0.5 - fabs(B - 32767.5) / 65535): B - B * ((32767.5 - A) / > 32767.5) * (0.5 - fabs(B - 32767.5)/65535)) > -- > 2.1.4 > > ___ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > http://ffmpeg.org/mailman/listinfo/ffmpeg-devel > ok ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
[FFmpeg-devel] [PATCH] vf_blend: Use integers for divide mode
2.5x faster for 8-bit mode without autovectorization in GCC, 2x slower with it on x86. However, since the platforms we enable GCC autovectorization on most probably has support for SSE2 optimization (added in the subsequent commit), this commit should in general do good. --- libavfilter/vf_blend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavfilter/vf_blend.c b/libavfilter/vf_blend.c index 2b734b4..b9e5add 100644 --- a/libavfilter/vf_blend.c +++ b/libavfilter/vf_blend.c @@ -240,7 +240,7 @@ DEFINE_BLEND8(hardlight, (B < 128) ? MULTIPLY(2, B, A) : SCREEN(2, B, A)) DEFINE_BLEND8(hardmix,(A < (255 - B)) ? 0: 255) DEFINE_BLEND8(darken, FFMIN(A, B)) DEFINE_BLEND8(lighten,FFMAX(A, B)) -DEFINE_BLEND8(divide, av_clip_uint8(((float)A / ((float)B) * 255))) +DEFINE_BLEND8(divide, av_clip_uint8(B == 0 ? 255 : 255 * A / B)) DEFINE_BLEND8(dodge, DODGE(A, B)) DEFINE_BLEND8(burn, BURN(A, B)) DEFINE_BLEND8(softlight, (A > 127) ? B + (255 - B) * (A - 127.5) / 127.5 * (0.5 - fabs(B - 127.5) / 255): B - B * ((127.5 - A) / 127.5) * (0.5 - fabs(B - 127.5)/255)) @@ -280,7 +280,7 @@ DEFINE_BLEND16(hardlight, (B < 32768) ? MULTIPLY(2, B, A) : SCREEN(2, B, A)) DEFINE_BLEND16(hardmix,(A < (65535 - B)) ? 0: 65535) DEFINE_BLEND16(darken, FFMIN(A, B)) DEFINE_BLEND16(lighten,FFMAX(A, B)) -DEFINE_BLEND16(divide, av_clip_uint16(((float)A / ((float)B) * 65535))) +DEFINE_BLEND16(divide, av_clip_uint16(B == 0 ? 65535 : 65535 * A / B)) DEFINE_BLEND16(dodge, DODGE(A, B)) DEFINE_BLEND16(burn, BURN(A, B)) DEFINE_BLEND16(softlight, (A > 32767) ? B + (65535 - B) * (A - 32767.5) / 32767.5 * (0.5 - fabs(B - 32767.5) / 65535): B - B * ((32767.5 - A) / 32767.5) * (0.5 - fabs(B - 32767.5)/65535)) -- 2.1.4 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel