Main MRPT website > C++ reference for MRPT 1.9.9
jidctred.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #define JPEG_INTERNALS
11 #include "jinclude.h"
12 #include "mrpt_jpeglib.h"
13 #include "jdct.h" /* Private declarations for DCT subsystem */
14 
15 #ifdef IDCT_SCALING_SUPPORTED
16 
17 /*
18  * This module is specialized to the case DCTSIZE = 8.
19  */
20 
21 #if DCTSIZE != 8
22 Sorry, this code only copes with 8x8 DCTs./* deliberate syntax err */
23 #endif
24 
25 /* Scaling is the same as in jidctint.c. */
26 
27 #if BITS_IN_JSAMPLE == 8
28 #define CONST_BITS 13
29 #define PASS1_BITS 2
30 #else
31 #define CONST_BITS 13
32 #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
33 #endif
34 
35 /* Some C compilers fail to reduce "FIX(constant)" at compile time, thus
36  * causing a lot of useless floating-point operations at run time.
37  * To get around this we use the following pre-calculated constants.
38  * If you change CONST_BITS you may want to add appropriate values.
39  * (With a reasonable C compiler, you can just rely on the FIX() macro...)
40  */
41 
42 #if CONST_BITS == 13
43 #define FIX_0_211164243 ((INT32)1730) /* FIX(0.211164243) */
44 #define FIX_0_509795579 ((INT32)4176) /* FIX(0.509795579) */
45 #define FIX_0_601344887 ((INT32)4926) /* FIX(0.601344887) */
46 #define FIX_0_720959822 ((INT32)5906) /* FIX(0.720959822) */
47 #define FIX_0_765366865 ((INT32)6270) /* FIX(0.765366865) */
48 #define FIX_0_850430095 ((INT32)6967) /* FIX(0.850430095) */
49 #define FIX_0_899976223 ((INT32)7373) /* FIX(0.899976223) */
50 #define FIX_1_061594337 ((INT32)8697) /* FIX(1.061594337) */
51 #define FIX_1_272758580 ((INT32)10426) /* FIX(1.272758580) */
52 #define FIX_1_451774981 ((INT32)11893) /* FIX(1.451774981) */
53 #define FIX_1_847759065 ((INT32)15137) /* FIX(1.847759065) */
54 #define FIX_2_172734803 ((INT32)17799) /* FIX(2.172734803) */
55 #define FIX_2_562915447 ((INT32)20995) /* FIX(2.562915447) */
56 #define FIX_3_624509785 ((INT32)29692) /* FIX(3.624509785) */
57 #else
58 #define FIX_0_211164243 FIX(0.211164243)
59 #define FIX_0_509795579 FIX(0.509795579)
60 #define FIX_0_601344887 FIX(0.601344887)
61 #define FIX_0_720959822 FIX(0.720959822)
62 #define FIX_0_765366865 FIX(0.765366865)
63 #define FIX_0_850430095 FIX(0.850430095)
64 #define FIX_0_899976223 FIX(0.899976223)
65 #define FIX_1_061594337 FIX(1.061594337)
66 #define FIX_1_272758580 FIX(1.272758580)
67 #define FIX_1_451774981 FIX(1.451774981)
68 #define FIX_1_847759065 FIX(1.847759065)
69 #define FIX_2_172734803 FIX(2.172734803)
70 #define FIX_2_562915447 FIX(2.562915447)
71 #define FIX_3_624509785 FIX(3.624509785)
72 #endif
73 
74 /* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.
75  * For 8-bit samples with the recommended scaling, all the variable
76  * and constant values involved are no more than 16 bits wide, so a
77  * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.
78  * For 12-bit samples, a full 32-bit multiplication will be needed.
79  */
80 
81 #if BITS_IN_JSAMPLE == 8
82 #define MULTIPLY(var, const) MULTIPLY16C16(var, const)
83 #else
84 #define MULTIPLY(var, const) ((var) * (const))
85 #endif
86 
87 /* Dequantize a coefficient by multiplying it by the multiplier-table
88  * entry; produce an int result. In this module, both inputs and result
89  * are 16 bits or less, so either int or short multiply will work.
90  */
91 
92 #define DEQUANTIZE(coef, quantval) (((ISLOW_MULT_TYPE)(coef)) * (quantval))
93 
94  /*
95  * Perform dequantization and inverse DCT on one block of coefficients,
96  * producing a reduced-size 4x4 output block.
97  */
98 
99  GLOBAL(void) jpeg_idct_4x4(
102 {
103  INT32 tmp0, tmp2, tmp10, tmp12;
107  int* wsptr;
110  int ctr;
111  int workspace[DCTSIZE * 4]; /* buffers data between passes */
113 
114  /* Pass 1: process columns from input, store into work array. */
115 
116  inptr = coef_block;
118  wsptr = workspace;
119  for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--)
120  {
121  /* Don't bother to process column 4, because second pass won't use it */
122  if (ctr == DCTSIZE - 4) continue;
123  if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 2] == 0 &&
124  inptr[DCTSIZE * 3] == 0 && inptr[DCTSIZE * 5] == 0 &&
125  inptr[DCTSIZE * 6] == 0 && inptr[DCTSIZE * 7] == 0)
126  {
127  /* AC terms all zero; we need not examine term 4 for 4x4 output */
128  int dcval = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0])
129  << PASS1_BITS;
130 
131  wsptr[DCTSIZE * 0] = dcval;
132  wsptr[DCTSIZE * 1] = dcval;
133  wsptr[DCTSIZE * 2] = dcval;
134  wsptr[DCTSIZE * 3] = dcval;
135 
136  continue;
137  }
138 
139  /* Even part */
140 
141  tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
142  tmp0 <<= (CONST_BITS + 1);
143 
144  z2 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
145  z3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
146 
148 
149  tmp10 = tmp0 + tmp2;
150  tmp12 = tmp0 - tmp2;
151 
152  /* Odd part */
153 
154  z1 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
155  z2 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
156  z3 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
157  z4 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
158 
159  tmp0 = MULTIPLY(z1, -FIX_0_211164243) /* sqrt(2) * (c3-c1) */
160  + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
161  + MULTIPLY(z3, -FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
162  + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
163 
164  tmp2 = MULTIPLY(z1, -FIX_0_509795579) /* sqrt(2) * (c7-c5) */
165  + MULTIPLY(z2, -FIX_0_601344887) /* sqrt(2) * (c5-c1) */
166  + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
167  + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
168 
169  /* Final output stage */
170 
171  wsptr[DCTSIZE * 0] =
172  (int)DESCALE(tmp10 + tmp2, CONST_BITS - PASS1_BITS + 1);
173  wsptr[DCTSIZE * 3] =
174  (int)DESCALE(tmp10 - tmp2, CONST_BITS - PASS1_BITS + 1);
175  wsptr[DCTSIZE * 1] =
176  (int)DESCALE(tmp12 + tmp0, CONST_BITS - PASS1_BITS + 1);
177  wsptr[DCTSIZE * 2] =
178  (int)DESCALE(tmp12 - tmp0, CONST_BITS - PASS1_BITS + 1);
179  }
180 
181  /* Pass 2: process 4 rows from work array, store into output array. */
182 
183  wsptr = workspace;
184  for (ctr = 0; ctr < 4; ctr++)
185  {
187 /* It's not clear whether a zero row test is worthwhile here ... */
188 
189 #ifndef NO_ZERO_ROW_TEST
190  if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[5] == 0 &&
191  wsptr[6] == 0 && wsptr[7] == 0)
192  {
193  /* AC terms all zero */
194  JSAMPLE dcval =
195  range_limit[(int)DESCALE((INT32)wsptr[0], PASS1_BITS + 3) &
196  RANGE_MASK];
197 
198  outptr[0] = dcval;
199  outptr[1] = dcval;
200  outptr[2] = dcval;
201  outptr[3] = dcval;
202 
203  wsptr += DCTSIZE; /* advance pointer to next row */
204  continue;
205  }
206 #endif
207 
208  /* Even part */
209 
210  tmp0 = ((INT32)wsptr[0]) << (CONST_BITS + 1);
211 
212  tmp2 = MULTIPLY((INT32)wsptr[2], FIX_1_847759065) +
214 
215  tmp10 = tmp0 + tmp2;
216  tmp12 = tmp0 - tmp2;
217 
218  /* Odd part */
219 
220  z1 = (INT32)wsptr[7];
221  z2 = (INT32)wsptr[5];
222  z3 = (INT32)wsptr[3];
223  z4 = (INT32)wsptr[1];
224 
225  tmp0 = MULTIPLY(z1, -FIX_0_211164243) /* sqrt(2) * (c3-c1) */
226  + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
227  + MULTIPLY(z3, -FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
228  + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
229 
230  tmp2 = MULTIPLY(z1, -FIX_0_509795579) /* sqrt(2) * (c7-c5) */
231  + MULTIPLY(z2, -FIX_0_601344887) /* sqrt(2) * (c5-c1) */
232  + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
233  + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
234 
235  /* Final output stage */
236 
237  outptr[0] =
238  range_limit[(int)DESCALE(
239  tmp10 + tmp2, CONST_BITS + PASS1_BITS + 3 + 1) &
240  RANGE_MASK];
241  outptr[3] =
242  range_limit[(int)DESCALE(
243  tmp10 - tmp2, CONST_BITS + PASS1_BITS + 3 + 1) &
244  RANGE_MASK];
245  outptr[1] =
246  range_limit[(int)DESCALE(
247  tmp12 + tmp0, CONST_BITS + PASS1_BITS + 3 + 1) &
248  RANGE_MASK];
249  outptr[2] =
250  range_limit[(int)DESCALE(
251  tmp12 - tmp0, CONST_BITS + PASS1_BITS + 3 + 1) &
252  RANGE_MASK];
253 
254  wsptr += DCTSIZE; /* advance pointer to next row */
255  }
256 }
257 
258 /*
259  * Perform dequantization and inverse DCT on one block of coefficients,
260  * producing a reduced-size 2x2 output block.
261  */
262 
263 GLOBAL(void)
267 {
268  INT32 tmp0, tmp10, z1;
269  JCOEFPTR inptr;
271  int* wsptr;
274  int ctr;
275  int workspace[DCTSIZE * 2]; /* buffers data between passes */
277 
278  /* Pass 1: process columns from input, store into work array. */
279 
280  inptr = coef_block;
282  wsptr = workspace;
283  for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--)
284  {
285  /* Don't bother to process columns 2,4,6 */
286  if (ctr == DCTSIZE - 2 || ctr == DCTSIZE - 4 || ctr == DCTSIZE - 6)
287  continue;
288  if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 3] == 0 &&
289  inptr[DCTSIZE * 5] == 0 && inptr[DCTSIZE * 7] == 0)
290  {
291  /* AC terms all zero; we need not examine terms 2,4,6 for 2x2 output
292  */
293  int dcval = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0])
294  << PASS1_BITS;
295 
296  wsptr[DCTSIZE * 0] = dcval;
297  wsptr[DCTSIZE * 1] = dcval;
298 
299  continue;
300  }
301 
302  /* Even part */
303 
304  z1 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
305  tmp10 = z1 << (CONST_BITS + 2);
306 
307  /* Odd part */
308 
309  z1 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
310  tmp0 = MULTIPLY(z1, -FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
311  z1 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
312  tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
313  z1 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
314  tmp0 += MULTIPLY(z1, -FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
315  z1 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
316  tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
317 
318  /* Final output stage */
319 
320  wsptr[DCTSIZE * 0] =
321  (int)DESCALE(tmp10 + tmp0, CONST_BITS - PASS1_BITS + 2);
322  wsptr[DCTSIZE * 1] =
323  (int)DESCALE(tmp10 - tmp0, CONST_BITS - PASS1_BITS + 2);
324  }
325 
326  /* Pass 2: process 2 rows from work array, store into output array. */
327 
328  wsptr = workspace;
329  for (ctr = 0; ctr < 2; ctr++)
330  {
332 /* It's not clear whether a zero row test is worthwhile here ... */
333 
334 #ifndef NO_ZERO_ROW_TEST
335  if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0)
336  {
337  /* AC terms all zero */
338  JSAMPLE dcval =
339  range_limit[(int)DESCALE((INT32)wsptr[0], PASS1_BITS + 3) &
340  RANGE_MASK];
341 
342  outptr[0] = dcval;
343  outptr[1] = dcval;
344 
345  wsptr += DCTSIZE; /* advance pointer to next row */
346  continue;
347  }
348 #endif
349 
350  /* Even part */
351 
352  tmp10 = ((INT32)wsptr[0]) << (CONST_BITS + 2);
353 
354  /* Odd part */
355 
356  tmp0 =
357  MULTIPLY(
358  (INT32)wsptr[7], -FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
359  +
360  MULTIPLY(
361  (INT32)wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
362  + MULTIPLY(
363  (INT32)wsptr[3],
364  -FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
365  +
366  MULTIPLY(
367  (INT32)wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
368 
369  /* Final output stage */
370 
371  outptr[0] =
372  range_limit[(int)DESCALE(
373  tmp10 + tmp0, CONST_BITS + PASS1_BITS + 3 + 2) &
374  RANGE_MASK];
375  outptr[1] =
376  range_limit[(int)DESCALE(
377  tmp10 - tmp0, CONST_BITS + PASS1_BITS + 3 + 2) &
378  RANGE_MASK];
379 
380  wsptr += DCTSIZE; /* advance pointer to next row */
381  }
382 }
383 
384 /*
385  * Perform dequantization and inverse DCT on one block of coefficients,
386  * producing a reduced-size 1x1 output block.
387  */
388 
389 GLOBAL(void)
393 {
394  int dcval;
398 
399  /* We hardly need an inverse DCT routine for this: just take the
400  * average pixel value, which is one-eighth of the DC coefficient.
401  */
403  dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
404  dcval = (int)DESCALE((INT32)dcval, 3);
405 
407 }
408 
409 #endif /* IDCT_SCALING_SUPPORTED */
#define DESCALE(x, n)
Definition: jdct.h:142
JCOEFPTR inptr
Definition: jidctred.cpp:105
#define IDCT_range_limit(cinfo)
Definition: jdct.h:68
INT32 z2
Definition: jidctred.cpp:104
char JSAMPLE
Definition: jmorecfg.h:58
#define FIX_0_850430095
Definition: jidctred.cpp:48
jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr, JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)
Definition: jidctred.cpp:264
FAST_FLOAT tmp12
Definition: jidctflt.cpp:40
#define DCTSIZE
Definition: mrpt_jpeglib.h:36
INT32 z3
Definition: jidctred.cpp:104
jpeg_component_info JCOEFPTR JSAMPARRAY JDIMENSION output_col
Definition: jidctred.cpp:102
#define RANGE_MASK
Definition: jdct.h:70
#define FIX_0_211164243
Definition: jidctred.cpp:43
#define FIX_1_061594337
Definition: jidctred.cpp:50
JSAMPLE FAR * JSAMPROW
Definition: mrpt_jpeglib.h:60
#define FIX_1_272758580
Definition: jidctred.cpp:51
long INT32
Definition: jmorecfg.h:151
#define SHIFT_TEMPS
Definition: jpegint.h:301
#define MULTIPLY(var, const)
Definition: jidctred.cpp:82
#define FIX_0_899976223
Definition: jidctred.cpp:49
#define FIX_0_765366865
Definition: jidctred.cpp:47
#define FIX_2_172734803
Definition: jidctred.cpp:54
for(ctr=DCTSIZE;ctr > 0;inptr++, quantptr++, wsptr++, ctr--)
Definition: jidctred.cpp:119
#define CONST_BITS
Definition: jidctred.cpp:28
JSAMPROW * JSAMPARRAY
Definition: mrpt_jpeglib.h:61
#define FIX_3_624509785
Definition: jidctred.cpp:56
ISLOW_MULT_TYPE * quantptr
Definition: jidctred.cpp:106
JCOEF FAR * JCOEFPTR
Definition: mrpt_jpeglib.h:69
#define FIX_2_562915447
Definition: jidctred.cpp:55
MULTIPLIER ISLOW_MULT_TYPE
Definition: jdct.h:49
#define DEQUANTIZE(coef, quantval)
Definition: jidctred.cpp:92
int * wsptr
Definition: jidctred.cpp:107
int ctr
Definition: jidctred.cpp:110
jpeg_component_info * compptr
Definition: jidctred.cpp:100
Definition: inftrees.h:28
#define FIX_0_601344887
Definition: jidctred.cpp:45
#define FIX_0_509795579
Definition: jidctred.cpp:44
jpeg_idct_1x1(j_decompress_ptr cinfo, jpeg_component_info *compptr, JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)
Definition: jidctred.cpp:390
#define FIX_1_451774981
Definition: jidctred.cpp:52
FAST_FLOAT tmp10
Definition: jidctflt.cpp:40
INT32 z4
Definition: jidctred.cpp:104
#define FIX_1_847759065
Definition: jidctred.cpp:53
jpeg_component_info JCOEFPTR coef_block
Definition: jidctred.cpp:100
unsigned int JDIMENSION
Definition: jmorecfg.h:161
INT32 z1
Definition: jidctred.cpp:104
#define PASS1_BITS
Definition: jidctred.cpp:29
int workspace[DCTSIZE *4]
Definition: jidctred.cpp:111
JSAMPROW outptr
Definition: jidctred.cpp:108
JSAMPLE * range_limit
Definition: jidctred.cpp:109
#define FIX_0_720959822
Definition: jidctred.cpp:46
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jidctred.cpp:100
GLOBAL(void) jpeg_idct_4x4(j_decompress_ptr cinfo



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019