7 * Copyright (C) 1994, Thomas G. Lane.
9 * This file is part of the Independent JPEG Group's software.
11 * For conditions of distribution and use, see the accompanying README file.
15 * This file contains a floating-point implementation of the
17 * forward DCT (Discrete Cosine Transform).
21 * This implementation should be more accurate than either of the integer
23 * DCT implementations. However, it may not give the same results on all
25 * machines because of differences in roundoff behavior. Speed will depend
27 * on the hardware's floating point capacity.
31 * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT
33 * on each column. Direct algorithms are also available, but they are
35 * much more complex and seem not to be any faster when reduced to code.
39 * This implementation is based on Arai, Agui, and Nakajima's algorithm for
41 * scaled DCT. Their original paper (Trans. IEICE E-71(11):1095) is in
43 * Japanese, but the algorithm is described in the Pennebaker & Mitchell
45 * JPEG textbook (see REFERENCES section in file README). The following code
47 * is based directly on figure 4-8 in P&M.
49 * While an 8-point DCT cannot be done in less than 11 multiplies, it is
51 * possible to arrange the computation so that many of the multiplies are
53 * simple scalings of the final outputs. These multiplies can then be
55 * folded into the multiplications or divisions by the JPEG quantization
57 * table entries. The AA&N method leaves only 5 multiplies and 29 adds
59 * to be done in the DCT itself.
61 * The primary disadvantage of this method is that with a fixed-point
63 * implementation, accuracy is lost due to imprecise representation of the
65 * scaled quantization values. However, that problem does not arise if
67 * we use floating point arithmetic.
73 #define JPEG_INTERNALS
77 #include "radiant_jpeglib.h"
79 #include "jdct.h" /* Private declarations for DCT subsystem */
83 #ifdef DCT_FLOAT_SUPPORTED
91 * This module is specialized to the case DCTSIZE = 8.
99 Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
109 * Perform the forward DCT on one block of samples.
117 jpeg_fdct_float (FAST_FLOAT * data)
121 FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
123 FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
125 FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
133 /* Pass 1: process rows. */
139 for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
141 tmp0 = dataptr[0] + dataptr[7];
143 tmp7 = dataptr[0] - dataptr[7];
145 tmp1 = dataptr[1] + dataptr[6];
147 tmp6 = dataptr[1] - dataptr[6];
149 tmp2 = dataptr[2] + dataptr[5];
151 tmp5 = dataptr[2] - dataptr[5];
153 tmp3 = dataptr[3] + dataptr[4];
155 tmp4 = dataptr[3] - dataptr[4];
163 tmp10 = tmp0 + tmp3; /* phase 2 */
173 dataptr[0] = tmp10 + tmp11; /* phase 3 */
175 dataptr[4] = tmp10 - tmp11;
179 z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
181 dataptr[2] = tmp13 + z1; /* phase 5 */
183 dataptr[6] = tmp13 - z1;
191 tmp10 = tmp4 + tmp5; /* phase 2 */
199 /* The rotator is modified from fig 4-8 to avoid extra negations. */
201 z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
203 z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
205 z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
207 z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
211 z11 = tmp7 + z3; /* phase 5 */
217 dataptr[5] = z13 + z2; /* phase 6 */
219 dataptr[3] = z13 - z2;
221 dataptr[1] = z11 + z4;
223 dataptr[7] = z11 - z4;
227 dataptr += DCTSIZE; /* advance pointer to next row */
233 /* Pass 2: process columns. */
239 for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
241 tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
243 tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
245 tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
247 tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
249 tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
251 tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
253 tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
255 tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
263 tmp10 = tmp0 + tmp3; /* phase 2 */
273 dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
275 dataptr[DCTSIZE*4] = tmp10 - tmp11;
279 z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
281 dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
283 dataptr[DCTSIZE*6] = tmp13 - z1;
291 tmp10 = tmp4 + tmp5; /* phase 2 */
299 /* The rotator is modified from fig 4-8 to avoid extra negations. */
301 z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
303 z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
305 z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
307 z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
311 z11 = tmp7 + z3; /* phase 5 */
317 dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
319 dataptr[DCTSIZE*3] = z13 - z2;
321 dataptr[DCTSIZE*1] = z11 + z4;
323 dataptr[DCTSIZE*7] = z11 - z4;
327 dataptr++; /* advance pointer to next column */
335 #endif /* DCT_FLOAT_SUPPORTED */