Changed russian description a little bit
[gnuplot] / src / color.h
1 /*
2  * $Id: color.h,v 1.29.2.2 2008/09/29 05:32:14 mikulik Exp $
3  */
4
5 /* GNUPLOT - color.h */
6
7 /* invert the gray for negative figure (default is positive) */
8
9 /*[
10  *
11  * Petr Mikulik, December 1998 -- June 1999
12  * Copyright: open source as much as possible
13  *
14 ]*/
15
16
17 /*
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.
21
22 Here we define structures which are required for the communication
23 of palettes between terminals and making palette routines.
24 */
25
26 #ifndef COLOR_H
27 #define COLOR_H
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
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 */
39 } t_colorspec;
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" */
47
48 #define DEFAULT_COLORSPEC {TC_DEFAULT, 0, 0.0}
49
50 #ifdef EXTENDED_COLOR_SPECS
51 typedef struct {
52     double gray;
53     /* to be extended */
54 } colorspec_t;
55 #endif
56
57 /* EAM July 2004 - Disentangle polygon support and PM3D support  */
58 /* a point (with integer coordinates) for use in polygon drawing */
59 typedef struct {
60     int x, y;
61 #ifdef EXTENDED_COLOR_SPECS
62     double z;
63     colorspec_t spec;
64 #endif
65     int style;
66 } gpiPoint;
67
68 #include "gp_types.h"
69 #include "eval.h"
70
71 /*
72  *    color modes
73  */
74 typedef enum {
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 */
81 } palette_color_mode;
82
83
84 /* Contains a colour in RGB scheme.
85    Values of  r, g and b  are all in range [0;1] */
86 typedef struct {
87     double r, g, b;
88 } rgb_color;
89
90 /* Contains a colour in RGB scheme.
91    Values of  r, g and b  are uchars in range [0;255] */
92 typedef struct {
93     unsigned char r, g, b;
94 } rgb255_color;
95
96
97 /* a point (with double coordinates) for use in polygon drawing */
98 /* the "c" field is used only inside the routine pm3d_plot() */
99 typedef struct {
100     double x, y, z, c;
101 } gpdPoint;
102
103
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 */
106 typedef struct {
107   double pos;
108   rgb_color col;
109 } gradient_struct;
110
111
112 /*
113   inverting the colour for negative picture (default is positive picture)
114   (for pm3d.positive)
115 */
116 #define SMPAL_NEGATIVE  'n'
117 #define SMPAL_POSITIVE  'p'
118
119
120 /* Declaration of smooth palette, i.e. palette for smooth colours */
121
122 typedef struct {
123   /** Constants: **/
124
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
128    * value. */
129   int colorFormulae;
130
131   /** Values that can be changed by `set' and shown by `show' commands: **/
132
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 */
138
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.  */
143
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 */
148   int use_maxcolors;
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 */
152   int colors;
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
156    * analytically. */
157   rgb_color *color;
158
159   /** Variables used by some terminals **/
160
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. */
171   char ps_allcF;
172
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 */
177   int gradient_num;
178   gradient_struct *gradient;
179
180   /* the used color model: RGB, HSV, XYZ, etc. */
181   int cmodel;
182
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, ... */
188
189   /* gamma for gray scale palettes only */
190   double gamma;
191 } t_sm_palette;
192
193
194
195 /* GLOBAL VARIABLES */
196
197 extern t_sm_palette sm_palette;
198
199 #ifdef EXTENDED_COLOR_SPECS
200 extern int supply_extended_color_specs;
201 #endif
202
203
204 /* ROUTINES */
205
206
207 void init_color __PROTO((void));  /* call once to initialize variables */
208
209
210 /*
211   Make the colour palette. Return 0 on success
212   Put number of allocated colours into sm_palette.colors
213 */
214 int make_palette __PROTO((void));
215
216 void invalidate_palette __PROTO((void));
217
218 /*
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
223 */
224 void set_color __PROTO(( double gray ));
225 void set_rgbcolor __PROTO(( int rgblt ));
226
227 void ifilled_quadrangle __PROTO((gpiPoint* icorners));
228
229 /*
230    The routine above for 4 points explicitly
231 */
232 #ifdef EXTENDED_COLOR_SPECS
233 void filled_quadrangle __PROTO((gpdPoint *corners, gpiPoint* icorners));
234 #else
235 void filled_quadrangle __PROTO((gpdPoint *corners));
236 #endif
237
238 /*
239    Makes mapping from real 3D coordinates, passed as coords array,
240    to 2D terminal coordinates, then draws filled polygon
241 */
242 /* HBB 20010216: added 'GPHUGE' attribute */
243 void filled_polygon_3dcoords __PROTO((int points, struct coordinate GPHUGE *coords));
244
245 /*
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
248 */
249 void filled_polygon_3dcoords_zfixed __PROTO((int points, struct coordinate GPHUGE *coords, double z));
250
251 /*
252   Draw colour smooth box
253 */
254 void draw_color_smooth_box __PROTO((int plot_mode));
255
256
257 #endif /* COLOR_H */
258
259 /* eof color.h */