ReactOS 0.4.15-dev-7918-g2a2556c
jcdctmgr.c File Reference
#include "jinclude.h"
#include "jpeglib.h"
#include "jdct.h"
Include dependency graph for jcdctmgr.c:

Go to the source code of this file.

Classes

struct  my_fdct_controller
 
union  divisor_table
 

Macros

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

Typedefs

typedef my_fdct_controllermy_fdct_ptr
 

Functions

 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)
 
 start_pass_fdctmgr (j_compress_ptr cinfo)
 
 jinit_forward_dct (j_compress_ptr cinfo)
 

Macro Definition Documentation

◆ DIVIDE_BY

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

◆ JPEG_INTERNALS

#define JPEG_INTERNALS

Definition at line 15 of file jcdctmgr.c.

Typedef Documentation

◆ my_fdct_ptr

Definition at line 35 of file jcdctmgr.c.

Function Documentation

◆ forward_DCT()

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 at line 74 of file jcdctmgr.c.

79{
80 /* This routine is heavily used, so it's worth coding it tightly. */
81 my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
82 forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index];
83 DCTELEM * divisors = (DCTELEM *) compptr->dct_table;
84 DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
85 JDIMENSION bi;
86
87 sample_data += start_row; /* fold in the vertical offset once */
88
89 for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
90 /* Perform the DCT */
91 (*do_dct) (workspace, sample_data, start_col);
92
93 /* Quantize/descale the coefficients, and store into coef_blocks[] */
94 { register DCTELEM temp, qval;
95 register int i;
96 register JCOEFPTR output_ptr = coef_blocks[bi];
97
98 for (i = 0; i < DCTSIZE2; i++) {
99 qval = divisors[i];
100 temp = workspace[i];
101 /* Divide the coefficient value by qval, ensuring proper rounding.
102 * Since C does not specify the direction of rounding for negative
103 * quotients, we have to force the dividend positive for portability.
104 *
105 * In most files, at least half of the output values will be zero
106 * (at default quantization settings, more like three-quarters...)
107 * so we should ensure that this case is fast. On many machines,
108 * a comparison is enough cheaper than a divide to make a special test
109 * a win. Since both inputs will be nonnegative, we need only test
110 * for a < b to discover whether a/b is 0.
111 * If your machine's division is fast enough, define FAST_DIVIDE.
112 */
113#ifdef FAST_DIVIDE
114#define DIVIDE_BY(a,b) a /= b
115#else
116#define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
117#endif
118 if (temp < 0) {
119 temp = -temp;
120 temp += qval>>1; /* for rounding */
121 DIVIDE_BY(temp, qval);
122 temp = -temp;
123 } else {
124 temp += qval>>1; /* for rounding */
125 DIVIDE_BY(temp, qval);
126 }
127 output_ptr[i] = (JCOEF) temp;
128 }
129 }
130 }
131}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define DIVIDE_BY(a, b)
my_fdct_controller * my_fdct_ptr
Definition: jcdctmgr.c:35
INT32 DCTELEM
Definition: jdct.h:38
JSAMPARRAY JDIMENSION start_col
Definition: jdct.h:169
jpeg_component_info * compptr
Definition: jdct.h:238
JSAMPARRAY sample_data
Definition: jdct.h:169
unsigned int JDIMENSION
Definition: jmorecfg.h:229
short JCOEF
Definition: jmorecfg.h:151
JBLOCKROW JDIMENSION num_blocks
Definition: jpegint.h:423
JCOEF FAR * JCOEFPTR
Definition: jpeglib.h:84
#define DCTSIZE2
Definition: jpeglib.h:51
static calc_node_t temp
Definition: rpn_ieee.c:38
struct jpeg_forward_dct * fdct
Definition: jpeglib.h:450
forward_DCT_method_ptr do_dct[MAX_COMPONENTS]
Definition: jcdctmgr.c:27

Referenced by compress_data(), and start_pass_fdctmgr().

◆ jinit_forward_dct()

jinit_forward_dct ( j_compress_ptr  cinfo)

Definition at line 458 of file jcdctmgr.c.

459{
460 my_fdct_ptr fdct;
461 int ci;
463
464 fdct = (my_fdct_ptr)
465 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
467 cinfo->fdct = &fdct->pub;
468 fdct->pub.start_pass = start_pass_fdctmgr;
469
470 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
471 ci++, compptr++) {
472 /* Allocate a divisor table for each component */
474 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
476 }
477}
#define SIZEOF(_ar)
Definition: calc.h:97
start_pass_fdctmgr(j_compress_ptr cinfo)
Definition: jcdctmgr.c:189
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:284
#define JPOOL_IMAGE
Definition: jpeglib.h:808
jpeg_component_info * comp_info
Definition: jpeglib.h:333
struct jpeg_forward_dct pub
Definition: jcdctmgr.c:24

Referenced by jinit_compress_master().

◆ start_pass_fdctmgr()

start_pass_fdctmgr ( j_compress_ptr  cinfo)

