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



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