MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / av_parse_color

Function av_parse_color

libavutil/parseutils.c:359–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

357#define ALPHA_SEP '@'
358
359int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen,
360 void *log_ctx)
361{
362 char *tail, color_string2[128];
363 const ColorEntry *entry;
364 int len, hex_offset = 0;
365
366 if (color_string[0] == '#') {
367 hex_offset = 1;
368 } else if (!strncmp(color_string, "0x", 2))
369 hex_offset = 2;
370
371 if (slen < 0)
372 slen = strlen(color_string);
373 av_strlcpy(color_string2, color_string + hex_offset,
374 FFMIN(slen-hex_offset+1, sizeof(color_string2)));
375 if ((tail = strchr(color_string2, ALPHA_SEP)))
376 *tail++ = 0;
377 len = strlen(color_string2);
378 rgba_color[3] = 255;
379
380 if (!av_strcasecmp(color_string2, "random") || !av_strcasecmp(color_string2, "bikeshed")) {
381 int rgba = av_get_random_seed();
382 rgba_color[0] = rgba >> 24;
383 rgba_color[1] = rgba >> 16;
384 rgba_color[2] = rgba >> 8;
385 rgba_color[3] = rgba;
386 } else if (hex_offset ||
387 strspn(color_string2, "0123456789ABCDEFabcdef") == len) {
388 char *tail;
389 unsigned int rgba = strtoul(color_string2, &tail, 16);
390
391 if (*tail || (len != 6 && len != 8)) {
392 av_log(log_ctx, AV_LOG_ERROR, "Invalid 0xRRGGBB[AA] color string: '%s'\n", color_string2);
393 return AVERROR(EINVAL);
394 }
395 if (len == 8) {
396 rgba_color[3] = rgba;
397 rgba >>= 8;
398 }
399 rgba_color[0] = rgba >> 16;
400 rgba_color[1] = rgba >> 8;
401 rgba_color[2] = rgba;
402 } else {
403 entry = bsearch(color_string2,
404 color_table,
405 FF_ARRAY_ELEMS(color_table),
406 sizeof(ColorEntry),
407 color_table_compare);
408 if (!entry) {
409 av_log(log_ctx, AV_LOG_ERROR, "Cannot find color '%s'\n", color_string2);
410 return AVERROR(EINVAL);
411 }
412 memcpy(rgba_color, entry->rgb_color, 3);
413 }
414
415 if (tail) {
416 double alpha;

Callers 15

set_string_colorFunction · 0.85
av_opt_is_set_to_defaultFunction · 0.85
test_av_parse_colorFunction · 0.85
stream_openFunction · 0.85
html_color_parseFunction · 0.85
set_paramFunction · 0.85
vgs_parse_colorFunction · 0.85
initFunction · 0.85
draw_curvesFunction · 0.85
config_video_outputFunction · 0.85
initFunction · 0.85
plot_freqsFunction · 0.85

Calls 4

av_strlcpyFunction · 0.85
av_strcasecmpFunction · 0.85
av_get_random_seedFunction · 0.85
av_logFunction · 0.85

Tested by 1

test_av_parse_colorFunction · 0.68