home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnuplapi.zip / gnuplot-api-os2 / build / color.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-15  |  6.3 KB  |  233 lines

  1.     /* invert the gray for negative figure (default is positive) */
  2.  
  3.  
  4. /* GNUPLOT - color.h */
  5.  
  6. /*[
  7.  *
  8.  * Petr Mikulik, December 1998 -- June 1999
  9.  * Copyright: open source as much as possible
  10.  *
  11. ]*/
  12.  
  13.  
  14. /*
  15. In general, this file deals with colours, and in the current gnuplot
  16. source layout it would correspond structures and routines found in
  17. driver.h, term.h and term.c.
  18.  
  19. Here we define structures which are required for the communication
  20. of palettes between terminals and making palette routines.
  21. */
  22.  
  23.  
  24. /** NOTICE: currently, this file is included only if PM3D is defined **/
  25. #ifdef PM3D
  26.  
  27. #ifndef COLOR_H
  28. #define COLOR_H
  29.  
  30.  
  31. /* Contains a colour in RGB scheme.
  32.    Values of  r, g and b  are all in range [0;1] */
  33. typedef struct {
  34.   double r, g, b;
  35.   } rgb_color;
  36.  
  37.  
  38. /* a point (with integer coordinates) for use in polygon drawing */
  39. typedef struct {
  40.     int x, y;
  41. } gpiPoint;
  42.  
  43.  
  44. /* a point (with double coordinates) for use in polygon drawing */
  45. typedef struct {
  46.     double x, y, z;
  47. } gpdPoint;
  48.  
  49.  
  50. /*
  51.    colour modes
  52. */
  53.  
  54. #define SMPAL_COLOR_MODE_GRAY 'g'
  55. #define SMPAL_COLOR_MODE_RGB  'r'
  56.  
  57. /*
  58.   inverting the colour for negative picture (default is positive picture)
  59.   (for pm3d.positive)
  60. */
  61. #define SMPAL_NEGATIVE  'n'
  62. #define SMPAL_POSITIVE  'p'
  63.  
  64.  
  65. /* Declaration of smooth palette, i.e. palette for smooth colours */
  66.  
  67. typedef struct {
  68.   /** Constants: **/
  69.   int colorFormulae;
  70.     /*
  71.     (fixed) number of formulae implemented for gray index to RGB mapping in
  72.     pm3d.c:double pm3dGetColorValue(..) + post.trm: PostScriptColorFormulae[]
  73.     Usage: somewhere in `set' command to check that each of the below-given
  74.     formula R,G,B are lower than this value
  75.     */
  76.  
  77.   /** Values that can be changed by `set' and shown by `show' commands: **/
  78.   char colorMode;
  79.     /* can be SMPAL_COLOR_MODE_GRAY or SMPAL_COLOR_MODE_RGB */
  80.   int formulaR, formulaG, formulaB;
  81.     /* mapping formulae for SMPAL_COLOR_MODE_RGB */
  82.   char positive;
  83.     /* positive, negative figure */
  84.  
  85.   /* Now the variables that contain the discrete approximation of the
  86.   desired palette of smooth colours as created by make_palette in pm3d.c.
  87.   This is then passed into terminal's make_palette, who transforms
  88.   this [0;1] into whatever it supports
  89.   */
  90.  
  91.   int use_maxcolors;
  92.     /* only this number of colour positions will be used even though there
  93.          are some more available in the discrete palette of the terminal.
  94.        Useful for multiplot. Max. number of colours is taken if this
  95.          value equals 0.
  96.        Unused by: PostScript
  97.     */
  98.   int colors;
  99.     /* number of colours used for the discrete palette. Equals to the result
  100.        from term->make_palette(NULL), or restricted by use_maxcolor
  101.        Used by: pm, gif
  102.        Unused by: PostScript
  103.      */
  104.   rgb_color *color;
  105.     /* table of RGB triplets resulted from applying the formulae. Used
  106.        in the 2nd call to term->make_palette for a terminal with discrete
  107.        colours. Unused by PostScript who has programmed them analytically
  108.     */
  109.  
  110.   /** Variables used by some terminals (those with palette, not post.trm) **/
  111.   int offset;
  112.     /* offset of the first smooth colour in the table (some first items
  113.        are usually occupied by the colours for linetypes)
  114.        Used by: pm
  115.        Unused by: gif (it uses its gif_smooth_color[0..colors]),
  116.               postscript (continous RGB values)
  117.     */
  118.   /* MAYBE: something like
  119.     int gif_smooth_color[ gdMaxColors ];  i.e.  int *itable;
  120.      could go here if there are at least two terminals using that;
  121.      currently only gif, so it's in his gif.trm
  122.   */
  123.  
  124.   char ps_allcF;
  125.     /* Option unique for output to PostScript file.
  126.        By default, ps_allcF=0 and only the 3 selected rgb color formulae
  127.        are written into the header preceding pm3d map in the file.
  128.        If ps_allcF is non-zero, then print there all color formulae, so
  129.        that it is easy to play with choosing manually any color scheme
  130.        in the PS file (see the definition of "/g"). Like that you can
  131.        get the Rosenbrock multiplot figure on my gnuplot.html#pm3d demo
  132.        page.
  133.     */
  134.  
  135. } t_sm_palette;
  136.  
  137.  
  138.  
  139. /* GLOBAL VARIABLES */
  140.  
  141. extern t_sm_palette sm_palette;
  142.  
  143. /*
  144. Position of the colour smooth box that shows the colours used.
  145. Currently, everything is default (I haven't figured out how to make it
  146. in gnuplot's usual way (like set labels, set key etc.) so the box is put
  147. somewhere right from the 3d graph.
  148. */
  149. #define SMCOLOR_BOX_NO      'n'
  150. #define SMCOLOR_BOX_DEFAULT 'd'
  151. #define SMCOLOR_BOX_USER    'u'
  152.  
  153. typedef struct {
  154.   char where;
  155.     /* where
  156.     SMCOLOR_BOX_NO .. do not draw the colour box
  157.     SMCOLOR_BOX_DEFAULT .. draw it at default position and size
  158.     SMCOLOR_BOX_USER .. draw it at the position given by user by using
  159.               corners from below ... ! NOT IMPLEMENTED !
  160.     */
  161. #if 0
  162.   /* corners of the box */
  163. PROPOSALS (WHO WANTS TO MAKE THIS?):
  164.   /* coordval ? */ double xlow, xhigh, ylow, yhigh;
  165.             OR
  166.   /* coordval ? */ double xlow, ylow, xsize, ysize; <--- preferred!
  167.   /* or some structure (x,y) or (x,y,z) that can do
  168.     set color_smooth_box from 0.8,0.6 screen to 0.95,0.95 screen
  169.     as well as
  170.     set color_smooth_box from 0.34,0.45,12.4 to 1.0,2.0,45
  171.   */
  172. #endif
  173.   char rotation;
  174.     /* 'v' or 'h' vertical or horizontal box */
  175. } color_box_struct;
  176.  
  177.  
  178. /* GLOBAL VARIABLES */
  179.  
  180. extern color_box_struct color_box;
  181.  
  182.  
  183. /* ROUTINES */
  184.  
  185. /*
  186.   Make the colour palette. Return 0 on success
  187.   Put number of allocated colours into sm_palette.colors
  188. */
  189. int make_palette();
  190.  
  191. /*
  192.    Set the colour on the terminal
  193.    Currently, each terminal takes care of remembering the current colour,
  194.    so there is not much to do here---well, except for reversing the gray
  195.    according to sm_palette.positive == SMPAL_POSITIVE or SMPAL_NEGATIVE
  196. */
  197. void set_color ( double gray );
  198.  
  199. /*
  200.    Makes mapping from real 3D coordinates to 2D terminal coordinates,
  201.    then draws filled polygon
  202. */
  203. void filled_polygon ( int points, gpdPoint *corners );
  204.  
  205. /*
  206.    The routine above for 4 points explicitly
  207. */
  208. void filled_quadrangle ( gpdPoint *corners );
  209.  
  210. /*
  211.    Makes mapping from real 3D coordinates, passed as coords array,
  212.    to 2D terminal coordinates, then draws filled polygon
  213. */
  214. void filled_polygon_3dcoords ( int points, struct coordinate GPHUGE *coords );
  215.  
  216. /*
  217.    Makes mapping from real 3D coordinates, passed as coords array, but at z coordinate
  218.    fixed (base_z, for instance) to 2D terminal coordinates, then draws filled polygon
  219. */
  220. void filled_polygon_3dcoords_zfixed ( int points, struct coordinate GPHUGE *coords, double z );
  221.  
  222. /*
  223.   Draw colour smooth box
  224. */
  225. void draw_color_smooth_box();
  226.  
  227.  
  228. #endif
  229.  
  230. #endif /* PM3D */
  231.  
  232. /* eof color.h */
  233.