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

Classes

struct  my_input_controller
 

Macros

#define JPEG_INTERNALS
 

Typedefs

typedef my_input_controllermy_inputctl_ptr
 

Functions

static int consume_markers (j_decompress_ptr cinfo)
 
static void initial_setup (j_decompress_ptr cinfo)
 
static void per_scan_setup (j_decompress_ptr cinfo)
 
static void latch_quant_tables (j_decompress_ptr cinfo)
 
static void start_input_pass (j_decompress_ptr cinfo)
 
static void finish_input_pass (j_decompress_ptr cinfo)
 
static void reset_input_controller (j_decompress_ptr cinfo)
 
void jinit_input_controller (j_decompress_ptr cinfo)
 

Macro Definition Documentation

#define JPEG_INTERNALS

Typedef Documentation

Function Documentation

static int consume_markers ( j_decompress_ptr  cinfo)
static
289 {
290  my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
291  int val;
292 
293  if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
294  return JPEG_REACHED_EOI;
295 
296  val = (*cinfo->marker->read_markers) (cinfo);
297 
298  switch (val) {
299  case JPEG_REACHED_SOS: /* Found SOS */
300  if (inputctl->inheaders) { /* 1st SOS */
301  initial_setup(cinfo);
302  inputctl->inheaders = FALSE;
303  /* Note: start_input_pass must be called by jdmaster.c
304  * before any more input can be consumed. jdapimin.c is
305  * responsible for enforcing this sequencing.
306  */
307  } else { /* 2nd or later SOS marker */
308  if (! inputctl->pub.has_multiple_scans)
309  ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
310  start_input_pass(cinfo);
311  }
312  break;
313  case JPEG_REACHED_EOI: /* Found EOI */
314  inputctl->pub.eoi_reached = TRUE;
315  if (inputctl->inheaders) { /* Tables-only datastream, apparently */
316  if (cinfo->marker->saw_SOF)
317  ERREXIT(cinfo, JERR_SOF_NO_SOS);
318  } else {
319  /* Prevent infinite loop in coef ctlr's decompress_data routine
320  * if user set output_scan_number larger than number of scans.
321  */
322  if (cinfo->output_scan_number > cinfo->input_scan_number)
323  cinfo->output_scan_number = cinfo->input_scan_number;
324  }
325  break;
326  case JPEG_SUSPENDED:
327  break;
328  }
329 
330  return val;
331 }
boolean has_multiple_scans
Definition: jpegint.h:153
boolean inheaders
Definition: jdinput.cpp:24
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
#define JPEG_REACHED_SOS
Definition: jpeglib.h:1001
static void initial_setup(j_decompress_ptr cinfo)
Definition: jdinput.cpp:39
#define JPEG_REACHED_EOI
Definition: jpeglib.h:1002
int output_scan_number
Definition: jpeglib.h:506
struct jpeg_marker_reader * marker
Definition: jpeglib.h:629
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
#define FALSE
Definition: jpleph.cpp:69
boolean saw_SOF
Definition: jpegint.h:203
int input_scan_number
Definition: jpeglib.h:499
Definition: jerror.h:107
struct jpeg_input_controller pub
Definition: jdinput.cpp:22
boolean eoi_reached
Definition: jpegint.h:154
#define TRUE
Definition: jpleph.cpp:68
Definition: jdinput.cpp:21
Definition: jerror.h:81
#define JPEG_SUSPENDED
Definition: jpeglib.h:970
my_input_controller * my_inputctl_ptr
Definition: jdinput.cpp:27
static void start_input_pass(j_decompress_ptr cinfo)
Definition: jdinput.cpp:254
static void initial_setup ( j_decompress_ptr  cinfo)
static
41 {
42  int ci;
44 
45  /* Make sure image isn't bigger than I can handle */
46  if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
47  (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
48  ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
49 
50  /* For now, precision must match compiled-in value... */
51  if (cinfo->data_precision != BITS_IN_JSAMPLE)
53 
54  /* Check that number of components won't exceed internal array sizes */
55  if (cinfo->num_components > MAX_COMPONENTS)
58 
59  /* Compute maximum sampling factors; check factor validity */
60  cinfo->max_h_samp_factor = 1;
61  cinfo->max_v_samp_factor = 1;
62  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
63  ci++, compptr++) {
64  if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
65  compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
66  ERREXIT(cinfo, JERR_BAD_SAMPLING);
67  cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
68  compptr->h_samp_factor);
69  cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
70  compptr->v_samp_factor);
71  }
72 
73  /* We initialize DCT_scaled_size and min_DCT_scaled_size to DCTSIZE.
74  * In the full decompressor, this will be overridden by jdmaster.c;
75  * but in the transcoder, jdmaster.c is not used, so we must do it here.
76  */
78 
79  /* Compute dimensions of components */
80  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
81  ci++, compptr++) {
82  compptr->DCT_scaled_size = DCTSIZE;
83  /* Size in DCT blocks */
84  compptr->width_in_blocks = (JDIMENSION)
85  jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
86  (long) (cinfo->max_h_samp_factor * DCTSIZE));
87  compptr->height_in_blocks = (JDIMENSION)
88  jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
89  (long) (cinfo->max_v_samp_factor * DCTSIZE));
90  /* downsampled_width and downsampled_height will also be overridden by
91  * jdmaster.c if we are doing full decompression. The transcoder library
92  * doesn't use these values, but the calling application might.
93  */
94  /* Size in samples */
95  compptr->downsampled_width = (JDIMENSION)
96  jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
97  (long) cinfo->max_h_samp_factor);
98  compptr->downsampled_height = (JDIMENSION)
99  jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
100  (long) cinfo->max_v_samp_factor);
101  /* Mark component needed, until color conversion says otherwise */
102  compptr->component_needed = TRUE;
103  /* Mark no quantization table yet saved for component */
104  compptr->quant_table = NULL;
105  }
106 
107  /* Compute number of fully interleaved MCU rows. */
108  cinfo->total_iMCU_rows = (JDIMENSION)
109  jdiv_round_up((long) cinfo->image_height,
110  (long) (cinfo->max_v_samp_factor*DCTSIZE));
111 
112  /* Decide whether file contains multiple scans */
113  if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
114  cinfo->inputctl->has_multiple_scans = TRUE;
115  else
117 }
boolean has_multiple_scans
Definition: jpegint.h:153
#define BITS_IN_JSAMPLE
Definition: jmorecfg.h:23
int v_samp_factor
Definition: jpeglib.h:128
int num_components
Definition: jpeglib.h:427
JDIMENSION downsampled_width
Definition: jpeglib.h:159
int comps_in_scan
Definition: jpeglib.h:601
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
jpeg_component_info * comp_info
Definition: jpeglib.h:540
Definition: jerror.h:63
int min_DCT_scaled_size
Definition: jpeglib.h:583
#define MAX_COMPONENTS
Definition: jmorecfg.h:35
int data_precision
Definition: jpeglib.h:538
int DCT_scaled_size
Definition: jpeglib.h:152
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
JDIMENSION image_width
Definition: jpeglib.h:425
Definition: jerror.h:72
JDIMENSION image_height
Definition: jpeglib.h:426
boolean component_needed
Definition: jpeglib.h:165
Definition: jerror.h:58
jpeg_component_info * compptr
Definition: jdct.h:102
JDIMENSION width_in_blocks
Definition: jpeglib.h:144
int max_h_samp_factor
Definition: jpeglib.h:580
#define FALSE
Definition: jpleph.cpp:69
JDIMENSION height_in_blocks
Definition: jpeglib.h:145
#define JPEG_MAX_DIMENSION
Definition: jmorecfg.h:173
#define MAX(a, b)
Definition: jpegint.h:267
#define TRUE
Definition: jpleph.cpp:68
#define MAX_SAMP_FACTOR
Definition: jpeglib.h:52
JQUANT_TBL * quant_table
Definition: jpeglib.h:180
int max_v_samp_factor
Definition: jpeglib.h:581
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
Definition: jpeglib.h:121
long jdiv_round_up(long a, long b)
Definition: jutils.cpp:72
#define DCTSIZE
Definition: jpeglib.h:46
int h_samp_factor
Definition: jpeglib.h:127
boolean progressive_mode
Definition: jpeglib.h:543
unsigned int JDIMENSION
Definition: jmorecfg.h:171
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:212
Definition: jerror.h:87
JDIMENSION total_iMCU_rows
Definition: jpeglib.h:585
JDIMENSION downsampled_height
Definition: jpeglib.h:160
static void per_scan_setup ( j_decompress_ptr  cinfo)
static
124 {
125  int ci, mcublks, tmp;
127 
128  if (cinfo->comps_in_scan == 1) {
129 
130  /* Noninterleaved (single-component) scan */
131  compptr = cinfo->cur_comp_info[0];
132 
133  /* Overall image size in MCUs */
134  cinfo->MCUs_per_row = compptr->width_in_blocks;
135  cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
136 
137  /* For noninterleaved scan, always one block per MCU */
138  compptr->MCU_width = 1;
139  compptr->MCU_height = 1;
140  compptr->MCU_blocks = 1;
141  compptr->MCU_sample_width = compptr->DCT_scaled_size;
142  compptr->last_col_width = 1;
143  /* For noninterleaved scans, it is convenient to define last_row_height
144  * as the number of block rows present in the last iMCU row.
145  */
146  tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
147  if (tmp == 0) tmp = compptr->v_samp_factor;
148  compptr->last_row_height = tmp;
149 
150  /* Prepare array describing MCU composition */
151  cinfo->blocks_in_MCU = 1;
152  cinfo->MCU_membership[0] = 0;
153 
154  } else {
155 
156  /* Interleaved (multi-component) scan */
157  if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
160 
161  /* Overall image size in MCUs */
162  cinfo->MCUs_per_row = (JDIMENSION)
163  jdiv_round_up((long) cinfo->image_width,
164  (long) (cinfo->max_h_samp_factor*DCTSIZE));
165  cinfo->MCU_rows_in_scan = (JDIMENSION)
166  jdiv_round_up((long) cinfo->image_height,
167  (long) (cinfo->max_v_samp_factor*DCTSIZE));
168 
169  cinfo->blocks_in_MCU = 0;
170 
171  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
172  compptr = cinfo->cur_comp_info[ci];
173  /* Sampling factors give # of blocks of component in each MCU */
174  compptr->MCU_width = compptr->h_samp_factor;
175  compptr->MCU_height = compptr->v_samp_factor;
176  compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
177  compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
178  /* Figure number of non-dummy blocks in last MCU column & row */
179  tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
180  if (tmp == 0) tmp = compptr->MCU_width;
181  compptr->last_col_width = tmp;
182  tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
183  if (tmp == 0) tmp = compptr->MCU_height;
184  compptr->last_row_height = tmp;
185  /* Prepare array describing MCU composition */
186  mcublks = compptr->MCU_blocks;
187  if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
188  ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
189  while (mcublks-- > 0) {
190  cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
191  }
192  }
193 
194  }
195 }
int v_samp_factor
Definition: jpeglib.h:128
Definition: jerror.h:56
jpeg_component_info * cur_comp_info[4]
Definition: jpeglib.h:602
int comps_in_scan
Definition: jpeglib.h:601
int MCU_height
Definition: jpeglib.h:170
int DCT_scaled_size
Definition: jpeglib.h:152
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
JDIMENSION image_width
Definition: jpeglib.h:425
int MCU_blocks
Definition: jpeglib.h:171
JDIMENSION image_height
Definition: jpeglib.h:426
Definition: jerror.h:72
jpeg_component_info * compptr
Definition: jdct.h:102
JDIMENSION width_in_blocks
Definition: jpeglib.h:144
int max_h_samp_factor
Definition: jpeglib.h:580
int MCU_width
Definition: jpeglib.h:169
JDIMENSION height_in_blocks
Definition: jpeglib.h:145
int last_row_height
Definition: jpeglib.h:174
int max_v_samp_factor
Definition: jpeglib.h:581
JDIMENSION MCU_rows_in_scan
Definition: jpeglib.h:606
Definition: jpeglib.h:121
int MCU_sample_width
Definition: jpeglib.h:172
#define D_MAX_BLOCKS_IN_MCU
Definition: jpeglib.h:62
int MCU_membership[10]
Definition: jpeglib.h:609
long jdiv_round_up(long a, long b)
Definition: jutils.cpp:72
JDIMENSION MCUs_per_row
Definition: jpeglib.h:605
#define DCTSIZE
Definition: jpeglib.h:46
int h_samp_factor
Definition: jpeglib.h:127
unsigned int JDIMENSION
Definition: jmorecfg.h:171
int blocks_in_MCU
Definition: jpeglib.h:608
#define ERREXIT2(cinfo, code, p1, p2)
Definition: jerror.h:212
int last_col_width
Definition: jpeglib.h:173
#define MAX_COMPS_IN_SCAN
Definition: jpeglib.h:51
static void latch_quant_tables ( j_decompress_ptr  cinfo)
static
221 {
222  int ci, qtblno;
224  JQUANT_TBL * qtbl;
225 
226  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
227  compptr = cinfo->cur_comp_info[ci];
228  /* No work if we already saved Q-table for this component */
229  if (compptr->quant_table != NULL)
230  continue;
231  /* Make sure specified quantization table is present */
232  qtblno = compptr->quant_tbl_no;
233  if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
234  cinfo->quant_tbl_ptrs[qtblno] == NULL)
235  ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
236  /* OK, save away the quantization table */
237  qtbl = (JQUANT_TBL *)
238  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
239  SIZEOF(JQUANT_TBL));
240  MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
241  compptr->quant_table = qtbl;
242  }
243 }
#define NUM_QUANT_TBLS
Definition: jpeglib.h:48
jpeg_component_info * cur_comp_info[4]
Definition: jpeglib.h:602
int comps_in_scan
Definition: jpeglib.h:601
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
void *(* alloc_small)()
Definition: jpeglib.h:764
Definition: jpeglib.h:88
#define SIZEOF(object)
Definition: jinclude.h:80
jpeg_component_info * compptr
Definition: jdct.h:102
#define JPOOL_IMAGE
Definition: jpeglib.h:754
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
#define MEMCOPY(dest, src, size)
Definition: jinclude.h:68
int quant_tbl_no
Definition: jpeglib.h:129
Definition: jerror.h:99
JQUANT_TBL * quant_table
Definition: jpeglib.h:180
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:208
Definition: jpeglib.h:121
JQUANT_TBL * quant_tbl_ptrs[4]
Definition: jpeglib.h:527
static void start_input_pass ( j_decompress_ptr  cinfo)
static
255 {
256  per_scan_setup(cinfo);
257  latch_quant_tables(cinfo);
258  (*cinfo->entropy->start_pass) (cinfo);
259  (*cinfo->coef->start_input_pass) (cinfo);
260  cinfo->inputctl->consume_input = cinfo->coef->consume_data;
261 }
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
struct jpeg_d_coef_controller * coef
Definition: jpeglib.h:626
static void latch_quant_tables(j_decompress_ptr cinfo)
Definition: jdinput.cpp:220
static void per_scan_setup(j_decompress_ptr cinfo)
Definition: jdinput.cpp:121
struct jpeg_entropy_decoder * entropy
Definition: jpeglib.h:630
static void finish_input_pass ( j_decompress_ptr  cinfo)
static
272 {
273  cinfo->inputctl->consume_input = consume_markers;
274 }
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
static int consume_markers(j_decompress_ptr cinfo)
Definition: jdinput.cpp:288
static void reset_input_controller ( j_decompress_ptr  cinfo)
static
340 {
341  my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
342 
343  inputctl->pub.consume_input = consume_markers;
344  inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
345  inputctl->pub.eoi_reached = FALSE;
346  inputctl->inheaders = TRUE;
347  /* Reset other modules */
348  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
349  (*cinfo->marker->reset_marker_reader) (cinfo);
350  /* Reset progression state -- would be cleaner if entropy decoder did this */
351  cinfo->coef_bits = NULL;
352 }
boolean has_multiple_scans
Definition: jpegint.h:153
boolean inheaders
Definition: jdinput.cpp:24
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
struct jpeg_marker_reader * marker
Definition: jpeglib.h:629
struct jpeg_error_mgr * err
Definition: jpeglib.h:417
#define FALSE
Definition: jpleph.cpp:69
static int consume_markers(j_decompress_ptr cinfo)
Definition: jdinput.cpp:288
int(* coef_bits)[64]
Definition: jpeglib.h:516
struct jpeg_input_controller pub
Definition: jdinput.cpp:22
boolean eoi_reached
Definition: jpegint.h:154
#define TRUE
Definition: jpleph.cpp:68
void(* reset_error_mgr)()
Definition: jpeglib.h:659
Definition: jdinput.cpp:21
my_input_controller * my_inputctl_ptr
Definition: jdinput.cpp:27
void jinit_input_controller ( j_decompress_ptr  cinfo)
362 {
363  my_inputctl_ptr inputctl;
364 
365  /* Create subobject in permanent pool */
366  inputctl = (my_inputctl_ptr)
367  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
369  cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
370  /* Initialize method pointers */
371  inputctl->pub.consume_input = consume_markers;
372  inputctl->pub.reset_input_controller = reset_input_controller;
373  inputctl->pub.start_input_pass = start_input_pass;
374  inputctl->pub.finish_input_pass = finish_input_pass;
375  /* Initialize state: can't use reset_input_controller since we don't
376  * want to try to reset other modules yet.
377  */
378  inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
379  inputctl->pub.eoi_reached = FALSE;
380  inputctl->inheaders = TRUE;
381 }
boolean has_multiple_scans
Definition: jpegint.h:153
boolean inheaders
Definition: jdinput.cpp:24
struct jpeg_input_controller * inputctl
Definition: jpeglib.h:628
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
void *(* alloc_small)()
Definition: jpeglib.h:764
#define SIZEOF(object)
Definition: jinclude.h:80
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
#define FALSE
Definition: jpleph.cpp:69
static int consume_markers(j_decompress_ptr cinfo)
Definition: jdinput.cpp:288
static void reset_input_controller(j_decompress_ptr cinfo)
Definition: jdinput.cpp:339
struct jpeg_input_controller pub
Definition: jdinput.cpp:22
boolean eoi_reached
Definition: jpegint.h:154
#define TRUE
Definition: jpleph.cpp:68
Definition: jpegint.h:146
Definition: jdinput.cpp:21
#define JPOOL_PERMANENT
Definition: jpeglib.h:753
static void finish_input_pass(j_decompress_ptr cinfo)
Definition: jdinput.cpp:271
my_input_controller * my_inputctl_ptr
Definition: jdinput.cpp:27
static void start_input_pass(j_decompress_ptr cinfo)
Definition: jdinput.cpp:254