Main MRPT website > C++ reference for MRPT 1.5.7
jdcoefct.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 
14 /* Block smoothing is only applicable for progressive JPEG, so: */
15 #ifndef D_PROGRESSIVE_SUPPORTED
16 #undef BLOCK_SMOOTHING_SUPPORTED
17 #endif
18 
19 /* Private buffer controller object */
20 
21 typedef struct {
22  struct jpeg_d_coef_controller pub; /* public fields */
23 
24  /* These variables keep track of the current location of the input side. */
25  /* cinfo->input_iMCU_row is also used for this. */
26  JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
27  int MCU_vert_offset; /* counts MCU rows within iMCU row */
28  int MCU_rows_per_iMCU_row; /* number of such rows needed */
29 
30  /* The output side's location is represented by cinfo->output_iMCU_row. */
31 
32  /* In single-pass modes, it's sufficient to buffer just one MCU.
33  * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,
34  * and let the entropy decoder write into that workspace each time.
35  * (On 80x86, the workspace is FAR even though it's not really very big;
36  * this is to keep the module interfaces unchanged when a large coefficient
37  * buffer is necessary.)
38  * In multi-pass modes, this array points to the current MCU's blocks
39  * within the virtual arrays; it is used only by the input side.
40  */
41  JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
42 
43 #ifdef D_MULTISCAN_FILES_SUPPORTED
44  /* In multi-pass modes, we need a virtual block array for each component. */
45  jvirt_barray_ptr whole_image[MAX_COMPONENTS];
46 #endif
47 
48 #ifdef BLOCK_SMOOTHING_SUPPORTED
49  /* When doing block smoothing, we latch coefficient Al values here */
51 #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
52 #endif
54 
56 
57 /* Forward declarations */
60 #ifdef D_MULTISCAN_FILES_SUPPORTED
63 #endif
64 #ifdef BLOCK_SMOOTHING_SUPPORTED
65 LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
68 #endif
69 
70 
71 LOCAL(void)
73 /* Reset within-iMCU-row counters for a new row (input side) */
74 {
75  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
76 
77  /* In an interleaved scan, an MCU row is the same as an iMCU row.
78  * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.
79  * But at the bottom of the image, process only what's left.
80  */
81  if (cinfo->comps_in_scan > 1) {
82  coef->MCU_rows_per_iMCU_row = 1;
83  } else {
84  if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
85  coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
86  else
87  coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
88  }
89 
90  coef->MCU_ctr = 0;
91  coef->MCU_vert_offset = 0;
92 }
93 
94 
95 /*
96  * Initialize for an input processing pass.
97  */
98 
99 METHODDEF(void)
101 {
102  cinfo->input_iMCU_row = 0;
103  start_iMCU_row(cinfo);
104 }
105 
106 
107 /*
108  * Initialize for an output processing pass.
109  */
110 
111 METHODDEF(void)
113 {
114 #ifdef BLOCK_SMOOTHING_SUPPORTED
115  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
116 
117  /* If multipass, check to see whether to use block smoothing on this pass */
118  if (coef->pub.coef_arrays != NULL) {
119  if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
120  coef->pub.decompress_data = decompress_smooth_data;
121  else
122  coef->pub.decompress_data = decompress_data;
123  }
124 #endif
125  cinfo->output_iMCU_row = 0;
126 }
127 
128 
129 /*
130  * Decompress and return some data in the single-pass case.
131  * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
132  * Input and output must run in lockstep since we have only a one-MCU buffer.
133  * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
134  *
135  * NB: output_buf contains a plane for each component in image,
136  * which we index according to the component's SOF position.
137  */
138 
139 METHODDEF(int)
141 {
142  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
143  JDIMENSION MCU_col_num; /* index of current MCU within row */
144  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
145  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
146  int blkn, ci, xindex, yindex, yoffset, useful_width;
147  JSAMPARRAY output_ptr;
148  JDIMENSION start_col, output_col;
150  inverse_DCT_method_ptr inverse_DCT;
151 
152  /* Loop to process as much as one whole iMCU row */
153  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
154  yoffset++) {
155  for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
156  MCU_col_num++) {
157  /* Try to fetch an MCU. Entropy decoder expects buffer to be zeroed. */
158  jzero_far((void FAR *) coef->MCU_buffer[0],
159  (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
160  if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
161  /* Suspension forced; update state counters and exit */
162  coef->MCU_vert_offset = yoffset;
163  coef->MCU_ctr = MCU_col_num;
164  return JPEG_SUSPENDED;
165  }
166  /* Determine where data should go in output_buf and do the IDCT thing.
167  * We skip dummy blocks at the right and bottom edges (but blkn gets
168  * incremented past them!). Note the inner loop relies on having
169  * allocated the MCU_buffer[] blocks sequentially.
170  */
171  blkn = 0; /* index of current DCT block within MCU */
172  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
173  compptr = cinfo->cur_comp_info[ci];
174  /* Don't bother to IDCT an uninteresting component. */
175  if (! compptr->component_needed) {
176  blkn += compptr->MCU_blocks;
177  continue;
178  }
179  inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
180  useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
182  output_ptr = output_buf[compptr->component_index] +
184  start_col = MCU_col_num * compptr->MCU_sample_width;
185  for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
186  if (cinfo->input_iMCU_row < last_iMCU_row ||
187  yoffset+yindex < compptr->last_row_height) {
188  output_col = start_col;
189  for (xindex = 0; xindex < useful_width; xindex++) {
190  (*inverse_DCT) (cinfo, compptr,
191  (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
192  output_ptr, output_col);
194  }
195  }
196  blkn += compptr->MCU_width;
197  output_ptr += compptr->DCT_scaled_size;
198  }
199  }
200  }
201  /* Completed an MCU row, but perhaps not an iMCU row */
202  coef->MCU_ctr = 0;
203  }
204  /* Completed the iMCU row, advance counters for next one */
205  cinfo->output_iMCU_row++;
206  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
207  start_iMCU_row(cinfo);
208  return JPEG_ROW_COMPLETED;
209  }
210  /* Completed the scan */
211  (*cinfo->inputctl->finish_input_pass) (cinfo);
212  return JPEG_SCAN_COMPLETED;
213 }
214 
215 
216 /*
217  * Dummy consume-input routine for single-pass operation.
218  */
219 
220 METHODDEF(int)
222 {
223  return JPEG_SUSPENDED; /* Always indicate nothing was done */
224 }
225 
226 
227 #ifdef D_MULTISCAN_FILES_SUPPORTED
228 
229 /*
230  * Consume input data and store it in the full-image coefficient buffer.
231  * We read as much as one fully interleaved MCU row ("iMCU" row) per call,
232  * ie, v_samp_factor block rows for each component in the scan.
233  * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
234  */
235 
236 METHODDEF(int)
238 {
239  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
240  JDIMENSION MCU_col_num; /* index of current MCU within row */
241  int blkn, ci, xindex, yindex, yoffset;
242  JDIMENSION start_col;
244  JBLOCKROW buffer_ptr;
246 
247  /* Align the virtual buffers for the components used in this scan. */
248  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
249  compptr = cinfo->cur_comp_info[ci];
250  buffer[ci] = (*cinfo->mem->access_virt_barray)
252  cinfo->input_iMCU_row * compptr->v_samp_factor,
254  /* Note: entropy decoder expects buffer to be zeroed,
255  * but this is handled automatically by the memory manager
256  * because we requested a pre-zeroed array.
257  */
258  }
259 
260  /* Loop to process one whole iMCU row */
261  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
262  yoffset++) {
263  for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
264  MCU_col_num++) {
265  /* Construct list of pointers to DCT blocks belonging to this MCU */
266  blkn = 0; /* index of current DCT block within MCU */
267  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
268  compptr = cinfo->cur_comp_info[ci];
269  start_col = MCU_col_num * compptr->MCU_width;
270  for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
271  buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
272  for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
273  coef->MCU_buffer[blkn++] = buffer_ptr++;
274  }
275  }
276  }
277  /* Try to fetch the MCU. */
278  if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
279  /* Suspension forced; update state counters and exit */
280  coef->MCU_vert_offset = yoffset;
281  coef->MCU_ctr = MCU_col_num;
282  return JPEG_SUSPENDED;
283  }
284  }
285  /* Completed an MCU row, but perhaps not an iMCU row */
286  coef->MCU_ctr = 0;
287  }
288  /* Completed the iMCU row, advance counters for next one */
289  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
290  start_iMCU_row(cinfo);
291  return JPEG_ROW_COMPLETED;
292  }
293  /* Completed the scan */
294  (*cinfo->inputctl->finish_input_pass) (cinfo);
295  return JPEG_SCAN_COMPLETED;
296 }
297 
298 
299 /*
300  * Decompress and return some data in the multi-pass case.
301  * Always attempts to emit one fully interleaved MCU row ("iMCU" row).
302  * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.
303  *
304  * NB: output_buf contains a plane for each component in image.
305  */
306 
307 METHODDEF(int)
309 {
310  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
311  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
312  JDIMENSION block_num;
313  int ci, block_row, block_rows;
315  JBLOCKROW buffer_ptr;
316  JSAMPARRAY output_ptr;
319  inverse_DCT_method_ptr inverse_DCT;
320 
321  /* Force some input to be done if we are getting ahead of the input. */
322  while (cinfo->input_scan_number < cinfo->output_scan_number ||
323  (cinfo->input_scan_number == cinfo->output_scan_number &&
324  cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
325  if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
326  return JPEG_SUSPENDED;
327  }
328 
329  /* OK, output from the virtual arrays. */
330  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
331  ci++, compptr++) {
332  /* Don't bother to IDCT an uninteresting component. */
333  if (! compptr->component_needed)
334  continue;
335  /* Align the virtual buffer for this component. */
336  buffer = (*cinfo->mem->access_virt_barray)
337  ((j_common_ptr) cinfo, coef->whole_image[ci],
338  cinfo->output_iMCU_row * compptr->v_samp_factor,
340  /* Count non-dummy DCT block rows in this iMCU row. */
341  if (cinfo->output_iMCU_row < last_iMCU_row)
342  block_rows = compptr->v_samp_factor;
343  else {
344  /* NB: can't use last_row_height here; it is input-side-dependent! */
345  block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
346  if (block_rows == 0) block_rows = compptr->v_samp_factor;
347  }
348  inverse_DCT = cinfo->idct->inverse_DCT[ci];
349  output_ptr = output_buf[ci];
350  /* Loop over all DCT blocks to be processed. */
351  for (block_row = 0; block_row < block_rows; block_row++) {
352  buffer_ptr = buffer[block_row];
353  output_col = 0;
354  for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
355  (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
356  output_ptr, output_col);
357  buffer_ptr++;
359  }
360  output_ptr += compptr->DCT_scaled_size;
361  }
362  }
363 
364  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
365  return JPEG_ROW_COMPLETED;
366  return JPEG_SCAN_COMPLETED;
367 }
368 
369 #endif /* D_MULTISCAN_FILES_SUPPORTED */
370 
371 
372 #ifdef BLOCK_SMOOTHING_SUPPORTED
373 
374 /*
375  * This code applies interblock smoothing as described by section K.8
376  * of the JPEG standard: the first 5 AC coefficients are estimated from
377  * the DC values of a DCT block and its 8 neighboring blocks.
378  * We apply smoothing only for progressive JPEG decoding, and only if
379  * the coefficients it can estimate are not yet known to full precision.
380  */
381 
382 /* Natural-order array positions of the first 5 zigzag-order coefficients */
383 #define Q01_POS 1
384 #define Q10_POS 8
385 #define Q20_POS 16
386 #define Q11_POS 9
387 #define Q02_POS 2
388 
389 /*
390  * Determine whether block smoothing is applicable and safe.
391  * We also latch the current states of the coef_bits[] entries for the
392  * AC coefficients; otherwise, if the input side of the decompressor
393  * advances into a new scan, we might think the coefficients are known
394  * more accurately than they really are.
395  */
396 
397 LOCAL(boolean)
399 {
400  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
401  boolean smoothing_useful = FALSE;
402  int ci, coefi;
404  JQUANT_TBL * qtable;
405  int * coef_bits;
406  int * coef_bits_latch;
407 
408  if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
409  return FALSE;
410 
411  /* Allocate latch area if not already done */
412  if (coef->coef_bits_latch == NULL)
413  coef->coef_bits_latch = (int *)
414  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
415  cinfo->num_components *
416  (SAVED_COEFS * SIZEOF(int)));
417  coef_bits_latch = coef->coef_bits_latch;
418 
419  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
420  ci++, compptr++) {
421  /* All components' quantization values must already be latched. */
422  if ((qtable = compptr->quant_table) == NULL)
423  return FALSE;
424  /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */
425  if (qtable->quantval[0] == 0 ||
426  qtable->quantval[Q01_POS] == 0 ||
427  qtable->quantval[Q10_POS] == 0 ||
428  qtable->quantval[Q20_POS] == 0 ||
429  qtable->quantval[Q11_POS] == 0 ||
430  qtable->quantval[Q02_POS] == 0)
431  return FALSE;
432  /* DC values must be at least partly known for all components. */
433  coef_bits = cinfo->coef_bits[ci];
434  if (coef_bits[0] < 0)
435  return FALSE;
436  /* Block smoothing is helpful if some AC coefficients remain inaccurate. */
437  for (coefi = 1; coefi <= 5; coefi++) {
438  coef_bits_latch[coefi] = coef_bits[coefi];
439  if (coef_bits[coefi] != 0)
440  smoothing_useful = TRUE;
441  }
442  coef_bits_latch += SAVED_COEFS;
443  }
444 
445  return smoothing_useful;
446 }
447 
448 
449 /*
450  * Variant of decompress_data for use when doing block smoothing.
451  */
452 
453 METHODDEF(int)
455 {
456  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
457  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
458  JDIMENSION block_num, last_block_column;
459  int ci, block_row, block_rows, access_rows;
461  JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
462  JSAMPARRAY output_ptr;
465  inverse_DCT_method_ptr inverse_DCT;
466  boolean first_row, last_row;
467  JBLOCK workspace;
468  int *coef_bits;
469  JQUANT_TBL *quanttbl;
470  INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
471  int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
472  int Al, pred;
473 
474  /* Force some input to be done if we are getting ahead of the input. */
475  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
476  ! cinfo->inputctl->eoi_reached) {
477  if (cinfo->input_scan_number == cinfo->output_scan_number) {
478  /* If input is working on current scan, we ordinarily want it to
479  * have completed the current row. But if input scan is DC,
480  * we want it to keep one row ahead so that next block row's DC
481  * values are up to date.
482  */
483  JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
484  if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
485  break;
486  }
487  if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
488  return JPEG_SUSPENDED;
489  }
490 
491  /* OK, output from the virtual arrays. */
492  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
493  ci++, compptr++) {
494  /* Don't bother to IDCT an uninteresting component. */
495  if (! compptr->component_needed)
496  continue;
497  /* Count non-dummy DCT block rows in this iMCU row. */
498  if (cinfo->output_iMCU_row < last_iMCU_row) {
499  block_rows = compptr->v_samp_factor;
500  access_rows = block_rows * 2; /* this and next iMCU row */
501  last_row = FALSE;
502  } else {
503  /* NB: can't use last_row_height here; it is input-side-dependent! */
504  block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
505  if (block_rows == 0) block_rows = compptr->v_samp_factor;
506  access_rows = block_rows; /* this iMCU row only */
507  last_row = TRUE;
508  }
509  /* Align the virtual buffer for this component. */
510  if (cinfo->output_iMCU_row > 0) {
511  access_rows += compptr->v_samp_factor; /* prior iMCU row too */
512  buffer = (*cinfo->mem->access_virt_barray)
513  ((j_common_ptr) cinfo, coef->whole_image[ci],
514  (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
515  (JDIMENSION) access_rows, FALSE);
516  buffer += compptr->v_samp_factor; /* point to current iMCU row */
517  first_row = FALSE;
518  } else {
519  buffer = (*cinfo->mem->access_virt_barray)
520  ((j_common_ptr) cinfo, coef->whole_image[ci],
521  (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
522  first_row = TRUE;
523  }
524  /* Fetch component-dependent info */
525  coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
526  quanttbl = compptr->quant_table;
527  Q00 = quanttbl->quantval[0];
528  Q01 = quanttbl->quantval[Q01_POS];
529  Q10 = quanttbl->quantval[Q10_POS];
530  Q20 = quanttbl->quantval[Q20_POS];
531  Q11 = quanttbl->quantval[Q11_POS];
532  Q02 = quanttbl->quantval[Q02_POS];
533  inverse_DCT = cinfo->idct->inverse_DCT[ci];
534  output_ptr = output_buf[ci];
535  /* Loop over all DCT blocks to be processed. */
536  for (block_row = 0; block_row < block_rows; block_row++) {
537  buffer_ptr = buffer[block_row];
538  if (first_row && block_row == 0)
539  prev_block_row = buffer_ptr;
540  else
541  prev_block_row = buffer[block_row-1];
542  if (last_row && block_row == block_rows-1)
543  next_block_row = buffer_ptr;
544  else
545  next_block_row = buffer[block_row+1];
546  /* We fetch the surrounding DC values using a sliding-register approach.
547  * Initialize all nine here so as to do the right thing on narrow pics.
548  */
549  DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
550  DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
551  DC7 = DC8 = DC9 = (int) next_block_row[0][0];
552  output_col = 0;
553  last_block_column = compptr->width_in_blocks - 1;
554  for (block_num = 0; block_num <= last_block_column; block_num++) {
555  /* Fetch current DCT block into workspace so we can modify it. */
556  jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
557  /* Update DC values */
558  if (block_num < last_block_column) {
559  DC3 = (int) prev_block_row[1][0];
560  DC6 = (int) buffer_ptr[1][0];
561  DC9 = (int) next_block_row[1][0];
562  }
563  /* Compute coefficient estimates per K.8.
564  * An estimate is applied only if coefficient is still zero,
565  * and is not known to be fully accurate.
566  */
567  /* AC01 */
568  if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
569  num = 36 * Q00 * (DC4 - DC6);
570  if (num >= 0) {
571  pred = (int) (((Q01<<7) + num) / (Q01<<8));
572  if (Al > 0 && pred >= (1<<Al))
573  pred = (1<<Al)-1;
574  } else {
575  pred = (int) (((Q01<<7) - num) / (Q01<<8));
576  if (Al > 0 && pred >= (1<<Al))
577  pred = (1<<Al)-1;
578  pred = -pred;
579  }
580  workspace[1] = (JCOEF) pred;
581  }
582  /* AC10 */
583  if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
584  num = 36 * Q00 * (DC2 - DC8);
585  if (num >= 0) {
586  pred = (int) (((Q10<<7) + num) / (Q10<<8));
587  if (Al > 0 && pred >= (1<<Al))
588  pred = (1<<Al)-1;
589  } else {
590  pred = (int) (((Q10<<7) - num) / (Q10<<8));
591  if (Al > 0 && pred >= (1<<Al))
592  pred = (1<<Al)-1;
593  pred = -pred;
594  }
595  workspace[8] = (JCOEF) pred;
596  }
597  /* AC20 */
598  if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
599  num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
600  if (num >= 0) {
601  pred = (int) (((Q20<<7) + num) / (Q20<<8));
602  if (Al > 0 && pred >= (1<<Al))
603  pred = (1<<Al)-1;
604  } else {
605  pred = (int) (((Q20<<7) - num) / (Q20<<8));
606  if (Al > 0 && pred >= (1<<Al))
607  pred = (1<<Al)-1;
608  pred = -pred;
609  }
610  workspace[16] = (JCOEF) pred;
611  }
612  /* AC11 */
613  if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
614  num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
615  if (num >= 0) {
616  pred = (int) (((Q11<<7) + num) / (Q11<<8));
617  if (Al > 0 && pred >= (1<<Al))
618  pred = (1<<Al)-1;
619  } else {
620  pred = (int) (((Q11<<7) - num) / (Q11<<8));
621  if (Al > 0 && pred >= (1<<Al))
622  pred = (1<<Al)-1;
623  pred = -pred;
624  }
625  workspace[9] = (JCOEF) pred;
626  }
627  /* AC02 */
628  if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
629  num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
630  if (num >= 0) {
631  pred = (int) (((Q02<<7) + num) / (Q02<<8));
632  if (Al > 0 && pred >= (1<<Al))
633  pred = (1<<Al)-1;
634  } else {
635  pred = (int) (((Q02<<7) - num) / (Q02<<8));
636  if (Al > 0 && pred >= (1<<Al))
637  pred = (1<<Al)-1;
638  pred = -pred;
639  }
640  workspace[2] = (JCOEF) pred;
641  }
642  /* OK, do the IDCT */
643  (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
644  output_ptr, output_col);
645  /* Advance for next column */
646  DC1 = DC2; DC2 = DC3;
647  DC4 = DC5; DC5 = DC6;
648  DC7 = DC8; DC8 = DC9;
649  buffer_ptr++, prev_block_row++, next_block_row++;
651  }
652  output_ptr += compptr->DCT_scaled_size;
653  }
654  }
655 
656  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
657  return JPEG_ROW_COMPLETED;
658  return JPEG_SCAN_COMPLETED;
659 }
660 
661 #endif /* BLOCK_SMOOTHING_SUPPORTED */
662 
663 
664 /*
665  * Initialize coefficient buffer controller.
666  */
667 
668 GLOBAL(void)
670 {
671  my_coef_ptr coef;
672 
673  coef = (my_coef_ptr)
674  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
676  cinfo->coef = (struct jpeg_d_coef_controller *) coef;
677  coef->pub.start_input_pass = start_input_pass;
678  coef->pub.start_output_pass = start_output_pass;
679 #ifdef BLOCK_SMOOTHING_SUPPORTED
680  coef->coef_bits_latch = NULL;
681 #endif
682 
683  /* Create the coefficient buffer. */
684  if (need_full_buffer) {
685 #ifdef D_MULTISCAN_FILES_SUPPORTED
686  /* Allocate a full-image virtual array for each component, */
687  /* padded to a multiple of samp_factor DCT blocks in each direction. */
688  /* Note we ask for a pre-zeroed array. */
689  int ci, access_rows;
691 
692  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
693  ci++, compptr++) {
694  access_rows = compptr->v_samp_factor;
695 #ifdef BLOCK_SMOOTHING_SUPPORTED
696  /* If block smoothing could be used, need a bigger window */
697  if (cinfo->progressive_mode)
698  access_rows *= 3;
699 #endif
700  coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
701  ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
703  (long) compptr->h_samp_factor),
705  (long) compptr->v_samp_factor),
706  (JDIMENSION) access_rows);
707  }
708  coef->pub.consume_data = consume_data;
709  coef->pub.decompress_data = decompress_data;
710  coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
711 #else
712  ERREXIT(cinfo, JERR_NOT_COMPILED);
713 #endif
714  } else {
715  /* We only need a single-MCU buffer. */
717  int i;
718 
719  buffer = (JBLOCKROW)
720  (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
722  for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
723  coef->MCU_buffer[i] = buffer + i;
724  }
725  coef->pub.consume_data = dummy_consume_data;
726  coef->pub.decompress_data = decompress_onepass;
727  coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
728  }
729 }
JDIMENSION MCU_ctr
Definition: jdcoefct.cpp:26
decompress_smooth_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
Definition: jdcoefct.cpp:454
#define JPEG_ROW_COMPLETED
Definition: mrpt_jpeglib.h:995
start_iMCU_row(j_decompress_ptr cinfo)
Definition: jdcoefct.cpp:72
jzero_far(void FAR *target, size_t bytestozero)
Definition: jutils.cpp:161
consume_data(j_decompress_ptr cinfo)
Definition: jdcoefct.cpp:237
LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo))
dummy_consume_data(j_decompress_ptr)
Definition: jdcoefct.cpp:221
UINT16 quantval[DCTSIZE2]
Definition: mrpt_jpeglib.h:85
jcopy_block_row(JBLOCKROW input_row, JBLOCKROW output_row, JDIMENSION num_blocks)
Definition: jutils.cpp:141
GLuint buffer
Definition: glext.h:3775
#define MAX_COMPS_IN_SCAN
Definition: mrpt_jpeglib.h:43
#define D_MAX_BLOCKS_IN_MCU
Definition: mrpt_jpeglib.h:54
jround_up(long a, long b)
Definition: jutils.cpp:77
struct jpeg_common_struct * j_common_ptr
Definition: mrpt_jpeglib.h:258
#define MAX_COMPONENTS
Definition: jmorecfg.h:32
#define ERREXIT(cinfo, code)
Definition: jerror.h:199
#define SIZEOF(object)
Definition: jinclude.h:73
boolean need_full_buffer
Definition: jpegint.h:335
smoothing_ok(j_decompress_ptr cinfo)
Definition: jdcoefct.cpp:398
short JCOEF
Definition: jmorecfg.h:96
long INT32
Definition: jmorecfg.h:158
jpeg_component_info * compptr
Definition: jdct.h:97
GLuint GLuint num
Definition: glext.h:6303
JDIMENSION width_in_blocks
Definition: mrpt_jpeglib.h:136
jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
Definition: jdcoefct.cpp:669
#define Q20_POS
Definition: jdcoefct.cpp:385
struct jpeg_c_coef_controller pub
Definition: jccoefct.cpp:32
jpeg_component_info JCOEFPTR JSAMPARRAY JDIMENSION output_col
Definition: jdct.h:97
JDIMENSION height_in_blocks
Definition: mrpt_jpeglib.h:137
#define Q11_POS
Definition: jdcoefct.cpp:386
GLint GLint GLint yoffset
Definition: glext.h:3546
#define FALSE
Definition: jmorecfg.h:227
#define JPOOL_IMAGE
Definition: mrpt_jpeglib.h:746
JSAMPROW * JSAMPARRAY
Definition: mrpt_jpeglib.h:64
JCOEF FAR * JCOEFPTR
Definition: mrpt_jpeglib.h:72
decompress_onepass(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
Definition: jdcoefct.cpp:140
#define JPEG_SUSPENDED
Definition: mrpt_jpeglib.h:962
#define JPP(arglist)
Definition: mrpt_jpeglib.h:815
#define TRUE
Definition: jmorecfg.h:230
start_output_pass(j_decompress_ptr cinfo)
Definition: jdcoefct.cpp:112
JQUANT_TBL * quant_table
Definition: mrpt_jpeglib.h:172
JSAMPARRAY * JSAMPIMAGE
Definition: mrpt_jpeglib.h:65
METHODDEF(int) decompress_onepass JPP((j_decompress_ptr cinfo
#define Q10_POS
Definition: jdcoefct.cpp:384
JBLOCKROW * JBLOCKARRAY
Definition: mrpt_jpeglib.h:69
JSAMPIMAGE output_buf
Definition: jdcoefct.cpp:59
#define GLOBAL(type)
Definition: jmorecfg.h:185
start_input_pass(j_decompress_ptr cinfo)
Definition: jdcoefct.cpp:100
JBLOCK FAR * JBLOCKROW
Definition: mrpt_jpeglib.h:68
#define Q02_POS
Definition: jdcoefct.cpp:387
unsigned int JDIMENSION
Definition: jmorecfg.h:168
#define FAR
Definition: zconf.h:261
decompress_data(j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
Definition: jdcoefct.cpp:308
#define Q01_POS
Definition: jdcoefct.cpp:383
JCOEF JBLOCK[DCTSIZE2]
Definition: mrpt_jpeglib.h:67
my_coef_controller * my_coef_ptr
Definition: jdcoefct.cpp:55
#define JPEG_SCAN_COMPLETED
Definition: mrpt_jpeglib.h:996
JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU]
Definition: jccoefct.cpp:48
#define SAVED_COEFS
Definition: jdcoefct.cpp:51
jvirt_barray_ptr whole_image[MAX_COMPONENTS]
Definition: jccoefct.cpp:51



Page generated by Doxygen 1.8.14 for MRPT 1.5.7 Git: 5902e14cc Wed Apr 24 15:04:01 2019 +0200 at lun oct 28 01:39:17 CET 2019