Back to index

tetex-bin  3.0
Public Member Functions | Private Member Functions | Private Attributes
GfxImageColorMap Class Reference

#include <GfxState.h>

Collaboration diagram for GfxImageColorMap:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 GfxImageColorMap (int bitsA, Object *decode, GfxColorSpace *colorSpaceA)
 ~GfxImageColorMap ()
GfxImageColorMapcopy ()
GBool isOk ()
GfxColorSpacegetColorSpace ()
int getNumPixelComps ()
int getBits ()
double getDecodeLow (int i)
double getDecodeHigh (int i)
void getGray (Guchar *x, double *gray)
void getRGB (Guchar *x, GfxRGB *rgb)
void getCMYK (Guchar *x, GfxCMYK *cmyk)
void getColor (Guchar *x, GfxColor *color)

Private Member Functions

 GfxImageColorMap (GfxImageColorMap *colorMap)

Private Attributes

GfxColorSpacecolorSpace
int bits
int nComps
GfxColorSpacecolorSpace2
int nComps2
double * lookup
double decodeLow [gfxColorMaxComps]
double decodeRange [gfxColorMaxComps]
GBool ok

Detailed Description

Definition at line 689 of file GfxState.h.


Constructor & Destructor Documentation

GfxImageColorMap::GfxImageColorMap ( int  bitsA,
Object decode,
GfxColorSpace colorSpaceA 
)

