Browse code

avfilter/vf_vectorscope: make background opacity customizable

Signed-off-by: Paul B Mahol <onemda@gmail.com>

Paul B Mahol authored on 2016/03/02 08:39:07
Showing 2 changed files
... ...
@@ -12581,6 +12581,9 @@ Draw graticule for white point.
12581 12581
 @item black
12582 12582
 Draw graticule for black point.
12583 12583
 @end table
12584
+
12585
+@item bgopacity, b
12586
+Set background opacity.
12584 12587
 @end table
12585 12588
 
12586 12589
 @anchor{vidstabdetect}
... ...
@@ -43,7 +43,7 @@ typedef struct VectorscopeContext {
43 43
     int mode;
44 44
     int intensity;
45 45
     float fintensity;
46
-    const uint8_t *bg_color;
46
+    uint16_t bg_color[4];
47 47
     int planewidth[4];
48 48
     int planeheight[4];
49 49
     int hsub, vsub;
... ...
@@ -55,6 +55,7 @@ typedef struct VectorscopeContext {
55 55
     int envelope;
56 56
     int graticule;
57 57
     float opacity;
58
+    float bgopacity;
58 59
     int flags;
59 60
     int cs;
60 61
     uint8_t peak[1024][1024];
... ...
@@ -98,6 +99,8 @@ static const AVOption vectorscope_options[] = {
98 98
     { "f",     "set graticule flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64=0}, 0, 3, FLAGS, "flags"},
99 99
     {   "white", "draw white point", 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "flags" },
100 100
     {   "black", "draw black point", 0, AV_OPT_TYPE_CONST, {.i64=2}, 0, 0, FLAGS, "flags" },
101
+    { "bgopacity", "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.3}, 0, 1, FLAGS},
102
+    { "b",         "set background opacity", OFFSET(bgopacity), AV_OPT_TYPE_FLOAT, {.dbl=0.3}, 0, 1, FLAGS},
101 103
     { NULL }
102 104
 };
103 105
 
... ...
@@ -209,9 +212,6 @@ static int query_formats(AVFilterContext *ctx)
209 209
     return 0;
210 210
 }
211 211
 
212
-static const uint8_t black_yuva_color[4] = { 0, 127, 127, 0 };
213
-static const uint8_t black_gbrp_color[4] = { 0, 0, 0, 0 };
214
-
215 212
 static int config_output(AVFilterLink *outlink)
216 213
 {
217 214
     VectorscopeContext *s = outlink->src->priv;
... ...
@@ -371,12 +371,10 @@ static void vectorscope16(VectorscopeContext *s, AVFrame *in, AVFrame *out, int
371 371
     int i, j, k;
372 372
 
373 373
     for (k = 0; k < 4 && dst[k]; k++) {
374
-        const int mult = s->mult;
375
-
376 374
         for (i = 0; i < out->height ; i++)
377 375
             for (j = 0; j < out->width; j++)
378 376
                 AV_WN16(out->data[k] + i * out->linesize[k] + j * 2,
379
-                        (s->mode == COLOR || s->mode == COLOR5) && k == s->pd ? 0 : s->bg_color[k] * mult);
377
+                        (s->mode == COLOR || s->mode == COLOR5) && k == s->pd ? 0 : s->bg_color[k]);
380 378
     }
381 379
 
382 380
     switch (s->mode) {
... ...
@@ -765,6 +763,7 @@ static void none_graticule(VectorscopeContext *s, AVFrame *out, int X, int Y, in
765 765
 
766 766
 static void color_graticule16(VectorscopeContext *s, AVFrame *out, int X, int Y, int D, int P)
767 767
 {
768
+    const int max = s->size - 1;
768 769
     const float o = s->opacity;
769 770
     int i;
770 771
 
... ...
@@ -776,6 +775,8 @@ static void color_graticule16(VectorscopeContext *s, AVFrame *out, int X, int Y,
776 776
         draw_dots16((uint16_t *)(out->data[D] + y * out->linesize[D] + x * 2), out->linesize[D] / 2, d, o);
777 777
         draw_dots16((uint16_t *)(out->data[X] + y * out->linesize[X] + x * 2), out->linesize[X] / 2, x, o);
778 778
         draw_dots16((uint16_t *)(out->data[Y] + y * out->linesize[Y] + x * 2), out->linesize[Y] / 2, y, o);
779
+        if (out->data[3])
780
+            draw_dots16((uint16_t *)(out->data[3] + y * out->linesize[3] + x * 2), out->linesize[3] / 2, max, o);
779 781
     }
780 782
 
781 783
     if (s->flags & 1) {
... ...
@@ -786,6 +787,8 @@ static void color_graticule16(VectorscopeContext *s, AVFrame *out, int X, int Y,
786 786
         draw_dots16((uint16_t *)(out->data[D] + y * out->linesize[D] + x * 2), out->linesize[D] / 2, d, o);
787 787
         draw_dots16((uint16_t *)(out->data[X] + y * out->linesize[X] + x * 2), out->linesize[X] / 2, x, o);
788 788
         draw_dots16((uint16_t *)(out->data[Y] + y * out->linesize[Y] + x * 2), out->linesize[Y] / 2, y, o);
789
+        if (out->data[3])
790
+            draw_dots16((uint16_t *)(out->data[3] + y * out->linesize[3] + x * 2), out->linesize[3] / 2, max, o);
789 791
     }
790 792
 
791 793
     if (s->flags & 2) {
... ...
@@ -796,6 +799,8 @@ static void color_graticule16(VectorscopeContext *s, AVFrame *out, int X, int Y,
796 796
         draw_dots16((uint16_t *)(out->data[D] + y * out->linesize[D] + x * 2), out->linesize[D] / 2, d, o);
797 797
         draw_dots16((uint16_t *)(out->data[X] + y * out->linesize[X] + x * 2), out->linesize[X] / 2, x, o);
798 798
         draw_dots16((uint16_t *)(out->data[Y] + y * out->linesize[Y] + x * 2), out->linesize[Y] / 2, y, o);
799
+        if (out->data[3])
800
+            draw_dots16((uint16_t *)(out->data[3] + y * out->linesize[3] + x * 2), out->linesize[3] / 2, max, o);
799 801
     }
800 802
 }
801 803
 
... ...
@@ -812,6 +817,8 @@ static void color_graticule(VectorscopeContext *s, AVFrame *out, int X, int Y, i
812 812
         draw_dots(out->data[D] + y * out->linesize[D] + x, out->linesize[D], d, o);
813 813
         draw_dots(out->data[X] + y * out->linesize[X] + x, out->linesize[X], x, o);
814 814
         draw_dots(out->data[Y] + y * out->linesize[Y] + x, out->linesize[Y], y, o);
815
+        if (out->data[3])
816
+            draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o);
815 817
     }
816 818
 
817 819
     if (s->flags & 1) {
... ...
@@ -822,6 +829,8 @@ static void color_graticule(VectorscopeContext *s, AVFrame *out, int X, int Y, i
822 822
         draw_dots(out->data[D] + y * out->linesize[D] + x, out->linesize[D], d, o);
823 823
         draw_dots(out->data[X] + y * out->linesize[X] + x, out->linesize[X], x, o);
824 824
         draw_dots(out->data[Y] + y * out->linesize[Y] + x, out->linesize[Y], y, o);
825
+        if (out->data[3])
826
+            draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o);
825 827
     }
826 828
 
827 829
     if (s->flags & 2) {
... ...
@@ -832,11 +841,14 @@ static void color_graticule(VectorscopeContext *s, AVFrame *out, int X, int Y, i
832 832
         draw_dots(out->data[D] + y * out->linesize[D] + x, out->linesize[D], d, o);
833 833
         draw_dots(out->data[X] + y * out->linesize[X] + x, out->linesize[X], x, o);
834 834
         draw_dots(out->data[Y] + y * out->linesize[Y] + x, out->linesize[Y], y, o);
835
+        if (out->data[3])
836
+            draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o);
835 837
     }
836 838
 }
837 839
 
838 840
 static void green_graticule16(VectorscopeContext *s, AVFrame *out, int X, int Y, int D, int P)
839 841
 {
842
+    const int max = s->size - 1;
840 843
     const float o = s->opacity;
841 844
     const int m = s->mult;
842 845
     int i;
... ...
@@ -848,6 +860,8 @@ static void green_graticule16(VectorscopeContext *s, AVFrame *out, int X, int Y,
848 848
         draw_dots16((uint16_t *)(out->data[D] + y * out->linesize[D] + x * 2), out->linesize[D] / 2, 128 * m, o);
849 849
         draw_dots16((uint16_t *)(out->data[X] + y * out->linesize[X] + x * 2), out->linesize[X] / 2, 0, o);
850 850
         draw_dots16((uint16_t *)(out->data[Y] + y * out->linesize[Y] + x * 2), out->linesize[Y] / 2, 0, o);
851
+        if (out->data[3])
852
+            draw_dots16((uint16_t *)(out->data[3] + y * out->linesize[3] + x * 2), out->linesize[3] / 2, max, o);
851 853
     }
852 854
 
853 855
     if (s->flags & 1) {
... ...
@@ -857,6 +871,8 @@ static void green_graticule16(VectorscopeContext *s, AVFrame *out, int X, int Y,
857 857
         draw_dots16((uint16_t *)(out->data[D] + y * out->linesize[D] + x * 2), out->linesize[D] / 2, 128 * m, o);
858 858
         draw_dots16((uint16_t *)(out->data[X] + y * out->linesize[X] + x * 2), out->linesize[X] / 2, 0, o);
859 859
         draw_dots16((uint16_t *)(out->data[Y] + y * out->linesize[Y] + x * 2), out->linesize[Y] / 2, 0, o);
860
+        if (out->data[3])
861
+            draw_dots16((uint16_t *)(out->data[3] + y * out->linesize[3] + x * 2), out->linesize[3] / 2, max, o);
860 862
     }
861 863
 
862 864
     if (s->flags & 2) {
... ...
@@ -866,6 +882,8 @@ static void green_graticule16(VectorscopeContext *s, AVFrame *out, int X, int Y,
866 866
         draw_dots16((uint16_t *)(out->data[D] + y * out->linesize[D] + x * 2), out->linesize[D] / 2, 128 * m, o);
867 867
         draw_dots16((uint16_t *)(out->data[X] + y * out->linesize[X] + x * 2), out->linesize[X] / 2, 0, o);
868 868
         draw_dots16((uint16_t *)(out->data[Y] + y * out->linesize[Y] + x * 2), out->linesize[Y] / 2, 0, o);
869
+        if (out->data[3])
870
+            draw_dots16((uint16_t *)(out->data[3] + y * out->linesize[3] + x * 2), out->linesize[3] / 2, max, o);
869 871
     }
870 872
 }
871 873
 
... ...
@@ -881,6 +899,8 @@ static void green_graticule(VectorscopeContext *s, AVFrame *out, int X, int Y, i
881 881
         draw_dots(out->data[D] + y * out->linesize[D] + x, out->linesize[D], 128, o);
882 882
         draw_dots(out->data[X] + y * out->linesize[X] + x, out->linesize[X], 0, o);
883 883
         draw_dots(out->data[Y] + y * out->linesize[Y] + x, out->linesize[Y], 0, o);
884
+        if (out->data[3])
885
+            draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o);
884 886
     }
885 887
 
886 888
     if (s->flags & 1) {
... ...
@@ -890,6 +910,8 @@ static void green_graticule(VectorscopeContext *s, AVFrame *out, int X, int Y, i
890 890
         draw_dots(out->data[D] + y * out->linesize[D] + x, out->linesize[D], 128, o);
891 891
         draw_dots(out->data[X] + y * out->linesize[X] + x, out->linesize[X], 0, o);
892 892
         draw_dots(out->data[Y] + y * out->linesize[Y] + x, out->linesize[Y], 0, o);
893
+        if (out->data[3])
894
+            draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o);
893 895
     }
894 896
 
895 897
     if (s->flags & 2) {
... ...
@@ -899,6 +921,8 @@ static void green_graticule(VectorscopeContext *s, AVFrame *out, int X, int Y, i
899 899
         draw_dots(out->data[D] + y * out->linesize[D] + x, out->linesize[D], 128, o);
900 900
         draw_dots(out->data[X] + y * out->linesize[X] + x, out->linesize[X], 0, o);
901 901
         draw_dots(out->data[Y] + y * out->linesize[Y] + x, out->linesize[Y], 0, o);
902
+        if (out->data[3])
903
+            draw_dots(out->data[3] + y * out->linesize[3] + x, out->linesize[3], 255, o);
902 904
     }
903 905
 }
904 906
 
... ...
@@ -973,15 +997,21 @@ static int config_input(AVFilterLink *inlink)
973 973
             s->graticulef = color_graticule16;
974 974
     }
975 975
 
976
+    s->bg_color[3] = s->bgopacity * (s->size - 1);
977
+
976 978
     switch (inlink->format) {
977 979
     case AV_PIX_FMT_GBRP10:
978 980
     case AV_PIX_FMT_GBRP9:
979 981
     case AV_PIX_FMT_GBRAP:
980 982
     case AV_PIX_FMT_GBRP:
981
-        s->bg_color = black_gbrp_color;
983
+        s->bg_color[0] = 0;
984
+        s->bg_color[1] = 0;
985
+        s->bg_color[2] = 0;
982 986
         break;
983 987
     default:
984
-        s->bg_color = black_yuva_color;
988
+        s->bg_color[0] = 0;
989
+        s->bg_color[1] = s->size / 2 - 1;
990
+        s->bg_color[2] = s->size / 2 - 1;
985 991
     }
986 992
 
987 993
     s->hsub = desc->log2_chroma_w;