10.2 Colorspaces

In order to represent a given color for a graphical object, we need both the color component values and details of the colorspace that the color is specified in. Color values are defined simply as floats (normally between 0 and 1 inclusive), and colorspaces are defined using the fz_colorspace structure.

As with many other such structures in MuPDF, these are reference counted objects (see section 21.3 Reference Counting).

10.2.1 Basic Colorspaces

MuPDF contains a set of inbuilt colorspaces that cover most simple requirements. These are the ‘device’ colorspaces:

/* 
   fz_device_gray: Get colorspace representing device specific gray. 
*/ 
fz_colorspace *fz_device_gray(fz_context *ctx); 
 
/* 
   fz_device_rgb: Get colorspace representing device specific rgb. 
*/ 
fz_colorspace *fz_device_rgb(fz_context *ctx); 
 
/* 
   fz_device_bgr: Get colorspace representing device specific bgr. 
*/ 
fz_colorspace *fz_device_bgr(fz_context *ctx); 
 
/* 
   fz_device_cmyk: Get colorspace representing device specific CMYK. 
*/ 
fz_colorspace *fz_device_cmyk(fz_context *ctx); 
 
/* 
   fz_device_lab: Get colorspace representing device specific LAB. 
*/ 
fz_colorspace *fz_device_lab(fz_context *ctx);

10.2.2 Indexed Colorspaces

MuPDF allows for indexed colorspaces - those where a palette is used to select color values from a (normally) larger colorspace.

These are created using the fz_new_indexed_colorspace call:

fz_colorspace *fz_new_indexed_colorspace(fz_context *ctx, fz_colorspace *base, int high, unsigned char *lookup);

10.2.3 Separation and DeviceN Colorspaces

MuPDF Colorspaces are extensible, so specific document handlers can implement their own new spaces. A good example of this is how PDF implements Separation and DeviceN colorspaces.

These are special spaces which represent arbitrary sets of 1 or more colorants. These can either be mapped down to ‘equivalent’ colors in a more standard space, or (depending on the capabilities of the underlying device) processed in their raw form.

10.2.4 Further information

Further information on Colorspaces can be found within chapter 29 Colorspace Internals.