config-parser: Add weston_config_section_get_color
authorBryce Harrington <bryce@osg.samsung.com>
Fri, 15 Jul 2016 01:28:03 +0000 (18:28 -0700)
committerBryce Harrington <bryce@osg.samsung.com>
Tue, 26 Jul 2016 22:57:14 +0000 (15:57 -0700)
commite776f2a4d9a335a41d9cbc8b06ba97a660051614
tree53c674532942a7d24a2a44a22bf9abaaa92210ab
parentcbfde138597e5a3f0693aa4bc7c08a515d1e0f82
config-parser: Add weston_config_section_get_color

Previously weston_config_section_get_uint was serving dual purpose for
parsing both unsigned decimal integer values (ids, counts, seconds,
etc.)  and hexadecimal values (colors), by relying on strtoul's
auto-detection mechanism.

However, this usage is unable to catch certain kinds of error
conditions, such as specifying a negative number where an unsigned
should be used.  And for colors in particular, it would misparse hex
values if the leading 0x was omitted.  E.g. "background-color=99999999"
would render a near-black background (effectively 0x05f5e0ff) instead of
medium grey, and "background-color=ffffffff" would be treated as an
error rather than white.  "background-color=0x01234567",
"background-color=01234567", and "background-color=1234567" each
resulted in the value being parsed as hexadecimal, octal, and decimal
respectively, resulting in colors 0x01234567, 0x00053977, and 0x0012d687
being displayed.

This new routine forces hexadecimal to be used in all cases when parsing
color values, so "0x01234567" and "01234567" result in the same color
value, "99999999" is grey, and "ffffffff" is white.  It also requires
exactly 8 or 10 digits (other lengths likely indicate typos), or the
value "0" (black).

Signed-off-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
clients/desktop-shell.c
clients/ivi-shell-user-interface.c
shared/config-parser.c
shared/config-parser.h
tests/config-parser-test.c