COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
jdapimin.cpp File Reference
#include "jinclude.h"
#include "jpeglib.h"
Include dependency graph for jdapimin.cpp:

Macros

#define JPEG_INTERNALS
 

Functions

void jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
 
void jpeg_destroy_decompress (j_decompress_ptr cinfo)
 
void jpeg_abort_decompress (j_decompress_ptr cinfo)
 
static void default_decompress_parms (j_decompress_ptr cinfo)
 
int jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
 
int jpeg_consume_input (j_decompress_ptr cinfo)
 
boolean jpeg_input_complete (j_decompress_ptr cinfo)
 
boolean jpeg_has_multiple_scans (j_decompress_ptr cinfo)
 
boolean jpeg_finish_decompress (j_decompress_ptr cinfo)
 

Macro Definition Documentation

#define JPEG_INTERNALS

Function Documentation

void jpeg_CreateDecompress ( j_decompress_ptr  cinfo,
int  version,
size_t  structsize 
)
31 {
32  int i;
33 
34  /* Guard against version mismatches between library and caller. */
35  cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
36  if (version != JPEG_LIB_VERSION)
38  if (structsize != SIZEOF(struct jpeg_decompress_struct))
40  (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
41 
42  /* For debugging purposes, we zero the whole master structure.
43  * But the application has already set the err pointer, and may have set
44  * client_data, so we have to save and restore those fields.
45  * Note: if application hasn't set client_data, tools like Purify may
46  * complain here.
47  */
48  {
49  struct jpeg_error_mgr * err = cinfo->err;
50  void * client_data = cinfo->client_data; /* ignore Purify complaint here */
51  MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
52  cinfo->err = err;
53  cinfo->client_data = client_data;
54  }
55  cinfo->is_decompressor = TRUE;
56 
57  /* Initialize a memory manager instance for this object */
59 
60  /* Zero out pointers to permanent structures. */
61  cinfo->progress = NULL;
62  cinfo->src = NULL;
63 
64  for (i = 0; i < NUM_QUANT_TBLS; i++)
65  cinfo->quant_tbl_ptrs[i] = NULL;
66 
67  for (i = 0; i < NUM_HUFF_TBLS; i++) {
68  cinfo->dc_huff_tbl_ptrs[i] = NULL;
69  cinfo->ac_huff_tbl_ptrs[i] = NULL;
70  }
71 
72  /* Initialize marker processor so application can override methods
73  * for COM, APPn markers before calling jpeg_read_header.
74  */
75  cinfo->marker_list = NULL;
76  jinit_marker_reader(cinfo);
77 
78  /* And initialize the overall input controller. */
80 
81  /* OK, I'm ready */
82  cinfo->global_state = DSTATE_START;
83 }
void jinit_input_controller(j_decompress_ptr cinfo)
Definition: jdinput.cpp:361
#define NUM_QUANT_TBLS
Definition: jpeglib.h:48
int i
Definition: rw_test.cpp:37
Definition: jerror.h:55
JHUFF_TBL * dc_huff_tbl_ptrs[4]
Definition: jpeglib.h:530
struct jpeg_progress_mgr * progress
Definition: jpeglib.h:417
#define NUM_HUFF_TBLS
Definition: jpeglib.h:49
Definition: jpeglib.h:648
struct jpeg_error_mgr * err
Definition: jpeglib.h:417
Definition: jpeglib.h:258
#define SIZEOF(object)
Definition: jinclude.h:80
void jinit_marker_reader(j_decompress_ptr cinfo)
Definition: jdmarker.cpp:1262
JHUFF_TBL * ac_huff_tbl_ptrs[4]
Definition: jpeglib.h:531
jpeg_saved_marker_ptr marker_list
Definition: jpeglib.h:571
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
#define JPEG_LIB_VERSION
Definition: jpeglib.h:38
#define DSTATE_START
Definition: jpegint.h:29
#define TRUE
Definition: jpleph.cpp:68
string & err
Definition: json11.cpp:362
Definition: jerror.h:67
void jinit_memory_mgr(j_common_ptr cinfo)
Definition: jmemmgr.cpp:1028
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:527
Definition: jpeglib.h:416
int global_state
Definition: jpeglib.h:417
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:212
void * client_data
Definition: jpeglib.h:417
#define MEMZERO(target, size)
Definition: jinclude.h:67
boolean is_decompressor
Definition: jpeglib.h:417
void jpeg_destroy_decompress ( j_decompress_ptr  cinfo)
92 {
93  jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
94 }
void jpeg_destroy(j_common_ptr cinfo)
Definition: jcomapi.cpp:69
Definition: jpeglib.h:258
void jpeg_abort_decompress ( j_decompress_ptr  cinfo)
104 {
105  jpeg_abort((j_common_ptr) cinfo); /* use common routine */
106 }
Definition: jpeglib.h:258
void jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.cpp:29
static void default_decompress_parms ( j_decompress_ptr  cinfo)
static
115 {
116  /* Guess the input colorspace, and set output colorspace accordingly. */
117  /* (Wish JPEG committee had provided a real way to specify this...) */
118  /* Note application may override our guesses. */
119  switch (cinfo->num_components) {
120  case 1:
123  break;
124 
125  case 3:
126  if (cinfo->saw_JFIF_marker) {
127  cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
128  } else if (cinfo->saw_Adobe_marker) {
129  switch (cinfo->Adobe_transform) {
130  case 0:
131  cinfo->jpeg_color_space = JCS_RGB;
132  break;
133  case 1:
134  cinfo->jpeg_color_space = JCS_YCbCr;
135  break;
136  default:
137  WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
138  cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
139  break;
140  }
141  } else {
142  /* Saw no special markers, try to guess from the component IDs */
143  int cid0 = cinfo->comp_info[0].component_id;
144  int cid1 = cinfo->comp_info[1].component_id;
145  int cid2 = cinfo->comp_info[2].component_id;
146 
147  if (cid0 == 1 && cid1 == 2 && cid2 == 3)
148  cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
149  else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
150  cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
151  else {
152  TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
153  cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
154  }
155  }
156  /* Always guess RGB is proper output colorspace. */
157  cinfo->out_color_space = JCS_RGB;
158  break;
159 
160  case 4:
161  if (cinfo->saw_Adobe_marker) {
162  switch (cinfo->Adobe_transform) {
163  case 0:
164  cinfo->jpeg_color_space = JCS_CMYK;
165  break;
166  case 2:
167  cinfo->jpeg_color_space = JCS_YCCK;
168  break;
169  default:
170  WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
171  cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
172  break;
173  }
174  } else {
175  /* No special markers, assume straight CMYK. */
176  cinfo->jpeg_color_space = JCS_CMYK;
177  }
178  cinfo->out_color_space = JCS_CMYK;
179  break;
180 
181  default:
182  cinfo->jpeg_color_space = JCS_UNKNOWN;
183  cinfo->out_color_space = JCS_UNKNOWN;
184  break;
185  }
186 
187  /* Set defaults for other decompression parameters. */
188  cinfo->scale_num = 1; /* 1:1 scaling */
189  cinfo->scale_denom = 1;
190  cinfo->output_gamma = 1.0;
191  cinfo->buffered_image = FALSE;
192  cinfo->raw_data_out = FALSE;
193  cinfo->dct_method = JDCT_DEFAULT;
194  cinfo->do_fancy_upsampling = TRUE;
195  cinfo->do_block_smoothing = TRUE;
196  cinfo->quantize_colors = FALSE;
197  /* We set these in case application only sets quantize_colors. */
198  cinfo->dither_mode = JDITHER_FS;
199 #ifdef QUANT_2PASS_SUPPORTED
200  cinfo->two_pass_quantize = TRUE;
201 #else
202  cinfo->two_pass_quantize = FALSE;
203 #endif
204  cinfo->desired_number_of_colors = 256;
205  cinfo->colormap = NULL;
206  /* Initialize for no mode change in buffered-image mode. */
207  cinfo->enable_1pass_quant = FALSE;
208  cinfo->enable_external_quant = FALSE;
209  cinfo->enable_2pass_quant = FALSE;
210 }
boolean do_block_smoothing
Definition: jpeglib.h:446
Definition: jpeglib.h:217
int num_components
Definition: jpeglib.h:427
Definition: jerror.h:172
jpeg_component_info * comp_info
Definition: jpeglib.h:540
boolean do_fancy_upsampling
Definition: jpeglib.h:445
boolean enable_2pass_quant
Definition: jpeglib.h:456
Definition: jpeglib.h:212
boolean quantize_colors
Definition: jpeglib.h:448
double output_gamma
Definition: jpeglib.h:439
#define JDCT_DEFAULT
Definition: jpeglib.h:229
boolean enable_external_quant
Definition: jpeglib.h:455
boolean saw_JFIF_marker
Definition: jpeglib.h:555
int desired_number_of_colors
Definition: jpeglib.h:452
boolean two_pass_quantize
Definition: jpeglib.h:451
J_COLOR_SPACE out_color_space
Definition: jpeglib.h:435
#define FALSE
Definition: jpleph.cpp:69
Definition: jpeglib.h:214
Definition: jpeglib.h:213
int component_id
Definition: jpeglib.h:125
boolean raw_data_out
Definition: jpeglib.h:442
J_DCT_METHOD dct_method
Definition: jpeglib.h:444
unsigned int scale_denom
Definition: jpeglib.h:437
boolean enable_1pass_quant
Definition: jpeglib.h:454
#define WARNMS1(cinfo, code, p1)
Definition: jerror.h:241
#define TRUE
Definition: jpleph.cpp:68
boolean saw_Adobe_marker
Definition: jpeglib.h:562
J_DITHER_MODE dither_mode
Definition: jpeglib.h:450
JSAMPARRAY colormap
Definition: jpeglib.h:484
Definition: jpeglib.h:240
uint8_t Adobe_transform
Definition: jpeglib.h:563
Definition: jpeglib.h:215
#define TRACEMS3(cinfo, lvl, code, p1, p2, p3)
Definition: jerror.h:264
unsigned int scale_num
Definition: jpeglib.h:437
boolean buffered_image
Definition: jpeglib.h:441
Definition: jerror.h:169
Definition: jpeglib.h:216
J_COLOR_SPACE jpeg_color_space
Definition: jpeglib.h:428
int jpeg_read_header ( j_decompress_ptr  cinfo,
boolean  require_image 
)
242 {
243  int retcode;
244 
245  if (cinfo->global_state != DSTATE_START &&
246  cinfo->global_state != DSTATE_INHEADER)
247  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
248 
249  retcode = jpeg_consume_input(cinfo);
250 
251  switch (retcode) {
252  case JPEG_REACHED_SOS:
253  retcode = JPEG_HEADER_OK;
254  break;
255  case JPEG_REACHED_EOI:
256  if (require_image) /* Complain if application wanted an image */
257  ERREXIT(cinfo, JERR_NO_IMAGE);
258  /* Reset to start state; it would be safer to require the application to
259  * call jpeg_abort, but we can't change it now for compatibility reasons.
260  * A side effect is to free any temporary memory (there shouldn't be any).
261  */
262  jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
263  retcode = JPEG_HEADER_TABLES_ONLY;
264  break;
265  case JPEG_SUSPENDED:
266  /* no work */
267  break;
268  }
269 
270  return retcode;
271 }
#define DSTATE_INHEADER
Definition: jpegint.h:30
#define JPEG_REACHED_SOS
Definition: jpeglib.h:1001
#define JPEG_REACHED_EOI
Definition: jpeglib.h:1002
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jpeglib.h:258
Definition: jerror.h:65
#define JPEG_HEADER_TABLES_ONLY
Definition: jpeglib.h:972
#define DSTATE_START
Definition: jpegint.h:29
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
#define JPEG_SUSPENDED
Definition: jpeglib.h:970
int jpeg_consume_input(j_decompress_ptr cinfo)
Definition: jdapimin.cpp:287
int global_state
Definition: jpeglib.h:417
Definition: jerror.h:98
void jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.cpp:29
#define JPEG_HEADER_OK
Definition: jpeglib.h:971
int jpeg_consume_input ( j_decompress_ptr  cinfo)
288 {
289  int retcode = JPEG_SUSPENDED;
290 
291  /* NB: every possible DSTATE value should be listed in this switch */
292  switch (cinfo->global_state) {
293  case DSTATE_START:
294  /* Start-of-datastream actions: reset appropriate modules */
295  (*cinfo->inputctl->reset_input_controller) (cinfo);
296  /* Initialize application's data source module */
297  (*cinfo->src->init_source) (cinfo);
298  cinfo->global_state = DSTATE_INHEADER;
299  /*FALLTHROUGH*/
300  case DSTATE_INHEADER:
301  retcode = (*cinfo->inputctl->consume_input) (cinfo);
302  if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
303  /* Set up default parameters based on header data */
305  /* Set global state: ready for start_decompress */
306  cinfo->global_state = DSTATE_READY;
307  }
308  break;
309  case DSTATE_READY:
310  /* Can't advance past first SOS until start_decompress is called */
311  retcode = JPEG_REACHED_SOS;
312  break;
313  case DSTATE_PRELOAD:
314  case DSTATE_PRESCAN:
315  case DSTATE_SCANNING:
316  case DSTATE_RAW_OK:
317  case DSTATE_BUFIMAGE:
318  case DSTATE_BUFPOST:
319  case DSTATE_STOPPING:
320  retcode = (*cinfo->inputctl->consume_input) (cinfo);
321  break;
322  default:
323  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
324  }
325  return retcode;
326 }
#define DSTATE_RAW_OK
Definition: jpegint.h:35
#define DSTATE_INHEADER
Definition: jpegint.h:30
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
#define JPEG_REACHED_SOS
Definition: jpeglib.h:1001
#define DSTATE_BUFIMAGE
Definition: jpegint.h:36
Definition: jerror.h:65
#define DSTATE_STOPPING
Definition: jpegint.h:39
#define DSTATE_PRELOAD
Definition: jpegint.h:32
#define DSTATE_READY
Definition: jpegint.h:31
#define DSTATE_START
Definition: jpegint.h:29
#define DSTATE_SCANNING
Definition: jpegint.h:34
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
#define DSTATE_BUFPOST
Definition: jpegint.h:37
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
#define DSTATE_PRESCAN
Definition: jpegint.h:33
#define JPEG_SUSPENDED
Definition: jpeglib.h:970
int global_state
Definition: jpeglib.h:417
void(* init_source)()
Definition: jpeglib.h:734
static void default_decompress_parms(j_decompress_ptr cinfo)
Definition: jdapimin.cpp:114
boolean jpeg_input_complete ( j_decompress_ptr  cinfo)
335 {
336  /* Check for valid jpeg object */
337  if (cinfo->global_state < DSTATE_START ||
338  cinfo->global_state > DSTATE_STOPPING)
339  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
340  return cinfo->inputctl->eoi_reached;
341 }
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
Definition: jerror.h:65
#define DSTATE_STOPPING
Definition: jpegint.h:39
#define DSTATE_START
Definition: jpegint.h:29
boolean eoi_reached
Definition: jpegint.h:154
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:417
boolean jpeg_has_multiple_scans ( j_decompress_ptr  cinfo)
350 {
351  /* Only valid after jpeg_read_header completes */
352  if (cinfo->global_state < DSTATE_READY ||
353  cinfo->global_state > DSTATE_STOPPING)
354  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
355  return cinfo->inputctl->has_multiple_scans;
356 }
boolean has_multiple_scans
Definition: jpegint.h:153
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
Definition: jerror.h:65
#define DSTATE_STOPPING
Definition: jpegint.h:39
#define DSTATE_READY
Definition: jpegint.h:31
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
int global_state
Definition: jpeglib.h:417
boolean jpeg_finish_decompress ( j_decompress_ptr  cinfo)
370 {
371  if ((cinfo->global_state == DSTATE_SCANNING ||
372  cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
373  /* Terminate final pass of non-buffered mode */
374  if (cinfo->output_scanline < cinfo->output_height)
376  (*cinfo->master->finish_output_pass) (cinfo);
377  cinfo->global_state = DSTATE_STOPPING;
378  } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
379  /* Finishing after a buffered-image operation */
380  cinfo->global_state = DSTATE_STOPPING;
381  } else if (cinfo->global_state != DSTATE_STOPPING) {
382  /* STOPPING = repeat call after a suspension, anything else is error */
383  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
384  }
385  /* Read until EOI */
386  while (! cinfo->inputctl->eoi_reached) {
387  if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
388  return FALSE; /* Suspend, come back later */
389  }
390  /* Do final cleanup */
391  (*cinfo->src->term_source) (cinfo);
392  /* We can use jpeg_abort to release memory and reset global_state */
393  jpeg_abort((j_common_ptr) cinfo);
394  return TRUE;
395 }
#define DSTATE_RAW_OK
Definition: jpegint.h:35
JDIMENSION output_height
Definition: jpeglib.h:465
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
#define DSTATE_BUFIMAGE
Definition: jpegint.h:36
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jpeglib.h:258
Definition: jerror.h:65
void(* term_source)()
Definition: jpeglib.h:738
#define DSTATE_STOPPING
Definition: jpegint.h:39
#define FALSE
Definition: jpleph.cpp:69
struct jpeg_decomp_master * master
Definition: jpeglib.h:624
boolean eoi_reached
Definition: jpegint.h:154
#define DSTATE_SCANNING
Definition: jpegint.h:34
#define TRUE
Definition: jpleph.cpp:68
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
JDIMENSION output_scanline
Definition: jpeglib.h:494
#define JPEG_SUSPENDED
Definition: jpeglib.h:970
int global_state
Definition: jpeglib.h:417
boolean buffered_image
Definition: jpeglib.h:441
void jpeg_abort(j_common_ptr cinfo)
Definition: jcomapi.cpp:29
Definition: jerror.h:116