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

Classes

struct  my_color_deconverter
 

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_color_deconvertermy_cconvert_ptr
 

Functions

static void build_ycc_rgb_table (j_decompress_ptr cinfo)
 
static void ycc_rgb_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
 
static void null_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
 
static void grayscale_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
 
static void gray_rgb_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
 
static void ycck_cmyk_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
 
static void start_pass_dcolor (j_decompress_ptr cinfo)
 
void jinit_color_deconverter (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
71 {
72  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
73  int i;
74  int32_t x;
76 
77  cconvert->Cr_r_tab = (int *)
78  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
79  (MAXJSAMPLE+1) * SIZEOF(int));
80  cconvert->Cb_b_tab = (int *)
81  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
82  (MAXJSAMPLE+1) * SIZEOF(int));
83  cconvert->Cr_g_tab = (int32_t *)
84  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
85  (MAXJSAMPLE+1) * SIZEOF(int32_t));
86  cconvert->Cb_g_tab = (int32_t *)
87  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
88  (MAXJSAMPLE+1) * SIZEOF(int32_t));
89 
90  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
91  /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
92  /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
93  /* Cr=>R value is nearest int to 1.40200 * x */
94  cconvert->Cr_r_tab[i] = (int)
95  RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
96  /* Cb=>B value is nearest int to 1.77200 * x */
97  cconvert->Cb_b_tab[i] = (int)
98  RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
99  /* Cr=>G value is scaled-up -0.71414 * x */
100  cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
101  /* Cb=>G value is scaled-up -0.34414 * x */
102  /* We also add in ONE_HALF so that need not do it in inner loop */
103  cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
104  }
105 }
#define CENTERJSAMPLE
Definition: jmorecfg.h:74
#define SCALEBITS
Definition: jdcolor.cpp:60
Definition: jccolor.cpp:18
int i
Definition: rw_test.cpp:37
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
void *(* alloc_small)()
Definition: jpeglib.h:764
Definition: jpeglib.h:258
#define SIZEOF(object)
Definition: jinclude.h:80
#define MAXJSAMPLE
Definition: jmorecfg.h:73
#define SHIFT_TEMPS
Definition: jpegint.h:289
#define JPOOL_IMAGE
Definition: jpeglib.h:754
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
my_color_deconverter * my_cconvert_ptr
Definition: jdcolor.cpp:28
#define FIX(x)
Definition: jdcolor.cpp:62
x
Definition: inputfile.py:6
struct jpeg_color_deconverter * cconvert
Definition: jpeglib.h:633
#define ONE_HALF
Definition: jdcolor.cpp:61
#define RIGHT_SHIFT(x, shft)
Definition: jpegint.h:290
static void ycc_rgb_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)
static
123 {
124  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
125  register int y, cb, cr;
126  register JSAMPROW outptr;
127  register JSAMPROW inptr0, inptr1, inptr2;
128  register JDIMENSION col;
130  /* copy these pointers into registers if possible */
131  register JSAMPLE * range_limit = cinfo->sample_range_limit;
132  register int * Crrtab = cconvert->Cr_r_tab;
133  register int * Cbbtab = cconvert->Cb_b_tab;
134  register int32_t * Crgtab = cconvert->Cr_g_tab;
135  register int32_t * Cbgtab = cconvert->Cb_g_tab;
137 
138  while (--num_rows >= 0) {
139  inptr0 = input_buf[0][input_row];
140  inptr1 = input_buf[1][input_row];
141  inptr2 = input_buf[2][input_row];
142  input_row++;
143  outptr = *output_buf++;
144  for (col = 0; col < num_cols; col++) {
145  y = GETJSAMPLE(inptr0[col]);
146  cb = GETJSAMPLE(inptr1[col]);
147  cr = GETJSAMPLE(inptr2[col]);
148  /* Range-limiting is essential due to noise introduced by DCT losses. */
149  outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
150  outptr[RGB_GREEN] = range_limit[y +
151  ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
152  SCALEBITS))];
153  outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
154  outptr += RGB_PIXELSIZE;
155  }
156  }
157 }
char JSAMPLE
Definition: jmorecfg.h:64
#define SCALEBITS
Definition: jdcolor.cpp:60
y
Definition: inputfile.py:6
Definition: jccolor.cpp:18
#define GETJSAMPLE(value)
Definition: jmorecfg.h:68
JDIMENSION output_width
Definition: jpeglib.h:464
#define SHIFT_TEMPS
Definition: jpegint.h:289
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
JSAMPLE * sample_range_limit
Definition: jpeglib.h:594
my_color_deconverter * my_cconvert_ptr
Definition: jdcolor.cpp:28
int JSAMPARRAY int int num_rows
Definition: jpegint.h:373
int JSAMPARRAY int int JDIMENSION num_cols
Definition: jpegint.h:373
struct jpeg_color_deconverter * cconvert
Definition: jpeglib.h:633
#define RIGHT_SHIFT(x, shft)
Definition: jpegint.h:290
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
static void null_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)
static
172 {
173  register JSAMPROW inptr, outptr;
174  register JDIMENSION count;
175  register int num_components = cinfo->num_components;
177  int ci;
178 
179  while (--num_rows >= 0) {
180  for (ci = 0; ci < num_components; ci++) {
181  inptr = input_buf[ci][input_row];
182  outptr = output_buf[0] + ci;
183  for (count = num_cols; count > 0; count--) {
184  *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
185  outptr += num_components;
186  }
187  }
188  input_row++;
189  output_buf++;
190  }
191 }
int num_components
Definition: jpeglib.h:427
int count
Definition: rw_test.cpp:36
JDIMENSION output_width
Definition: jpeglib.h:464
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
int JSAMPARRAY int int num_rows
Definition: jpegint.h:373
int JSAMPARRAY int int JDIMENSION num_cols
Definition: jpegint.h:373
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
static void grayscale_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)
static
204 {
205  jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
206  num_rows, cinfo->output_width);
207 }
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 output_width
Definition: jpeglib.h:464
int JSAMPARRAY int int num_rows
Definition: jpegint.h:373
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
static void gray_rgb_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)
static
220 {
221  register JSAMPROW inptr, outptr;
222  register JDIMENSION col;
224 
225  while (--num_rows >= 0) {
226  inptr = input_buf[0][input_row++];
227  outptr = *output_buf++;
228  for (col = 0; col < num_cols; col++) {
229  /* We can dispense with GETJSAMPLE() here */
230  outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
231  outptr += RGB_PIXELSIZE;
232  }
233  }
234 }
JDIMENSION output_width
Definition: jpeglib.h:464
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
int JSAMPARRAY int int num_rows
Definition: jpegint.h:373
int JSAMPARRAY int int JDIMENSION num_cols
Definition: jpegint.h:373
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
static void ycck_cmyk_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)
static
248 {
249  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
250  register int y, cb, cr;
251  register JSAMPROW outptr;
252  register JSAMPROW inptr0, inptr1, inptr2, inptr3;
253  register JDIMENSION col;
255  /* copy these pointers into registers if possible */
256  register JSAMPLE * range_limit = cinfo->sample_range_limit;
257  register int * Crrtab = cconvert->Cr_r_tab;
258  register int * Cbbtab = cconvert->Cb_b_tab;
259  register int32_t * Crgtab = cconvert->Cr_g_tab;
260  register int32_t * Cbgtab = cconvert->Cb_g_tab;
262 
263  while (--num_rows >= 0) {
264  inptr0 = input_buf[0][input_row];
265  inptr1 = input_buf[1][input_row];
266  inptr2 = input_buf[2][input_row];
267  inptr3 = input_buf[3][input_row];
268  input_row++;
269  outptr = *output_buf++;
270  for (col = 0; col < num_cols; col++) {
271  y = GETJSAMPLE(inptr0[col]);
272  cb = GETJSAMPLE(inptr1[col]);
273  cr = GETJSAMPLE(inptr2[col]);
274  /* Range-limiting is essential due to noise introduced by DCT losses. */
275  outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
276  outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
277  ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
278  SCALEBITS)))];
279  outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
280  /* K passes through unchanged */
281  outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
282  outptr += 4;
283  }
284  }
285 }
char JSAMPLE
Definition: jmorecfg.h:64
#define SCALEBITS
Definition: jdcolor.cpp:60
y
Definition: inputfile.py:6
Definition: jccolor.cpp:18
#define GETJSAMPLE(value)
Definition: jmorecfg.h:68
JDIMENSION output_width
Definition: jpeglib.h:464
#define MAXJSAMPLE
Definition: jmorecfg.h:73
#define SHIFT_TEMPS
Definition: jpegint.h:289
JSAMPLE * JSAMPROW
Definition: jpeglib.h:71
JSAMPLE * sample_range_limit
Definition: jpeglib.h:594
my_color_deconverter * my_cconvert_ptr
Definition: jdcolor.cpp:28
int JSAMPARRAY int int num_rows
Definition: jpegint.h:373
int JSAMPARRAY int int JDIMENSION num_cols
Definition: jpegint.h:373
struct jpeg_color_deconverter * cconvert
Definition: jpeglib.h:633
#define RIGHT_SHIFT(x, shft)
Definition: jpegint.h:290
jpeg_component_info JCOEFPTR JSAMPARRAY output_buf
Definition: jdct.h:102
unsigned int JDIMENSION
Definition: jmorecfg.h:171
static void start_pass_dcolor ( j_decompress_ptr  cinfo)
static
294 {
295  /* no work needed */
296 }
void jinit_color_deconverter ( j_decompress_ptr  cinfo)
305 {
306  my_cconvert_ptr cconvert;
307  int ci;
308 
309  cconvert = (my_cconvert_ptr)
310  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
312  cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
313  cconvert->pub.start_pass = start_pass_dcolor;
314 
315  /* Make sure num_components agrees with jpeg_color_space */
316  switch (cinfo->jpeg_color_space) {
317  case JCS_GRAYSCALE:
318  if (cinfo->num_components != 1)
320  break;
321 
322  case JCS_RGB:
323  case JCS_YCbCr:
324  if (cinfo->num_components != 3)
326  break;
327 
328  case JCS_CMYK:
329  case JCS_YCCK:
330  if (cinfo->num_components != 4)
332  break;
333 
334  default: /* JCS_UNKNOWN can be anything */
335  if (cinfo->num_components < 1)
337  break;
338  }
339 
340  /* Set out_color_components and conversion method based on requested space.
341  * Also clear the component_needed flags for any unused components,
342  * so that earlier pipeline stages can avoid useless computation.
343  */
344 
345  switch (cinfo->out_color_space) {
346  case JCS_GRAYSCALE:
347  cinfo->out_color_components = 1;
348  if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
349  cinfo->jpeg_color_space == JCS_YCbCr) {
350  cconvert->pub.color_convert = grayscale_convert;
351  /* For color->grayscale conversion, only the Y (0) component is needed */
352  for (ci = 1; ci < cinfo->num_components; ci++)
353  cinfo->comp_info[ci].component_needed = FALSE;
354  } else
356  break;
357 
358  case JCS_RGB:
359  cinfo->out_color_components = RGB_PIXELSIZE;
360  if (cinfo->jpeg_color_space == JCS_YCbCr) {
361  cconvert->pub.color_convert = ycc_rgb_convert;
362  build_ycc_rgb_table(cinfo);
363  } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
364  cconvert->pub.color_convert = gray_rgb_convert;
365  } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
366  cconvert->pub.color_convert = null_convert;
367  } else
369  break;
370 
371  case JCS_CMYK:
372  cinfo->out_color_components = 4;
373  if (cinfo->jpeg_color_space == JCS_YCCK) {
374  cconvert->pub.color_convert = ycck_cmyk_convert;
375  build_ycc_rgb_table(cinfo);
376  } else if (cinfo->jpeg_color_space == JCS_CMYK) {
377  cconvert->pub.color_convert = null_convert;
378  } else
380  break;
381 
382  default:
383  /* Permit null conversion to same output space */
384  if (cinfo->out_color_space == cinfo->jpeg_color_space) {
385  cinfo->out_color_components = cinfo->num_components;
386  cconvert->pub.color_convert = null_convert;
387  } else /* unsupported non-null conversion */
389  break;
390  }
391 
392  if (cinfo->quantize_colors)
393  cinfo->output_components = 1; /* single colormapped output component */
394  else
395  cinfo->output_components = cinfo->out_color_components;
396 }
Definition: jpeglib.h:217
Definition: jdcolor.cpp:18
int num_components
Definition: jpeglib.h:427
static void start_pass_dcolor(j_decompress_ptr cinfo)
Definition: jdcolor.cpp:293
Definition: jerror.h:73
static void null_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
Definition: jdcolor.cpp:169
Definition: jccolor.cpp:18
static void ycc_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
Definition: jdcolor.cpp:120
jpeg_component_info * comp_info
Definition: jpeglib.h:540
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
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
#define SIZEOF(object)
Definition: jinclude.h:80
boolean component_needed
Definition: jpeglib.h:165
static void build_ycc_rgb_table(j_decompress_ptr cinfo)
Definition: jdcolor.cpp:70
Definition: jerror.h:52
#define JPOOL_IMAGE
Definition: jpeglib.h:754
J_COLOR_SPACE out_color_space
Definition: jpeglib.h:435
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
#define FALSE
Definition: jpleph.cpp:69
Definition: jpegint.h:246
Definition: jpeglib.h:214
Definition: jpeglib.h:213
my_color_deconverter * my_cconvert_ptr
Definition: jdcolor.cpp:28
int output_components
Definition: jpeglib.h:467
int out_color_components
Definition: jpeglib.h:466
struct jpeg_color_converter pub
Definition: jccolor.cpp:19
struct jpeg_color_deconverter * cconvert
Definition: jpeglib.h:633
static void grayscale_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
Definition: jdcolor.cpp:201
Definition: jpeglib.h:215
static void ycck_cmyk_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
Definition: jdcolor.cpp:245
static void gray_rgb_convert(j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
Definition: jdcolor.cpp:217
Definition: jpeglib.h:216
J_COLOR_SPACE jpeg_color_space
Definition: jpeglib.h:428