avcodec/xpmdec: Use LUT for hex char->number conversion
Speeds up decoding and also reduces binary size. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
0b2ed7f6c7
commit
9e36e2fb7b
|
@ -193,15 +193,22 @@ static const ColorEntry color_table[] = {
|
||||||
|
|
||||||
static unsigned hex_char_to_number(uint8_t x)
|
static unsigned hex_char_to_number(uint8_t x)
|
||||||
{
|
{
|
||||||
if (x >= 'a' && x <= 'f')
|
#define TIMES256(idx) \
|
||||||
x -= 'a' - 10;
|
TIMES64(4 * (idx)) TIMES64(4 * (idx) + 1) TIMES64(4 * (idx) + 2) TIMES64(4 * (idx) + 3)
|
||||||
else if (x >= 'A' && x <= 'F')
|
#define TIMES64(idx) \
|
||||||
x -= 'A' - 10;
|
TIMES16(4 * (idx)) TIMES16(4 * (idx) + 1) TIMES16(4 * (idx) + 2) TIMES16(4 * (idx) + 3)
|
||||||
else if (x >= '0' && x <= '9')
|
#define TIMES16(idx) \
|
||||||
x -= '0';
|
TIMES4(4 * (idx)) TIMES4(4 * (idx) + 1) TIMES4(4 * (idx) + 2) TIMES4(4 * (idx) + 3)
|
||||||
else
|
#define TIMES4(idx) \
|
||||||
x = 0;
|
ENTRY(4 * (idx)) ENTRY(4 * (idx) + 1) ENTRY(4 * (idx) + 2) ENTRY(4 * (idx) + 3)
|
||||||
return x;
|
#define ENTRY(x) [x] = ((x) >= 'a' && (x) <= 'f') ? (x) - ('a' - 10) : \
|
||||||
|
((x) >= 'A' && (x) <= 'F') ? (x) - ('A' - 10) : \
|
||||||
|
((x) >= '0' && (x) <= '9') ? (x) - '0' : 0,
|
||||||
|
|
||||||
|
static const uint8_t lut[] = {
|
||||||
|
TIMES256(0)
|
||||||
|
};
|
||||||
|
return lut[x];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue