Showing the changes to libavfilter (1 of 2 files). Show all
Unified · Split
| @@ -19,6 +19,7 @@ · 18 unmodified lines | ||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | #include "libavutil/avassert.h" |
| 22 | +#include "libavutil/colorspace.h" | |
| 22 | 23 | #include "libavutil/opt.h" |
| 23 | 24 | #include "libavutil/parseutils.h" |
| 24 | 25 | #include "libavutil/pixdesc.h" |
| @@ -32,6 +33,7 @@ · 7 unmodified lines | ||
| 32 | 33 | typedef struct HistogramContext { |
| 33 | 34 | const AVClass *class; ///< AVClass context for log and options purpose |
| 34 | 35 | int thistogram; |
| 36 | + int envelope; | |
| 35 | 37 | unsigned histogram[256*256]; |
| 36 | 38 | int histogram_size; |
| 37 | 39 | int width; |
| @@ -41,6 +43,8 @@ typedef struct HistogramContext { · 3 unmodified lines | ||
| 41 | 43 | int dncomp; |
| 42 | 44 | uint8_t bg_color[4]; |
| 43 | 45 | uint8_t fg_color[4]; |
| 46 | + uint8_t envelope_rgba[4]; | |
| 47 | + uint8_t envelope_color[4]; | |
| 44 | 48 | int level_height; |
| 45 | 49 | int scale_height; |
| 46 | 50 | int display_mode; |
| @@ -219,12 +223,17 @@ static int config_input(AVFilterLink *inlink) · 172 unmodified lines | ||
| 219 | 223 | memcpy(s->bg_color, black_gbrp_color, 4); |
| 220 | 224 | memcpy(s->fg_color, white_gbrp_color, 4); |
| 221 | 225 | s->start[0] = s->start[1] = s->start[2] = s->start[3] = 0; |
| 226 | + memcpy(s->envelope_color, s->envelope_rgba, 4); | |
| 222 | 227 | break; |
| 223 | 228 | default: |
| 224 | 229 | memcpy(s->bg_color, black_yuva_color, 4); |
| 225 | 230 | memcpy(s->fg_color, white_yuva_color, 4); |
| 226 | 231 | s->start[0] = s->start[3] = 0; |
| 227 | 232 | 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]; | |
| 228 | 237 | } |
| 229 | 238 | |
| 230 | 239 | s->fg_color[3] = s->fgopacity * 255; |
| @@ -345,10 +354,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 114 unmodified lines | ||
| 345 | 354 | max_hval_log = log2(max_hval + 1); |
| 346 | 355 | |
| 347 | 356 | if (s->thistogram) { |
| 357 | + int minh = s->histogram_size - 1, maxh = 0; | |
| 358 | + | |
| 348 | 359 | for (int i = 0; i < s->histogram_size; i++) { |
| 349 | 360 | int idx = s->histogram_size - i - 1; |
| 350 | 361 | int value = s->start[p]; |
| 351 | 362 | |
| 363 | + if (s->envelope && s->histogram[idx]) { | |
| 364 | + minh = FFMIN(minh, i); | |
| 365 | + maxh = FFMAX(maxh, i); | |
| 366 | + } | |
| 367 | + | |
| 352 | 368 | if (s->levels_mode) |
| 353 | 369 | value += lrint(max_value * (log2(s->histogram[idx] + 1) / max_hval_log)); |
| 354 | 370 | else |
| @@ -360,6 +376,30 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 5 unmodified lines | ||
| 360 | 376 | AV_WN16(s->out->data[p] + (i + starty) * s->out->linesize[p] + startx * 2 + s->x_pos * 2, value); |
| 361 | 377 | } |
| 362 | 378 | } |
| 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 | + } | |
| 363 | 403 | } else { |
| 364 | 404 | for (i = 0; i < s->histogram_size; i++) { |
| 365 | 405 | int col_height; |
| @@ -455,8 +495,12 @@ static const AVOption thistogram_options[] = { · 89 unmodified lines | ||
| 455 | 495 | { "width", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS}, |
| 456 | 496 | { "w", "set width", OFFSET(width), AV_OPT_TYPE_INT, {.i64=0}, 0, 8192, FLAGS}, |
| 457 | 497 | 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 }, | |
| 460 | 504 | { NULL } |
| 461 | 505 | }; |
| 462 | 506 | |