forked from len0rd/rockbox
Convert Huffman decode from inline function to macro, for small code size saving on ARM and on Coldfire color, only finish DC decode on greyscale targets if decoding luma channel.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20874 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
0af7494b37
commit
7b81cd0caf
1 changed files with 70 additions and 79 deletions
|
|
@ -1675,84 +1675,74 @@ static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Decode a single value */
|
/* Decode a single value */
|
||||||
INLINE int huff_decode_dc(struct jpeg *p_jpeg, struct derived_tbl* tbl)
|
#define huff_decode_dc(p_jpeg, tbl, s, r) \
|
||||||
{
|
{ \
|
||||||
int nb, look, s, r;
|
int nb, look; \
|
||||||
|
\
|
||||||
check_bit_buffer(p_jpeg, HUFF_LOOKAHEAD);
|
check_bit_buffer((p_jpeg), HUFF_LOOKAHEAD); \
|
||||||
look = peek_bits(p_jpeg, HUFF_LOOKAHEAD);
|
look = peek_bits((p_jpeg), HUFF_LOOKAHEAD); \
|
||||||
if ((nb = tbl->look_nbits[look]) != 0)
|
if ((nb = (tbl)->look_nbits[look]) != 0) \
|
||||||
{
|
{ \
|
||||||
drop_bits(p_jpeg, nb);
|
drop_bits((p_jpeg), nb); \
|
||||||
s = tbl->look_sym[look];
|
s = (tbl)->look_sym[look]; \
|
||||||
check_bit_buffer(p_jpeg, s);
|
check_bit_buffer((p_jpeg), s); \
|
||||||
r = get_bits(p_jpeg, s);
|
r = get_bits((p_jpeg), s); \
|
||||||
s = HUFF_EXTEND(r, s);
|
} else { \
|
||||||
}
|
/* slow_DECODE(s, HUFF_LOOKAHEAD+1)) < 0); */ \
|
||||||
else
|
long code; \
|
||||||
{ /* slow_DECODE(s, HUFF_LOOKAHEAD+1)) < 0); */
|
nb=HUFF_LOOKAHEAD+1; \
|
||||||
long code;
|
check_bit_buffer((p_jpeg), nb); \
|
||||||
nb=HUFF_LOOKAHEAD+1;
|
code = get_bits((p_jpeg), nb); \
|
||||||
check_bit_buffer(p_jpeg, nb);
|
while (code > (tbl)->maxcode[nb]) \
|
||||||
code = get_bits(p_jpeg, nb);
|
{ \
|
||||||
while (code > tbl->maxcode[nb])
|
code <<= 1; \
|
||||||
{
|
check_bit_buffer((p_jpeg), 1); \
|
||||||
code <<= 1;
|
code |= get_bits((p_jpeg), 1); \
|
||||||
check_bit_buffer(p_jpeg, 1);
|
nb++; \
|
||||||
code |= get_bits(p_jpeg, 1);
|
} \
|
||||||
nb++;
|
if (nb > 16) /* error in Huffman */ \
|
||||||
}
|
{ \
|
||||||
if (nb > 16) /* error in Huffman */
|
r = 0; s = 0; /* fake a zero, this is most safe */ \
|
||||||
{
|
} else { \
|
||||||
s=0; /* fake a zero, this is most safe */
|
s = (tbl)->pub[16 + (tbl)->valptr[nb] + \
|
||||||
}
|
((int) (code - (tbl)->mincode[nb]))]; \
|
||||||
else
|
check_bit_buffer((p_jpeg), s); \
|
||||||
{
|
r = get_bits((p_jpeg), s); \
|
||||||
s = tbl->pub[16 + tbl->valptr[nb] +
|
} \
|
||||||
((int) (code - tbl->mincode[nb]))];
|
} /* end slow decode */ \
|
||||||
check_bit_buffer(p_jpeg, s);
|
|
||||||
r = get_bits(p_jpeg, s);
|
|
||||||
s = HUFF_EXTEND(r, s);
|
|
||||||
}
|
|
||||||
} /* end slow decode */
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE int huff_decode_ac(struct jpeg *p_jpeg, struct derived_tbl* tbl)
|
#define huff_decode_ac(p_jpeg, tbl, s) \
|
||||||
{
|
{ \
|
||||||
int nb, look, s;
|
int nb, look; \
|
||||||
|
\
|
||||||
check_bit_buffer(p_jpeg, HUFF_LOOKAHEAD);
|
check_bit_buffer((p_jpeg), HUFF_LOOKAHEAD); \
|
||||||
look = peek_bits(p_jpeg, HUFF_LOOKAHEAD);
|
look = peek_bits((p_jpeg), HUFF_LOOKAHEAD); \
|
||||||
if ((nb = tbl->look_nbits[look]) != 0)
|
if ((nb = (tbl)->look_nbits[look]) != 0) \
|
||||||
{
|
{ \
|
||||||
drop_bits(p_jpeg, nb);
|
drop_bits((p_jpeg), nb); \
|
||||||
s = tbl->look_sym[look];
|
s = (tbl)->look_sym[look]; \
|
||||||
}
|
} else { \
|
||||||
else
|
/* slow_DECODE(s, HUFF_LOOKAHEAD+1)) < 0); */ \
|
||||||
{ /* slow_DECODE(s, HUFF_LOOKAHEAD+1)) < 0); */
|
long code; \
|
||||||
long code;
|
nb=HUFF_LOOKAHEAD+1; \
|
||||||
nb=HUFF_LOOKAHEAD+1;
|
check_bit_buffer((p_jpeg), nb); \
|
||||||
check_bit_buffer(p_jpeg, nb);
|
code = get_bits((p_jpeg), nb); \
|
||||||
code = get_bits(p_jpeg, nb);
|
while (code > (tbl)->maxcode[nb]) \
|
||||||
while (code > tbl->maxcode[nb])
|
{ \
|
||||||
{
|
code <<= 1; \
|
||||||
code <<= 1;
|
check_bit_buffer((p_jpeg), 1); \
|
||||||
check_bit_buffer(p_jpeg, 1);
|
code |= get_bits((p_jpeg), 1); \
|
||||||
code |= get_bits(p_jpeg, 1);
|
nb++; \
|
||||||
nb++;
|
} \
|
||||||
}
|
if (nb > 16) /* error in Huffman */ \
|
||||||
if (nb > 16) /* error in Huffman */
|
{ \
|
||||||
{
|
s = 0; /* fake a zero, this is most safe */ \
|
||||||
s=0; /* fake a zero, this is most safe */
|
} else { \
|
||||||
}
|
s = (tbl)->pub[16 + (tbl)->valptr[nb] + \
|
||||||
else
|
((int) (code - (tbl)->mincode[nb]))]; \
|
||||||
{
|
} \
|
||||||
s = tbl->pub[16 + tbl->valptr[nb] +
|
} /* end slow decode */ \
|
||||||
((int) (code - tbl->mincode[nb]))];
|
|
||||||
}
|
|
||||||
} /* end slow decode */
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct img_part *store_row_jpeg(void *jpeg_args)
|
static struct img_part *store_row_jpeg(void *jpeg_args)
|
||||||
|
|
@ -1799,12 +1789,13 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
|
||||||
struct derived_tbl* actbl = &p_jpeg->ac_derived_tbls[ti];
|
struct derived_tbl* actbl = &p_jpeg->ac_derived_tbls[ti];
|
||||||
|
|
||||||
/* Section F.2.2.1: decode the DC coefficient difference */
|
/* Section F.2.2.1: decode the DC coefficient difference */
|
||||||
s = huff_decode_dc(p_jpeg, dctbl);
|
huff_decode_dc(p_jpeg, dctbl, s, r);
|
||||||
|
|
||||||
#ifndef HAVE_LCD_COLOR
|
#ifndef HAVE_LCD_COLOR
|
||||||
if (!ci)
|
if (!ci)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
s = HUFF_EXTEND(r, s);
|
||||||
#ifdef HAVE_LCD_COLOR
|
#ifdef HAVE_LCD_COLOR
|
||||||
p_jpeg->last_dc_val[ci] += s;
|
p_jpeg->last_dc_val[ci] += s;
|
||||||
/* output it (assumes zag[0] = 0) */
|
/* output it (assumes zag[0] = 0) */
|
||||||
|
|
@ -1821,7 +1812,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
|
||||||
/* Section F.2.2.2: decode the AC coefficients */
|
/* Section F.2.2.2: decode the AC coefficients */
|
||||||
for (; k < p_jpeg->k_need[!!ci]; k++)
|
for (; k < p_jpeg->k_need[!!ci]; k++)
|
||||||
{
|
{
|
||||||
s = huff_decode_ac(p_jpeg, actbl);
|
huff_decode_ac(p_jpeg, actbl, s);
|
||||||
r = s >> 4;
|
r = s >> 4;
|
||||||
s &= 15;
|
s &= 15;
|
||||||
if (s)
|
if (s)
|
||||||
|
|
@ -1851,7 +1842,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
|
||||||
}
|
}
|
||||||
for (; k < 64; k++)
|
for (; k < 64; k++)
|
||||||
{
|
{
|
||||||
s = huff_decode_ac(p_jpeg, actbl);
|
huff_decode_ac(p_jpeg, actbl, s);
|
||||||
r = s >> 4;
|
r = s >> 4;
|
||||||
s &= 15;
|
s &= 15;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue