コード例 #1
0
ファイル: encode.c プロジェクト: captain168/STM32F407_GDUI
//设置默认参数
void jpeg_set_default(jpeg_compress_info *cinfo) 
{
  	cinfo->precision=8;//采样精度8  
  	cinfo->in_color_space=JCS_RGB;//色彩空间
  	cinfo->quality=0.2f;//图像质量,值越小质量越好 
  	//初始化元件颜色为YCbCr彩色  
  	cinfo->num_comp=3;//元件数量为3
  	SET_COMP(cinfo->comp[0],1,2,2,0,0,0);//
  	SET_COMP(cinfo->comp[1],2,1,1,1,1,1);//
  	SET_COMP(cinfo->comp[2],3,1,1,1,1,1);//  	
  	jint_std_quant_tables(cinfo);//设置标准量化表  	
  	jint_std_huff_tables(cinfo);//设置标准huffman表  
  	jpeg_calc_value(cinfo);//其它变量
}
コード例 #2
0
ファイル: jcparam.c プロジェクト: wongm168/PegDF
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) )

  /* Safety check to ensure start_compress not called yet. */
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

  /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
   * tables 1 for chrominance components.
   */

  cinfo->jpeg_color_space = colorspace;

  cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */

  switch (colorspace) {
  case JCS_GRAYSCALE:
    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
    cinfo->num_components = 1;
    /* JFIF specifies component ID 1 */
    SET_COMP(0, 1, 1,1, 0, 0,0);
    break;
  case JCS_RGB:
    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
    cinfo->num_components = 3;
    SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
    SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
    SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
    break;
  case JCS_YCbCr:
    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
    cinfo->num_components = 3;
    /* JFIF specifies component IDs 1,2,3 */
    /* We default to 2x2 subsamples of chrominance */
    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; /* write Adobe marker to flag CMYK */
    cinfo->num_components = 4;
    SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
    SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
    SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
    SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
    break;
  case JCS_YCCK:
    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
    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);
  }
}
コード例 #3
0
ファイル: pxvendor.c プロジェクト: hackqiang/gs
/* TODO: the whole purpose of fastforward_jpeg_stream_state(),
   (as well as add_huff_table()/add_huff_tables() above), is to wind
   the state of the jpeg stream forward, since the incoming
   data is headerless. On hide-sight, it might be cleaner
   and more future-proof against changes in libjpeg
   to construct a made-up header, read it then switch data stream. */
static void
fastforward_jpeg_stream_state(jpeg_decompress_data * jddp,
			      stream_DCT_state * ss, px_state_t * pxs)
{
    px_vendor_state_t *v_state = pxs->vendor_state;
    j_decompress_ptr cinfo = &jddp->dinfo;
    int i;
    int j, qcount = 0;
    jpeg_component_info *compptr;
    int factor = ((v_state->color_space == eGraySub) ? 8 : 1);
    extern const int jpeg_natural_order[];

    if (cinfo->comp_info == NULL)
	cinfo->comp_info = (jpeg_component_info *)
	    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo,
					JPOOL_PERMANENT,
					MAX_COMPONENTS *
					sizeof(jpeg_component_info));
    /* default_decompress_parms() starts */
    if (v_state->color_space == eGraySub) {
	cinfo->jpeg_color_space = JCS_GRAYSCALE;
	cinfo->out_color_space = JCS_GRAYSCALE;
    } else {
	cinfo->jpeg_color_space = JCS_YCbCr;
	cinfo->out_color_space = JCS_YCbCr;
    }
    cinfo->scale_num = 8;
    cinfo->scale_denom = 8;
    cinfo->output_gamma = 1.0;
    cinfo->buffered_image = FALSE;
    cinfo->raw_data_out = FALSE;
    cinfo->dct_method = JDCT_DEFAULT;
    cinfo->do_fancy_upsampling = TRUE;
    cinfo->do_block_smoothing = TRUE;
    cinfo->quantize_colors = FALSE;
    /* */
    cinfo->dither_mode = JDITHER_FS;
    /* */
    cinfo->two_pass_quantize = 1;
    /* */
    cinfo->desired_number_of_colors = 256;
    /* */
    cinfo->enable_1pass_quant = 0;
    cinfo->enable_external_quant = 0;
    cinfo->enable_2pass_quant = FALSE;
    /* default_decompress_parms() ends */
    std_huff_tables(cinfo);
    /* get_soi begins */
    for (i = 0; i < NUM_ARITH_TBLS; i++) {
	cinfo->arith_dc_L[i] = 0;
	cinfo->arith_dc_U[i] = 1;
	cinfo->arith_ac_K[i] = 5;
    }
    cinfo->restart_interval = 0;
    cinfo->CCIR601_sampling = FALSE;
    /* */
    cinfo->JFIF_major_version = 1;	/* Default JFIF version = 1.01 */
    cinfo->JFIF_minor_version = 1;
    cinfo->density_unit = 0;	/* Pixel size is unknown by default */
    cinfo->X_density = 1;	/* Pixel aspect ratio is square by default */
    cinfo->Y_density = 1;
    /* get_soi ends */
    /* get_sof */
    cinfo->is_baseline = 1;
    cinfo->progressive_mode = FALSE;
    cinfo->arith_code = FALSE;
    cinfo->data_precision = BITS_IN_JSAMPLE;
    if (v_state->color_space == eGraySub)
	cinfo->num_components = 1;
    else
	cinfo->num_components = 3;

    cinfo->image_width = v_state->SourceWidth;
    cinfo->image_height = v_state->BlockHeight;

    for (i = 0; i < cinfo->num_components; i++) {
	if (cinfo->quant_tbl_ptrs[i] == NULL)
	    cinfo->quant_tbl_ptrs[i] =
		jpeg_alloc_quant_table((j_common_ptr) cinfo);
	for (j = 0; j < 64; j++)
	    cinfo->quant_tbl_ptrs[i]->quantval[j] =
		v_state->qvalues[qcount++];
    }

