⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jccolor.c

📁 This is a resource based on j2me embedded,if you dont understand,you can connection with me .
💻 C
📖 第 1 页 / 共 2 页
字号:
 * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same * conversion as above, while passing K (black) unchanged. * We assume rgb_ycc_start has been called. */METHODDEF(void)cmyk_ycck_convert (j_compress_ptr cinfo,		   JSAMPARRAY input_buf, JSAMPIMAGE output_buf,		   JDIMENSION output_row, int num_rows){  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;  register int r, g, b;  register INT32 * ctab = cconvert->rgb_ycc_tab;  register JSAMPROW inptr;  register JSAMPROW outptr0, outptr1, outptr2, outptr3;  register JDIMENSION col;  JDIMENSION num_cols = cinfo->image_width;  while (--num_rows >= 0) {    inptr = *input_buf++;    outptr0 = output_buf[0][output_row];    outptr1 = output_buf[1][output_row];    outptr2 = output_buf[2][output_row];    outptr3 = output_buf[3][output_row];    output_row++;    for (col = 0; col < num_cols; col++) {      r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);      g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);      b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);      /* K passes through as-is */      outptr3[col] = inptr[3];	/* don't need GETJSAMPLE here */      inptr += 4;      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations       * must be too; we do not need an explicit range-limiting operation.       * Hence the value being shifted is never negative, and we don't       * need the general RIGHT_SHIFT macro.       */      /* Y */      outptr0[col] = (JSAMPLE)		((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])		 >> SCALEBITS);      /* Cb */      outptr1[col] = (JSAMPLE)		((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])		 >> SCALEBITS);      /* Cr */      outptr2[col] = (JSAMPLE)		((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])		 >> SCALEBITS);    }  }}/* * Convert some rows of samples to the JPEG colorspace. * This version handles grayscale output with no conversion. * The source can be either plain grayscale or YCbCr (since Y == gray). */METHODDEF(void)grayscale_convert (j_compress_ptr cinfo,		   JSAMPARRAY input_buf, JSAMPIMAGE output_buf,		   JDIMENSION output_row, int num_rows){  register JSAMPROW inptr;  register JSAMPROW outptr;  register JDIMENSION col;  JDIMENSION num_cols = cinfo->image_width;  int instride = cinfo->input_components;  while (--num_rows >= 0) {    inptr = *input_buf++;    outptr = output_buf[0][output_row];    output_row++;    for (col = 0; col < num_cols; col++) {      outptr[col] = inptr[0];	/* don't need GETJSAMPLE() here */      inptr += instride;    }  }}/* * Convert some rows of samples to the JPEG colorspace. * This version handles multi-component colorspaces without conversion. * We assume input_components == num_components. */METHODDEF(void)null_convert (j_compress_ptr cinfo,	      JSAMPARRAY input_buf, JSAMPIMAGE output_buf,	      JDIMENSION output_row, int num_rows){  register JSAMPROW inptr;  register JSAMPROW outptr;  register JDIMENSION col;  register int ci;  int nc = cinfo->num_components;  JDIMENSION num_cols = cinfo->image_width;  while (--num_rows >= 0) {    /* It seems fastest to make a separate pass for each component. */    for (ci = 0; ci < nc; ci++) {      inptr = *input_buf;      outptr = output_buf[ci][output_row];      for (col = 0; col < num_cols; col++) {	outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */	inptr += nc;      }    }    input_buf++;    output_row++;  }}/* * Empty method for start_pass. */METHODDEF(void)null_method (j_compress_ptr cinfo){  /* no work needed */}/* * Module initialization routine for input colorspace conversion. */GLOBAL(void)jinit_color_converter (j_compress_ptr cinfo){  my_cconvert_ptr cconvert;  cconvert = (my_cconvert_ptr)    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,				SIZEOF(my_color_converter));  cinfo->cconvert = (struct jpeg_color_converter *) cconvert;  /* set start_pass to null method until we find out differently */  cconvert->pub.start_pass = null_method;  /* Make sure input_components agrees with in_color_space */  switch (cinfo->in_color_space) {  case JCS_GRAYSCALE:    if (cinfo->input_components != 1)      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;#ifdef NIFTY	/* some colorspaces that we've added for NIFTY */    case JCS_YCC:    if (cinfo->input_components != 3)      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;    case JCS_RGBA:    if (cinfo->input_components != 4)      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;    case JCS_RGBA_LEGACY:    if (cinfo->input_components != 4)      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;    case JCS_YCbCrA:    if (cinfo->input_components != 4)      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;    case JCS_YCbCrA_LEGACY:     /* JCS_YCbCrA_LEGACY is a hack and should only exist with an input space of   	   JCS_RGBA_LEGACY. */      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;    case JCS_YCCA:    if (cinfo->input_components != 4)      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;#endif  case JCS_RGB:#if RGB_PIXELSIZE != 3    if (cinfo->input_components != RGB_PIXELSIZE)      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;#endif /* else share code with YCbCr */  case JCS_YCbCr:    if (cinfo->input_components != 3)      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;  case JCS_CMYK:  case JCS_YCCK:    if (cinfo->input_components != 4)      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;  default:			/* JCS_UNKNOWN can be anything */    if (cinfo->input_components < 1)      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);    break;  }  /* Check num_components, set conversion method based on requested space */  switch (cinfo->jpeg_color_space) {  case JCS_GRAYSCALE:    if (cinfo->num_components != 1)      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);    if (cinfo->in_color_space == JCS_GRAYSCALE)      cconvert->pub.color_convert = grayscale_convert;    else if (cinfo->in_color_space == JCS_RGB) {      cconvert->pub.start_pass = rgb_ycc_start;      cconvert->pub.color_convert = rgb_gray_convert;    } else if (cinfo->in_color_space == JCS_YCbCr)      cconvert->pub.color_convert = grayscale_convert;    else      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    break;#ifdef NIFTY  /* Store and compress data as PhotoYCC */  /* Only current option is to start with PhotoYCC   * although I do include the function RGB->PhotoYCC   * in the compressor, I don't think it's a good idea   * to rotate to PhotoYCC from RGB in this context.   * If subsampling is required, then just use YCrCb.   */  case JCS_YCC:    if (cinfo->num_components != 3)      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);    if (cinfo->in_color_space == JCS_YCC)      cconvert->pub.color_convert = null_convert;    else      if (cinfo->in_color_space == JCS_RGB) {	/* this is where the RGB->PhotoYCC could be called */        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);	      } else {        ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);      }    break;  case JCS_YCCA:    if (cinfo->num_components != 4)      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);    if (cinfo->in_color_space == JCS_YCCA)      cconvert->pub.color_convert = null_convert;    else      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    break;  case JCS_RGBA:    if (cinfo->num_components != 4)      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);    if (cinfo->in_color_space == JCS_RGBA) {      cconvert->pub.color_convert = null_convert;    } else {      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    }    break;  case JCS_YCbCrA:    if (cinfo->num_components != 4)      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);    if (cinfo->in_color_space == JCS_YCbCrA)      cconvert->pub.color_convert = null_convert;    else if (cinfo->in_color_space == JCS_RGBA) {      cconvert->pub.start_pass = rgb_ycc_start;      cconvert->pub.color_convert = rgba_ycbcra_convert;    } else      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    break;  case JCS_RGBA_LEGACY:     /* JCS_RGBA_LEGACY is a hack and should only exist with an output space of   	   JCS_YCbCrA_LEGACY. */      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    break;  case JCS_YCbCrA_LEGACY:     /* JCS_YCbCrA_LEGACY  is a hack and should only exist with an input space of   	   JCS_RGBA_LEGACY. */    if (cinfo->num_components != 4)      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);	if (cinfo->in_color_space == JCS_RGBA_LEGACY) {      cconvert->pub.start_pass = rgb_ycc_start;      cconvert->pub.color_convert = rgba_ycbcra_legacy_convert;    } else      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    break;#endif  case JCS_RGB:    if (cinfo->num_components != 3)      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);    if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)      cconvert->pub.color_convert = null_convert;    else      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    break;  case JCS_YCbCr:    if (cinfo->num_components != 3)      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);    if (cinfo->in_color_space == JCS_RGB) {      cconvert->pub.start_pass = rgb_ycc_start;      cconvert->pub.color_convert = rgb_ycc_convert;    } else if (cinfo->in_color_space == JCS_YCbCr)      cconvert->pub.color_convert = null_convert;    else      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    break;  case JCS_CMYK:    if (cinfo->num_components != 4)      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);    if (cinfo->in_color_space == JCS_CMYK)      cconvert->pub.color_convert = null_convert;    else      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    break;  case JCS_YCCK:    if (cinfo->num_components != 4)      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);    if (cinfo->in_color_space == JCS_CMYK) {      cconvert->pub.start_pass = rgb_ycc_start;      cconvert->pub.color_convert = cmyk_ycck_convert;    } else if (cinfo->in_color_space == JCS_YCCK)      cconvert->pub.color_convert = null_convert;    else      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    break;  default:			/* allow null conversion of JCS_UNKNOWN */    if (cinfo->jpeg_color_space != cinfo->in_color_space ||	cinfo->num_components != cinfo->input_components)      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);    cconvert->pub.color_convert = null_convert;    break;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -