Main MRPT website > C++ reference for MRPT 1.9.9
jcmainct.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 /* Note: currently, there is no operating mode in which a full-image buffer
15  * is needed at this step. If there were, that mode could not be used with
16  * "raw data" input, since this module is bypassed in that case. However,
17  * we've left the code here for possible use in special applications.
18  */
19 #undef FULL_MAIN_BUFFER_SUPPORTED
20 
21 /* Private buffer controller object */
22 
23 typedef struct
24 {
25  struct jpeg_c_main_controller pub; /* public fields */
26 
27  JDIMENSION cur_iMCU_row; /* number of current iMCU row */
28  JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
29  boolean suspended; /* remember if we suspended output */
30  J_BUF_MODE pass_mode; /* current operating mode */
31 
32  /* If using just a strip buffer, this points to the entire set of buffers
33  * (we allocate one for each component). In the full-image case, this
34  * points to the currently accessible strips of the virtual arrays.
35  */
37 
38 #ifdef FULL_MAIN_BUFFER_SUPPORTED
39  /* If using full-image storage, this array holds pointers to virtual-array
40  * control blocks for each component. Unused if not full-image storage.
41  */
42  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
43 #endif
45 
47 
48 /* Forward declarations */
49 METHODDEF(void)
51  (j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION* in_row_ctr,
52  JDIMENSION in_rows_avail));
53 #ifdef FULL_MAIN_BUFFER_SUPPORTED
54 METHODDEF(void)
55 process_data_buffer_main JPP(
56  (j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION* in_row_ctr,
57  JDIMENSION in_rows_avail));
58 #endif
59 
60 /*
61  * Initialize for a processing pass.
62  */
63 
64 METHODDEF(void)
66 {
67  my_main_ptr main = (my_main_ptr)cinfo->main;
68 
69  /* Do nothing in raw-data mode. */
70  if (cinfo->raw_data_in) return;
71 
72  main->cur_iMCU_row = 0; /* initialize counters */
73  main->rowgroup_ctr = 0;
74  main->suspended = FALSE;
75  main->pass_mode = pass_mode; /* save mode for use by process_data */
76 
77  switch (pass_mode)
78  {
79  case JBUF_PASS_THRU:
80 #ifdef FULL_MAIN_BUFFER_SUPPORTED
81  if (main->whole_image[0] != nullptr)
82  ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
83 #endif
84  main->pub.process_data = process_data_simple_main;
85  break;
86 #ifdef FULL_MAIN_BUFFER_SUPPORTED
87  case JBUF_SAVE_SOURCE:
88  case JBUF_CRANK_DEST:
89  case JBUF_SAVE_AND_PASS:
90  if (main->whole_image[0] == nullptr)
91  ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
92  main->pub.process_data = process_data_buffer_main;
93  break;
94 #endif
95  default:
96  ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
97  break;
98  }
99 }
100 
101 /*
102  * Process some data.
103  * This routine handles the simple pass-through mode,
104  * where we have only a strip buffer.
105  */
106 
107 METHODDEF(void)
109  j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION* in_row_ctr,
110  JDIMENSION in_rows_avail)
111 {
112  my_main_ptr main = (my_main_ptr)cinfo->main;
113 
114  while (main->cur_iMCU_row < cinfo->total_iMCU_rows)
115  {
116  /* Read input data if we haven't filled the main buffer yet */
117  if (main->rowgroup_ctr < DCTSIZE)
118  (*cinfo->prep->pre_process_data)(
119  cinfo, input_buf, in_row_ctr, in_rows_avail, main->buffer,
120  &main->rowgroup_ctr, (JDIMENSION)DCTSIZE);
121 
122  /* If we don't have a full iMCU row buffered, return to application for
123  * more data. Note that preprocessor will always pad to fill the iMCU
124  * row
125  * at the bottom of the image.
126  */
127  if (main->rowgroup_ctr != DCTSIZE) return;
128 
129  /* Send the completed row to the compressor */
130  if (!(*cinfo->coef->compress_data)(cinfo, main->buffer))
131  {
132  /* If compressor did not consume the whole row, then we must need to
133  * suspend processing and return to the application. In this
134  * situation
135  * we pretend we didn't yet consume the last input row; otherwise,
136  * if
137  * it happened to be the last row of the image, the application
138  * would
139  * think we were done.
140  */
141  if (!main->suspended)
142  {
143  (*in_row_ctr)--;
144  main->suspended = TRUE;
145  }
146  return;
147  }
148  /* We did finish the row. Undo our little suspension hack if a previous
149  * call suspended; then mark the main buffer empty.
150  */
151  if (main->suspended)
152  {
153  (*in_row_ctr)++;
154  main->suspended = FALSE;
155  }
156  main->rowgroup_ctr = 0;
157  main->cur_iMCU_row++;
158  }
159 }
160 
161 #ifdef FULL_MAIN_BUFFER_SUPPORTED
162 
163 /*
164  * Process some data.
165  * This routine handles all of the modes that use a full-size buffer.
166  */
167 
168 METHODDEF(void)
169 process_data_buffer_main(
170  j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION* in_row_ctr,
171  JDIMENSION in_rows_avail)
172 {
173  my_main_ptr main = (my_main_ptr)cinfo->main;
174  int ci;
176  boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
177 
178  while (main->cur_iMCU_row < cinfo->total_iMCU_rows)
179  {
180  /* Realign the virtual buffers if at the start of an iMCU row. */
181  if (main->rowgroup_ctr == 0)
182  {
183  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
184  ci++, compptr++)
185  {
186  main->buffer[ci] = (*cinfo->mem->access_virt_sarray)(
187  (j_common_ptr)cinfo, main->whole_image[ci],
189  (JDIMENSION)(compptr->v_samp_factor * DCTSIZE), writing);
190  }
191  /* In a read pass, pretend we just read some source data. */
192  if (!writing)
193  {
194  *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
195  main->rowgroup_ctr = DCTSIZE;
196  }
197  }
198 
199  /* If a write pass, read input data until the current iMCU row is full.
200  */
201  /* Note: preprocessor will pad if necessary to fill the last iMCU row.
202  */
203  if (writing)
204  {
205  (*cinfo->prep->pre_process_data)(
206  cinfo, input_buf, in_row_ctr, in_rows_avail, main->buffer,
207  &main->rowgroup_ctr, (JDIMENSION)DCTSIZE);
208  /* Return to application if we need more data to fill the iMCU row.
209  */
210  if (main->rowgroup_ctr < DCTSIZE) return;
211  }
212 
213  /* Emit data, unless this is a sink-only pass. */
214  if (main->pass_mode != JBUF_SAVE_SOURCE)
215  {
216  if (!(*cinfo->coef->compress_data)(cinfo, main->buffer))
217  {
218  /* If compressor did not consume the whole row, then we must
219  * need to
220  * suspend processing and return to the application. In this
221  * situation
222  * we pretend we didn't yet consume the last input row;
223  * otherwise, if
224  * it happened to be the last row of the image, the application
225  * would
226  * think we were done.
227  */
228  if (!main->suspended)
229  {
230  (*in_row_ctr)--;
231  main->suspended = TRUE;
232  }
233  return;
234  }
235  /* We did finish the row. Undo our little suspension hack if a
236  * previous
237  * call suspended; then mark the main buffer empty.
238  */
239  if (main->suspended)
240  {
241  (*in_row_ctr)++;
242  main->suspended = FALSE;
243  }
244  }
245 
246  /* If get here, we are done with this iMCU row. Mark buffer empty. */
247  main->rowgroup_ctr = 0;
248  main->cur_iMCU_row++;
249  }
250 }
251 
252 #endif /* FULL_MAIN_BUFFER_SUPPORTED */
253 
254 /*
255  * Initialize main buffer controller.
256  */
257 
258 GLOBAL(void)
259 jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
260 {
261  my_main_ptr main;
262  int ci;
264 
265  main = (my_main_ptr)(*cinfo->mem->alloc_small)(
267  cinfo->main = (struct jpeg_c_main_controller*)main;
268  main->pub.start_pass = start_pass_main;
269 
270  /* We don't need to create a buffer in raw-data mode. */
271  if (cinfo->raw_data_in) return;
272 
273  /* Create the buffer. It holds downsampled data, so each component
274  * may be of a different size.
275  */
276  if (need_full_buffer)
277  {
278 #ifdef FULL_MAIN_BUFFER_SUPPORTED
279  /* Allocate a full-image virtual array for each component */
280  /* Note we pad the bottom to a multiple of the iMCU height */
281  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
282  ci++, compptr++)
283  {
284  main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)(
285  (j_common_ptr)cinfo, JPOOL_IMAGE, FALSE,
288  (long)compptr->height_in_blocks,
289  (long)compptr->v_samp_factor) *
290  DCTSIZE,
292  }
293 #else
294  ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
295 #endif
296  }
297  else
298  {
299 #ifdef FULL_MAIN_BUFFER_SUPPORTED
300  main->whole_image[0] = nullptr; /* flag for no virtual arrays */
301 #endif
302  /* Allocate a strip buffer for each component */
303  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
304  ci++, compptr++)
305  {
306  main->buffer[ci] = (*cinfo->mem->alloc_sarray)(
307  (j_common_ptr)cinfo, JPOOL_IMAGE,
310  }
311  }
312 }
struct jpeg_c_prep_controller * prep
Definition: mrpt_jpeglib.h:397
struct jpeg_c_main_controller pub
Definition: jcmainct.cpp:25
GLuint buffer
Definition: glext.h:3917
#define DCTSIZE
Definition: mrpt_jpeglib.h:36
process_data_simple_main JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail))
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
J_BUF_MODE pass_mode
Definition: jcmainct.cpp:30
#define SIZEOF(object)
Definition: jinclude.h:74
start_pass_main(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
Definition: jcmainct.cpp:65
JDIMENSION rowgroup_ctr
Definition: jcmainct.cpp:28
my_main_controller * my_main_ptr
Definition: jcmainct.cpp:46
JDIMENSION width_in_blocks
Definition: mrpt_jpeglib.h:132
process_data_simple_main(j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail)
Definition: jcmainct.cpp:108
JSAMPARRAY buffer[MAX_COMPONENTS]
Definition: jcmainct.cpp:36
JDIMENSION height_in_blocks
Definition: mrpt_jpeglib.h:133
#define FALSE
Definition: jmorecfg.h:216
struct jpeg_c_coef_controller * coef
Definition: mrpt_jpeglib.h:398
#define JPOOL_IMAGE
Definition: mrpt_jpeglib.h:750
JDIMENSION total_iMCU_rows
Definition: mrpt_jpeglib.h:365
JSAMPROW * JSAMPARRAY
Definition: mrpt_jpeglib.h:61
struct jpeg_c_main_controller * main
Definition: mrpt_jpeglib.h:396
#define TRUE
Definition: jmorecfg.h:219
JDIMENSION cur_iMCU_row
Definition: jcmainct.cpp:27
jinit_c_main_controller(j_compress_ptr cinfo, boolean need_full_buffer)
Definition: jcmainct.cpp:259
#define GLOBAL(type)
Definition: jmorecfg.h:177
#define METHODDEF(type)
Definition: jmorecfg.h:173
J_BUF_MODE
Definition: jpegint.h:12
unsigned int JDIMENSION
Definition: jmorecfg.h:161
jpeg_component_info * comp_info
Definition: mrpt_jpeglib.h:296
jpeg_component_info * compptr
Definition: jidctflt.cpp:36



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