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



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