1
2 /********************************************************************
3 * code in this file is designed to send raster data to the graphics
4 * driver. It handles raster->color lookup translation, as well as
5 * loading appropriate colormaps into the driver and the sending of
6 * raster data to the plotter. The loading of colors is designed to
7 * never send more colors than the hardware can support - even though
8 * the GRASS drivers will allocate virtual colormaps to pretend there are more
9 * This code effectively disables that driver feature/mistake.
10 *
11 * To simply plot raster data:
12 *
13 * to specify if overlay mode is to be used
14 * D_set_overlay_mode(flag)
15 * int flag; /1=yes,0=no/
16 *
17 * to select a raster color for line drawing
18 * D_color (cat, colors)
19 * CELL cat
20 * struct Colors *colors; /color info/
21 *
22 * D_color_of_type(raster, colors, data_type);
23 * void *raster;
24 * struct Colors *colors; /color info/
25 * RASTER_MAP_TYPE data_type;
26 *
27 * Note: the same Colors structure must be passed to all routines.
28 *
29 */
30 #include <stdlib.h>
31
32 #include <grass/gis.h>
33 #include <grass/raster.h>
34 #include <grass/display.h>
35
36 int D__overlay_mode = 0; /* external for now, but to be fixed later */
37
38
39 /*!
40 * \brief Configure raster overlay mode
41 *
42 * This routine determines if D_draw_raster() draws in overlay mode
43 * (locations with category 0 are left untouched) or not (colored with
44 * the color for category 0).
45 *
46 * \param n 1 (TRUE) for overlay mode; 0 (FALSE) otherwise
47 *
48 * \return 0
49 */
D_set_overlay_mode(int n)50 int D_set_overlay_mode(int n)
51 {
52 D__overlay_mode = (n != 0);
53
54 return 0;
55 }
56
57
58 /* this routine modifies the hardware colormap
59 * provided that we are not using fixed mode colors.
60 * For use by programs such as d.colors
61 *
62 * returns:
63 * 0 error - in fixed mode,
64 * or cat not in min:max color range
65 * 1 ok
66 */
67
D_color(CELL cat,struct Colors * colors)68 int D_color(CELL cat, struct Colors *colors)
69 {
70 return D_c_color(cat, colors);
71 }
72
73 /* select color for line drawing */
D_c_color(CELL cat,struct Colors * colors)74 int D_c_color(CELL cat, struct Colors *colors)
75 {
76 return D_color_of_type(&cat, colors, CELL_TYPE);
77 }
78
79 /* select color for line drawing */
80
81 /*!
82 * \brief
83 *
84 * Same functionality as <tt>D_color()</tt> except that the <em>value</em> is type
85 * <tt>DCELL</tt>. This implies that the floating-point interfaces to the <em>colors</em>
86 * are used by this routine.
87 *
88 * \param value
89 * \param colors
90 * \return int
91 */
92
D_d_color(DCELL val,struct Colors * colors)93 int D_d_color(DCELL val, struct Colors *colors)
94 {
95 return D_color_of_type(&val, colors, DCELL_TYPE);
96 }
97
98 /* select color for line drawing */
99
100 /*!
101 * \brief
102 *
103 * Same
104 * functionality as <tt>D_color()</tt> except that the <em>value</em> is type <tt>FCELL</tt>.
105 * This implies that the floating-point interfaces to the <em>colors</em> are used by this routine.
106 *
107 * \param value
108 * \param colors
109 * \return int
110 */
111
D_f_color(FCELL val,struct Colors * colors)112 int D_f_color(FCELL val, struct Colors *colors)
113 {
114 return D_color_of_type(&val, colors, FCELL_TYPE);
115 }
116
117
118 /*!
119 * \brief
120 *
121 * If the <em>data_type</em> is CELL_TYPE,
122 * calls D_color((CELL *value, colors);
123 * If the <em>data_type</em> is FCELL_TYPE, calls D_f_color((FCELL *value,
124 * colors);
125 * If the <em>data_type</em> is DCELL_TYPE, calls D_d_color((DCELL *value,
126 * colors);
127 *
128 * \param value
129 * \param colors
130 * \param data_type
131 * \return int
132 */
133
D_color_of_type(const void * raster,struct Colors * colors,RASTER_MAP_TYPE data_type)134 int D_color_of_type(const void *raster,
135 struct Colors *colors, RASTER_MAP_TYPE data_type)
136 {
137 int r, g, b;
138
139 Rast_get_color(raster, &r, &g, &b, colors, data_type);
140 D_RGB_color((unsigned char)r, (unsigned char)g, (unsigned char)b);
141
142 return 0;
143 }
144