22 * jidctflt.c
33 *
44 * Copyright (C) 1994-1998, Thomas G. Lane.
5+ * Modified 2010 by Guido Vollbeding.
56 * This file is part of the Independent JPEG Group's software.
67 * For conditions of distribution and use, see the accompanying README file.
78 *
@@ -76,10 +77,9 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
7677 FLOAT_MULT_TYPE * quantptr ;
7778 FAST_FLOAT * wsptr ;
7879 JSAMPROW outptr ;
79- JSAMPLE * range_limit = IDCT_range_limit ( cinfo ) ;
80+ JSAMPLE * range_limit = cinfo -> sample_range_limit ;
8081 int ctr ;
8182 FAST_FLOAT workspace [DCTSIZE2 ]; /* buffers data between passes */
82- SHIFT_TEMPS
8383
8484 /* Pass 1: process columns from input, store into work array. */
8585
@@ -152,29 +152,28 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
152152 tmp11 = (z11 - z13 ) * ((FAST_FLOAT ) 1.414213562 ); /* 2*c4 */
153153
154154 z5 = (z10 + z12 ) * ((FAST_FLOAT ) 1.847759065 ); /* 2*c2 */
155- tmp10 = ((FAST_FLOAT ) 1.082392200 ) * z12 - z5 ; /* 2*(c2-c6) */
156- tmp12 = ((FAST_FLOAT ) - 2.613125930 ) * z10 + z5 ; /* - 2*(c2+c6) */
155+ tmp10 = z5 - z12 * ((FAST_FLOAT ) 1.082392200 ); /* 2*(c2-c6) */
156+ tmp12 = z5 - z10 * ((FAST_FLOAT ) 2.613125930 ); /* 2*(c2+c6) */
157157
158158 tmp6 = tmp12 - tmp7 ; /* phase 2 */
159159 tmp5 = tmp11 - tmp6 ;
160- tmp4 = tmp10 + tmp5 ;
160+ tmp4 = tmp10 - tmp5 ;
161161
162162 wsptr [DCTSIZE * 0 ] = tmp0 + tmp7 ;
163163 wsptr [DCTSIZE * 7 ] = tmp0 - tmp7 ;
164164 wsptr [DCTSIZE * 1 ] = tmp1 + tmp6 ;
165165 wsptr [DCTSIZE * 6 ] = tmp1 - tmp6 ;
166166 wsptr [DCTSIZE * 2 ] = tmp2 + tmp5 ;
167167 wsptr [DCTSIZE * 5 ] = tmp2 - tmp5 ;
168- wsptr [DCTSIZE * 4 ] = tmp3 + tmp4 ;
169- wsptr [DCTSIZE * 3 ] = tmp3 - tmp4 ;
168+ wsptr [DCTSIZE * 3 ] = tmp3 + tmp4 ;
169+ wsptr [DCTSIZE * 4 ] = tmp3 - tmp4 ;
170170
171171 inptr ++ ; /* advance pointers to next column */
172172 quantptr ++ ;
173173 wsptr ++ ;
174174 }
175175
176176 /* Pass 2: process rows from work array, store into output array. */
177- /* Note that we must descale the results by a factor of 8 == 2**3. */
178177
179178 wsptr = workspace ;
180179 for (ctr = 0 ; ctr < DCTSIZE ; ctr ++ ) {
@@ -187,8 +186,10 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
187186
188187 /* Even part */
189188
190- tmp10 = wsptr [0 ] + wsptr [4 ];
191- tmp11 = wsptr [0 ] - wsptr [4 ];
189+ /* Apply signed->unsigned and prepare float->int conversion */
190+ z5 = wsptr [0 ] + ((FAST_FLOAT ) CENTERJSAMPLE + (FAST_FLOAT ) 0.5 );
191+ tmp10 = z5 + wsptr [4 ];
192+ tmp11 = z5 - wsptr [4 ];
192193
193194 tmp13 = wsptr [2 ] + wsptr [6 ];
194195 tmp12 = (wsptr [2 ] - wsptr [6 ]) * ((FAST_FLOAT ) 1.414213562 ) - tmp13 ;
@@ -209,31 +210,23 @@ jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
209210 tmp11 = (z11 - z13 ) * ((FAST_FLOAT ) 1.414213562 );
210211
211212 z5 = (z10 + z12 ) * ((FAST_FLOAT ) 1.847759065 ); /* 2*c2 */
212- tmp10 = ((FAST_FLOAT ) 1.082392200 ) * z12 - z5 ; /* 2*(c2-c6) */
213- tmp12 = ((FAST_FLOAT ) - 2.613125930 ) * z10 + z5 ; /* - 2*(c2+c6) */
213+ tmp10 = z5 - z12 * ((FAST_FLOAT ) 1.082392200 ); /* 2*(c2-c6) */
214+ tmp12 = z5 - z10 * ((FAST_FLOAT ) 2.613125930 ); /* 2*(c2+c6) */
214215
215216 tmp6 = tmp12 - tmp7 ;
216217 tmp5 = tmp11 - tmp6 ;
217- tmp4 = tmp10 + tmp5 ;
218-
219- /* Final output stage: scale down by a factor of 8 and range-limit */
220-
221- outptr [0 ] = range_limit [(int ) DESCALE ((INT32 ) (tmp0 + tmp7 ), 3 )
222- & RANGE_MASK ];
223- outptr [7 ] = range_limit [(int ) DESCALE ((INT32 ) (tmp0 - tmp7 ), 3 )
224- & RANGE_MASK ];
225- outptr [1 ] = range_limit [(int ) DESCALE ((INT32 ) (tmp1 + tmp6 ), 3 )
226- & RANGE_MASK ];
227- outptr [6 ] = range_limit [(int ) DESCALE ((INT32 ) (tmp1 - tmp6 ), 3 )
228- & RANGE_MASK ];
229- outptr [2 ] = range_limit [(int ) DESCALE ((INT32 ) (tmp2 + tmp5 ), 3 )
230- & RANGE_MASK ];
231- outptr [5 ] = range_limit [(int ) DESCALE ((INT32 ) (tmp2 - tmp5 ), 3 )
232- & RANGE_MASK ];
233- outptr [4 ] = range_limit [(int ) DESCALE ((INT32 ) (tmp3 + tmp4 ), 3 )
234- & RANGE_MASK ];
235- outptr [3 ] = range_limit [(int ) DESCALE ((INT32 ) (tmp3 - tmp4 ), 3 )
236- & RANGE_MASK ];
218+ tmp4 = tmp10 - tmp5 ;
219+
220+ /* Final output stage: float->int conversion and range-limit */
221+
222+ outptr [0 ] = range_limit [((int ) (tmp0 + tmp7 )) & RANGE_MASK ];
223+ outptr [7 ] = range_limit [((int ) (tmp0 - tmp7 )) & RANGE_MASK ];
224+ outptr [1 ] = range_limit [((int ) (tmp1 + tmp6 )) & RANGE_MASK ];
225+ outptr [6 ] = range_limit [((int ) (tmp1 - tmp6 )) & RANGE_MASK ];
226+ outptr [2 ] = range_limit [((int ) (tmp2 + tmp5 )) & RANGE_MASK ];
227+ outptr [5 ] = range_limit [((int ) (tmp2 - tmp5 )) & RANGE_MASK ];
228+ outptr [3 ] = range_limit [((int ) (tmp3 + tmp4 )) & RANGE_MASK ];
229+ outptr [4 ] = range_limit [((int ) (tmp3 - tmp4 )) & RANGE_MASK ];
237230
238231 wsptr += DCTSIZE ; /* advance pointer to next row */
239232 }
0 commit comments