[FFmpeg-devel] [PATCH] lavu: add av_get_color_string() and use it in -colors option

Stefano Sabatini stefano.sabatini-lala
Sat Mar 12 13:36:05 CET 2011


---
 cmdutils.c                   |   13 +++++++++++++
 cmdutils.h                   |    6 ++++++
 cmdutils_common_opts.h       |    1 +
 doc/fftools-common-opts.texi |    3 +++
 libavutil/parseutils.c       |   18 ++++++++++++++++++
 libavutil/parseutils.h       |   14 ++++++++++++++
 6 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/cmdutils.c b/cmdutils.c
index 514ebad..549c673 100644
--- a/cmdutils.c
+++ b/cmdutils.c
@@ -713,6 +713,19 @@ void show_pix_fmts(void)
     }
 }
 
+void show_colors(void)
+{
+    char buf[256];
+    int i;
+
+    /* print header */
+    fprintf(stderr, av_get_color_string(buf, sizeof(buf), -1));
+
+    for (i = 0; av_get_color_string(buf, sizeof(buf), i); i++) {
+        printf("%s", buf);
+    }
+}
+
 int read_yesno(void)
 {
     int c = getchar();
diff --git a/cmdutils.h b/cmdutils.h
index c3d8a42..191ee36 100644
--- a/cmdutils.h
+++ b/cmdutils.h
@@ -195,6 +195,12 @@ void show_formats(void);
 void show_codecs(void);
 
 /**
+ * Print a listing containing all the color names supported by the
+ * program.
+ */
+void show_colors(void);
+
+/**
  * Print a listing containing all the filters supported by the
  * program.
  */
diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h
index da30997..1e3799a 100644
--- a/cmdutils_common_opts.h
+++ b/cmdutils_common_opts.h
@@ -6,6 +6,7 @@
     { "version", OPT_EXIT, {(void*)show_version}, "show version" },
     { "formats"  , OPT_EXIT, {(void*)show_formats  }, "show available formats" },
     { "codecs"   , OPT_EXIT, {(void*)show_codecs   }, "show available codecs" },
+    { "colors"   , OPT_EXIT, {(void*)show_colors   }, "show recognized color names" },
     { "bsfs"     , OPT_EXIT, {(void*)show_bsfs     }, "show available bit stream filters" },
     { "protocols", OPT_EXIT, {(void*)show_protocols}, "show available protocols" },
     { "filters",   OPT_EXIT, {(void*)show_filters  }, "show available filters" },
diff --git a/doc/fftools-common-opts.texi b/doc/fftools-common-opts.texi
index d72ca5c..5b25971 100644
--- a/doc/fftools-common-opts.texi
+++ b/doc/fftools-common-opts.texi
@@ -59,6 +59,9 @@ Codec can handle input truncated at random locations instead of only at frame bo
 @item -bsfs
 Show available bitstream filters.
 
+ at item -colors
+Show recognized color names.
+
 @item -protocols
 Show available protocols.
 
diff --git a/libavutil/parseutils.c b/libavutil/parseutils.c
index d67d31b..e701620 100644
--- a/libavutil/parseutils.c
+++ b/libavutil/parseutils.c
@@ -373,6 +373,24 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
     return 0;
 }
 
+char *av_get_color_string(char *buf, int buf_size, int color_idx)
+{
+    /* print header */
+    if (color_idx < 0) {
+        snprintf(buf, buf_size, "%-32s #RRGGBB\n", "name");
+    } else {
+        ColorEntry *color;
+        if (color_idx >= FF_ARRAY_ELEMS(color_table))
+            return NULL;
+        color = &color_table[color_idx];
+        snprintf(buf, buf_size, "%-32s #%02X%02X%02X\n",
+                 color->name,
+                 color->rgb_color[0], color->rgb_color[1], color->rgb_color[2]);
+    }
+
+    return buf;
+}
+
 /* get a positive number between n_min and n_max, for a maximum length
    of len_max. Return -1 if error. */
 static int date_get_num(const char **pp,
diff --git a/libavutil/parseutils.h b/libavutil/parseutils.h
index c3986af..3e3a34b 100644
--- a/libavutil/parseutils.h
+++ b/libavutil/parseutils.h
@@ -73,6 +73,20 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
                    void *log_ctx);
 
 /**
+ * Print in buf the string corresponding to the color with
+ * number color_idx, or an header if color_idx is negative.
+ *
+ * @param buf the buffer where to write the string
+ * @param buf_size the size of buf
+ * @param color_idx the number of the pixel format to print the
+ * corresponding info string, or a negative value to print the
+ * corresponding header.
+ * @return the printed string or NULL if color_idx doesn't correspond to any
+ * color
+ */
+char *av_get_color_string(char *buf, int buf_size, int color_idx);
+
+/**
  * Parses timestr and returns in *time a corresponding number of
  * microseconds.
  *
-- 
1.7.2.3




More information about the ffmpeg-devel mailing list