Final 350 project
Dependencies: uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed
includes/jidctfst.c@0:791a779d6220, 2017-07-31 (annotated)
- Committer:
- shoaib_ahmed
- Date:
- Mon Jul 31 09:16:35 2017 +0000
- Revision:
- 0:791a779d6220
final project;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shoaib_ahmed | 0:791a779d6220 | 1 | /* |
shoaib_ahmed | 0:791a779d6220 | 2 | * jidctfst.c |
shoaib_ahmed | 0:791a779d6220 | 3 | * |
shoaib_ahmed | 0:791a779d6220 | 4 | * Copyright (C) 1994-1998, Thomas G. Lane. |
shoaib_ahmed | 0:791a779d6220 | 5 | * Modified 2015 by Guido Vollbeding. |
shoaib_ahmed | 0:791a779d6220 | 6 | * This file is part of the Independent JPEG Group's software. |
shoaib_ahmed | 0:791a779d6220 | 7 | * For conditions of distribution and use, see the accompanying README file. |
shoaib_ahmed | 0:791a779d6220 | 8 | * |
shoaib_ahmed | 0:791a779d6220 | 9 | * This file contains a fast, not so accurate integer implementation of the |
shoaib_ahmed | 0:791a779d6220 | 10 | * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine |
shoaib_ahmed | 0:791a779d6220 | 11 | * must also perform dequantization of the input coefficients. |
shoaib_ahmed | 0:791a779d6220 | 12 | * |
shoaib_ahmed | 0:791a779d6220 | 13 | * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT |
shoaib_ahmed | 0:791a779d6220 | 14 | * on each row (or vice versa, but it's more convenient to emit a row at |
shoaib_ahmed | 0:791a779d6220 | 15 | * a time). Direct algorithms are also available, but they are much more |
shoaib_ahmed | 0:791a779d6220 | 16 | * complex and seem not to be any faster when reduced to code. |
shoaib_ahmed | 0:791a779d6220 | 17 | * |
shoaib_ahmed | 0:791a779d6220 | 18 | * This implementation is based on Arai, Agui, and Nakajima's algorithm for |
shoaib_ahmed | 0:791a779d6220 | 19 | * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in |
shoaib_ahmed | 0:791a779d6220 | 20 | * Japanese, but the algorithm is described in the Pennebaker & Mitchell |
shoaib_ahmed | 0:791a779d6220 | 21 | * JPEG textbook (see REFERENCES section in file README). The following code |
shoaib_ahmed | 0:791a779d6220 | 22 | * is based directly on figure 4-8 in P&M. |
shoaib_ahmed | 0:791a779d6220 | 23 | * While an 8-point DCT cannot be done in less than 11 multiplies, it is |
shoaib_ahmed | 0:791a779d6220 | 24 | * possible to arrange the computation so that many of the multiplies are |
shoaib_ahmed | 0:791a779d6220 | 25 | * simple scalings of the final outputs. These multiplies can then be |
shoaib_ahmed | 0:791a779d6220 | 26 | * folded into the multiplications or divisions by the JPEG quantization |
shoaib_ahmed | 0:791a779d6220 | 27 | * table entries. The AA&N method leaves only 5 multiplies and 29 adds |
shoaib_ahmed | 0:791a779d6220 | 28 | * to be done in the DCT itself. |
shoaib_ahmed | 0:791a779d6220 | 29 | * The primary disadvantage of this method is that with fixed-point math, |
shoaib_ahmed | 0:791a779d6220 | 30 | * accuracy is lost due to imprecise representation of the scaled |
shoaib_ahmed | 0:791a779d6220 | 31 | * quantization values. The smaller the quantization table entry, the less |
shoaib_ahmed | 0:791a779d6220 | 32 | * precise the scaled value, so this implementation does worse with high- |
shoaib_ahmed | 0:791a779d6220 | 33 | * quality-setting files than with low-quality ones. |
shoaib_ahmed | 0:791a779d6220 | 34 | */ |
shoaib_ahmed | 0:791a779d6220 | 35 | |
shoaib_ahmed | 0:791a779d6220 | 36 | #define JPEG_INTERNALS |
shoaib_ahmed | 0:791a779d6220 | 37 | #include "jinclude.h" |
shoaib_ahmed | 0:791a779d6220 | 38 | #include "jpeglib.h" |
shoaib_ahmed | 0:791a779d6220 | 39 | #include "jdct.h" /* Private declarations for DCT subsystem */ |
shoaib_ahmed | 0:791a779d6220 | 40 | |
shoaib_ahmed | 0:791a779d6220 | 41 | #ifdef DCT_IFAST_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 42 | |
shoaib_ahmed | 0:791a779d6220 | 43 | |
shoaib_ahmed | 0:791a779d6220 | 44 | /* |
shoaib_ahmed | 0:791a779d6220 | 45 | * This module is specialized to the case DCTSIZE = 8. |
shoaib_ahmed | 0:791a779d6220 | 46 | */ |
shoaib_ahmed | 0:791a779d6220 | 47 | |
shoaib_ahmed | 0:791a779d6220 | 48 | #if DCTSIZE != 8 |
shoaib_ahmed | 0:791a779d6220 | 49 | Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ |
shoaib_ahmed | 0:791a779d6220 | 50 | #endif |
shoaib_ahmed | 0:791a779d6220 | 51 | |
shoaib_ahmed | 0:791a779d6220 | 52 | |
shoaib_ahmed | 0:791a779d6220 | 53 | /* Scaling decisions are generally the same as in the LL&M algorithm; |
shoaib_ahmed | 0:791a779d6220 | 54 | * see jidctint.c for more details. However, we choose to descale |
shoaib_ahmed | 0:791a779d6220 | 55 | * (right shift) multiplication products as soon as they are formed, |
shoaib_ahmed | 0:791a779d6220 | 56 | * rather than carrying additional fractional bits into subsequent additions. |
shoaib_ahmed | 0:791a779d6220 | 57 | * This compromises accuracy slightly, but it lets us save a few shifts. |
shoaib_ahmed | 0:791a779d6220 | 58 | * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples) |
shoaib_ahmed | 0:791a779d6220 | 59 | * everywhere except in the multiplications proper; this saves a good deal |
shoaib_ahmed | 0:791a779d6220 | 60 | * of work on 16-bit-int machines. |
shoaib_ahmed | 0:791a779d6220 | 61 | * |
shoaib_ahmed | 0:791a779d6220 | 62 | * The dequantized coefficients are not integers because the AA&N scaling |
shoaib_ahmed | 0:791a779d6220 | 63 | * factors have been incorporated. We represent them scaled up by PASS1_BITS, |
shoaib_ahmed | 0:791a779d6220 | 64 | * so that the first and second IDCT rounds have the same input scaling. |
shoaib_ahmed | 0:791a779d6220 | 65 | * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to |
shoaib_ahmed | 0:791a779d6220 | 66 | * avoid a descaling shift; this compromises accuracy rather drastically |
shoaib_ahmed | 0:791a779d6220 | 67 | * for small quantization table entries, but it saves a lot of shifts. |
shoaib_ahmed | 0:791a779d6220 | 68 | * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway, |
shoaib_ahmed | 0:791a779d6220 | 69 | * so we use a much larger scaling factor to preserve accuracy. |
shoaib_ahmed | 0:791a779d6220 | 70 | * |
shoaib_ahmed | 0:791a779d6220 | 71 | * A final compromise is to represent the multiplicative constants to only |
shoaib_ahmed | 0:791a779d6220 | 72 | * 8 fractional bits, rather than 13. This saves some shifting work on some |
shoaib_ahmed | 0:791a779d6220 | 73 | * machines, and may also reduce the cost of multiplication (since there |
shoaib_ahmed | 0:791a779d6220 | 74 | * are fewer one-bits in the constants). |
shoaib_ahmed | 0:791a779d6220 | 75 | */ |
shoaib_ahmed | 0:791a779d6220 | 76 | |
shoaib_ahmed | 0:791a779d6220 | 77 | #if BITS_IN_JSAMPLE == 8 |
shoaib_ahmed | 0:791a779d6220 | 78 | #define CONST_BITS 8 |
shoaib_ahmed | 0:791a779d6220 | 79 | #define PASS1_BITS 2 |
shoaib_ahmed | 0:791a779d6220 | 80 | #else |
shoaib_ahmed | 0:791a779d6220 | 81 | #define CONST_BITS 8 |
shoaib_ahmed | 0:791a779d6220 | 82 | #define PASS1_BITS 1 /* lose a little precision to avoid overflow */ |
shoaib_ahmed | 0:791a779d6220 | 83 | #endif |
shoaib_ahmed | 0:791a779d6220 | 84 | |
shoaib_ahmed | 0:791a779d6220 | 85 | /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus |
shoaib_ahmed | 0:791a779d6220 | 86 | * causing a lot of useless floating-point operations at run time. |
shoaib_ahmed | 0:791a779d6220 | 87 | * To get around this we use the following pre-calculated constants. |
shoaib_ahmed | 0:791a779d6220 | 88 | * If you change CONST_BITS you may want to add appropriate values. |
shoaib_ahmed | 0:791a779d6220 | 89 | * (With a reasonable C compiler, you can just rely on the FIX() macro...) |
shoaib_ahmed | 0:791a779d6220 | 90 | */ |
shoaib_ahmed | 0:791a779d6220 | 91 | |
shoaib_ahmed | 0:791a779d6220 | 92 | #if CONST_BITS == 8 |
shoaib_ahmed | 0:791a779d6220 | 93 | #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */ |
shoaib_ahmed | 0:791a779d6220 | 94 | #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */ |
shoaib_ahmed | 0:791a779d6220 | 95 | #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */ |
shoaib_ahmed | 0:791a779d6220 | 96 | #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */ |
shoaib_ahmed | 0:791a779d6220 | 97 | #else |
shoaib_ahmed | 0:791a779d6220 | 98 | #define FIX_1_082392200 FIX(1.082392200) |
shoaib_ahmed | 0:791a779d6220 | 99 | #define FIX_1_414213562 FIX(1.414213562) |
shoaib_ahmed | 0:791a779d6220 | 100 | #define FIX_1_847759065 FIX(1.847759065) |
shoaib_ahmed | 0:791a779d6220 | 101 | #define FIX_2_613125930 FIX(2.613125930) |
shoaib_ahmed | 0:791a779d6220 | 102 | #endif |
shoaib_ahmed | 0:791a779d6220 | 103 | |
shoaib_ahmed | 0:791a779d6220 | 104 | |
shoaib_ahmed | 0:791a779d6220 | 105 | /* We can gain a little more speed, with a further compromise in accuracy, |
shoaib_ahmed | 0:791a779d6220 | 106 | * by omitting the addition in a descaling shift. This yields an incorrectly |
shoaib_ahmed | 0:791a779d6220 | 107 | * rounded result half the time... |
shoaib_ahmed | 0:791a779d6220 | 108 | */ |
shoaib_ahmed | 0:791a779d6220 | 109 | |
shoaib_ahmed | 0:791a779d6220 | 110 | #ifndef USE_ACCURATE_ROUNDING |
shoaib_ahmed | 0:791a779d6220 | 111 | #undef DESCALE |
shoaib_ahmed | 0:791a779d6220 | 112 | #define DESCALE(x,n) RIGHT_SHIFT(x, n) |
shoaib_ahmed | 0:791a779d6220 | 113 | #endif |
shoaib_ahmed | 0:791a779d6220 | 114 | |
shoaib_ahmed | 0:791a779d6220 | 115 | |
shoaib_ahmed | 0:791a779d6220 | 116 | /* Multiply a DCTELEM variable by an INT32 constant, and immediately |
shoaib_ahmed | 0:791a779d6220 | 117 | * descale to yield a DCTELEM result. |
shoaib_ahmed | 0:791a779d6220 | 118 | */ |
shoaib_ahmed | 0:791a779d6220 | 119 | |
shoaib_ahmed | 0:791a779d6220 | 120 | #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) |
shoaib_ahmed | 0:791a779d6220 | 121 | |
shoaib_ahmed | 0:791a779d6220 | 122 | |
shoaib_ahmed | 0:791a779d6220 | 123 | /* Dequantize a coefficient by multiplying it by the multiplier-table |
shoaib_ahmed | 0:791a779d6220 | 124 | * entry; produce a DCTELEM result. For 8-bit data a 16x16->16 |
shoaib_ahmed | 0:791a779d6220 | 125 | * multiplication will do. For 12-bit data, the multiplier table is |
shoaib_ahmed | 0:791a779d6220 | 126 | * declared INT32, so a 32-bit multiply will be used. |
shoaib_ahmed | 0:791a779d6220 | 127 | */ |
shoaib_ahmed | 0:791a779d6220 | 128 | |
shoaib_ahmed | 0:791a779d6220 | 129 | #if BITS_IN_JSAMPLE == 8 |
shoaib_ahmed | 0:791a779d6220 | 130 | #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval)) |
shoaib_ahmed | 0:791a779d6220 | 131 | #else |
shoaib_ahmed | 0:791a779d6220 | 132 | #define DEQUANTIZE(coef,quantval) \ |
shoaib_ahmed | 0:791a779d6220 | 133 | DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS) |
shoaib_ahmed | 0:791a779d6220 | 134 | #endif |
shoaib_ahmed | 0:791a779d6220 | 135 | |
shoaib_ahmed | 0:791a779d6220 | 136 | |
shoaib_ahmed | 0:791a779d6220 | 137 | /* |
shoaib_ahmed | 0:791a779d6220 | 138 | * Perform dequantization and inverse DCT on one block of coefficients. |
shoaib_ahmed | 0:791a779d6220 | 139 | * |
shoaib_ahmed | 0:791a779d6220 | 140 | * cK represents cos(K*pi/16). |
shoaib_ahmed | 0:791a779d6220 | 141 | */ |
shoaib_ahmed | 0:791a779d6220 | 142 | |
shoaib_ahmed | 0:791a779d6220 | 143 | GLOBAL(void) |
shoaib_ahmed | 0:791a779d6220 | 144 | jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr, |
shoaib_ahmed | 0:791a779d6220 | 145 | JCOEFPTR coef_block, |
shoaib_ahmed | 0:791a779d6220 | 146 | JSAMPARRAY output_buf, JDIMENSION output_col) |
shoaib_ahmed | 0:791a779d6220 | 147 | { |
shoaib_ahmed | 0:791a779d6220 | 148 | DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; |
shoaib_ahmed | 0:791a779d6220 | 149 | DCTELEM tmp10, tmp11, tmp12, tmp13; |
shoaib_ahmed | 0:791a779d6220 | 150 | DCTELEM z5, z10, z11, z12, z13; |
shoaib_ahmed | 0:791a779d6220 | 151 | JCOEFPTR inptr; |
shoaib_ahmed | 0:791a779d6220 | 152 | IFAST_MULT_TYPE * quantptr; |
shoaib_ahmed | 0:791a779d6220 | 153 | int * wsptr; |
shoaib_ahmed | 0:791a779d6220 | 154 | JSAMPROW outptr; |
shoaib_ahmed | 0:791a779d6220 | 155 | JSAMPLE *range_limit = IDCT_range_limit(cinfo); |
shoaib_ahmed | 0:791a779d6220 | 156 | int ctr; |
shoaib_ahmed | 0:791a779d6220 | 157 | int workspace[DCTSIZE2]; /* buffers data between passes */ |
shoaib_ahmed | 0:791a779d6220 | 158 | SHIFT_TEMPS /* for DESCALE */ |
shoaib_ahmed | 0:791a779d6220 | 159 | ISHIFT_TEMPS /* for IRIGHT_SHIFT */ |
shoaib_ahmed | 0:791a779d6220 | 160 | |
shoaib_ahmed | 0:791a779d6220 | 161 | /* Pass 1: process columns from input, store into work array. */ |
shoaib_ahmed | 0:791a779d6220 | 162 | |
shoaib_ahmed | 0:791a779d6220 | 163 | inptr = coef_block; |
shoaib_ahmed | 0:791a779d6220 | 164 | quantptr = (IFAST_MULT_TYPE *) compptr->dct_table; |
shoaib_ahmed | 0:791a779d6220 | 165 | wsptr = workspace; |
shoaib_ahmed | 0:791a779d6220 | 166 | for (ctr = DCTSIZE; ctr > 0; ctr--) { |
shoaib_ahmed | 0:791a779d6220 | 167 | /* Due to quantization, we will usually find that many of the input |
shoaib_ahmed | 0:791a779d6220 | 168 | * coefficients are zero, especially the AC terms. We can exploit this |
shoaib_ahmed | 0:791a779d6220 | 169 | * by short-circuiting the IDCT calculation for any column in which all |
shoaib_ahmed | 0:791a779d6220 | 170 | * the AC terms are zero. In that case each output is equal to the |
shoaib_ahmed | 0:791a779d6220 | 171 | * DC coefficient (with scale factor as needed). |
shoaib_ahmed | 0:791a779d6220 | 172 | * With typical images and quantization tables, half or more of the |
shoaib_ahmed | 0:791a779d6220 | 173 | * column DCT calculations can be simplified this way. |
shoaib_ahmed | 0:791a779d6220 | 174 | */ |
shoaib_ahmed | 0:791a779d6220 | 175 | |
shoaib_ahmed | 0:791a779d6220 | 176 | if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && |
shoaib_ahmed | 0:791a779d6220 | 177 | inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && |
shoaib_ahmed | 0:791a779d6220 | 178 | inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && |
shoaib_ahmed | 0:791a779d6220 | 179 | inptr[DCTSIZE*7] == 0) { |
shoaib_ahmed | 0:791a779d6220 | 180 | /* AC terms all zero */ |
shoaib_ahmed | 0:791a779d6220 | 181 | int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); |
shoaib_ahmed | 0:791a779d6220 | 182 | |
shoaib_ahmed | 0:791a779d6220 | 183 | wsptr[DCTSIZE*0] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 184 | wsptr[DCTSIZE*1] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 185 | wsptr[DCTSIZE*2] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 186 | wsptr[DCTSIZE*3] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 187 | wsptr[DCTSIZE*4] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 188 | wsptr[DCTSIZE*5] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 189 | wsptr[DCTSIZE*6] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 190 | wsptr[DCTSIZE*7] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 191 | |
shoaib_ahmed | 0:791a779d6220 | 192 | inptr++; /* advance pointers to next column */ |
shoaib_ahmed | 0:791a779d6220 | 193 | quantptr++; |
shoaib_ahmed | 0:791a779d6220 | 194 | wsptr++; |
shoaib_ahmed | 0:791a779d6220 | 195 | continue; |
shoaib_ahmed | 0:791a779d6220 | 196 | } |
shoaib_ahmed | 0:791a779d6220 | 197 | |
shoaib_ahmed | 0:791a779d6220 | 198 | /* Even part */ |
shoaib_ahmed | 0:791a779d6220 | 199 | |
shoaib_ahmed | 0:791a779d6220 | 200 | tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); |
shoaib_ahmed | 0:791a779d6220 | 201 | tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); |
shoaib_ahmed | 0:791a779d6220 | 202 | tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); |
shoaib_ahmed | 0:791a779d6220 | 203 | tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); |
shoaib_ahmed | 0:791a779d6220 | 204 | |
shoaib_ahmed | 0:791a779d6220 | 205 | tmp10 = tmp0 + tmp2; /* phase 3 */ |
shoaib_ahmed | 0:791a779d6220 | 206 | tmp11 = tmp0 - tmp2; |
shoaib_ahmed | 0:791a779d6220 | 207 | |
shoaib_ahmed | 0:791a779d6220 | 208 | tmp13 = tmp1 + tmp3; /* phases 5-3 */ |
shoaib_ahmed | 0:791a779d6220 | 209 | tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */ |
shoaib_ahmed | 0:791a779d6220 | 210 | |
shoaib_ahmed | 0:791a779d6220 | 211 | tmp0 = tmp10 + tmp13; /* phase 2 */ |
shoaib_ahmed | 0:791a779d6220 | 212 | tmp3 = tmp10 - tmp13; |
shoaib_ahmed | 0:791a779d6220 | 213 | tmp1 = tmp11 + tmp12; |
shoaib_ahmed | 0:791a779d6220 | 214 | tmp2 = tmp11 - tmp12; |
shoaib_ahmed | 0:791a779d6220 | 215 | |
shoaib_ahmed | 0:791a779d6220 | 216 | /* Odd part */ |
shoaib_ahmed | 0:791a779d6220 | 217 | |
shoaib_ahmed | 0:791a779d6220 | 218 | tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); |
shoaib_ahmed | 0:791a779d6220 | 219 | tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); |
shoaib_ahmed | 0:791a779d6220 | 220 | tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); |
shoaib_ahmed | 0:791a779d6220 | 221 | tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); |
shoaib_ahmed | 0:791a779d6220 | 222 | |
shoaib_ahmed | 0:791a779d6220 | 223 | z13 = tmp6 + tmp5; /* phase 6 */ |
shoaib_ahmed | 0:791a779d6220 | 224 | z10 = tmp6 - tmp5; |
shoaib_ahmed | 0:791a779d6220 | 225 | z11 = tmp4 + tmp7; |
shoaib_ahmed | 0:791a779d6220 | 226 | z12 = tmp4 - tmp7; |
shoaib_ahmed | 0:791a779d6220 | 227 | |
shoaib_ahmed | 0:791a779d6220 | 228 | tmp7 = z11 + z13; /* phase 5 */ |
shoaib_ahmed | 0:791a779d6220 | 229 | tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ |
shoaib_ahmed | 0:791a779d6220 | 230 | |
shoaib_ahmed | 0:791a779d6220 | 231 | z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ |
shoaib_ahmed | 0:791a779d6220 | 232 | tmp10 = z5 - MULTIPLY(z12, FIX_1_082392200); /* 2*(c2-c6) */ |
shoaib_ahmed | 0:791a779d6220 | 233 | tmp12 = z5 - MULTIPLY(z10, FIX_2_613125930); /* 2*(c2+c6) */ |
shoaib_ahmed | 0:791a779d6220 | 234 | |
shoaib_ahmed | 0:791a779d6220 | 235 | tmp6 = tmp12 - tmp7; /* phase 2 */ |
shoaib_ahmed | 0:791a779d6220 | 236 | tmp5 = tmp11 - tmp6; |
shoaib_ahmed | 0:791a779d6220 | 237 | tmp4 = tmp10 - tmp5; |
shoaib_ahmed | 0:791a779d6220 | 238 | |
shoaib_ahmed | 0:791a779d6220 | 239 | wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7); |
shoaib_ahmed | 0:791a779d6220 | 240 | wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7); |
shoaib_ahmed | 0:791a779d6220 | 241 | wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6); |
shoaib_ahmed | 0:791a779d6220 | 242 | wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6); |
shoaib_ahmed | 0:791a779d6220 | 243 | wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5); |
shoaib_ahmed | 0:791a779d6220 | 244 | wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5); |
shoaib_ahmed | 0:791a779d6220 | 245 | wsptr[DCTSIZE*3] = (int) (tmp3 + tmp4); |
shoaib_ahmed | 0:791a779d6220 | 246 | wsptr[DCTSIZE*4] = (int) (tmp3 - tmp4); |
shoaib_ahmed | 0:791a779d6220 | 247 | |
shoaib_ahmed | 0:791a779d6220 | 248 | inptr++; /* advance pointers to next column */ |
shoaib_ahmed | 0:791a779d6220 | 249 | quantptr++; |
shoaib_ahmed | 0:791a779d6220 | 250 | wsptr++; |
shoaib_ahmed | 0:791a779d6220 | 251 | } |
shoaib_ahmed | 0:791a779d6220 | 252 | |
shoaib_ahmed | 0:791a779d6220 | 253 | /* Pass 2: process rows from work array, store into output array. |
shoaib_ahmed | 0:791a779d6220 | 254 | * Note that we must descale the results by a factor of 8 == 2**3, |
shoaib_ahmed | 0:791a779d6220 | 255 | * and also undo the PASS1_BITS scaling. |
shoaib_ahmed | 0:791a779d6220 | 256 | */ |
shoaib_ahmed | 0:791a779d6220 | 257 | |
shoaib_ahmed | 0:791a779d6220 | 258 | wsptr = workspace; |
shoaib_ahmed | 0:791a779d6220 | 259 | for (ctr = 0; ctr < DCTSIZE; ctr++) { |
shoaib_ahmed | 0:791a779d6220 | 260 | outptr = output_buf[ctr] + output_col; |
shoaib_ahmed | 0:791a779d6220 | 261 | |
shoaib_ahmed | 0:791a779d6220 | 262 | /* Add range center and fudge factor for final descale and range-limit. */ |
shoaib_ahmed | 0:791a779d6220 | 263 | z5 = (DCTELEM) wsptr[0] + |
shoaib_ahmed | 0:791a779d6220 | 264 | ((((DCTELEM) RANGE_CENTER) << (PASS1_BITS+3)) + |
shoaib_ahmed | 0:791a779d6220 | 265 | (1 << (PASS1_BITS+2))); |
shoaib_ahmed | 0:791a779d6220 | 266 | |
shoaib_ahmed | 0:791a779d6220 | 267 | /* Rows of zeroes can be exploited in the same way as we did with columns. |
shoaib_ahmed | 0:791a779d6220 | 268 | * However, the column calculation has created many nonzero AC terms, so |
shoaib_ahmed | 0:791a779d6220 | 269 | * the simplification applies less often (typically 5% to 10% of the time). |
shoaib_ahmed | 0:791a779d6220 | 270 | * On machines with very fast multiplication, it's possible that the |
shoaib_ahmed | 0:791a779d6220 | 271 | * test takes more time than it's worth. In that case this section |
shoaib_ahmed | 0:791a779d6220 | 272 | * may be commented out. |
shoaib_ahmed | 0:791a779d6220 | 273 | */ |
shoaib_ahmed | 0:791a779d6220 | 274 | |
shoaib_ahmed | 0:791a779d6220 | 275 | #ifndef NO_ZERO_ROW_TEST |
shoaib_ahmed | 0:791a779d6220 | 276 | if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && |
shoaib_ahmed | 0:791a779d6220 | 277 | wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { |
shoaib_ahmed | 0:791a779d6220 | 278 | /* AC terms all zero */ |
shoaib_ahmed | 0:791a779d6220 | 279 | JSAMPLE dcval = range_limit[(int) IRIGHT_SHIFT(z5, PASS1_BITS+3) |
shoaib_ahmed | 0:791a779d6220 | 280 | & RANGE_MASK]; |
shoaib_ahmed | 0:791a779d6220 | 281 | |
shoaib_ahmed | 0:791a779d6220 | 282 | outptr[0] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 283 | outptr[1] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 284 | outptr[2] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 285 | outptr[3] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 286 | outptr[4] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 287 | outptr[5] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 288 | outptr[6] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 289 | outptr[7] = dcval; |
shoaib_ahmed | 0:791a779d6220 | 290 | |
shoaib_ahmed | 0:791a779d6220 | 291 | wsptr += DCTSIZE; /* advance pointer to next row */ |
shoaib_ahmed | 0:791a779d6220 | 292 | continue; |
shoaib_ahmed | 0:791a779d6220 | 293 | } |
shoaib_ahmed | 0:791a779d6220 | 294 | #endif |
shoaib_ahmed | 0:791a779d6220 | 295 | |
shoaib_ahmed | 0:791a779d6220 | 296 | /* Even part */ |
shoaib_ahmed | 0:791a779d6220 | 297 | |
shoaib_ahmed | 0:791a779d6220 | 298 | tmp10 = z5 + (DCTELEM) wsptr[4]; |
shoaib_ahmed | 0:791a779d6220 | 299 | tmp11 = z5 - (DCTELEM) wsptr[4]; |
shoaib_ahmed | 0:791a779d6220 | 300 | |
shoaib_ahmed | 0:791a779d6220 | 301 | tmp13 = (DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]; |
shoaib_ahmed | 0:791a779d6220 | 302 | tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], |
shoaib_ahmed | 0:791a779d6220 | 303 | FIX_1_414213562) - tmp13; /* 2*c4 */ |
shoaib_ahmed | 0:791a779d6220 | 304 | |
shoaib_ahmed | 0:791a779d6220 | 305 | tmp0 = tmp10 + tmp13; |
shoaib_ahmed | 0:791a779d6220 | 306 | tmp3 = tmp10 - tmp13; |
shoaib_ahmed | 0:791a779d6220 | 307 | tmp1 = tmp11 + tmp12; |
shoaib_ahmed | 0:791a779d6220 | 308 | tmp2 = tmp11 - tmp12; |
shoaib_ahmed | 0:791a779d6220 | 309 | |
shoaib_ahmed | 0:791a779d6220 | 310 | /* Odd part */ |
shoaib_ahmed | 0:791a779d6220 | 311 | |
shoaib_ahmed | 0:791a779d6220 | 312 | z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3]; |
shoaib_ahmed | 0:791a779d6220 | 313 | z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3]; |
shoaib_ahmed | 0:791a779d6220 | 314 | z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7]; |
shoaib_ahmed | 0:791a779d6220 | 315 | z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7]; |
shoaib_ahmed | 0:791a779d6220 | 316 | |
shoaib_ahmed | 0:791a779d6220 | 317 | tmp7 = z11 + z13; /* phase 5 */ |
shoaib_ahmed | 0:791a779d6220 | 318 | tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */ |
shoaib_ahmed | 0:791a779d6220 | 319 | |
shoaib_ahmed | 0:791a779d6220 | 320 | z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */ |
shoaib_ahmed | 0:791a779d6220 | 321 | tmp10 = z5 - MULTIPLY(z12, FIX_1_082392200); /* 2*(c2-c6) */ |
shoaib_ahmed | 0:791a779d6220 | 322 | tmp12 = z5 - MULTIPLY(z10, FIX_2_613125930); /* 2*(c2+c6) */ |
shoaib_ahmed | 0:791a779d6220 | 323 | |
shoaib_ahmed | 0:791a779d6220 | 324 | tmp6 = tmp12 - tmp7; /* phase 2 */ |
shoaib_ahmed | 0:791a779d6220 | 325 | tmp5 = tmp11 - tmp6; |
shoaib_ahmed | 0:791a779d6220 | 326 | tmp4 = tmp10 - tmp5; |
shoaib_ahmed | 0:791a779d6220 | 327 | |
shoaib_ahmed | 0:791a779d6220 | 328 | /* Final output stage: scale down by a factor of 8 and range-limit */ |
shoaib_ahmed | 0:791a779d6220 | 329 | |
shoaib_ahmed | 0:791a779d6220 | 330 | outptr[0] = range_limit[(int) IRIGHT_SHIFT(tmp0 + tmp7, PASS1_BITS+3) |
shoaib_ahmed | 0:791a779d6220 | 331 | & RANGE_MASK]; |
shoaib_ahmed | 0:791a779d6220 | 332 | outptr[7] = range_limit[(int) IRIGHT_SHIFT(tmp0 - tmp7, PASS1_BITS+3) |
shoaib_ahmed | 0:791a779d6220 | 333 | & RANGE_MASK]; |
shoaib_ahmed | 0:791a779d6220 | 334 | outptr[1] = range_limit[(int) IRIGHT_SHIFT(tmp1 + tmp6, PASS1_BITS+3) |
shoaib_ahmed | 0:791a779d6220 | 335 | & RANGE_MASK]; |
shoaib_ahmed | 0:791a779d6220 | 336 | outptr[6] = range_limit[(int) IRIGHT_SHIFT(tmp1 - tmp6, PASS1_BITS+3) |
shoaib_ahmed | 0:791a779d6220 | 337 | & RANGE_MASK]; |
shoaib_ahmed | 0:791a779d6220 | 338 | outptr[2] = range_limit[(int) IRIGHT_SHIFT(tmp2 + tmp5, PASS1_BITS+3) |
shoaib_ahmed | 0:791a779d6220 | 339 | & RANGE_MASK]; |
shoaib_ahmed | 0:791a779d6220 | 340 | outptr[5] = range_limit[(int) IRIGHT_SHIFT(tmp2 - tmp5, PASS1_BITS+3) |
shoaib_ahmed | 0:791a779d6220 | 341 | & RANGE_MASK]; |
shoaib_ahmed | 0:791a779d6220 | 342 | outptr[3] = range_limit[(int) IRIGHT_SHIFT(tmp3 + tmp4, PASS1_BITS+3) |
shoaib_ahmed | 0:791a779d6220 | 343 | & RANGE_MASK]; |
shoaib_ahmed | 0:791a779d6220 | 344 | outptr[4] = range_limit[(int) IRIGHT_SHIFT(tmp3 - tmp4, PASS1_BITS+3) |
shoaib_ahmed | 0:791a779d6220 | 345 | & RANGE_MASK]; |
shoaib_ahmed | 0:791a779d6220 | 346 | |
shoaib_ahmed | 0:791a779d6220 | 347 | wsptr += DCTSIZE; /* advance pointer to next row */ |
shoaib_ahmed | 0:791a779d6220 | 348 | } |
shoaib_ahmed | 0:791a779d6220 | 349 | } |
shoaib_ahmed | 0:791a779d6220 | 350 | |
shoaib_ahmed | 0:791a779d6220 | 351 | #endif /* DCT_IFAST_SUPPORTED */ |