123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368 |
- #define JPEG_INTERNALS
- #include "jinclude.h"
- #include "jpeglib.h"
- #include "jdct.h"
- #ifdef DCT_IFAST_SUPPORTED
- #if DCTSIZE != 8
- Sorry, this code only copes with 8x8 DCTs.
- #endif
- #if BITS_IN_JSAMPLE == 8
- #define CONST_BITS 8
- #define PASS1_BITS 2
- #else
- #define CONST_BITS 8
- #define PASS1_BITS 1
- #endif
- #if CONST_BITS == 8
- #define FIX_1_082392200 ((INT32) 277)
- #define FIX_1_414213562 ((INT32) 362)
- #define FIX_1_847759065 ((INT32) 473)
- #define FIX_2_613125930 ((INT32) 669)
- #else
- #define FIX_1_082392200 FIX(1.082392200)
- #define FIX_1_414213562 FIX(1.414213562)
- #define FIX_1_847759065 FIX(1.847759065)
- #define FIX_2_613125930 FIX(2.613125930)
- #endif
- #ifndef USE_ACCURATE_ROUNDING
- #undef DESCALE
- #define DESCALE(x,n) RIGHT_SHIFT(x, n)
- #endif
- #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
- #if BITS_IN_JSAMPLE == 8
- #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
- #else
- #define DEQUANTIZE(coef,quantval) \
- DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
- #endif
- #ifdef RIGHT_SHIFT_IS_UNSIGNED
- #define ISHIFT_TEMPS DCTELEM ishift_temp;
- #if BITS_IN_JSAMPLE == 8
- #define DCTELEMBITS 16
- #else
- #define DCTELEMBITS 32
- #endif
- #define IRIGHT_SHIFT(x,shft) \
- ((ishift_temp = (x)) < 0 ? \
- (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
- (ishift_temp >> (shft)))
- #else
- #define ISHIFT_TEMPS
- #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
- #endif
- #ifdef USE_ACCURATE_ROUNDING
- #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
- #else
- #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
- #endif
- /*
- * Perform dequantization and inverse DCT on one block of coefficients.
- */
- GLOBAL void
- jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
- JCOEFPTR coef_block,
- JSAMPARRAY output_buf, JDIMENSION output_col)
- {
- DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
- DCTELEM tmp10, tmp11, tmp12, tmp13;
- DCTELEM z5, z10, z11, z12, z13;
- JCOEFPTR inptr;
- IFAST_MULT_TYPE * quantptr;
- int * wsptr;
- JSAMPROW outptr;
- JSAMPLE *range_limit = IDCT_range_limit(cinfo);
- int ctr;
- int workspace[DCTSIZE2]; /* buffers data between passes */
- SHIFT_TEMPS /* for DESCALE */
- ISHIFT_TEMPS /* for IDESCALE */
- /* Pass 1: process columns from input, store into work array. */
- inptr = coef_block;
- quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
- wsptr = workspace;
- for (ctr = DCTSIZE; ctr > 0; ctr--) {
-
-
- if ((inptr[DCTSIZE*1] | inptr[DCTSIZE*2] | inptr[DCTSIZE*3] |
- inptr[DCTSIZE*4] | inptr[DCTSIZE*5] | inptr[DCTSIZE*6] |
- inptr[DCTSIZE*7]) == 0) {
-
- int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- wsptr[DCTSIZE*0] = dcval;
- wsptr[DCTSIZE*1] = dcval;
- wsptr[DCTSIZE*2] = dcval;
- wsptr[DCTSIZE*3] = dcval;
- wsptr[DCTSIZE*4] = dcval;
- wsptr[DCTSIZE*5] = dcval;
- wsptr[DCTSIZE*6] = dcval;
- wsptr[DCTSIZE*7] = dcval;
-
- inptr++;
- quantptr++;
- wsptr++;
- continue;
- }
-
-
- tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
- tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
- tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
- tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
- tmp10 = tmp0 + tmp2;
- tmp11 = tmp0 - tmp2;
- tmp13 = tmp1 + tmp3;
- tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13;
- tmp0 = tmp10 + tmp13;
- tmp3 = tmp10 - tmp13;
- tmp1 = tmp11 + tmp12;
- tmp2 = tmp11 - tmp12;
-
-
- tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
- tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
- tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
- tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
- z13 = tmp6 + tmp5;
- z10 = tmp6 - tmp5;
- z11 = tmp4 + tmp7;
- z12 = tmp4 - tmp7;
- tmp7 = z11 + z13;
- tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);
- z5 = MULTIPLY(z10 + z12, FIX_1_847759065);
- tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;
- tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;
- tmp6 = tmp12 - tmp7;
- tmp5 = tmp11 - tmp6;
- tmp4 = tmp10 + tmp5;
- wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
- wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
- wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
- wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
- wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
- wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
- wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
- wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
- inptr++;
- quantptr++;
- wsptr++;
- }
-
-
-
-
- wsptr = workspace;
- for (ctr = 0; ctr < DCTSIZE; ctr++) {
- outptr = output_buf[ctr] + output_col;
-
-
- #ifndef NO_ZERO_ROW_TEST
- if ((wsptr[1] | wsptr[2] | wsptr[3] | wsptr[4] | wsptr[5] | wsptr[6] |
- wsptr[7]) == 0) {
-
- JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
- & RANGE_MASK];
-
- outptr[0] = dcval;
- outptr[1] = dcval;
- outptr[2] = dcval;
- outptr[3] = dcval;
- outptr[4] = dcval;
- outptr[5] = dcval;
- outptr[6] = dcval;
- outptr[7] = dcval;
- wsptr += DCTSIZE;
- continue;
- }
- #endif
-
-
- tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
- tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
- tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
- tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
- - tmp13;
- tmp0 = tmp10 + tmp13;
- tmp3 = tmp10 - tmp13;
- tmp1 = tmp11 + tmp12;
- tmp2 = tmp11 - tmp12;
-
- z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
- z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
- z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
- z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
- tmp7 = z11 + z13;
- tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562);
- z5 = MULTIPLY(z10 + z12, FIX_1_847759065);
- tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5;
- tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5;
- tmp6 = tmp12 - tmp7;
- tmp5 = tmp11 - tmp6;
- tmp4 = tmp10 + tmp5;
-
- outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
- & RANGE_MASK];
- outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
- & RANGE_MASK];
- outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
- & RANGE_MASK];
- outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
- & RANGE_MASK];
- outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
- & RANGE_MASK];
- outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
- & RANGE_MASK];
- outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
- & RANGE_MASK];
- outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
- & RANGE_MASK];
- wsptr += DCTSIZE;
- }
- }
- #endif
|