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



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019