[SCM] libav/experimental: improve av_parse_color() to support html formatting

siretart at users.alioth.debian.org siretart at users.alioth.debian.org
Sun Jun 30 17:19:00 UTC 2013


The following commit has been merged in the experimental branch:
commit 521b8607488966a236cee5268a8797f3ed37e1ed
Author: Aurelien Jacobs <aurel at gnuage.org>
Date:   Sat Nov 13 13:49:58 2010 +0000

    improve av_parse_color() to support html formatting
    
    Originally committed as revision 25743 to svn://svn.ffmpeg.org/ffmpeg/trunk

diff --git a/libavfilter/parseutils.c b/libavfilter/parseutils.c
index c78b64a..ebb0061 100644
--- a/libavfilter/parseutils.c
+++ b/libavfilter/parseutils.c
@@ -187,9 +187,17 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, void *log_ctx)
 {
     char *tail, color_string2[128];
     const ColorEntry *entry;
-    av_strlcpy(color_string2, color_string, sizeof(color_string2));
+    int len, hex_offset = 0;
+
+    if (color_string[0] == '#') {
+        hex_offset = 1;
+    } else if (!strncmp(color_string, "0x", 2))
+        hex_offset = 2;
+
+    av_strlcpy(color_string2, color_string + hex_offset, sizeof(color_string2));
     if ((tail = strchr(color_string2, ALPHA_SEP)))
         *tail++ = 0;
+    len = strlen(color_string2);
     rgba_color[3] = 255;
 
     if (!strcasecmp(color_string2, "random") || !strcasecmp(color_string2, "bikeshed")) {
@@ -198,16 +206,16 @@ int av_parse_color(uint8_t *rgba_color, const char *color_string, void *log_ctx)
         rgba_color[1] = rgba >> 16;
         rgba_color[2] = rgba >> 8;
         rgba_color[3] = rgba;
-    } else if (!strncmp(color_string2, "0x", 2)) {
+    } else if (hex_offset ||
+               strspn(color_string2, "0123456789ABCDEFabcdef") == len) {
         char *tail;
-        int len = strlen(color_string2);
         unsigned int rgba = strtoul(color_string2, &tail, 16);
 
-        if (*tail || (len != 8 && len != 10)) {
+        if (*tail || (len != 6 && len != 8)) {
             av_log(log_ctx, AV_LOG_ERROR, "Invalid 0xRRGGBB[AA] color string: '%s'\n", color_string2);
             return AVERROR(EINVAL);
         }
-        if (len == 10) {
+        if (len == 8) {
             rgba_color[3] = rgba;
             rgba >>= 8;
         }
@@ -276,6 +284,10 @@ int main(void)
             "0xffXXee",
             "0xfoobar",
             "0xffffeeeeeeee",
+            "#ff0000",
+            "#ffXX00",
+            "ff0000",
+            "ffXX00",
             "red at foo",
             "random at 10",
             "0xff0000 at 1.0",
diff --git a/libavfilter/parseutils.h b/libavfilter/parseutils.h
index e1bd552..a56750c 100644
--- a/libavfilter/parseutils.h
+++ b/libavfilter/parseutils.h
@@ -31,7 +31,7 @@
  * Put the RGBA values that correspond to color_string in rgba_color.
  *
  * @param color_string a string specifying a color. It can be the name of
- * a color (case insensitive match) or a 0xRRGGBB[AA] sequence,
+ * a color (case insensitive match) or a [0x|#]RRGGBB[AA] sequence,
  * possibly followed by "@" and a string representing the alpha
  * component.
  * The alpha component may be a string composed by "0x" followed by an

-- 
Libav/FFmpeg packaging



More information about the pkg-multimedia-commits mailing list