History

avfilter/vf_histogram: add envelope to thistogram filter

Paul B Mahol committed 6 years ago

Commit f651b181 parent b2491562 files · +53 −3Browse files

Showing the changes to libavfilter (1 of 2 files). Show all

Unified · Split

libavfilter/vf_histogram.c+46−2
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 */
2020
2121 #include "libavutil/avassert.h"
22+#include "libavutil/colorspace.h"
2223 #include "libavutil/opt.h"
2324 #include "libavutil/parseutils.h"
2425 #include "libavutil/pixdesc.h"
@@ -32,6 +33,7 @@ · 7 unmodified lines
3233 typedef struct HistogramContext {
3334 const AVClass *class; ///< AVClass context for log and options purpose
3435 int thistogram;
36+ int envelope;
3537 unsigned histogram[256*256];
3638 int histogram_size;
3739 int width;
@@ -41,6 +43,8 @@ typedef struct HistogramContext { · 3 unmodified lines
4143 int dncomp;
4244 uint8_t bg_color[4];
4345 uint8_t fg_color[4];
46+ uint8_t envelope_rgba[4];
47+ uint8_t envelope_color[4];
4448 int level_height;
4549 int scale_height;
4650 int display_mode;
@@ -219,12 +223,17 @@ static int config_input(AVFilterLink *inlink) · 172 unmodified lines
219223 memcpy(s->bg_color, black_gbrp_color, 4);
220224 memcpy(s->fg_color, white_gbrp_color, 4);
221225 s->start[0] = s->start[1] = s->start[2] = s->start[3] = 0;
226+ memcpy(s->envelope_color, s->envelope_rgba, 4);
222227 break;
223228 default:
224229 memcpy(s->bg_color, black_yuva_color, 4);
225230 memcpy(s->fg_color, white_yuva_color, 4);
226231 s->start[0] = s->start[3] = 0;
227232 s->start[1] = s->start[2] = s->histogram_size / 2;
233+ s->envelope_color[0] = RGB_TO_Y_BT709(s->envelope_rgba[0], s->envelope_rgba[1], s->envelope_rgba[2]);
234+ s->envelope_color[1] = RGB_TO_U_BT709(s->envelope_rgba[0], s->envelope_rgba[1], s->envelope_rgba[2], 0);
235+ s->envelope_color[2] = RGB_TO_V_BT709(s->envelope_rgba[0], s->envelope_rgba[1], s->envelope_rgba[2], 0);
236+ s->envelope_color[3] = s->envelope_rgba[3];
228237 }
229238
230239 s->fg_color[3] = s->fgopacity * 255;
@@ -345,10 +354,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 114 unmodified lines
345354 max_hval_log = log2(max_hval + 1);
346355
347356 if (s->thistogram) {
357+ int minh = s->histogram_size - 1, maxh = 0;
358+
348359 for (int i = 0; i < s->histogram_size; i++) {
349360 int idx = s->histogram_size - i - 1;
350361 int value = s->start[p];
351362
363+ if (s->envelope && s->histogram[idx]) {
364+ minh = FFMIN(minh, i);
365+ maxh = FFMAX(maxh, i);
366+ }
367+
352368 if (s->levels_mode)
353369 value += lrint(max_value * (log2(s->histogram[idx] + 1) / max_hval_log));
354370 else
@@ -360,6 +376,30 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 5 unmodified lines
360376 AV_WN16(s->out->data[p] + (i + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, value);
361377 }
362378 }
379+
380+ if (s->envelope) {
381+ if (s->histogram_size <= 256) {
382+ s->out->data[0][(minh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[0];
383+ s->out->data[0][(maxh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[0];
384+ if (s->dncomp >= 3) {
385+ s->out->data[1][(minh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[1];
386+ s->out->data[2][(minh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[2];
387+ s->out->data[1][(maxh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[1];
388+ s->out->data[2][(maxh + starty) * s->out->linesize[p] + startx + s->x_pos] = s->envelope_color[2];
389+ }
390+ } else {
391+ const int mult = s->mult;
392+
393+ AV_WN16(s->out->data[0] + (minh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[0] * mult);
394+ AV_WN16(s->out->data[0] + (maxh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[0] * mult);
395+ if (s->dncomp >= 3) {
396+ AV_WN16(s->out->data[1] + (minh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[1] * mult);
397+ AV_WN16(s->out->data[2] + (minh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[2] * mult);
398+ AV_WN16(s->out->data[1] + (maxh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[1] * mult);
399+ AV_WN16(s->out->data[2] + (maxh + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, s->envelope_color[2] * mult);
400+ }
401+ }
402+ }
363403 } else {
364404 for (i = 0; i < s->histogram_size; i++) {
365405 int col_height;
@@ -455,8 +495,12 @@ static const AVOption thistogram_options[] = { · 89 unmodified lines
455495 { "width", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS},
456496 { "w", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS},
457497 COMMON_OPTIONS
458− { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS},
459− { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.5}, 0, 1, FLAGS},
498+ { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.9}, 0, 1, FLAGS},
499+ { "b", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.9}, 0, 1, FLAGS},
500+ { "envelope", "display envelope", OFFSET(envelope), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
501+ { "e", "display envelope", OFFSET(envelope), AV_OPT_TYPE_BOOL, {.i64=0}, 0, 1, FLAGS },
502+ { "ecolor", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },
503+ { "ec", "set envelope color", OFFSET(envelope_rgba), AV_OPT_TYPE_COLOR, {.str="gold"}, 0, 0, FLAGS },
460504 { NULL }
461505 };
462506

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