summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/recorder/jpeg_load.c84
1 files changed, 41 insertions, 43 deletions
diff --git a/apps/recorder/jpeg_load.c b/apps/recorder/jpeg_load.c
index 754cf41ab1..d1f47d7a33 100644
--- a/apps/recorder/jpeg_load.c
+++ b/apps/recorder/jpeg_load.c
@@ -96,7 +96,7 @@ struct jpeg
96#endif 96#endif
97 jpeg_pix_t *img_buf; 97 jpeg_pix_t *img_buf;
98 98
99 int quanttable[4][QUANT_TABLE_LENGTH]; /* raw quantization tables 0-3 */ 99 int16_t quanttable[4][QUANT_TABLE_LENGTH];/* raw quantization tables 0-3 */
100 100
101 struct huffman_table hufftable[2]; /* Huffman tables */ 101 struct huffman_table hufftable[2]; /* Huffman tables */
102 struct derived_tbl dc_derived_tbls[2]; /* Huffman-LUTs */ 102 struct derived_tbl dc_derived_tbls[2]; /* Huffman-LUTs */
@@ -206,10 +206,15 @@ INLINE unsigned range_limit(int value)
206* 16x16->32 bit multiply can be used instead of a full 32x32 multiply. 206* 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
207* For 12-bit samples, a full 32-bit multiplication will be needed. 207* For 12-bit samples, a full 32-bit multiplication will be needed.
208*/ 208*/
209#define MULTIPLY16(var,const) (((short) (var)) * ((short) (const)))
210
211#define MULTIPLY(var1, var2) ((var1) * (var2)) 209#define MULTIPLY(var1, var2) ((var1) * (var2))
212 210
211#if defined(CPU_SH) || defined(CPU_COLDFIRE) || \
212 (defined(CPU_ARM) && ARM_ARCH > 4)
213#define MULTIPLY16(var,const) (((short) (var)) * ((short) (const)))
214#else
215#define MULTIPLY16 MULTIPLY
216#endif
217
213/* 218/*
214 * Macros for handling fixed-point arithmetic; these are used by many 219 * Macros for handling fixed-point arithmetic; these are used by many
215 * but not all of the DCT/IDCT modules. 220 * but not all of the DCT/IDCT modules.
@@ -255,19 +260,19 @@ INLINE unsigned range_limit(int value)
255#define COMPONENT_SHIFT 15 260#define COMPONENT_SHIFT 15
256 261
257/* horizontal-pass 1-point IDCT */ 262/* horizontal-pass 1-point IDCT */
258static void idct1h(int *ws, unsigned char *out, int rows, int rowstep) 263static void idct1h(int16_t *ws, unsigned char *out, int rows, int rowstep)
259{ 264{
260 int row; 265 int row;
261 for (row = 0; row < rows; row++) 266 for (row = 0; row < rows; row++)
262 { 267 {
263 *out = range_limit((int) DESCALE(*ws, DS_OUT)); 268 *out = range_limit((int) DESCALE(*ws, 3 + PASS1_BITS));
264 out += rowstep; 269 out += rowstep;
265 ws += 8; 270 ws += 8;
266 } 271 }
267} 272}
268 273
269/* vertical-pass 2-point IDCT */ 274/* vertical-pass 2-point IDCT */
270static void idct2v(int *ws, int cols) 275static void idct2v(int16_t *ws, int cols)
271{ 276{
272 int col; 277 int col;
273 for (col = 0; col < cols; col++) 278 for (col = 0; col < cols; col++)
@@ -281,30 +286,30 @@ static void idct2v(int *ws, int cols)
281} 286}
282 287
283/* horizontal-pass 2-point IDCT */ 288/* horizontal-pass 2-point IDCT */
284static void idct2h(int *ws, unsigned char *out, int rows, int rowstep) 289static void idct2h(int16_t *ws, unsigned char *out, int rows, int rowstep)
285{ 290{
286 int row; 291 int row;
287 for (row = 0; row < rows; row++) 292 for (row = 0; row < rows; row++)
288 { 293 {
289 int tmp1 = ws[0] + (ONE << (DS_OUT - 1)); 294 int tmp1 = ws[0] + (ONE << (PASS1_BITS + 2));
290 int tmp2 = ws[1]; 295 int tmp2 = ws[1];
291 out[JPEG_PIX_SZ*0] = range_limit((int) RIGHT_SHIFT(tmp1 + tmp2, 296 out[JPEG_PIX_SZ*0] = range_limit((int) RIGHT_SHIFT(tmp1 + tmp2,
292 DS_OUT)); 297 PASS1_BITS + 3));
293 out[JPEG_PIX_SZ*1] = range_limit((int) RIGHT_SHIFT(tmp1 - tmp2, 298 out[JPEG_PIX_SZ*1] = range_limit((int) RIGHT_SHIFT(tmp1 - tmp2,
294 DS_OUT)); 299 PASS1_BITS + 3));
295 out += rowstep; 300 out += rowstep;
296 ws += 8; 301 ws += 8;
297 } 302 }
298} 303}
299 304
300/* vertical-pass 4-point IDCT */ 305/* vertical-pass 4-point IDCT */
301static void idct4v(int *ws, int cols) 306static void idct4v(int16_t *ws, int cols)
302{ 307{
303 int tmp0, tmp2, tmp10, tmp12;
304 int z1, z2, z3;
305 int col; 308 int col;
306 for (col = 0; col < cols; col++, ws++) 309 for (col = 0; col < cols; col++, ws++)
307 { 310 {
311 int tmp0, tmp2, tmp10, tmp12;
312 int z1, z2, z3;
308 /* Even part */ 313 /* Even part */
309 314
310 tmp0 = ws[8*0]; 315 tmp0 = ws[8*0];
@@ -336,7 +341,7 @@ static void idct4v(int *ws, int cols)
336} 341}
337 342
338/* horizontal-pass 4-point IDCT */ 343/* horizontal-pass 4-point IDCT */
339static void idct4h(int *ws, unsigned char *out, int rows, int rowstep) 344static void idct4h(int16_t *ws, unsigned char *out, int rows, int rowstep)
340{ 345{
341 int tmp0, tmp2, tmp10, tmp12; 346 int tmp0, tmp2, tmp10, tmp12;
342 int z1, z2, z3; 347 int z1, z2, z3;
@@ -375,7 +380,7 @@ static void idct4h(int *ws, unsigned char *out, int rows, int rowstep)
375} 380}
376 381
377/* vertical-pass 8-point IDCT */ 382/* vertical-pass 8-point IDCT */
378static void idct8v(int *ws, int cols) 383static void idct8v(int16_t *ws, int cols)
379{ 384{
380 long tmp0, tmp1, tmp2, tmp3; 385 long tmp0, tmp1, tmp2, tmp3;
381 long tmp10, tmp11, tmp12, tmp13; 386 long tmp10, tmp11, tmp12, tmp13;
@@ -469,7 +474,7 @@ static void idct8v(int *ws, int cols)
469} 474}
470 475
471/* horizontal-pass 8-point IDCT */ 476/* horizontal-pass 8-point IDCT */
472static void idct8h(int *ws, unsigned char *out, int rows, int rowstep) 477static void idct8h(int16_t *ws, unsigned char *out, int rows, int rowstep)
473{ 478{
474 long tmp0, tmp1, tmp2, tmp3; 479 long tmp0, tmp1, tmp2, tmp3;
475 long tmp10, tmp11, tmp12, tmp13; 480 long tmp10, tmp11, tmp12, tmp13;
@@ -580,7 +585,7 @@ static void idct8h(int *ws, unsigned char *out, int rows, int rowstep)
580 585
581#ifdef HAVE_LCD_COLOR 586#ifdef HAVE_LCD_COLOR
582/* vertical-pass 16-point IDCT */ 587/* vertical-pass 16-point IDCT */
583static void idct16v(int *ws, int cols) 588static void idct16v(int16_t *ws, int cols)
584{ 589{
585 long tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13; 590 long tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;
586 long tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27; 591 long tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
@@ -687,7 +692,7 @@ static void idct16v(int *ws, int cols)
687} 692}
688 693
689/* horizontal-pass 16-point IDCT */ 694/* horizontal-pass 16-point IDCT */
690static void idct16h(int *ws, unsigned char *out, int rows, int rowstep) 695static void idct16h(int16_t *ws, unsigned char *out, int rows, int rowstep)
691{ 696{
692 long tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13; 697 long tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;
693 long tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27; 698 long tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;
@@ -812,19 +817,18 @@ static void idct16h(int *ws, unsigned char *out, int rows, int rowstep)
812#endif 817#endif
813 818
814struct idct_entry { 819struct idct_entry {
815 int v_scale; 820 int scale;
816 int h_scale; 821 void (*v_idct)(int16_t *ws, int cols);
817 void (*v_idct)(int *ws, int cols); 822 void (*h_idct)(int16_t *ws, unsigned char *out, int rows, int rowstep);
818 void (*h_idct)(int *ws, unsigned char *out, int rows, int rowstep);
819}; 823};
820 824
821struct idct_entry idct_tbl[] = { 825struct idct_entry idct_tbl[] = {
822 { PASS1_BITS, CONST_BITS, NULL, idct1h }, 826 { PASS1_BITS, NULL, idct1h },
823 { PASS1_BITS, CONST_BITS, idct2v, idct2h }, 827 { PASS1_BITS, idct2v, idct2h },
824 { 0, 0, idct4v, idct4h }, 828 { 0, idct4v, idct4h },
825 { 0, 0, idct8v, idct8h }, 829 { 0, idct8v, idct8h },
826#ifdef HAVE_LCD_COLOR 830#ifdef HAVE_LCD_COLOR
827 { 0, 0, idct16v, idct16h }, 831 { 0, idct16v, idct16h },
828#endif 832#endif
829}; 833};
830 834
@@ -1506,20 +1510,14 @@ INLINE void fix_huff_tables(struct jpeg *p_jpeg)
1506 */ 1510 */
1507INLINE void fix_quant_tables(struct jpeg *p_jpeg) 1511INLINE void fix_quant_tables(struct jpeg *p_jpeg)
1508{ 1512{
1509 int shift, i, x, y, a; 1513 int shift, i, j;
1510 for (i = 0; i < 2; i++) 1514 for (i = 0; i < 2; i++)
1511 { 1515 {
1512 shift = idct_tbl[p_jpeg->v_scale[i]].v_scale + 1516 shift = idct_tbl[p_jpeg->v_scale[i]].scale;
1513 idct_tbl[p_jpeg->h_scale[i]].h_scale;
1514 if (shift) 1517 if (shift)
1515 { 1518 {
1516 a = 0; 1519 for (j = 0; j < 64; j++)
1517 for (y = 0; y < (int)BIT_N(p_jpeg->h_scale[i]); y++) 1520 p_jpeg->quanttable[i][j] <<= shift;
1518 {
1519 for (x = 0; x < (int)BIT_N(p_jpeg->v_scale[i]); x++)
1520 p_jpeg->quanttable[i][zig[a+x]] <<= shift;
1521 a += 8;
1522 }
1523 } 1521 }
1524 } 1522 }
1525} 1523}
@@ -1780,7 +1778,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1780 store_offs[p_jpeg->store_pos[2]] = b_width << p_jpeg->v_scale[0]; 1778 store_offs[p_jpeg->store_pos[2]] = b_width << p_jpeg->v_scale[0];
1781 store_offs[p_jpeg->store_pos[3]] = store_offs[1] + store_offs[2]; 1779 store_offs[p_jpeg->store_pos[3]] = store_offs[1] + store_offs[2];
1782 1780
1783 int block[128]; /* decoded DCT coefficients */ 1781 int16_t block[128]; /* decoded DCT coefficients */
1784 for (x = 0; x < p_jpeg->x_mbl; x++) 1782 for (x = 0; x < p_jpeg->x_mbl; x++)
1785 { 1783 {
1786 int blkn; 1784 int blkn;
@@ -1804,13 +1802,13 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1804#ifdef HAVE_LCD_COLOR 1802#ifdef HAVE_LCD_COLOR
1805 p_jpeg->last_dc_val[ci] += s; 1803 p_jpeg->last_dc_val[ci] += s;
1806 /* output it (assumes zag[0] = 0) */ 1804 /* output it (assumes zag[0] = 0) */
1807 block[0] = p_jpeg->last_dc_val[ci] * 1805 block[0] = MULTIPLY16(p_jpeg->last_dc_val[ci],
1808 p_jpeg->quanttable[!!ci][0]; 1806 p_jpeg->quanttable[!!ci][0]);
1809#else 1807#else
1810 p_jpeg->last_dc_val += s; 1808 p_jpeg->last_dc_val += s;
1811 /* output it (assumes zag[0] = 0) */ 1809 /* output it (assumes zag[0] = 0) */
1812 block[0] = p_jpeg->last_dc_val * 1810 block[0] = MULTIPLY16(p_jpeg->last_dc_val,
1813 p_jpeg->quanttable[0][0]; 1811 p_jpeg->quanttable[0][0]);
1814#endif 1812#endif
1815 /* coefficient buffer must be cleared */ 1813 /* coefficient buffer must be cleared */
1816 MEMSET(block+1, 0, p_jpeg->zero_need[!!ci] * sizeof(int)); 1814 MEMSET(block+1, 0, p_jpeg->zero_need[!!ci] * sizeof(int));
@@ -1830,7 +1828,7 @@ static struct img_part *store_row_jpeg(void *jpeg_args)
1830 if (a <= zag[p_jpeg->k_need[!!ci]] && (a & 7) <= 1828 if (a <= zag[p_jpeg->k_need[!!ci]] && (a & 7) <=
1831 (zag[p_jpeg->k_need[!!ci]] & 7)) 1829 (zag[p_jpeg->k_need[!!ci]] & 7))
1832 { 1830 {
1833 r *= p_jpeg->quanttable[!!ci][k]; 1831 r = MULTIPLY16(r, p_jpeg->quanttable[!!ci][k]);
1834 block[zag[k]] = r ; 1832 block[zag[k]] = r ;
1835 } 1833 }
1836 } 1834 }