summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2009-05-08 07:21:35 +0000
committerAndrew Mahone <andrew.mahone@gmail.com>2009-05-08 07:21:35 +0000
commit7b81cd0caf85eef3086866ad3d09fec10cf8eceb (patch)
tree1bcb2bb9ace718f17356ed083916ad3f3d6364ac
parent0af7494b372dc1b2b4612f811c625bb0edae6dae (diff)
downloadrockbox-7b81cd0caf85eef3086866ad3d09fec10cf8eceb.tar.gz
rockbox-7b81cd0caf85eef3086866ad3d09fec10cf8eceb.zip
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
-rw-r--r--apps/recorder/jpeg_load.c149
1 files changed, 70 insertions, 79 deletions
diff --git a/apps/recorder/jpeg_load.c b/apps/recorder/jpeg_load.c
index 99ab61154d..555f60d6bd 100644
--- a/apps/recorder/jpeg_load.c
+++ b/apps/recorder/jpeg_load.c
@@ -1675,84 +1675,74 @@ static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
1675#endif 1675#endif
1676 1676
1677/* Decode a single value */ 1677/* Decode a single value */
1678INLINE int huff_decode_dc(struct jpeg *p_jpeg, struct derived_tbl* tbl) 1678#define huff_decode_dc(p_jpeg, tbl, s, r) \
1679{ 1679{ \
1680 int nb, look, s, r; 1680 int nb, look; \
1681 1681\
1682 check_bit_buffer(p_jpeg, HUFF_LOOKAHEAD); 1682 check_bit_buffer((p_jpeg), HUFF_LOOKAHEAD); \
1683 look = peek_bits(p_jpeg, HUFF_LOOKAHEAD); 1683 look = peek_bits((p_jpeg), HUFF_LOOKAHEAD); \
1684 if ((nb = tbl->look_nbits[look]) != 0) 1684 if ((nb = (tbl)->look_nbits[look]) != 0) \
1685 { 1685 { \
1686 drop_bits(p_jpeg, nb); 1686 drop_bits((p_jpeg), nb); \
1687 s = tbl->look_sym[look]; 1687 s = (tbl)->look_sym[look]; \
1688 check_bit_buffer(p_jpeg, s); 1688 check_bit_buffer((p_jpeg), s); \
1689 r = get_bits(p_jpeg, s); 1689 r = get_bits((p_jpeg), s); \
1690 s = HUFF_EXTEND(r, s); 1690 } else { \
1691 } 1691 /* slow_DECODE(s, HUFF_LOOKAHEAD+1)) < 0); */ \
1692 else 1692 long code; \
1693 { /* slow_DECODE(s, HUFF_LOOKAHEAD+1)) < 0); */ 1693 nb=HUFF_LOOKAHEAD+1; \
1694 long code; 1694 check_bit_buffer((p_jpeg), nb); \
1695 nb=HUFF_LOOKAHEAD+1; 1695 code = get_bits((p_jpeg), nb); \
1696 check_bit_buffer(p_jpeg, nb); 1696 while (code > (tbl)->maxcode[nb]) \
1697 code = get_bits(p_jpeg, nb); 1697 { \
1698 while (code > tbl->maxcode[nb]) 1698 code <<= 1; \
1699 { 1699 check_bit_buffer((p_jpeg), 1); \
1700 code <<= 1; 1700 code |= get_bits((p_jpeg), 1); \
1701 check_bit_buffer(p_jpeg, 1); 1701 nb++; \
1702 code |= get_bits(p_jpeg, 1); 1702 } \
1703 nb++; 1703 if (nb > 16) /* error in Huffman */ \
1704 } 1704 { \
1705 if (nb > 16) /* error in Huffman */ 1705 r = 0; s = 0; /* fake a zero, this is most safe */ \
1706 { 1706 } else { \
1707 s=0; /* fake a zero, this is most safe */ 1707 s = (tbl)->pub[16 + (tbl)->valptr[nb] + \
1708 } 1708 ((int) (code - (tbl)->mincode[nb]))]; \
1709 else 1709 check_bit_buffer((p_jpeg), s); \
1710 { 1710 r = get_bits((p_jpeg), s); \
1711 s = tbl->pub[16 + tbl->valptr[nb] + 1711 } \
1712 ((int) (code - tbl->mincode[nb]))]; 1712 } /* end slow decode */ \
1713 check_bit_buffer(p_jpeg, s);
1714 r = get_bits(p_jpeg, s);
1715 s = HUFF_EXTEND(r, s);
1716 }
1717 } /* end slow decode */
1718 return s;
1719} 1713}
1720 1714
1721INLINE int huff_decode_ac(struct jpeg *p_jpeg, struct derived_tbl* tbl) 1715#define huff_decode_ac(p_jpeg, tbl, s) \
1722{ 1716{ \
1723 int nb, look, s; 1717 int nb, look; \
1724 1718\
1725 check_bit_buffer(p_jpeg, HUFF_LOOKAHEAD); 1719 check_bit_buffer((p_jpeg), HUFF_LOOKAHEAD); \
1726 look = peek_bits(p_jpeg, HUFF_LOOKAHEAD); 1720 look = peek_bits((p_jpeg), HUFF_LOOKAHEAD); \
1727 if ((nb = tbl->look_nbits[look]) != 0) 1721 if ((nb = (tbl)->look_nbits[look]) != 0) \
1728 { 1722 { \
1729 drop_bits(p_jpeg, nb); 1723 drop_bits((p_jpeg), nb); \
1730 s = tbl->look_sym[look]; 1724 s = (tbl)->look_sym[look]; \
1731 } 1725 } else { \
1732 else 1726 /* slow_DECODE(s, HUFF_LOOKAHEAD+1)) < 0); */ \
1733 { /* slow_DECODE(s, HUFF_LOOKAHEAD+1)) < 0); */ 1727 long code; \
1734 long code; 1728 nb=HUFF_LOOKAHEAD+1; \
1735 nb=HUFF_LOOKAHEAD+1; 1729 check_bit_buffer((p_jpeg), nb); \
1736 check_bit_buffer(p_jpeg, nb); 1730 code = get_bits((p_jpeg), nb); \
1737 code = get_bits(p_jpeg, nb); 1731 while (code > (tbl)->maxcode[nb]) \
1738 while (code > tbl->maxcode[nb]) 1732 { \
1739 { 1733 code <<= 1; \
1740 code <<= 1; 1734 check_bit_buffer((p_jpeg), 1); \
1741 check_bit_buffer(p_jpeg, 1); 1735 code |= get_bits((p_jpeg), 1); \
1742 code |= get_bits(p_jpeg, 1); 1736 nb++; \
1743 nb++; 1737 } \
1744 } 1738 if (nb > 16) /* error in Huffman */ \
1745 if (nb > 16) /* error in Huffman */ 1739 { \
1746 { 1740 s = 0; /* fake a zero, this is most safe */ \
1747 s=0; /* fake a zero, this is most safe */ 1741 } else { \
1748 } 1742 s = (tbl)->pub[16 + (tbl)->valptr[nb] + \
1749 else 1743 ((int) (code - (tbl)->mincode[nb]))]; \
1750 { 1744 } \
1751 s = tbl->pub[16 + tbl->valptr[nb] + 1745 } /* end slow decode */ \
1752 ((int) (code - tbl->mincode[nb]))];
1753 }
1754 } /* end slow decode */
1755 return s;
1756} 1746}
1757 1747
1758static struct img_part *store_row_jpeg(void *jpeg_args) 1748static struct img_part *store_row_jpeg(void *jpeg_args)
@@ -1799,12 +1789,13 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1799 struct derived_tbl* actbl = &p_jpeg->ac_derived_tbls[ti]; 1789 struct derived_tbl* actbl = &p_jpeg->ac_derived_tbls[ti];
1800 1790
1801 /* Section F.2.2.1: decode the DC coefficient difference */ 1791 /* Section F.2.2.1: decode the DC coefficient difference */
1802 s = huff_decode_dc(p_jpeg, dctbl); 1792 huff_decode_dc(p_jpeg, dctbl, s, r);
1803 1793
1804#ifndef HAVE_LCD_COLOR 1794#ifndef HAVE_LCD_COLOR
1805 if (!ci) 1795 if (!ci)
1806#endif 1796#endif
1807 { 1797 {
1798 s = HUFF_EXTEND(r, s);
1808#ifdef HAVE_LCD_COLOR 1799#ifdef HAVE_LCD_COLOR
1809 p_jpeg->last_dc_val[ci] += s; 1800 p_jpeg->last_dc_val[ci] += s;
1810 /* output it (assumes zag[0] = 0) */ 1801 /* output it (assumes zag[0] = 0) */
@@ -1821,7 +1812,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1821 /* Section F.2.2.2: decode the AC coefficients */ 1812 /* Section F.2.2.2: decode the AC coefficients */
1822 for (; k < p_jpeg->k_need[!!ci]; k++) 1813 for (; k < p_jpeg->k_need[!!ci]; k++)
1823 { 1814 {
1824 s = huff_decode_ac(p_jpeg, actbl); 1815 huff_decode_ac(p_jpeg, actbl, s);
1825 r = s >> 4; 1816 r = s >> 4;
1826 s &= 15; 1817 s &= 15;
1827 if (s) 1818 if (s)
@@ -1851,7 +1842,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1851 } 1842 }
1852 for (; k < 64; k++) 1843 for (; k < 64; k++)
1853 { 1844 {
1854 s = huff_decode_ac(p_jpeg, actbl); 1845 huff_decode_ac(p_jpeg, actbl, s);
1855 r = s >> 4; 1846 r = s >> 4;
1856 s &= 15; 1847 s &= 15;
1857 1848