COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
jcdctmgr.cpp File Reference
#include "jinclude.h"
#include "jpeglib.h"
#include "jdct.h"
Include dependency graph for jcdctmgr.cpp:

Classes

struct  my_fdct_controller
 

Macros

#define JPEG_INTERNALS
 
#define CONST_BITS   14
 
#define DIVIDE_BY(a, b)   if (a >= b) a /= b; else a = 0
 

Typedefs

typedef my_fdct_controllermy_fdct_ptr
 

Functions

static void start_pass_fdctmgr (j_compress_ptr cinfo)
 
static void forward_DCT (j_compress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JDIMENSION start_row, JDIMENSION start_col, JDIMENSION num_blocks)
 
static void forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JDIMENSION start_row, JDIMENSION start_col, JDIMENSION num_blocks)
 
void jinit_forward_dct (j_compress_ptr cinfo)
 

Macro Definition Documentation

#define JPEG_INTERNALS
#define CONST_BITS   14
#define DIVIDE_BY (   a,
  b 
)    if (a >= b) a /= b; else a = 0

Typedef Documentation

Function Documentation

static void start_pass_fdctmgr ( j_compress_ptr  cinfo)
static
55 {
56  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
57  int ci, qtblno, i;
59  JQUANT_TBL * qtbl;
60  DCTELEM * dtbl;
61 
62  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
63  ci++, compptr++) {
64  qtblno = compptr->quant_tbl_no;
65  /* Make sure specified quantization table is present */
66  if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
67  cinfo->quant_tbl_ptrs[qtblno] == NULL)
68  ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
69  qtbl = cinfo->quant_tbl_ptrs[qtblno];
70  /* Compute divisors for this quant table */
71  /* We may do this more than once for same table, but it's not a big deal */
72  switch (cinfo->dct_method) {
73 #ifdef DCT_ISLOW_SUPPORTED
74  case JDCT_ISLOW:
75  /* For LL&M IDCT method, divisors are equal to raw quantization
76  * coefficients multiplied by 8 (to counteract scaling).
77  */
78  if (fdct->divisors[qtblno] == NULL) {
79  fdct->divisors[qtblno] = (DCTELEM *)
80  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
82  }
83  dtbl = fdct->divisors[qtblno];
84  for (i = 0; i < DCTSIZE2; i++) {
85  dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
86  }
87  break;
88 #endif
89 #ifdef DCT_IFAST_SUPPORTED
90  case JDCT_IFAST:
91  {
92  /* For AA&N IDCT method, divisors are equal to quantization
93  * coefficients scaled by scalefactor[row]*scalefactor[col], where
94  * scalefactor[0] = 1
95  * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
96  * We apply a further scale factor of 8.
97  */
98 #define CONST_BITS 14
99  static const int16_t aanscales[DCTSIZE2] = {
100  /* precomputed values scaled up by 14 bits */
101  16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
102  22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
103  21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
104  19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
105  16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
106  12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
107  8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
108  4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
109  };
111 
112  if (fdct->divisors[qtblno] == NULL) {
113  fdct->divisors[qtblno] = (DCTELEM *)
114  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
115  DCTSIZE2 * SIZEOF(DCTELEM));
116  }
117  dtbl = fdct->divisors[qtblno];
118  for (i = 0; i < DCTSIZE2; i++) {
119  dtbl[i] = (DCTELEM)
120  DESCALE(MULTIPLY16V16((int32_t) qtbl->quantval[i],
121  (int32_t) aanscales[i]),
122  CONST_BITS-3);
123  }
124  }
125  break;
126 #endif
127 #ifdef DCT_FLOAT_SUPPORTED
128  case JDCT_FLOAT:
129  {
130  /* For float AA&N IDCT method, divisors are equal to quantization
131  * coefficients scaled by scalefactor[row]*scalefactor[col], where
132  * scalefactor[0] = 1
133  * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
134  * We apply a further scale factor of 8.
135  * What's actually stored is 1/divisor so that the inner loop can
136  * use a multiplication rather than a division.
137  */
138  FAST_FLOAT * fdtbl;
139  int row, col;
140  static const double aanscalefactor[DCTSIZE] = {
141  1.0, 1.387039845, 1.306562965, 1.175875602,
142  1.0, 0.785694958, 0.541196100, 0.275899379
143  };
144 
145  if (fdct->float_divisors[qtblno] == NULL) {
146  fdct->float_divisors[qtblno] = (FAST_FLOAT *)
147  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
148  DCTSIZE2 * SIZEOF(FAST_FLOAT));
149  }
150  fdtbl = fdct->float_divisors[qtblno];
151  i = 0;
152  for (row = 0; row < DCTSIZE; row++) {
153  for (col = 0; col < DCTSIZE; col++) {
154  fdtbl[i] = (FAST_FLOAT)
155  (1.0 / (((double) qtbl->quantval[i] *
156  aanscalefactor[row] * aanscalefactor[col] * 8.0)));
157  i++;
158  }
159  }
160  }
161  break;
162 #endif
163  default:
164  ERREXIT(cinfo, JERR_NOT_COMPILED);
165  break;
166  }
167  }
168 }
#define DESCALE(x, n)
Definition: jdct.h:146
#define NUM_QUANT_TBLS
Definition: jpeglib.h:48
my_fdct_controller * my_fdct_ptr
Definition: jcdctmgr.cpp:41
struct jpeg_forward_dct * fdct
Definition: jpeglib.h:407
int i
Definition: rw_test.cpp:37
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:307
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
void *(* alloc_small)()
Definition: jpeglib.h:764
Definition: jpeglib.h:88
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
#define SIZEOF(object)
Definition: jinclude.h:80
#define SHIFT_TEMPS
Definition: jpegint.h:289
Definition: jpeglib.h:224
jpeg_component_info * compptr
Definition: jdct.h:102
#define JPOOL_IMAGE
Definition: jpeglib.h:754
Definition: jerror.h:95
int quant_tbl_no
Definition: jpeglib.h:129
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:274
#define DCTSIZE2
Definition: jpeglib.h:47
Definition: jerror.h:99
Definition: jcdctmgr.cpp:22
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
float * float_divisors[4]
Definition: jcdctmgr.cpp:37
int32_t DCTELEM
Definition: jdct.h:32
Definition: jpeglib.h:121
Definition: jpeglib.h:225
DCTELEM * divisors[4]
Definition: jcdctmgr.cpp:32
J_DCT_METHOD dct_method
Definition: jpeglib.h:330
#define DCTSIZE
Definition: jpeglib.h:46
#define CONST_BITS
jpeg_component_info * comp_info
Definition: jpeglib.h:304
Definition: jpeglib.h:223
#define MULTIPLY16V16(var1, var2)
Definition: jdct.h:175
static void forward_DCT ( j_compress_ptr  cinfo,
jpeg_component_info compptr,
JSAMPARRAY  sample_data,
JBLOCKROW  coef_blocks,
JDIMENSION  start_row,
JDIMENSION  start_col,
JDIMENSION  num_blocks 
)
static
185 {
186  /* This routine is heavily used, so it's worth coding it tightly. */
187  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
188  forward_DCT_method_ptr do_dct = fdct->do_dct;
189  DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
190  DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
191  JDIMENSION bi;
192 
193  sample_data += start_row; /* fold in the vertical offset once */
194 
195  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
196  /* Load data into workspace, applying unsigned->signed conversion */
197  { register DCTELEM *workspaceptr;
198  register JSAMPROW elemptr;
199  register int elemr;
200 
201  workspaceptr = workspace;
202  for (elemr = 0; elemr < DCTSIZE; elemr++) {
203  elemptr = sample_data[elemr] + start_col;
204 #if DCTSIZE == 8 /* unroll the inner loop */
205  *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
206  *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
207  *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
208  *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
209  *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
210  *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
211  *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
212  *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
213 #else
214  { register int elemc;
215  for (elemc = DCTSIZE; elemc > 0; elemc--) {
216  *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
217  }
218  }
219 #endif
220  }
221  }
222 
223  /* Perform the DCT */
224  (*do_dct) (workspace);
225 
226  /* Quantize/descale the coefficients, and store into coef_blocks[] */
227  { register DCTELEM temp, qval;
228  register int i;
229  register JCOEFPTR output_ptr = coef_blocks[bi];
230 
231  for (i = 0; i < DCTSIZE2; i++) {
232  qval = divisors[i];
233  temp = workspace[i];
234  /* Divide the coefficient value by qval, ensuring proper rounding.
235  * Since C does not specify the direction of rounding for negative
236  * quotients, we have to force the dividend positive for portability.
237  *
238  * In most files, at least half of the output values will be zero
239  * (at default quantization settings, more like three-quarters...)
240  * so we should ensure that this case is fast. On many machines,
241  * a comparison is enough cheaper than a divide to make a special test
242  * a win. Since both inputs will be nonnegative, we need only test
243  * for a < b to discover whether a/b is 0.
244  * If your machine's division is fast enough, define FAST_DIVIDE.
245  */
246 #ifdef FAST_DIVIDE
247 #define DIVIDE_BY(a,b) a /= b
248 #else
249 #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
250 #endif
251  if (temp < 0) {
252  temp = -temp;
253  temp += qval>>1; /* for rounding */
254  DIVIDE_BY(temp, qval);
255  temp = -temp;
256  } else {
257  temp += qval>>1; /* for rounding */
258  DIVIDE_BY(temp, qval);
259  }
260  output_ptr[i] = (JCOEF) temp;
261  }
262  }
263  }
264 }
#define CENTERJSAMPLE
Definition: jmorecfg.h:74
forward_DCT_method_ptr do_dct
Definition: jcdctmgr.cpp:26
#define DIVIDE_BY(a, b)
my_fdct_controller * my_fdct_ptr
Definition: jcdctmgr.cpp:41
struct jpeg_forward_dct * fdct
Definition: jpeglib.h:407
int i
Definition: rw_test.cpp:37
#define GETJSAMPLE(value)
Definition: jmorecfg.h:68
short JCOEF
Definition: jmorecfg.h:99
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
int quant_tbl_no
Definition: jpeglib.h:129
#define DCTSIZE2
Definition: jpeglib.h:47
JBLOCKROW JDIMENSION num_blocks
Definition: jpegint.h:376
JCOEF * JCOEFPTR
Definition: jpeglib.h:80
Definition: jcdctmgr.cpp:22
int32_t DCTELEM
Definition: jdct.h:32
DCTELEM * divisors[4]
Definition: jcdctmgr.cpp:32
#define DCTSIZE
Definition: jpeglib.h:46
unsigned int JDIMENSION
Definition: jmorecfg.h:171
static void forward_DCT_float ( j_compress_ptr  cinfo,
jpeg_component_info compptr,
JSAMPARRAY  sample_data,
JBLOCKROW  coef_blocks,
JDIMENSION  start_row,
JDIMENSION  start_col,
JDIMENSION  num_blocks 
)
static
275 {
276  /* This routine is heavily used, so it's worth coding it tightly. */
277  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
278  float_DCT_method_ptr do_dct = fdct->do_float_dct;
279  FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
280  FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
281  JDIMENSION bi;
282 
283  sample_data += start_row; /* fold in the vertical offset once */
284 
285  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
286  /* Load data into workspace, applying unsigned->signed conversion */
287  { register FAST_FLOAT *workspaceptr;
288  register JSAMPROW elemptr;
289  register int elemr;
290 
291  workspaceptr = workspace;
292  for (elemr = 0; elemr < DCTSIZE; elemr++) {
293  elemptr = sample_data[elemr] + start_col;
294 #if DCTSIZE == 8 /* unroll the inner loop */
295  *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
296  *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
297  *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
298  *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
299  *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
300  *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
301  *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
302  *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
303 #else
304  { register int elemc;
305  for (elemc = DCTSIZE; elemc > 0; elemc--) {
306  *workspaceptr++ = (FAST_FLOAT)
307  (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
308  }
309  }
310 #endif
311  }
312  }
313 
314  /* Perform the DCT */
315  (*do_dct) (workspace);
316 
317  /* Quantize/descale the coefficients, and store into coef_blocks[] */
318  { register FAST_FLOAT temp;
319  register int i;
320  register JCOEFPTR output_ptr = coef_blocks[bi];
321 
322  for (i = 0; i < DCTSIZE2; i++) {
323  /* Apply the quantization and scaling factor */
324  temp = workspace[i] * divisors[i];
325  /* Round to nearest integer.
326  * Since C does not specify the direction of rounding for negative
327  * quotients, we have to force the dividend positive for portability.
328  * The maximum coefficient size is +-16K (for 12-bit data), so this
329  * code should work for either 16-bit or 32-bit ints.
330  */
331  output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
332  }
333  }
334  }
335 }
#define CENTERJSAMPLE
Definition: jmorecfg.h:74
my_fdct_controller * my_fdct_ptr
Definition: jcdctmgr.cpp:41
struct jpeg_forward_dct * fdct
Definition: jpeglib.h:407
int i
Definition: rw_test.cpp:37
#define GETJSAMPLE(value)
Definition: jmorecfg.h:68
short JCOEF
Definition: jmorecfg.h:99
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
float_DCT_method_ptr do_float_dct
Definition: jcdctmgr.cpp:36
int quant_tbl_no
Definition: jpeglib.h:129
#define DCTSIZE2
Definition: jpeglib.h:47
JBLOCKROW JDIMENSION num_blocks
Definition: jpegint.h:376
JCOEF * JCOEFPTR
Definition: jpeglib.h:80
Definition: jcdctmgr.cpp:22
float * float_divisors[4]
Definition: jcdctmgr.cpp:37
#define DCTSIZE
Definition: jpeglib.h:46
unsigned int JDIMENSION
Definition: jmorecfg.h:171
void jinit_forward_dct ( j_compress_ptr  cinfo)
346 {
347  my_fdct_ptr fdct;
348  int i;
349 
350  fdct = (my_fdct_ptr)
351  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
353  cinfo->fdct = (struct jpeg_forward_dct *) fdct;
354  fdct->pub.start_pass = start_pass_fdctmgr;
355 
356  switch (cinfo->dct_method) {
357 #ifdef DCT_ISLOW_SUPPORTED
358  case JDCT_ISLOW:
359  fdct->pub.forward_DCT = forward_DCT;
360  fdct->do_dct = jpeg_fdct_islow;
361  break;
362 #endif
363 #ifdef DCT_IFAST_SUPPORTED
364  case JDCT_IFAST:
365  fdct->pub.forward_DCT = forward_DCT;
366  fdct->do_dct = jpeg_fdct_ifast;
367  break;
368 #endif
369 #ifdef DCT_FLOAT_SUPPORTED
370  case JDCT_FLOAT:
371  fdct->pub.forward_DCT = forward_DCT_float;
373  break;
374 #endif
375  default:
376  ERREXIT(cinfo, JERR_NOT_COMPILED);
377  break;
378  }
379 
380  /* Mark divisor tables unallocated */
381  for (i = 0; i < NUM_QUANT_TBLS; i++) {
382  fdct->divisors[i] = NULL;
383 #ifdef DCT_FLOAT_SUPPORTED
384  fdct->float_divisors[i] = NULL;
385 #endif
386  }
387 }
forward_DCT_method_ptr do_dct
Definition: jcdctmgr.cpp:26
static void forward_DCT_float(j_compress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JDIMENSION start_row, JDIMENSION start_col, JDIMENSION num_blocks)
Definition: jcdctmgr.cpp:270
#define NUM_QUANT_TBLS
Definition: jpeglib.h:48
my_fdct_controller * my_fdct_ptr
Definition: jcdctmgr.cpp:41
struct jpeg_forward_dct * fdct
Definition: jpeglib.h:407
int i
Definition: rw_test.cpp:37
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
void *(* alloc_small)()
Definition: jpeglib.h:764
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
#define SIZEOF(object)
Definition: jinclude.h:80
Definition: jpeglib.h:224
Definition: jpegint.h:102
#define JPOOL_IMAGE
Definition: jpeglib.h:754
Definition: jerror.h:95
float_DCT_method_ptr do_float_dct
Definition: jcdctmgr.cpp:36
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:274
void jpeg_fdct_islow(DCTELEM *data)
Definition: jfdctint.cpp:140
static void forward_DCT(j_compress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JDIMENSION start_row, JDIMENSION start_col, JDIMENSION num_blocks)
Definition: jcdctmgr.cpp:180
static void start_pass_fdctmgr(j_compress_ptr cinfo)
Definition: jcdctmgr.cpp:54
struct jpeg_forward_dct pub
Definition: jcdctmgr.cpp:23
Definition: jcdctmgr.cpp:22
float * float_divisors[4]
Definition: jcdctmgr.cpp:37
Definition: jpeglib.h:225
DCTELEM * divisors[4]
Definition: jcdctmgr.cpp:32
J_DCT_METHOD dct_method
Definition: jpeglib.h:330
void jpeg_fdct_float(float *data)
Definition: jfdctflt.cpp:59
Definition: jpeglib.h:223
void jpeg_fdct_ifast(DCTELEM *data)
Definition: jfdctfst.cpp:114