diff options
author | Aurelien Jacobs <aurel@gnuage.org> | 2010-11-18 01:58:28 +0300 |
---|---|---|
committer | Aurelien Jacobs <aurel@gnuage.org> | 2010-11-18 01:58:28 +0300 |
commit | 0985e1a3ca52436741b95907d9d1c90a42f839b1 (patch) | |
tree | 7ffe8a500cf8e24d3a978c69d39b92c5163bb070 | |
parent | 909865fdbe7225d6e9b4eb5da15028104a4a06da (diff) |
move the av_parse_color() function from libavfilter to libavcore
Originally committed as revision 25761 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | doc/APIchanges | 3 | ||||
-rw-r--r-- | libavcore/avcore.h | 4 | ||||
-rw-r--r-- | libavcore/parseutils.c | 285 | ||||
-rw-r--r-- | libavcore/parseutils.h | 22 | ||||
-rw-r--r-- | libavfilter/Makefile | 1 | ||||
-rw-r--r-- | libavfilter/graphparser.c | 1 | ||||
-rw-r--r-- | libavfilter/parseutils.c | 323 | ||||
-rw-r--r-- | libavfilter/parseutils.h | 52 | ||||
-rw-r--r-- | libavfilter/vf_drawbox.c | 2 | ||||
-rw-r--r-- | libavfilter/vf_frei0r.c | 2 | ||||
-rw-r--r-- | libavfilter/vf_pad.c | 1 |
11 files changed, 314 insertions, 382 deletions
diff --git a/doc/APIchanges b/doc/APIchanges index b6806f8b5e..a506299b2d 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2009-03-08 API changes, most recent first: +2010-11-17 - r25761 - lavcore 0.13.0 - parseutils.h + Add av_parse_color() declared in libavcore/parseutils.h. + 2010-11-13 - r25745 - lavc 52.95.0 - AVCodecContext Add AVCodecContext.subtitle_header and AVCodecContext.subtitle_header_size fields. diff --git a/libavcore/avcore.h b/libavcore/avcore.h index 312cd865d3..a4c36ba5f9 100644 --- a/libavcore/avcore.h +++ b/libavcore/avcore.h @@ -27,8 +27,8 @@ #include "libavutil/avutil.h" #define LIBAVCORE_VERSION_MAJOR 0 -#define LIBAVCORE_VERSION_MINOR 12 -#define LIBAVCORE_VERSION_MICRO 1 +#define LIBAVCORE_VERSION_MINOR 13 +#define LIBAVCORE_VERSION_MICRO 0 #define LIBAVCORE_VERSION_INT AV_VERSION_INT(LIBAVCORE_VERSION_MAJOR, \ LIBAVCORE_VERSION_MINOR, \ diff --git a/libavcore/parseutils.c b/libavcore/parseutils.c index cdf8b56142..abf0422ff4 100644 --- a/libavcore/parseutils.c +++ b/libavcore/parseutils.c @@ -21,9 +21,12 @@ * misc parsing utilities for libavcore */ +#include <strings.h> #include "parseutils.h" #include "libavutil/avutil.h" #include "libavutil/eval.h" +#include "libavutil/avstring.h" +#include "libavutil/random_seed.h" typedef struct { const char *abbr; @@ -137,6 +140,237 @@ int av_parse_video_rate(AVRational *rate, const char *arg) return 0; } +typedef struct { + const char *name; ///< a string representing the name of the color + uint8_t rgb_color[3]; ///< RGB values for the color +} ColorEntry; + +static ColorEntry color_table[] = { + { "AliceBlue", { 0xF0, 0xF8, 0xFF } }, + { "AntiqueWhite", { 0xFA, 0xEB, 0xD7 } }, + { "Aqua", { 0x00, 0xFF, 0xFF } }, + { "Aquamarine", { 0x7F, 0xFF, 0xD4 } }, + { "Azure", { 0xF0, 0xFF, 0xFF } }, + { "Beige", { 0xF5, 0xF5, 0xDC } }, + { "Bisque", { 0xFF, 0xE4, 0xC4 } }, + { "Black", { 0x00, 0x00, 0x00 } }, + { "BlanchedAlmond", { 0xFF, 0xEB, 0xCD } }, + { "Blue", { 0x00, 0x00, 0xFF } }, + { "BlueViolet", { 0x8A, 0x2B, 0xE2 } }, + { "Brown", { 0xA5, 0x2A, 0x2A } }, + { "BurlyWood", { 0xDE, 0xB8, 0x87 } }, + { "CadetBlue", { 0x5F, 0x9E, 0xA0 } }, + { "Chartreuse", { 0x7F, 0xFF, 0x00 } }, + { "Chocolate", { 0xD2, 0x69, 0x1E } }, + { "Coral", { 0xFF, 0x7F, 0x50 } }, + { "CornflowerBlue", { 0x64, 0x95, 0xED } }, + { "Cornsilk", { 0xFF, 0xF8, 0xDC } }, + { "Crimson", { 0xDC, 0x14, 0x3C } }, + { "Cyan", { 0x00, 0xFF, 0xFF } }, + { "DarkBlue", { 0x00, 0x00, 0x8B } }, + { "DarkCyan", { 0x00, 0x8B, 0x8B } }, + { "DarkGoldenRod", { 0xB8, 0x86, 0x0B } }, + { "DarkGray", { 0xA9, 0xA9, 0xA9 } }, + { "DarkGreen", { 0x00, 0x64, 0x00 } }, + { "DarkKhaki", { 0xBD, 0xB7, 0x6B } }, + { "DarkMagenta", { 0x8B, 0x00, 0x8B } }, + { "DarkOliveGreen", { 0x55, 0x6B, 0x2F } }, + { "Darkorange", { 0xFF, 0x8C, 0x00 } }, + { "DarkOrchid", { 0x99, 0x32, 0xCC } }, + { "DarkRed", { 0x8B, 0x00, 0x00 } }, + { "DarkSalmon", { 0xE9, 0x96, 0x7A } }, + { "DarkSeaGreen", { 0x8F, 0xBC, 0x8F } }, + { "DarkSlateBlue", { 0x48, 0x3D, 0x8B } }, + { "DarkSlateGray", { 0x2F, 0x4F, 0x4F } }, + { "DarkTurquoise", { 0x00, 0xCE, 0xD1 } }, + { "DarkViolet", { 0x94, 0x00, 0xD3 } }, + { "DeepPink", { 0xFF, 0x14, 0x93 } }, + { "DeepSkyBlue", { 0x00, 0xBF, 0xFF } }, + { "DimGray", { 0x69, 0x69, 0x69 } }, + { "DodgerBlue", { 0x1E, 0x90, 0xFF } }, + { "FireBrick", { 0xB2, 0x22, 0x22 } }, + { "FloralWhite", { 0xFF, 0xFA, 0xF0 } }, + { "ForestGreen", { 0x22, 0x8B, 0x22 } }, + { "Fuchsia", { 0xFF, 0x00, 0xFF } }, + { "Gainsboro", { 0xDC, 0xDC, 0xDC } }, + { "GhostWhite", { 0xF8, 0xF8, 0xFF } }, + { "Gold", { 0xFF, 0xD7, 0x00 } }, + { "GoldenRod", { 0xDA, 0xA5, 0x20 } }, + { "Gray", { 0x80, 0x80, 0x80 } }, + { "Green", { 0x00, 0x80, 0x00 } }, + { "GreenYellow", { 0xAD, 0xFF, 0x2F } }, + { "HoneyDew", { 0xF0, 0xFF, 0xF0 } }, + { "HotPink", { 0xFF, 0x69, 0xB4 } }, + { "IndianRed", { 0xCD, 0x5C, 0x5C } }, + { "Indigo", { 0x4B, 0x00, 0x82 } }, + { "Ivory", { 0xFF, 0xFF, 0xF0 } }, + { "Khaki", { 0xF0, 0xE6, 0x8C } }, + { "Lavender", { 0xE6, 0xE6, 0xFA } }, + { "LavenderBlush", { 0xFF, 0xF0, 0xF5 } }, + { "LawnGreen", { 0x7C, 0xFC, 0x00 } }, + { "LemonChiffon", { 0xFF, 0xFA, 0xCD } }, + { "LightBlue", { 0xAD, 0xD8, 0xE6 } }, + { "LightCoral", { 0xF0, 0x80, 0x80 } }, + { "LightCyan", { 0xE0, 0xFF, 0xFF } }, + { "LightGoldenRodYellow", { 0xFA, 0xFA, 0xD2 } }, + { "LightGrey", { 0xD3, 0xD3, 0xD3 } }, + { "LightGreen", { 0x90, 0xEE, 0x90 } }, + { "LightPink", { 0xFF, 0xB6, 0xC1 } }, + { "LightSalmon", { 0xFF, 0xA0, 0x7A } }, + { "LightSeaGreen", { 0x20, 0xB2, 0xAA } }, + { "LightSkyBlue", { 0x87, 0xCE, 0xFA } }, + { "LightSlateGray", { 0x77, 0x88, 0x99 } }, + { "LightSteelBlue", { 0xB0, 0xC4, 0xDE } }, + { "LightYellow", { 0xFF, 0xFF, 0xE0 } }, + { "Lime", { 0x00, 0xFF, 0x00 } }, + { "LimeGreen", { 0x32, 0xCD, 0x32 } }, + { "Linen", { 0xFA, 0xF0, 0xE6 } }, + { "Magenta", { 0xFF, 0x00, 0xFF } }, + { "Maroon", { 0x80, 0x00, 0x00 } }, + { "MediumAquaMarine", { 0x66, 0xCD, 0xAA } }, + { "MediumBlue", { 0x00, 0x00, 0xCD } }, + { "MediumOrchid", { 0xBA, 0x55, 0xD3 } }, + { "MediumPurple", { 0x93, 0x70, 0xD8 } }, + { "MediumSeaGreen", { 0x3C, 0xB3, 0x71 } }, + { "MediumSlateBlue", { 0x7B, 0x68, 0xEE } }, + { "MediumSpringGreen", { 0x00, 0xFA, 0x9A } }, + { "MediumTurquoise", { 0x48, 0xD1, 0xCC } }, + { "MediumVioletRed", { 0xC7, 0x15, 0x85 } }, + { "MidnightBlue", { 0x19, 0x19, 0x70 } }, + { "MintCream", { 0xF5, 0xFF, 0xFA } }, + { "MistyRose", { 0xFF, 0xE4, 0xE1 } }, + { "Moccasin", { 0xFF, 0xE4, 0xB5 } }, + { "NavajoWhite", { 0xFF, 0xDE, 0xAD } }, + { "Navy", { 0x00, 0x00, 0x80 } }, + { "OldLace", { 0xFD, 0xF5, 0xE6 } }, + { "Olive", { 0x80, 0x80, 0x00 } }, + { "OliveDrab", { 0x6B, 0x8E, 0x23 } }, + { "Orange", { 0xFF, 0xA5, 0x00 } }, + { "OrangeRed", { 0xFF, 0x45, 0x00 } }, + { "Orchid", { 0xDA, 0x70, 0xD6 } }, + { "PaleGoldenRod", { 0xEE, 0xE8, 0xAA } }, + { "PaleGreen", { 0x98, 0xFB, 0x98 } }, + { "PaleTurquoise", { 0xAF, 0xEE, 0xEE } }, + { "PaleVioletRed", { 0xD8, 0x70, 0x93 } }, + { "PapayaWhip", { 0xFF, 0xEF, 0xD5 } }, + { "PeachPuff", { 0xFF, 0xDA, 0xB9 } }, + { "Peru", { 0xCD, 0x85, 0x3F } }, + { "Pink", { 0xFF, 0xC0, 0xCB } }, + { "Plum", { 0xDD, 0xA0, 0xDD } }, + { "PowderBlue", { 0xB0, 0xE0, 0xE6 } }, + { "Purple", { 0x80, 0x00, 0x80 } }, + { "Red", { 0xFF, 0x00, 0x00 } }, + { "RosyBrown", { 0xBC, 0x8F, 0x8F } }, + { "RoyalBlue", { 0x41, 0x69, 0xE1 } }, + { "SaddleBrown", { 0x8B, 0x45, 0x13 } }, + { "Salmon", { 0xFA, 0x80, 0x72 } }, + { "SandyBrown", { 0xF4, 0xA4, 0x60 } }, + { "SeaGreen", { 0x2E, 0x8B, 0x57 } }, + { "SeaShell", { 0xFF, 0xF5, 0xEE } }, + { "Sienna", { 0xA0, 0x52, 0x2D } }, + { "Silver", { 0xC0, 0xC0, 0xC0 } }, + { "SkyBlue", { 0x87, 0xCE, 0xEB } }, + { "SlateBlue", { 0x6A, 0x5A, 0xCD } }, + { "SlateGray", { 0x70, 0x80, 0x90 } }, + { "Snow", { 0xFF, 0xFA, 0xFA } }, + { "SpringGreen", { 0x00, 0xFF, 0x7F } }, + { "SteelBlue", { 0x46, 0x82, 0xB4 } }, + { "Tan", { 0xD2, 0xB4, 0x8C } }, + { "Teal", { 0x00, 0x80, 0x80 } }, + { "Thistle", { 0xD8, 0xBF, 0xD8 } }, + { "Tomato", { 0xFF, 0x63, 0x47 } }, + { "Turquoise", { 0x40, 0xE0, 0xD0 } }, + { "Violet", { 0xEE, 0x82, 0xEE } }, + { "Wheat", { 0xF5, 0xDE, 0xB3 } }, + { "White", { 0xFF, 0xFF, 0xFF } }, + { "WhiteSmoke", { 0xF5, 0xF5, 0xF5 } }, + { "Yellow", { 0xFF, 0xFF, 0x00 } }, + { "YellowGreen", { 0x9A, 0xCD, 0x32 } }, +}; + +static int color_table_compare(const void *lhs, const void *rhs) +{ + return strcasecmp(lhs, ((const ColorEntry *)rhs)->name); +} + +#define ALPHA_SEP '@' + +int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, + void *log_ctx) +{ + char *tail, color_string2[128]; + const ColorEntry *entry; + int len, hex_offset = 0; + + if (color_string[0] == '#') { + hex_offset = 1; + } else if (!strncmp(color_string, "0x", 2)) + hex_offset = 2; + + if (slen < 0) + slen = strlen(color_string); + av_strlcpy(color_string2, color_string + hex_offset, + FFMIN(slen-hex_offset+1, 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")) { + int rgba = av_get_random_seed(); + rgba_color[0] = rgba >> 24; + rgba_color[1] = rgba >> 16; + rgba_color[2] = rgba >> 8; + rgba_color[3] = rgba; + } else if (hex_offset || + strspn(color_string2, "0123456789ABCDEFabcdef") == len) { + char *tail; + unsigned int rgba = strtoul(color_string2, &tail, 16); + + 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 == 8) { + rgba_color[3] = rgba; + rgba >>= 8; + } + rgba_color[0] = rgba >> 16; + rgba_color[1] = rgba >> 8; + rgba_color[2] = rgba; + } else { + entry = bsearch(color_string2, + color_table, + FF_ARRAY_ELEMS(color_table), + sizeof(ColorEntry), + color_table_compare); + if (!entry) { + av_log(log_ctx, AV_LOG_ERROR, "Cannot find color '%s'\n", color_string2); + return AVERROR(EINVAL); + } + memcpy(rgba_color, entry->rgb_color, 3); + } + + if (tail) { + unsigned long int alpha; + const char *alpha_string = tail; + if (!strncmp(alpha_string, "0x", 2)) { + alpha = strtoul(alpha_string, &tail, 16); + } else { + alpha = 255 * strtod(alpha_string, &tail); + } + + if (tail == alpha_string || *tail || alpha > 255) { + av_log(log_ctx, AV_LOG_ERROR, "Invalid alpha value specifier '%s' in '%s'\n", + alpha_string, color_string); + return AVERROR(EINVAL); + } + rgba_color[3] = alpha; + } + + return 0; +} + #ifdef TEST #undef printf @@ -183,6 +417,57 @@ int main(void) } } + printf("\nTesting av_parse_color()\n"); + { + int i; + uint8_t rgba[4]; + const char *color_names[] = { + "bikeshed", + "RaNdOm", + "foo", + "red", + "Red ", + "RED", + "Violet", + "Yellow", + "Red", + "0x000000", + "0x0000000", + "0xff000000", + "0x3e34ff", + "0x3e34ffaa", + "0xffXXee", + "0xfoobar", + "0xffffeeeeeeee", + "#ff0000", + "#ffXX00", + "ff0000", + "ffXX00", + "red@foo", + "random@10", + "0xff0000@1.0", + "red@", + "red@0xfff", + "red@0xf", + "red@2", + "red@0.1", + "red@-1", + "red@0.5", + "red@1.0", + "red@256", + "red@10foo", + "red@-1.0", + "red@-0.0", + }; + + av_log_set_level(AV_LOG_DEBUG); + + for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) { + if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0) + printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]); + } + } + return 0; } diff --git a/libavcore/parseutils.h b/libavcore/parseutils.h index ad31ef29e5..052427bbfd 100644 --- a/libavcore/parseutils.h +++ b/libavcore/parseutils.h @@ -50,4 +50,26 @@ int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str); */ int av_parse_video_rate(AVRational *rate, const char *str); +/** + * 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 [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 + * hexadecimal number or a decimal number between 0.0 and 1.0, which + * represents the opacity value (0x00/0.0 means completely transparent, + * 0xff/1.0 completely opaque). + * If the alpha component is not specified then 0xff is assumed. + * The string "random" will result in a random color. + * @param slen length of the initial part of color_string containing the + * color. It can be set to -1 if color_string is a null terminated string + * containing nothing else than the color. + * @return >= 0 in case of success, a negative value in case of + * failure (for example if color_string cannot be parsed). + */ +int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, + void *log_ctx); + #endif /* AVCORE_PARSEUTILS_H */ diff --git a/libavfilter/Makefile b/libavfilter/Makefile index 254d4dbee1..71dcf2a01f 100644 --- a/libavfilter/Makefile +++ b/libavfilter/Makefile @@ -12,7 +12,6 @@ OBJS = allfilters.o \ defaults.o \ formats.o \ graphparser.o \ - parseutils.o \ OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o diff --git a/libavfilter/graphparser.c b/libavfilter/graphparser.c index 99982b3727..e4faa927b9 100644 --- a/libavfilter/graphparser.c +++ b/libavfilter/graphparser.c @@ -26,7 +26,6 @@ #include "libavutil/avstring.h" #include "avfilter.h" #include "avfiltergraph.h" -#include "parseutils.h" #define WHITESPACES " \n\t" diff --git a/libavfilter/parseutils.c b/libavfilter/parseutils.c deleted file mode 100644 index 4a7536f915..0000000000 --- a/libavfilter/parseutils.c +++ /dev/null @@ -1,323 +0,0 @@ -/* - * copyright (c) 2009 Stefano Sabatini - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * parsing utils - */ - -#include <strings.h> -#include "libavutil/avutil.h" -#include "libavutil/avstring.h" -#include "libavutil/random_seed.h" -#include "parseutils.h" - -typedef struct { - const char *name; ///< a string representing the name of the color - uint8_t rgb_color[3]; ///< RGB values for the color -} ColorEntry; - -static ColorEntry color_table[] = { - { "AliceBlue", { 0xF0, 0xF8, 0xFF } }, - { "AntiqueWhite", { 0xFA, 0xEB, 0xD7 } }, - { "Aqua", { 0x00, 0xFF, 0xFF } }, - { "Aquamarine", { 0x7F, 0xFF, 0xD4 } }, - { "Azure", { 0xF0, 0xFF, 0xFF } }, - { "Beige", { 0xF5, 0xF5, 0xDC } }, - { "Bisque", { 0xFF, 0xE4, 0xC4 } }, - { "Black", { 0x00, 0x00, 0x00 } }, - { "BlanchedAlmond", { 0xFF, 0xEB, 0xCD } }, - { "Blue", { 0x00, 0x00, 0xFF } }, - { "BlueViolet", { 0x8A, 0x2B, 0xE2 } }, - { "Brown", { 0xA5, 0x2A, 0x2A } }, - { "BurlyWood", { 0xDE, 0xB8, 0x87 } }, - { "CadetBlue", { 0x5F, 0x9E, 0xA0 } }, - { "Chartreuse", { 0x7F, 0xFF, 0x00 } }, - { "Chocolate", { 0xD2, 0x69, 0x1E } }, - { "Coral", { 0xFF, 0x7F, 0x50 } }, - { "CornflowerBlue", { 0x64, 0x95, 0xED } }, - { "Cornsilk", { 0xFF, 0xF8, 0xDC } }, - { "Crimson", { 0xDC, 0x14, 0x3C } }, - { "Cyan", { 0x00, 0xFF, 0xFF } }, - { "DarkBlue", { 0x00, 0x00, 0x8B } }, - { "DarkCyan", { 0x00, 0x8B, 0x8B } }, - { "DarkGoldenRod", { 0xB8, 0x86, 0x0B } }, - { "DarkGray", { 0xA9, 0xA9, 0xA9 } }, - { "DarkGreen", { 0x00, 0x64, 0x00 } }, - { "DarkKhaki", { 0xBD, 0xB7, 0x6B } }, - { "DarkMagenta", { 0x8B, 0x00, 0x8B } }, - { "DarkOliveGreen", { 0x55, 0x6B, 0x2F } }, - { "Darkorange", { 0xFF, 0x8C, 0x00 } }, - { "DarkOrchid", { 0x99, 0x32, 0xCC } }, - { "DarkRed", { 0x8B, 0x00, 0x00 } }, - { "DarkSalmon", { 0xE9, 0x96, 0x7A } }, - { "DarkSeaGreen", { 0x8F, 0xBC, 0x8F } }, - { "DarkSlateBlue", { 0x48, 0x3D, 0x8B } }, - { "DarkSlateGray", { 0x2F, 0x4F, 0x4F } }, - { "DarkTurquoise", { 0x00, 0xCE, 0xD1 } }, - { "DarkViolet", { 0x94, 0x00, 0xD3 } }, - { "DeepPink", { 0xFF, 0x14, 0x93 } }, - { "DeepSkyBlue", { 0x00, 0xBF, 0xFF } }, - { "DimGray", { 0x69, 0x69, 0x69 } }, - { "DodgerBlue", { 0x1E, 0x90, 0xFF } }, - { "FireBrick", { 0xB2, 0x22, 0x22 } }, - { "FloralWhite", { 0xFF, 0xFA, 0xF0 } }, - { "ForestGreen", { 0x22, 0x8B, 0x22 } }, - { "Fuchsia", { 0xFF, 0x00, 0xFF } }, - { "Gainsboro", { 0xDC, 0xDC, 0xDC } }, - { "GhostWhite", { 0xF8, 0xF8, 0xFF } }, - { "Gold", { 0xFF, 0xD7, 0x00 } }, - { "GoldenRod", { 0xDA, 0xA5, 0x20 } }, - { "Gray", { 0x80, 0x80, 0x80 } }, - { "Green", { 0x00, 0x80, 0x00 } }, - { "GreenYellow", { 0xAD, 0xFF, 0x2F } }, - { "HoneyDew", { 0xF0, 0xFF, 0xF0 } }, - { "HotPink", { 0xFF, 0x69, 0xB4 } }, - { "IndianRed", { 0xCD, 0x5C, 0x5C } }, - { "Indigo", { 0x4B, 0x00, 0x82 } }, - { "Ivory", { 0xFF, 0xFF, 0xF0 } }, - { "Khaki", { 0xF0, 0xE6, 0x8C } }, - { "Lavender", { 0xE6, 0xE6, 0xFA } }, - { "LavenderBlush", { 0xFF, 0xF0, 0xF5 } }, - { "LawnGreen", { 0x7C, 0xFC, 0x00 } }, - { "LemonChiffon", { 0xFF, 0xFA, 0xCD } }, - { "LightBlue", { 0xAD, 0xD8, 0xE6 } }, - { "LightCoral", { 0xF0, 0x80, 0x80 } }, - { "LightCyan", { 0xE0, 0xFF, 0xFF } }, - { "LightGoldenRodYellow", { 0xFA, 0xFA, 0xD2 } }, - { "LightGrey", { 0xD3, 0xD3, 0xD3 } }, - { "LightGreen", { 0x90, 0xEE, 0x90 } }, - { "LightPink", { 0xFF, 0xB6, 0xC1 } }, - { "LightSalmon", { 0xFF, 0xA0, 0x7A } }, - { "LightSeaGreen", { 0x20, 0xB2, 0xAA } }, - { "LightSkyBlue", { 0x87, 0xCE, 0xFA } }, - { "LightSlateGray", { 0x77, 0x88, 0x99 } }, - { "LightSteelBlue", { 0xB0, 0xC4, 0xDE } }, - { "LightYellow", { 0xFF, 0xFF, 0xE0 } }, - { "Lime", { 0x00, 0xFF, 0x00 } }, - { "LimeGreen", { 0x32, 0xCD, 0x32 } }, - { "Linen", { 0xFA, 0xF0, 0xE6 } }, - { "Magenta", { 0xFF, 0x00, 0xFF } }, - { "Maroon", { 0x80, 0x00, 0x00 } }, - { "MediumAquaMarine", { 0x66, 0xCD, 0xAA } }, - { "MediumBlue", { 0x00, 0x00, 0xCD } }, - { "MediumOrchid", { 0xBA, 0x55, 0xD3 } }, - { "MediumPurple", { 0x93, 0x70, 0xD8 } }, - { "MediumSeaGreen", { 0x3C, 0xB3, 0x71 } }, - { "MediumSlateBlue", { 0x7B, 0x68, 0xEE } }, - { "MediumSpringGreen", { 0x00, 0xFA, 0x9A } }, - { "MediumTurquoise", { 0x48, 0xD1, 0xCC } }, - { "MediumVioletRed", { 0xC7, 0x15, 0x85 } }, - { "MidnightBlue", { 0x19, 0x19, 0x70 } }, - { "MintCream", { 0xF5, 0xFF, 0xFA } }, - { "MistyRose", { 0xFF, 0xE4, 0xE1 } }, - { "Moccasin", { 0xFF, 0xE4, 0xB5 } }, - { "NavajoWhite", { 0xFF, 0xDE, 0xAD } }, - { "Navy", { 0x00, 0x00, 0x80 } }, - { "OldLace", { 0xFD, 0xF5, 0xE6 } }, - { "Olive", { 0x80, 0x80, 0x00 } }, - { "OliveDrab", { 0x6B, 0x8E, 0x23 } }, - { "Orange", { 0xFF, 0xA5, 0x00 } }, - { "OrangeRed", { 0xFF, 0x45, 0x00 } }, - { "Orchid", { 0xDA, 0x70, 0xD6 } }, - { "PaleGoldenRod", { 0xEE, 0xE8, 0xAA } }, - { "PaleGreen", { 0x98, 0xFB, 0x98 } }, - { "PaleTurquoise", { 0xAF, 0xEE, 0xEE } }, - { "PaleVioletRed", { 0xD8, 0x70, 0x93 } }, - { "PapayaWhip", { 0xFF, 0xEF, 0xD5 } }, - { "PeachPuff", { 0xFF, 0xDA, 0xB9 } }, - { "Peru", { 0xCD, 0x85, 0x3F } }, - { "Pink", { 0xFF, 0xC0, 0xCB } }, - { "Plum", { 0xDD, 0xA0, 0xDD } }, - { "PowderBlue", { 0xB0, 0xE0, 0xE6 } }, - { "Purple", { 0x80, 0x00, 0x80 } }, - { "Red", { 0xFF, 0x00, 0x00 } }, - { "RosyBrown", { 0xBC, 0x8F, 0x8F } }, - { "RoyalBlue", { 0x41, 0x69, 0xE1 } }, - { "SaddleBrown", { 0x8B, 0x45, 0x13 } }, - { "Salmon", { 0xFA, 0x80, 0x72 } }, - { "SandyBrown", { 0xF4, 0xA4, 0x60 } }, - { "SeaGreen", { 0x2E, 0x8B, 0x57 } }, - { "SeaShell", { 0xFF, 0xF5, 0xEE } }, - { "Sienna", { 0xA0, 0x52, 0x2D } }, - { "Silver", { 0xC0, 0xC0, 0xC0 } }, - { "SkyBlue", { 0x87, 0xCE, 0xEB } }, - { "SlateBlue", { 0x6A, 0x5A, 0xCD } }, - { "SlateGray", { 0x70, 0x80, 0x90 } }, - { "Snow", { 0xFF, 0xFA, 0xFA } }, - { "SpringGreen", { 0x00, 0xFF, 0x7F } }, - { "SteelBlue", { 0x46, 0x82, 0xB4 } }, - { "Tan", { 0xD2, 0xB4, 0x8C } }, - { "Teal", { 0x00, 0x80, 0x80 } }, - { "Thistle", { 0xD8, 0xBF, 0xD8 } }, - { "Tomato", { 0xFF, 0x63, 0x47 } }, - { "Turquoise", { 0x40, 0xE0, 0xD0 } }, - { "Violet", { 0xEE, 0x82, 0xEE } }, - { "Wheat", { 0xF5, 0xDE, 0xB3 } }, - { "White", { 0xFF, 0xFF, 0xFF } }, - { "WhiteSmoke", { 0xF5, 0xF5, 0xF5 } }, - { "Yellow", { 0xFF, 0xFF, 0x00 } }, - { "YellowGreen", { 0x9A, 0xCD, 0x32 } }, -}; - -static int color_table_compare(const void *lhs, const void *rhs) -{ - return strcasecmp(lhs, ((const ColorEntry *)rhs)->name); -} - -#define ALPHA_SEP '@' - -int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, - void *log_ctx) -{ - char *tail, color_string2[128]; - const ColorEntry *entry; - int len, hex_offset = 0; - - if (color_string[0] == '#') { - hex_offset = 1; - } else if (!strncmp(color_string, "0x", 2)) - hex_offset = 2; - - if (slen < 0) - slen = strlen(color_string); - av_strlcpy(color_string2, color_string + hex_offset, - FFMIN(slen-hex_offset+1, 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")) { - int rgba = av_get_random_seed(); - rgba_color[0] = rgba >> 24; - rgba_color[1] = rgba >> 16; - rgba_color[2] = rgba >> 8; - rgba_color[3] = rgba; - } else if (hex_offset || - strspn(color_string2, "0123456789ABCDEFabcdef") == len) { - char *tail; - unsigned int rgba = strtoul(color_string2, &tail, 16); - - 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 == 8) { - rgba_color[3] = rgba; - rgba >>= 8; - } - rgba_color[0] = rgba >> 16; - rgba_color[1] = rgba >> 8; - rgba_color[2] = rgba; - } else { - entry = bsearch(color_string2, - color_table, - FF_ARRAY_ELEMS(color_table), - sizeof(ColorEntry), - color_table_compare); - if (!entry) { - av_log(log_ctx, AV_LOG_ERROR, "Cannot find color '%s'\n", color_string2); - return AVERROR(EINVAL); - } - memcpy(rgba_color, entry->rgb_color, 3); - } - - if (tail) { - unsigned long int alpha; - const char *alpha_string = tail; - if (!strncmp(alpha_string, "0x", 2)) { - alpha = strtoul(alpha_string, &tail, 16); - } else { - alpha = 255 * strtod(alpha_string, &tail); - } - - if (tail == alpha_string || *tail || alpha > 255) { - av_log(log_ctx, AV_LOG_ERROR, "Invalid alpha value specifier '%s' in '%s'\n", - alpha_string, color_string); - return AVERROR(EINVAL); - } - rgba_color[3] = alpha; - } - - return 0; -} - -#ifdef TEST - -#undef printf - -int main(void) -{ - int i; - - printf("\nTesting av_parse_color()\n"); - { - uint8_t rgba[4]; - const char *color_names[] = { - "bikeshed", - "RaNdOm", - "foo", - "red", - "Red ", - "RED", - "Violet", - "Yellow", - "Red", - "0x000000", - "0x0000000", - "0xff000000", - "0x3e34ff", - "0x3e34ffaa", - "0xffXXee", - "0xfoobar", - "0xffffeeeeeeee", - "#ff0000", - "#ffXX00", - "ff0000", - "ffXX00", - "red@foo", - "random@10", - "0xff0000@1.0", - "red@", - "red@0xfff", - "red@0xf", - "red@2", - "red@0.1", - "red@-1", - "red@0.5", - "red@1.0", - "red@256", - "red@10foo", - "red@-1.0", - "red@-0.0", - }; - - av_log_set_level(AV_LOG_DEBUG); - - for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) { - if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0) - printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]); - } - } - - return 0; -} - -#endif diff --git a/libavfilter/parseutils.h b/libavfilter/parseutils.h deleted file mode 100644 index 322afb3e76..0000000000 --- a/libavfilter/parseutils.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * copyright (c) 2009 Stefano Sabatini - * This file is part of FFmpeg. - * - * FFmpeg is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * FFmpeg is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with FFmpeg; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/** - * @file - * parsing utils - */ - -#ifndef AVFILTER_PARSEUTILS_H -#define AVFILTER_PARSEUTILS_H - -#include "libavutil/opt.h" - -/** - * 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 [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 - * hexadecimal number or a decimal number between 0.0 and 1.0, which - * represents the opacity value (0x00/0.0 means completely transparent, - * 0xff/1.0 completely opaque). - * If the alpha component is not specified then 0xff is assumed. - * The string "random" will result in a random color. - * @param slen length of the initial part of color_string containing the - * color. It can be set to -1 if color_string is a null terminated string - * containing nothing else than the color. - * @return >= 0 in case of success, a negative value in case of - * failure (for example if color_string cannot be parsed). - */ -int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, - void *log_ctx); - -#endif /* AVFILTER_PARSEUTILS_H */ diff --git a/libavfilter/vf_drawbox.c b/libavfilter/vf_drawbox.c index 17e73f5588..114a2ac830 100644 --- a/libavfilter/vf_drawbox.c +++ b/libavfilter/vf_drawbox.c @@ -26,8 +26,8 @@ #include "libavutil/colorspace.h" #include "libavutil/pixdesc.h" +#include "libavcore/parseutils.h" #include "avfilter.h" -#include "parseutils.h" enum { Y, U, V, A }; diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c index 226f656bcd..49fe172be0 100644 --- a/libavfilter/vf_frei0r.c +++ b/libavfilter/vf_frei0r.c @@ -27,8 +27,8 @@ #include <dlfcn.h> #include <frei0r.h> #include "libavutil/avstring.h" +#include "libavcore/parseutils.h" #include "avfilter.h" -#include "parseutils.h" typedef f0r_instance_t (*f0r_construct_f)(unsigned int width, unsigned int height); typedef void (*f0r_destruct_f)(f0r_instance_t instance); diff --git a/libavfilter/vf_pad.c b/libavfilter/vf_pad.c index c385a2f1f8..f86e4c6fb6 100644 --- a/libavfilter/vf_pad.c +++ b/libavfilter/vf_pad.c @@ -25,7 +25,6 @@ */ #include "avfilter.h" -#include "parseutils.h" #include "libavutil/pixdesc.h" #include "libavutil/colorspace.h" #include "libavcore/imgutils.h" |