[FFmpeg-devel] [PATCH 1/3] avfilter/vf_pseudocolor: add presets

Nuo Mi nuomi2021 at gmail.com
Sat Jan 30 05:48:58 EET 2021


>
> +#define RGB_TO_Y_BT709(r, g, b) \
> +((0.21260*219.0/255.0) * (r) + (0.71520*219.0/255.0) * (g) + \
> + (0.07220*219.0/255.0) * (b))
> +
> +#define RGB_TO_U_BT709(r1, g1, b1, max) \
> +(-(0.11457*224.0/255.0) * r1 - (0.38543*224.0/255.0) * g1 + \
> +    (0.50000*224.0/255.0) * b1 + max * 0.5)
> +
> +#define RGB_TO_V_BT709(r1, g1, b1, max) \
> +((0.50000*224.0/255.0) * r1 - (0.45415*224.0/255.0) * g1 - \
> +   (0.04585*224.0/255.0) * b1 + max * 0.5)
> +
> +static float lerpf(float v0, float v1, float f)
> +{
> +    return v0 + (v1 - v0) * f;
> +}
>
Do we need to make this always inline?

> +
>  static int config_input(AVFilterLink *inlink)
>  {
>      AVFilterContext *ctx = inlink->dst;
>      PseudoColorContext *s = ctx->priv;
>      const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format);
> -    int depth, ret, hsub, vsub, color;
> +    int depth, ret, hsub, vsub, color, factor, rgb;
>
> +    rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
>      depth = desc->comp[0].depth;
> +    factor = 1 << (depth - 8);
>      s->max = (1 << depth) - 1;
>      s->nb_planes = av_pix_fmt_count_planes(inlink->format);
>
> @@ -457,7 +1138,7 @@ static int config_input(AVFilterLink *inlink)
>      s->var_values[VAR_VMAX] = 240 * (1 << (depth - 8));
>      s->var_values[VAR_AMAX] = s->max;
>
> -    for (color = 0; color < s->nb_planes; color++) {
> +    for (color = 0; color < s->nb_planes && s->preset < 0; color++) {
>          double res;
>          int val;
>
> @@ -488,6 +1169,56 @@ static int config_input(AVFilterLink *inlink)
>          }
>      }
>
> +    if (s->preset >= 0) {
> +        for (int i = 0; i < 255; i++) {
> +            for (int j = 0; j < factor; j++) {
> +                const float lf = j / (float)factor;
> +                int r, g, b;
> +
> +                g = lerpf(presets[s->preset][i][1],
> presets[s->preset][i+1][1], lf) * s->max;
> +                b = lerpf(presets[s->preset][i][2],
> presets[s->preset][i+1][2], lf) * s->max;
> +                r = lerpf(presets[s->preset][i][0],
> presets[s->preset][i+1][0], lf) * s->max;
> +
> +                if (!rgb) {
> +                    int y = RGB_TO_Y_BT709(r, g, b);
> +                    int u = RGB_TO_U_BT709(r, g, b, s->max);
> +                    int v = RGB_TO_V_BT709(r, g, b, s->max);
> +
> +                    r = v;
> +                    g = y;
> +                    b = u;
> +                }
> +
> +                s->lut[0][i*factor+j] = g;
> +                s->lut[1][i*factor+j] = b;
> +                s->lut[2][i*factor+j] = r;
> +            }
> +        }
> +
>
Near the same code block as below, could we move the for loop in a
function?

> +        for (int j = 0; j < factor; j++) {
> +            const float lf = j / (float)factor;
> +            int r, g, b;
> +
> +            g = lerpf(presets[s->preset][254][1],
> presets[s->preset][255][1], lf) * s->max;
> +            b = lerpf(presets[s->preset][254][2],
> presets[s->preset][255][2], lf) * s->max;
> +            r = lerpf(presets[s->preset][254][0],
> presets[s->preset][255][0], lf) * s->max;
> +
> +            if (!rgb) {
> +                int y = RGB_TO_Y_BT709(r, g, b);
> +                int u = RGB_TO_U_BT709(r, g, b, s->max);
> +                int v = RGB_TO_V_BT709(r, g, b, s->max);
> +
> +                r = v;
> +                g = y;
> +                b = u;
> +            }
> +
> +            s->lut[0][255*factor+j] = g;
> +            s->lut[1][255*factor+j] = b;
> +            s->lut[2][255*factor+j] = r;

the previous block is " s->lut[2][i*factor+j] = r ",
Is this a typo of  "s->lut[2][254*factor+j] = r" ?

>

+        }
> +    }

+
>      switch (inlink->format) {
>      case AV_PIX_FMT_YUV444P:
>      case AV_PIX_FMT_YUVA444P:
> --
> 2.17.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".


More information about the ffmpeg-devel mailing list