1 /*
2  * jdct.h
3  *
4  * Copyright (C) 1994-1996, Thomas G. Lane.
5  * Modified 2002-2015 by Guido Vollbeding.
6  * This file is part of the Independent JPEG Group's software.
7  * For conditions of distribution and use, see the accompanying README file.
8  *
9  * This include file contains common declarations for the forward and
10  * inverse DCT modules.  These declarations are private to the DCT managers
11  * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.
12  * The individual DCT algorithms are kept in separate files to ease
13  * machine-dependent tuning (e.g., assembly coding).
14  */
15 
16 
17 /*
18  * A forward DCT routine is given a pointer to an input sample array and
19  * a pointer to a work area of type DCTELEM[]; the DCT is to be performed
20  * in-place in that buffer.  Type DCTELEM is int for 8-bit samples, INT32
21  * for 12-bit samples.  (NOTE: Floating-point DCT implementations use an
22  * array of type FAST_FLOAT, instead.)
23  * The input data is to be fetched from the sample array starting at a
24  * specified column.  (Any row offset needed will be applied to the array
25  * pointer before it is passed to the FDCT code.)
26  * Note that the number of samples fetched by the FDCT routine is
27  * DCT_h_scaled_size * DCT_v_scaled_size.
28  * The DCT outputs are returned scaled up by a factor of 8; they therefore
29  * have a range of +-8K for 8-bit data, +-128K for 12-bit data.  This
30  * convention improves accuracy in integer implementations and saves some
31  * work in floating-point ones.
32  * Quantization of the output coefficients is done by jcdctmgr.c.
33  */
34 
35 #if BITS_IN_JSAMPLE == 8
36 typedef int DCTELEM;		/* 16 or 32 bits is fine */
37 #else
38 typedef INT32 DCTELEM;		/* must have 32 bits */
39 #endif
40 
41 typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data,
42 					       JSAMPARRAY sample_data,
43 					       JDIMENSION start_col));
44 typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data,
45 					     JSAMPARRAY sample_data,
46 					     JDIMENSION start_col));
47 
48 
49 /*
50  * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer
51  * to an output sample array.  The routine must dequantize the input data as
52  * well as perform the IDCT; for dequantization, it uses the multiplier table
53  * pointed to by compptr->dct_table.  The output data is to be placed into the
54  * sample array starting at a specified column.  (Any row offset needed will
55  * be applied to the array pointer before it is passed to the IDCT code.)
56  * Note that the number of samples emitted by the IDCT routine is
57  * DCT_h_scaled_size * DCT_v_scaled_size.
58  */
59 
60 /* typedef inverse_DCT_method_ptr is declared in jpegint.h */
61 
62 /*
63  * Each IDCT routine has its own ideas about the best dct_table element type.
64  */
65 
66 typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
67 #if BITS_IN_JSAMPLE == 8
68 typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
69 #define IFAST_SCALE_BITS  2	/* fractional bits in scale factors */
70 #else
71 typedef INT32 IFAST_MULT_TYPE;	/* need 32 bits for scaled quantizers */
72 #define IFAST_SCALE_BITS  13	/* fractional bits in scale factors */
73 #endif
74 typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
75 
76 
77 /*
78  * Each IDCT routine is responsible for range-limiting its results and
79  * converting them to unsigned form (0..MAXJSAMPLE).  The raw outputs could
80  * be quite far out of range if the input data is corrupt, so a bulletproof
81  * range-limiting step is required.  We use a mask-and-table-lookup method
82  * to do the combined operations quickly, assuming that MAXJSAMPLE+1
83  * is a power of 2.  See the comments with prepare_range_limit_table
84  * (in jdmaster.c) for more info.
85  */
86 
87 #define RANGE_MASK  (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
88 #define RANGE_CENTER  (MAXJSAMPLE * 2 + 2)
89 #define RANGE_SUBSET  (RANGE_CENTER - CENTERJSAMPLE)
90 
91 #define IDCT_range_limit(cinfo)  ((cinfo)->sample_range_limit - RANGE_SUBSET)
92 
93 
94 /* Short forms of external names for systems with brain-damaged linkers. */
95 
96 #ifdef NEED_SHORT_EXTERNAL_NAMES
97 #define jpeg_fdct_islow		jFDislow
98 #define jpeg_fdct_ifast		jFDifast
99 #define jpeg_fdct_float		jFDfloat
100 #define jpeg_fdct_7x7		jFD7x7
101 #define jpeg_fdct_6x6		jFD6x6
102 #define jpeg_fdct_5x5		jFD5x5
103 #define jpeg_fdct_4x4		jFD4x4
104 #define jpeg_fdct_3x3		jFD3x3
105 #define jpeg_fdct_2x2		jFD2x2
106 #define jpeg_fdct_1x1		jFD1x1
107 #define jpeg_fdct_9x9		jFD9x9
108 #define jpeg_fdct_10x10		jFD10x10
109 #define jpeg_fdct_11x11		jFD11x11
110 #define jpeg_fdct_12x12		jFD12x12
111 #define jpeg_fdct_13x13		jFD13x13
112 #define jpeg_fdct_14x14		jFD14x14
113 #define jpeg_fdct_15x15		jFD15x15
114 #define jpeg_fdct_16x16		jFD16x16
115 #define jpeg_fdct_16x8		jFD16x8
116 #define jpeg_fdct_14x7		jFD14x7
117 #define jpeg_fdct_12x6		jFD12x6
118 #define jpeg_fdct_10x5		jFD10x5
119 #define jpeg_fdct_8x4		jFD8x4
120 #define jpeg_fdct_6x3		jFD6x3
121 #define jpeg_fdct_4x2		jFD4x2
122 #define jpeg_fdct_2x1		jFD2x1
123 #define jpeg_fdct_8x16		jFD8x16
124 #define jpeg_fdct_7x14		jFD7x14
125 #define jpeg_fdct_6x12		jFD6x12
126 #define jpeg_fdct_5x10		jFD5x10
127 #define jpeg_fdct_4x8		jFD4x8
128 #define jpeg_fdct_3x6		jFD3x6
129 #define jpeg_fdct_2x4		jFD2x4
130 #define jpeg_fdct_1x2		jFD1x2
131 #define jpeg_idct_islow		jRDislow
132 #define jpeg_idct_ifast		jRDifast
133 #define jpeg_idct_float		jRDfloat
134 #define jpeg_idct_7x7		jRD7x7
135 #define jpeg_idct_6x6		jRD6x6
136 #define jpeg_idct_5x5		jRD5x5
137 #define jpeg_idct_4x4		jRD4x4
138 #define jpeg_idct_3x3		jRD3x3
139 #define jpeg_idct_2x2		jRD2x2
140 #define jpeg_idct_1x1		jRD1x1
141 #define jpeg_idct_9x9		jRD9x9
142 #define jpeg_idct_10x10		jRD10x10
143 #define jpeg_idct_11x11		jRD11x11
144 #define jpeg_idct_12x12		jRD12x12
145 #define jpeg_idct_13x13		jRD13x13
146 #define jpeg_idct_14x14		jRD14x14
147 #define jpeg_idct_15x15		jRD15x15
148 #define jpeg_idct_16x16		jRD16x16
149 #define jpeg_idct_16x8		jRD16x8
150 #define jpeg_idct_14x7		jRD14x7
151 #define jpeg_idct_12x6		jRD12x6
152 #define jpeg_idct_10x5		jRD10x5
153 #define jpeg_idct_8x4		jRD8x4
154 #define jpeg_idct_6x3		jRD6x3
155 #define jpeg_idct_4x2		jRD4x2
156 #define jpeg_idct_2x1		jRD2x1
157 #define jpeg_idct_8x16		jRD8x16
158 #define jpeg_idct_7x14		jRD7x14
159 #define jpeg_idct_6x12		jRD6x12
160 #define jpeg_idct_5x10		jRD5x10
161 #define jpeg_idct_4x8		jRD4x8
162 #define jpeg_idct_3x6		jRD3x8
163 #define jpeg_idct_2x4		jRD2x4
164 #define jpeg_idct_1x2		jRD1x2
165 #endif /* NEED_SHORT_EXTERNAL_NAMES */
166 
167 /* Extern declarations for the forward and inverse DCT routines. */
168 
169 EXTERN(void) jpeg_fdct_islow
170     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
171 EXTERN(void) jpeg_fdct_ifast
172     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
173 EXTERN(void) jpeg_fdct_float
174     JPP((FAST_FLOAT * data, JSAMPARRAY sample_data, JDIMENSION start_col));
175 EXTERN(void) jpeg_fdct_7x7
176     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
177 EXTERN(void) jpeg_fdct_6x6
178     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
179 EXTERN(void) jpeg_fdct_5x5
180     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
181 EXTERN(void) jpeg_fdct_4x4
182     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
183 EXTERN(void) jpeg_fdct_3x3
184     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
185 EXTERN(void) jpeg_fdct_2x2
186     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
187 EXTERN(void) jpeg_fdct_1x1
188     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
189 EXTERN(void) jpeg_fdct_9x9
190     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
191 EXTERN(void) jpeg_fdct_10x10
192     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
193 EXTERN(void) jpeg_fdct_11x11
194     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
195 EXTERN(void) jpeg_fdct_12x12
196     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
197 EXTERN(void) jpeg_fdct_13x13
198     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
199 EXTERN(void) jpeg_fdct_14x14
200     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
201 EXTERN(void) jpeg_fdct_15x15
202     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
203 EXTERN(void) jpeg_fdct_16x16
204     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
205 EXTERN(void) jpeg_fdct_16x8
206     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
207 EXTERN(void) jpeg_fdct_14x7
208     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
209 EXTERN(void) jpeg_fdct_12x6
210     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
211 EXTERN(void) jpeg_fdct_10x5
212     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
213 EXTERN(void) jpeg_fdct_8x4
214     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
215 EXTERN(void) jpeg_fdct_6x3
216     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
217 EXTERN(void) jpeg_fdct_4x2
218     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
219 EXTERN(void) jpeg_fdct_2x1
220     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
221 EXTERN(void) jpeg_fdct_8x16
222     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
223 EXTERN(void) jpeg_fdct_7x14
224     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
225 EXTERN(void) jpeg_fdct_6x12
226     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
227 EXTERN(void) jpeg_fdct_5x10
228     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
229 EXTERN(void) jpeg_fdct_4x8
230     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
231 EXTERN(void) jpeg_fdct_3x6
232     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
233 EXTERN(void) jpeg_fdct_2x4
234     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
235 EXTERN(void) jpeg_fdct_1x2
236     JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));
237 
238 EXTERN(void) jpeg_idct_islow
239     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
240 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
241 EXTERN(void) jpeg_idct_ifast
242     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
243 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
244 EXTERN(void) jpeg_idct_float
245     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
246 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
247 EXTERN(void) jpeg_idct_7x7
248     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
249 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
250 EXTERN(void) jpeg_idct_6x6
251     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
252 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
253 EXTERN(void) jpeg_idct_5x5
254     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
255 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
256 EXTERN(void) jpeg_idct_4x4
257     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
258 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
259 EXTERN(void) jpeg_idct_3x3
260     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
261 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
262 EXTERN(void) jpeg_idct_2x2
263     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
264 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
265 EXTERN(void) jpeg_idct_1x1
266     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
267 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
268 EXTERN(void) jpeg_idct_9x9
269     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
270 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
271 EXTERN(void) jpeg_idct_10x10
272     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
273 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
274 EXTERN(void) jpeg_idct_11x11
275     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
276 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
277 EXTERN(void) jpeg_idct_12x12
278     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
279 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
280 EXTERN(void) jpeg_idct_13x13
281     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
282 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
283 EXTERN(void) jpeg_idct_14x14
284     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
285 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
286 EXTERN(void) jpeg_idct_15x15
287     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
288 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
289 EXTERN(void) jpeg_idct_16x16
290     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
291 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
292 EXTERN(void) jpeg_idct_16x8
293     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
294 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
295 EXTERN(void) jpeg_idct_14x7
296     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
297 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
298 EXTERN(void) jpeg_idct_12x6
299     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
300 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
301 EXTERN(void) jpeg_idct_10x5
302     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
303 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
304 EXTERN(void) jpeg_idct_8x4
305     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
306 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
307 EXTERN(void) jpeg_idct_6x3
308     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
309 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
310 EXTERN(void) jpeg_idct_4x2
311     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
312 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
313 EXTERN(void) jpeg_idct_2x1
314     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
315 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
316 EXTERN(void) jpeg_idct_8x16
317     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
318 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
319 EXTERN(void) jpeg_idct_7x14
320     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
321 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
322 EXTERN(void) jpeg_idct_6x12
323     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
324 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
325 EXTERN(void) jpeg_idct_5x10
326     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
327 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
328 EXTERN(void) jpeg_idct_4x8
329     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
330 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
331 EXTERN(void) jpeg_idct_3x6
332     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
333 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
334 EXTERN(void) jpeg_idct_2x4
335     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
336 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
337 EXTERN(void) jpeg_idct_1x2
338     JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
339 	 JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
340 
341 
342 /*
343  * Macros for handling fixed-point arithmetic; these are used by many
344  * but not all of the DCT/IDCT modules.
345  *
346  * All values are expected to be of type INT32.
347  * Fractional constants are scaled left by CONST_BITS bits.
348  * CONST_BITS is defined within each module using these macros,
349  * and may differ from one module to the next.
350  */
351 
352 #define ONE	((INT32) 1)
353 #define CONST_SCALE (ONE << CONST_BITS)
354 
355 /* Convert a positive real constant to an integer scaled by CONST_SCALE.
356  * Caution: some C compilers fail to reduce "FIX(constant)" at compile time,
357  * thus causing a lot of useless floating-point operations at run time.
358  */
359 
360 #define FIX(x)	((INT32) ((x) * CONST_SCALE + 0.5))
361 
362 /* Descale and correctly round an INT32 value that's scaled by N bits.
363  * We assume RIGHT_SHIFT rounds towards minus infinity, so adding
364  * the fudge factor is correct for either sign of X.
365  */
366 
367 #define DESCALE(x,n)  RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
368 
369 /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
370  * This macro is used only when the two inputs will actually be no more than
371  * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a
372  * full 32x32 multiply.  This provides a useful speedup on many machines.
373  * Unfortunately there is no way to specify a 16x16->32 multiply portably
374  * in C, but some C compilers will do the right thing if you provide the
375  * correct combination of casts.
376  */
377 
378 #ifdef SHORTxSHORT_32		/* may work if 'int' is 32 bits */
379 #define MULTIPLY16C16(var,const)  (((INT16) (var)) * ((INT16) (const)))
380 #endif
381 #ifdef SHORTxLCONST_32		/* known to work with Microsoft C 6.0 */
382 #define MULTIPLY16C16(var,const)  (((INT16) (var)) * ((INT32) (const)))
383 #endif
384 
385 #ifndef MULTIPLY16C16		/* default definition */
386 #define MULTIPLY16C16(var,const)  ((var) * (const))
387 #endif
388 
389 /* Same except both inputs are variables. */
390 
391 #ifdef SHORTxSHORT_32		/* may work if 'int' is 32 bits */
392 #define MULTIPLY16V16(var1,var2)  (((INT16) (var1)) * ((INT16) (var2)))
393 #endif
394 
395 #ifndef MULTIPLY16V16		/* default definition */
396 #define MULTIPLY16V16(var1,var2)  ((var1) * (var2))
397 #endif
398 
399 /* Like RIGHT_SHIFT, but applies to a DCTELEM.
400  * We assume that int right shift is unsigned if INT32 right shift is.
401  */
402 
403 #ifdef RIGHT_SHIFT_IS_UNSIGNED
404 #define ISHIFT_TEMPS	DCTELEM ishift_temp;
405 #if BITS_IN_JSAMPLE == 8
406 #define DCTELEMBITS  16		/* DCTELEM may be 16 or 32 bits */
407 #else
408 #define DCTELEMBITS  32		/* DCTELEM must be 32 bits */
409 #endif
410 #define IRIGHT_SHIFT(x,shft)  \
411     ((ishift_temp = (x)) < 0 ? \
412      (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
413      (ishift_temp >> (shft)))
414 #else
415 #define ISHIFT_TEMPS
416 #define IRIGHT_SHIFT(x,shft)	((x) >> (shft))
417 #endif
418