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

Classes

struct  my_upsampler
 

Macros

#define JPEG_INTERNALS
 
#define SCALEBITS   16 /* speediest right-shift on some machines */
 
#define ONE_HALF   ((int32_t) 1 << (SCALEBITS-1))
 
#define FIX(x)   ((int32_t) ((x) * (1L<<SCALEBITS) + 0.5))
 

Typedefs

typedef my_upsamplermy_upsample_ptr
 

Functions

static void build_ycc_rgb_table (j_decompress_ptr cinfo)
 
static void start_pass_merged_upsample (j_decompress_ptr cinfo)
 
static void merged_2v_upsample (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 merged_1v_upsample (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 h2v1_merged_upsample (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
 
static void h2v2_merged_upsample (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
 
void jinit_merged_upsampler (j_decompress_ptr cinfo)
 

Macro Definition Documentation

#define JPEG_INTERNALS
#define SCALEBITS   16 /* speediest right-shift on some machines */
#define ONE_HALF   ((int32_t) 1 << (SCALEBITS-1))
#define FIX (   x)    ((int32_t) ((x) * (1L<<SCALEBITS) + 0.5))

Typedef Documentation

Function Documentation

static void build_ycc_rgb_table ( j_decompress_ptr  cinfo)
static
84 {
85  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
86  int i;
87  int32_t x;
89 
90  upsample->Cr_r_tab = (int *)
91  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
92  (MAXJSAMPLE+1) * SIZEOF(int));
93  upsample->Cb_b_tab = (int *)
94  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
95  (MAXJSAMPLE+1) * SIZEOF(int));
96  upsample->Cr_g_tab = (int32_t *)
97  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
98  (MAXJSAMPLE+1) * SIZEOF(int32_t));
99  upsample->Cb_g_tab = (int32_t *)
100  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
101  (MAXJSAMPLE+1) * SIZEOF(int32_t));
102 
103  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
104  /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
105  /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
106  /* Cr=>R value is nearest int to 1.40200 * x */
107  upsample->Cr_r_tab[i] = (int)
108  RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
109  /* Cb=>B value is nearest int to 1.77200 * x */
110  upsample->Cb_b_tab[i] = (int)
111  RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
112  /* Cr=>G value is scaled-up -0.71414 * x */
113  upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
114  /* Cb=>G value is scaled-up -0.34414 * x */
115  /* We also add in ONE_HALF so that need not do it in inner loop */
116  upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
117  }
118 }
#define CENTERJSAMPLE
Definition: jmorecfg.h:74
#define FIX(x)
Definition: jdmerge.cpp:74
int i
Definition: rw_test.cpp:37
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
#define ONE_HALF
Definition: jdmerge.cpp:73
void *(* alloc_small)()
Definition: jpeglib.h:764
Definition: jpeglib.h:258
int * Cr_r_tab
Definition: jdmerge.cpp:53
#define SIZEOF(object)
Definition: jinclude.h:80
#define MAXJSAMPLE
Definition: jmorecfg.h:73
#define SHIFT_TEMPS
Definition: jpegint.h:289
int32_t * Cb_g_tab
Definition: jdmerge.cpp:56
#define JPOOL_IMAGE
Definition: jpeglib.h:754
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
int * Cb_b_tab
Definition: jdmerge.cpp:54
#define SCALEBITS
Definition: jdmerge.cpp:72
x
Definition: inputfile.py:6
Definition: jdmerge.cpp:44
struct jpeg_upsampler * upsample
Definition: jpeglib.h:632
#define RIGHT_SHIFT(x, shft)
Definition: jpegint.h:290
int32_t * Cr_g_tab
Definition: jdmerge.cpp:55
my_upsampler * my_upsample_ptr
Definition: jdmerge.cpp:70
static void start_pass_merged_upsample ( j_decompress_ptr  cinfo)
static
127 {
128  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
129 
130  /* Mark the spare buffer empty */
131  upsample->spare_full = FALSE;
132  /* Initialize total-height counter for detecting bottom of image */
133  upsample->rows_to_go = cinfo->output_height;
134 }
JDIMENSION output_height
Definition: jpeglib.h:465
JDIMENSION rows_to_go
Definition: jdmerge.cpp:67
#define FALSE
Definition: jpleph.cpp:69
boolean spare_full
Definition: jdmerge.cpp:64
Definition: jdmerge.cpp:44
struct jpeg_upsampler * upsample
Definition: jpeglib.h:632
my_upsampler * my_upsample_ptr
Definition: jdmerge.cpp:70
static void merged_2v_upsample ( 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
150 {
151  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
152  JSAMPROW work_ptrs[2];
153  JDIMENSION num_rows; /* number of rows returned to caller */
154 
155  if (upsample->spare_full) {
156  /* If we have a spare row saved from a previous cycle, just return it. */
157  jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
158  1, upsample->out_row_width);
159  num_rows = 1;
160  upsample->spare_full = FALSE;
161  } else {
162  /* Figure number of rows to return to caller. */
163  num_rows = 2;
164  /* Not more than the distance to the end of the image. */
165  if (num_rows > upsample->rows_to_go)
166  num_rows = upsample->rows_to_go;
167  /* And not more than what the client can accept: */
168  out_rows_avail -= *out_row_ctr;
169  if (num_rows > out_rows_avail)
170  num_rows = out_rows_avail;
171  /* Create output pointer array for upsampler. */
172  work_ptrs[0] = output_buf[*out_row_ctr];
173  if (num_rows > 1) {
174  work_ptrs[1] = output_buf[*out_row_ctr + 1];
175  } else {
176  work_ptrs[1] = upsample->spare_row;
177  upsample->spare_full = TRUE;
178  }
179  /* Now do the upsampling. */
180  (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
181  }
182 
183  /* Adjust counts */
184  *out_row_ctr += num_rows;
185  upsample->rows_to_go -= num_rows;
186  /* When the buffer is emptied, declare this input row group consumed */
187  if (! upsample->spare_full)
188  (*in_row_group_ctr)++;
189 }
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
void(* upmethod)(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
Definition: jdmerge.cpp:50
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
JDIMENSION rows_to_go
Definition: jdmerge.cpp:67
#define FALSE
Definition: jpleph.cpp:69
boolean spare_full
Definition: jdmerge.cpp:64
int JSAMPARRAY int int num_rows
Definition: jpegint.h:373
#define TRUE
Definition: jpleph.cpp:68
Definition: jdmerge.cpp:44
JSAMPROW spare_row
Definition: jdmerge.cpp:63
struct jpeg_upsampler * upsample
Definition: jpeglib.h:632
my_upsampler * my_upsample_ptr
Definition: jdmerge.cpp:70
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
JDIMENSION out_row_width
Definition: jdmerge.cpp:66
static void merged_1v_upsample ( 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
199 {
200  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
201 
202  /* Just do the upsampling. */
203  (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
204  output_buf + *out_row_ctr);
205  /* Adjust counts */
206  (*out_row_ctr)++;
207  (*in_row_group_ctr)++;
208 }
void(* upmethod)(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
Definition: jdmerge.cpp:50
Definition: jdmerge.cpp:44
struct jpeg_upsampler * upsample
Definition: jpeglib.h:632
my_upsampler * my_upsample_ptr
Definition: jdmerge.cpp:70
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
static void h2v1_merged_upsample ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  in_row_group_ctr,
JSAMPARRAY  output_buf 
)
static
229 {
230  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
231  register int y, cred, cgreen, cblue;
232  int cb, cr;
233  register JSAMPROW outptr;
234  JSAMPROW inptr0, inptr1, inptr2;
235  JDIMENSION col;
236  /* copy these pointers into registers if possible */
237  register JSAMPLE * range_limit = cinfo->sample_range_limit;
238  int * Crrtab = upsample->Cr_r_tab;
239  int * Cbbtab = upsample->Cb_b_tab;
240  int32_t * Crgtab = upsample->Cr_g_tab;
241  int32_t * Cbgtab = upsample->Cb_g_tab;
243 
244  inptr0 = input_buf[0][in_row_group_ctr];
245  inptr1 = input_buf[1][in_row_group_ctr];
246  inptr2 = input_buf[2][in_row_group_ctr];
247  outptr = output_buf[0];
248  /* Loop for each pair of output pixels */
249  for (col = cinfo->output_width >> 1; col > 0; col--) {
250  /* Do the chroma part of the calculation */
251  cb = GETJSAMPLE(*inptr1++);
252  cr = GETJSAMPLE(*inptr2++);
253  cred = Crrtab[cr];
254  cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
255  cblue = Cbbtab[cb];
256  /* Fetch 2 Y values and emit 2 pixels */
257  y = GETJSAMPLE(*inptr0++);
258  outptr[RGB_RED] = range_limit[y + cred];
259  outptr[RGB_GREEN] = range_limit[y + cgreen];
260  outptr[RGB_BLUE] = range_limit[y + cblue];
261  outptr += RGB_PIXELSIZE;
262  y = GETJSAMPLE(*inptr0++);
263  outptr[RGB_RED] = range_limit[y + cred];
264  outptr[RGB_GREEN] = range_limit[y + cgreen];
265  outptr[RGB_BLUE] = range_limit[y + cblue];
266  outptr += RGB_PIXELSIZE;
267  }
268  /* If image width is odd, do the last output column separately */
269  if (cinfo->output_width & 1) {
270  cb = GETJSAMPLE(*inptr1);
271  cr = GETJSAMPLE(*inptr2);
272  cred = Crrtab[cr];
273  cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
274  cblue = Cbbtab[cb];
275  y = GETJSAMPLE(*inptr0);
276  outptr[RGB_RED] = range_limit[y + cred];
277  outptr[RGB_GREEN] = range_limit[y + cgreen];
278  outptr[RGB_BLUE] = range_limit[y + cblue];
279  }
280 }
char JSAMPLE
Definition: jmorecfg.h:64
y
Definition: inputfile.py:6
#define GETJSAMPLE(value)
Definition: jmorecfg.h:68
JDIMENSION output_width
Definition: jpeglib.h:464
int * Cr_r_tab
Definition: jdmerge.cpp:53
#define SHIFT_TEMPS
Definition: jpegint.h:289
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
int32_t * Cb_g_tab
Definition: jdmerge.cpp:56
int * Cb_b_tab
Definition: jdmerge.cpp:54
#define SCALEBITS
Definition: jdmerge.cpp:72
JSAMPLE * sample_range_limit
Definition: jpeglib.h:594
Definition: jdmerge.cpp:44
struct jpeg_upsampler * upsample
Definition: jpeglib.h:632
#define RIGHT_SHIFT(x, shft)
Definition: jpegint.h:290
int32_t * Cr_g_tab
Definition: jdmerge.cpp:55
my_upsampler * my_upsample_ptr
Definition: jdmerge.cpp:70
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
static void h2v2_merged_upsample ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  in_row_group_ctr,
JSAMPARRAY  output_buf 
)
static
291 {
292  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
293  register int y, cred, cgreen, cblue;
294  int cb, cr;
295  register JSAMPROW outptr0, outptr1;
296  JSAMPROW inptr00, inptr01, inptr1, inptr2;
297  JDIMENSION col;
298  /* copy these pointers into registers if possible */
299  register JSAMPLE * range_limit = cinfo->sample_range_limit;
300  int * Crrtab = upsample->Cr_r_tab;
301  int * Cbbtab = upsample->Cb_b_tab;
302  int32_t * Crgtab = upsample->Cr_g_tab;
303  int32_t * Cbgtab = upsample->Cb_g_tab;
305 
306  inptr00 = input_buf[0][in_row_group_ctr*2];
307  inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
308  inptr1 = input_buf[1][in_row_group_ctr];
309  inptr2 = input_buf[2][in_row_group_ctr];
310  outptr0 = output_buf[0];
311  outptr1 = output_buf[1];
312  /* Loop for each group of output pixels */
313  for (col = cinfo->output_width >> 1; col > 0; col--) {
314  /* Do the chroma part of the calculation */
315  cb = GETJSAMPLE(*inptr1++);
316  cr = GETJSAMPLE(*inptr2++);
317  cred = Crrtab[cr];
318  cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
319  cblue = Cbbtab[cb];
320  /* Fetch 4 Y values and emit 4 pixels */
321  y = GETJSAMPLE(*inptr00++);
322  outptr0[RGB_RED] = range_limit[y + cred];
323  outptr0[RGB_GREEN] = range_limit[y + cgreen];
324  outptr0[RGB_BLUE] = range_limit[y + cblue];
325  outptr0 += RGB_PIXELSIZE;
326  y = GETJSAMPLE(*inptr00++);
327  outptr0[RGB_RED] = range_limit[y + cred];
328  outptr0[RGB_GREEN] = range_limit[y + cgreen];
329  outptr0[RGB_BLUE] = range_limit[y + cblue];
330  outptr0 += RGB_PIXELSIZE;
331  y = GETJSAMPLE(*inptr01++);
332  outptr1[RGB_RED] = range_limit[y + cred];
333  outptr1[RGB_GREEN] = range_limit[y + cgreen];
334  outptr1[RGB_BLUE] = range_limit[y + cblue];
335  outptr1 += RGB_PIXELSIZE;
336  y = GETJSAMPLE(*inptr01++);
337  outptr1[RGB_RED] = range_limit[y + cred];
338  outptr1[RGB_GREEN] = range_limit[y + cgreen];
339  outptr1[RGB_BLUE] = range_limit[y + cblue];
340  outptr1 += RGB_PIXELSIZE;
341  }
342  /* If image width is odd, do the last output column separately */
343  if (cinfo->output_width & 1) {
344  cb = GETJSAMPLE(*inptr1);
345  cr = GETJSAMPLE(*inptr2);
346  cred = Crrtab[cr];
347  cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
348  cblue = Cbbtab[cb];
349  y = GETJSAMPLE(*inptr00);
350  outptr0[RGB_RED] = range_limit[y + cred];
351  outptr0[RGB_GREEN] = range_limit[y + cgreen];
352  outptr0[RGB_BLUE] = range_limit[y + cblue];
353  y = GETJSAMPLE(*inptr01);
354  outptr1[RGB_RED] = range_limit[y + cred];
355  outptr1[RGB_GREEN] = range_limit[y + cgreen];
356  outptr1[RGB_BLUE] = range_limit[y + cblue];
357  }
358 }
char JSAMPLE
Definition: jmorecfg.h:64
y
Definition: inputfile.py:6
#define GETJSAMPLE(value)
Definition: jmorecfg.h:68
JDIMENSION output_width
Definition: jpeglib.h:464
int * Cr_r_tab
Definition: jdmerge.cpp:53
#define SHIFT_TEMPS
Definition: jpegint.h:289
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
int32_t * Cb_g_tab
Definition: jdmerge.cpp:56
int * Cb_b_tab
Definition: jdmerge.cpp:54
#define SCALEBITS
Definition: jdmerge.cpp:72
JSAMPLE * sample_range_limit
Definition: jpeglib.h:594
Definition: jdmerge.cpp:44
struct jpeg_upsampler * upsample
Definition: jpeglib.h:632
#define RIGHT_SHIFT(x, shft)
Definition: jpegint.h:290
int32_t * Cr_g_tab
Definition: jdmerge.cpp:55
my_upsampler * my_upsample_ptr
Definition: jdmerge.cpp:70
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
void jinit_merged_upsampler ( j_decompress_ptr  cinfo)
371 {
372  my_upsample_ptr upsample;
373 
374  upsample = (my_upsample_ptr)
375  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
377  cinfo->upsample = (struct jpeg_upsampler *) upsample;
378  upsample->pub.start_pass = start_pass_merged_upsample;
379  upsample->pub.need_context_rows = FALSE;
380 
381  upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
382 
383  if (cinfo->max_v_samp_factor == 2) {
384  upsample->pub.upsample = merged_2v_upsample;
385  upsample->upmethod = h2v2_merged_upsample;
386  /* Allocate a spare row buffer */
387  upsample->spare_row = (JSAMPROW)
388  (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
389  (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
390  } else {
391  upsample->pub.upsample = merged_1v_upsample;
392  upsample->upmethod = h2v1_merged_upsample;
393  /* No spare row needed */
394  upsample->spare_row = NULL;
395  }
396 
397  build_ycc_rgb_table(cinfo);
398 }
char JSAMPLE
Definition: jmorecfg.h:64
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
void *(* alloc_small)()
Definition: jpeglib.h:764
JDIMENSION output_width
Definition: jpeglib.h:464
void(* upmethod)(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
Definition: jdmerge.cpp:50
#define SIZEOF(object)
Definition: jinclude.h:80
Definition: jpegint.h:232
struct jpeg_upsampler pub
Definition: jdmerge.cpp:45
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
#define JPOOL_IMAGE
Definition: jpeglib.h:754
static void h2v2_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
Definition: jdmerge.cpp:288
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
#define FALSE
Definition: jpleph.cpp:69
int out_color_components
Definition: jpeglib.h:466
Definition: jdmerge.cpp:44
int max_v_samp_factor
Definition: jpeglib.h:581
static void merged_1v_upsample(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: jdmerge.cpp:193
JSAMPROW spare_row
Definition: jdmerge.cpp:63
static void h2v1_merged_upsample(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr, JSAMPARRAY output_buf)
Definition: jdmerge.cpp:226
struct jpeg_upsampler * upsample
Definition: jpeglib.h:632
static void build_ycc_rgb_table(j_decompress_ptr cinfo)
Definition: jdmerge.cpp:83
void *(* alloc_large)()
Definition: jpeglib.h:766
boolean need_context_rows
Definition: jpegint.h:242
my_upsampler * my_upsample_ptr
Definition: jdmerge.cpp:70
static void merged_2v_upsample(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: jdmerge.cpp:144
JDIMENSION out_row_width
Definition: jdmerge.cpp:66
static void start_pass_merged_upsample(j_decompress_ptr cinfo)
Definition: jdmerge.cpp:126