1 /* GNUPLOT - color.h */ 2 3 /* invert the gray for negative figure (default is positive) */ 4 5 /*[ 6 * 7 * Petr Mikulik, December 1998 -- June 1999 8 * Copyright: open source as much as possible 9 * 10 ]*/ 11 12 13 /* 14 In general, this file deals with colours, and in the current gnuplot 15 source layout it would correspond to structures and routines found in 16 driver.h, term.h and term.c. 17 18 Here we define structures which are required for the communication 19 of palettes between terminals and making palette routines. 20 */ 21 22 #ifndef COLOR_H 23 #define COLOR_H 24 25 #ifdef HAVE_CONFIG_H 26 # include "config.h" 27 #endif 28 29 typedef enum colortype { 30 TC_DEFAULT = 0, /* Use default color, set separately */ 31 TC_LT = 1, /* Use the color of linetype <n> */ 32 TC_LINESTYLE = 2, /* Use the color of line style <n> */ 33 TC_RGB = 3, /* Explicit RGB triple provided by user */ 34 TC_CB = 4, /* "palette cb <value>" */ 35 TC_FRAC = 5, /* "palette frac <value> */ 36 TC_Z = 6, /* "palette z" */ 37 TC_VARIABLE = 7 /* only used for "tc", never "lc" */ 38 } colortype; 39 40 /* Generalized pm3d-compatible color specifier 41 * Supplements basic linetype choice */ 42 typedef struct t_colorspec { 43 colortype type; /* TC_<type> definitions below */ 44 int lt; /* used for TC_LT, TC_LINESTYLE and TC_RGB */ 45 double value; /* used for TC_CB and TC_FRAC */ 46 } t_colorspec; 47 48 #define DEFAULT_COLORSPEC {TC_DEFAULT, 0, 0.0} 49 #define BLACK_COLORSPEC {TC_LT, LT_BLACK, 0.0} 50 #define BACKGROUND_COLORSPEC {TC_LT, LT_BACKGROUND, 0.0} 51 52 /* EAM July 2004 - Disentangle polygon support and PM3D support */ 53 /* a point (with integer coordinates) for use in polygon drawing */ 54 typedef struct { 55 int x, y; 56 int style; 57 } gpiPoint; 58 59 #include "gp_types.h" 60 #include "eval.h" 61 62 /* 63 * color modes 64 */ 65 typedef enum { 66 SMPAL_COLOR_MODE_NONE = '0', 67 SMPAL_COLOR_MODE_GRAY = 'g', /* grayscale only */ 68 SMPAL_COLOR_MODE_RGB = 'r', /* one of several fixed transforms */ 69 SMPAL_COLOR_MODE_FUNCTIONS = 'f', /* user defined transforms */ 70 SMPAL_COLOR_MODE_GRADIENT = 'd', /* interpolated table: 71 * explicitly defined or read from file */ 72 SMPAL_COLOR_MODE_CUBEHELIX = 'c' 73 } palette_color_mode; 74 75 76 /* Contains a colour in RGB scheme. 77 Values of r, g and b are all in range [0;1] */ 78 typedef struct { 79 double r, g, b; 80 } rgb_color; 81 82 /* Contains a colour in RGB scheme. 83 Values of r, g and b are uchars in range [0;255] */ 84 typedef struct { 85 unsigned char r, g, b; 86 } rgb255_color; 87 88 89 /* a point (with double coordinates) for use in polygon drawing */ 90 /* the "c" field is used only inside the routine pm3d_plot() */ 91 typedef struct { 92 double x, y, z, c; 93 } gpdPoint; 94 95 96 /* to build up gradients: whether it is really red, green and blue or maybe 97 * hue saturation and value in col depends on cmodel */ 98 typedef struct { 99 double pos; 100 rgb_color col; 101 } gradient_struct; 102 103 104 /* 105 inverting the colour for negative picture (default is positive picture) 106 (for pm3d.positive) 107 */ 108 #define SMPAL_NEGATIVE 'n' 109 #define SMPAL_POSITIVE 'p' 110 111 112 /* Declaration of smooth palette, i.e. palette for smooth colours */ 113 114 typedef struct { 115 /** Constants: **/ 116 117 /* (Fixed) number of formulae implemented for gray index to RGB 118 * mapping in color.c. Usage: somewhere in `set' command to check 119 * that each of the below-given formula R,G,B are lower than this 120 * value. */ 121 int colorFormulae; 122 123 /** Values that can be changed by `set' and shown by `show' commands: **/ 124 125 /* can be SMPAL_COLOR_MODE_GRAY or SMPAL_COLOR_MODE_RGB */ 126 palette_color_mode colorMode; 127 /* mapping formulae for SMPAL_COLOR_MODE_RGB */ 128 int formulaR, formulaG, formulaB; 129 char positive; /* positive or negative figure */ 130 131 /* Now the variables that contain the discrete approximation of the 132 * desired palette of smooth colours as created by make_palette in 133 * pm3d.c. This is then passed into terminal's make_palette, who 134 * transforms this [0;1] into whatever it supports. */ 135 136 /* Only this number of colour positions will be used even though 137 * there are some more available in the discrete palette of the 138 * terminal. Useful for multiplot. Max. number of colours is taken 139 * if this value equals 0. Unused by: PostScript */ 140 int use_maxcolors; 141 /* Number of colours used for the discrete palette. Equals to the 142 * result from term->make_palette(NULL), or restricted by 143 * use_maxcolor. Used by: pm, gif. Unused by: PostScript */ 144 int colors; 145 /* Table of RGB triplets resulted from applying the formulae. Used 146 * in the 2nd call to term->make_palette for a terminal with 147 * discrete colours. Unused by PostScript which calculates them 148 * analytically. */ 149 rgb_color *color; 150 151 /** Variables used by some terminals **/ 152 153 /* Option unique for output to PostScript file. By default, 154 * ps_allcF=0 and only the 3 selected rgb color formulae are written 155 * into the header preceding pm3d map in the file. If ps_allcF is 156 * non-zero, then print there all color formulae, so that it is easy 157 * to play with choosing manually any color scheme in the PS file 158 * (see the definition of "/g"). Like that you can get the 159 * Rosenbrock multiplot figure on my gnuplot.html#pm3d demo page. 160 * Note: this option is used by all terminals of the postscript 161 * family, i.e. postscript, pslatex, epslatex, so it will not be 162 * comfortable to move it to the particular .trm files. */ 163 TBOOLEAN ps_allcF; 164 165 /* These variables are used to define interpolated color palettes: 166 * gradient is an array if (gray,color) pairs. This array is 167 * gradient_num entries big. 168 * Interpolated tables are used if colorMode==SMPAL_COLOR_MODE_GRADIENT */ 169 int gradient_num; 170 gradient_struct *gradient; 171 /* Smallest nonzero gradient[i+1] - gradient[i]. If this is < (1/colors) 172 * Then a truncated gray value may miss the gradient it belongs in. */ 173 double smallest_gradient_interval; 174 175 /* the used color model: RGB, HSV, XYZ, etc. */ 176 int cmodel; 177 178 /* Three mapping function for gray->RGB/HSV/XYZ/etc. mapping 179 * used if colorMode == SMPAL_COLOR_MODE_FUNCTIONS */ 180 struct udft_entry Afunc; /* R for RGB, H for HSV, C for CMY, ... */ 181 struct udft_entry Bfunc; /* G for RGB, S for HSV, M for CMY, ... */ 182 struct udft_entry Cfunc; /* B for RGB, V for HSV, Y for CMY, ... */ 183 184 /* gamma for gray scale and cubehelix palettes only */ 185 double gamma; 186 187 /* control parameters for the cubehelix palette scheme */ 188 double cubehelix_start; /* offset (radians) from colorwheel 0 */ 189 double cubehelix_cycles; /* number of times round the colorwheel */ 190 double cubehelix_saturation; /* color saturation */ 191 192 } t_sm_palette; 193 194 195 196 /* GLOBAL VARIABLES */ 197 198 extern t_sm_palette sm_palette; 199 200 201 /* ROUTINES */ 202 203 204 void init_color(void); /* call once to initialize variables */ 205 206 207 /* 208 Make the colour palette. Return 0 on success 209 Put number of allocated colours into sm_palette.colors 210 */ 211 int make_palette(void); 212 213 void invalidate_palette(void); 214 215 /* 216 Send current colour to the terminal 217 */ 218 void set_color( double gray ); 219 void set_rgbcolor_var( unsigned int rgbvalue ); 220 void set_rgbcolor_const( unsigned int rgbvalue ); 221 222 /* 223 Draw colour smooth box 224 */ 225 void draw_color_smooth_box(int plot_mode); 226 227 /* 228 Support for user-callable routines 229 */ 230 void f_hsv2rgb(union argument *); 231 void f_palette(union argument *); 232 233 #endif /* COLOR_H */ 234 235 /* eof color.h */ 236