istereo

annotate libs/libjpeg/jidctflt.c @ 35:23e5d274b2a2

added options panel, also added the xib files to the repository as they're needed
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 09 Sep 2011 10:03:42 +0300
parents
children
rev   line source
nuclear@26 1 /*
nuclear@26 2 * jidctflt.c
nuclear@26 3 *
nuclear@26 4 * Copyright (C) 1994-1998, Thomas G. Lane.
nuclear@26 5 * This file is part of the Independent JPEG Group's software.
nuclear@26 6 * For conditions of distribution and use, see the accompanying README file.
nuclear@26 7 *
nuclear@26 8 * This file contains a floating-point implementation of the
nuclear@26 9 * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine
nuclear@26 10 * must also perform dequantization of the input coefficients.
nuclear@26 11 *
nuclear@26 12 * This implementation should be more accurate than either of the integer
nuclear@26 13 * IDCT implementations. However, it may not give the same results on all
nuclear@26 14 * machines because of differences in roundoff behavior. Speed will depend
nuclear@26 15 * on the hardware's floating point capacity.
nuclear@26 16 *
nuclear@26 17 * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT
nuclear@26 18 * on each row (or vice versa, but it's more convenient to emit a row at
nuclear@26 19 * a time). Direct algorithms are also available, but they are much more
nuclear@26 20 * complex and seem not to be any faster when reduced to code.
nuclear@26 21 *
nuclear@26 22 * This implementation is based on Arai, Agui, and Nakajima's algorithm for
nuclear@26 23 * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
nuclear@26 24 * Japanese, but the algorithm is described in the Pennebaker & Mitchell
nuclear@26 25 * JPEG textbook (see REFERENCES section in file README). The following code
nuclear@26 26 * is based directly on figure 4-8 in P&M.
nuclear@26 27 * While an 8-point DCT cannot be done in less than 11 multiplies, it is
nuclear@26 28 * possible to arrange the computation so that many of the multiplies are
nuclear@26 29 * simple scalings of the final outputs. These multiplies can then be
nuclear@26 30 * folded into the multiplications or divisions by the JPEG quantization
nuclear@26 31 * table entries. The AA&N method leaves only 5 multiplies and 29 adds
nuclear@26 32 * to be done in the DCT itself.
nuclear@26 33 * The primary disadvantage of this method is that with a fixed-point
nuclear@26 34 * implementation, accuracy is lost due to imprecise representation of the
nuclear@26 35 * scaled quantization values. However, that problem does not arise if
nuclear@26 36 * we use floating point arithmetic.
nuclear@26 37 */
nuclear@26 38
nuclear@26 39 #define JPEG_INTERNALS
nuclear@26 40 #include "jinclude.h"
nuclear@26 41 #include "jpeglib.h"
nuclear@26 42 #include "jdct.h" /* Private declarations for DCT subsystem */
nuclear@26 43
nuclear@26 44 #ifdef DCT_FLOAT_SUPPORTED
nuclear@26 45
nuclear@26 46
nuclear@26 47 /*
nuclear@26 48 * This module is specialized to the case DCTSIZE = 8.
nuclear@26 49 */
nuclear@26 50
nuclear@26 51 #if DCTSIZE != 8
nuclear@26 52 Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
nuclear@26 53 #endif
nuclear@26 54
nuclear@26 55
nuclear@26 56 /* Dequantize a coefficient by multiplying it by the multiplier-table
nuclear@26 57 * entry; produce a float result.
nuclear@26 58 */
nuclear@26 59
nuclear@26 60 #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
nuclear@26 61
nuclear@26 62
nuclear@26 63 /*
nuclear@26 64 * Perform dequantization and inverse DCT on one block of coefficients.
nuclear@26 65 */
nuclear@26 66
nuclear@26 67 GLOBAL(void)
nuclear@26 68 jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
nuclear@26 69 JCOEFPTR coef_block,
nuclear@26 70 JSAMPARRAY output_buf, JDIMENSION output_col)
nuclear@26 71 {
nuclear@26 72 FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
nuclear@26 73 FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
nuclear@26 74 FAST_FLOAT z5, z10, z11, z12, z13;
nuclear@26 75 JCOEFPTR inptr;
nuclear@26 76 FLOAT_MULT_TYPE * quantptr;
nuclear@26 77 FAST_FLOAT * wsptr;
nuclear@26 78 JSAMPROW outptr;
nuclear@26 79 JSAMPLE *range_limit = IDCT_range_limit(cinfo);
nuclear@26 80 int ctr;
nuclear@26 81 FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
nuclear@26 82 SHIFT_TEMPS
nuclear@26 83
nuclear@26 84 /* Pass 1: process columns from input, store into work array. */
nuclear@26 85
nuclear@26 86 inptr = coef_block;
nuclear@26 87 quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
nuclear@26 88 wsptr = workspace;
nuclear@26 89 for (ctr = DCTSIZE; ctr > 0; ctr--) {
nuclear@26 90 /* Due to quantization, we will usually find that many of the input
nuclear@26 91 * coefficients are zero, especially the AC terms. We can exploit this
nuclear@26 92 * by short-circuiting the IDCT calculation for any column in which all
nuclear@26 93 * the AC terms are zero. In that case each output is equal to the
nuclear@26 94 * DC coefficient (with scale factor as needed).
nuclear@26 95 * With typical images and quantization tables, half or more of the
nuclear@26 96 * column DCT calculations can be simplified this way.
nuclear@26 97 */
nuclear@26 98
nuclear@26 99 if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
nuclear@26 100 inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
nuclear@26 101 inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
nuclear@26 102 inptr[DCTSIZE*7] == 0) {
nuclear@26 103 /* AC terms all zero */
nuclear@26 104 FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
nuclear@26 105
nuclear@26 106 wsptr[DCTSIZE*0] = dcval;
nuclear@26 107 wsptr[DCTSIZE*1] = dcval;
nuclear@26 108 wsptr[DCTSIZE*2] = dcval;
nuclear@26 109 wsptr[DCTSIZE*3] = dcval;
nuclear@26 110 wsptr[DCTSIZE*4] = dcval;
nuclear@26 111 wsptr[DCTSIZE*5] = dcval;
nuclear@26 112 wsptr[DCTSIZE*6] = dcval;
nuclear@26 113 wsptr[DCTSIZE*7] = dcval;
nuclear@26 114
nuclear@26 115 inptr++; /* advance pointers to next column */
nuclear@26 116 quantptr++;
nuclear@26 117 wsptr++;
nuclear@26 118 continue;
nuclear@26 119 }
nuclear@26 120
nuclear@26 121 /* Even part */
nuclear@26 122
nuclear@26 123 tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
nuclear@26 124 tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
nuclear@26 125 tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
nuclear@26 126 tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
nuclear@26 127
nuclear@26 128 tmp10 = tmp0 + tmp2; /* phase 3 */
nuclear@26 129 tmp11 = tmp0 - tmp2;
nuclear@26 130
nuclear@26 131 tmp13 = tmp1 + tmp3; /* phases 5-3 */
nuclear@26 132 tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
nuclear@26 133
nuclear@26 134 tmp0 = tmp10 + tmp13; /* phase 2 */
nuclear@26 135 tmp3 = tmp10 - tmp13;
nuclear@26 136 tmp1 = tmp11 + tmp12;
nuclear@26 137 tmp2 = tmp11 - tmp12;
nuclear@26 138
nuclear@26 139 /* Odd part */
nuclear@26 140
nuclear@26 141 tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
nuclear@26 142 tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
nuclear@26 143 tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
nuclear@26 144 tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
nuclear@26 145
nuclear@26 146 z13 = tmp6 + tmp5; /* phase 6 */
nuclear@26 147 z10 = tmp6 - tmp5;
nuclear@26 148 z11 = tmp4 + tmp7;
nuclear@26 149 z12 = tmp4 - tmp7;
nuclear@26 150
nuclear@26 151 tmp7 = z11 + z13; /* phase 5 */
nuclear@26 152 tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
nuclear@26 153
nuclear@26 154 z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
nuclear@26 155 tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
nuclear@26 156 tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
nuclear@26 157
nuclear@26 158 tmp6 = tmp12 - tmp7; /* phase 2 */
nuclear@26 159 tmp5 = tmp11 - tmp6;
nuclear@26 160 tmp4 = tmp10 + tmp5;
nuclear@26 161
nuclear@26 162 wsptr[DCTSIZE*0] = tmp0 + tmp7;
nuclear@26 163 wsptr[DCTSIZE*7] = tmp0 - tmp7;
nuclear@26 164 wsptr[DCTSIZE*1] = tmp1 + tmp6;
nuclear@26 165 wsptr[DCTSIZE*6] = tmp1 - tmp6;
nuclear@26 166 wsptr[DCTSIZE*2] = tmp2 + tmp5;
nuclear@26 167 wsptr[DCTSIZE*5] = tmp2 - tmp5;
nuclear@26 168 wsptr[DCTSIZE*4] = tmp3 + tmp4;
nuclear@26 169 wsptr[DCTSIZE*3] = tmp3 - tmp4;
nuclear@26 170
nuclear@26 171 inptr++; /* advance pointers to next column */
nuclear@26 172 quantptr++;
nuclear@26 173 wsptr++;
nuclear@26 174 }
nuclear@26 175
nuclear@26 176 /* Pass 2: process rows from work array, store into output array. */
nuclear@26 177 /* Note that we must descale the results by a factor of 8 == 2**3. */
nuclear@26 178
nuclear@26 179 wsptr = workspace;
nuclear@26 180 for (ctr = 0; ctr < DCTSIZE; ctr++) {
nuclear@26 181 outptr = output_buf[ctr] + output_col;
nuclear@26 182 /* Rows of zeroes can be exploited in the same way as we did with columns.
nuclear@26 183 * However, the column calculation has created many nonzero AC terms, so
nuclear@26 184 * the simplification applies less often (typically 5% to 10% of the time).
nuclear@26 185 * And testing floats for zero is relatively expensive, so we don't bother.
nuclear@26 186 */
nuclear@26 187
nuclear@26 188 /* Even part */
nuclear@26 189
nuclear@26 190 tmp10 = wsptr[0] + wsptr[4];
nuclear@26 191 tmp11 = wsptr[0] - wsptr[4];
nuclear@26 192
nuclear@26 193 tmp13 = wsptr[2] + wsptr[6];
nuclear@26 194 tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
nuclear@26 195
nuclear@26 196 tmp0 = tmp10 + tmp13;
nuclear@26 197 tmp3 = tmp10 - tmp13;
nuclear@26 198 tmp1 = tmp11 + tmp12;
nuclear@26 199 tmp2 = tmp11 - tmp12;
nuclear@26 200
nuclear@26 201 /* Odd part */
nuclear@26 202
nuclear@26 203 z13 = wsptr[5] + wsptr[3];
nuclear@26 204 z10 = wsptr[5] - wsptr[3];
nuclear@26 205 z11 = wsptr[1] + wsptr[7];
nuclear@26 206 z12 = wsptr[1] - wsptr[7];
nuclear@26 207
nuclear@26 208 tmp7 = z11 + z13;
nuclear@26 209 tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
nuclear@26 210
nuclear@26 211 z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
nuclear@26 212 tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
nuclear@26 213 tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
nuclear@26 214
nuclear@26 215 tmp6 = tmp12 - tmp7;
nuclear@26 216 tmp5 = tmp11 - tmp6;
nuclear@26 217 tmp4 = tmp10 + tmp5;
nuclear@26 218
nuclear@26 219 /* Final output stage: scale down by a factor of 8 and range-limit */
nuclear@26 220
nuclear@26 221 outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
nuclear@26 222 & RANGE_MASK];
nuclear@26 223 outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
nuclear@26 224 & RANGE_MASK];
nuclear@26 225 outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
nuclear@26 226 & RANGE_MASK];
nuclear@26 227 outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
nuclear@26 228 & RANGE_MASK];
nuclear@26 229 outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
nuclear@26 230 & RANGE_MASK];
nuclear@26 231 outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
nuclear@26 232 & RANGE_MASK];
nuclear@26 233 outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
nuclear@26 234 & RANGE_MASK];
nuclear@26 235 outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
nuclear@26 236 & RANGE_MASK];
nuclear@26 237
nuclear@26 238 wsptr += DCTSIZE; /* advance pointer to next row */
nuclear@26 239 }
nuclear@26 240 }
nuclear@26 241
nuclear@26 242 #endif /* DCT_FLOAT_SUPPORTED */