Browse code

avfilter/vf_histogram: add support for subsampled planar yuv modes in waveform mode

Signed-off-by: Marton Balint <cus@passwd.hu>

Marton Balint authored on 2013/10/02 05:39:03
Showing 2 changed files
... ...
@@ -87,6 +87,18 @@ static const enum AVPixelFormat levels_pix_fmts[] = {
87 87
     AV_PIX_FMT_GRAY8, AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_NONE
88 88
 };
89 89
 
90
+static const enum AVPixelFormat waveform_pix_fmts[] = {
91
+     AV_PIX_FMT_GBRP,     AV_PIX_FMT_GBRAP,
92
+     AV_PIX_FMT_YUV422P,  AV_PIX_FMT_YUV420P,
93
+     AV_PIX_FMT_YUV444P,  AV_PIX_FMT_YUV440P,
94
+     AV_PIX_FMT_YUV411P,  AV_PIX_FMT_YUV410P,
95
+     AV_PIX_FMT_YUVJ440P, AV_PIX_FMT_YUVJ411P, AV_PIX_FMT_YUVJ420P,
96
+     AV_PIX_FMT_YUVJ422P, AV_PIX_FMT_YUVJ444P,
97
+     AV_PIX_FMT_YUVA444P, AV_PIX_FMT_YUVA422P, AV_PIX_FMT_YUVA420P,
98
+     AV_PIX_FMT_GRAY8,
99
+     AV_PIX_FMT_NONE
100
+};
101
+
90 102
 static int query_formats(AVFilterContext *ctx)
91 103
 {
92 104
     HistogramContext *h = ctx->priv;
... ...
@@ -94,6 +106,8 @@ static int query_formats(AVFilterContext *ctx)
94 94
 
95 95
     switch (h->mode) {
96 96
     case MODE_WAVEFORM:
97
+        pix_fmts = waveform_pix_fmts;
98
+        break;
97 99
     case MODE_LEVELS:
98 100
         pix_fmts = levels_pix_fmts;
99 101
         break;
... ...
@@ -175,8 +189,11 @@ static void gen_waveform(HistogramContext *h, AVFrame *inpicref, AVFrame *outpic
175 175
     uint8_t *dst_data = outpicref->data[plane] + (col_mode ? offset * dst_linesize : offset);
176 176
     uint8_t * const dst_line = dst_data;
177 177
     const uint8_t max = 255 - intensity;
178
-    const int src_h = inpicref->height;
179
-    const int src_w = inpicref->width;
178
+    const int is_chroma = (component == 1 || component == 2);
179
+    const int shift_w = (is_chroma ? h->desc->log2_chroma_w : 0);
180
+    const int shift_h = (is_chroma ? h->desc->log2_chroma_h : 0);
181
+    const int src_h = FF_CEIL_RSHIFT(inpicref->height, shift_h);
182
+    const int src_w = FF_CEIL_RSHIFT(inpicref->width, shift_w);
180 183
     uint8_t *dst, *p;
181 184
     int y;
182 185
 
... ...
@@ -186,9 +203,9 @@ static void gen_waveform(HistogramContext *h, AVFrame *inpicref, AVFrame *outpic
186 186
         for (p = src_data; p < src_data_end; p++) {
187 187
             uint8_t *target;
188 188
             if (col_mode)
189
-                target = dst++ + dst_linesize * *p;
189
+                target = dst++ + dst_linesize * (*p >> shift_h);
190 190
             else
191
-                target = dst_data + *p;
191
+                target = dst_data + (*p >> shift_w);
192 192
             if (*target <= max)
193 193
                 *target += intensity;
194 194
             else
... ...
@@ -218,9 +235,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
218 218
 
219 219
     out->pts = in->pts;
220 220
 
221
-    for (k = 0; k < h->ncomp; k++)
222
-        for (i = 0; i < outlink->h; i++)
223
-            memset(out->data[k] + i * out->linesize[k], h->bg_color[k], outlink->w);
221
+    for (k = 0; k < h->ncomp; k++) {
222
+        int is_chroma = (k == 1 || k == 2);
223
+        int dst_h = FF_CEIL_RSHIFT(outlink->h, (is_chroma ? h->desc->log2_chroma_h : 0));
224
+        int dst_w = FF_CEIL_RSHIFT(outlink->w, (is_chroma ? h->desc->log2_chroma_w : 0));
225
+        for (i = 0; i < dst_h ; i++)
226
+            memset(out->data[h->desc->comp[k].plane] +
227
+                   i * out->linesize[h->desc->comp[k].plane],
228
+                   h->bg_color[k], dst_w);
229
+    }
224 230
 
225 231
     switch (h->mode) {
226 232
     case MODE_LEVELS:
... ...
@@ -57,7 +57,7 @@ FATE_FILTER_VSYNTH-$(CONFIG_HISTOGRAM_FILTER) += fate-filter-histogram-levels
57 57
 fate-filter-histogram-levels: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf histogram -flags +bitexact -sws_flags +accurate_rnd+bitexact
58 58
 
59 59
 FATE_FILTER_VSYNTH-$(CONFIG_HISTOGRAM_FILTER) += fate-filter-histogram-waveform
60
-fate-filter-histogram-waveform: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf histogram=mode=waveform -flags +bitexact -sws_flags +accurate_rnd+bitexact
60
+fate-filter-histogram-waveform: CMD = framecrc -c:v pgmyuv -i $(SRC) -vf format=yuv444p,histogram=mode=waveform -flags +bitexact -sws_flags +accurate_rnd+bitexact
61 61
 
62 62
 FATE_FILTER_VSYNTH-$(CONFIG_OVERLAY_FILTER) += fate-filter-overlay
63 63
 fate-filter-overlay: tests/data/filtergraphs/overlay