Browse code

avfilter/avf_showcqt: add bar_t option

custom bargraph transparency

Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>

Muhammad Faiz authored on 2016/10/28 14:55:04
Showing 3 changed files
... ...
@@ -16835,6 +16835,10 @@ Acceptable range is @code{[1, 7]}.
16835 16835
 Specify the bargraph gamma. Default value is @code{1}. Acceptable range is
16836 16836
 @code{[1, 7]}.
16837 16837
 
16838
+@item bar_t
16839
+Specify the bargraph transparency level. Lower value makes the bargraph sharper.
16840
+Default value is @code{1}. Acceptable range is @code{[0, 1]}.
16841
+
16838 16842
 @item timeclamp, tc
16839 16843
 Specify the transform timeclamp. At low frequency, there is trade-off between
16840 16844
 accuracy in time domain and frequency domain. If timeclamp is lower,
... ...
@@ -75,6 +75,7 @@ static const AVOption showcqt_options[] = {
75 75
     { "gamma",    "set sonogram gamma", OFFSET(sono_g),     AV_OPT_TYPE_FLOAT, { .dbl = 3.0 },            1.0, 7.0,      FLAGS },
76 76
     { "bar_g",    "set bargraph gamma", OFFSET(bar_g),      AV_OPT_TYPE_FLOAT, { .dbl = 1.0 },            1.0, 7.0,      FLAGS },
77 77
     { "gamma2",   "set bargraph gamma", OFFSET(bar_g),      AV_OPT_TYPE_FLOAT, { .dbl = 1.0 },            1.0, 7.0,      FLAGS },
78
+    { "bar_t",  "set bar transparency", OFFSET(bar_t),      AV_OPT_TYPE_FLOAT, { .dbl = 1.0 },            0.0, 1.0,      FLAGS },
78 79
     { "timeclamp",     "set timeclamp", OFFSET(timeclamp), AV_OPT_TYPE_DOUBLE, { .dbl = 0.17 },           0.1, 1.0,      FLAGS },
79 80
     { "tc",            "set timeclamp", OFFSET(timeclamp), AV_OPT_TYPE_DOUBLE, { .dbl = 0.17 },           0.1, 1.0,      FLAGS },
80 81
     { "basefreq", "set base frequency", OFFSET(basefreq),  AV_OPT_TYPE_DOUBLE, { .dbl = BASEFREQ },      10.0, 100000.0, FLAGS },
... ...
@@ -752,10 +753,10 @@ static void yuv_from_cqt(ColorFloat *c, const FFTComplex *v, float gamma, int le
752 752
 }
753 753
 
754 754
 static void draw_bar_rgb(AVFrame *out, const float *h, const float *rcp_h,
755
-                         const ColorFloat *c, int bar_h)
755
+                         const ColorFloat *c, int bar_h, float bar_t)
756 756
 {
757 757
     int x, y, w = out->width;
758
-    float mul, ht, rcp_bar_h = 1.0f / bar_h;
758
+    float mul, ht, rcp_bar_h = 1.0f / bar_h, rcp_bar_t = 1.0f / bar_t;
759 759
     uint8_t *v = out->data[0], *lp;
760 760
     int ls = out->linesize[0];
761 761
 
... ...
@@ -769,6 +770,7 @@ static void draw_bar_rgb(AVFrame *out, const float *h, const float *rcp_h,
769 769
                 *lp++ = 0;
770 770
             } else {
771 771
                 mul = (h[x] - ht) * rcp_h[x];
772
+                mul = (mul < bar_t) ? (mul * rcp_bar_t) : 1.0f;
772 773
                 *lp++ = lrintf(mul * c[x].rgb.r);
773 774
                 *lp++ = lrintf(mul * c[x].rgb.g);
774 775
                 *lp++ = lrintf(mul * c[x].rgb.b);
... ...
@@ -785,6 +787,7 @@ do { \
785 785
         *lpv++ = 128; \
786 786
     } else { \
787 787
         mul = (h[x] - ht) * rcp_h[x]; \
788
+        mul = (mul < bar_t) ? (mul * rcp_bar_t) : 1.0f; \
788 789
         *lpy++ = lrintf(mul * c[x].yuv.y + 16.0f); \
789 790
         *lpu++ = lrintf(mul * c[x].yuv.u + 128.0f); \
790 791
         *lpv++ = lrintf(mul * c[x].yuv.v + 128.0f); \
... ...
@@ -797,15 +800,16 @@ do { \
797 797
         *lpy++ = 16; \
798 798
     } else { \
799 799
         mul = (h[x] - ht) * rcp_h[x]; \
800
+        mul = (mul < bar_t) ? (mul * rcp_bar_t) : 1.0f; \
800 801
         *lpy++ = lrintf(mul * c[x].yuv.y + 16.0f); \
801 802
     } \
802 803
 } while (0)
803 804
 
804 805
 static void draw_bar_yuv(AVFrame *out, const float *h, const float *rcp_h,
805
-                         const ColorFloat *c, int bar_h)
806
+                         const ColorFloat *c, int bar_h, float bar_t)
806 807
 {
807 808
     int x, y, yh, w = out->width;
808
-    float mul, ht, rcp_bar_h = 1.0f / bar_h;
809
+    float mul, ht, rcp_bar_h = 1.0f / bar_h, rcp_bar_t = 1.0f / bar_t;
809 810
     uint8_t *vy = out->data[0], *vu = out->data[1], *vv = out->data[2];
810 811
     uint8_t *lpy, *lpu, *lpv;
811 812
     int lsy = out->linesize[0], lsu = out->linesize[1], lsv = out->linesize[2];
... ...
@@ -1160,7 +1164,7 @@ static int plot_cqt(AVFilterContext *ctx, AVFrame **frameout)
1160 1160
         UPDATE_TIME(s->alloc_time);
1161 1161
 
1162 1162
         if (s->bar_h) {
1163
-            s->draw_bar(out, s->h_buf, s->rcp_h_buf, s->c_buf, s->bar_h);
1163
+            s->draw_bar(out, s->h_buf, s->rcp_h_buf, s->c_buf, s->bar_h, s->bar_t);
1164 1164
             UPDATE_TIME(s->bar_time);
1165 1165
         }
1166 1166
 
... ...
@@ -78,7 +78,7 @@ typedef struct {
78 78
                                     int len, int fft_len);
79 79
     void                (*permute_coeffs)(float *v, int len);
80 80
     void                (*draw_bar)(AVFrame *out, const float *h, const float *rcp_h,
81
-                                    const ColorFloat *c, int bar_h);
81
+                                    const ColorFloat *c, int bar_h, float bar_t);
82 82
     void                (*draw_axis)(AVFrame *out, AVFrame *axis, const ColorFloat *c, int off);
83 83
     void                (*draw_sono)(AVFrame *out, AVFrame *sono, int off, int idx);
84 84
     void                (*update_sono)(AVFrame *sono, const ColorFloat *c, int idx);
... ...
@@ -102,6 +102,7 @@ typedef struct {
102 102
     char                *bar_v;
103 103
     float               sono_g;
104 104
     float               bar_g;
105
+    float               bar_t;
105 106
     double              timeclamp;
106 107
     double              basefreq;
107 108
     double              endfreq;