Back to index

texmacs  1.0.7.15
Classes | Defines | Functions
pdfcolor.h File Reference
#include "pdfobj.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  pdf_color

Defines

#define PDF_COLORSPACE_TYPE_DEVICECMYK   -4
#define PDF_COLORSPACE_TYPE_DEVICERGB   -3
#define PDF_COLORSPACE_TYPE_DEVICEGRAY   -1
#define PDF_COLORSPACE_TYPE_INVALID   0
#define PDF_COLORSPACE_TYPE_CALGRAY   1
#define PDF_COLORSPACE_TYPE_CIELAB   2
#define PDF_COLORSPACE_TYPE_CALRGB   3
#define PDF_COLORSPACE_TYPE_ICCBASED   4
#define PDF_COLORSPACE_TYPE_CMYK   PDF_COLORSPACE_TYPE_DEVICECMYK
#define PDF_COLORSPACE_TYPE_RGB   PDF_COLORSPACE_TYPE_DEVICERGB
#define PDF_COLORSPACE_TYPE_GRAY   PDF_COLORSPACE_TYPE_DEVICEGRAY
#define PDF_COLOR_COMPONENT_MAX   4
#define pdf_color_black(c)   pdf_color_graycolor(c, 0.0);
#define pdf_color_white(c)   pdf_color_graycolor(c, 1.0);

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_compare (const pdf_color *color1, const pdf_color *color2)
int pdf_color_is_white (const pdf_color *color)
int pdf_color_is_valid (const pdf_color *color)
int pdf_color_to_string (const pdf_color *color, char *buffer)
pdf_objiccp_get_rendering_intent (const void *profile, long proflen)
int iccp_check_colorspace (int colortype, const void *profile, long proflen)
int iccp_load_profile (const char *ident, const void *profile, long proflen)
void pdf_init_colors (void)
void pdf_close_colors (void)
pdf_objpdf_get_colorspace_reference (int cspc_id)
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_clear_stack (void)
void pdf_color_get_current (pdf_color **sc, pdf_color **fc)

Class Documentation

struct pdf_color

Definition at line 46 of file pdfcolor.h.

Class Members
int num_components
double values

Define Documentation

#define pdf_color_black (   c)    pdf_color_graycolor(c, 0.0);

Definition at line 60 of file pdfcolor.h.

#define PDF_COLOR_COMPONENT_MAX   4

Definition at line 44 of file pdfcolor.h.

#define pdf_color_white (   c)    pdf_color_graycolor(c, 1.0);

Definition at line 61 of file pdfcolor.h.

Definition at line 34 of file pdfcolor.h.

Definition at line 36 of file pdfcolor.h.

Definition at line 35 of file pdfcolor.h.

Definition at line 39 of file pdfcolor.h.

Definition at line 30 of file pdfcolor.h.

Definition at line 32 of file pdfcolor.h.

Definition at line 31 of file pdfcolor.h.

Definition at line 41 of file pdfcolor.h.

Definition at line 37 of file pdfcolor.h.

Definition at line 33 of file pdfcolor.h.

Definition at line 40 of file pdfcolor.h.


Function Documentation

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:

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:

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:

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:

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: