diff options
author | Dave Chapman <dave@dchapman.com> | 2008-03-21 14:04:19 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2008-03-21 14:04:19 +0000 |
commit | a96a733c7a43bf0d1a8cffc8ce38e5dddc4c4e0a (patch) | |
tree | 726edb7d37b05f10d6923adbc54941ce5e34985d | |
parent | e92d2c51ed455cc0a889fb6d38b4802eee252a6a (diff) |
Another small optimisation/simplification to the hex_to_rgb() function.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16729 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/misc.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/apps/misc.c b/apps/misc.c index 632b12b9aa..8b6773dd6f 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -1099,28 +1099,23 @@ static int hex2dec(int c) } int hex_to_rgb(const char* hex, int* color) -{ int ok = 1; - int i; +{ int red, green, blue; + int i = 0; - if (strlen(hex) == 6) { - for (i=0; i < 6; i++ ) { - if (!isxdigit(hex[i])) { - ok=0; - break; - } - } + while ((i < 6) && (isxdigit(hex[i]))) + i++; - if (ok) { - red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); - green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); - blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); - *color = LCD_RGBPACK(red,green,blue); - return 0; - } - } + if (i < 6) + return -1; + + red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); + green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); + blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); - return -1; + *color = LCD_RGBPACK(red,green,blue); + + return 0; } #endif /* HAVE_LCD_COLOR */ |