Main MRPT website > C++ reference for MRPT 1.5.9
jcapimin.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 /*
16  * Initialization of a JPEG compression object.
17  * The error manager must already be set up (in case memory manager fails).
18  */
19 
20 GLOBAL(void)
22 {
23  int i;
24 
25  /* Guard against version mismatches between library and caller. */
26  cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
28  ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
29  if (structsize != SIZEOF(struct jpeg_compress_struct))
30  ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
31  (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
32 
33  /* For debugging purposes, we zero the whole master structure.
34  * But the application has already set the err pointer, and may have set
35  * client_data, so we have to save and restore those fields.
36  * Note: if application hasn't set client_data, tools like Purify may
37  * complain here.
38  */
39  {
40  struct jpeg_error_mgr * err = cinfo->err;
41  void * client_data = cinfo->client_data; /* ignore Purify complaint here */
42  MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
43  cinfo->err = err;
44  cinfo->client_data = client_data;
45  }
46  cinfo->is_decompressor = FALSE;
47 
48  /* Initialize a memory manager instance for this object */
50 
51  /* Zero out pointers to permanent structures. */
52  cinfo->progress = NULL;
53  cinfo->dest = NULL;
54 
55  cinfo->comp_info = NULL;
56 
57  for (i = 0; i < NUM_QUANT_TBLS; i++)
58  cinfo->quant_tbl_ptrs[i] = NULL;
59 
60  for (i = 0; i < NUM_HUFF_TBLS; i++) {
61  cinfo->dc_huff_tbl_ptrs[i] = NULL;
62  cinfo->ac_huff_tbl_ptrs[i] = NULL;
63  }
64 
65  cinfo->script_space = NULL;
66 
67  cinfo->input_gamma = 1.0; /* in case application forgets */
68 
69  /* OK, I'm ready */
70  cinfo->global_state = CSTATE_START;
71 }
72 
73 
74 /*
75  * Destruction of a JPEG compression object
76  */
77 
78 GLOBAL(void)
80 {
81  jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
82 }
83 
84 
85 /*
86  * Abort processing of a JPEG compression operation,
87  * but don't destroy the object itself.
88  */
89 
90 GLOBAL(void)
92 {
93  jpeg_abort((j_common_ptr) cinfo); /* use common routine */
94 }
95 
96 
97 /*
98  * Forcibly suppress or un-suppress all quantization and Huffman tables.
99  * Marks all currently defined tables as already written (if suppress)
100  * or not written (if !suppress). This will control whether they get emitted
101  * by a subsequent jpeg_start_compress call.
102  *
103  * This routine is exported for use by applications that want to produce
104  * abbreviated JPEG datastreams. It logically belongs in jcparam.c, but
105  * since it is called by jpeg_start_compress, we put it here --- otherwise
106  * jcparam.o would be linked whether the application used it or not.
107  */
108 
109 GLOBAL(void)
111 {
112  int i;
113  JQUANT_TBL * qtbl;
114  JHUFF_TBL * htbl;
115 
116  for (i = 0; i < NUM_QUANT_TBLS; i++) {
117  if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
118  qtbl->sent_table = suppress;
119  }
120 
121  for (i = 0; i < NUM_HUFF_TBLS; i++) {
122  if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
124  if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
126  }
127 }
128 
129 
130 /*
131  * Finish JPEG compression.
132  *
133  * If a multipass operating mode was selected, this may do a great deal of
134  * work including most of the actual output.
135  */
136 
137 GLOBAL(void)
139 {
140  JDIMENSION iMCU_row;
141 
142  if (cinfo->global_state == CSTATE_SCANNING ||
143  cinfo->global_state == CSTATE_RAW_OK) {
144  /* Terminate first pass */
145  if (cinfo->next_scanline < cinfo->image_height)
146  ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
147  (*cinfo->master->finish_pass) (cinfo);
148  } else if (cinfo->global_state != CSTATE_WRCOEFS)
149  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
150  /* Perform any remaining passes */
151  while (! cinfo->master->is_last_pass) {
152  (*cinfo->master->prepare_for_pass) (cinfo);
153  for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
154  if (cinfo->progress != NULL) {
155  cinfo->progress->pass_counter = (long) iMCU_row;
156  cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
157  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
158  }
159  /* We bypass the main controller and invoke coef controller directly;
160  * all work is being done from the coefficient buffer.
161  */
162  if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
163  ERREXIT(cinfo, JERR_CANT_SUSPEND);
164  }
165  (*cinfo->master->finish_pass) (cinfo);
166  }
167  /* Write EOI, do final cleanup */
168  (*cinfo->marker->write_file_trailer) (cinfo);
169  (*cinfo->dest->term_destination) (cinfo);
170  /* We can use jpeg_abort to release memory and reset global_state */
171  jpeg_abort((j_common_ptr) cinfo);
172 }
173 
174 
175 /*
176  * Write a special marker.
177  * This is only recommended for writing COM or APPn markers.
178  * Must be called after jpeg_start_compress() and before
179  * first call to jpeg_write_scanlines() or jpeg_write_raw_data().
180  */
181 
182 GLOBAL(void)
184  const JOCTET *dataptr, unsigned int datalen)
185 {
187 
188  if (cinfo->next_scanline != 0 ||
189  (cinfo->global_state != CSTATE_SCANNING &&
190  cinfo->global_state != CSTATE_RAW_OK &&
191  cinfo->global_state != CSTATE_WRCOEFS))
192  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
193 
194  (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
195  write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
196  while (datalen--) {
197  (*write_marker_byte) (cinfo, *dataptr);
198  dataptr++;
199  }
200 }
201 
202 /* Same, but piecemeal. */
203 
204 GLOBAL(void)
206 {
207  if (cinfo->next_scanline != 0 ||
208  (cinfo->global_state != CSTATE_SCANNING &&
209  cinfo->global_state != CSTATE_RAW_OK &&
210  cinfo->global_state != CSTATE_WRCOEFS))
211  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
212 
213  (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
214 }
215 
216 GLOBAL(void)
218 {
219  (*cinfo->marker->write_marker_byte) (cinfo, val);
220 }
221 
222 
223 /*
224  * Alternate compression function: just write an abbreviated table file.
225  * Before calling this, all parameters and a data destination must be set up.
226  *
227  * To produce a pair of files containing abbreviated tables and abbreviated
228  * image data, one would proceed as follows:
229  *
230  * initialize JPEG object
231  * set JPEG parameters
232  * set destination to table file
233  * jpeg_write_tables(cinfo);
234  * set destination to image file
235  * jpeg_start_compress(cinfo, FALSE);
236  * write data...
237  * jpeg_finish_compress(cinfo);
238  *
239  * jpeg_write_tables has the side effect of marking all tables written
240  * (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
241  * will not re-emit the tables unless it is passed write_all_tables=TRUE.
242  */
243 
244 GLOBAL(void)
246 {
247  if (cinfo->global_state != CSTATE_START)
248  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
249 
250  /* (Re)initialize error mgr and destination modules */
251  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
252  (*cinfo->dest->init_destination) (cinfo);
253  /* Initialize the marker writer ... bit of a crock to do it here. */
254  jinit_marker_writer(cinfo);
255  /* Write them tables! */
256  (*cinfo->marker->write_tables_only) (cinfo);
257  /* And clean up. */
258  (*cinfo->dest->term_destination) (cinfo);
259  /*
260  * In library releases up through v6a, we called jpeg_abort() here to free
261  * any working memory allocated by the destination manager and marker
262  * writer. Some applications had a problem with that: they allocated space
263  * of their own from the library memory manager, and didn't want it to go
264  * away during write_tables. So now we do nothing. This will cause a
265  * memory leak if an app calls write_tables repeatedly without doing a full
266  * compression cycle or otherwise resetting the JPEG object. However, that
267  * seems less bad than unexpectedly freeing memory in the normal case.
268  * An app that prefers the old behavior can call jpeg_abort for itself after
269  * each call to jpeg_write_tables().
270  */
271 }
int const JOCTET * dataptr
Definition: mrpt_jpeglib.h:947
#define CSTATE_START
Definition: jpegint.h:22
int size_t structsize
Definition: mrpt_jpeglib.h:898
jpeg_write_tables(j_compress_ptr cinfo)
Definition: jcapimin.cpp:245
struct jpeg_common_struct * j_common_ptr
Definition: mrpt_jpeglib.h:258
boolean sent_table
Definition: mrpt_jpeglib.h:91
jpeg_destroy(j_common_ptr cinfo)
Definition: jcomapi.cpp:67
#define ERREXIT(cinfo, code)
Definition: jerror.h:199
#define SIZEOF(object)
Definition: jinclude.h:73
jpeg_suppress_tables(j_compress_ptr cinfo, boolean suppress)
Definition: jcapimin.cpp:110
#define CSTATE_RAW_OK
Definition: jpegint.h:24
#define CSTATE_SCANNING
Definition: jpegint.h:23
jpeg_CreateCompress(j_compress_ptr cinfo, int version, size_t structsize)
Definition: jcapimin.cpp:21
int marker
Definition: mrpt_jpeglib.h:947
jpeg_write_m_byte(j_compress_ptr cinfo, int val)
Definition: jcapimin.cpp:217
jpeg_finish_compress(j_compress_ptr cinfo)
Definition: jcapimin.cpp:138
jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.cpp:27
jinit_memory_mgr(j_common_ptr cinfo)
Definition: jmemmgr.cpp:1011
#define FALSE
Definition: jmorecfg.h:227
int const JOCTET unsigned int datalen
Definition: mrpt_jpeglib.h:947
int val
Definition: mrpt_jpeglib.h:953
int version
Definition: mrpt_jpeglib.h:898
#define JMETHOD(type, methodname, arglist)
Definition: jmorecfg.h:199
#define NUM_HUFF_TBLS
Definition: mrpt_jpeglib.h:41
jpeg_destroy_compress(j_compress_ptr cinfo)
Definition: jcapimin.cpp:79
boolean suppress
Definition: mrpt_jpeglib.h:928
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:202
jpeg_write_m_header(j_compress_ptr cinfo, int marker, unsigned int datalen)
Definition: jcapimin.cpp:205
JSAMPARRAY * JSAMPIMAGE
Definition: mrpt_jpeglib.h:65
jpeg_write_marker(j_compress_ptr cinfo, int marker, const JOCTET *dataptr, unsigned int datalen)
Definition: jcapimin.cpp:183
boolean sent_table
Definition: mrpt_jpeglib.h:107
#define JPEG_LIB_VERSION
Definition: mrpt_jpeglib.h:30
#define GLOBAL(type)
Definition: jmorecfg.h:185
backing_store_ptr info
Definition: jmemsys.h:170
#define NUM_QUANT_TBLS
Definition: mrpt_jpeglib.h:40
write_marker_byte(j_compress_ptr cinfo, int val)
Definition: jcmarker.cpp:449
unsigned int JDIMENSION
Definition: jmorecfg.h:168
JHUFF_TBL * htbl
Definition: jchuff.h:44
char JOCTET
Definition: jmorecfg.h:112
#define CSTATE_WRCOEFS
Definition: jpegint.h:25
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:206
jinit_marker_writer(j_compress_ptr cinfo)
Definition: jcmarker.cpp:644
jpeg_abort_compress(j_compress_ptr cinfo)
Definition: jcapimin.cpp:91
#define MEMZERO(target, size)
Definition: jinclude.h:60



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