[FFmpeg-cvslog] avfilter/vf_vibrance: factor some calculations out of loop
Paul B Mahol
git at videolan.org
Sun May 5 14:31:11 EEST 2019
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Sun May 5 13:09:37 2019 +0200| [526bc2205b361bb1b8fd2de825f98d36e6554d42] | committer: Paul B Mahol
avfilter/vf_vibrance: factor some calculations out of loop
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=526bc2205b361bb1b8fd2de825f98d36e6554d42
---
libavfilter/vf_vibrance.c | 32 ++++++++++++++++++++------------
1 file changed, 20 insertions(+), 12 deletions(-)
diff --git a/libavfilter/vf_vibrance.c b/libavfilter/vf_vibrance.c
index 1e5bf26512..bbcb7bef6f 100644
--- a/libavfilter/vf_vibrance.c
+++ b/libavfilter/vf_vibrance.c
@@ -49,6 +49,7 @@ static int vibrance_slice8(AVFilterContext *avctx, void *arg, int jobnr, int nb_
AVFrame *frame = arg;
const int width = frame->width;
const int height = frame->height;
+ const float scale = 1.f / 255.f;
const float gc = s->lcoeffs[0];
const float bc = s->lcoeffs[1];
const float rc = s->lcoeffs[2];
@@ -56,6 +57,9 @@ static int vibrance_slice8(AVFilterContext *avctx, void *arg, int jobnr, int nb_
const float gintensity = intensity * s->balance[0];
const float bintensity = intensity * s->balance[1];
const float rintensity = intensity * s->balance[2];
+ const float sgintensity = FFSIGN(intensity);
+ const float sbintensity = FFSIGN(intensity);
+ const float srintensity = FFSIGN(intensity);
const int slice_start = (height * jobnr) / nb_jobs;
const int slice_end = (height * (jobnr + 1)) / nb_jobs;
const int glinesize = frame->linesize[0];
@@ -67,16 +71,16 @@ static int vibrance_slice8(AVFilterContext *avctx, void *arg, int jobnr, int nb_
for (int y = slice_start; y < slice_end; y++) {
for (int x = 0; x < width; x++) {
- float g = gptr[x] / 255.f;
- float b = bptr[x] / 255.f;
- float r = rptr[x] / 255.f;
+ float g = gptr[x] * scale;
+ float b = bptr[x] * scale;
+ float r = rptr[x] * scale;
float max_color = FFMAX3(r, g, b);
float min_color = FFMIN3(r, g, b);
float color_saturation = max_color - min_color;
float luma = g * gc + r * rc + b * bc;
- const float cg = 1.f + gintensity * (1.f - FFSIGN(gintensity) * color_saturation);
- const float cb = 1.f + bintensity * (1.f - FFSIGN(bintensity) * color_saturation);
- const float cr = 1.f + rintensity * (1.f - FFSIGN(rintensity) * color_saturation);
+ const float cg = 1.f + gintensity * (1.f - sgintensity * color_saturation);
+ const float cb = 1.f + bintensity * (1.f - sbintensity * color_saturation);
+ const float cr = 1.f + rintensity * (1.f - srintensity * color_saturation);
g = lerpf(luma, g, cg);
b = lerpf(luma, b, cb);
@@ -101,6 +105,7 @@ static int vibrance_slice16(AVFilterContext *avctx, void *arg, int jobnr, int nb
AVFrame *frame = arg;
const int depth = s->depth;
const float max = (1 << depth) - 1;
+ const float scale = 1.f / max;
const float gc = s->lcoeffs[0];
const float bc = s->lcoeffs[1];
const float rc = s->lcoeffs[2];
@@ -110,6 +115,9 @@ static int vibrance_slice16(AVFilterContext *avctx, void *arg, int jobnr, int nb
const float gintensity = intensity * s->balance[0];
const float bintensity = intensity * s->balance[1];
const float rintensity = intensity * s->balance[2];
+ const float sgintensity = FFSIGN(intensity);
+ const float sbintensity = FFSIGN(intensity);
+ const float srintensity = FFSIGN(intensity);
const int slice_start = (height * jobnr) / nb_jobs;
const int slice_end = (height * (jobnr + 1)) / nb_jobs;
const int glinesize = frame->linesize[0] / 2;
@@ -121,16 +129,16 @@ static int vibrance_slice16(AVFilterContext *avctx, void *arg, int jobnr, int nb
for (int y = slice_start; y < slice_end; y++) {
for (int x = 0; x < width; x++) {
- float g = gptr[x] / max;
- float b = bptr[x] / max;
- float r = rptr[x] / max;
+ float g = gptr[x] * scale;
+ float b = bptr[x] * scale;
+ float r = rptr[x] * scale;
float max_color = FFMAX3(r, g, b);
float min_color = FFMIN3(r, g, b);
float color_saturation = max_color - min_color;
float luma = g * gc + r * rc + b * bc;
- const float cg = 1.f + gintensity * (1.f - FFSIGN(gintensity) * color_saturation);
- const float cb = 1.f + bintensity * (1.f - FFSIGN(bintensity) * color_saturation);
- const float cr = 1.f + rintensity * (1.f - FFSIGN(rintensity) * color_saturation);
+ const float cg = 1.f + gintensity * (1.f - sgintensity * color_saturation);
+ const float cb = 1.f + bintensity * (1.f - sbintensity * color_saturation);
+ const float cr = 1.f + rintensity * (1.f - srintensity * color_saturation);
g = lerpf(luma, g, cg);
b = lerpf(luma, b, cb);
More information about the ffmpeg-cvslog
mailing list