From a96a733c7a43bf0d1a8cffc8ce38e5dddc4c4e0a Mon Sep 17 00:00:00 2001 From: Dave Chapman Date: Fri, 21 Mar 2008 14:04:19 +0000 Subject: [PATCH] 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 --- apps/misc.c | 31 +++++++++++++------------------ 1 file 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; - 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]); + + *color = LCD_RGBPACK(red,green,blue); + + return 0; } #endif /* HAVE_LCD_COLOR */