jdcolor.c File Reference

#include "jinclude.h"
#include "jpeglib.h"

Go to the source code of this file.

Data Structures

struct  my_color_deconverter

Defines

#define FIX(x)   ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
#define JPEG_INTERNALS
#define ONE_HALF   ((INT32) 1 << (SCALEBITS-1))
#define SCALEBITS   16

Typedefs

typedef my_color_deconvertermy_cconvert_ptr

Functions

 build_ycc_rgb_table (j_decompress_ptr cinfo)
 gray_rgb_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
 grayscale_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
 jinit_color_deconverter (j_decompress_ptr cinfo)
 null_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
 start_pass_dcolor (j_decompress_ptr cinfo)
 ycc_rgb565_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
 ycc_rgb_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)
 ycck_cmyk_convert (j_decompress_ptr cinfo, JSAMPIMAGE input_buf, JDIMENSION input_row, JSAMPARRAY output_buf, int num_rows)

Variables

unsigned short int * jpeg_out_buffer_pos


Define Documentation

#define FIX (  )     ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))

Definition at line 62 of file jdcolor.c.

#define JPEG_INTERNALS

Definition at line 11 of file jdcolor.c.

#define ONE_HALF   ((INT32) 1 << (SCALEBITS-1))

Definition at line 61 of file jdcolor.c.

#define SCALEBITS   16

Definition at line 60 of file jdcolor.c.


Typedef Documentation

Definition at line 28 of file jdcolor.c.


Function Documentation

build_ycc_rgb_table ( j_decompress_ptr  cinfo  ) 

Definition at line 70 of file jdcolor.c.

References CENTERJSAMPLE, FIX, JPOOL_IMAGE, MAXJSAMPLE, ONE_HALF, RIGHT_SHIFT, SCALEBITS, SHIFT_TEMPS, and SIZEOF.

Referenced by jinit_color_deconverter(), and jinit_merged_upsampler().

00071 {
00072   my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
00073   int i;
00074   INT32 x;
00075   SHIFT_TEMPS
00076 
00077   cconvert->Cr_r_tab = (int *)
00078     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00079                 (MAXJSAMPLE+1) * SIZEOF(int));
00080   cconvert->Cb_b_tab = (int *)
00081     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00082                 (MAXJSAMPLE+1) * SIZEOF(int));
00083   cconvert->Cr_g_tab = (INT32 *)
00084     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00085                 (MAXJSAMPLE+1) * SIZEOF(INT32));
00086   cconvert->Cb_g_tab = (INT32 *)
00087     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00088                 (MAXJSAMPLE+1) * SIZEOF(INT32));
00089 
00090   for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
00091     /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
00092     /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
00093     /* Cr=>R value is nearest int to 1.40200 * x */
00094     cconvert->Cr_r_tab[i] = (int)
00095             RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
00096     /* Cb=>B value is nearest int to 1.77200 * x */
00097     cconvert->Cb_b_tab[i] = (int)
00098             RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
00099     /* Cr=>G value is scaled-up -0.71414 * x */
00100     cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
00101     /* Cb=>G value is scaled-up -0.34414 * x */
00102     /* We also add in ONE_HALF so that need not do it in inner loop */
00103     cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
00104   }
00105 }

gray_rgb_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)

Definition at line 277 of file jdcolor.c.

References num_cols.

Referenced by jinit_color_deconverter().

00280 {
00281   register JSAMPROW inptr, outptr;
00282   register JDIMENSION col;
00283   JDIMENSION num_cols = cinfo->output_width;
00284 
00285   while (--num_rows >= 0) {
00286     inptr = input_buf[0][input_row++];
00287     outptr = *output_buf++;
00288     for (col = 0; col < num_cols; col++) {
00289       /* We can dispense with GETJSAMPLE() here */
00290       outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
00291       outptr += RGB_PIXELSIZE;
00292     }
00293   }
00294 }

grayscale_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)

Definition at line 261 of file jdcolor.c.

References jcopy_sample_rows().

00264 {
00265   jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
00266             num_rows, cinfo->output_width);
00267 }

