GRASS 8 Programmer's Manual 8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
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
35int 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 */
65int D_color(CELL cat, struct Colors *colors)
66{
67 return D_c_color(cat, colors);
68}
69
70/* select color for line drawing */
71int 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 */
87int D_d_color(DCELL val, struct Colors *colors)
88{
89 return D_color_of_type(&val, colors, DCELL_TYPE);
90}
91
92/*!
93 * \brief select color for line drawing
94 *
95 * Same
96 * functionality as <tt>D_color()</tt> except that the <em>value</em> is type
97 * <tt>FCELL</tt>. This implies that the floating-point interfaces to the
98 * <em>colors</em> are used by this routine.
99 *
100 * \param val
101 * \param colors
102 * \return int
103 */
104int D_f_color(FCELL val, struct Colors *colors)
105{
106 return D_color_of_type(&val, colors, FCELL_TYPE);
107}
108
109/*!
110 * \brief
111 *
112 * If the <em>data_type</em> is CELL_TYPE,
113 * calls D_color((CELL *value, colors);
114 * If the <em>data_type</em> is FCELL_TYPE, calls D_f_color((FCELL *value,
115 * colors);
116 * If the <em>data_type</em> is DCELL_TYPE, calls D_d_color((DCELL *value,
117 * colors);
118 *
119 * \param raster
120 * \param colors
121 * \param data_type
122 * \return int
123 */
124int D_color_of_type(const void *raster, struct Colors *colors,
125 RASTER_MAP_TYPE data_type)
126{
127 int r, g, b;
128
129 Rast_get_color(raster, &r, &g, &b, colors, data_type);
130 D_RGB_color((unsigned char)r, (unsigned char)g, (unsigned char)b);
131
132 return 0;
133}
void D_RGB_color(int, int, int)
Definition tran_colr.c:213
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:124
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:104
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:87
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