Definition at line 1980 of file GfxState.cc.

                                                           {
  GfxIndexedColorSpace *indexedCS;
  GfxSeparationColorSpace *sepCS;
  int maxPixel, indexHigh;
  Guchar *lookup2;
  Function *sepFunc;
  Object obj;
  double x[gfxColorMaxComps];
  double y[gfxColorMaxComps];
  int i, j, k;

  ok = gTrue;

  // bits per component and color space
  bits = bitsA;
  maxPixel = (1 << bits) - 1;
  colorSpace = colorSpaceA;

  // get decode map
  if (decode->isNull()) {
    nComps = colorSpace->getNComps();
    colorSpace->getDefaultRanges(decodeLow, decodeRange, maxPixel);
  } else if (decode->isArray()) {
    nComps = decode->arrayGetLength() / 2;
    if (nComps != colorSpace->getNComps()) {
      goto err1;
    }
    for (i = 0; i < nComps; ++i) {
      decode->arrayGet(2*i, &obj);
      if (!obj.isNum()) {
       goto err2;
      }
      decodeLow[i] = obj.getNum();
      obj.free();
      decode->arrayGet(2*i+1, &obj);
      if (!obj.isNum()) {
       goto err2;
      }
      decodeRange[i] = obj.getNum() - decodeLow[i];
      obj.free();
    }
  } else {
    goto err1;
  }

  // Construct a lookup table -- this stores pre-computed decoded
  // values for each component, i.e., the result of applying the
  // decode mapping to each possible image pixel component value.
  //
  // Optimization: for Indexed and Separation color spaces (which have
  // only one component), we store color values in the lookup table
  // rather than component values.
  colorSpace2 = NULL;
  nComps2 = 0;
  if (colorSpace->getMode() == csIndexed) {
    // Note that indexHigh may not be the same as maxPixel --
    // Distiller will remove unused palette entries, resulting in
    // indexHigh < maxPixel.
    indexedCS = (GfxIndexedColorSpace *)colorSpace;
    colorSpace2 = indexedCS->getBase();
    indexHigh = indexedCS->getIndexHigh();
    nComps2 = colorSpace2->getNComps();
    lookup = (double *)gmalloc((maxPixel + 1) * nComps2 * sizeof(double));
    lookup2 = indexedCS->getLookup();
    colorSpace2->getDefaultRanges(x, y, indexHigh);
    for (i = 0; i <= maxPixel; ++i) {
      j = (int)(decodeLow[0] + (i * decodeRange[0]) / maxPixel + 0.5);
      if (j < 0) {
       j = 0;
      } else if (j > indexHigh) {
       j = indexHigh;
      }
      for (k = 0; k < nComps2; ++k) {
       lookup[i*nComps2 + k] = x[k] + (lookup2[j*nComps2 + k] / 255.0) * y[k];
      }
    }
  } else if (colorSpace->getMode() == csSeparation) {
    sepCS = (GfxSeparationColorSpace *)colorSpace;
    colorSpace2 = sepCS->getAlt();
    nComps2 = colorSpace2->getNComps();
    lookup = (double *)gmalloc((maxPixel + 1) * nComps2 * sizeof(double));
    sepFunc = sepCS->getFunc();
    for (i = 0; i <= maxPixel; ++i) {
      x[0] = decodeLow[0] + (i * decodeRange[0]) / maxPixel;
      sepFunc->transform(x, y);
      for (k = 0; k < nComps2; ++k) {
       lookup[i*nComps2 + k] = y[k];
      }
    }
  } else {
    lookup = (double *)gmalloc((maxPixel + 1) * nComps * sizeof(double));
    for (i = 0; i <= maxPixel; ++i) {
      for (k = 0; k < nComps; ++k) {
       lookup[i*nComps + k] = decodeLow[k] +
                                (i * decodeRange[k]) / maxPixel;
      }
    }
  }

  return;

 err2:
  obj.free();
 err1:
  ok = gFalse;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 2116 of file GfxState.cc.

                                    {
  delete colorSpace;
  gfree(lookup);
}

Here is the call graph for this function:

Definition at line 2088 of file GfxState.cc.

                                                             {
  int n, i;

  colorSpace = colorMap->colorSpace->copy();
  bits = colorMap->bits;
  nComps = colorMap->nComps;
  nComps2 = colorMap->nComps2;
  colorSpace2 = NULL;
  lookup = NULL;
  n = 1 << bits;
  if (colorSpace->getMode() == csIndexed) {
    colorSpace2 = ((GfxIndexedColorSpace *)colorSpace)->getBase();
    n = n * nComps2 * sizeof(double);
  } else if (colorSpace->getMode() == csSeparation) {
    colorSpace2 = ((GfxSeparationColorSpace *)colorSpace)->getAlt();
    n = n * nComps2 * sizeof(double);
  } else {
    n = n * nComps * sizeof(double);
  }
  lookup = (double *)gmalloc(n);
  memcpy(lookup, colorMap->lookup, n);
  for (i = 0; i < nComps; ++i) {
    decodeLow[i] = colorMap->decodeLow[i];
    decodeRange[i] = colorMap->decodeRange[i];
  }
  ok = gTrue;
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 699 of file GfxState.h.

{ return new GfxImageColorMap(this); }

Here is the call graph for this function:

Definition at line 709 of file GfxState.h.

{ return bits; }

Here is the caller graph for this function:

Definition at line 2159 of file GfxState.cc.

                                                       {
  GfxColor color;
  double *p;
  int i;

  if (colorSpace2) {
    p = &lookup[x[0] * nComps2];
    for (i = 0; i < nComps2; ++i) {
      color.c[i] = *p++;
    }
    colorSpace2->getCMYK(&color, cmyk);
  } else {
    for (i = 0; i < nComps; ++i) {
      color.c[i] = lookup[x[i] * nComps + i];
    }
    colorSpace->getCMYK(&color, cmyk);
  }
}

Here is the call graph for this function:

Definition at line 2178 of file GfxState.cc.

                                                          {
  int maxPixel, i;

  maxPixel = (1 << bits) - 1;
  for (i = 0; i < nComps; ++i) {
    color->c[i] = decodeLow[i] + (x[i] * decodeRange[i]) / maxPixel;
  }
}

Definition at line 705 of file GfxState.h.

{ return colorSpace; }
double GfxImageColorMap::getDecodeHigh ( int  i) [inline]

Definition at line 713 of file GfxState.h.

{ return decodeLow[i] + decodeRange[i]; }
double GfxImageColorMap::getDecodeLow ( int  i) [inline]

Definition at line 712 of file GfxState.h.

{ return decodeLow[i]; }
void GfxImageColorMap::getGray ( Guchar x,
double *  gray 
)

Definition at line 2121 of file GfxState.cc.

                                                      {
  GfxColor color;
  double *p;
  int i;

  if (colorSpace2) {
    p = &lookup[x[0] * nComps2];
    for (i = 0; i < nComps2; ++i) {
      color.c[i] = *p++;
    }
    colorSpace2->getGray(&color, gray);
  } else {
    for (i = 0; i < nComps; ++i) {
      color.c[i] = lookup[x[i] * nComps + i];
    }
    colorSpace->getGray(&color, gray);
  }
}

Here is the call graph for this function:

Definition at line 708 of file GfxState.h.

{ return nComps; }

Here is the caller graph for this function:

Definition at line 2140 of file GfxState.cc.

                                                    {
  GfxColor color;
  double *p;
  int i;

  if (colorSpace2) {
    p = &lookup[x[0] * nComps2];
    for (i = 0; i < nComps2; ++i) {
      color.c[i] = *p++;
    }
    colorSpace2->getRGB(&color, rgb);
  } else {
    for (i = 0; i < nComps; ++i) {
      color.c[i] = lookup[x[i] * nComps + i];
    }
    colorSpace->getRGB(&color, rgb);
  }
}

Here is the call graph for this function:

Definition at line 702 of file GfxState.h.

{ return ok; }

Here is the caller graph for this function:


Member Data Documentation

Definition at line 726 of file GfxState.h.

Definition at line 725 of file GfxState.h.

Definition at line 728 of file GfxState.h.

Definition at line 732 of file GfxState.h.

Definition at line 734 of file GfxState.h.

double* GfxImageColorMap::lookup [private]

Definition at line 730 of file GfxState.h.

Definition at line 727 of file GfxState.h.

Definition at line 729 of file GfxState.h.

Definition at line 735 of file GfxState.h.


The documentation for this class was generated from the following files: