summaryrefslogtreecommitdiff
path: root/apps/misc.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2008-03-21 14:04:19 +0000
committerDave Chapman <dave@dchapman.com>2008-03-21 14:04:19 +0000
commita96a733c7a43bf0d1a8cffc8ce38e5dddc4c4e0a (patch)
tree726edb7d37b05f10d6923adbc54941ce5e34985d /apps/misc.c
parente92d2c51ed455cc0a889fb6d38b4802eee252a6a (diff)
downloadrockbox-a96a733c7a43bf0d1a8cffc8ce38e5dddc4c4e0a.tar.gz
rockbox-a96a733c7a43bf0d1a8cffc8ce38e5dddc4c4e0a.zip
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
Diffstat (limited to 'apps/misc.c')
-rw-r--r--apps/misc.c31
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)
1099} 1099}
1100 1100
1101int hex_to_rgb(const char* hex, int* color) 1101int hex_to_rgb(const char* hex, int* color)
1102{ int ok = 1; 1102{
1103 int i;
1104 int red, green, blue; 1103 int red, green, blue;
1104 int i = 0;
1105 1105
1106 if (strlen(hex) == 6) { 1106 while ((i < 6) && (isxdigit(hex[i])))
1107 for (i=0; i < 6; i++ ) { 1107 i++;
1108 if (!isxdigit(hex[i])) {
1109 ok=0;
1110 break;
1111 }
1112 }
1113 1108
1114 if (ok) { 1109 if (i < 6)
1115 red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); 1110 return -1;
1116 green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); 1111
1117 blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); 1112 red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]);
1118 *color = LCD_RGBPACK(red,green,blue); 1113 green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]);
1119 return 0; 1114 blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]);
1120 }
1121 }
1122 1115
1123 return -1; 1116 *color = LCD_RGBPACK(red,green,blue);
1117
1118 return 0;
1124} 1119}
1125#endif /* HAVE_LCD_COLOR */ 1120#endif /* HAVE_LCD_COLOR */
1126 1121