mirror of
https://gitee.com/openharmony/third_party_ffmpeg
synced 2024-11-23 11:19:55 +00:00
avfilter/vf_pixscope: also show standard deviation of zoomed area
This commit is contained in:
parent
cca0436efc
commit
f53fc935b8
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user