History

avfilter/vf_pixscope: also show standard deviation of zoomed area

Paul B Mahol committed 6 years ago

Commit f53fc931 parent cca04361 file · +28 −3Browse files

Unified · Split

libavfilter/vf_datascope.c+28−3
@@ -452,6 +452,8 @@ typedef struct PixscopeContext { · 451 unmodified lines
452 FFDrawColor red;452 FFDrawColor red;
453 FFDrawColor *colors[4];453 FFDrawColor *colors[4];
454 454
455 uint16_t values[4][80][80];
456
455 void (*pick_color)(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value);457 void (*pick_color)(FFDrawContext *draw, FFDrawColor *color, AVFrame *in, int x, int y, int *value);
456} PixscopeContext;458} PixscopeContext;
457 459
@@ -526,6 +528,8 @@ static int pixscope_config_input(AVFilterLink *inlink) · 68 unmodified lines
526 return 0;528 return 0;
527}529}
528 530
531#define SQR(x) ((x)*(x))
532
529static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in)533static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in)
530{534{
531 AVFilterContext *ctx = inlink->dst;535 AVFilterContext *ctx = inlink->dst;
@@ -534,7 +538,7 @@ static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in) · 2 unmodified lines
534 AVFrame *out = ff_get_video_buffer(outlink, in->width, in->height);538 AVFrame *out = ff_get_video_buffer(outlink, in->width, in->height);
535 int max[4] = { 0 }, min[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX };539 int max[4] = { 0 }, min[4] = { INT_MAX, INT_MAX, INT_MAX, INT_MAX };
536 float average[4] = { 0 };540 float average[4] = { 0 };
537 double rms[4] = { 0 };541 double std[4] = { 0 }, rms[4] = { 0 };
538 const char rgba[4] = { 'R', 'G', 'B', 'A' };542 const char rgba[4] = { 'R', 'G', 'B', 'A' };
539 const char yuva[4] = { 'Y', 'U', 'V', 'A' };543 const char yuva[4] = { 'Y', 'U', 'V', 'A' };
540 int x, y, X, Y, i, w, h;544 int x, y, X, Y, i, w, h;
@@ -591,6 +595,7 @@ static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in) · 50 unmodified lines
591 ff_fill_rectangle(&s->draw, &color, out->data, out->linesize,595 ff_fill_rectangle(&s->draw, &color, out->data, out->linesize,
592 x * w + (s->ww - 4 - (s->w * w)) / 2 + X, y * h + 2 + Y, w, h);596 x * w + (s->ww - 4 - (s->w * w)) / 2 + X, y * h + 2 + Y, w, h);
593 for (i = 0; i < 4; i++) {597 for (i = 0; i < 4; i++) {
598 s->values[i][x][y] = value[i];
594 rms[i] += (double)value[i] * (double)value[i];599 rms[i] += (double)value[i] * (double)value[i];
595 average[i] += value[i];600 average[i] += value[i];
596 min[i] = FFMIN(min[i], value[i]);601 min[i] = FFMIN(min[i], value[i]);
@@ -637,13 +642,33 @@ static int pixscope_filter_frame(AVFilterLink *inlink, AVFrame *in) · 40 unmodified lines
637 average[i] /= s->w * s->h;642 average[i] /= s->w * s->h;
638 }643 }
639 644
645 for (y = 0; y < s->h; y++) {
646 for (x = 0; x < s->w; x++) {
647 for (i = 0; i < 4; i++)
648 std[i] += SQR(s->values[i][x][y] - average[i]);
649 }
650 }
651
652 for (i = 0; i < 4; i++) {
653 std[i] /= s->w * s->h;
654 std[i] = sqrt(std[i]);
655 }
656
640 snprintf(text, sizeof(text), "CH AVG MIN MAX RMS\n");657 snprintf(text, sizeof(text), "CH AVG MIN MAX RMS\n");
641 draw_text(&s->draw, out, &s->white, X + 28, Y + s->ww + 20, text, 0);658 draw_text(&s->draw, out, &s->white, X + 28, Y + s->ww + 5, text, 0);
642 for (i = 0; i < s->nb_comps; i++) {659 for (i = 0; i < s->nb_comps; i++) {
643 int c = s->rgba_map[i];660 int c = s->rgba_map[i];
644 661
645 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]);662 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]);
646 draw_text(&s->draw, out, s->colors[i], X + 28, Y + s->ww + 20 * (i + 2), text, 0);663 draw_text(&s->draw, out, s->colors[i], X + 28, Y + s->ww + 15 * (i + 1), text, 0);
664 }
665 snprintf(text, sizeof(text), "CH STD\n");
666 draw_text(&s->draw, out, &s->white, X + 28, Y + s->ww + 15 * (0 + 5), text, 0);
667 for (i = 0; i < s->nb_comps; i++) {
668 int c = s->rgba_map[i];
669
670 snprintf(text, sizeof(text), "%c %07.2f\n", s->is_rgb ? rgba[i] : yuva[i], std[c]);
671 draw_text(&s->draw, out, s->colors[i], X + 28, Y + s->ww + 15 * (i + 6), text, 0);
647 }672 }
648 673
649 av_frame_free(&in);674 av_frame_free(&in);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t