summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2009-05-07 08:32:17 +0000
committerAndrew Mahone <andrew.mahone@gmail.com>2009-05-07 08:32:17 +0000
commitd2c1298e194f35ebe371dde7c345fbe2ee054208 (patch)
tree28da0f759281dee214a03750151dde8d85c77597
parent3651a903f355ad4eb5b6bbbbb8001a7c144560fc (diff)
downloadrockbox-d2c1298e194f35ebe371dde7c345fbe2ee054208.tar.gz
rockbox-d2c1298e194f35ebe371dde7c345fbe2ee054208.zip
Never use upscaling IDCT for luma (to reduce blockiness), plus some small size optimizations by not calculating or storing scale factors or k_need/zero_need for chroma on greyscale.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20866 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/recorder/jpeg_load.c73
1 files changed, 47 insertions, 26 deletions
diff --git a/apps/recorder/jpeg_load.c b/apps/recorder/jpeg_load.c
index 14aa024fcf..1d8c9edba3 100644
--- a/apps/recorder/jpeg_load.c
+++ b/apps/recorder/jpeg_load.c
@@ -73,13 +73,17 @@ struct jpeg
73 int store_pos[4]; /* for Y block ordering */ 73 int store_pos[4]; /* for Y block ordering */
74#ifdef HAVE_LCD_COLOR 74#ifdef HAVE_LCD_COLOR
75 int last_dc_val[3]; 75 int last_dc_val[3];
76 int h_scale[2]; /* horizontal scalefactor = (2**N) / 8 */
77 int v_scale[2]; /* same as above, for vertical direction */
78 int k_need[2]; /* per component zig-zag index of last needed coefficient */
79 int zero_need[2]; /* per compenent number of coefficients to zero */
76#else 80#else
77 int last_dc_val; 81 int last_dc_val;
82 int h_scale[1]; /* horizontal scalefactor = (2**N) / 8 */
83 int v_scale[1]; /* same as above, for vertical direction */
84 int k_need[1]; /* per component zig-zag index of last needed coefficient */
85 int zero_need[1]; /* per compenent number of coefficients to zero */
78#endif 86#endif
79 int h_scale[2]; /* horizontal scalefactor = (2**N) / 8 */
80 int v_scale[2]; /* same as above, for vertical direction */
81 int k_need[3]; /* per component zig-zag index of last needed coefficient */
82 int zero_need[3]; /* per compenent number of coefficients to zero */
83 jpeg_pix_t *img_buf; 87 jpeg_pix_t *img_buf;
84 88
85 int quanttable[4][QUANT_TABLE_LENGTH]; /* raw quantization tables 0-3 */ 89 int quanttable[4][QUANT_TABLE_LENGTH]; /* raw quantization tables 0-3 */
@@ -1685,15 +1689,25 @@ INLINE int huff_decode_ac(struct jpeg *p_jpeg, struct derived_tbl* tbl)
1685static struct img_part *store_row_jpeg(void *jpeg_args) 1689static struct img_part *store_row_jpeg(void *jpeg_args)
1686{ 1690{
1687 struct jpeg *p_jpeg = (struct jpeg*) jpeg_args; 1691 struct jpeg *p_jpeg = (struct jpeg*) jpeg_args;
1688 unsigned int width = p_jpeg->x_mbl << p_jpeg->h_scale[1]; 1692#ifdef HAVE_LCD_COLOR
1693 int mcu_hscale = p_jpeg->h_scale[1];
1694 int mcu_vscale = p_jpeg->v_scale[1];
1695#else
1696 int mcu_hscale = (p_jpeg->h_scale[0] + p_jpeg->frameheader[0].horizontal_sampling - 1);
1697 int mcu_vscale = (p_jpeg->v_scale[0] + p_jpeg->frameheader[0].vertical_sampling - 1);
1698#endif
1699 unsigned int width = p_jpeg->x_mbl << mcu_hscale;
1689 unsigned int b_width = width * JPEG_PIX_SZ; 1700 unsigned int b_width = width * JPEG_PIX_SZ;
1690 int height = 1U << p_jpeg->v_scale[1]; 1701 int height = 1U << mcu_vscale;
1691 int x; 1702 int x;
1692 if (!p_jpeg->mcu_row) /* Need to decode a new row of MCUs */ 1703 if (!p_jpeg->mcu_row) /* Need to decode a new row of MCUs */
1693 { 1704 {
1694 p_jpeg->out_ptr = (unsigned char *)p_jpeg->img_buf; 1705 p_jpeg->out_ptr = (unsigned char *)p_jpeg->img_buf;
1695 int store_offs[4]; 1706 int store_offs[4];
1696 int mcu_offset = JPEG_PIX_SZ << p_jpeg->h_scale[1]; 1707#ifdef HAVE_LCD_COLOR
1708 unsigned mcu_width = 1U << mcu_hscale;
1709#endif
1710 int mcu_offset = JPEG_PIX_SZ << mcu_hscale;
1697 unsigned char *out = p_jpeg->out_ptr; 1711 unsigned char *out = p_jpeg->out_ptr;
1698 store_offs[p_jpeg->store_pos[0]] = 0; 1712 store_offs[p_jpeg->store_pos[0]] = 0;
1699 store_offs[p_jpeg->store_pos[1]] = JPEG_PIX_SZ << p_jpeg->h_scale[0]; 1713 store_offs[p_jpeg->store_pos[1]] = JPEG_PIX_SZ << p_jpeg->h_scale[0];
@@ -1729,7 +1743,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1729 p_jpeg->last_dc_val += s; 1743 p_jpeg->last_dc_val += s;
1730 /* output it (assumes zag[0] = 0) */ 1744 /* output it (assumes zag[0] = 0) */
1731 block[0] = p_jpeg->last_dc_val * 1745 block[0] = p_jpeg->last_dc_val *
1732 p_jpeg->quanttable[!!ci][0]; 1746 p_jpeg->quanttable[0][0];
1733#endif 1747#endif
1734 /* coefficient buffer must be cleared */ 1748 /* coefficient buffer must be cleared */
1735 MEMSET(block+1, 0, p_jpeg->zero_need[!!ci] * sizeof(int)); 1749 MEMSET(block+1, 0, p_jpeg->zero_need[!!ci] * sizeof(int));
@@ -1787,13 +1801,12 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1787 if (!ci) 1801 if (!ci)
1788#endif 1802#endif
1789 { 1803 {
1790 unsigned char si = !!ci; 1804 int idct_cols = 1 << MIN(p_jpeg->h_scale[!!ci], 3);
1791 int idct_cols = 1 << MIN(p_jpeg->h_scale[si], 3); 1805 int idct_rows = 1 << p_jpeg->v_scale[!!ci];
1792 int idct_rows = 1 << p_jpeg->v_scale[si];
1793 unsigned char *b_out = out + (ci ? ci : store_offs[blkn]); 1806 unsigned char *b_out = out + (ci ? ci : store_offs[blkn]);
1794 if (idct_tbl[p_jpeg->v_scale[si]].v_idct) 1807 if (idct_tbl[p_jpeg->v_scale[!!ci]].v_idct)
1795 idct_tbl[p_jpeg->v_scale[si]].v_idct(block, idct_cols); 1808 idct_tbl[p_jpeg->v_scale[!!ci]].v_idct(block, idct_cols);
1796 idct_tbl[p_jpeg->h_scale[si]].h_idct(block, b_out, 1809 idct_tbl[p_jpeg->h_scale[!!ci]].h_idct(block, b_out,
1797 idct_rows, b_width); 1810 idct_rows, b_width);
1798 } 1811 }
1799 } /* for blkn */ 1812 } /* for blkn */
@@ -1808,8 +1821,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1808 for (yp = 0; yp < height; yp++, row += b_width) 1821 for (yp = 0; yp < height; yp++, row += b_width)
1809 { 1822 {
1810 unsigned char *px = row; 1823 unsigned char *px = row;
1811 for (xp = 0; xp < 1U << p_jpeg->h_scale[1]; 1824 for (xp = 0; xp < mcu_width; xp++, px += JPEG_PIX_SZ)
1812 xp++, px += JPEG_PIX_SZ)
1813 { 1825 {
1814 px[1] = px[2] = px[0]; 1826 px[1] = px[2] = px[0];
1815 } 1827 }
@@ -1863,11 +1875,11 @@ int read_jpeg_file(const char* filename,
1863 return ret; 1875 return ret;
1864} 1876}
1865 1877
1866static int calc_scale(int in_size, int out_size, int subsample) 1878static int calc_scale(int in_size, int out_size)
1867{ 1879{
1868 int scale = 0; 1880 int scale = 0;
1869 out_size <<= 3; 1881 out_size <<= 3;
1870 for (scale = 0; scale < 5 - subsample; scale++) 1882 for (scale = 0; scale < 3; scale++)
1871 { 1883 {
1872 if (out_size <= in_size) 1884 if (out_size <= in_size)
1873 break; 1885 break;
@@ -1926,25 +1938,27 @@ int read_jpeg_fd(int fd,
1926 bm->width = p_jpeg->x_size; 1938 bm->width = p_jpeg->x_size;
1927 bm->height = p_jpeg->y_size; 1939 bm->height = p_jpeg->y_size;
1928 } 1940 }
1929 p_jpeg->h_scale[0] = calc_scale(p_jpeg->x_size, bm->width, 1941 p_jpeg->h_scale[0] = calc_scale(p_jpeg->x_size, bm->width);
1930 p_jpeg->frameheader[0].horizontal_sampling); 1942 p_jpeg->v_scale[0] = calc_scale(p_jpeg->y_size, bm->height);
1931 p_jpeg->v_scale[0] = calc_scale(p_jpeg->y_size, bm->height, 1943#ifdef HAVE_LCD_COLOR
1932 p_jpeg->frameheader[0].vertical_sampling);
1933 p_jpeg->h_scale[1] = p_jpeg->h_scale[0] + 1944 p_jpeg->h_scale[1] = p_jpeg->h_scale[0] +
1934 p_jpeg->frameheader[0].horizontal_sampling - 1; 1945 p_jpeg->frameheader[0].horizontal_sampling - 1;
1935 p_jpeg->v_scale[1] = p_jpeg->v_scale[0] + 1946 p_jpeg->v_scale[1] = p_jpeg->v_scale[0] +
1936 p_jpeg->frameheader[0].vertical_sampling - 1; 1947 p_jpeg->frameheader[0].vertical_sampling - 1;
1948#endif
1937 fix_quant_tables(p_jpeg); 1949 fix_quant_tables(p_jpeg);
1938 int decode_w = (1 << MIN(p_jpeg->h_scale[0],3)) - 1; 1950 int decode_w = (1 << p_jpeg->h_scale[0]) - 1;
1939 int decode_h = (1 << MIN(p_jpeg->v_scale[0],3)) - 1; 1951 int decode_h = (1 << p_jpeg->v_scale[0]) - 1;
1940 src_dim.width = (p_jpeg->x_size << p_jpeg->h_scale[0]) >> 3; 1952 src_dim.width = (p_jpeg->x_size << p_jpeg->h_scale[0]) >> 3;
1941 src_dim.height = (p_jpeg->y_size << p_jpeg->v_scale[0]) >> 3; 1953 src_dim.height = (p_jpeg->y_size << p_jpeg->v_scale[0]) >> 3;
1942 p_jpeg->zero_need[0] = (decode_h << 3) + decode_w; 1954 p_jpeg->zero_need[0] = (decode_h << 3) + decode_w;
1943 p_jpeg->k_need[0] = zig[p_jpeg->zero_need[0]]; 1955 p_jpeg->k_need[0] = zig[p_jpeg->zero_need[0]];
1956#ifdef HAVE_LCD_COLOR
1944 decode_w = (1 << MIN(p_jpeg->h_scale[1],3)) - 1; 1957 decode_w = (1 << MIN(p_jpeg->h_scale[1],3)) - 1;
1945 decode_h = (1 << MIN(p_jpeg->v_scale[1],3)) - 1; 1958 decode_h = (1 << MIN(p_jpeg->v_scale[1],3)) - 1;
1946 p_jpeg->zero_need[1] = p_jpeg->zero_need[2] = (decode_h << 3) + decode_w; 1959 p_jpeg->zero_need[1] = (decode_h << 3) + decode_w;
1947 p_jpeg->k_need[1] = p_jpeg->k_need[2] = zig[p_jpeg->zero_need[1]]; 1960 p_jpeg->k_need[1] = zig[p_jpeg->zero_need[1]];
1961#endif
1948 if (cformat) 1962 if (cformat)
1949 bm_size = cformat->get_size(bm); 1963 bm_size = cformat->get_size(bm);
1950 else 1964 else
@@ -1962,8 +1976,15 @@ int read_jpeg_fd(int fd,
1962 fix_huff_tables(p_jpeg); 1976 fix_huff_tables(p_jpeg);
1963 buf_start += sizeof(struct jpeg); 1977 buf_start += sizeof(struct jpeg);
1964 maxsize = buf_end - buf_start; 1978 maxsize = buf_end - buf_start;
1979#ifdef HAVE_LCD_COLOR
1965 int decode_buf_size = (p_jpeg->x_mbl << p_jpeg->h_scale[1]) 1980 int decode_buf_size = (p_jpeg->x_mbl << p_jpeg->h_scale[1])
1966 << p_jpeg->v_scale[1]; 1981 << p_jpeg->v_scale[1];
1982#else
1983 int decode_buf_size = (p_jpeg->x_mbl << p_jpeg->h_scale[0])
1984 << p_jpeg->v_scale[0];
1985 decode_buf_size <<= p_jpeg->frameheader[0].horizontal_sampling +
1986 p_jpeg->frameheader[0].vertical_sampling - 2;
1987#endif
1967 decode_buf_size *= JPEG_PIX_SZ; 1988 decode_buf_size *= JPEG_PIX_SZ;
1968 p_jpeg->img_buf = (jpeg_pix_t *)buf_start; 1989 p_jpeg->img_buf = (jpeg_pix_t *)buf_start;
1969 if (buf_end - buf_start < decode_buf_size) 1990 if (buf_end - buf_start < decode_buf_size)