26.4 Decomposition

For devices that wish to get access to a higher level representation of a shading, but do not wish to access the internals of a shading directly, we provide a function to decompose a shading to a mesh.

This is called with functions to ‘prepare’ and ‘fill’ vertices respectively. The mesh is decomposed to triangles internally, each vertex is ‘prepared’ and each triangle ‘filled’ in turn.

The ordering of these calls is not guaranteed, other than the fact that a vertex will always be prepared before it is used as part of a triangle to be filled.

typedef struct fz_vertex_s fz_vertex; 
 
struct fz_vertex_s 
{ 
   fz_point p; 
   float c[FZ_MAX_COLORS]; 
}; 
 
/* 
   fz_shade_prepare_fn: Callback function type for use with 
   fz_process_shade. 
 
   arg: Opaque pointer from fz_process_shade caller. 
 
   v: Pointer to a fz_vertex structure to populate. 
 
   c: Pointer to an array of floats to use to populate v. 
*/ 
typedef void (fz_shade_prepare_fn)(fz_context *ctx, void *arg, fz_vertex *v, const float *c); 
 
/* 
   fz_shade_process_fn: Callback function type for use with 
   fz_process_shade. 
 
   arg: Opaque pointer from fz_process_shade caller. 
 
   av, bv, cv: Pointers to a fz_vertex structure describing 
   the corner locations and colors of a triangle to be 
   filled. 
*/ 
typedef void (fz_shade_process_fn)(fz_context *ctx, void *arg, fz_vertex *av, fz_vertex *bv, fz_vertex *cv); 
 
/* 
   fz_process_shade: Process a shade, using supplied callback 
   functions. This decomposes the shading to a mesh (even ones 
   that are not natively meshes, such as linear or radial 
   shadings), and processes triangles from those meshes. 
 
   shade: The shade to process. 
 
   ctm: The transform to use 
 
   prepare: Callback function to prepare each vertex. 
   This function is passed an array of floats, and populates 
   an fz_vertex structure. 
 
   process: This function is passed 3 pointers to vertex 
   structures, and actually performs the processing (typically 
   filling the area between the vertexes). 
 
   process_arg: An opaque argument passed through from caller 
   to callback functions. 
*/ 
void fz_process_shade(fz_context *ctx, fz_shade *shade, const fz_matrix *ctm, 
         fz_shade_prepare_fn *prepare, fz_shade_process_fn *process, void *process_arg);

This function is used internally as part of fz_paint_shade, but is intended to also allow extraction of arbitrary shading data.