Return to index

NAME

c_hcolor, c_getcolor, c_ccname, c_ccolor, c_ccvt, c_isgrey - color entity support

SYNOPSIS

#include "parser.h"

int c_hcolor( int argc, char **argv )

C_COLOR *c_getcolor( char *name )

extern char *c_ccname

extern C_COLOR *c_ccolor

void c_ccvt( C_COLOR *cvp, int cflags )

int c_isgrey( C_COLOR *cvp )

DESCRIPTION

The c_hcolor function supports the MGF entities, c, cxy, cspec, cct and cmix. It is an error to support any of the color field entities without supporting the c entity itself. The assignments are normally made to the mg_ehand array prior to parser initialization, like so:

mg_ehand[MG_E_COLOR] = c_hcolor;	/* support "c" entity */
mg_ehand[MG_E_CXY] = c_hcolor;		/* support "cxy" entity */
mg_ehand[MG_E_CSPEC] = c_hcolor;	/* support "cspec" entity */
mg_ehand[MG_E_CCT] = c_hcolor;		/* support "cct" entity */
mg_ehand[MG_E_CMIX] = c_hcolor;		/* support "cmix" entity */
/* other entity handler assignments... */
mg_init();			/* initialize parser */
If the loader/translator has no use for spectral data, the entries for cspec and cct may be left with their original NULL assignments and these entities will be re-expressed appropriately as tristimulus values.

The c_getcolor function takes the name of a defined color and returns a pointer to its C_COLOR structure, defined in "parser.h" as:

#define C_CMINWL	380		/* minimum wavelength */
#define C_CMAXWL	780		/* maximum wavelength */
#define C_CNSS		41		/* number of spectral samples */
#define C_CWLI		((C_CMAXWL-C_CMINWL)/(C_CNSS-1))
#define C_CMAXV		10000		/* nominal maximum sample value */
#define C_CLPWM		(683./C_CMAXV)	/* peak lumens/watt multiplier */

typedef struct {
	int	clock;			/* incremented each change */
	short	flags;			/* what's been set */
	short	ssamp[C_CNSS];		/* spectral samples, min wl to max */
	long	ssum;			/* straight sum of spectral values */
	float	cx, cy;			/* xy chromaticity value */
	float	eff;			/* efficacy (lumens/watt) */
} C_COLOR;		/* color context */
The clock member will be incremented each time the value gets changed by a color field entity, and may be reset by the calling program if desired. This is a convenient way to keep track of whether or not a color has changed since its last use. The flags member indicates which color representations have been assigned, and is an inclusive OR of one or more of the following:

#define C_CSSPEC	01		/* flag if spectrum is set */
#define C_CDSPEC	02		/* flag if defined w/ spectrum */
#define C_CSXY		04		/* flag if xy is set */
#define C_CDXY		010		/* flag if defined w/ xy */
#define C_CSEFF		020		/* flag if efficacy set */

It is possible but not recommended to alter the contents of the color structure returned by c_getcolor. Normally, this routine is never called directly, since there are no entities that access colors by name other than c.

The global variable c_ccname points to the name of the current color, or NULL if it is unnamed. The variable c_ccolor points to the current color value, which should never be NULL.

The c_ccvt routine takes a C_COLOR structure and a set of desired flag settings and computes the missing color representation(s).

The c_isgrey function returns 1 if the passed color is very close to neutral grey, or 0 otherwise.

DIAGNOSTICS

The c_hcolor function returns MG_OK (0) if the color is handled correctly, or one of the predefined error values if there is a problem. (See the mg_load page for a list of errors.)

The c_getcolor function returns NULL if the specified color name is undefined, at which point the calling function should return an MG_EUNDEF error.

SEE ALSO

c_hmaterial, c_hvertex, mg_init, mg_load