ReactOS 0.4.16-dev-2617-g01a0906
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_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_col,
JDIMENSION  num_blocks 
)

Definition at line 62 of file jcdctmgr.c.

66{
67 /* This routine is heavily used, so it's worth coding it tightly. */
68 my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
69 forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index];
70 DCTELEM * divisors = (DCTELEM *) compptr->dct_table;
71 DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
72 JDIMENSION bi;
73
74 for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {
75 /* Perform the DCT */
76 (*do_dct) (workspace, sample_data, start_col);
77
78 /* Quantize/descale the coefficients, and store into coef_blocks[] */
79 { register DCTELEM temp, qval;
80 register int i;
81 register JCOEFPTR output_ptr = coef_blocks[bi];
82
83 for (i = 0; i < DCTSIZE2; i++) {
84 qval = divisors[i];
85 temp = workspace[i];
86 /* Divide the coefficient value by qval, ensuring proper rounding.
87 * Since C does not specify the direction of rounding for negative
88 * quotients, we have to force the dividend positive for portability.
89 *
90 * In most files, at least half of the output values will be zero
91 * (at default quantization settings, more like three-quarters...)
92 * so we should ensure that this case is fast. On many machines,
93 * a comparison is enough cheaper than a divide to make a special
94 * test a win. Since both inputs will be nonnegative, we need
95 * only test for a < b to discover whether a/b is 0.
96 * If your machine's division is fast enough, define FAST_DIVIDE.
97 */
98#ifdef FAST_DIVIDE
99#define DIVIDE_BY(a,b) a /= b
100#else
101#define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
102#endif
103 if (temp < 0) {
104 temp = -temp;
105 temp += qval>>1; /* for rounding */
106 DIVIDE_BY(temp, qval);
107 temp = -temp;
108 } else {
109 temp += qval>>1; /* for rounding */
110 DIVIDE_BY(temp, qval);
111 }
112 output_ptr[i] = (JCOEF) temp;
113 }
114 }
115 }
116}
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
JSAMPARRAY JDIMENSION start_col
Definition: jdct.h:183
jpeg_component_info * compptr
Definition: jdct.h:252
int DCTELEM
Definition: jdct.h:49
JSAMPARRAY sample_data
Definition: jdct.h:183
unsigned int JDIMENSION
Definition: jmorecfg.h:265
short JCOEF
Definition: jmorecfg.h:187
JBLOCKROW JDIMENSION num_blocks
Definition: jpegint.h:422
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:451
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 496 of file jcdctmgr.c.

497{
498 my_fdct_ptr fdct;
499 int ci;
501
502 fdct = (my_fdct_ptr) (*cinfo->mem->alloc_small)
504 cinfo->fdct = &fdct->pub;
505 fdct->pub.start_pass = start_pass_fdctmgr;
506
507 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
508 ci++, compptr++) {
509 /* Allocate a divisor table for each component */
510 compptr->dct_table = (*cinfo->mem->alloc_small)
512 }
513}
#define SIZEOF(_ar)
Definition: calc.h:97
start_pass_fdctmgr(j_compress_ptr cinfo)
Definition: jcdctmgr.c:171
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:284
#define JPOOL_IMAGE
Definition: jpeglib.h:810
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 171 of file jcdctmgr.c.

