From f53fc935b8b75cd301e8beb8ab8e276034cd3442 Mon Sep 17 00:00:00 2001 From: Paul B Mahol Date: Sun, 26 Apr 2020 12:15:12 +0200 Subject: [PATCH] avfilter/vf_pixscope: also show standard deviation of zoomed area --- libavfilter/vf_datascope.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/libavfilter/vf_datascope.c b/libavfilter/vf_datascope.c index e83f04c697..35f60aa2f6 100644 --- a/libavfilter/vf_datascope.c +++ b/libavfilter/vf_datascope.c @@ -452,6 +452,8 @@ typedef struct PixscopeContext { FFDrawColor red; FFDrawColor *colors[4]; + uint16_t values[4][80][80]; + void (*pick_color)(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value); } PixscopeContext; @@ -526,6 +528,8 @@ static int pixscope_config_input(AVFilterLink *inlink) return 0; } +#define SQR(x) ((x)*(x)) + static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in) { AVFilterContext *ctx = inlink->dst; @@ -534,7 +538,7 @@ static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in) AVFrame *out = ff_get_video_buffer(outlink, in->width, in->height); int max[4] = { 0 }, min[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX }; float average[4] = { 0 }; - double rms[4] = { 0 }; + double std[4] = { 0 }, rms[4] = { 0 }; const char rgba[4] = { 'R', 'G', 'B', 'A' }; const char yuva[4] = { 'Y', 'U', 'V', 'A' }; int x, y, X, Y, i, w, h; @@ -591,6 +595,7 @@ static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in) ff_fill_rectangle(&s->draw, &color, out->data, out->linesize, x * w + (s->ww - 4 - (s->w * w)) / 2 + X, y * h + 2 + Y, w, h); for (i = 0; i < 4; i++) { + s->values[i][x][y] = value[i]; rms[i] += (double)value[i] * (double)value[i]; average[i] += value[i]; min[i] = FFMIN(min[i], value[i]); @@ -637,13 +642,33 @@ static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in) average[i] /= s->w * s->h; } + for (y = 0; y < s->h; y++) { + for (x = 0; x < s->w; x++) { + for (i = 0; i < 4; i++) + std[i] += SQR(s->values[i][x][y] - average[i]); + } + } + + for (i = 0; i < 4; i++) { + std[i] /= s->w * s->h; + std[i] = sqrt(std[i]); + } + snprintf(text, sizeof(text), "CH AVG MIN MAX RMS\n"); - draw_text(&s->draw, out, &s->white, X + 28, Y + s->ww + 20, text, 0); + draw_text(&s->draw, out, &s->white, X + 28, Y + s->ww + 5, text, 0); for (i = 0; i < s->nb_comps; i++) { int c = s->rgba_map[i]; snprintf(text, sizeof(text), "%c %07.1f %05d %05d %07.1f\n", s->is_rgb ? rgba[i] : yuva[i], average[c], min[c], max[c], rms[c]); - draw_text(&s->draw, out, s->colors[i], X + 28, Y + s->ww + 20 * (i + 2), text, 0); + draw_text(&s->draw, out, s->colors[i], X + 28, Y + s->ww + 15 * (i + 1), text, 0); + } + snprintf(text, sizeof(text), "CH STD\n"); + draw_text(&s->draw, out, &s->white, X + 28, Y + s->ww + 15 * (0 + 5), text, 0); + for (i = 0; i < s->nb_comps; i++) { + int c = s->rgba_map[i]; + + snprintf(text, sizeof(text), "%c %07.2f\n", s->is_rgb ? rgba[i] : yuva[i], std[c]); + draw_text(&s->draw, out, s->colors[i], X + 28, Y + s->ww + 15 * (i + 6), text, 0); } av_frame_free(&in);