Back to index

plt-scheme  4.2.1
Classes | Defines | Typedefs | Functions
jccolor.c File Reference
#include "jinclude.h"
#include "jpeglib.h"

Go to the source code of this file.

Classes

struct  my_color_converter

Defines

#define JPEG_INTERNALS
#define SCALEBITS   16 /* speediest right-shift on some machines */
#define CBCR_OFFSET   ((INT32) CENTERJSAMPLE << SCALEBITS)
#define ONE_HALF   ((INT32) 1 << (SCALEBITS-1))
#define FIX(x)   ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
#define R_Y_OFF   0 /* offset to R => Y section */
#define G_Y_OFF   (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
#define B_Y_OFF   (2*(MAXJSAMPLE+1)) /* etc. */
#define R_CB_OFF   (3*(MAXJSAMPLE+1))
#define G_CB_OFF   (4*(MAXJSAMPLE+1))
#define B_CB_OFF   (5*(MAXJSAMPLE+1))
#define R_CR_OFF   B_CB_OFF /* B=>Cb, R=>Cr are the same */
#define G_CR_OFF   (6*(MAXJSAMPLE+1))
#define B_CR_OFF   (7*(MAXJSAMPLE+1))
#define TABLE_SIZE   (8*(MAXJSAMPLE+1))

Typedefs

typedef my_color_convertermy_cconvert_ptr

Functions

 rgb_ycc_start (j_compress_ptr cinfo)
 rgb_ycc_convert (j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
 rgb_gray_convert (j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
 cmyk_ycck_convert (j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
 grayscale_convert (j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
 null_convert (j_compress_ptr cinfo, JSAMPARRAY input_buf, JSAMPIMAGE output_buf, JDIMENSION output_row, int num_rows)
 null_method (j_compress_ptr cinfo)
 jinit_color_converter (j_compress_ptr cinfo)

Class Documentation

struct my_color_converter

Definition at line 18 of file jccolor.c.

Class Members
INT32 * rgb_ycc_tab

Define Documentation

#define B_CB_OFF   (5*(MAXJSAMPLE+1))

Definition at line 74 of file jccolor.c.

#define B_CR_OFF   (7*(MAXJSAMPLE+1))

Definition at line 77 of file jccolor.c.

#define B_Y_OFF   (2*(MAXJSAMPLE+1)) /* etc. */

Definition at line 71 of file jccolor.c.

Definition at line 59 of file jccolor.c.

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

Definition at line 61 of file jccolor.c.

#define G_CB_OFF   (4*(MAXJSAMPLE+1))

Definition at line 73 of file jccolor.c.

#define G_CR_OFF   (6*(MAXJSAMPLE+1))

Definition at line 76 of file jccolor.c.

#define G_Y_OFF   (1*(MAXJSAMPLE+1)) /* offset to G => Y section */

Definition at line 70 of file jccolor.c.

#define JPEG_INTERNALS

Definition at line 11 of file jccolor.c.

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

Definition at line 60 of file jccolor.c.

#define R_CB_OFF   (3*(MAXJSAMPLE+1))

Definition at line 72 of file jccolor.c.

#define R_CR_OFF   B_CB_OFF /* B=>Cb, R=>Cr are the same */

Definition at line 75 of file jccolor.c.

#define R_Y_OFF   0 /* offset to R => Y section */

Definition at line 69 of file jccolor.c.

#define SCALEBITS   16 /* speediest right-shift on some machines */

Definition at line 58 of file jccolor.c.

#define TABLE_SIZE   (8*(MAXJSAMPLE+1))

Definition at line 78 of file jccolor.c.


Typedef Documentation

Definition at line 25 of file jccolor.c.


Function Documentation

cmyk_ycck_convert ( j_compress_ptr  cinfo,
JSAMPARRAY  input_buf,
JSAMPIMAGE  output_buf,
JDIMENSION  output_row,
int  num_rows 
)

Definition at line 225 of file jccolor.c.

{
  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);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

grayscale_convert ( j_compress_ptr  cinfo,
JSAMPARRAY  input_buf,
JSAMPIMAGE  output_buf,
JDIMENSION  output_row,
int  num_rows 
)

Definition at line 280 of file jccolor.c.

{
  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;
    }
  }
}

Here is the caller graph for this function:

Definition at line 352 of file jccolor.c.

{
  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;

  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;

  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;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

null_convert ( j_compress_ptr  cinfo,
JSAMPARRAY  input_buf,
JSAMPIMAGE  output_buf,
JDIMENSION  output_row,
int  num_rows 
)

Definition at line 309 of file jccolor.c.

{
  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++;
  }
}

Here is the caller graph for this function:

Definition at line 341 of file jccolor.c.

{
  /* no work needed */
}

Here is the caller graph for this function:

rgb_gray_convert ( j_compress_ptr  cinfo,
JSAMPARRAY  input_buf,
JSAMPIMAGE  output_buf,
JDIMENSION  output_row,
int  num_rows 
)

Definition at line 186 of file jccolor.c.

{
  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 outptr;
  register JDIMENSION col;
  JDIMENSION num_cols = cinfo->image_width;

  while (--num_rows >= 0) {
    inptr = *input_buf++;
    outptr = output_buf[0][output_row];
    output_row++;
    for (col = 0; col < num_cols; col++) {
      r = GETJSAMPLE(inptr[RGB_RED]);
      g = GETJSAMPLE(inptr[RGB_GREEN]);
      b = GETJSAMPLE(inptr[RGB_BLUE]);
      inptr += RGB_PIXELSIZE;
      /* Y */
      outptr[col] = (JSAMPLE)
              ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
               >> SCALEBITS);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

rgb_ycc_convert ( j_compress_ptr  cinfo,
JSAMPARRAY  input_buf,
JSAMPIMAGE  output_buf,
JDIMENSION  output_row,
int  num_rows 
)

Definition at line 130 of file jccolor.c.

{
  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;
  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];
    output_row++;
    for (col = 0; col < num_cols; col++) {
      r = GETJSAMPLE(inptr[RGB_RED]);
      g = GETJSAMPLE(inptr[RGB_GREEN]);
      b = GETJSAMPLE(inptr[RGB_BLUE]);
      inptr += RGB_PIXELSIZE;
      /* 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);
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 86 of file jccolor.c.

{
  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  INT32 * rgb_ycc_tab;
  INT32 i;

  /* Allocate and fill in the conversion tables. */
  cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
                            (TABLE_SIZE * SIZEOF(INT32)));

  for (i = 0; i <= MAXJSAMPLE; i++) {
    rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
    rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
    rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i     + ONE_HALF;
    rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
    rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
    /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.
     * This ensures that the maximum output will round to MAXJSAMPLE
     * not MAXJSAMPLE+1, and thus that we don't have to range-limit.
     */
    rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i    + CBCR_OFFSET + ONE_HALF-1;
/*  B=>Cb and R=>Cr tables are the same
    rgb_ycc_tab[i+R_CR_OFF] = FIX(0.50000) * i    + CBCR_OFFSET + ONE_HALF-1;
*/
    rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
    rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  }
}

Here is the caller graph for this function: