Showing the changes to libavfilter (1 of 2 files). Show all
Unified · Split
| @@ -96,8 +96,8 @@ typedef struct ShowSpectrumContext { · 95 unmodified lines | ||
| 96 | 96 | float overlap; |
| 97 | 97 | float gain; |
| 98 | 98 | int hop_size; |
| 99 | − float *combine_buffer; ///< color combining buffer (3 * h items) | |
| 100 | − float **color_buffer; ///< color buffer (3 * h * ch items) | |
| 99 | + float *combine_buffer; ///< color combining buffer (4 * h items) | |
| 100 | + float **color_buffer; ///< color buffer (4 * h * ch items) | |
| 101 | 101 | int64_t pts; |
| 102 | 102 | int64_t old_pts; |
| 103 | 103 | int64_t in_pts; |
| @@ -110,6 +110,8 @@ typedef struct ShowSpectrumContext { · 6 unmodified lines | ||
| 110 | 110 | uint64_t samples; |
| 111 | 111 | int (*plot_channel)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs); |
| 112 | 112 | |
| 113 | + float opacity_factor; | |
| 114 | + | |
| 113 | 115 | AVFrame **frames; |
| 114 | 116 | unsigned int nb_frames; |
| 115 | 117 | unsigned int frames_size; |
| @@ -174,6 +176,7 @@ static const AVOption showspectrum_options[] = { · 58 unmodified lines | ||
| 174 | 176 | { "legend", "draw legend", OFFSET(legend), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, FLAGS }, |
| 175 | 177 | { "drange", "set dynamic range in dBFS", OFFSET(drange), AV_OPT_TYPE_FLOAT, {.dbl = 120}, 10, 200, FLAGS }, |
| 176 | 178 | { "limit", "set upper limit in dBFS", OFFSET(limit), AV_OPT_TYPE_FLOAT, {.dbl = 0}, -100, 100, FLAGS }, |
| 179 | + { "opacity", "set opacity strength", OFFSET(opacity_factor), AV_OPT_TYPE_FLOAT, {.dbl = 1}, 0, 10, FLAGS }, | |
| 177 | 180 | { NULL } |
| 178 | 181 | }; |
| 179 | 182 | |
| @@ -360,7 +363,7 @@ static int query_formats(AVFilterContext *ctx) · 180 unmodified lines | ||
| 360 | 363 | AVFilterLink *inlink = ctx->inputs[0]; |
| 361 | 364 | AVFilterLink *outlink = ctx->outputs[0]; |
| 362 | 365 | static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }; |
| 363 | − static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_NONE }; | |
| 366 | + static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUV444P, AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_YUVA444P, AV_PIX_FMT_NONE }; | |
| 364 | 367 | int ret; |
| 365 | 368 | |
| 366 | 369 | /* set input audio formats */ |
| @@ -495,11 +498,10 @@ static void drawtext(AVFrame *pic, int x, int y, const char *txt, int o) · 128 unmodified lines | ||
| 495 | 498 | { |
| 496 | 499 | const uint8_t *font; |
| 497 | 500 | int font_height; |
| 498 | − int i; | |
| 499 | 501 | |
| 500 | 502 | font = avpriv_cga_font, font_height = 8; |
| 501 | 503 | |
| 502 | − for (i = 0; txt[i]; i++) { | |
| 504 | + for (int i = 0; txt[i]; i++) { | |
| 503 | 505 | int char_y, mask; |
| 504 | 506 | |
| 505 | 507 | if (o) { |
| @@ -523,6 +525,28 @@ static void drawtext(AVFrame *pic, int x, int y, const char *txt, int o) · 17 unmodified lines | ||
| 523 | 525 | } |
| 524 | 526 | } |
| 525 | 527 | } |
| 528 | + | |
| 529 | + for (int i = 0; txt[i] && pic->data[3]; i++) { | |
| 530 | + int char_y, mask; | |
| 531 | + | |
| 532 | + if (o) { | |
| 533 | + for (char_y = font_height - 1; char_y >= 0; char_y--) { | |
| 534 | + uint8_t *p = pic->data[3] + (y + i * 10) * pic->linesize[3] + x; | |
| 535 | + for (mask = 0x80; mask; mask >>= 1) { | |
| 536 | + for (int k = 0; k < 8; k++) | |
| 537 | + p[k] = 255; | |
| 538 | + p += pic->linesize[3]; | |
| 539 | + } | |
| 540 | + } | |
| 541 | + } else { | |
| 542 | + uint8_t *p = pic->data[3] + y*pic->linesize[3] + (x + i*8); | |
| 543 | + for (char_y = 0; char_y < font_height; char_y++) { | |
| 544 | + for (mask = 0x80; mask; mask >>= 1) | |
| 545 | + *p++ = 255; | |
| 546 | + p += pic->linesize[3] - 8; | |
| 547 | + } | |
| 548 | + } | |
| 549 | + } | |
| 526 | 550 | } |
| 527 | 551 | |
| 528 | 552 | static void color_range(ShowSpectrumContext *s, int ch, |
| @@ -591,6 +615,8 @@ static void pick_color(ShowSpectrumContext *s, · 62 unmodified lines | ||
| 591 | 615 | float yf, float uf, float vf, |
| 592 | 616 | float a, float *out) |
| 593 | 617 | { |
| 618 | + const float af = s->opacity_factor * 255.f; | |
| 619 | + | |
| 594 | 620 | if (s->color_mode > CHANNEL) { |
| 595 | 621 | const int cm = s->color_mode; |
| 596 | 622 | float y, u, v; |
| @@ -624,10 +650,12 @@ static void pick_color(ShowSpectrumContext *s, · 27 unmodified lines | ||
| 624 | 650 | out[0] = y * yf; |
| 625 | 651 | out[1] = u * uf; |
| 626 | 652 | out[2] = v * vf; |
| 653 | + out[3] = a * af; | |
| 627 | 654 | } else { |
| 628 | 655 | out[0] = a * yf; |
| 629 | 656 | out[1] = a * uf; |
| 630 | 657 | out[2] = a * vf; |
| 658 | + out[3] = a * af; | |
| 631 | 659 | } |
| 632 | 660 | } |
| 633 | 661 | |
| @@ -907,23 +935,26 @@ static int draw_legend(AVFilterContext *ctx, uint64_t samples) · 273 unmodified lines | ||
| 907 | 935 | int h = multi ? s->h / s->nb_display_channels : s->h; |
| 908 | 936 | |
| 909 | 937 | for (y = 0; y < h; y++) { |
| 910 | − float out[3] = { 0., 127.5, 127.5}; | |
| 938 | + float out[4] = { 0., 127.5, 127.5, 0.f}; | |
| 911 | 939 | int chn; |
| 912 | 940 | |
| 913 | 941 | for (chn = 0; chn < (s->mode == SEPARATE ? 1 : s->nb_display_channels); chn++) { |
| 914 | 942 | float yf, uf, vf; |
| 915 | 943 | int channel = (multi) ? s->nb_display_channels - ch - 1 : chn; |
| 916 | − float lout[3]; | |
| 944 | + float lout[4]; | |
| 917 | 945 | |
| 918 | 946 | color_range(s, channel, &yf, &uf, &vf); |
| 919 | 947 | pick_color(s, yf, uf, vf, y / (float)h, lout); |
| 920 | 948 | out[0] += lout[0]; |
| 921 | 949 | out[1] += lout[1]; |
| 922 | 950 | out[2] += lout[2]; |
| 951 | + out[3] += lout[3]; | |
| 923 | 952 | } |
| 924 | 953 | memset(s->outpicref->data[0]+(s->start_y + h * (ch + 1) - y - 1) * s->outpicref->linesize[0] + s->w + s->start_x + 20, av_clip_uint8(out[0]), 10); |
| 925 | 954 | memset(s->outpicref->data[1]+(s->start_y + h * (ch + 1) - y - 1) * s->outpicref->linesize[1] + s->w + s->start_x + 20, av_clip_uint8(out[1]), 10); |
| 926 | 955 | memset(s->outpicref->data[2]+(s->start_y + h * (ch + 1) - y - 1) * s->outpicref->linesize[2] + s->w + s->start_x + 20, av_clip_uint8(out[2]), 10); |
| 956 | + if (s->outpicref->data[3]) | |
| 957 | + memset(s->outpicref->data[3]+(s->start_y + h * (ch + 1) - y - 1) * s->outpicref->linesize[3] + s->w + s->start_x + 20, av_clip_uint8(out[3]), 10); | |
| 927 | 958 | } |
| 928 | 959 | |
| 929 | 960 | for (y = 0; ch == 0 && y < h + 5; y += 25) { |
| @@ -985,7 +1016,7 @@ static int plot_channel_lin(AVFilterContext *ctx, void *arg, int jobnr, int nb_j · 55 unmodified lines | ||
| 985 | 1016 | /* draw the channel */ |
| 986 | 1017 | for (y = 0; y < h; y++) { |
| 987 | 1018 | int row = (s->mode == COMBINED) ? y : ch * h + y; |
| 988 | − float *out = &s->color_buffer[ch][3 * row]; | |
| 1019 | + float *out = &s->color_buffer[ch][4 * row]; | |
| 989 | 1020 | float a = get_value(ctx, ch, y); |
| 990 | 1021 | |
| 991 | 1022 | pick_color(s, yf, uf, vf, a, out); |
| @@ -1016,7 +1047,7 @@ static int plot_channel_log(AVFilterContext *ctx, void *arg, int jobnr, int nb_j · 24 unmodified lines | ||
| 1016 | 1047 | a1 = get_value(ctx, ch, av_clip(pos+1, 0, h-1)); |
| 1017 | 1048 | { |
| 1018 | 1049 | int row = (s->mode == COMBINED) ? yy : ch * h + yy; |
| 1019 | − float *out = &s->color_buffer[ch][3 * row]; | |
| 1050 | + float *out = &s->color_buffer[ch][4 * row]; | |
| 1020 | 1051 | |
| 1021 | 1052 | pick_color(s, yf, uf, vf, delta * a1 + (1.f - delta) * a0, out); |
| 1022 | 1053 | } |
| @@ -1155,7 +1186,7 @@ static int config_output(AVFilterLink *outlink) · 132 unmodified lines | ||
| 1155 | 1186 | if (!s->color_buffer) |
| 1156 | 1187 | return AVERROR(ENOMEM); |
| 1157 | 1188 | for (i = 0; i < s->nb_display_channels; i++) { |
| 1158 | − s->color_buffer[i] = av_calloc(s->orientation == VERTICAL ? s->h * 3 : s->w * 3, sizeof(**s->color_buffer)); | |
| 1189 | + s->color_buffer[i] = av_calloc(s->orientation == VERTICAL ? s->h * 4 : s->w * 4, sizeof(**s->color_buffer)); | |
| 1159 | 1190 | if (!s->color_buffer[i]) |
| 1160 | 1191 | return AVERROR(ENOMEM); |
| 1161 | 1192 | } |
| @@ -1214,6 +1245,8 @@ static int config_output(AVFilterLink *outlink) · 52 unmodified lines | ||
| 1214 | 1245 | memset(outpicref->data[0] + i * outpicref->linesize[0], 0, outlink->w); |
| 1215 | 1246 | memset(outpicref->data[1] + i * outpicref->linesize[1], 128, outlink->w); |
| 1216 | 1247 | memset(outpicref->data[2] + i * outpicref->linesize[2], 128, outlink->w); |
| 1248 | + if (outpicref->data[3]) | |
| 1249 | + memset(outpicref->data[3] + i * outpicref->linesize[3], 0, outlink->w); | |
| 1217 | 1250 | } |
| 1218 | 1251 | outpicref->color_range = AVCOL_RANGE_JPEG; |
| 1219 | 1252 | |
| @@ -1251,11 +1284,11 @@ static int config_output(AVFilterLink *outlink) · 31 unmodified lines | ||
| 1251 | 1284 | |
| 1252 | 1285 | if (s->orientation == VERTICAL) { |
| 1253 | 1286 | s->combine_buffer = |
| 1254 | − av_realloc_f(s->combine_buffer, s->h * 3, | |
| 1287 | + av_realloc_f(s->combine_buffer, s->h * 4, | |
| 1255 | 1288 | sizeof(*s->combine_buffer)); |
| 1256 | 1289 | } else { |
| 1257 | 1290 | s->combine_buffer = |
| 1258 | − av_realloc_f(s->combine_buffer, s->w * 3, | |
| 1291 | + av_realloc_f(s->combine_buffer, s->w * 4, | |
| 1259 | 1292 | sizeof(*s->combine_buffer)); |
| 1260 | 1293 | } |
| 1261 | 1294 | |
| @@ -1379,9 +1412,10 @@ static void clear_combine_buffer(ShowSpectrumContext *s, int size) · 117 unmodified lines | ||
| 1379 | 1412 | int y; |
| 1380 | 1413 | |
| 1381 | 1414 | for (y = 0; y < size; y++) { |
| 1382 | − s->combine_buffer[3 * y ] = 0; | |
| 1383 | − s->combine_buffer[3 * y + 1] = 127.5; | |
| 1384 | − s->combine_buffer[3 * y + 2] = 127.5; | |
| 1415 | + s->combine_buffer[4 * y ] = 0; | |
| 1416 | + s->combine_buffer[4 * y + 1] = 127.5; | |
| 1417 | + s->combine_buffer[4 * y + 2] = 127.5; | |
| 1418 | + s->combine_buffer[4 * y + 3] = 0; | |
| 1385 | 1419 | } |
| 1386 | 1420 | } |
| 1387 | 1421 | |
| @@ -1392,6 +1426,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples) · 4 unmodified lines | ||
| 1392 | 1426 | ShowSpectrumContext *s = ctx->priv; |
| 1393 | 1427 | AVFrame *outpicref = s->outpicref; |
| 1394 | 1428 | int ret, plane, x, y, z = s->orientation == VERTICAL ? s->h : s->w; |
| 1429 | + const int alpha = outpicref->data[3] != NULL; | |
| 1395 | 1430 | |
| 1396 | 1431 | /* fill a new spectrum column */ |
| 1397 | 1432 | /* initialize buffer for combining to black */ |
| @@ -1399,7 +1434,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples) · 1 unmodified line | ||
| 1399 | 1434 | |
| 1400 | 1435 | ff_filter_execute(ctx, s->plot_channel, NULL, NULL, s->nb_display_channels); |
| 1401 | 1436 | |
| 1402 | − for (y = 0; y < z * 3; y++) { | |
| 1437 | + for (y = 0; y < z * 4; y++) { | |
| 1403 | 1438 | for (x = 0; x < s->nb_display_channels; x++) { |
| 1404 | 1439 | s->combine_buffer[y] += s->color_buffer[x][y]; |
| 1405 | 1440 | } |
| @@ -1409,7 +1444,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples) · 3 unmodified lines | ||
| 1409 | 1444 | /* copy to output */ |
| 1410 | 1445 | if (s->orientation == VERTICAL) { |
| 1411 | 1446 | if (s->sliding == SCROLL) { |
| 1412 | − for (plane = 0; plane < 3; plane++) { | |
| 1447 | + for (plane = 0; plane < 3 + alpha; plane++) { | |
| 1413 | 1448 | for (y = 0; y < s->h; y++) { |
| 1414 | 1449 | uint8_t *p = outpicref->data[plane] + s->start_x + |
| 1415 | 1450 | (y + s->start_y) * outpicref->linesize[plane]; |
| @@ -1418,7 +1453,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples) · 2 unmodified lines | ||
| 1418 | 1453 | } |
| 1419 | 1454 | s->xpos = s->w - 1; |
| 1420 | 1455 | } else if (s->sliding == RSCROLL) { |
| 1421 | − for (plane = 0; plane < 3; plane++) { | |
| 1456 | + for (plane = 0; plane < 3 + alpha; plane++) { | |
| 1422 | 1457 | for (y = 0; y < s->h; y++) { |
| 1423 | 1458 | uint8_t *p = outpicref->data[plane] + s->start_x + |
| 1424 | 1459 | (y + s->start_y) * outpicref->linesize[plane]; |
| @@ -1432,13 +1467,22 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples) · 7 unmodified lines | ||
| 1432 | 1467 | (outlink->h - 1 - s->start_y) * outpicref->linesize[plane] + |
| 1433 | 1468 | s->xpos; |
| 1434 | 1469 | for (y = 0; y < s->h; y++) { |
| 1435 | − *p = lrintf(av_clipf(s->combine_buffer[3 * y + plane], 0, 255)); | |
| 1470 | + *p = lrintf(av_clipf(s->combine_buffer[4 * y + plane], 0, 255)); | |
| 1436 | 1471 | p -= outpicref->linesize[plane]; |
| 1437 | 1472 | } |
| 1438 | 1473 | } |
| 1474 | + if (alpha) { | |
| 1475 | + uint8_t *p = outpicref->data[3] + s->start_x + | |
| 1476 | + (outlink->h - 1 - s->start_y) * outpicref->linesize[3] + | |
| 1477 | + s->xpos; | |
| 1478 | + for (y = 0; y < s->h; y++) { | |
| 1479 | + *p = lrintf(av_clipf(s->combine_buffer[4 * y + 3], 0, 255)); | |
| 1480 | + p -= outpicref->linesize[3]; | |
| 1481 | + } | |
| 1482 | + } | |
| 1439 | 1483 | } else { |
| 1440 | 1484 | if (s->sliding == SCROLL) { |
| 1441 | − for (plane = 0; plane < 3; plane++) { | |
| 1485 | + for (plane = 0; plane < 3 + alpha; plane++) { | |
| 1442 | 1486 | for (y = 1; y < s->h; y++) { |
| 1443 | 1487 | memmove(outpicref->data[plane] + (y-1 + s->start_y) * outpicref->linesize[plane] + s->start_x, |
| 1444 | 1488 | outpicref->data[plane] + (y + s->start_y) * outpicref->linesize[plane] + s->start_x, |
| @@ -1447,7 +1491,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples) · 2 unmodified lines | ||
| 1447 | 1491 | } |
| 1448 | 1492 | s->xpos = s->h - 1; |
| 1449 | 1493 | } else if (s->sliding == RSCROLL) { |
| 1450 | − for (plane = 0; plane < 3; plane++) { | |
| 1494 | + for (plane = 0; plane < 3 + alpha; plane++) { | |
| 1451 | 1495 | for (y = s->h - 1; y >= 1; y--) { |
| 1452 | 1496 | memmove(outpicref->data[plane] + (y + s->start_y) * outpicref->linesize[plane] + s->start_x, |
| 1453 | 1497 | outpicref->data[plane] + (y-1 + s->start_y) * outpicref->linesize[plane] + s->start_x, |
| @@ -1460,7 +1504,15 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples) · 6 unmodified lines | ||
| 1460 | 1504 | uint8_t *p = outpicref->data[plane] + s->start_x + |
| 1461 | 1505 | (s->xpos + s->start_y) * outpicref->linesize[plane]; |
| 1462 | 1506 | for (x = 0; x < s->w; x++) { |
| 1463 | − *p = lrintf(av_clipf(s->combine_buffer[3 * x + plane], 0, 255)); | |
| 1507 | + *p = lrintf(av_clipf(s->combine_buffer[4 * x + plane], 0, 255)); | |
| 1508 | + p++; | |
| 1509 | + } | |
| 1510 | + } | |
| 1511 | + if (alpha) { | |
| 1512 | + uint8_t *p = outpicref->data[3] + s->start_x + | |
| 1513 | + (s->xpos + s->start_y) * outpicref->linesize[3]; | |
| 1514 | + for (x = 0; x < s->w; x++) { | |
| 1515 | + *p = lrintf(av_clipf(s->combine_buffer[4 * x + 3], 0, 255)); | |
| 1464 | 1516 | p++; |
| 1465 | 1517 | } |
| 1466 | 1518 | } |
| @@ -1576,12 +1628,16 @@ static int activate(AVFilterContext *ctx) · 109 unmodified lines | ||
| 1576 | 1628 | memset(s->outpicref->data[0] + i * s->outpicref->linesize[0] + s->xpos, 0, outlink->w - s->xpos); |
| 1577 | 1629 | memset(s->outpicref->data[1] + i * s->outpicref->linesize[1] + s->xpos, 128, outlink->w - s->xpos); |
| 1578 | 1630 | memset(s->outpicref->data[2] + i * s->outpicref->linesize[2] + s->xpos, 128, outlink->w - s->xpos); |
| 1631 | + if (s->outpicref->data[3]) | |
| 1632 | + memset(s->outpicref->data[3] + i * s->outpicref->linesize[3] + s->xpos, 0, outlink->w - s->xpos); | |
| 1579 | 1633 | } |
| 1580 | 1634 | } else { |
| 1581 | 1635 | for (int i = s->xpos; i < outlink->h; i++) { |
| 1582 | 1636 | memset(s->outpicref->data[0] + i * s->outpicref->linesize[0], 0, outlink->w); |
| 1583 | 1637 | memset(s->outpicref->data[1] + i * s->outpicref->linesize[1], 128, outlink->w); |
| 1584 | 1638 | memset(s->outpicref->data[2] + i * s->outpicref->linesize[2], 128, outlink->w); |
| 1639 | + if (s->outpicref->data[3]) | |
| 1640 | + memset(s->outpicref->data[3] + i * s->outpicref->linesize[3], 0, outlink->w); | |
| 1585 | 1641 | } |
| 1586 | 1642 | } |
| 1587 | 1643 | s->outpicref->pts = av_rescale_q(s->in_pts, inlink->time_base, outlink->time_base); |
| @@ -1687,6 +1743,7 @@ static const AVOption showspectrumpic_options[] = { · 99 unmodified lines | ||
| 1687 | 1743 | { "stop", "stop frequency", OFFSET(stop), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT32_MAX, FLAGS }, |
| 1688 | 1744 | { "drange", "set dynamic range in dBFS", OFFSET(drange), AV_OPT_TYPE_FLOAT, {.dbl = 120}, 10, 200, FLAGS }, |
| 1689 | 1745 | { "limit", "set upper limit in dBFS", OFFSET(limit), AV_OPT_TYPE_FLOAT, {.dbl = 0}, -100, 100, FLAGS }, |
| 1746 | + { "opacity", "set opacity strength", OFFSET(opacity_factor), AV_OPT_TYPE_FLOAT, {.dbl = 1}, 0, 10, FLAGS }, | |
| 1690 | 1747 | { NULL } |
| 1691 | 1748 | }; |
| 1692 | 1749 | |