Back to index

texmacs  1.0.7.15
Classes | Defines | Typedefs | Functions | Variables
pdfcolor.c File Reference
#include "system.h"
#include "mem.h"
#include "error.h"
#include "dpxfile.h"
#include "pdfdoc.h"
#include "pdfdraw.h"
#include "pdfcolor.h"
#include "dpxcrypt.h"

Go to the source code of this file.

Classes

struct  iccXYZNumber
struct  iccHeader
struct  iccbased_cdata
struct  pdf_colorspace

Defines

#define DEV_COLOR_STACK_MAX   128
#define iccNullSig   0
#define ICC_INTENT_TYPE(n)   ((int) (((n) >> 16) & 0xff))
#define ICC_INTENT_PERCEPTUAL   0
#define ICC_INTENT_RELATIVE   1
#define ICC_INTENT_SATURATION   2
#define ICC_INTENT_ABSOLUTE   3
#define check_sig(d, p, q, r, s)   ((d) && (d)->sig == ((p)<<24|(q)<<16|(r)<<8|(s)))
#define sget_signed_long(p)   ((long) ((p)[0] << 24|(p)[1] << 16|(p)[2] << 8|(p)[3]))
#define sget_signed_short(p)   ((short) ((p)[0] << 8|(p)[1]))
#define get_iccSig(p)   ((iccSig) ((p)[0] << 24|(p)[1] << 16|(p)[2] << 8|(p)[3]))
#define ICC_HEAD_SECT1_START   0
#define ICC_HEAD_SECT1_LENGTH   56
#define ICC_HEAD_SECT2_START   68
#define ICC_HEAD_SECT2_LENGTH   16
#define ICC_HEAD_SECT3_START   100
#define ICC_HEAD_SECT3_LENGTH   28
#define print_iccSig(s, t)
#define PDF_COLORSPACE_FAMILY_DEVICE   0
#define PDF_COLORSPACE_FAMILY_CIEBASED   1
#define PDF_COLORSPACE_FAMILY_SPECIAL   2

Typedefs

typedef unsigned long iccSig

Functions

void pdf_color_set_verbose (void)
int pdf_color_type (const pdf_color *color)
int pdf_color_rgbcolor (pdf_color *color, double r, double g, double b)
int pdf_color_cmykcolor (pdf_color *color, double c, double m, double y, double k)
int pdf_color_graycolor (pdf_color *color, double g)
void pdf_color_copycolor (pdf_color *color1, const pdf_color *color2)
void pdf_color_brighten_color (pdf_color *dst, const pdf_color *src, double f)
int pdf_color_is_white (const pdf_color *color)
int pdf_color_to_string (const pdf_color *color, char *buffer)
int pdf_color_compare (const pdf_color *color1, const pdf_color *color2)
int pdf_color_is_valid (const pdf_color *color)
void pdf_color_clear_stack (void)
void pdf_color_set (pdf_color *sc, pdf_color *fc)
void pdf_color_push (pdf_color *sc, pdf_color *fc)
void pdf_color_pop (void)
void pdf_color_get_current (pdf_color **sc, pdf_color **fc)
static int pdf_colorspace_defineresource (const char *ident, int subtype, void *cdata, pdf_obj *resource)
static int pdf_colorspace_findresource (const char *ident, int subtype, const void *cdata)
static int iccp_version_supported (int major, int minor)
static iccSig str2iccSig (const void *s)
static void iccp_init_iccHeader (iccHeader *icch)
static void init_iccbased_cdata (struct iccbased_cdata *cdata)
static void release_iccbased_cdata (struct iccbased_cdata *cdata)
static int get_num_components_iccbased (const struct iccbased_cdata *cdata)
static int compare_iccbased (const char *ident1, const struct iccbased_cdata *cdata1, const char *ident2, const struct iccbased_cdata *cdata2)
int iccp_check_colorspace (int colortype, const void *profile, long proflen)
pdf_objiccp_get_rendering_intent (const void *profile, long proflen)
static int iccp_unpack_header (iccHeader *icch, const void *profile, long proflen, int check_size)
static void iccp_get_checksum (unsigned char *checksum, const void *profile, long proflen)
static void print_iccp_header (iccHeader *icch, unsigned char *checksum)
static int iccp_devClass_allowed (int dev_class)
int iccp_load_profile (const char *ident, const void *profile, long proflen)
static void pdf_init_colorspace_struct (pdf_colorspace *colorspace)
static void pdf_clean_colorspace_struct (pdf_colorspace *colorspace)
static void pdf_flush_colorspace (pdf_colorspace *colorspace)
pdf_objpdf_get_colorspace_reference (int cspc_id)
void pdf_init_colors (void)
void pdf_close_colors (void)

Variables

