Main MRPT website > C++ reference for MRPT 1.5.7
jdapistd.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 
15 /* Forward declarations */
17 
18 
19 /*
20  * Decompression initialization.
21  * jpeg_read_header must be completed before calling this.
22  *
23  * If a multipass operating mode was selected, this will do all but the
24  * last pass, and thus may take a great deal of time.
25  *
26  * Returns FALSE if suspended. The return value need be inspected only if
27  * a suspending data source is used.
28  */
29 
30 GLOBAL(boolean)
32 {
33  if (cinfo->global_state == DSTATE_READY) {
34  /* First call: initialize master control, select active modules */
36  if (cinfo->buffered_image) {
37  /* No more work here; expecting jpeg_start_output next */
38  cinfo->global_state = DSTATE_BUFIMAGE;
39  return TRUE;
40  }
41  cinfo->global_state = DSTATE_PRELOAD;
42  }
43  if (cinfo->global_state == DSTATE_PRELOAD) {
44  /* If file has multiple scans, absorb them all into the coef buffer */
45  if (cinfo->inputctl->has_multiple_scans) {
46 #ifdef D_MULTISCAN_FILES_SUPPORTED
47  for (;;) {
48  int retcode;
49  /* Call progress monitor hook if present */
50  if (cinfo->progress != NULL)
51  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
52  /* Absorb some more input */
53  retcode = (*cinfo->inputctl->consume_input) (cinfo);
54  if (retcode == JPEG_SUSPENDED)
55  return FALSE;
56  if (retcode == JPEG_REACHED_EOI)
57  break;
58  /* Advance progress counter if appropriate */
59  if (cinfo->progress != NULL &&
60  (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
61  if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
62  /* jdmaster underestimated number of scans; ratchet up one scan */
63  cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
64  }
65  }
66  }
67 #else
68  ERREXIT(cinfo, JERR_NOT_COMPILED);
69 #endif /* D_MULTISCAN_FILES_SUPPORTED */
70  }
71  cinfo->output_scan_number = cinfo->input_scan_number;
72  } else if (cinfo->global_state != DSTATE_PRESCAN)
73  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
74  /* Perform any dummy output passes, and set up for the final pass */
75  return output_pass_setup(cinfo);
76 }
77 
78 
79 /*
80  * Set up for an output pass, and perform any dummy pass(es) needed.
81  * Common subroutine for jpeg_start_decompress and jpeg_start_output.
82  * Entry: global_state = DSTATE_PRESCAN only if previously suspended.
83  * Exit: If done, returns TRUE and sets global_state for proper output mode.
84  * If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.
85  */
86 
87 LOCAL(boolean)
89 {
90  if (cinfo->global_state != DSTATE_PRESCAN) {
91  /* First call: do pass setup */
92  (*cinfo->master->prepare_for_output_pass) (cinfo);
93  cinfo->output_scanline = 0;
94  cinfo->global_state = DSTATE_PRESCAN;
95  }
96  /* Loop over any required dummy passes */
97  while (cinfo->master->is_dummy_pass) {
98 #ifdef QUANT_2PASS_SUPPORTED
99  /* Crank through the dummy pass */
100  while (cinfo->output_scanline < cinfo->output_height) {
101  JDIMENSION last_scanline;
102  /* Call progress monitor hook if present */
103  if (cinfo->progress != NULL) {
104  cinfo->progress->pass_counter = (long) cinfo->output_scanline;
105  cinfo->progress->pass_limit = (long) cinfo->output_height;
106  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
107  }
108  /* Process some data */
109  last_scanline = cinfo->output_scanline;
110  (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
111  &cinfo->output_scanline, (JDIMENSION) 0);
112  if (cinfo->output_scanline == last_scanline)
113  return FALSE; /* No progress made, must suspend */
114  }
115  /* Finish up dummy pass, and set up for another one */
116  (*cinfo->master->finish_output_pass) (cinfo);
117  (*cinfo->master->prepare_for_output_pass) (cinfo);
118  cinfo->output_scanline = 0;
119 #else
120  ERREXIT(cinfo, JERR_NOT_COMPILED);
121 #endif /* QUANT_2PASS_SUPPORTED */
122  }
123  /* Ready for application to drive output pass through
124  * jpeg_read_scanlines or jpeg_read_raw_data.
125  */
126  cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
127  return TRUE;
128 }
129 
130 
131 /*
132  * Read some scanlines of data from the JPEG decompressor.
133  *
134  * The return value will be the number of lines actually read.
135  * This may be less than the number requested in several cases,
136  * including bottom of image, data source suspension, and operating
137  * modes that emit multiple scanlines at a time.
138  *
139  * Note: we warn about excess calls to jpeg_read_scanlines() since
140  * this likely signals an application programmer error. However,
141  * an oversize buffer (max_lines > scanlines remaining) is not an error.
142  */
143 
147 {
148  JDIMENSION row_ctr;
149 
150  if (cinfo->global_state != DSTATE_SCANNING)
151  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
152  if (cinfo->output_scanline >= cinfo->output_height) {
153  WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
154  return 0;
155  }
156 
157  /* Call progress monitor hook if present */
158  if (cinfo->progress != NULL) {
159  cinfo->progress->pass_counter = (long) cinfo->output_scanline;
160  cinfo->progress->pass_limit = (long) cinfo->output_height;
161  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
162  }
163 
164  /* Process some data */
165  row_ctr = 0;
166  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
167  cinfo->output_scanline += row_ctr;
168  return row_ctr;
169 }
170 
171 
172 /*
173  * Alternate entry point to read raw data.
174  * Processes exactly one iMCU row per call, unless suspended.
175  */
176 
180 {
181  JDIMENSION lines_per_iMCU_row;
182 
183  if (cinfo->global_state != DSTATE_RAW_OK)
184  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
185  if (cinfo->output_scanline >= cinfo->output_height) {
186  WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
187  return 0;
188  }
189 
190  /* Call progress monitor hook if present */
191  if (cinfo->progress != NULL) {
192  cinfo->progress->pass_counter = (long) cinfo->output_scanline;
193  cinfo->progress->pass_limit = (long) cinfo->output_height;
194  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
195  }
196 
197  /* Verify that at least one iMCU row can be returned. */
198  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
199  if (max_lines < lines_per_iMCU_row)
200  ERREXIT(cinfo, JERR_BUFFER_SIZE);
201 
202  /* Decompress directly into user's buffer. */
203  if (! (*cinfo->coef->decompress_data) (cinfo, data))
204  return 0; /* suspension forced, can do nothing more */
205 
206  /* OK, we processed one iMCU row. */
207  cinfo->output_scanline += lines_per_iMCU_row;
208  return lines_per_iMCU_row;
209 }
210 
211 
212 /* Additional entry points for buffered-image mode. */
213 
214 #ifdef D_MULTISCAN_FILES_SUPPORTED
215 
216 /*
217  * Initialize for an output pass in buffered-image mode.
218  */
219 
220 GLOBAL(boolean)
222 {
223  if (cinfo->global_state != DSTATE_BUFIMAGE &&
224  cinfo->global_state != DSTATE_PRESCAN)
225  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
226  /* Limit scan number to valid range */
227  if (scan_number <= 0)
228  scan_number = 1;
229  if (cinfo->inputctl->eoi_reached &&
230  scan_number > cinfo->input_scan_number)
231  scan_number = cinfo->input_scan_number;
232  cinfo->output_scan_number = scan_number;
233  /* Perform any dummy output passes, and set up for the real pass */
234  return output_pass_setup(cinfo);
235 }
236 
237 
238 /*
239  * Finish up after an output pass in buffered-image mode.
240  *
241  * Returns FALSE if suspended. The return value need be inspected only if
242  * a suspending data source is used.
243  */
244 
245 GLOBAL(boolean)
247 {
248  if ((cinfo->global_state == DSTATE_SCANNING ||
249  cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
250  /* Terminate this pass. */
251  /* We do not require the whole pass to have been completed. */
252  (*cinfo->master->finish_output_pass) (cinfo);
253  cinfo->global_state = DSTATE_BUFPOST;
254  } else if (cinfo->global_state != DSTATE_BUFPOST) {
255  /* BUFPOST = repeat call after a suspension, anything else is error */
256  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
257  }
258  /* Read markers looking for SOS or EOI */
259  while (cinfo->input_scan_number <= cinfo->output_scan_number &&
260  ! cinfo->inputctl->eoi_reached) {
261  if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
262  return FALSE; /* Suspend, come back later */
263  }
264  cinfo->global_state = DSTATE_BUFIMAGE;
265  return TRUE;
266 }
267 
268 #endif /* D_MULTISCAN_FILES_SUPPORTED */
#define JPEG_ROW_COMPLETED
Definition: mrpt_jpeglib.h:995
#define DSTATE_RAW_OK
Definition: jpegint.h:32
LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo))
jpeg_finish_output(j_decompress_ptr cinfo)
Definition: jdapistd.cpp:246
#define DSTATE_BUFIMAGE
Definition: jpegint.h:33
jpeg_start_decompress(j_decompress_ptr cinfo)
Definition: jdapistd.cpp:31
#define ERREXIT(cinfo, code)
Definition: jerror.h:199
JSAMPARRAY scanlines
Definition: mrpt_jpeglib.h:936
#define DSTATE_PRELOAD
Definition: jpegint.h:29
output_pass_setup(j_decompress_ptr cinfo)
Definition: jdapistd.cpp:88
jpeg_start_output(j_decompress_ptr cinfo, int scan_number)
Definition: jdapistd.cpp:221
jpeg_read_scanlines(j_decompress_ptr cinfo, JSAMPARRAY scanlines, JDIMENSION max_lines)
Definition: jdapistd.cpp:145
#define FALSE
Definition: jmorecfg.h:227
#define JPEG_REACHED_EOI
Definition: mrpt_jpeglib.h:994
jpeg_read_raw_data(j_decompress_ptr cinfo, JSAMPIMAGE data, JDIMENSION max_lines)
Definition: jdapistd.cpp:178
JSAMPROW * JSAMPARRAY
Definition: mrpt_jpeglib.h:64
#define DSTATE_READY
Definition: jpegint.h:28
#define JPEG_SUSPENDED
Definition: mrpt_jpeglib.h:962
#define WARNMS(cinfo, code)
Definition: jerror.h:232
#define DSTATE_SCANNING
Definition: jpegint.h:31
#define JPP(arglist)
Definition: mrpt_jpeglib.h:815
#define TRUE
Definition: jmorecfg.h:230
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:202
JSAMPARRAY JDIMENSION max_lines
Definition: mrpt_jpeglib.h:974
JSAMPARRAY * JSAMPIMAGE
Definition: mrpt_jpeglib.h:65
#define DSTATE_BUFPOST
Definition: jpegint.h:34
int scan_number
Definition: mrpt_jpeglib.h:986
#define GLOBAL(type)
Definition: jmorecfg.h:185
#define DSTATE_PRESCAN
Definition: jpegint.h:30
#define JPEG_REACHED_SOS
Definition: mrpt_jpeglib.h:993
unsigned int JDIMENSION
Definition: jmorecfg.h:168
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3520
jinit_master_decompress(j_decompress_ptr cinfo)
Definition: jdmaster.cpp:539



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