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