jinit_color_deconverter ( j_decompress_ptr  cinfo  ) 

Definition at line 364 of file jdcolor.c.

References build_ycc_rgb_table(), ERREXIT, FALSE, gray_rgb_convert(), grayscale_convert(), JCS_CMYK, JCS_GRAYSCALE, JCS_RGB, JCS_RGB565, JCS_YCbCr, JCS_YCCK, JPOOL_IMAGE, null_convert(), my_color_converter::pub, SIZEOF, start_pass_dcolor(), ycc_rgb565_convert(), ycc_rgb_convert(), and ycck_cmyk_convert().

Referenced by master_selection().

00365 {
00366   my_cconvert_ptr cconvert;
00367   int ci;
00368 
00369   cconvert = (my_cconvert_ptr)
00370     (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00371                 SIZEOF(my_color_deconverter));
00372   cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
00373   cconvert->pub.start_pass = start_pass_dcolor;
00374 
00375   /* Make sure num_components agrees with jpeg_color_space */
00376   switch (cinfo->jpeg_color_space) {
00377   case JCS_GRAYSCALE:
00378     if (cinfo->num_components != 1)
00379       ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
00380     break;
00381 
00382   case JCS_RGB:
00383   case JCS_RGB565:
00384   case JCS_YCbCr:
00385     if (cinfo->num_components != 3)
00386       ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
00387     break;
00388 
00389   case JCS_CMYK:
00390   case JCS_YCCK:
00391     if (cinfo->num_components != 4)
00392       ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
00393     break;
00394 
00395   default:          /* JCS_UNKNOWN can be anything */
00396     if (cinfo->num_components < 1)
00397       ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
00398     break;
00399   }
00400 
00401   /* Set out_color_components and conversion method based on requested space.
00402    * Also clear the component_needed flags for any unused components,
00403    * so that earlier pipeline stages can avoid useless computation.
00404    */
00405 
00406   switch (cinfo->out_color_space) {
00407   case JCS_GRAYSCALE:
00408     cinfo->out_color_components = 1;
00409     if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
00410     cinfo->jpeg_color_space == JCS_YCbCr) {
00411       cconvert->pub.color_convert = grayscale_convert;
00412       /* For color->grayscale conversion, only the Y (0) component is needed */
00413       for (ci = 1; ci < cinfo->num_components; ci++)
00414     cinfo->comp_info[ci].component_needed = FALSE;
00415     } else
00416       ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
00417     break;
00418 
00419   case JCS_RGB:
00420     cinfo->out_color_components = RGB_PIXELSIZE;
00421     if (cinfo->jpeg_color_space == JCS_YCbCr) {
00422       cconvert->pub.color_convert = ycc_rgb_convert;
00423       build_ycc_rgb_table(cinfo);
00424     } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
00425       cconvert->pub.color_convert = gray_rgb_convert;
00426     } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
00427       cconvert->pub.color_convert = null_convert;
00428     } else
00429       ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
00430     break;
00431   
00432   case JCS_RGB565:
00433       cinfo->out_color_components = RGB_PIXELSIZE;
00434       if(cinfo->jpeg_color_space == JCS_YCbCr)
00435       {
00436           cconvert->pub.color_convert = ycc_rgb565_convert;
00437           build_ycc_rgb_table(cinfo);
00438       }
00439       else
00440           ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
00441       break;
00442       
00443   case JCS_CMYK:
00444     cinfo->out_color_components = 4;
00445     if (cinfo->jpeg_color_space == JCS_YCCK) {
00446       cconvert->pub.color_convert = ycck_cmyk_convert;
00447       build_ycc_rgb_table(cinfo);
00448     } else if (cinfo->jpeg_color_space == JCS_CMYK) {
00449       cconvert->pub.color_convert = null_convert;
00450     } else
00451       ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
00452     break;
00453 
00454   default:
00455     /* Permit null conversion to same output space */
00456     if (cinfo->out_color_space == cinfo->jpeg_color_space) {
00457       cinfo->out_color_components = cinfo->num_components;
00458       cconvert->pub.color_convert = null_convert;
00459     } else          /* unsupported non-null conversion */
00460       ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
00461     break;
00462   }
00463 
00464   if (cinfo->quantize_colors)
00465     cinfo->output_components = 1; /* single colormapped output component */
00466   else
00467     cinfo->output_components = cinfo->out_color_components;
00468 }

