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



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020