GRASS GIS 8 Programmer's Manual  8.5.0dev(2025)-b35369f6b7
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 /*!
56  * \brief this routine modifies the hardware colormap provided that we are not
57  * using fixed mode colors.
58  *
59  * For use by programs such as d.colors.
60  *
61  * \param cat
62  * \param colors
63  * \return
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 /*!
77  * \brief select color for line drawing
78  *
79  * Same functionality as <tt>D_color()</tt> except that the <em>value</em> is
80  * type <tt>DCELL</tt>. This implies that the floating-point interfaces to the
81  * <em>colors</em> are used by this routine.
82  *
83  * \param val Value
84  * \param colors
85  * \return int
86  */
87 
88 int D_d_color(DCELL val, struct Colors *colors)
89 {
90  return D_color_of_type(&val, colors, DCELL_TYPE);
91 }
92 
93 /*!
94  * \brief select color for line drawing
95  *
96  * Same
97  * functionality as <tt>D_color()</tt> except that the <em>value</em> is type
98  * <tt>FCELL</tt>. This implies that the floating-point interfaces to the
99  * <em>colors</em> are used by this routine.
100  *
101  * \param val
102  * \param colors
103  * \return int
104  */
105 int D_f_color(FCELL val, struct Colors *colors)
106 {
107  return D_color_of_type(&val, colors, FCELL_TYPE);
108 }
109 
110 /*!
111  * \brief
112  *
113  * If the <em>data_type</em> is CELL_TYPE,
114  * calls D_color((CELL *value, colors);
115  * If the <em>data_type</em> is FCELL_TYPE, calls D_f_color((FCELL *value,
116  * colors);
117  * If the <em>data_type</em> is DCELL_TYPE, calls D_d_color((DCELL *value,
118  * colors);
119  *
120  * \param raster
121  * \param colors
122  * \param data_type
123  * \return int
124  */
125 int D_color_of_type(const void *raster, struct Colors *colors,
126  RASTER_MAP_TYPE data_type)
127 {
128  int r, g, b;
129 
130  Rast_get_color(raster, &r, &g, &b, colors, data_type);
131  D_RGB_color((unsigned char)r, (unsigned char)g, (unsigned char)b);
132 
133  return 0;
134 }
void D_RGB_color(int, int, int)
Definition: tran_colr.c:217
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:636
double DCELL
Definition: gis.h:635
int CELL
Definition: gis.h:634
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)
this routine modifies the hardware colormap provided that we are not using fixed mode 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:125
int D_set_overlay_mode(int n)
Configure raster overlay mode.
Definition: raster2.c:48
int D_f_color(FCELL val, struct Colors *colors)
select color for line drawing
Definition: raster2.c:105
int D_c_color(CELL cat, struct Colors *colors)
Definition: raster2.c:71
int D_d_color(DCELL val, struct Colors *colors)
select color for line drawing
Definition: raster2.c:88
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:692