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

Classes

struct  my_post_controller
 

Macros

#define JPEG_INTERNALS
 

Typedefs

typedef my_post_controllermy_post_ptr
 

Functions

static void post_process_1pass (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
 
static void post_process_prepass (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
 
static void post_process_2pass (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
 
static void start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
 
void jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
 

Macro Definition Documentation

#define JPEG_INTERNALS

Typedef Documentation

Function Documentation

static void post_process_1pass ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION in_row_group_ctr,
JDIMENSION  in_row_groups_avail,
JSAMPARRAY  output_buf,
JDIMENSION out_row_ctr,
JDIMENSION  out_rows_avail 
)
static
131 {
132  my_post_ptr post = (my_post_ptr) cinfo->post;
133  JDIMENSION num_rows, max_rows;
134 
135  /* Fill the buffer, but not more than what we can dump out in one go. */
136  /* Note we rely on the upsampler to detect bottom of image. */
137  max_rows = out_rows_avail - *out_row_ctr;
138  if (max_rows > post->strip_height)
139  max_rows = post->strip_height;
140  num_rows = 0;
141  (*cinfo->upsample->upsample) (cinfo,
142  input_buf, in_row_group_ctr, in_row_groups_avail,
143  post->buffer, &num_rows, max_rows);
144  /* Quantize and emit data. */
145  (*cinfo->cquantize->color_quantize) (cinfo,
146  post->buffer, output_buf + *out_row_ctr, (int) num_rows);
147  *out_row_ctr += num_rows;
148 }
struct jpeg_d_post_controller * post
Definition: jpeglib.h:627
JDIMENSION strip_height
Definition: jdpostct.cpp:36
my_post_controller * my_post_ptr
Definition: jdpostct.cpp:42
struct jpeg_color_quantizer * cquantize
Definition: jpeglib.h:634
int JSAMPARRAY int int num_rows
Definition: jpegint.h:373
struct jpeg_upsampler * upsample
Definition: jpeglib.h:632
JSAMPARRAY buffer
Definition: jdpostct.cpp:35
Definition: jdpostct.cpp:26
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
static void post_process_prepass ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION in_row_group_ctr,
JDIMENSION  in_row_groups_avail,
JSAMPARRAY  output_buf,
JDIMENSION out_row_ctr,
JDIMENSION  out_rows_avail 
)
static
163 {
164  my_post_ptr post = (my_post_ptr) cinfo->post;
165  JDIMENSION old_next_row, num_rows;
166 
167  /* Reposition virtual buffer if at start of strip. */
168  if (post->next_row == 0) {
169  post->buffer = (*cinfo->mem->access_virt_sarray)
170  ((j_common_ptr) cinfo, post->whole_image,
171  post->starting_row, post->strip_height, TRUE);
172  }
173 
174  /* Upsample some data (up to a strip height's worth). */
175  old_next_row = post->next_row;
176  (*cinfo->upsample->upsample) (cinfo,
177  input_buf, in_row_group_ctr, in_row_groups_avail,
178  post->buffer, &post->next_row, post->strip_height);
179 
180  /* Allow quantizer to scan new data. No data is emitted, */
181  /* but we advance out_row_ctr so outer loop can tell when we're done. */
182  if (post->next_row > old_next_row) {
183  num_rows = post->next_row - old_next_row;
184  (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
185  (JSAMPARRAY) NULL, (int) num_rows);
186  *out_row_ctr += num_rows;
187  }
188 
189  /* Advance if we filled the strip. */
190  if (post->next_row >= post->strip_height) {
191  post->starting_row += post->strip_height;
192  post->next_row = 0;
193  }
194 }
JSAMPARRAY(* access_virt_sarray)()
Definition: jpeglib.h:790
struct jpeg_d_post_controller * post
Definition: jpeglib.h:627
Definition: jpeglib.h:258
JDIMENSION strip_height
Definition: jdpostct.cpp:36
my_post_controller * my_post_ptr
Definition: jdpostct.cpp:42
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
struct jpeg_color_quantizer * cquantize
Definition: jpeglib.h:634
int JSAMPARRAY int int num_rows
Definition: jpegint.h:373
#define TRUE
Definition: jpleph.cpp:68
JDIMENSION next_row
Definition: jdpostct.cpp:39
JDIMENSION starting_row
Definition: jdpostct.cpp:38
JSAMPROW * JSAMPARRAY
Definition: jpeglib.h:72
struct jpeg_upsampler * upsample
Definition: jpeglib.h:632
JSAMPARRAY buffer
Definition: jdpostct.cpp:35
Definition: jdpostct.cpp:26
unsigned int JDIMENSION
Definition: jmorecfg.h:171
jvirt_sarray_ptr whole_image
Definition: jdpostct.cpp:34
static void post_process_2pass ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION in_row_group_ctr,
JDIMENSION  in_row_groups_avail,
JSAMPARRAY  output_buf,
JDIMENSION out_row_ctr,
JDIMENSION  out_rows_avail 
)
static
207 {
208  my_post_ptr post = (my_post_ptr) cinfo->post;
209  JDIMENSION num_rows, max_rows;
210 
211  /* Reposition virtual buffer if at start of strip. */
212  if (post->next_row == 0) {
213  post->buffer = (*cinfo->mem->access_virt_sarray)
214  ((j_common_ptr) cinfo, post->whole_image,
215  post->starting_row, post->strip_height, FALSE);
216  }
217 
218  /* Determine number of rows to emit. */
219  num_rows = post->strip_height - post->next_row; /* available in strip */
220  max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
221  if (num_rows > max_rows)
222  num_rows = max_rows;
223  /* We have to check bottom of image here, can't depend on upsampler. */
224  max_rows = cinfo->output_height - post->starting_row;
225  if (num_rows > max_rows)
226  num_rows = max_rows;
227 
228  /* Quantize and emit data. */
229  (*cinfo->cquantize->color_quantize) (cinfo,
230  post->buffer + post->next_row, output_buf + *out_row_ctr,
231  (int) num_rows);
232  *out_row_ctr += num_rows;
233 
234  /* Advance if we filled the strip. */
235  post->next_row += num_rows;
236  if (post->next_row >= post->strip_height) {
237  post->starting_row += post->strip_height;
238  post->next_row = 0;
239  }
240 }
JSAMPARRAY(* access_virt_sarray)()
Definition: jpeglib.h:790
JDIMENSION output_height
Definition: jpeglib.h:465
struct jpeg_d_post_controller * post
Definition: jpeglib.h:627
Definition: jpeglib.h:258
JDIMENSION strip_height
Definition: jdpostct.cpp:36
my_post_controller * my_post_ptr
Definition: jdpostct.cpp:42
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
#define FALSE
Definition: jpleph.cpp:69
struct jpeg_color_quantizer * cquantize
Definition: jpeglib.h:634
int JSAMPARRAY int int num_rows
Definition: jpegint.h:373
JDIMENSION next_row
Definition: jdpostct.cpp:39
JDIMENSION starting_row
Definition: jdpostct.cpp:38
JSAMPARRAY buffer
Definition: jdpostct.cpp:35
Definition: jdpostct.cpp:26
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
jvirt_sarray_ptr whole_image
Definition: jdpostct.cpp:34
static void start_pass_dpost ( j_decompress_ptr  cinfo,
J_BUF_MODE  pass_mode 
)
static
74 {
75  my_post_ptr post = (my_post_ptr) cinfo->post;
76 
77  switch (pass_mode) {
78  case JBUF_PASS_THRU:
79  if (cinfo->quantize_colors) {
80  /* Single-pass processing with color quantization. */
81  post->pub.post_process_data = post_process_1pass;
82  /* We could be doing buffered-image output before starting a 2-pass
83  * color quantization; in that case, jinit_d_post_controller did not
84  * allocate a strip buffer. Use the virtual-array buffer as workspace.
85  */
86  if (post->buffer == NULL) {
87  post->buffer = (*cinfo->mem->access_virt_sarray)
88  ((j_common_ptr) cinfo, post->whole_image,
89  (JDIMENSION) 0, post->strip_height, TRUE);
90  }
91  } else {
92  /* For single-pass processing without color quantization,
93  * I have no work to do; just call the upsampler directly.
94  */
95  post->pub.post_process_data = cinfo->upsample->upsample;
96  }
97  break;
98 #ifdef QUANT_2PASS_SUPPORTED
99  case JBUF_SAVE_AND_PASS:
100  /* First pass of 2-pass quantization */
101  if (post->whole_image == NULL)
103  post->pub.post_process_data = post_process_prepass;
104  break;
105  case JBUF_CRANK_DEST:
106  /* Second pass of 2-pass quantization */
107  if (post->whole_image == NULL)
109  post->pub.post_process_data = post_process_2pass;
110  break;
111 #endif /* QUANT_2PASS_SUPPORTED */
112  default:
114  break;
115  }
116  post->starting_row = post->next_row = 0;
117 }
JSAMPARRAY(* access_virt_sarray)()
Definition: jpeglib.h:790
Definition: jerror.h:46
struct jpeg_d_post_controller * post
Definition: jpeglib.h:627
Definition: jpegint.h:20
boolean quantize_colors
Definition: jpeglib.h:448
Definition: jpegint.h:21
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jpeglib.h:258
JDIMENSION strip_height
Definition: jdpostct.cpp:36
struct jpeg_d_post_controller pub
Definition: jdpostct.cpp:27
my_post_controller * my_post_ptr
Definition: jdpostct.cpp:42
static void post_process_2pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
Definition: jdpostct.cpp:202
static void post_process_1pass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
Definition: jdpostct.cpp:126
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
#define TRUE
Definition: jpleph.cpp:68
JDIMENSION next_row
Definition: jdpostct.cpp:39
JDIMENSION starting_row
Definition: jdpostct.cpp:38
struct jpeg_upsampler * upsample
Definition: jpeglib.h:632
JSAMPARRAY buffer
Definition: jdpostct.cpp:35
static void post_process_prepass(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr, JDIMENSION in_row_groups_avail, JSAMPARRAY output_buf, JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail)
Definition: jdpostct.cpp:158
Definition: jdpostct.cpp:26
unsigned int JDIMENSION
Definition: jmorecfg.h:171
jvirt_sarray_ptr whole_image
Definition: jdpostct.cpp:34
Definition: jpegint.h:17
void jinit_d_post_controller ( j_decompress_ptr  cinfo,
boolean  need_full_buffer 
)
251 {
252  my_post_ptr post;
253 
254  post = (my_post_ptr)
255  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
257  cinfo->post = (struct jpeg_d_post_controller *) post;
258  post->pub.start_pass = start_pass_dpost;
259  post->whole_image = NULL; /* flag for no virtual arrays */
260  post->buffer = NULL; /* flag for no strip buffer */
261 
262  /* Create the quantization buffer, if needed */
263  if (cinfo->quantize_colors) {
264  /* The buffer strip height is max_v_samp_factor, which is typically
265  * an efficient number of rows for upsampling to return.
266  * (In the presence of output rescaling, we might want to be smarter?)
267  */
268  post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
269  if (need_full_buffer) {
270  /* Two-pass color quantization: need full-image storage. */
271  /* We round up the number of rows to a multiple of the strip height. */
272 #ifdef QUANT_2PASS_SUPPORTED
273  post->whole_image = (*cinfo->mem->request_virt_sarray)
274  ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
275  cinfo->output_width * cinfo->out_color_components,
276  (JDIMENSION) jround_up((long) cinfo->output_height,
277  (long) post->strip_height),
278  post->strip_height);
279 #else
281 #endif /* QUANT_2PASS_SUPPORTED */
282  } else {
283  /* One-pass color quantization: just make a strip buffer. */
284  post->buffer = (*cinfo->mem->alloc_sarray)
285  ((j_common_ptr) cinfo, JPOOL_IMAGE,
286  cinfo->output_width * cinfo->out_color_components,
287  post->strip_height);
288  }
289  }
290 }
Definition: jerror.h:46
JDIMENSION output_height
Definition: jpeglib.h:465
struct jpeg_d_post_controller * post
Definition: jpeglib.h:627
jvirt_sarray_ptr(* request_virt_sarray)()
Definition: jpeglib.h:778
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
boolean quantize_colors
Definition: jpeglib.h:448
void *(* alloc_small)()
Definition: jpeglib.h:764
static void start_pass_dpost(j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
Definition: jdpostct.cpp:73
long jround_up(long a, long b)
Definition: jutils.cpp:81
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jpeglib.h:258
JDIMENSION output_width
Definition: jpeglib.h:464
#define SIZEOF(object)
Definition: jinclude.h:80
Definition: jpegint.h:177
JDIMENSION strip_height
Definition: jdpostct.cpp:36
boolean need_full_buffer
Definition: jpegint.h:338
struct jpeg_d_post_controller pub
Definition: jdpostct.cpp:27
my_post_controller * my_post_ptr
Definition: jdpostct.cpp:42
#define JPOOL_IMAGE
Definition: jpeglib.h:754
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
#define FALSE
Definition: jpleph.cpp:69
int out_color_components
Definition: jpeglib.h:466
int max_v_samp_factor
Definition: jpeglib.h:581
JSAMPARRAY buffer
Definition: jdpostct.cpp:35
Definition: jdpostct.cpp:26
JSAMPARRAY(* alloc_sarray)()
Definition: jpeglib.h:769
unsigned int JDIMENSION
Definition: jmorecfg.h:171
jvirt_sarray_ptr whole_image
Definition: jdpostct.cpp:34