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
This commit is contained in:
parent
e92d2c51ed
commit
a96a733c7a
1 changed files with 13 additions and 18 deletions
31
apps/misc.c
31
apps/misc.c
|
@ -1099,28 +1099,23 @@ static int hex2dec(int c)
|
||||||
}
|
}
|
||||||
|
|
||||||
int hex_to_rgb(const char* hex, int* color)
|
int hex_to_rgb(const char* hex, int* color)
|
||||||
{ int ok = 1;
|
{
|
||||||
int i;
|
|
||||||
int red, green, blue;
|
int red, green, blue;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
if (strlen(hex) == 6) {
|
while ((i < 6) && (isxdigit(hex[i])))
|
||||||
for (i=0; i < 6; i++ ) {
|
i++;
|
||||||
if (!isxdigit(hex[i])) {
|
|
||||||
ok=0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ok) {
|
if (i < 6)
|
||||||
red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]);
|
return -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 */
|
#endif /* HAVE_LCD_COLOR */
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue