30.1 Overview

MuPDF can optionally make use of a color management engine to offer a fully color managed workflow.

Its use of the engine is encapsulated within the fz_cmm_engine structure. Currently we provide an implementation of this structure using a modified version of LCMS2 (known as LCMS2MT), but systems with other CMM engines in already can use those instead by reimplementing the functions therein.

By default, on start-up, MuPDF has no color management engine enabled. This keeps the library size down (and performance up!) for people who do not wish to use it.

The relevant functions are:

/* 
   fz_set_cmm_engine: Set the color management engine to 
   be used. This should only ever be called on the "base" 
   context before cloning it, and before opening any files. 
 
   Attempting to change the engine in use once a file has 
   been opened, or to use different color management engine 
   for the same file in different threads will lead to 
   undefined behaviour, including crashing. 
 
   Using different ICC engines for different files using 
   different sets of fz_contexts should theoretically be 
   possible. 
*/ 
void fz_set_cmm_engine(fz_context *ctx, const fz_cmm_engine *engine); 
 
/* 
   Currently we only provide a single color management 
   engine, based on a (modified) LCMS2. 
 
   An unmodified LCMS2 should work too, but only when restricted 
   to a single thread. 
*/ 
extern fz_cmm_engine fz_cmm_engine_lcms;

Thus to enable the color managed workflow using LCMS, call:

fz_set_cmm_engine(ctx, &fz_cmm_engine_lcms);

It is best to do this immediately after creating the base context.

It is possible to switch between ICC and non-ICC workflows in the same instance of MuPDF (and even to use the two simultaneously). It is, however, not generally possible to swap a given context once operations on that context have started. This is because any outstanding fz_colorspaces (such as those found within the store) will still refer to the wrong color management implementation!