dbf-halloween2015
diff libs/libjpeg/jidctflt.c @ 1:c3f5c32cb210
barfed all the libraries in the source tree to make porting easier
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 01 Nov 2015 00:36:56 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/libs/libjpeg/jidctflt.c Sun Nov 01 00:36:56 2015 +0200 1.3 @@ -0,0 +1,242 @@ 1.4 +/* 1.5 + * jidctflt.c 1.6 + * 1.7 + * Copyright (C) 1994-1998, Thomas G. Lane. 1.8 + * This file is part of the Independent JPEG Group's software. 1.9 + * For conditions of distribution and use, see the accompanying README file. 1.10 + * 1.11 + * This file contains a floating-point implementation of the 1.12 + * inverse DCT (Discrete Cosine Transform). In the IJG code, this routine 1.13 + * must also perform dequantization of the input coefficients. 1.14 + * 1.15 + * This implementation should be more accurate than either of the integer 1.16 + * IDCT implementations. However, it may not give the same results on all 1.17 + * machines because of differences in roundoff behavior. Speed will depend 1.18 + * on the hardware's floating point capacity. 1.19 + * 1.20 + * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT 1.21 + * on each row (or vice versa, but it's more convenient to emit a row at 1.22 + * a time). Direct algorithms are also available, but they are much more 1.23 + * complex and seem not to be any faster when reduced to code. 1.24 + * 1.25 + * This implementation is based on Arai, Agui, and Nakajima's algorithm for 1.26 + * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in 1.27 + * Japanese, but the algorithm is described in the Pennebaker & Mitchell 1.28 + * JPEG textbook (see REFERENCES section in file README). The following code 1.29 + * is based directly on figure 4-8 in P&M. 1.30 + * While an 8-point DCT cannot be done in less than 11 multiplies, it is 1.31 + * possible to arrange the computation so that many of the multiplies are 1.32 + * simple scalings of the final outputs. These multiplies can then be 1.33 + * folded into the multiplications or divisions by the JPEG quantization 1.34 + * table entries. The AA&N method leaves only 5 multiplies and 29 adds 1.35 + * to be done in the DCT itself. 1.36 + * The primary disadvantage of this method is that with a fixed-point 1.37 + * implementation, accuracy is lost due to imprecise representation of the 1.38 + * scaled quantization values. However, that problem does not arise if 1.39 + * we use floating point arithmetic. 1.40 + */ 1.41 + 1.42 +#define JPEG_INTERNALS 1.43 +#include "jinclude.h" 1.44 +#include "jpeglib.h" 1.45 +#include "jdct.h" /* Private declarations for DCT subsystem */ 1.46 + 1.47 +#ifdef DCT_FLOAT_SUPPORTED 1.48 + 1.49 + 1.50 +/* 1.51 + * This module is specialized to the case DCTSIZE = 8. 1.52 + */ 1.53 + 1.54 +#if DCTSIZE != 8 1.55 + Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ 1.56 +#endif 1.57 + 1.58 + 1.59 +/* Dequantize a coefficient by multiplying it by the multiplier-table 1.60 + * entry; produce a float result. 1.61 + */ 1.62 + 1.63 +#define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval)) 1.64 + 1.65 + 1.66 +/* 1.67 + * Perform dequantization and inverse DCT on one block of coefficients. 1.68 + */ 1.69 + 1.70 +GLOBAL(void) 1.71 +jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr, 1.72 + JCOEFPTR coef_block, 1.73 + JSAMPARRAY output_buf, JDIMENSION output_col) 1.74 +{ 1.75 + FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; 1.76 + FAST_FLOAT tmp10, tmp11, tmp12, tmp13; 1.77 + FAST_FLOAT z5, z10, z11, z12, z13; 1.78 + JCOEFPTR inptr; 1.79 + FLOAT_MULT_TYPE * quantptr; 1.80 + FAST_FLOAT * wsptr; 1.81 + JSAMPROW outptr; 1.82 + JSAMPLE *range_limit = IDCT_range_limit(cinfo); 1.83 + int ctr; 1.84 + FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */ 1.85 + SHIFT_TEMPS 1.86 + 1.87 + /* Pass 1: process columns from input, store into work array. */ 1.88 + 1.89 + inptr = coef_block; 1.90 + quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table; 1.91 + wsptr = workspace; 1.92 + for (ctr = DCTSIZE; ctr > 0; ctr--) { 1.93 + /* Due to quantization, we will usually find that many of the input 1.94 + * coefficients are zero, especially the AC terms. We can exploit this 1.95 + * by short-circuiting the IDCT calculation for any column in which all 1.96 + * the AC terms are zero. In that case each output is equal to the 1.97 + * DC coefficient (with scale factor as needed). 1.98 + * With typical images and quantization tables, half or more of the 1.99 + * column DCT calculations can be simplified this way. 1.100 + */ 1.101 + 1.102 + if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && 1.103 + inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && 1.104 + inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && 1.105 + inptr[DCTSIZE*7] == 0) { 1.106 + /* AC terms all zero */ 1.107 + FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 1.108 + 1.109 + wsptr[DCTSIZE*0] = dcval; 1.110 + wsptr[DCTSIZE*1] = dcval; 1.111 + wsptr[DCTSIZE*2] = dcval; 1.112 + wsptr[DCTSIZE*3] = dcval; 1.113 + wsptr[DCTSIZE*4] = dcval; 1.114 + wsptr[DCTSIZE*5] = dcval; 1.115 + wsptr[DCTSIZE*6] = dcval; 1.116 + wsptr[DCTSIZE*7] = dcval; 1.117 + 1.118 + inptr++; /* advance pointers to next column */ 1.119 + quantptr++; 1.120 + wsptr++; 1.121 + continue; 1.122 + } 1.123 + 1.124 + /* Even part */ 1.125 + 1.126 + tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); 1.127 + tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); 1.128 + tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); 1.129 + tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); 1.130 + 1.131 + tmp10 = tmp0 + tmp2; /* phase 3 */ 1.132 + tmp11 = tmp0 - tmp2; 1.133 + 1.134 + tmp13 = tmp1 + tmp3; /* phases 5-3 */ 1.135 + tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */ 1.136 + 1.137 + tmp0 = tmp10 + tmp13; /* phase 2 */ 1.138 + tmp3 = tmp10 - tmp13; 1.139 + tmp1 = tmp11 + tmp12; 1.140 + tmp2 = tmp11 - tmp12; 1.141 + 1.142 + /* Odd part */ 1.143 + 1.144 + tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); 1.145 + tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); 1.146 + tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); 1.147 + tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); 1.148 + 1.149 + z13 = tmp6 + tmp5; /* phase 6 */ 1.150 + z10 = tmp6 - tmp5; 1.151 + z11 = tmp4 + tmp7; 1.152 + z12 = tmp4 - tmp7; 1.153 + 1.154 + tmp7 = z11 + z13; /* phase 5 */ 1.155 + tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */ 1.156 + 1.157 + z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ 1.158 + tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ 1.159 + tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ 1.160 + 1.161 + tmp6 = tmp12 - tmp7; /* phase 2 */ 1.162 + tmp5 = tmp11 - tmp6; 1.163 + tmp4 = tmp10 + tmp5; 1.164 + 1.165 + wsptr[DCTSIZE*0] = tmp0 + tmp7; 1.166 + wsptr[DCTSIZE*7] = tmp0 - tmp7; 1.167 + wsptr[DCTSIZE*1] = tmp1 + tmp6; 1.168 + wsptr[DCTSIZE*6] = tmp1 - tmp6; 1.169 + wsptr[DCTSIZE*2] = tmp2 + tmp5; 1.170 + wsptr[DCTSIZE*5] = tmp2 - tmp5; 1.171 + wsptr[DCTSIZE*4] = tmp3 + tmp4; 1.172 + wsptr[DCTSIZE*3] = tmp3 - tmp4; 1.173 + 1.174 + inptr++; /* advance pointers to next column */ 1.175 + quantptr++; 1.176 + wsptr++; 1.177 + } 1.178 + 1.179 + /* Pass 2: process rows from work array, store into output array. */ 1.180 + /* Note that we must descale the results by a factor of 8 == 2**3. */ 1.181 + 1.182 + wsptr = workspace; 1.183 + for (ctr = 0; ctr < DCTSIZE; ctr++) { 1.184 + outptr = output_buf[ctr] + output_col; 1.185 + /* Rows of zeroes can be exploited in the same way as we did with columns. 1.186 + * However, the column calculation has created many nonzero AC terms, so 1.187 + * the simplification applies less often (typically 5% to 10% of the time). 1.188 + * And testing floats for zero is relatively expensive, so we don't bother. 1.189 + */ 1.190 + 1.191 + /* Even part */ 1.192 + 1.193 + tmp10 = wsptr[0] + wsptr[4]; 1.194 + tmp11 = wsptr[0] - wsptr[4]; 1.195 + 1.196 + tmp13 = wsptr[2] + wsptr[6]; 1.197 + tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13; 1.198 + 1.199 + tmp0 = tmp10 + tmp13; 1.200 + tmp3 = tmp10 - tmp13; 1.201 + tmp1 = tmp11 + tmp12; 1.202 + tmp2 = tmp11 - tmp12; 1.203 + 1.204 + /* Odd part */ 1.205 + 1.206 + z13 = wsptr[5] + wsptr[3]; 1.207 + z10 = wsptr[5] - wsptr[3]; 1.208 + z11 = wsptr[1] + wsptr[7]; 1.209 + z12 = wsptr[1] - wsptr[7]; 1.210 + 1.211 + tmp7 = z11 + z13; 1.212 + tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); 1.213 + 1.214 + z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */ 1.215 + tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */ 1.216 + tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */ 1.217 + 1.218 + tmp6 = tmp12 - tmp7; 1.219 + tmp5 = tmp11 - tmp6; 1.220 + tmp4 = tmp10 + tmp5; 1.221 + 1.222 + /* Final output stage: scale down by a factor of 8 and range-limit */ 1.223 + 1.224 + outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3) 1.225 + & RANGE_MASK]; 1.226 + outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3) 1.227 + & RANGE_MASK]; 1.228 + outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3) 1.229 + & RANGE_MASK]; 1.230 + outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3) 1.231 + & RANGE_MASK]; 1.232 + outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3) 1.233 + & RANGE_MASK]; 1.234 + outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3) 1.235 + & RANGE_MASK]; 1.236 + outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3) 1.237 + & RANGE_MASK]; 1.238 + outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3) 1.239 + & RANGE_MASK]; 1.240 + 1.241 + wsptr += DCTSIZE; /* advance pointer to next row */ 1.242 + } 1.243 +} 1.244 + 1.245 +#endif /* DCT_FLOAT_SUPPORTED */