[FFmpeg-devel] [PATCH 4/4] avfilter/vf_histogram: add mirrored waveform mode

Marton Balint cus at passwd.hu
Tue Oct 1 21:54:00 CEST 2013


Added parameter to mirror the waveform (high values are shown on top in column mode)

Signed-off-by: Marton Balint <cus at passwd.hu>
---
 doc/filters.texi           |  6 ++++++
 libavfilter/version.h      |  2 +-
 libavfilter/vf_histogram.c | 24 +++++++++++++++++-------
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/doc/filters.texi b/doc/filters.texi
index 93cdad8..3b8c42a 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -4751,6 +4751,12 @@ Default value is @code{10}. Allowed range is [1, 255].
 Set mode for @code{waveform}. Can be either @code{row}, or @code{column}.
 Default is @code{row}.
 
+ at item waveform_mirror
+Set mirroring mode for @code{waveform}. @code{0} means unmirrored, @code{1}
+means mirrored. In mirrored mode, higher values will be represented on the left
+side for @code{row} mode and at the top for @code{column} mode. Default is
+ at code{0} (unmirrored).
+
 @item display_mode
 Set display mode for @code{waveform} and @code{levels}.
 It accepts the following values:
diff --git a/libavfilter/version.h b/libavfilter/version.h
index 4e496a2..07bc23c 100644
--- a/libavfilter/version.h
+++ b/libavfilter/version.h
@@ -30,7 +30,7 @@
 #include "libavutil/avutil.h"
 
 #define LIBAVFILTER_VERSION_MAJOR  3
-#define LIBAVFILTER_VERSION_MINOR  88
+#define LIBAVFILTER_VERSION_MINOR  89
 #define LIBAVFILTER_VERSION_MICRO 100
 
 #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
diff --git a/libavfilter/vf_histogram.c b/libavfilter/vf_histogram.c
index 5fd997b..dc6e4ac 100644
--- a/libavfilter/vf_histogram.c
+++ b/libavfilter/vf_histogram.c
@@ -46,6 +46,7 @@ typedef struct HistogramContext {
     int            scale_height;
     int            step;
     int            waveform_mode;
+    int            waveform_mirror;
     int            display_mode;
     int            levels_mode;
 } HistogramContext;
@@ -65,6 +66,7 @@ static const AVOption histogram_options[] = {
     { "waveform_mode", "set waveform mode", OFFSET(waveform_mode), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "waveform_mode"},
     { "row",   NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "waveform_mode" },
     { "column", NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "waveform_mode" },
+    { "waveform_mirror", "set waveform mirroring", OFFSET(waveform_mirror), AV_OPT_TYPE_INT, {.i64=0}, 0, 1, FLAGS, "waveform_mirror"},
     { "display_mode", "set display mode", OFFSET(display_mode), AV_OPT_TYPE_INT, {.i64=1}, 0, 1, FLAGS, "display_mode"},
     { "parade",  NULL, 0, AV_OPT_TYPE_CONST, {.i64=1}, 0, 0, FLAGS, "display_mode" },
     { "overlay", NULL, 0, AV_OPT_TYPE_CONST, {.i64=0}, 0, 0, FLAGS, "display_mode" },
@@ -175,7 +177,7 @@ static int config_output(AVFilterLink *outlink)
     return 0;
 }
 
-static void gen_waveform(int component, int intensity, int offset, int col_mode, AVFrame *inpicref, AVFrame *outpicref)
+static void gen_waveform(int component, int intensity, int mirror, int offset, int col_mode, AVFrame *inpicref, AVFrame *outpicref)
 {
     int y;
     uint8_t *p;
@@ -188,20 +190,28 @@ static void gen_waveform(int component, int intensity, int offset, int col_mode,
     uint8_t *src_data = inpicref->data[desc->comp[component].plane];
     const int src_linesize = inpicref->linesize[desc->comp[component].plane];
     const int dst_linesize = outpicref->linesize[desc->comp[component].plane];
+    const int dst_signed_linesize = dst_linesize * (mirror == 1 ? -1 : 1);
     uint8_t *dst_data = outpicref->data[desc->comp[component].plane] + (col_mode ? ((offset >> shift_h) * dst_linesize) : (offset >> shift_w));
-    uint8_t * const dst_line = dst_data;
+    uint8_t * const dst_bottom_line = dst_data + dst_linesize * ((256 >> shift_h) - 1);
+    uint8_t * const dst_line = (mirror ? dst_bottom_line : dst_data);
     const uint8_t max = 255 - intensity;
     uint8_t *dst;
 
+    if (!col_mode && mirror)
+        dst_data += 256 >> shift_w;
     for (y = 0; y < src_h; y++) {
         uint8_t * const src_data_end = src_data + src_w;
         dst = dst_line;
         for (p = src_data; p < src_data_end; p++) {
             uint8_t *target;
-            if (col_mode)
-                target = dst++ + dst_linesize * (*p >> shift_h);
-            else
-                target = dst_data + (*p >> shift_w);
+            if (col_mode) {
+                target = dst++ + dst_signed_linesize * (*p >> shift_h);
+            } else {
+                if (mirror)
+                    target = dst_data - (*p >> shift_w);
+                else
+                    target = dst_data + (*p >> shift_w);
+            }
             if (*target <= max)
                 *target += intensity;
             else
@@ -283,7 +293,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
     case MODE_WAVEFORM:
         for (k = 0; k < h->ncomp; k++) {
             int offset = k * 256 * h->display_mode;
-            gen_waveform(k, h->step, offset, h->waveform_mode, in, out);
+            gen_waveform(k, h->step, h->waveform_mirror, offset, h->waveform_mode, in, out);
         }
         break;
     case MODE_COLOR:
-- 
1.8.1.4



More information about the ffmpeg-devel mailing list