null_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)

Definition at line 229 of file jdcolor.c.

References num_cols.

00232 {
00233   register JSAMPROW inptr, outptr;
00234   register JDIMENSION count;
00235   register int num_components = cinfo->num_components;
00236   JDIMENSION num_cols = cinfo->output_width;
00237   int ci;
00238 
00239   while (--num_rows >= 0) {
00240     for (ci = 0; ci < num_components; ci++) {
00241       inptr = input_buf[ci][input_row];
00242       outptr = output_buf[0] + ci;
00243       for (count = num_cols; count > 0; count--) {
00244     *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
00245     outptr += num_components;
00246       }
00247     }
00248     input_row++;
00249     output_buf++;
00250   }
00251 }

start_pass_dcolor ( j_decompress_ptr  cinfo  ) 

Definition at line 353 of file jdcolor.c.

Referenced by jinit_color_deconverter().

00354 {
00355   /* no work needed */
00356 }

ycc_rgb565_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)

Definition at line 172 of file jdcolor.c.

References GETJSAMPLE, jpeg_out_buffer_pos, num_cols, RIGHT_SHIFT, SCALEBITS, and SHIFT_TEMPS.

Referenced by jinit_color_deconverter().

00175 {
00176   my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
00177   register int y, cb, cr;
00178   //register unsigned short *outptr;
00179   register JSAMPROW inptr0, inptr1, inptr2;
00180   register JDIMENSION col;
00181   JDIMENSION num_cols = cinfo->output_width;
00182   /* copy these pointers into registers if possible */
00183   register JSAMPLE * range_limit = cinfo->sample_range_limit;
00184   register int * Crrtab = cconvert->Cr_r_tab;
00185   register int * Cbbtab = cconvert->Cb_b_tab;
00186   register INT32 * Crgtab = cconvert->Cr_g_tab;
00187   register INT32 * Cbgtab = cconvert->Cb_g_tab;
00188   SHIFT_TEMPS
00189   JSAMPLE red, green, blue;
00190 
00191   while (--num_rows >= 0) {
00192     inptr0 = input_buf[0][input_row];
00193     inptr1 = input_buf[1][input_row];
00194     inptr2 = input_buf[2][input_row];
00195     input_row++;
00196 
00197     for (col = 0; col < num_cols; col++) {
00198       y  = GETJSAMPLE(inptr0[col]);
00199       cb = GETJSAMPLE(inptr1[col]);
00200       cr = GETJSAMPLE(inptr2[col]);
00201       
00202       red = range_limit[y + Crrtab[cr]];
00203       green = range_limit[y + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS))];
00204       blue = range_limit[y + Cbbtab[cb]];
00205     *jpeg_out_buffer_pos = ((red >> 3) & 0x1F) << 11 
00206         | (((green >> 2) & 0x3F) << 5)
00207         | ((blue >> 3) & 0x1F);
00208 
00209       /* Range-limiting is essential due to noise introduced by DCT losses. */
00210       /*
00211       *jpeg_out_buffer_pos =   ((((range_limit[y + Crrtab[cr]]) >> 3) & 0x1F) << 11)
00212         | ((((range_limit[y + ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS))]) >> 2) & 0x3F) << 5)
00213         | (((range_limit[y + Cbbtab[cb]]) >> 3) & 0x1F);
00214     */
00215       jpeg_out_buffer_pos++;
00216     }
00217   }
00218 }

ycc_rgb_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)

Definition at line 120 of file jdcolor.c.

References GETJSAMPLE, num_cols, RIGHT_SHIFT, SCALEBITS, and SHIFT_TEMPS.

Referenced by jinit_color_deconverter().

00123 {
00124   my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
00125   register int y, cb, cr;
00126   register JSAMPROW outptr;
00127   register JSAMPROW inptr0, inptr1, inptr2;
00128   register JDIMENSION col;
00129   JDIMENSION num_cols = cinfo->output_width;
00130   /* copy these pointers into registers if possible */
00131   register JSAMPLE * range_limit = cinfo->sample_range_limit;
00132   register int * Crrtab = cconvert->Cr_r_tab;
00133   register int * Cbbtab = cconvert->Cb_b_tab;
00134   register INT32 * Crgtab = cconvert->Cr_g_tab;
00135   register INT32 * Cbgtab = cconvert->Cb_g_tab;
00136   SHIFT_TEMPS
00137 
00138   while (--num_rows >= 0) {
00139     inptr0 = input_buf[0][input_row];
00140     inptr1 = input_buf[1][input_row];
00141     inptr2 = input_buf[2][input_row];
00142     input_row++;
00143     outptr = *output_buf++;
00144     for (col = 0; col < num_cols; col++) {
00145       y  = GETJSAMPLE(inptr0[col]);
00146       cb = GETJSAMPLE(inptr1[col]);
00147       cr = GETJSAMPLE(inptr2[col]);
00148       /* Range-limiting is essential due to noise introduced by DCT losses. */
00149       outptr[RGB_RED] =   range_limit[y + Crrtab[cr]];
00150       outptr[RGB_GREEN] = range_limit[y +
00151                   ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
00152                          SCALEBITS))];
00153       outptr[RGB_BLUE] =  range_limit[y + Cbbtab[cb]];
00154       outptr += RGB_PIXELSIZE;
00155     }
00156   }
00157 }

ycck_cmyk_convert ( j_decompress_ptr  cinfo,
JSAMPIMAGE  input_buf,
JDIMENSION  input_row,
JSAMPARRAY  output_buf,
int  num_rows 
)

Definition at line 305 of file jdcolor.c.

References GETJSAMPLE, MAXJSAMPLE, num_cols, RIGHT_SHIFT, SCALEBITS, and SHIFT_TEMPS.

Referenced by jinit_color_deconverter().

00308 {
00309   my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
00310   register int y, cb, cr;
00311   register JSAMPROW outptr;
00312   register JSAMPROW inptr0, inptr1, inptr2, inptr3;
00313   register JDIMENSION col;
00314   JDIMENSION num_cols = cinfo->output_width;
00315   /* copy these pointers into registers if possible */
00316   register JSAMPLE * range_limit = cinfo->sample_range_limit;
00317   register int * Crrtab = cconvert->Cr_r_tab;
00318   register int * Cbbtab = cconvert->Cb_b_tab;
00319   register INT32 * Crgtab = cconvert->Cr_g_tab;
00320   register INT32 * Cbgtab = cconvert->Cb_g_tab;
00321   SHIFT_TEMPS
00322 
00323   while (--num_rows >= 0) {
00324     inptr0 = input_buf[0][input_row];
00325     inptr1 = input_buf[1][input_row];
00326     inptr2 = input_buf[2][input_row];
00327     inptr3 = input_buf[3][input_row];
00328     input_row++;
00329     outptr = *output_buf++;
00330     for (col = 0; col < num_cols; col++) {
00331       y  = GETJSAMPLE(inptr0[col]);
00332       cb = GETJSAMPLE(inptr1[col]);
00333       cr = GETJSAMPLE(inptr2[col]);
00334       /* Range-limiting is essential due to noise introduced by DCT losses. */
00335       outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])];   /* red */
00336       outptr[1] = range_limit[MAXJSAMPLE - (y +         /* green */
00337                   ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
00338                          SCALEBITS)))];
00339       outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])];   /* blue */
00340       /* K passes through unchanged */
00341       outptr[3] = inptr3[col];  /* don't need GETJSAMPLE here */
00342       outptr += 4;
00343     }
00344   }
00345 }


Variable Documentation

unsigned short int* jpeg_out_buffer_pos

Definition at line 274 of file EXAMPLE/jdatasrc.c.

Referenced by jpeg_lib_decode(), and ycc_rgb565_convert().


Generated on Fri Feb 19 02:31:03 2010 for AVR32 - IJG JPEG Decoder Example by  doxygen 1.5.5