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

Classes

struct  my_prep_controller
 

Macros

#define JPEG_INTERNALS
 
#define CONTEXT_ROWS_SUPPORTED
 

Typedefs

typedef my_prep_controllermy_prep_ptr
 

Functions

static void start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
 
static void expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows, int output_rows)
 
static void pre_process_data (j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail, JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, JDIMENSION out_row_groups_avail)
 
static void pre_process_context (j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail, JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, JDIMENSION out_row_groups_avail)
 
static void create_context_buffer (j_compress_ptr cinfo)
 
void jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
 

Macro Definition Documentation

#define JPEG_INTERNALS
#define CONTEXT_ROWS_SUPPORTED

Typedef Documentation

Function Documentation

static void start_pass_prep ( j_compress_ptr  cinfo,
J_BUF_MODE  pass_mode 
)
static
79 {
80  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
81 
82  if (pass_mode != JBUF_PASS_THRU)
84 
85  /* Initialize total-height counter for detecting bottom of image */
86  prep->rows_to_go = cinfo->image_height;
87  /* Mark the conversion buffer empty */
88  prep->next_buf_row = 0;
89 #ifdef CONTEXT_ROWS_SUPPORTED
90  /* Preset additional state variables for context mode.
91  * These aren't used in non-context mode, so we needn't test which mode.
92  */
93  prep->this_row_group = 0;
94  /* Set next_buf_stop to stop after two row groups have been read in. */
95  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
96 #endif
97 }
struct jpeg_c_prep_controller * prep
Definition: jpeglib.h:402
Definition: jerror.h:46
Definition: jcprepct.cpp:53
JDIMENSION image_height
Definition: jpeglib.h:285
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
int next_buf_row
Definition: jcprepct.cpp:62
int max_v_samp_factor
Definition: jpeglib.h:370
int next_buf_stop
Definition: jcprepct.cpp:66
my_prep_controller * my_prep_ptr
Definition: jcprepct.cpp:70
Definition: jpegint.h:17
int this_row_group
Definition: jcprepct.cpp:65
JDIMENSION rows_to_go
Definition: jcprepct.cpp:61
static void expand_bottom_edge ( JSAMPARRAY  image_data,
JDIMENSION  num_cols,
int  input_rows,
int  output_rows 
)
static
108 {
109  register int row;
110 
111  for (row = input_rows; row < output_rows; row++) {
112  jcopy_sample_rows(image_data, input_rows-1, image_data, row,
113  1, num_cols);
114  }
115 }
void jcopy_sample_rows(JSAMPARRAY input_array, int source_row, JSAMPARRAY output_array, int dest_row, int num_rows, JDIMENSION num_cols)
Definition: jutils.cpp:111
int JSAMPARRAY int int JDIMENSION num_cols
Definition: jpegint.h:373
static void pre_process_data ( j_compress_ptr  cinfo,
JSAMPARRAY  input_buf,
JDIMENSION in_row_ctr,
JDIMENSION  in_rows_avail,
JSAMPIMAGE  output_buf,
JDIMENSION out_row_group_ctr,
JDIMENSION  out_row_groups_avail 
)
static
133 {
134  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
135  int numrows, ci;
136  JDIMENSION inrows;
138 
139  while (*in_row_ctr < in_rows_avail &&
140  *out_row_group_ctr < out_row_groups_avail) {
141  /* Do color conversion to fill the conversion buffer. */
142  inrows = in_rows_avail - *in_row_ctr;
143  numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
144  numrows = (int) MIN((JDIMENSION) numrows, inrows);
145  (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
146  prep->color_buf,
147  (JDIMENSION) prep->next_buf_row,
148  numrows);
149  *in_row_ctr += numrows;
150  prep->next_buf_row += numrows;
151  prep->rows_to_go -= numrows;
152  /* If at bottom of image, pad to fill the conversion buffer. */
153  if (prep->rows_to_go == 0 &&
154  prep->next_buf_row < cinfo->max_v_samp_factor) {
155  for (ci = 0; ci < cinfo->num_components; ci++) {
156  expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
157  prep->next_buf_row, cinfo->max_v_samp_factor);
158  }
159  prep->next_buf_row = cinfo->max_v_samp_factor;
160  }
161  /* If we've filled the conversion buffer, empty it. */
162  if (prep->next_buf_row == cinfo->max_v_samp_factor) {
163  (*cinfo->downsample->downsample) (cinfo,
164  prep->color_buf, (JDIMENSION) 0,
165  output_buf, *out_row_group_ctr);
166  prep->next_buf_row = 0;
167  (*out_row_group_ctr)++;
168  }
169  /* If at bottom of image, pad the output to a full iMCU height.
170  * Note we assume the caller is providing a one-iMCU-height output buffer!
171  */
172  if (prep->rows_to_go == 0 &&
173  *out_row_group_ctr < out_row_groups_avail) {
174  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
175  ci++, compptr++) {
178  (int) (*out_row_group_ctr * compptr->v_samp_factor),
179  (int) (out_row_groups_avail * compptr->v_samp_factor));
180  }
181  *out_row_group_ctr = out_row_groups_avail;
182  break; /* can exit outer loop without test */
183  }
184  }
185 }
struct jpeg_c_prep_controller * prep
Definition: jpeglib.h:402
int v_samp_factor
Definition: jpeglib.h:128
Definition: jcprepct.cpp:53
#define MIN(a, b)
Definition: jpegint.h:269
struct jpeg_color_converter * cconvert
Definition: jpeglib.h:405
int num_components
Definition: jpeglib.h:301
JSAMPARRAY color_buf[10]
Definition: jcprepct.cpp:59
jpeg_component_info * compptr
Definition: jdct.h:102
JDIMENSION width_in_blocks
Definition: jpeglib.h:144
static void expand_bottom_edge(JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows, int output_rows)
Definition: jcprepct.cpp:106
int next_buf_row
Definition: jcprepct.cpp:62
int max_v_samp_factor
Definition: jpeglib.h:370
struct jpeg_downsampler * downsample
Definition: jpeglib.h:406
Definition: jpeglib.h:121
my_prep_controller * my_prep_ptr
Definition: jcprepct.cpp:70
#define DCTSIZE
Definition: jpeglib.h:46
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
jpeg_component_info * comp_info
Definition: jpeglib.h:304
JDIMENSION image_width
Definition: jpeglib.h:284
JDIMENSION rows_to_go
Definition: jcprepct.cpp:61
static void pre_process_context ( j_compress_ptr  cinfo,
JSAMPARRAY  input_buf,
JDIMENSION in_row_ctr,
JDIMENSION  in_rows_avail,
JSAMPIMAGE  output_buf,
JDIMENSION out_row_group_ctr,
JDIMENSION  out_row_groups_avail 
)
static
200 {
201  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
202  int numrows, ci;
203  int buf_height = cinfo->max_v_samp_factor * 3;
204  JDIMENSION inrows;
205 
206  while (*out_row_group_ctr < out_row_groups_avail) {
207  if (*in_row_ctr < in_rows_avail) {
208  /* Do color conversion to fill the conversion buffer. */
209  inrows = in_rows_avail - *in_row_ctr;
210  numrows = prep->next_buf_stop - prep->next_buf_row;
211  numrows = (int) MIN((JDIMENSION) numrows, inrows);
212  (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
213  prep->color_buf,
214  (JDIMENSION) prep->next_buf_row,
215  numrows);
216  /* Pad at top of image, if first time through */
217  if (prep->rows_to_go == cinfo->image_height) {
218  for (ci = 0; ci < cinfo->num_components; ci++) {
219  int row;
220  for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
221  jcopy_sample_rows(prep->color_buf[ci], 0,
222  prep->color_buf[ci], -row,
223  1, cinfo->image_width);
224  }
225  }
226  }
227  *in_row_ctr += numrows;
228  prep->next_buf_row += numrows;
229  prep->rows_to_go -= numrows;
230  } else {
231  /* Return for more data, unless we are at the bottom of the image. */
232  if (prep->rows_to_go != 0)
233  break;
234  /* When at bottom of image, pad to fill the conversion buffer. */
235  if (prep->next_buf_row < prep->next_buf_stop) {
236  for (ci = 0; ci < cinfo->num_components; ci++) {
237  expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
238  prep->next_buf_row, prep->next_buf_stop);
239  }
240  prep->next_buf_row = prep->next_buf_stop;
241  }
242  }
243  /* If we've gotten enough data, downsample a row group. */
244  if (prep->next_buf_row == prep->next_buf_stop) {
245  (*cinfo->downsample->downsample) (cinfo,
246  prep->color_buf,
247  (JDIMENSION) prep->this_row_group,
248  output_buf, *out_row_group_ctr);
249  (*out_row_group_ctr)++;
250  /* Advance pointers with wraparound as necessary. */
251  prep->this_row_group += cinfo->max_v_samp_factor;
252  if (prep->this_row_group >= buf_height)
253  prep->this_row_group = 0;
254  if (prep->next_buf_row >= buf_height)
255  prep->next_buf_row = 0;
256  prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
257  }
258  }
259 }
struct jpeg_c_prep_controller * prep
Definition: jpeglib.h:402
Definition: jcprepct.cpp:53
void jcopy_sample_rows(JSAMPARRAY input_array, int source_row, JSAMPARRAY output_array, int dest_row, int num_rows, JDIMENSION num_cols)
Definition: jutils.cpp:111
JDIMENSION image_height
Definition: jpeglib.h:285
#define MIN(a, b)
Definition: jpegint.h:269
struct jpeg_color_converter * cconvert
Definition: jpeglib.h:405
int num_components
Definition: jpeglib.h:301
JSAMPARRAY color_buf[10]
Definition: jcprepct.cpp:59
static void expand_bottom_edge(JSAMPARRAY image_data, JDIMENSION num_cols, int input_rows, int output_rows)
Definition: jcprepct.cpp:106
int next_buf_row
Definition: jcprepct.cpp:62
int max_v_samp_factor
Definition: jpeglib.h:370
int next_buf_stop
Definition: jcprepct.cpp:66
struct jpeg_downsampler * downsample
Definition: jpeglib.h:406
my_prep_controller * my_prep_ptr
Definition: jcprepct.cpp:70
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
int this_row_group
Definition: jcprepct.cpp:65
JDIMENSION image_width
Definition: jpeglib.h:284
JDIMENSION rows_to_go
Definition: jcprepct.cpp:61
static void create_context_buffer ( j_compress_ptr  cinfo)
static
268 {
269  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
270  int rgroup_height = cinfo->max_v_samp_factor;
271  int ci, i;
273  JSAMPARRAY true_buffer, fake_buffer;
274 
275  /* Grab enough space for fake row pointers for all the components;
276  * we need five row groups' worth of pointers for each component.
277  */
278  fake_buffer = (JSAMPARRAY)
279  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
280  (cinfo->num_components * 5 * rgroup_height) *
281  SIZEOF(JSAMPROW));
282 
283  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
284  ci++, compptr++) {
285  /* Allocate the actual buffer space (3 row groups) for this component.
286  * We make the buffer wide enough to allow the downsampler to edge-expand
287  * horizontally within the buffer, if it so chooses.
288  */
289  true_buffer = (*cinfo->mem->alloc_sarray)
290  ((j_common_ptr) cinfo, JPOOL_IMAGE,
291  (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
293  (JDIMENSION) (3 * rgroup_height));
294  /* Copy true buffer row pointers into the middle of the fake row array */
295  MEMCOPY(fake_buffer + rgroup_height, true_buffer,
296  3 * rgroup_height * SIZEOF(JSAMPROW));
297  /* Fill in the above and below wraparound pointers */
298  for (i = 0; i < rgroup_height; i++) {
299  fake_buffer[i] = true_buffer[2 * rgroup_height + i];
300  fake_buffer[4 * rgroup_height + i] = true_buffer[i];
301  }
302  prep->color_buf[ci] = fake_buffer + rgroup_height;
303  fake_buffer += 5 * rgroup_height; /* point to space for next component */
304  }
305 }
struct jpeg_c_prep_controller * prep
Definition: jpeglib.h:402
Definition: jcprepct.cpp:53
int i
Definition: rw_test.cpp:37
void *(* alloc_small)()
Definition: jpeglib.h:764
int num_components
Definition: jpeglib.h:301
Definition: jpeglib.h:258
#define SIZEOF(object)
Definition: jinclude.h:80
JSAMPARRAY color_buf[10]
Definition: jcprepct.cpp:59
int max_h_samp_factor
Definition: jpeglib.h:369
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
jpeg_component_info * compptr
Definition: jdct.h:102
JDIMENSION width_in_blocks
Definition: jpeglib.h:144
#define JPOOL_IMAGE
Definition: jpeglib.h:754
#define MEMCOPY(dest, src, size)
Definition: jinclude.h:68
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:274
int max_v_samp_factor
Definition: jpeglib.h:370
JSAMPROW * JSAMPARRAY
Definition: jpeglib.h:72
Definition: jpeglib.h:121
my_prep_controller * my_prep_ptr
Definition: jcprepct.cpp:70
#define DCTSIZE
Definition: jpeglib.h:46
int h_samp_factor
Definition: jpeglib.h:127
JSAMPARRAY(* alloc_sarray)()
Definition: jpeglib.h:769
unsigned int JDIMENSION
Definition: jmorecfg.h:171
jpeg_component_info * comp_info
Definition: jpeglib.h:304
void jinit_c_prep_controller ( j_compress_ptr  cinfo,
boolean  need_full_buffer 
)
316 {
317  my_prep_ptr prep;
318  int ci;
320 
321  if (need_full_buffer) /* safety check */
323 
324  prep = (my_prep_ptr)
325  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
327  cinfo->prep = (struct jpeg_c_prep_controller *) prep;
328  prep->pub.start_pass = start_pass_prep;
329 
330  /* Allocate the color conversion buffer.
331  * We make the buffer wide enough to allow the downsampler to edge-expand
332  * horizontally within the buffer, if it so chooses.
333  */
334  if (cinfo->downsample->need_context_rows) {
335  /* Set up to provide context rows */
336 #ifdef CONTEXT_ROWS_SUPPORTED
337  prep->pub.pre_process_data = pre_process_context;
338  create_context_buffer(cinfo);
339 #else
340  ERREXIT(cinfo, JERR_NOT_COMPILED);
341 #endif
342  } else {
343  /* No context, just make it tall enough for one row group */
344  prep->pub.pre_process_data = pre_process_data;
345  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
346  ci++, compptr++) {
347  prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
348  ((j_common_ptr) cinfo, JPOOL_IMAGE,
349  (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
350  cinfo->max_h_samp_factor) / compptr->h_samp_factor),
351  (JDIMENSION) cinfo->max_v_samp_factor);
352  }
353  }
354 }
Definition: jpegint.h:64
struct jpeg_c_prep_controller * prep
Definition: jpeglib.h:402
Definition: jerror.h:46
Definition: jcprepct.cpp:53
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
void *(* alloc_small)()
Definition: jpeglib.h:764
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
Definition: jpeglib.h:258
#define SIZEOF(object)
Definition: jinclude.h:80
JSAMPARRAY color_buf[10]
Definition: jcprepct.cpp:59
boolean need_full_buffer
Definition: jpegint.h:338
int max_h_samp_factor
Definition: jpeglib.h:369
jpeg_component_info * compptr
Definition: jdct.h:102
JDIMENSION width_in_blocks
Definition: jpeglib.h:144
#define JPOOL_IMAGE
Definition: jpeglib.h:754
Definition: jerror.h:95
static void pre_process_context(j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail, JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, JDIMENSION out_row_groups_avail)
Definition: jcprepct.cpp:195
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:274
struct jpeg_c_prep_controller pub
Definition: jcprepct.cpp:54
int max_v_samp_factor
Definition: jpeglib.h:370
struct jpeg_downsampler * downsample
Definition: jpeglib.h:406
static void start_pass_prep(j_compress_ptr cinfo, J_BUF_MODE pass_mode)
Definition: jcprepct.cpp:78
static void create_context_buffer(j_compress_ptr cinfo)
Definition: jcprepct.cpp:267
Definition: jpeglib.h:121
static void pre_process_data(j_compress_ptr cinfo, JSAMPARRAY input_buf, JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail, JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr, JDIMENSION out_row_groups_avail)
Definition: jcprepct.cpp:128
my_prep_controller * my_prep_ptr
Definition: jcprepct.cpp:70
#define DCTSIZE
Definition: jpeglib.h:46
int h_samp_factor
Definition: jpeglib.h:127
JSAMPARRAY(* alloc_sarray)()
Definition: jpeglib.h:769
unsigned int JDIMENSION
Definition: jmorecfg.h:171
jpeg_component_info * comp_info
Definition: jpeglib.h:304
boolean need_context_rows
Definition: jpegint.h:98