[cairo] [RFC] Color space API (partial proposal)

Adrian Johnson ajohnson at redneon.com
Fri Feb 26 06:15:07 PST 2010

Chris Murphy wrote:
> And to put a clearer point on this, I think you are fine 
> implementing case #1 and case #2. I don't think you need to beat 
> yourselves up supporting DeviceN output profiles, and such complex 
> designs from applications. If you first get to CMYK, and then CMYK +
>  2 spots. I think that's the vast majority of printing going on, 
> where special objects (like logos or vector art) are the only 
> objects that utilize either of the two spots. This would not 
> disallow artists from forcing interaction of all six colorants, and
>  producing valid PDF. Previewing and printing them is another matter
>  and while I'd like the PDF to be self-documenting how to properly 
> preview and print it, that's presently not the case as far as I'm 
> aware.
> The Hexachrome workflow, with six primaries, is challenging even 
> with existing professional applications so I'd get the CMYK + spot 
> stuff working before even considering 5+ channel color separations 
> with DeviceN output profiles.

For case #1 (CMYK). The API proposed at [1] should handle
this. Is there anything incorrect or missing? An example of usage would be:

/* Create a PDF surface and cairo context */

  surface = cairo_pdf_surface_create ("file.pdf", 595, 842);
  cr = cairo_create (surface);

/* Set a CMYK profile to be used as the page color space
  * (and blending space)

  dest_col_space = cairo_color_space_create_icc_from_file
  cairo_surface_set_color_space (surface, dest_col_space);

/* Create a color in the same CMYK color space as the page
  * and draw a rectangle.

  double cmyk[4] = { 0.1, 0.2, 0.3, 0.4 };
  c = cairo_color_create (dest_col_space, &cmyk);
  cairo_set_source_color (cr, c);
  cairo_rectangle (cr, 10, 10, 20, 20);
  cairo_fill (cr);

/* We can also create a color in a different color space
  * such as sRGB to draw another rectangle

  srgb_col_space = cairo_color_space_create_icc_from_file ("sRGB.icc");
  double rgb[3] = { 0.1, 0.2, 0.3 };
  c = cairo_color_create (srgb_col_space, &rgb);
  cairo_set_source_color (cr, c);
  cairo_rectangle (cr, 40, 10, 20, 20);
  cairo_fill (cr);

For case #2 (CMYK + spot) we need API for creating spot colors. To do
this we need to specify the name of the spot color, the alternate
color space for simulating the spot for when the output device does not
support it, and the tint transform to specify the alternate color for
any given tint value between 0 and 1.

Do you have any suggestions on what the API should look like?

One possibility for specifying the alternate color space and tint
transform would be to specify two colors and linearly interpolate
between the colors for tint values between 0 and 1.

For example:

cairo_color_space_t *
cairo_color_space_create_spot (const char    *name,
                                cairo_color_t *first_color,
                                cairo_color_t *second_color);

where first_color and second_color must be in the same color space.
The color space of first_color/second_color will be used as the
alternate color space. The tint transform will map tint values between 
0 and 1 to the linear interpolation between first_color and


cairo_color_space_t *
cairo_color_space_create_spot (const char    *name,
                       cairo_color_space_t *alternate_color_space,
                       double              *first_color,
                       double              *second_color);

In this case the alternate color space is specified directly along with
the component values for the first and second colors.

[1] http://lists.cairographics.org/archives/cairo/2010-February/019352.html

More information about the cairo mailing list