#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), \
         compptr->DCT_h_scaled_size = 8, \
         compptr->DCT_v_scaled_size = 8, \
         compptr->width_in_blocks = cinfo->image_width/factor, \
         compptr->height_in_blocks = cinfo->image_height/factor, \
         compptr->quant_table = cinfo->quant_tbl_ptrs[index], \
         compptr->component_index = index, \
         compptr->component_needed = TRUE, \
         compptr->downsampled_width = cinfo->image_width, \
         compptr->downsampled_height = cinfo->image_height)

    SET_COMP(0, 1, 1, 1, 0, 0, 0);	/* not default! */
    if (v_state->color_space != eGraySub) {
	SET_COMP(1, 2, 1, 1, 1, 1, 1);
	SET_COMP(2, 3, 1, 1, 1, 1, 1);
    }
    /* end_sof */
    cinfo->rec_outbuf_height = 1;

    if (v_state->color_space == eGraySub) {
	cinfo->out_color_components = 1;
	cinfo->output_components = 1;
    } else {
	cinfo->out_color_components = 3;
	cinfo->output_components = 3;
    }
    cinfo->global_state = DSTATE_READY;
    /* no SOS markers, so we just do this by hand - mostly from get_sos() */
    cinfo->cur_comp_info[0] = &cinfo->comp_info[0];
    cinfo->comp_info[0].dc_tbl_no = 0;
    cinfo->comp_info[0].ac_tbl_no = 0;
    if (v_state->color_space != eGraySub) {
	cinfo->cur_comp_info[1] = &cinfo->comp_info[1];
	cinfo->comp_info[1].dc_tbl_no = 1;
	cinfo->comp_info[1].ac_tbl_no = 1;
	cinfo->cur_comp_info[2] = &cinfo->comp_info[2];
	cinfo->comp_info[2].dc_tbl_no = 1;
	cinfo->comp_info[2].ac_tbl_no = 1;
    }
    cinfo->Ss = 0;
    cinfo->Se = 63;
    cinfo->Ah = 0;
    cinfo->Al = 0;
    /* initial_setup() */
    cinfo->input_scan_number = 1;
    cinfo->block_size = DCTSIZE;

    cinfo->natural_order = jpeg_natural_order;
    cinfo->lim_Se = DCTSIZE2 - 1;
    cinfo->min_DCT_h_scaled_size = 8;
    cinfo->min_DCT_v_scaled_size = 8;
    cinfo->max_h_samp_factor = 1;
    cinfo->max_v_samp_factor = 1;
    if (v_state->color_space == eGraySub)
	cinfo->comps_in_scan = 1;
    else
	cinfo->comps_in_scan = 3;

    /* */
    jpeg_core_output_dimensions(cinfo);
    cinfo->total_iMCU_rows = 16;

    ss->phase = 2;		/* fast forward to phase 2, on to start_decompress */
}
コード例 #4
0
ファイル: jcparam.c プロジェクト: msabhijith/dgate
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) )

  /* Safety check to ensure start_compress not called yet. */
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

  /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
   * tables 1 for chrominance components.
   */

  cinfo->jpeg_color_space = colorspace;

  cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  
  /* Fix the bit width stuff here, by now cinfo->data_precision should be set */
  if (2 > cinfo->data_precision || cinfo->data_precision > 16)
    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  if (!cinfo->lossless) {
    if (cinfo->data_precision <=8) {
      if (cinfo->data_precision !=8) {
        WARNMS2(cinfo, JWRN_JPEG_PRECISION_CHANGED, cinfo->data_precision, 8);
        cinfo->data_precision = 8;
      }
    } else if (cinfo->data_precision != 12) {
      WARNMS2(cinfo, JWRN_JPEG_PRECISION_CHANGED, cinfo->data_precision, 12);
      cinfo->data_precision = 12;
    }
  }
  cinfo->maxjsample = (1 << cinfo->data_precision) - 1;
  cinfo->centerjsample = (cinfo->maxjsample + 1)/2;
#ifdef HAVE_GETJSAMPLE_MASK
  cinfo->maskjsample = cinfo->maxjsample;
#endif

  /* The standard Huffman tables are only valid for 8-bit data precision.
   * If the precision is higher, force optimization on so that usable
   * tables will be computed.  This test can be removed if default tables
   * are supplied that are valid for the desired precision.
   */
  if (cinfo->data_precision != 8)
    cinfo->optimize_coding = TRUE;

  switch (colorspace) {
  case JCS_GRAYSCALE:
    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
    cinfo->num_components = 1;
    /* JFIF specifies component ID 1 */
    SET_COMP(0, 1, 1,1, 0, 0,0);
    break;
  case JCS_RGB:
    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
    cinfo->num_components = 3;
    SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
    SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
    SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
    break;
  case JCS_YCbCr:
    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
    cinfo->num_components = 3;
    /* JFIF specifies component IDs 1,2,3 */
    if (cinfo->lossless) {
      SET_COMP(0, 1, 1,1, 0, 0,0);
      SET_COMP(1, 2, 1,1, 1, 1,1);
      SET_COMP(2, 3, 1,1, 1, 1,1);
    } else { /* lossy */
      /* We default to 2x2 subsamples of chrominance */
      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; /* write Adobe marker to flag CMYK */
    cinfo->num_components = 4;
    SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
    SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
    SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
    SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
    break;
  case JCS_YCCK:
    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
    cinfo->num_components = 4;
    if (cinfo->lossless) {
      SET_COMP(0, 1, 1,1, 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, 1,1, 0, 0,0);
    } else { /* lossy */
      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);
  }
}
コード例 #5
0
ファイル: jcparam.c プロジェクト: qtekfun/htcDesire820Kernel
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);
  }
}
コード例 #6
0
ファイル: jcparam.c プロジェクト: fatman2021/myforthprocessor
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) )

  /* Safety check to ensure start_compress not called yet. */
  if (cinfo->global_state != CSTATE_START)
    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

  /* For all colorspaces, we use Q and Huff tables 0 for luminance components,
   * tables 1 for chrominance components.
   */

  cinfo->jpeg_color_space = colorspace;

  cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */

  switch (colorspace) {
  case JCS_GRAYSCALE:
    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
    cinfo->num_components = 1;
    /* JFIF specifies component ID 1 */
    SET_COMP(0, 1, 1,1, 0, 0,0);
    break;
#ifdef NIFTY
  case JCS_YCC:
    cinfo->write_JFIF_header = FALSE; /* don't write a JFIF marker. */
    cinfo->num_components = 3;
    /* NOTE:
      these component numbers MUST BE UNIQUE!!! 
      so YCC was changed to YCc.
      And it wasn't an easy bug to find, either!!!! rgvb. */
    SET_COMP(0, 0x59 /* 'Y' */, 2,2, 0, 0,0);	/* Photo YCC */
    SET_COMP(1, 0x43 /* 'C' */, 1,1, 1, 1,1);
    SET_COMP(2, 0x63 /* 'c' */, 1,1, 1, 1,1);
    break;

  case JCS_YCCA:
    cinfo->write_JFIF_header = FALSE; /* don't write a JFIF marker. */
    cinfo->num_components = 4;
    /* NOTE:
      these component numbers MUST BE UNIQUE!!! 
      so YCC was changed to YCc.
      And it wasn't an easy bug to find, either!!!! rgvb. */
    SET_COMP(0, 0x59 /* 'Y' */, 2,2, 0, 0,0);	/* PhotoYCC-Alpha */
    SET_COMP(1, 0x43 /* 'C' */, 1,1, 1, 1,1);
    SET_COMP(2, 0x63 /* 'c' */, 1,1, 1, 1,1);
    SET_COMP(3, 0x41 /* 'A' */, 2,2, 0, 0,0);
    break;

  case JCS_YCbCrA:
    cinfo->write_JFIF_header = FALSE; /* don't write a JFIF marker. */
    cinfo->num_components = 4;
    SET_COMP(0, 1, 2,2, 0, 0,0);	/* YCbCr-Alpha */
    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_RGBA:
    cinfo->write_JFIF_header = FALSE; /* don't write a JFIF marker. */
    cinfo->num_components = 4;
    SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);	/* RGB-Alpha Straight through */
    SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
    SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
    SET_COMP(3, 0x41 /* 'A' */, 1,1, 0, 0,0);
    break;

  case JCS_YCbCrA_LEGACY:
    cinfo->write_JFIF_header = FALSE; /* don't write a JFIF marker. */
    cinfo->num_components = 4;
    SET_COMP(0, 1, 2,2, 0, 0,0);	/* YCbCr-Alpha */
    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;

	/* JCS_RGBA_LEGACY should NEVER appear as a JPEG colorspace. It 
	   is only valid as an input color on compression and an output
	   color on decompression. */
  case JCS_RGBA_LEGACY:
    ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
    break;
#endif
  case JCS_RGB:
    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
    cinfo->num_components = 3;
    SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
    SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
    SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
    break;
  case JCS_YCbCr:
    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
    cinfo->num_components = 3;
    /* JFIF specifies component IDs 1,2,3 */
    /* We default to 2x2 subsamples of chrominance */
    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; /* write Adobe marker to flag CMYK */
    cinfo->num_components = 4;
    SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
    SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
    SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
    SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
    break;
  case JCS_YCCK:
    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
    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);
  }
}