Definition at line 189 of file jcdctmgr.c.

190{
191 my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
192 int ci, qtblno, i;
194 int method = 0;
195 JQUANT_TBL * qtbl;
196 DCTELEM * dtbl;
197
198 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
199 ci++, compptr++) {
200 /* Select the proper DCT routine for this component's scaling */
202#ifdef DCT_SCALING_SUPPORTED
203 case ((1 << 8) + 1):
204 fdct->do_dct[ci] = jpeg_fdct_1x1;
205 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
206 break;
207 case ((2 << 8) + 2):
208 fdct->do_dct[ci] = jpeg_fdct_2x2;
209 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
210 break;
211 case ((3 << 8) + 3):
212 fdct->do_dct[ci] = jpeg_fdct_3x3;
213 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
214 break;
215 case ((4 << 8) + 4):
216 fdct->do_dct[ci] = jpeg_fdct_4x4;
217 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
218 break;
219 case ((5 << 8) + 5):
220 fdct->do_dct[ci] = jpeg_fdct_5x5;
221 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
222 break;
223 case ((6 << 8) + 6):
224 fdct->do_dct[ci] = jpeg_fdct_6x6;
225 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
226 break;
227 case ((7 << 8) + 7):
228 fdct->do_dct[ci] = jpeg_fdct_7x7;
229 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
230 break;
231 case ((9 << 8) + 9):
232 fdct->do_dct[ci] = jpeg_fdct_9x9;
233 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
234 break;
235 case ((10 << 8) + 10):
236 fdct->do_dct[ci] = jpeg_fdct_10x10;
237 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
238 break;
239 case ((11 << 8) + 11):
240 fdct->do_dct[ci] = jpeg_fdct_11x11;
241 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
242 break;
243 case ((12 << 8) + 12):
244 fdct->do_dct[ci] = jpeg_fdct_12x12;
245 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
246 break;
247 case ((13 << 8) + 13):
248 fdct->do_dct[ci] = jpeg_fdct_13x13;
249 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
250 break;
251 case ((14 << 8) + 14):
252 fdct->do_dct[ci] = jpeg_fdct_14x14;
253 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
254 break;
255 case ((15 << 8) + 15):
256 fdct->do_dct[ci] = jpeg_fdct_15x15;
257 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
258 break;
259 case ((16 << 8) + 16):
260 fdct->do_dct[ci] = jpeg_fdct_16x16;
261 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
262 break;
263 case ((16 << 8) + 8):
264 fdct->do_dct[ci] = jpeg_fdct_16x8;
265 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
266 break;
267 case ((14 << 8) + 7):
268 fdct->do_dct[ci] = jpeg_fdct_14x7;
269 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
270 break;
271 case ((12 << 8) + 6):
272 fdct->do_dct[ci] = jpeg_fdct_12x6;
273 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
274 break;
275 case ((10 << 8) + 5):
276 fdct->do_dct[ci] = jpeg_fdct_10x5;
277 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
278 break;
279 case ((8 << 8) + 4):
280 fdct->do_dct[ci] = jpeg_fdct_8x4;
281 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
282 break;
283 case ((6 << 8) + 3):
284 fdct->do_dct[ci] = jpeg_fdct_6x3;
285 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
286 break;
287 case ((4 << 8) + 2):
288 fdct->do_dct[ci] = jpeg_fdct_4x2;
289 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
290 break;
291 case ((2 << 8) + 1):
292 fdct->do_dct[ci] = jpeg_fdct_2x1;
293 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
294 break;
295 case ((8 << 8) + 16):
296 fdct->do_dct[ci] = jpeg_fdct_8x16;
297 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
298 break;
299 case ((7 << 8) + 14):
300 fdct->do_dct[ci] = jpeg_fdct_7x14;
301 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
302 break;
303 case ((6 << 8) + 12):
304 fdct->do_dct[ci] = jpeg_fdct_6x12;
305 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
306 break;
307 case ((5 << 8) + 10):
308 fdct->do_dct[ci] = jpeg_fdct_5x10;
309 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
310 break;
311 case ((4 << 8) + 8):
312 fdct->do_dct[ci] = jpeg_fdct_4x8;
313 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
314 break;
315 case ((3 << 8) + 6):
316 fdct->do_dct[ci] = jpeg_fdct_3x6;
317 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
318 break;
319 case ((2 << 8) + 4):
320 fdct->do_dct[ci] = jpeg_fdct_2x4;
321 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
322 break;
323 case ((1 << 8) + 2):
324 fdct->do_dct[ci] = jpeg_fdct_1x2;
325 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
326 break;
327#endif
328 case ((DCTSIZE << 8) + DCTSIZE):
329 switch (cinfo->dct_method) {
330#ifdef DCT_ISLOW_SUPPORTED
331 case JDCT_ISLOW:
332 fdct->do_dct[ci] = jpeg_fdct_islow;
334 break;
335#endif
336#ifdef DCT_IFAST_SUPPORTED
337 case JDCT_IFAST:
338 fdct->do_dct[ci] = jpeg_fdct_ifast;
340 break;
341#endif
342#ifdef DCT_FLOAT_SUPPORTED
343 case JDCT_FLOAT:
344 fdct->do_float_dct[ci] = jpeg_fdct_float;
346 break;
347#endif
348 default:
349 ERREXIT(cinfo, JERR_NOT_COMPILED);
350 break;
351 }
352 break;
353 default:
354 ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
356 break;
357 }
358 qtblno = compptr->quant_tbl_no;
359 /* Make sure specified quantization table is present */
360 if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
361 cinfo->quant_tbl_ptrs[qtblno] == NULL)
362 ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
363 qtbl = cinfo->quant_tbl_ptrs[qtblno];
364 /* Create divisor table from quant table */
365 switch (method) {
366#ifdef PROVIDE_ISLOW_TABLES
367 case JDCT_ISLOW:
368 /* For LL&M IDCT method, divisors are equal to raw quantization
369 * coefficients multiplied by 8 (to counteract scaling).
370 */
371 dtbl = (DCTELEM *) compptr->dct_table;
372 for (i = 0; i < DCTSIZE2; i++) {
373 dtbl[i] =
374 ((DCTELEM) qtbl->quantval[i]) << (compptr->component_needed ? 4 : 3);
375 }
376 fdct->pub.forward_DCT[ci] = forward_DCT;
377 break;
378#endif
379#ifdef DCT_IFAST_SUPPORTED
380 case JDCT_IFAST:
381 {
382 /* For AA&N IDCT method, divisors are equal to quantization
383 * coefficients scaled by scalefactor[row]*scalefactor[col], where
384 * scalefactor[0] = 1
385 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
386 * We apply a further scale factor of 8.
387 */
388#define CONST_BITS 14
389 static const INT16 aanscales[DCTSIZE2] = {
390 /* precomputed values scaled up by 14 bits */
391 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
392 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
393 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
394 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
395 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
396 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
397 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
398 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
399 };
401
402 dtbl = (DCTELEM *) compptr->dct_table;
403 for (i = 0; i < DCTSIZE2; i++) {
404 dtbl[i] = (DCTELEM)
405 DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
406 (INT32) aanscales[i]),
407 compptr->component_needed ? CONST_BITS-4 : CONST_BITS-3);
408 }
409 }
410 fdct->pub.forward_DCT[ci] = forward_DCT;
411 break;
412#endif
413#ifdef DCT_FLOAT_SUPPORTED
414 case JDCT_FLOAT:
415 {
416 /* For float AA&N IDCT method, divisors are equal to quantization
417 * coefficients scaled by scalefactor[row]*scalefactor[col], where
418 * scalefactor[0] = 1
419 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
420 * We apply a further scale factor of 8.
421 * What's actually stored is 1/divisor so that the inner loop can
422 * use a multiplication rather than a division.
423 */
424 FAST_FLOAT * fdtbl = (FAST_FLOAT *) compptr->dct_table;
425 int row, col;
426 static const double aanscalefactor[DCTSIZE] = {
427 1.0, 1.387039845, 1.306562965, 1.175875602,
428 1.0, 0.785694958, 0.541196100, 0.275899379
429 };
430
431 i = 0;
432 for (row = 0; row < DCTSIZE; row++) {
433 for (col = 0; col < DCTSIZE; col++) {
434 fdtbl[i] = (FAST_FLOAT)
435 (1.0 / ((double) qtbl->quantval[i] *
436 aanscalefactor[row] * aanscalefactor[col] *
437 (compptr->component_needed ? 16.0 : 8.0)));
438 i++;
439 }
440 }
441 }
442 fdct->pub.forward_DCT[ci] = forward_DCT_float;
443 break;
444#endif
445 default:
446 ERREXIT(cinfo, JERR_NOT_COMPILED);
447 break;
448 }
449 }
450}
signed int INT32
signed short INT16
#define NULL
Definition: types.h:112
struct png_info_def *typedef unsigned char **typedef struct png_info_def *typedef struct png_info_def *typedef struct png_info_def *typedef unsigned char ** row
Definition: typeof.h:78
method
Definition: dragdrop.c:54
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.c:74
#define MULTIPLY16V16(var1, var2)
Definition: jdct.h:388
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:212
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:216
#define SHIFT_TEMPS
Definition: jpegint.h:301
#define DESCALE(x, n)
Definition: jpegint.h:310
#define DCTSIZE
Definition: jpeglib.h:50
#define NUM_QUANT_TBLS
Definition: jpeglib.h:52
@ JDCT_IFAST
Definition: jpeglib.h:242
@ JDCT_FLOAT
Definition: jpeglib.h:243
@ JDCT_ISLOW
Definition: jpeglib.h:241
#define for
Definition: utility.h:88
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
boolean component_needed
Definition: jpeglib.h:174
JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]
Definition: jpeglib.h:336
J_DCT_METHOD dct_method
Definition: jpeglib.h:363

Referenced by jinit_forward_dct().