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



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020