Back to index

plt-scheme  4.2.1
Functions
rdcolmap.c File Reference
#include "cdjpeg.h"

Go to the source code of this file.

Functions

 add_map_entry (j_decompress_ptr cinfo, int R, int G, int B)
 read_gif_map (j_decompress_ptr cinfo, FILE *infile)
 pbm_getc (FILE *infile)
 read_pbm_integer (j_decompress_ptr cinfo, FILE *infile)
 read_ppm_map (j_decompress_ptr cinfo, FILE *infile)
 read_color_map (j_decompress_ptr cinfo, FILE *infile)

Function Documentation

add_map_entry ( j_decompress_ptr  cinfo,
int  R,
int  G,
int  B 
)

Definition at line 46 of file rdcolmap.c.

{
  JSAMPROW colormap0 = cinfo->colormap[0];
  JSAMPROW colormap1 = cinfo->colormap[1];
  JSAMPROW colormap2 = cinfo->colormap[2];
  int ncolors = cinfo->actual_number_of_colors;
  int index;

  /* Check for duplicate color. */
  for (index = 0; index < ncolors; index++) {
    if (GETJSAMPLE(colormap0[index]) == R &&
       GETJSAMPLE(colormap1[index]) == G &&
       GETJSAMPLE(colormap2[index]) == B)
      return;               /* color is already in map */
  }

  /* Check for map overflow. */
  if (ncolors >= (MAXJSAMPLE+1))
    ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1));

  /* OK, add color to map. */
  colormap0[ncolors] = (JSAMPLE) R;
  colormap1[ncolors] = (JSAMPLE) G;
  colormap2[ncolors] = (JSAMPLE) B;
  cinfo->actual_number_of_colors++;
}

Here is the caller graph for this function:

pbm_getc ( FILE *  infile)

Definition at line 121 of file rdcolmap.c.

{
  register int ch;
  
  ch = getc(infile);
  if (ch == '#') {
    do {
      ch = getc(infile);
    } while (ch != '\n' && ch != EOF);
  }
  return ch;
}

Here is the caller graph for this function:

read_color_map ( j_decompress_ptr  cinfo,
FILE *  infile 
)

Definition at line 231 of file rdcolmap.c.

{
  /* Allocate space for a color map of maximum supported size. */
  cinfo->colormap = (*cinfo->mem->alloc_sarray)
    ((j_common_ptr) cinfo, JPOOL_IMAGE,
     (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3);
  cinfo->actual_number_of_colors = 0; /* initialize map to empty */

  /* Read first byte to determine file format */
  switch (getc(infile)) {
  case 'G':
    read_gif_map(cinfo, infile);
    break;
  case 'P':
    read_ppm_map(cinfo, infile);
    break;
  default:
    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
    break;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

read_gif_map ( j_decompress_ptr  cinfo,
FILE *  infile 
)

Definition at line 79 of file rdcolmap.c.

{
  int header[13];
  int i, colormaplen;
  int R, G, B;

  /* Initial 'G' has already been read by read_color_map */
  /* Read the rest of the GIF header and logical screen descriptor */
  for (i = 1; i < 13; i++) {
    if ((header[i] = getc(infile)) == EOF)
      ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
  }

  /* Verify GIF Header */
  if (header[1] != 'I' || header[2] != 'F')
    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);

  /* There must be a global color map. */
  if ((header[10] & 0x80) == 0)
    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);

  /* OK, fetch it. */
  colormaplen = 2 << (header[10] & 0x07);

  for (i = 0; i < colormaplen; i++) {
    R = getc(infile);
    G = getc(infile);
    B = getc(infile);
    if (R == EOF || G == EOF || B == EOF)
      ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
    add_map_entry(cinfo,
                R << (BITS_IN_JSAMPLE-8),
                G << (BITS_IN_JSAMPLE-8),
                B << (BITS_IN_JSAMPLE-8));
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

read_pbm_integer ( j_decompress_ptr  cinfo,
FILE *  infile 
)

Definition at line 138 of file rdcolmap.c.

{
  register int ch;
  register unsigned int val;
  
  /* Skip any leading whitespace */
  do {
    ch = pbm_getc(infile);
    if (ch == EOF)
      ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
  } while (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r');
  
  if (ch < '0' || ch > '9')
    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
  
  val = ch - '0';
  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {
    val *= 10;
    val += ch - '0';
  }
  return val;
}

Here is the call graph for this function:

Here is the caller graph for this function:

read_ppm_map ( j_decompress_ptr  cinfo,
FILE *  infile 
)

Definition at line 171 of file rdcolmap.c.

{
  int c;
  unsigned int w, h, maxval, row, col;
  int R, G, B;

  /* Initial 'P' has already been read by read_color_map */
  c = getc(infile);         /* save format discriminator for a sec */

  /* while we fetch the remaining header info */
  w = read_pbm_integer(cinfo, infile);
  h = read_pbm_integer(cinfo, infile);
  maxval = read_pbm_integer(cinfo, infile);

  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */
    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);

  /* For now, we don't support rescaling from an unusual maxval. */
  if (maxval != (unsigned int) MAXJSAMPLE)
    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);

  switch (c) {
  case '3':                 /* it's a text-format PPM file */
    for (row = 0; row < h; row++) {
      for (col = 0; col < w; col++) {
       R = read_pbm_integer(cinfo, infile);
       G = read_pbm_integer(cinfo, infile);
       B = read_pbm_integer(cinfo, infile);
       add_map_entry(cinfo, R, G, B);
      }
    }
    break;

  case '6':                 /* it's a raw-format PPM file */
    for (row = 0; row < h; row++) {
      for (col = 0; col < w; col++) {
       R = getc(infile);
       G = getc(infile);
       B = getc(infile);
       if (R == EOF || G == EOF || B == EOF)
         ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
       add_map_entry(cinfo, R, G, B);
      }
    }
    break;

  default:
    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);
    break;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function: