From e0de0aa5856c337e79eccab600cfa46ef522f6a9 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 15 Aug 2021 23:58:05 +0200 Subject: [PATCH] avfilter/vf_colorcorrect: calculate imax/max once at config stage --- libavfilter/vf_colorcorrect.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/libavfilter/vf_colorcorrect.c b/libavfilter/vf_colorcorrect.c index 1019d431ce..3fb2798256 100644 --- a/libavfilter/vf_colorcorrect.c +++ b/libavfilter/vf_colorcorrect.c @@ -42,6 +42,7 @@ typedef struct ColorCorrectContext { int analyze; int depth; + float max, imax; int chroma_w, chroma_h; int planeheight[4]; @@ -59,9 +60,7 @@ static int average_slice8(AVFilterContext *ctx, void *arg, int jobnr, int nb_job { ColorCorrectContext *s = ctx->priv; AVFrame *frame = arg; - const int depth = s->depth; - const float max = (1 << depth) - 1; - const float imax = 1.f / max; + const float imax = s->imax; const int width = s->planewidth[1]; const int height = s->planeheight[1]; const int slice_start = (height * jobnr) / nb_jobs; @@ -92,9 +91,7 @@ static int average_slice16(AVFilterContext *ctx, void *arg, int jobnr, int nb_jo { ColorCorrectContext *s = ctx->priv; AVFrame *frame = arg; - const int depth = s->depth; - const float max = (1 << depth) - 1; - const float imax = 1.f / max; + const float imax = s->imax; const int width = s->planewidth[1]; const int height = s->planeheight[1]; const int slice_start = (height * jobnr) / nb_jobs; @@ -134,9 +131,8 @@ static int colorcorrect_slice8(AVFilterContext *ctx, void *arg, int jobnr, int n { ColorCorrectContext *s = ctx->priv; AVFrame *frame = arg; - const int depth = s->depth; - const float max = (1 << depth) - 1; - const float imax = 1.f / max; + const float max = s->max; + const float imax = s->imax; const int chroma_w = s->chroma_w; const int chroma_h = s->chroma_h; const int width = s->planewidth[1]; @@ -176,8 +172,8 @@ static int colorcorrect_slice16(AVFilterContext *ctx, void *arg, int jobnr, int ColorCorrectContext *s = ctx->priv; AVFrame *frame = arg; const int depth = s->depth; - const float max = (1 << depth) - 1; - const float imax = 1.f / max; + const float max = s->max; + const float imax = s->imax; const int chroma_w = s->chroma_w; const int chroma_h = s->chroma_h; const int width = s->planewidth[1]; @@ -268,6 +264,8 @@ static av_cold int config_input(AVFilterLink *inlink) const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); s->depth = desc->comp[0].depth; + s->max = (1 << s->depth) - 1; + s->imax = 1.f / s->max; s->do_slice = s->depth <= 8 ? colorcorrect_slice8 : colorcorrect_slice16; s->analyzeret = av_calloc(inlink->h, sizeof(*s->analyzeret));