Main MRPT website > C++ reference for MRPT 1.9.9
jddctmgr.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 /*
16  * The decompressor input side (jdinput.c) saves away the appropriate
17  * quantization table for each component at the start of the first scan
18  * involving that component. (This is necessary in order to correctly
19  * decode files that reuse Q-table slots.)
20  * When we are ready to make an output pass, the saved Q-table is converted
21  * to a multiplier table that will actually be used by the IDCT routine.
22  * The multiplier table contents are IDCT-method-dependent. To support
23  * application changes in IDCT method between scans, we can remake the
24  * multiplier tables if necessary.
25  * In buffered-image mode, the first output pass may occur before any data
26  * has been seen for some components, and thus before their Q-tables have
27  * been saved away. To handle this case, multiplier tables are preset
28  * to zeroes; the result of the IDCT will be a neutral gray level.
29  */
30 
31 /* Private subobject for this module */
32 
33 typedef struct
34 {
35  struct jpeg_inverse_dct pub; /* public fields */
36 
37  /* This array contains the IDCT method code that each multiplier table
38  * is currently set up for, or -1 if it's not yet set up.
39  * The actual multiplier tables are pointed to by dct_table in the
40  * per-component comp_info structures.
41  */
42  int cur_method[MAX_COMPONENTS];
44 
46 
47 /* Allocated multiplier tables: big enough for any supported variant */
48 
49 typedef union {
50  ISLOW_MULT_TYPE islow_array[DCTSIZE2];
51 #ifdef DCT_IFAST_SUPPORTED
52  IFAST_MULT_TYPE ifast_array[DCTSIZE2];
53 #endif
54 #ifdef DCT_FLOAT_SUPPORTED
55  FLOAT_MULT_TYPE float_array[DCTSIZE2];
56 #endif
58 
59 /* The current scaled-IDCT routines require ISLOW-style multiplier tables,
60  * so be sure to compile that code if either ISLOW or SCALING is requested.
61  */
62 #ifdef DCT_ISLOW_SUPPORTED
63 #define PROVIDE_ISLOW_TABLES
64 #else
65 #ifdef IDCT_SCALING_SUPPORTED
66 #define PROVIDE_ISLOW_TABLES
67 #endif
68 #endif
69 
70 /*
71  * Prepare for an output pass.
72  * Here we select the proper IDCT routine for each component and build
73  * a matching multiplier table.
74  */
75 
76 METHODDEF(void)
78 {
79  my_idct_ptr idct = (my_idct_ptr)cinfo->idct;
80  int ci, i;
82  int method = 0;
83  inverse_DCT_method_ptr method_ptr = nullptr;
84  JQUANT_TBL* qtbl;
85 
86  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
87  ci++, compptr++)
88  {
89  /* Select the proper IDCT routine for this component's scaling */
90  switch (compptr->DCT_scaled_size)
91  {
92 #ifdef IDCT_SCALING_SUPPORTED
93  case 1:
94  method_ptr = jpeg_idct_1x1;
95  method = JDCT_ISLOW; /* jidctred uses islow-style table */
96  break;
97  case 2:
98  method_ptr = jpeg_idct_2x2;
99  method = JDCT_ISLOW; /* jidctred uses islow-style table */
100  break;
101  case 4:
102  method_ptr = jpeg_idct_4x4;
103  method = JDCT_ISLOW; /* jidctred uses islow-style table */
104  break;
105 #endif
106  case DCTSIZE:
107  switch (cinfo->dct_method)
108  {
109 #ifdef DCT_ISLOW_SUPPORTED
110  case JDCT_ISLOW:
111  method_ptr = jpeg_idct_islow;
112  method = JDCT_ISLOW;
113  break;
114 #endif
115 #ifdef DCT_IFAST_SUPPORTED
116  case JDCT_IFAST:
117  method_ptr = jpeg_idct_ifast;
118  method = JDCT_IFAST;
119  break;
120 #endif
121 #ifdef DCT_FLOAT_SUPPORTED
122  case JDCT_FLOAT:
123  method_ptr = jpeg_idct_float;
124  method = JDCT_FLOAT;
125  break;
126 #endif
127  default:
128  ERREXIT(cinfo, JERR_NOT_COMPILED);
129  break;
130  }
131  break;
132  default:
133  ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
134  break;
135  }
136  idct->pub.inverse_DCT[ci] = method_ptr;
137  /* Create multiplier table from quant table.
138  * However, we can skip this if the component is uninteresting
139  * or if we already built the table. Also, if no quant table
140  * has yet been saved for the component, we leave the
141  * multiplier table all-zero; we'll be reading zeroes from the
142  * coefficient controller's buffer anyway.
143  */
144  if (!compptr->component_needed || idct->cur_method[ci] == method)
145  continue;
146  qtbl = compptr->quant_table;
147  if (qtbl == nullptr) /* happens if no data yet for component */
148  continue;
149  idct->cur_method[ci] = method;
150  switch (method)
151  {
152 #ifdef PROVIDE_ISLOW_TABLES
153  case JDCT_ISLOW:
154  {
155  /* For LL&M IDCT method, multipliers are equal to raw
156  * quantization
157  * coefficients, but are stored as ints to ensure access
158  * efficiency.
159  */
161  for (i = 0; i < DCTSIZE2; i++)
162  {
163  ismtbl[i] = (ISLOW_MULT_TYPE)qtbl->quantval[i];
164  }
165  }
166  break;
167 #endif
168 #ifdef DCT_IFAST_SUPPORTED
169  case JDCT_IFAST:
170  {
171  /* For AA&N IDCT method, multipliers are equal to quantization
172  * coefficients scaled by scalefactor[row]*scalefactor[col],
173  * where
174  * scalefactor[0] = 1
175  * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
176  * For integer operation, the multiplier table is to be scaled
177  * by
178  * IFAST_SCALE_BITS.
179  */
181 #define CONST_BITS 14
182  static const INT16 aanscales[DCTSIZE2] = {
183  /* precomputed values scaled up by 14 bits */
184  16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
185  22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
186  21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
187  19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
188  16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
189  12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
190  8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
191  4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247};
193 
194  for (i = 0; i < DCTSIZE2; i++)
195  {
196  ifmtbl[i] = (IFAST_MULT_TYPE)DESCALE(
198  (INT32)qtbl->quantval[i], (INT32)aanscales[i]),
200  }
201  }
202  break;
203 #endif
204 #ifdef DCT_FLOAT_SUPPORTED
205  case JDCT_FLOAT:
206  {
207  /* For float AA&N IDCT method, multipliers are equal to
208  * quantization
209  * coefficients scaled by scalefactor[row]*scalefactor[col],
210  * where
211  * scalefactor[0] = 1
212  * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
213  */
215  int row, col;
216  static const double aanscalefactor[DCTSIZE] = {
217  1.0, 1.387039845, 1.306562965, 1.175875602,
218  1.0, 0.785694958, 0.541196100, 0.275899379};
219 
220  i = 0;
221  for (row = 0; row < DCTSIZE; row++)
222  {
223  for (col = 0; col < DCTSIZE; col++)
224  {
225  fmtbl[i] = (FLOAT_MULT_TYPE)(
226  (double)qtbl->quantval[i] * aanscalefactor[row] *
227  aanscalefactor[col]);
228  i++;
229  }
230  }
231  }
232  break;
233 #endif
234  default:
235  ERREXIT(cinfo, JERR_NOT_COMPILED);
236  break;
237  }
238  }
239 }
240 
241 /*
242  * Initialize IDCT manager.
243  */
244 
245 GLOBAL(void)
247 {
248  my_idct_ptr idct;
249  int ci;
251 
252  idct = (my_idct_ptr)(*cinfo->mem->alloc_small)(
254  cinfo->idct = (struct jpeg_inverse_dct*)idct;
255  idct->pub.start_pass = start_pass;
256 
257  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
258  ci++, compptr++)
259  {
260  /* Allocate and pre-zero a multiplier table for each component */
261  compptr->dct_table = (*cinfo->mem->alloc_small)(
264  /* Mark multiplier table not yet set up for any method */
265  idct->cur_method[ci] = -1;
266  }
267 }
#define DESCALE(x, n)
Definition: jdct.h:142
short INT16
Definition: jmorecfg.h:145
#define IFAST_SCALE_BITS
Definition: jdct.h:55
jinit_inverse_dct(j_decompress_ptr cinfo)
Definition: jddctmgr.cpp:246
jpeg_idct_2x2(j_decompress_ptr cinfo, jpeg_component_info *compptr, JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)
Definition: jidctred.cpp:264
#define DCTSIZE
Definition: mrpt_jpeglib.h:36
inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS]
Definition: jpegint.h:240
struct jpeg_common_struct * j_common_ptr
Definition: mrpt_jpeglib.h:258
my_idct_controller * my_idct_ptr
Definition: jddctmgr.cpp:45
int cur_method[MAX_COMPONENTS]
Definition: jddctmgr.cpp:42
#define MAX_COMPONENTS
Definition: jmorecfg.h:30
#define ERREXIT(cinfo, code)
Definition: jerror.h:451
for(ctr=DCTSIZE;ctr > 0;ctr--)
Definition: jidctflt.cpp:56
#define SIZEOF(object)
Definition: jinclude.h:74
long INT32
Definition: jmorecfg.h:151
#define SHIFT_TEMPS
Definition: jpegint.h:301
#define JPOOL_IMAGE
Definition: mrpt_jpeglib.h:750
#define DCTSIZE2
Definition: mrpt_jpeglib.h:37
INT32 IFAST_MULT_TYPE
Definition: jdct.h:54
MULTIPLIER ISLOW_MULT_TYPE
Definition: jdct.h:49
FAST_FLOAT FLOAT_MULT_TYPE
Definition: jdct.h:57
JQUANT_TBL * quant_table
Definition: mrpt_jpeglib.h:169
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:454
struct jpeg_inverse_dct pub
Definition: jddctmgr.cpp:35
#define GLOBAL(type)
Definition: jmorecfg.h:177
jpeg_idct_1x1(j_decompress_ptr cinfo, jpeg_component_info *compptr, JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col)
Definition: jidctred.cpp:390
GLenum GLenum GLvoid * row
Definition: glext.h:3576
#define METHODDEF(type)
Definition: jmorecfg.h:173
start_pass(j_decompress_ptr cinfo)
Definition: jddctmgr.cpp:77
#define CONST_BITS
#define MEMZERO(target, size)
Definition: jinclude.h:60
jpeg_component_info * compptr
Definition: jidctflt.cpp:36
#define MULTIPLY16V16(var1, var2)
Definition: jdct.h:171



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