diff options
author | Paul B Mahol <onemda@gmail.com> | 2021-01-31 20:24:04 +0100 |
---|---|---|
committer | Paul B Mahol <onemda@gmail.com> | 2021-01-31 20:55:23 +0100 |
commit | aa8cf8fdee415106e55e19a81599a4d8e6c51a1f (patch) | |
tree | 1a9a17cb2902cea93cf2823038acf4e17007dfab | |
parent | 6de039823c2ffcf88e8bfff0d4e3ed9d5601a122 (diff) |
avfilter/vf_colortemperature: use macro for identical code
-rw-r--r-- | libavfilter/vf_colortemperature.c | 61 |
1 files changed, 23 insertions, 38 deletions
diff --git a/libavfilter/vf_colortemperature.c b/libavfilter/vf_colortemperature.c index 0466573e96..f2026c6fca 100644 --- a/libavfilter/vf_colortemperature.c +++ b/libavfilter/vf_colortemperature.c @@ -73,6 +73,27 @@ static float lerpf(float v0, float v1, float f) return v0 + (v1 - v0) * f; } +#define PROCESS() \ + nr = r * color[0]; \ + ng = g * color[1]; \ + nb = b * color[2]; \ + \ + nr = lerpf(r, nr, mix); \ + ng = lerpf(g, ng, mix); \ + nb = lerpf(b, nb, mix); \ + \ + l0 = (FFMAX3(r, g, b) + FFMIN3(r, g, b)) + FLT_EPSILON; \ + l1 = (FFMAX3(nr, ng, nb) + FFMIN3(nr, ng, nb)) + FLT_EPSILON; \ + l = l0 / l1; \ + \ + r = nr * l; \ + g = ng * l; \ + b = nb * l; \ + \ + nr = lerpf(nr, r, preserve); \ + ng = lerpf(ng, g, preserve); \ + nb = lerpf(nb, b, preserve); + static int temperature_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) { ColorTemperatureContext *s = ctx->priv; @@ -99,25 +120,7 @@ static int temperature_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb float nr, ng, nb; float l0, l1, l; - nr = r * color[0]; - ng = g * color[1]; - nb = b * color[2]; - - nr = lerpf(r, nr, mix); - ng = lerpf(g, ng, mix); - nb = lerpf(b, nb, mix); - - l0 = (FFMAX3(r, g, b) + FFMIN3(r, g, b)) + FLT_EPSILON; - l1 = (FFMAX3(nr, ng, nb) + FFMIN3(nr, ng, nb)) + FLT_EPSILON; - l = l0 / l1; - - r = nr * l; - g = ng * l; - b = nb * l; - - nr = lerpf(nr, r, preserve); - ng = lerpf(ng, g, preserve); - nb = lerpf(nb, b, preserve); + PROCESS() gptr[x] = av_clip_uint8(ng); bptr[x] = av_clip_uint8(nb); @@ -159,25 +162,7 @@ static int temperature_slice16(AVFilterContext *ctx, void *arg, int jobnr, int n float nr, ng, nb; float l0, l1, l; - nr = r * color[0]; - ng = g * color[1]; - nb = b * color[2]; - - nr = lerpf(r, nr, mix); - ng = lerpf(g, ng, mix); - nb = lerpf(b, nb, mix); - - l0 = (FFMAX3(r, g, b) + FFMIN3(r, g, b)) + FLT_EPSILON; - l1 = (FFMAX3(nr, ng, nb) + FFMIN3(nr, ng, nb)) + FLT_EPSILON; - l = l0 / l1; - - r = nr * l; - g = ng * l; - b = nb * l; - - nr = lerpf(nr, r, preserve); - ng = lerpf(ng, g, preserve); - nb = lerpf(nb, b, preserve); + PROCESS() gptr[x] = av_clip_uintp2_c(ng, depth); bptr[x] = av_clip_uintp2_c(nb, depth); |