2 * $Id: color.h,v 1.29.2.2 2008/09/29 05:32:14 mikulik Exp $
5 /* GNUPLOT - color.h */
7 /* invert the gray for negative figure (default is positive) */
11 * Petr Mikulik, December 1998 -- June 1999
12 * Copyright: open source as much as possible
18 In general, this file deals with colours, and in the current gnuplot
19 source layout it would correspond to structures and routines found in
20 driver.h, term.h and term.c.
22 Here we define structures which are required for the communication
23 of palettes between terminals and making palette routines.
33 /* Generalized pm3d-compatible color specifier
34 * Supplements basic linetype choice */
35 typedef struct t_colorspec {
36 int type; /* TC_<type> definitions below */
37 int lt; /* used for TC_LT, TC_LINESTYLE and TC_RGB */
38 double value; /* used for TC_CB and TC_FRAC */
40 #define TC_DEFAULT 0 /* Use default color, set separately */
41 #define TC_LT 1 /* Use the color of linetype <n> */
42 #define TC_LINESTYLE 2 /* Use the color of line style <n> */
43 #define TC_RGB 3 /* Explicit RGB triple provided by user */
44 #define TC_CB 4 /* "palette cb <value>" */
45 #define TC_FRAC 5 /* "palette frac <value> */
46 #define TC_Z 6 /* "palette z" */
48 #define DEFAULT_COLORSPEC {TC_DEFAULT, 0, 0.0}
50 #ifdef EXTENDED_COLOR_SPECS
57 /* EAM July 2004 - Disentangle polygon support and PM3D support */
58 /* a point (with integer coordinates) for use in polygon drawing */
61 #ifdef EXTENDED_COLOR_SPECS
75 SMPAL_COLOR_MODE_NONE = '0',
76 SMPAL_COLOR_MODE_GRAY = 'g', /* grayscale only */
77 SMPAL_COLOR_MODE_RGB = 'r', /* one of several fixed transforms */
78 SMPAL_COLOR_MODE_FUNCTIONS = 'f', /* user defined transforms */
79 SMPAL_COLOR_MODE_GRADIENT = 'd' /* interpolated table:
80 * explicitly defined or read from file */
84 /* Contains a colour in RGB scheme.
85 Values of r, g and b are all in range [0;1] */
90 /* Contains a colour in RGB scheme.
91 Values of r, g and b are uchars in range [0;255] */
93 unsigned char r, g, b;
97 /* a point (with double coordinates) for use in polygon drawing */
98 /* the "c" field is used only inside the routine pm3d_plot() */
104 /* to build up gradients: whether it is really red, green and blue or maybe
105 * hue saturation and value in col depends on cmodel */
113 inverting the colour for negative picture (default is positive picture)
116 #define SMPAL_NEGATIVE 'n'
117 #define SMPAL_POSITIVE 'p'
120 /* Declaration of smooth palette, i.e. palette for smooth colours */
125 /* (Fixed) number of formulae implemented for gray index to RGB
126 * mapping in color.c. Usage: somewhere in `set' command to check
127 * that each of the below-given formula R,G,B are lower than this
131 /** Values that can be changed by `set' and shown by `show' commands: **/
133 /* can be SMPAL_COLOR_MODE_GRAY or SMPAL_COLOR_MODE_RGB */
134 palette_color_mode colorMode;
135 /* mapping formulae for SMPAL_COLOR_MODE_RGB */
136 int formulaR, formulaG, formulaB;
137 char positive; /* positive or negative figure */
139 /* Now the variables that contain the discrete approximation of the
140 * desired palette of smooth colours as created by make_palette in
141 * pm3d.c. This is then passed into terminal's make_palette, who
142 * transforms this [0;1] into whatever it supports. */
144 /* Only this number of colour positions will be used even though
145 * there are some more available in the discrete palette of the
146 * terminal. Useful for multiplot. Max. number of colours is taken
147 * if this value equals 0. Unused by: PostScript */
149 /* Number of colours used for the discrete palette. Equals to the
150 * result from term->make_palette(NULL), or restricted by
151 * use_maxcolor. Used by: pm, gif. Unused by: PostScript */
153 /* Table of RGB triplets resulted from applying the formulae. Used
154 * in the 2nd call to term->make_palette for a terminal with
155 * discrete colours. Unused by PostScript which calculates them
159 /** Variables used by some terminals **/
161 /* Option unique for output to PostScript file. By default,
162 * ps_allcF=0 and only the 3 selected rgb color formulae are written
163 * into the header preceding pm3d map in the file. If ps_allcF is
164 * non-zero, then print there all color formulae, so that it is easy
165 * to play with choosing manually any color scheme in the PS file
166 * (see the definition of "/g"). Like that you can get the
167 * Rosenbrock multiplot figure on my gnuplot.html#pm3d demo page.
168 * Note: this option is used by all terminals of the postscript
169 * family, i.e. postscript, pslatex, epslatex, so it will not be
170 * comfortable to move it to the particular .trm files. */
173 /* These variables are used to define interpolated color palettes:
174 * gradient is an array if (gray,color) pairs. This array is
175 * gradient_num entries big.
176 * Interpolated tables are used if colorMode==SMPAL_COLOR_MODE_GRADIENT */
178 gradient_struct *gradient;
180 /* the used color model: RGB, HSV, XYZ, etc. */
183 /* Three mapping function for gray->RGB/HSV/XYZ/etc. mapping
184 * used if colorMode == SMPAL_COLOR_MODE_FUNCTIONS */
185 struct udft_entry Afunc; /* R for RGB, H for HSV, C for CMY, ... */
186 struct udft_entry Bfunc; /* G for RGB, S for HSV, M for CMY, ... */
187 struct udft_entry Cfunc; /* B for RGB, V for HSV, Y for CMY, ... */
189 /* gamma for gray scale palettes only */
195 /* GLOBAL VARIABLES */
197 extern t_sm_palette sm_palette;
199 #ifdef EXTENDED_COLOR_SPECS
200 extern int supply_extended_color_specs;
207 void init_color __PROTO((void)); /* call once to initialize variables */
211 Make the colour palette. Return 0 on success
212 Put number of allocated colours into sm_palette.colors
214 int make_palette __PROTO((void));
216 void invalidate_palette __PROTO((void));
219 Set the colour on the terminal
220 Currently, each terminal takes care of remembering the current colour,
221 so there is not much to do here---well, except for reversing the gray
222 according to sm_palette.positive == SMPAL_POSITIVE or SMPAL_NEGATIVE
224 void set_color __PROTO(( double gray ));
225 void set_rgbcolor __PROTO(( int rgblt ));
227 void ifilled_quadrangle __PROTO((gpiPoint* icorners));
230 The routine above for 4 points explicitly
232 #ifdef EXTENDED_COLOR_SPECS
233 void filled_quadrangle __PROTO((gpdPoint *corners, gpiPoint* icorners));
235 void filled_quadrangle __PROTO((gpdPoint *corners));
239 Makes mapping from real 3D coordinates, passed as coords array,
240 to 2D terminal coordinates, then draws filled polygon
242 /* HBB 20010216: added 'GPHUGE' attribute */
243 void filled_polygon_3dcoords __PROTO((int points, struct coordinate GPHUGE *coords));
246 Makes mapping from real 3D coordinates, passed as coords array, but at z coordinate
247 fixed (base_z, for instance) to 2D terminal coordinates, then draws filled polygon
249 void filled_polygon_3dcoords_zfixed __PROTO((int points, struct coordinate GPHUGE *coords, double z));
252 Draw colour smooth box
254 void draw_color_smooth_box __PROTO((int plot_mode));