Main MRPT website > C++ reference for MRPT 1.9.9
jidctflt.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 DCT_FLOAT_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 /* Dequantize a coefficient by multiplying it by the multiplier-table
26  * entry; produce a float result.
27  */
28 
29 #define DEQUANTIZE(coef, quantval) (((FAST_FLOAT)(coef)) * (quantval))
30 
31  /*
32  * Perform dequantization and inverse DCT on one block of coefficients.
33  */
34 
35  GLOBAL(void) jpeg_idct_float(
38 {
39  FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
40  FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
41  FAST_FLOAT z5, z10, z11, z12, z13;
44  FAST_FLOAT* wsptr;
47  int ctr;
48  FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
50 
51  /* Pass 1: process columns from input, store into work array. */
52 
53  inptr = coef_block;
55  wsptr = workspace;
56  for (ctr = DCTSIZE; ctr > 0; ctr--)
57  {
58  /* Due to quantization, we will usually find that many of the input
59  * coefficients are zero, especially the AC terms. We can exploit this
60  * by short-circuiting the IDCT calculation for any column in which all
61  * the AC terms are zero. In that case each output is equal to the
62  * DC coefficient (with scale factor as needed).
63  * With typical images and quantization tables, half or more of the
64  * column DCT calculations can be simplified this way.
65  */
66 
67  if (inptr[DCTSIZE * 1] == 0 && inptr[DCTSIZE * 2] == 0 &&
68  inptr[DCTSIZE * 3] == 0 && inptr[DCTSIZE * 4] == 0 &&
69  inptr[DCTSIZE * 5] == 0 && inptr[DCTSIZE * 6] == 0 &&
70  inptr[DCTSIZE * 7] == 0)
71  {
72  /* AC terms all zero */
73  FAST_FLOAT dcval =
75 
76  wsptr[DCTSIZE * 0] = dcval;
77  wsptr[DCTSIZE * 1] = dcval;
78  wsptr[DCTSIZE * 2] = dcval;
79  wsptr[DCTSIZE * 3] = dcval;
80  wsptr[DCTSIZE * 4] = dcval;
81  wsptr[DCTSIZE * 5] = dcval;
82  wsptr[DCTSIZE * 6] = dcval;
83  wsptr[DCTSIZE * 7] = dcval;
84 
85  inptr++; /* advance pointers to next column */
86  quantptr++;
87  wsptr++;
88  continue;
89  }
90 
91  /* Even part */
92 
93  tmp0 = DEQUANTIZE(inptr[DCTSIZE * 0], quantptr[DCTSIZE * 0]);
94  tmp1 = DEQUANTIZE(inptr[DCTSIZE * 2], quantptr[DCTSIZE * 2]);
95  tmp2 = DEQUANTIZE(inptr[DCTSIZE * 4], quantptr[DCTSIZE * 4]);
96  tmp3 = DEQUANTIZE(inptr[DCTSIZE * 6], quantptr[DCTSIZE * 6]);
97 
98  tmp10 = tmp0 + tmp2; /* phase 3 */
99  tmp11 = tmp0 - tmp2;
100 
101  tmp13 = tmp1 + tmp3; /* phases 5-3 */
102  tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT)1.414213562) - tmp13; /* 2*c4 */
103 
104  tmp0 = tmp10 + tmp13; /* phase 2 */
105  tmp3 = tmp10 - tmp13;
106  tmp1 = tmp11 + tmp12;
107  tmp2 = tmp11 - tmp12;
108 
109  /* Odd part */
110 
111  tmp4 = DEQUANTIZE(inptr[DCTSIZE * 1], quantptr[DCTSIZE * 1]);
112  tmp5 = DEQUANTIZE(inptr[DCTSIZE * 3], quantptr[DCTSIZE * 3]);
113  tmp6 = DEQUANTIZE(inptr[DCTSIZE * 5], quantptr[DCTSIZE * 5]);
114  tmp7 = DEQUANTIZE(inptr[DCTSIZE * 7], quantptr[DCTSIZE * 7]);
115 
116  z13 = tmp6 + tmp5; /* phase 6 */
117  z10 = tmp6 - tmp5;
118  z11 = tmp4 + tmp7;
119  z12 = tmp4 - tmp7;
120 
121  tmp7 = z11 + z13; /* phase 5 */
122  tmp11 = (z11 - z13) * ((FAST_FLOAT)1.414213562); /* 2*c4 */
123 
124  z5 = (z10 + z12) * ((FAST_FLOAT)1.847759065); /* 2*c2 */
125  tmp10 = ((FAST_FLOAT)1.082392200) * z12 - z5; /* 2*(c2-c6) */
126  tmp12 = ((FAST_FLOAT)-2.613125930) * z10 + z5; /* -2*(c2+c6) */
127 
128  tmp6 = tmp12 - tmp7; /* phase 2 */
129  tmp5 = tmp11 - tmp6;
130  tmp4 = tmp10 + tmp5;
131 
132  wsptr[DCTSIZE * 0] = tmp0 + tmp7;
133  wsptr[DCTSIZE * 7] = tmp0 - tmp7;
134  wsptr[DCTSIZE * 1] = tmp1 + tmp6;
135  wsptr[DCTSIZE * 6] = tmp1 - tmp6;
136  wsptr[DCTSIZE * 2] = tmp2 + tmp5;
137  wsptr[DCTSIZE * 5] = tmp2 - tmp5;
138  wsptr[DCTSIZE * 4] = tmp3 + tmp4;
139  wsptr[DCTSIZE * 3] = tmp3 - tmp4;
140 
141  inptr++; /* advance pointers to next column */
142  quantptr++;
143  wsptr++;
144  }
145 
146  /* Pass 2: process rows from work array, store into output array. */
147  /* Note that we must descale the results by a factor of 8 == 2**3. */
148 
149  wsptr = workspace;
150  for (ctr = 0; ctr < DCTSIZE; ctr++)
151  {
153  /* Rows of zeroes can be exploited in the same way as we did with
154  * columns.
155  * However, the column calculation has created many nonzero AC terms, so
156  * the simplification applies less often (typically 5% to 10% of the
157  * time).
158  * And testing floats for zero is relatively expensive, so we don't
159  * bother.
160  */
161 
162  /* Even part */
163 
164  tmp10 = wsptr[0] + wsptr[4];
165  tmp11 = wsptr[0] - wsptr[4];
166 
167  tmp13 = wsptr[2] + wsptr[6];
168  tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT)1.414213562) - tmp13;
169 
170  tmp0 = tmp10 + tmp13;
171  tmp3 = tmp10 - tmp13;
172  tmp1 = tmp11 + tmp12;
173  tmp2 = tmp11 - tmp12;
174 
175  /* Odd part */
176 
177  z13 = wsptr[5] + wsptr[3];
178  z10 = wsptr[5] - wsptr[3];
179  z11 = wsptr[1] + wsptr[7];
180  z12 = wsptr[1] - wsptr[7];
181 
182  tmp7 = z11 + z13;
183  tmp11 = (z11 - z13) * ((FAST_FLOAT)1.414213562);
184 
185  z5 = (z10 + z12) * ((FAST_FLOAT)1.847759065); /* 2*c2 */
186  tmp10 = ((FAST_FLOAT)1.082392200) * z12 - z5; /* 2*(c2-c6) */
187  tmp12 = ((FAST_FLOAT)-2.613125930) * z10 + z5; /* -2*(c2+c6) */
188 
189  tmp6 = tmp12 - tmp7;
190  tmp5 = tmp11 - tmp6;
191  tmp4 = tmp10 + tmp5;
192 
193  /* Final output stage: scale down by a factor of 8 and range-limit */
194 
195  outptr[0] =
196  range_limit[(int)DESCALE((INT32)(tmp0 + tmp7), 3) & RANGE_MASK];
197  outptr[7] =
198  range_limit[(int)DESCALE((INT32)(tmp0 - tmp7), 3) & RANGE_MASK];
199  outptr[1] =
200  range_limit[(int)DESCALE((INT32)(tmp1 + tmp6), 3) & RANGE_MASK];
201  outptr[6] =
202  range_limit[(int)DESCALE((INT32)(tmp1 - tmp6), 3) & RANGE_MASK];
203  outptr[2] =
204  range_limit[(int)DESCALE((INT32)(tmp2 + tmp5), 3) & RANGE_MASK];
205  outptr[5] =
206  range_limit[(int)DESCALE((INT32)(tmp2 - tmp5), 3) & RANGE_MASK];
207  outptr[4] =
208  range_limit[(int)DESCALE((INT32)(tmp3 + tmp4), 3) & RANGE_MASK];
209  outptr[3] =
210  range_limit[(int)DESCALE((INT32)(tmp3 - tmp4), 3) & RANGE_MASK];
211 
212  wsptr += DCTSIZE; /* advance pointer to next row */
213  }
214 }
215 
216 #endif /* DCT_FLOAT_SUPPORTED */
FAST_FLOAT z12
Definition: jidctflt.cpp:41
#define DESCALE(x, n)
Definition: jdct.h:142
JSAMPLE * range_limit
Definition: jidctflt.cpp:46
#define IDCT_range_limit(cinfo)
Definition: jdct.h:68
char JSAMPLE
Definition: jmorecfg.h:58
FAST_FLOAT workspace[DCTSIZE2]
Definition: jidctflt.cpp:48
FAST_FLOAT tmp12
Definition: jidctflt.cpp:40
#define DCTSIZE
Definition: mrpt_jpeglib.h:36
#define RANGE_MASK
Definition: jdct.h:70
GLOBAL(void) jpeg_idct_float(j_decompress_ptr cinfo
for(ctr=DCTSIZE;ctr > 0;ctr--)
Definition: jidctflt.cpp:56
JSAMPLE FAR * JSAMPROW
Definition: mrpt_jpeglib.h:60
FAST_FLOAT tmp13
Definition: jidctflt.cpp:40
long INT32
Definition: jmorecfg.h:151
#define SHIFT_TEMPS
Definition: jpegint.h:301
FLOAT_MULT_TYPE * quantptr
Definition: jidctflt.cpp:43
JCOEFPTR inptr
Definition: jidctflt.cpp:42
JSAMPROW outptr
Definition: jidctflt.cpp:45
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jidctflt.cpp:36
JSAMPROW * JSAMPARRAY
Definition: mrpt_jpeglib.h:61
JCOEF FAR * JCOEFPTR
Definition: mrpt_jpeglib.h:69
#define DCTSIZE2
Definition: mrpt_jpeglib.h:37
FAST_FLOAT z5
Definition: jidctflt.cpp:41
FAST_FLOAT FLOAT_MULT_TYPE
Definition: jdct.h:57
#define DEQUANTIZE(coef, quantval)
Definition: jidctflt.cpp:29
Definition: inftrees.h:28
FAST_FLOAT z10
Definition: jidctflt.cpp:41
FAST_FLOAT tmp10
Definition: jidctflt.cpp:40
int ctr
Definition: jidctflt.cpp:47
unsigned int JDIMENSION
Definition: jmorecfg.h:161
FAST_FLOAT tmp11
Definition: jidctflt.cpp:40
FAST_FLOAT * wsptr
Definition: jidctflt.cpp:44
jpeg_component_info JCOEFPTR coef_block
Definition: jidctflt.cpp:36
FAST_FLOAT z13
Definition: jidctflt.cpp:41
jpeg_component_info JCOEFPTR JSAMPARRAY JDIMENSION output_col
Definition: jidctflt.cpp:38
FAST_FLOAT z11
Definition: jidctflt.cpp:41
jpeg_component_info * compptr
Definition: jidctflt.cpp:36



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