| @@ -59,8 +59,53 @@ enum var_name { · 58 unmodified lines |
| 59 | VAR_VARS_NB | 59 | VAR_VARS_NB |
| 60 | }; | 60 | }; |
| 61 | | 61 | |
| | 62 | enum ColorMaps { |
| | 63 | MAGMA, |
| | 64 | INFERNO, |
| | 65 | PLASMA, |
| | 66 | VIRIDIS, |
| | 67 | TURBO, |
| | 68 | CIVIDIS, |
| | 69 | NB_CMAPS, |
| | 70 | }; |
| | 71 | |
| | 72 | static const double presets[][3][8] = |
| | 73 | { |
| | 74 | [MAGMA] = { |
| | 75 | {-7.5631093e-16, 7.4289183e-13, -2.8525484e-10, 5.4446085e-08, -5.5596238e-06, 3.0569325e-04, -2.3137421e-03, 1.2152095e-02 }, |
| | 76 | { 1.3217636e-15, -1.2214648e-12, 4.4319712e-10, -8.0197993e-08, 7.6598370e-06, -3.6523704e-04, 8.4836670e-03, -2.5536888e-02 }, |
| | 77 | {-1.1446568e-15, 1.0013446e-12, -3.5651575e-10, 6.6775016e-08, -6.7120346e-06, 2.7346619e-04, 4.7969657e-03, 1.1971441e-02 }, |
| | 78 | }, |
| | 79 | [INFERNO] = { |
| | 80 | {-3.9848859e-18, 9.4821649e-14, -6.7371977e-11, 1.8469937e-08, -2.5359307e-06, 1.7959053e-04, 3.9782564e-04, 2.8845935e-04 }, |
| | 81 | { 6.8408539e-16, -6.5499979e-13, 2.4562526e-10, -4.5989298e-08, 4.5723324e-06, -2.2111913e-04, 5.2023164e-03, -1.1226064e-02 }, |
| | 82 | {-2.9921470e-15, 2.5864165e-12, -8.7403799e-10, 1.4713388e-07, -1.2701505e-05, 4.5159935e-04, 3.1087989e-03, 1.9122831e-02 }, |
| | 83 | }, |
| | 84 | [PLASMA] = { |
| | 85 | { 3.6196089e-16, -3.3623041e-13, 1.2324010e-10, -2.2769060e-08, 2.2297792e-06, -1.2567829e-04, 9.9791629e-03, 5.7247918e-02 }, |
| | 86 | { 5.0262888e-16, -5.3193896e-13, 2.2451715e-10, -4.7529623e-08, 5.1374873e-06, -2.3260136e-04, 3.1502825e-03, 1.5362491e-02 }, |
| | 87 | {-1.7782261e-16, 2.2487839e-13, -1.0610236e-10, 2.4112644e-08, -2.6331623e-06, 8.9499751e-05, 2.1386328e-03, 5.3824268e-01 }, |
| | 88 | }, |
| | 89 | [VIRIDIS] = { |
| | 90 | { 9.4850045e-16, -8.6629383e-13, 3.0310944e-10, -5.1340396e-08, 4.6024275e-06, -2.2744239e-04, 4.5559993e-03, 2.5662350e-01 }, |
| | 91 | { 9.6461041e-17, -6.9209477e-14, 1.7625397e-11, -2.0229773e-09, 1.4900110e-07, -1.9315187e-05, 5.8967339e-03, 3.9544827e-03 }, |
| | 92 | { 5.1785449e-16, -3.6663004e-13, 1.0249990e-10, -1.5431998e-08, 1.5007941e-06, -1.2001502e-04, 7.6951526e-03, 3.2292815e-01 }, |
| | 93 | }, |
| | 94 | [TURBO] = { |
| | 95 | {-4.3683890e-15, 3.7020347e-12, -1.1712592e-09, 1.6401790e-07, -8.6842919e-06, -1.8542465e-06, 8.4485325e-03, 1.6267077e-01 }, |
| | 96 | {-4.0011069e-16, 2.7861423e-13, -6.3388921e-11, 5.8872238e-09, -5.4466522e-07, 1.8037114e-05, 1.0599869e-02, 7.6914696e-02 }, |
| | 97 | {-2.8242609e-15, 2.9234108e-12, -1.1726546e-09, 2.2552115e-07, -2.0059387e-05, 5.0595552e-04, 1.7714932e-02, 2.7271836e-01 }, |
| | 98 | }, |
| | 99 | [CIVIDIS] = { |
| | 100 | {-9.5484131e-16, 9.6988184e-13, -4.0058766e-10, 8.5743924e-08, -9.9644797e-06, 5.9197908e-04, -1.0361579e-02, 3.3164429e-02 }, |
| | 101 | { 1.2731941e-17, -9.4238449e-15, 2.2808841e-12, -1.1548296e-10, -2.3888913e-08, 3.8986680e-06, 2.5879330e-03, 1.2769733e-01 }, |
| | 102 | { 4.6004608e-16, -5.0686849e-13, 2.2753449e-10, -5.3074099e-08, 6.7196096e-06, -4.4120020e-04, 1.3435551e-02, 2.8293355e-01 }, |
| | 103 | }, |
| | 104 | }; |
| | 105 | |
| 62 | typedef struct PseudoColorContext { | 106 | typedef struct PseudoColorContext { |
| 63 | const AVClass *class; | 107 | const AVClass *class; |
| | 108 | int preset; |
| 64 | int max; | 109 | int max; |
| 65 | int index; | 110 | int index; |
| 66 | int nb_planes; | 111 | int nb_planes; |
| @@ -90,6 +135,14 @@ static const AVOption pseudocolor_options[] = { · 23 unmodified lines |
| 90 | { "c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS }, | 135 | { "c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS }, |
| 91 | { "c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS }, | 136 | { "c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, {.str="val"}, .flags = FLAGS }, |
| 92 | { "i", "set component as base", OFFSET(index), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, .flags = FLAGS }, | 137 | { "i", "set component as base", OFFSET(index), AV_OPT_TYPE_INT, {.i64=0}, 0, 3, .flags = FLAGS }, |
| | 138 | { "p", "set preset", OFFSET(preset), AV_OPT_TYPE_INT, {.i64=-1},-1,NB_CMAPS-1, .flags = FLAGS, "preset" }, |
| | 139 | { "none", NULL, 0, AV_OPT_TYPE_CONST, {.i64=-1},.flags = FLAGS, "preset" }, |
| | 140 | { "magma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=MAGMA}, .flags = FLAGS, "preset" }, |
| | 141 | { "inferno", NULL, 0, AV_OPT_TYPE_CONST, {.i64=INFERNO}, .flags = FLAGS, "preset" }, |
| | 142 | { "plasma", NULL, 0, AV_OPT_TYPE_CONST, {.i64=PLASMA}, .flags = FLAGS, "preset" }, |
| | 143 | { "viridis", NULL, 0, AV_OPT_TYPE_CONST, {.i64=VIRIDIS}, .flags = FLAGS, "preset" }, |
| | 144 | { "turbo", NULL, 0, AV_OPT_TYPE_CONST, {.i64=TURBO}, .flags = FLAGS, "preset" }, |
| | 145 | { "cividis", NULL, 0, AV_OPT_TYPE_CONST, {.i64=CIVIDIS}, .flags = FLAGS, "preset" }, |
| 93 | { NULL } | 146 | { NULL } |
| 94 | }; | 147 | }; |
| 95 | | 148 | |
| @@ -419,14 +472,39 @@ static void pseudocolor_filter_16_11d(int max, int width, int height, · 323 unmodified lines |
| 419 | } | 472 | } |
| 420 | } | 473 | } |
| 421 | | 474 | |
| | 475 | #define RGB_TO_Y_BT709(r, g, b) \ |
| | 476 | ((0.21260*219.0/255.0) * (r) + (0.71520*219.0/255.0) * (g) + \ |
| | 477 | (0.07220*219.0/255.0) * (b)) |
| | 478 | |
| | 479 | #define RGB_TO_U_BT709(r1, g1, b1, max) \ |
| | 480 | (-(0.11457*224.0/255.0) * r1 - (0.38543*224.0/255.0) * g1 + \ |
| | 481 | (0.50000*224.0/255.0) * b1 + max * 0.5) |
| | 482 | |
| | 483 | #define RGB_TO_V_BT709(r1, g1, b1, max) \ |
| | 484 | ((0.50000*224.0/255.0) * r1 - (0.45415*224.0/255.0) * g1 - \ |
| | 485 | (0.04585*224.0/255.0) * b1 + max * 0.5) |
| | 486 | |
| | 487 | static double poly_eval(const double *const poly, double x) |
| | 488 | { |
| | 489 | double res = 0.; |
| | 490 | |
| | 491 | for (int i = 0; i < 8; i++) { |
| | 492 | res += pow(x, i) * poly[7-i]; |
| | 493 | } |
| | 494 | |
| | 495 | return av_clipd(res, 0., 1.); |
| | 496 | } |
| | 497 | |
| 422 | static int config_input(AVFilterLink *inlink) | 498 | static int config_input(AVFilterLink *inlink) |
| 423 | { | 499 | { |
| 424 | AVFilterContext *ctx = inlink->dst; | 500 | AVFilterContext *ctx = inlink->dst; |
| 425 | PseudoColorContext *s = ctx->priv; | 501 | PseudoColorContext *s = ctx->priv; |
| 426 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); | 502 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
| 427 | int depth, ret, hsub, vsub, color; | 503 | int depth, ret, hsub, vsub, color, factor, rgb; |
| 428 | | 504 | |
| | 505 | rgb = desc->flags & AV_PIX_FMT_FLAG_RGB; |
| 429 | depth = desc->comp[0].depth; | 506 | depth = desc->comp[0].depth; |
| | 507 | factor = 1 << (depth - 8); |
| 430 | s->max = (1 << depth) - 1; | 508 | s->max = (1 << depth) - 1; |
| 431 | s->nb_planes = av_pix_fmt_count_planes(inlink->format); | 509 | s->nb_planes = av_pix_fmt_count_planes(inlink->format); |
| 432 | | 510 | |
| @@ -457,7 +535,7 @@ static int config_input(AVFilterLink *inlink) · 24 unmodified lines |
| 457 | s->var_values[VAR_VMAX] = 240 * (1 << (depth - 8)); | 535 | s->var_values[VAR_VMAX] = 240 * (1 << (depth - 8)); |
| 458 | s->var_values[VAR_AMAX] = s->max; | 536 | s->var_values[VAR_AMAX] = s->max; |
| 459 | | 537 | |
| 460 | for (color = 0; color < s->nb_planes; color++) { | 538 | for (color = 0; color < s->nb_planes && s->preset < 0; color++) { |
| 461 | double res; | 539 | double res; |
| 462 | int val; | 540 | int val; |
| 463 | | 541 | |
| @@ -488,6 +566,33 @@ static int config_input(AVFilterLink *inlink) · 24 unmodified lines |
| 488 | } | 566 | } |
| 489 | } | 567 | } |
| 490 | | 568 | |
| | 569 | if (s->preset >= 0) { |
| | 570 | for (int i = 0; i < 256; i++) { |
| | 571 | for (int j = 0; j < factor; j++) { |
| | 572 | const double lf = j / (double)factor; |
| | 573 | double r, g, b; |
| | 574 | |
| | 575 | g = poly_eval(presets[s->preset][1], i + lf) * s->max; |
| | 576 | b = poly_eval(presets[s->preset][2], i + lf) * s->max; |
| | 577 | r = poly_eval(presets[s->preset][0], i + lf) * s->max; |
| | 578 | |
| | 579 | if (!rgb) { |
| | 580 | double y = RGB_TO_Y_BT709(r, g, b); |
| | 581 | double u = RGB_TO_U_BT709(r, g, b, s->max); |
| | 582 | double v = RGB_TO_V_BT709(r, g, b, s->max); |
| | 583 | |
| | 584 | r = v; |
| | 585 | g = y; |
| | 586 | b = u; |
| | 587 | } |
| | 588 | |
| | 589 | s->lut[0][i*factor+j] = g; |
| | 590 | s->lut[1][i*factor+j] = b; |
| | 591 | s->lut[2][i*factor+j] = r; |
| | 592 | } |
| | 593 | } |
| | 594 | } |
| | 595 | |
| 491 | switch (inlink->format) { | 596 | switch (inlink->format) { |
| 492 | case AV_PIX_FMT_YUV444P: | 597 | case AV_PIX_FMT_YUV444P: |
| 493 | case AV_PIX_FMT_YUVA444P: | 598 | case AV_PIX_FMT_YUVA444P: |