172{
173 my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
174 int ci, qtblno, i;
177 JQUANT_TBL * qtbl;
178 DCTELEM * dtbl;
179
180 for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
181 ci++, compptr++) {
182 /* Select the proper DCT routine for this component's scaling */
184#ifdef DCT_SCALING_SUPPORTED
185/*
186 * The current scaled-DCT routines require ISLOW-style divisor tables,
187 * so be sure to compile that code if either ISLOW or SCALING is requested.
188 */
189#ifndef PROVIDE_ISLOW_TABLES
190#define PROVIDE_ISLOW_TABLES
191#endif
192 case ((1 << 8) + 1):
193 fdct->do_dct[ci] = jpeg_fdct_1x1;
194 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
195 break;
196 case ((2 << 8) + 2):
197 fdct->do_dct[ci] = jpeg_fdct_2x2;
198 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
199 break;
200 case ((3 << 8) + 3):
201 fdct->do_dct[ci] = jpeg_fdct_3x3;
202 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
203 break;
204 case ((4 << 8) + 4):
205 fdct->do_dct[ci] = jpeg_fdct_4x4;
206 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
207 break;
208 case ((5 << 8) + 5):
209 fdct->do_dct[ci] = jpeg_fdct_5x5;
210 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
211 break;
212 case ((6 << 8) + 6):
213 fdct->do_dct[ci] = jpeg_fdct_6x6;
214 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
215 break;
216 case ((7 << 8) + 7):
217 fdct->do_dct[ci] = jpeg_fdct_7x7;
218 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
219 break;
220 case ((9 << 8) + 9):
221 fdct->do_dct[ci] = jpeg_fdct_9x9;
222 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
223 break;
224 case ((10 << 8) + 10):
225 fdct->do_dct[ci] = jpeg_fdct_10x10;
226 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
227 break;
228 case ((11 << 8) + 11):
229 fdct->do_dct[ci] = jpeg_fdct_11x11;
230 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
231 break;
232 case ((12 << 8) + 12):
233 fdct->do_dct[ci] = jpeg_fdct_12x12;
234 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
235 break;
236 case ((13 << 8) + 13):
237 fdct->do_dct[ci] = jpeg_fdct_13x13;
238 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
239 break;
240 case ((14 << 8) + 14):
241 fdct->do_dct[ci] = jpeg_fdct_14x14;
242 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
243 break;
244 case ((15 << 8) + 15):
245 fdct->do_dct[ci] = jpeg_fdct_15x15;
246 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
247 break;
248 case ((16 << 8) + 16):
249 fdct->do_dct[ci] = jpeg_fdct_16x16;
250 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
251 break;
252 case ((16 << 8) + 8):
253 fdct->do_dct[ci] = jpeg_fdct_16x8;
254 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
255 break;
256 case ((14 << 8) + 7):
257 fdct->do_dct[ci] = jpeg_fdct_14x7;
258 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
259 break;
260 case ((12 << 8) + 6):
261 fdct->do_dct[ci] = jpeg_fdct_12x6;
262 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
263 break;
264 case ((10 << 8) + 5):
265 fdct->do_dct[ci] = jpeg_fdct_10x5;
266 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
267 break;
268 case ((8 << 8) + 4):
269 fdct->do_dct[ci] = jpeg_fdct_8x4;
270 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
271 break;
272 case ((6 << 8) + 3):
273 fdct->do_dct[ci] = jpeg_fdct_6x3;
274 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
275 break;
276 case ((4 << 8) + 2):
277 fdct->do_dct[ci] = jpeg_fdct_4x2;
278 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
279 break;
280 case ((2 << 8) + 1):
281 fdct->do_dct[ci] = jpeg_fdct_2x1;
282 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
283 break;
284 case ((8 << 8) + 16):
285 fdct->do_dct[ci] = jpeg_fdct_8x16;
286 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
287 break;
288 case ((7 << 8) + 14):
289 fdct->do_dct[ci] = jpeg_fdct_7x14;
290 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
291 break;
292 case ((6 << 8) + 12):
293 fdct->do_dct[ci] = jpeg_fdct_6x12;
294 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
295 break;
296 case ((5 << 8) + 10):
297 fdct->do_dct[ci] = jpeg_fdct_5x10;
298 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
299 break;
300 case ((4 << 8) + 8):
301 fdct->do_dct[ci] = jpeg_fdct_4x8;
302 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
303 break;
304 case ((3 << 8) + 6):
305 fdct->do_dct[ci] = jpeg_fdct_3x6;
306 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
307 break;
308 case ((2 << 8) + 4):
309 fdct->do_dct[ci] = jpeg_fdct_2x4;
310 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
311 break;
312 case ((1 << 8) + 2):
313 fdct->do_dct[ci] = jpeg_fdct_1x2;
314 method = JDCT_ISLOW; /* jfdctint uses islow-style table */
315 break;
316#endif
317 case ((DCTSIZE << 8) + DCTSIZE):
318 switch (cinfo->dct_method) {
319#ifdef DCT_ISLOW_SUPPORTED
320 case JDCT_ISLOW:
321#ifndef PROVIDE_ISLOW_TABLES
322#define PROVIDE_ISLOW_TABLES
323#endif
324 fdct->do_dct[ci] = jpeg_fdct_islow;
326 break;
327#endif
328#ifdef DCT_IFAST_SUPPORTED
329 case JDCT_IFAST:
330#if BITS_IN_JSAMPLE < JPEG_DATA_PRECISION || \
331 BITS_IN_JSAMPLE > JPEG_DATA_PRECISION + 8
332 /*
333 * Adjustment of divisor tables in JDCT_IFAST
334 * below doesn't work well in this condition.
335 * Use JDCT_ISLOW instead.
336 */
337#ifndef PROVIDE_ISLOW_TABLES
338#define PROVIDE_ISLOW_TABLES
339#endif
340 fdct->do_dct[ci] = jpeg_fdct_islow;
342#else
343#ifndef PROVIDE_IFAST_TABLES
344#define PROVIDE_IFAST_TABLES
345#endif
346 fdct->do_dct[ci] = jpeg_fdct_ifast;
348#endif
349 break;
350#endif
351#ifdef DCT_FLOAT_SUPPORTED
352 case JDCT_FLOAT:
353 fdct->do_float_dct[ci] = jpeg_fdct_float;
355 break;
356#endif
357 default:
358 ERREXIT(cinfo, JERR_NOT_COMPILED);
359 }
360 break;
361 default:
362 ERREXIT2(cinfo, JERR_BAD_DCTSIZE,
364 }
365 qtblno = compptr->quant_tbl_no;
366 /* Make sure specified quantization table is present */
367 if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
368 cinfo->quant_tbl_ptrs[qtblno] == NULL)
369 ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
370 qtbl = cinfo->quant_tbl_ptrs[qtblno];
371 /* Create divisor table from quant table */
372 switch (method) {
373#ifdef PROVIDE_ISLOW_TABLES
374 case JDCT_ISLOW:
375 /* For LL&M FDCT method, divisors are equal to raw quantization
376 * coefficients multiplied by 8 (to counteract scaling).
377 */
378 dtbl = (DCTELEM *) compptr->dct_table;
379 for (i = 0; i < DCTSIZE2; i++) {
380 dtbl[i] =
381 ((DCTELEM) qtbl->quantval[i]) << (compptr->component_needed ? 4 : 3);
382 }
383 fdct->pub.forward_DCT[ci] = forward_DCT;
384 break;
385#endif
386#ifdef PROVIDE_IFAST_TABLES
387 case JDCT_IFAST:
388 {
389 /* For AA&N FDCT method, divisors are equal to quantization
390 * coefficients scaled by scalefactor[row]*scalefactor[col], where
391 * scalefactor[0] = 1
392 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
393 * We apply a further scale factor of 8
394 * with adjustment if necessary.
395 */
396#define CONST_BITS 14
397 static const INT16 aanscales[DCTSIZE2] = {
398 /* precomputed values scaled up by 14 bits */
399 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
400 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
401 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
402 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
403 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
404 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
405 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
406 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
407 };
409
410 dtbl = (DCTELEM *) compptr->dct_table;
412 for (i = 0; i < DCTSIZE2; i++) {
413 dtbl[i] = (DCTELEM)
414 DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
415 (INT32) aanscales[i]),
417 }
418 } else {
419 for (i = 0; i < DCTSIZE2; i++) {
420 dtbl[i] = (DCTELEM)
421 DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
422 (INT32) aanscales[i]),
424 }
425 }
426 }
427 fdct->pub.forward_DCT[ci] = forward_DCT;
428 break;
429#endif
430#ifdef DCT_FLOAT_SUPPORTED
431 case JDCT_FLOAT:
432 {
433 /* For float AA&N FDCT method, divisors are equal to quantization
434 * coefficients scaled by scalefactor[row]*scalefactor[col], where
435 * scalefactor[0] = 1
436 * scalefactor[k] = cos(k*PI/16) * sqrt(2) for k=1..7
437 * We apply a further scale factor of 8
438 * with adjustment if necessary.
439 * What's actually stored is 1/divisor so that the inner loop can
440 * use a multiplication rather than a division.
441 */
442 FAST_FLOAT * fdtbl = (FAST_FLOAT *) compptr->dct_table;
443 int row, col;
444 static const double aanscalefactor[DCTSIZE] = {
445 1.0, 1.387039845, 1.306562965, 1.175875602,
446 1.0, 0.785694958, 0.541196100, 0.275899379
447 };
448#if BITS_IN_JSAMPLE == JPEG_DATA_PRECISION
449
450 i = 0;
451 for (row = 0; row < DCTSIZE; row++) {
452 for (col = 0; col < DCTSIZE; col++) {
453 fdtbl[i] = (FAST_FLOAT)
454 (1.0 / ((double) qtbl->quantval[i] *
455 aanscalefactor[row] * aanscalefactor[col] *
456 (compptr->component_needed ? 16.0 : 8.0)));
457#else
458 double extrafactor = compptr->component_needed ? 16.0 : 8.0;
459
460 /* Adjust extra factor */
461#if BITS_IN_JSAMPLE < JPEG_DATA_PRECISION
463 do { extrafactor *= 0.5; } while (--i);
464#else
466 do { extrafactor *= 2.0; } while (--i);
467#endif
468
469 i = 0;
470 for (row = 0; row < DCTSIZE; row++) {
471 for (col = 0; col < DCTSIZE; col++) {
472 fdtbl[i] = (FAST_FLOAT)
473 (1.0 / ((double) qtbl->quantval[i] *
474 aanscalefactor[row] * aanscalefactor[col] *
475 extrafactor));
476#endif
477 i++;
478 }
479 }
480 }
481 fdct->pub.forward_DCT[ci] = forward_DCT_float;
482 break;
483#endif
484 default:
485 ERREXIT(cinfo, JERR_NOT_COMPILED);
486 }
487 }
488}
short INT16
Definition: actypes.h:130
#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
for(i=0;i< ARRAY_SIZE(offsets);i++)
forward_DCT(j_compress_ptr cinfo, jpeg_component_info *compptr, JSAMPARRAY sample_data, JBLOCKROW coef_blocks, JDIMENSION start_col, JDIMENSION num_blocks)
Definition: jcdctmgr.c:62
#define MULTIPLY16V16(var1, var2)
Definition: jdct.h:402
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:212
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:216
#define JPEG_DATA_PRECISION
Definition: jmorecfg.h:15
#define BITS_IN_JSAMPLE
Definition: jmorecfg.h:16
#define SHIFT_TEMPS
Definition: jpegint.h:300
#define DESCALE(x, n)
Definition: jpegint.h:309
#define JDCT_DEFAULT
Definition: jpeglib.h:247
#define DCTSIZE
Definition: jpeglib.h:50
#define NUM_QUANT_TBLS
Definition: jpeglib.h:52
J_DCT_METHOD
Definition: jpeglib.h:240
@ JDCT_IFAST
Definition: jpeglib.h:242
@ JDCT_FLOAT
Definition: jpeglib.h:243
@ JDCT_ISLOW
Definition: jpeglib.h:241
if(dx< 0)
Definition: linetemp.h:194
#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
int32_t INT32
Definition: typedefs.h:58

Referenced by jinit_forward_dct().