static int verbose = 0
pdf_color current_fill
pdf_color current_stroke
struct {
int current
pdf_color stroke [DEV_COLOR_STACK_MAX]
pdf_color fill [DEV_COLOR_STACK_MAX]
color_stack
static unsigned char nullbytes16 [16]
struct {
int major
int minor
icc_versions []
struct {
int count
int capacity
pdf_colorspacecolorspaces
cspc_cache

Class Documentation

struct iccXYZNumber

Definition at line 527 of file pdfcolor.c.

Class Members
long X
long Y
long Z
struct iccHeader

Definition at line 532 of file pdfcolor.c.

Collaboration diagram for iccHeader:
Class Members
iccSig acsp
iccSig CMMType
iccSig colorSpace
char creationDate
iccSig creator
char devAttr
iccSig devClass
iccSig devMnfct
iccSig devModel
char flags
unsigned char ID
iccXYZNumber illuminant
long intent
iccSig PCS
iccSig platform
long size
long version
struct iccbased_cdata

Definition at line 596 of file pdfcolor.c.

Class Members
int alternate
unsigned char checksum
int colorspace
long sig
struct pdf_colorspace

Definition at line 1278 of file pdfcolor.c.

Collaboration diagram for pdf_colorspace:
Class Members
void * cdata
char * ident
pdf_obj * reference
pdf_obj * resource
int subtype

Define Documentation

#define check_sig (   d,
  p,
  q,
  r,
 
)    ((d) && (d)->sig == ((p)<<24|(q)<<16|(r)<<8|(s)))

Definition at line 607 of file pdfcolor.c.

#define DEV_COLOR_STACK_MAX   128

Definition at line 242 of file pdfcolor.c.

#define get_iccSig (   p)    ((iccSig) ((p)[0] << 24|(p)[1] << 16|(p)[2] << 8|(p)[3]))

Definition at line 757 of file pdfcolor.c.

#define ICC_HEAD_SECT1_LENGTH   56

Definition at line 844 of file pdfcolor.c.

#define ICC_HEAD_SECT1_START   0

Definition at line 843 of file pdfcolor.c.

#define ICC_HEAD_SECT2_LENGTH   16

Definition at line 847 of file pdfcolor.c.

#define ICC_HEAD_SECT2_START   68

Definition at line 846 of file pdfcolor.c.

#define ICC_HEAD_SECT3_LENGTH   28

Definition at line 850 of file pdfcolor.c.

#define ICC_HEAD_SECT3_START   100

Definition at line 849 of file pdfcolor.c.

#define ICC_INTENT_ABSOLUTE   3

Definition at line 588 of file pdfcolor.c.

#define ICC_INTENT_PERCEPTUAL   0

Definition at line 585 of file pdfcolor.c.

#define ICC_INTENT_RELATIVE   1

Definition at line 586 of file pdfcolor.c.

#define ICC_INTENT_SATURATION   2

Definition at line 587 of file pdfcolor.c.

#define ICC_INTENT_TYPE (   n)    ((int) (((n) >> 16) & 0xff))

Definition at line 584 of file pdfcolor.c.

#define iccNullSig   0

Definition at line 557 of file pdfcolor.c.

Definition at line 1514 of file pdfcolor.c.

Definition at line 1513 of file pdfcolor.c.

Definition at line 1515 of file pdfcolor.c.

#define print_iccSig (   s,
 
)
Value:
if ((s) == 0) {\
    MESG("pdf_color>> %s:\t(null)\n", (t)); \
  } else if (!isprint(((s) >> 24) & 0xff) || \
             !isprint(((s) >> 16) & 0xff) || \
             !isprint(((s) >>  8) & 0xff) || \
             !isprint((s) & 0xff)) { \
    MESG("pdf_color>> %s:\t(invalid)\n", (t)); \
  } else { \
    MESG("pdf_color>> %s:\t%c%c%c%c\n",  (t), \
         ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, \
         ((s) >>  8) & 0xff, (s) & 0xff); \
}
#define sget_signed_long (   p)    ((long) ((p)[0] << 24|(p)[1] << 16|(p)[2] << 8|(p)[3]))

Definition at line 755 of file pdfcolor.c.

#define sget_signed_short (   p)    ((short) ((p)[0] << 8|(p)[1]))

Definition at line 756 of file pdfcolor.c.


Typedef Documentation

typedef unsigned long iccSig

Definition at line 516 of file pdfcolor.c.


Function Documentation

static int compare_iccbased ( const char *  ident1,
const struct iccbased_cdata cdata1,
const char *  ident2,
const struct iccbased_cdata cdata2 
) [static]

Definition at line 656 of file pdfcolor.c.

{
  if (cdata1 && cdata2) {

    ASSERT(check_sig(cdata1, 'i', 'c', 'c', 'b'));
    ASSERT(check_sig(cdata2, 'i', 'c', 'c', 'b'));

    if (memcmp(cdata1->checksum, nullbytes16, 16) &&
       memcmp(cdata2->checksum, nullbytes16, 16)) {
      return memcmp(cdata1->checksum, cdata2->checksum, 16);
    }
    if (cdata1->colorspace != cdata2->colorspace) {
      return (cdata1->colorspace - cdata2->colorspace);
    }

    /* Continue if checksum unknown and colorspace is same. */
  }

  if (ident1 && ident2)
    return strcmp(ident1, ident2);

  /* No way to compare */
  return -1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int get_num_components_iccbased ( const struct iccbased_cdata cdata) [static]

Definition at line 631 of file pdfcolor.c.

{
  int  num_components = 0;

  ASSERT(check_sig(cdata, 'i', 'c', 'c', 'b'));

  switch (cdata->colorspace) {
  case PDF_COLORSPACE_TYPE_RGB:
    num_components = 3;
    break;
  case PDF_COLORSPACE_TYPE_CMYK:
    num_components = 4;
    break;
  case PDF_COLORSPACE_TYPE_GRAY:
    num_components = 1;
    break;
  case PDF_COLORSPACE_TYPE_CIELAB:
    num_components = 3;
    break;
  }

  return num_components;
}

Here is the caller graph for this function:

int iccp_check_colorspace ( int  colortype,
const void *  profile,
long  proflen 
)

Definition at line 683 of file pdfcolor.c.

{
  iccSig  colorspace;
  unsigned char  *p;

  if (!profile || proflen < 128)
    return -1;

  p = (unsigned char *) profile;

  colorspace = str2iccSig(p + 16);

  switch (colortype) {
  case PDF_COLORSPACE_TYPE_CALRGB:
  case PDF_COLORSPACE_TYPE_RGB:
    if (colorspace != str2iccSig("RGB ")) {
      return -1;
    }
    break;
  case PDF_COLORSPACE_TYPE_CALGRAY:
  case PDF_COLORSPACE_TYPE_GRAY:
    if (colorspace != str2iccSig("GRAY")) {
      return -1;
    }
    break;
  case PDF_COLORSPACE_TYPE_CMYK:
    if (colorspace != str2iccSig("CMYK")) {
      return -1;
    }
    break;
  default:
    return -1;
    break;
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int iccp_devClass_allowed ( int  dev_class) [static]

Definition at line 982 of file pdfcolor.c.

{
  int    colormode;

  colormode = pdf_dev_get_param(PDF_DEV_PARAM_COLORMODE);

  switch (colormode) {
#if 0
  case PDF_DEV_COLORMODE_PDFX1:
    break;
  case PDF_DEV_COLORMODE_PDFX3:
    if (dev_class != str2iccSig("prtr")) {
      return 0;
    }
    break;
#endif
  default:
    if (dev_class != str2iccSig("scnr") &&
       dev_class != str2iccSig("mntr") &&
       dev_class != str2iccSig("prtr") &&
       dev_class != str2iccSig("spac")) {
      return 0;
    }
    break;
  }


  return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void iccp_get_checksum ( unsigned char *  checksum,
const void *  profile,
long  proflen 
) [static]

Definition at line 854 of file pdfcolor.c.

{
  unsigned char *p;
  MD5_CONTEXT    md5;

  p = (unsigned char *) profile;

  MD5_init (&md5);
  MD5_write(&md5, p + ICC_HEAD_SECT1_START, ICC_HEAD_SECT1_LENGTH);
  MD5_write(&md5, nullbytes16, 12);
  MD5_write(&md5, p + ICC_HEAD_SECT2_START, ICC_HEAD_SECT2_LENGTH);
  MD5_write(&md5, nullbytes16, 16);
  MD5_write(&md5, p + ICC_HEAD_SECT3_START, ICC_HEAD_SECT3_LENGTH);

  /* body */
  MD5_write(&md5, p + 128, proflen - 128);

  MD5_final(checksum, &md5);
}

Here is the call graph for this function:

Here is the caller graph for this function:

pdf_obj* iccp_get_rendering_intent ( const void *  profile,
long  proflen 
)

Definition at line 722 of file pdfcolor.c.

{
  pdf_obj       *ri = NULL;
  unsigned char *p;
  long           intent;

  if (!profile || proflen < 128)
    return NULL;

  p = (unsigned char *) profile;

  intent = (p[64] << 24)|(p[65] << 16)|(p[66] << 8)|p[67];
  switch (ICC_INTENT_TYPE(intent)) {
  case ICC_INTENT_SATURATION:
    ri = pdf_new_name("Saturation");
    break;
  case ICC_INTENT_PERCEPTUAL:
    ri = pdf_new_name("Perceptual");
    break;
  case ICC_INTENT_ABSOLUTE:
    ri = pdf_new_name("AbsoluteColorimetric");
    break;
  case ICC_INTENT_RELATIVE:
    ri = pdf_new_name("RelativeColorimetric");
    break;
  default:
    WARN("Invalid rendering intent type: %d", ICC_INTENT_TYPE(intent));
    ri = NULL;
  }

  return ri;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void iccp_init_iccHeader ( iccHeader icch) [static]

Definition at line 559 of file pdfcolor.c.

{
  ASSERT(icch);

  icch->size       = 0;
  icch->CMMType    = iccNullSig;
  icch->version    = 0xFFFFFF;
  icch->devClass   = iccNullSig;
  icch->colorSpace = iccNullSig;
  icch->PCS        = iccNullSig;
  memset(icch->creationDate, 0, 12);
  icch->acsp       = str2iccSig("ascp");
  icch->platform   = iccNullSig;
  memset(icch->flags, 0, 4);
  icch->devMnfct   = iccNullSig;
  icch->devModel   = iccNullSig;
  memset(icch->devAttr, 0, 8);
  icch->intent     = 0;
  icch->illuminant.X = 0;
  icch->illuminant.Y = 0;
  icch->illuminant.Z = 0;
  icch->creator      = iccNullSig;
  memset(icch->ID, 0, 16);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int iccp_load_profile ( const char *  ident,
const void *  profile,
long  proflen 
)

Definition at line 1013 of file pdfcolor.c.

{
  int       cspc_id;
  pdf_obj  *resource;
  pdf_obj  *stream;
  pdf_obj  *stream_dict;
  iccHeader icch;
  int       colorspace;
  unsigned char checksum[16];
  struct iccbased_cdata *cdata;

  iccp_init_iccHeader(&icch);
  if (iccp_unpack_header(&icch, profile, proflen, 1) < 0) { /* check size */
    WARN("Invalid ICC profile header in \"%s\"", ident);
    print_iccp_header(&icch, NULL);
    return -1;
  }

  if (!iccp_version_supported((icch.version >> 24) & 0xff,
                           (icch.version >> 16) & 0xff)) {
    WARN("ICC profile format spec. version %d.%01d.%01d"
        " not supported in current PDF version setting.",
        (icch.version >> 24) & 0xff,
        (icch.version >> 20) & 0x0f,
        (icch.version >> 16) & 0x0f);
    WARN("ICC profile not embedded.");
    print_iccp_header(&icch, NULL);
    return -1;
  }

  if (!iccp_devClass_allowed(icch.devClass)) {
    WARN("Unsupported ICC Profile Device Class:");
    print_iccp_header(&icch, NULL);
    return -1;
  }

  if (icch.colorSpace == str2iccSig("RGB ")) {
    colorspace = PDF_COLORSPACE_TYPE_RGB;
  } else if (icch.colorSpace == str2iccSig("GRAY")) {
    colorspace = PDF_COLORSPACE_TYPE_GRAY;
  } else if (icch.colorSpace == str2iccSig("CMYK")) {
    colorspace = PDF_COLORSPACE_TYPE_CMYK;
  } else {
    WARN("Unsupported input color space.");
    print_iccp_header(&icch, NULL);
    return -1;
  }

  iccp_get_checksum(checksum, profile, proflen);
  if (memcmp(icch.ID,  nullbytes16, 16) &&
      memcmp(icch.ID,  checksum, 16)) {
    WARN("Invalid ICC profile: Inconsistent checksum.");
    print_iccp_header(&icch, checksum);
    return -1;
  }

  cdata = NEW(1, struct iccbased_cdata);
  init_iccbased_cdata(cdata);
  cdata->colorspace = colorspace;
  memcpy(cdata->checksum, checksum, 16);

  cspc_id = pdf_colorspace_findresource(ident,
                                   PDF_COLORSPACE_TYPE_ICCBASED, cdata);
  if (cspc_id >= 0) {
    if (verbose)
      MESG("(ICCP:[id=%d])", cspc_id);
    release_iccbased_cdata(cdata);
    return cspc_id;
  }
  if (verbose > 1) {
    print_iccp_header(&icch, checksum);
  }

  resource = pdf_new_array();

  stream = pdf_new_stream(STREAM_COMPRESS);
  pdf_add_array(resource, pdf_new_name("ICCBased"));
  pdf_add_array(resource, pdf_ref_obj (stream));

  stream_dict = pdf_stream_dict(stream);
  pdf_add_dict(stream_dict, pdf_new_name("N"),
              pdf_new_number(get_num_components_iccbased(cdata)));

  pdf_add_stream (stream, profile, proflen);
  pdf_release_obj(stream);

  cspc_id = pdf_colorspace_defineresource(ident,
                                     PDF_COLORSPACE_TYPE_ICCBASED,
                                     cdata, resource);

  return cspc_id;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int iccp_unpack_header ( iccHeader icch,
const void *  profile,
long  proflen,
int  check_size 
) [static]

Definition at line 760 of file pdfcolor.c.

{
  unsigned char *p, *endptr;

  if (check_size) {
    if (!profile || proflen < 128 ||
       proflen % 4 != 0) {
      WARN("Profile size: %ld", proflen);
      return -1;
    }
  }

  p      = (unsigned char *) profile;
  endptr = p + 128;

  icch->size = sget_signed_long(p);
  if (check_size) {
    if (icch->size != proflen) {
      WARN("ICC Profile size: %ld(header) != %ld", icch->size, proflen);
      return -1;
    }
  }
  p += 4;

  icch->CMMType    = str2iccSig(p);
  p += 4;
  icch->version    = sget_signed_long(p);
  p += 4;
  icch->devClass   = str2iccSig(p);
  p += 4;
  icch->colorSpace = str2iccSig(p);
  p += 4;
  icch->PCS        = str2iccSig(p);
  p += 4;
  memcpy(icch->creationDate, p, 12);
  p += 12;
  icch->acsp = str2iccSig(p); /* acsp */
  if (icch->acsp != str2iccSig("acsp")) {
    WARN("Invalid ICC profile: not \"acsp\" - %c%c%c%c ",
        p[0], p[1], p[2], p[3]);
    return -1;
  }
  p += 4;
  icch->platform = str2iccSig(p);
  p += 4;
  memcpy(icch->flags, p, 4);
  p += 4;
  icch->devMnfct = str2iccSig(p);
  p += 4;
  icch->devModel = str2iccSig(p);
  p += 4;
  memcpy(icch->devAttr,  p, 8);
  p += 8;
  icch->intent = (p[0] << 24)|(p[1] << 16)|(p[2] << 8)|p[3];
  p += 4;
  icch->illuminant.X = sget_signed_long(p);
  p += 4;
  icch->illuminant.Y = sget_signed_long(p);
  p += 4;
  icch->illuminant.Z = sget_signed_long(p);
  p += 4;
  icch->creator = str2iccSig(p);
  p += 4;
  memcpy(icch->ID, p, 16);
  p += 16;

  /* 28 bytes reserved - must be set to zeros */
  for (; p < endptr; p++) {
    if (*p != '\0') {
      WARN("Reserved pad not zero: %02x (at offset %ld in ICC profile header.)",
          *p, 128 - ((long) (endptr - p)));
      return -1;
    }
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int iccp_version_supported ( int  major,
int  minor 
) [static]

Definition at line 497 of file pdfcolor.c.

{
  int  pdf_ver;

  pdf_ver = pdf_get_version();
  if (pdf_ver < 6) {
    if (icc_versions[pdf_ver].major < major)
      return 0;
    else if (icc_versions[pdf_ver].major == major &&
            icc_versions[pdf_ver].minor <  minor)
      return 0;
    else {
      return 1;
    }
  }

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_iccbased_cdata ( struct iccbased_cdata cdata) [static]

Definition at line 610 of file pdfcolor.c.

{
  ASSERT(cdata);

  cdata->sig = ('i' << 24|'c' << 16|'c' << 8|'b');
  memset(cdata->checksum, 0, 16);
  cdata->colorspace = PDF_COLORSPACE_TYPE_INVALID;
  cdata->alternate  = -1;

  return;
}

Here is the caller graph for this function:

static void pdf_clean_colorspace_struct ( pdf_colorspace colorspace) [static]

Definition at line 1338 of file pdfcolor.c.

{
  ASSERT(colorspace);

  if (colorspace->ident)
    RELEASE(colorspace->ident);
  if (colorspace->resource)
    pdf_release_obj(colorspace->resource);
  if (colorspace->reference)
    pdf_release_obj(colorspace->reference);
  colorspace->resource  = NULL;
  colorspace->reference = NULL;

  if (colorspace->cdata) {
    switch (colorspace->subtype) {
    case PDF_COLORSPACE_TYPE_ICCBASED:
      release_iccbased_cdata(colorspace->cdata);
      break;
    }
  }
  colorspace->cdata     = NULL;
  colorspace->subtype   = PDF_COLORSPACE_TYPE_INVALID;

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_close_colors ( void  )

Definition at line 1496 of file pdfcolor.c.

{
  int  i;

  for (i = 0; i < cspc_cache.count; i++) {
    pdf_colorspace *colorspace;

    colorspace = &cspc_cache.colorspaces[i];
    pdf_flush_colorspace(colorspace);
    pdf_clean_colorspace_struct(colorspace);
  }
  RELEASE(cspc_cache.colorspaces);
  cspc_cache.colorspaces = NULL;
  cspc_cache.count = cspc_cache.capacity = 0;

}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_color_brighten_color ( pdf_color dst,
const pdf_color src,
double  f 
)

Definition at line 149 of file pdfcolor.c.

{
  ASSERT(dst && src);

  if (f == 1.0) {
    pdf_color_white(dst);
  } else {
    double f0, f1;
    int n;

    n = dst->num_components = src->num_components;
    f1 = n == 4 ? 0.0 : f;  /* n == 4 is CMYK, others are RGB and Gray */
    f0 = 1.0-f;

    while (n--)
      dst->values[n] = f0 * src->values[n] + f1;
  }
}
void pdf_color_clear_stack ( void  )

Definition at line 251 of file pdfcolor.c.

{
  if (color_stack.current > 0) {
    WARN("You've mistakenly made a global color change within nested colors.");
  }
  color_stack.current = 0;
  pdf_color_black(color_stack.stroke);
  pdf_color_black(color_stack.fill);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdf_color_cmykcolor ( pdf_color color,
double  c,
double  m,
double  y,
double  k 
)

Definition at line 89 of file pdfcolor.c.

{
  ASSERT(color);

  if (c < 0.0 || c > 1.0) {
    WARN("Invalid color value specified: cyan=%g", c);
    return -1;
  }
  if (m < 0.0 || m > 1.0) {
    WARN("Invalid color value specified: magenta=%g", m);
    return -1;
  }
  if (y < 0.0 || y > 1.0) {
    WARN("Invalid color value specified: yellow=%g", y);
    return -1;
  }
  if (k < 0.0 || k > 1.0) {
    WARN("Invalid color value specified: black=%g", k);
    return -1;
  }

  color->values[0] = c;
  color->values[1] = m;
  color->values[2] = y;
  color->values[3] = k;

  color->num_components = 4;

  return 0;
}

Here is the call graph for this function:

int pdf_color_compare ( const pdf_color color1,
const pdf_color color2 
)

Definition at line 211 of file pdfcolor.c.

{
  int n = color1->num_components;

  if (n != color2->num_components)
    return -1;

  while (n--)
    if (color1->values[n] != color2->values[n])
      return -1;

  return 0;
}

Here is the caller graph for this function:

void pdf_color_copycolor ( pdf_color color1,
const pdf_color color2 
)

Definition at line 140 of file pdfcolor.c.

{
  ASSERT(color1 && color2);

  memcpy(color1, color2, sizeof(pdf_color));
}

Here is the caller graph for this function:

void pdf_color_get_current ( pdf_color **  sc,
pdf_color **  fc 
)

Definition at line 295 of file pdfcolor.c.

{
  *sc = &color_stack.stroke[color_stack.current];
  *fc = &color_stack.fill[color_stack.current];
  return;
}

Here is the caller graph for this function:

int pdf_color_graycolor ( pdf_color color,
double  g 
)

Definition at line 122 of file pdfcolor.c.

{
  ASSERT(color);

  if (g < 0.0 || g > 1.0) {
    WARN("Invalid color value specified: gray=%g", g);
    return -1;
  }

  color->values[0] = g;

  color->num_components = 1;

  return 0;
}

Here is the call graph for this function:

int pdf_color_is_valid ( const pdf_color color)

Definition at line 226 of file pdfcolor.c.

{
  int  n;

  n = color->num_components;
  if (n != 1 && n != 3 && n != 4)
    return 0;

  while (n--)
    if (color->values[n] < 0.0 || color->values[n] > 1.0)
      return 0;

  return 1;
}

Here is the caller graph for this function:

int pdf_color_is_white ( const pdf_color color)

Definition at line 169 of file pdfcolor.c.

{
  int n;
  double f;

  ASSERT(color);

  n = color->num_components;
  f = n == 4 ? 0.0 : 1.0;  /* n == 4 is CMYK, others are RGB and Gray */

  while (n--)
    if (color->values[n] != f)
      return 0;

  return 1;
}

Here is the caller graph for this function:

void pdf_color_pop ( void  )

Definition at line 283 of file pdfcolor.c.

{
  if (color_stack.current <= 0) {
    WARN("Color stack underflow. Just ignore.");
  } else {
    color_stack.current--;
    pdf_dev_reset_color(0);
  }
  return;
}

Here is the call graph for this function:

void pdf_color_push ( pdf_color sc,
pdf_color fc 
)

Definition at line 271 of file pdfcolor.c.

{
  if (color_stack.current >= DEV_COLOR_STACK_MAX-1) {
    WARN("Color stack overflow. Just ignore.");
  } else {
    color_stack.current++;
    pdf_color_set(sc, fc);
  }
  return;
}

Here is the call graph for this function:

int pdf_color_rgbcolor ( pdf_color color,
double  r,
double  g,
double  b 
)

Definition at line 63 of file pdfcolor.c.

{
  ASSERT(color);

  if (r < 0.0 || r > 1.0) {
    WARN("Invalid color value specified: red=%g",   r);
    return -1;
  }
  if (g < 0.0 || g > 1.0) {
    WARN("Invalid color value specified: green=%g", g);
    return -1;
  }
  if (b < 0.0 || b > 1.0) {
    WARN("Invalid color value specified: blue=%g", b);
    return -1;
  }
  color->values[0] = r;
  color->values[1] = g;
  color->values[2] = b;

  color->num_components = 3;

  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_color_set ( pdf_color sc,
pdf_color fc 
)

Definition at line 263 of file pdfcolor.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_color_set_verbose ( void  )

Definition at line 46 of file pdfcolor.c.

{
  verbose++;
}

Here is the caller graph for this function:

int pdf_color_to_string ( const pdf_color color,
char *  buffer 
)

Definition at line 187 of file pdfcolor.c.

{
  int i, len = 0;

  for (i = 0; i < color->num_components; i++) {
    len += sprintf(buffer+len, " %g", ROUND(color->values[i], 0.001));
  }
  return len;
}

Here is the caller graph for this function:

int pdf_color_type ( const pdf_color color)

Definition at line 55 of file pdfcolor.c.

{
  ASSERT(color);

  return -color->num_components;
}

Here is the caller graph for this function:

int pdf_colorspace_defineresource ( const char *  ident,
int  subtype,
void *  cdata,
pdf_obj resource 
) [static]

Definition at line 1379 of file pdfcolor.c.

{
  int  cspc_id;
  pdf_colorspace *colorspace;

  if (cspc_cache.count >= cspc_cache.capacity) {
    cspc_cache.capacity   += 16;
    cspc_cache.colorspaces = RENEW(cspc_cache.colorspaces,
                               cspc_cache.capacity, pdf_colorspace);
  }
  cspc_id    = cspc_cache.count;
  colorspace = &cspc_cache.colorspaces[cspc_id];

  pdf_init_colorspace_struct(colorspace);
  if (ident) {
    colorspace->ident = NEW(strlen(ident) + 1, char);
    strcpy(colorspace->ident, ident);
  }
  colorspace->subtype  = subtype;
  colorspace->cdata    = cdata;
  colorspace->resource = resource;

  if (verbose) {
    MESG("(ColorSpace:%s", ident);
    if (verbose > 1) {
      switch (subtype) {
      case PDF_COLORSPACE_TYPE_ICCBASED:
       MESG("[ICCBased]");
       break;
      case PDF_COLORSPACE_TYPE_CALRGB:
       MESG("[CalRGB]");
       break;
      case PDF_COLORSPACE_TYPE_CALGRAY:
       MESG("[CalGray]");
       break;
      }
    }
    MESG(")");
  }

  cspc_cache.count++;

  return cspc_id;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int pdf_colorspace_findresource ( const char *  ident,
int  subtype,
const void *  cdata 
) [static]

Definition at line 1297 of file pdfcolor.c.

{
  pdf_colorspace *colorspace;
  int  cspc_id, cmp = -1;

  for (cspc_id = 0;
       cmp && cspc_id < cspc_cache.count; cspc_id++) {
    colorspace = &cspc_cache.colorspaces[cspc_id];
    if (colorspace->subtype != type)
      continue;

    switch (colorspace->subtype) {
    case PDF_COLORSPACE_TYPE_ICCBASED:
      cmp = compare_iccbased(ident, cdata,
                          colorspace->ident, colorspace->cdata);
      break;
    }
    if (!cmp)
      return cspc_id;
  }

  return -1; /* not found */
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void pdf_flush_colorspace ( pdf_colorspace colorspace) [static]

Definition at line 1365 of file pdfcolor.c.

{
  ASSERT(colorspace);

  if (colorspace->resource)
    pdf_release_obj(colorspace->resource);
  if (colorspace->reference)
    pdf_release_obj(colorspace->reference);

  colorspace->resource  = NULL;
  colorspace->reference = NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1426 of file pdfcolor.c.

{
  pdf_colorspace *colorspace;

  colorspace = &cspc_cache.colorspaces[cspc_id];
  if (!colorspace->reference) {
    colorspace->reference = pdf_ref_obj(colorspace->resource);
    pdf_release_obj(colorspace->resource); /* .... */
    colorspace->resource = NULL;
  }

  return pdf_link_obj(colorspace->reference);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pdf_init_colors ( void  )

Definition at line 1488 of file pdfcolor.c.

{
  cspc_cache.count    = 0;
  cspc_cache.capacity = 0;
  cspc_cache.colorspaces = NULL;
}

Here is the caller graph for this function:

static void pdf_init_colorspace_struct ( pdf_colorspace colorspace) [static]

Definition at line 1323 of file pdfcolor.c.

{
  ASSERT(colorspace);

  colorspace->ident     = NULL;
  colorspace->subtype   = PDF_COLORSPACE_TYPE_INVALID;

  colorspace->resource  = NULL;
  colorspace->reference = NULL;
  colorspace->cdata     = NULL;

  return;
}

Here is the caller graph for this function:

static void print_iccp_header ( iccHeader icch,
unsigned char *  checksum 
) [static]

Definition at line 875 of file pdfcolor.c.

{
  int   i;

  ASSERT(icch);

#define print_iccSig(s,t) if ((s) == 0) {\
    MESG("pdf_color>> %s:\t(null)\n", (t)); \
  } else if (!isprint(((s) >> 24) & 0xff) || \
             !isprint(((s) >> 16) & 0xff) || \
             !isprint(((s) >>  8) & 0xff) || \
             !isprint((s) & 0xff)) { \
    MESG("pdf_color>> %s:\t(invalid)\n", (t)); \
  } else { \
    MESG("pdf_color>> %s:\t%c%c%c%c\n",  (t), \
         ((s) >> 24) & 0xff, ((s) >> 16) & 0xff, \
         ((s) >>  8) & 0xff, (s) & 0xff); \
}

  MESG("\n");
  MESG("pdf_color>> ICC Profile Info\n");
  MESG("pdf_color>> Profile Size:\t%ld bytes\n", icch->size);
  print_iccSig(icch->CMMType, "CMM Type");
  MESG("pdf_color>> Profile Version:\t%d.%01d.%01d\n",
       (icch->version >> 24) & 0xff,
       (icch->version >> 20) & 0x0f,
       (icch->version >> 16) & 0x0f);
  print_iccSig(icch->devClass,   "Device Class");
  print_iccSig(icch->colorSpace, "Color Space");
  print_iccSig(icch->PCS, "Connection Space");
  MESG("pdf_color>> Creation Date:\t");
  for (i = 0; i < 12; i += 2) {
    if (i == 0)
      MESG("%04u",
          sget_unsigned_pair((unsigned char *) icch->creationDate));
    else {
      MESG(":%02u",
          sget_unsigned_pair((unsigned char *) (&icch->creationDate[i])));
    }
  }
  MESG("\n");
  print_iccSig(icch->platform, "Primary Platform");
  MESG("pdf_color>> Profile Flags:\t%02x:%02x:%02x:%02x\n",
       icch->flags[0], icch->flags[1], icch->flags[2], icch->flags[3]);
  print_iccSig(icch->devMnfct, "Device Mnfct");
  print_iccSig(icch->devModel, "Device Model");
  MESG("pdf_color>> Device Attr:\t");
  for (i = 0; i < 8; i++) {
    if (i == 0)
      MESG("%02x",  icch->devAttr[i]);
    else
      MESG(":%02x", icch->devAttr[i]);
  }
  MESG("\n");
  MESG("pdf_color>> Rendering Intent:\t");
  switch (ICC_INTENT_TYPE(icch->intent)) {
  case ICC_INTENT_SATURATION:
    MESG("Saturation");
    break;
  case ICC_INTENT_PERCEPTUAL:
    MESG("Perceptual");
    break;
  case ICC_INTENT_ABSOLUTE:
    MESG("Absolute Colorimetric");
    break;
  case ICC_INTENT_RELATIVE:
    MESG("Relative Colorimetric");
    break;
  default:
    MESG("(invalid)");
    break;
  }
  MESG("\n");
  print_iccSig(icch->creator, "Creator");
  MESG("pdf_color>> Illuminant (XYZ):\t");
  MESG("%.3f %.3f %.3f\n",
       (double) icch->illuminant.X / 0x10000,
       (double) icch->illuminant.Y / 0x10000,
       (double) icch->illuminant.Z / 0x10000);
  MESG("pdf_color>> Checksum:\t");
  if (!memcmp(icch->ID, nullbytes16, 16)) {
    MESG("(null)");
  } else {
    for (i = 0; i < 16; i++) {
      if (i == 0)
       MESG("%02x",  icch->ID[i]);
      else
       MESG(":%02x", icch->ID[i]);
    }
  }
  MESG("\n");
  if (checksum) {
    MESG("pdf_color>> Calculated:\t");
    for (i = 0; i < 16; i++) {
      if (i == 0)
       MESG("%02x", checksum[i]);
      else
       MESG(":%02x", checksum[i]);
    }
    MESG("\n");
  }

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void release_iccbased_cdata ( struct iccbased_cdata cdata) [static]

Definition at line 623 of file pdfcolor.c.

{
  ASSERT(check_sig(cdata, 'i', 'c', 'c', 'b'));

  RELEASE(cdata);
}

Here is the caller graph for this function:

static iccSig str2iccSig ( const void *  s) [static]

Definition at line 518 of file pdfcolor.c.

{
  char  *p;

  p = (char *) s;

  return (iccSig) ((p[0]<<24)|(p[1]<<16)|(p[2]<<8)|p[3]);
}

Here is the caller graph for this function:


Variable Documentation

struct { ... } color_stack [static]
struct { ... } cspc_cache [static]
Initial value:
 {
  1,
  {0.0, 0.0, 0.0, 0.0}
}

Definition at line 197 of file pdfcolor.c.

Initial value:
 {
  1,
  {0.0, 0.0, 0.0, 0.0}
}

Definition at line 202 of file pdfcolor.c.

struct { ... } icc_versions[] [static]
unsigned char nullbytes16[16] [static]
Initial value:
 {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
}

Definition at line 479 of file pdfcolor.c.

int verbose = 0 [static]

Definition at line 44 of file pdfcolor.c.