jcparam.c
/*
 * Set the JPEG colorspace, and choose colorspace-dependent default values.
 */
Set the JPEG colorspace, and choose colorspace-dependent default values.
Set the JPEG colorspace and choose colorspace - dependent default values .
GLOBAL(void)
jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
{
  jpeg_component_info *compptr;
  int ci;
#define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl)  \
  (compptr = &cinfo->comp_info[index], \
   compptr->component_id = (id), \
   compptr->h_samp_factor = (hsamp), \
   compptr->v_samp_factor = (vsamp), \
   compptr->quant_tbl_no = (quant), \
   compptr->dc_tbl_no = (dctbl), \
   compptr->ac_tbl_no = (actbl) )
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  cinfo->jpeg_color_space = colorspace;
  cinfo->write_JFIF_header = FALSE; 
  cinfo->write_Adobe_marker = FALSE; 
  switch (colorspace) {
  case JCS_GRAYSCALE:
    cinfo->write_JFIF_header = TRUE; 
    cinfo->num_components = 1;
    SET_COMP(0, 1, 1,1, 0, 0,0);
    break;
  case JCS_RGB:
    cinfo->write_Adobe_marker = TRUE; 
    cinfo->num_components = 3;
    SET_COMP(0, 0x52 , 1,1, 0, 0,0);
    SET_COMP(1, 0x47 , 1,1, 0, 0,0);
    SET_COMP(2, 0x42 , 1,1, 0, 0,0);
    break;
  case JCS_YCbCr:
    cinfo->write_JFIF_header = TRUE; 
    cinfo->num_components = 3;
    SET_COMP(0, 1, 2,2, 0, 0,0);
    SET_COMP(1, 2, 1,1, 1, 1,1);
    SET_COMP(2, 3, 1,1, 1, 1,1);
    break;
  case JCS_CMYK:
    cinfo->write_Adobe_marker = TRUE; 
    cinfo->num_components = 4;
    SET_COMP(0, 0x43 , 1,1, 0, 0,0);
    SET_COMP(1, 0x4D , 1,1, 0, 0,0);
    SET_COMP(2, 0x59 , 1,1, 0, 0,0);
    SET_COMP(3, 0x4B , 1,1, 0, 0,0);
    break;
  case JCS_YCCK:
    cinfo->write_Adobe_marker = TRUE; 
    cinfo->num_components = 4;
    SET_COMP(0, 1, 2,2, 0, 0,0);
    SET_COMP(1, 2, 1,1, 1, 1,1);
    SET_COMP(2, 3, 1,1, 1, 1,1);
    SET_COMP(3, 4, 2,2, 0, 0,0);
    break;
  case JCS_UNKNOWN:
    cinfo->num_components = cinfo->input_components;
    if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
               MAX_COMPONENTS);
    for (ci = 0; ci < cinfo->num_components; ci++) {
      SET_COMP(ci, ci, 1,1, 0, 0,0);
    }
    break;
  default:
    ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  }
}
GLOBAL ( void ) jpeg_set_colorspace ( j_compress_ptr cinfo , J_COLOR_SPACE colorspace ) { jpeg_component_info * compptr ; int ci ; #define SET_COMP ( index , id , hsamp , vsamp , quant , dctbl , actbl )   \
  (compptr = &cinfo->comp_info[index], \
   compptr->component_id = (id), \
   compptr->h_samp_factor = (hsamp), \
   compptr->v_samp_factor = (vsamp), \
   compptr->quant_tbl_no = (quant), \
   compptr->dc_tbl_no = (dctbl), \
   compptr->ac_tbl_no = (actbl) ) if ( cinfo -> global_state != CSTATE_START ) ERREXIT1 ( cinfo , JERR_BAD_STATE , cinfo -> global_state ) ; cinfo -> jpeg_color_space = colorspace ; cinfo -> write_JFIF_header = FALSE ; cinfo -> write_Adobe_marker = FALSE ; switch ( colorspace ) { case JCS_GRAYSCALE : cinfo -> write_JFIF_header = TRUE ; cinfo -> num_components = 1 ; SET_COMP ( 0 , 1 , 1 , 1 , 0 , 0 , 0 ) ; break ; case JCS_RGB : cinfo -> write_Adobe_marker = TRUE ; cinfo -> num_components = 3 ; SET_COMP ( 0 , 0x52 , 1 , 1 , 0 , 0 , 0 ) ; SET_COMP ( 1 , 0x47 , 1 , 1 , 0 , 0 , 0 ) ; SET_COMP ( 2 , 0x42 , 1 , 1 , 0 , 0 , 0 ) ; break ; case JCS_YCbCr : cinfo -> write_JFIF_header = TRUE ; cinfo -> num_components = 3 ; SET_COMP ( 0 , 1 , 2 , 2 , 0 , 0 , 0 ) ; SET_COMP ( 1 , 2 , 1 , 1 , 1 , 1 , 1 ) ; SET_COMP ( 2 , 3 , 1 , 1 , 1 , 1 , 1 ) ; break ; case JCS_CMYK : cinfo -> write_Adobe_marker = TRUE ; cinfo -> num_components = 4 ; SET_COMP ( 0 , 0x43 , 1 , 1 , 0 , 0 , 0 ) ; SET_COMP ( 1 , 0x4D , 1 , 1 , 0 , 0 , 0 ) ; SET_COMP ( 2 , 0x59 , 1 , 1 , 0 , 0 , 0 ) ; SET_COMP ( 3 , 0x4B , 1 , 1 , 0 , 0 , 0 ) ; break ; case JCS_YCCK : cinfo -> write_Adobe_marker = TRUE ; cinfo -> num_components = 4 ; SET_COMP ( 0 , 1 , 2 , 2 , 0 , 0 , 0 ) ; SET_COMP ( 1 , 2 , 1 , 1 , 1 , 1 , 1 ) ; SET_COMP ( 2 , 3 , 1 , 1 , 1 , 1 , 1 ) ; SET_COMP ( 3 , 4 , 2 , 2 , 0 , 0 , 0 ) ; break ; case JCS_UNKNOWN : cinfo -> num_components = cinfo -> input_components ; if ( cinfo -> num_components < 1 || cinfo -> num_components > MAX_COMPONENTS ) ERREXIT2 ( cinfo , JERR_COMPONENT_COUNT , cinfo -> num_components , MAX_COMPONENTS ) ; for ( ci = 0 ; ci < cinfo -> num_components ; ci ++ ) { SET_COMP ( ci , ci , 1 , 1 , 0 , 0 , 0 ) ; } break ; default : ERREXIT ( cinfo , JERR_BAD_J_COLORSPACE ) ; } }
Set the JPEG colorspace, and choose colorspace-dependent default values.
Set the JPEG colorspace and choose colorspace - dependent default values .
/* Safety check to ensure start_compress not called yet. */ /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
   * tables 1 for chrominance components.
   */ /* No marker for non-JFIF colorspaces */ /* write no Adobe marker by default */ /* Write a JFIF marker */ /* JFIF specifies component ID 1 */ /* write Adobe marker to flag RGB */ /* 'R' */ /* 'G' */ /* 'B' */ /* Write a JFIF marker */ /* JFIF specifies component IDs 1,2,3 */ /* We default to 2x2 subsamples of chrominance */ /* write Adobe marker to flag CMYK */ /* 'C' */ /* 'M' */ /* 'Y' */ /* 'K' */ /* write Adobe marker to flag YCCK */