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