GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
get_row_colr.c
Go to the documentation of this file.
1 /*!
2  * \file lib/raster/get_row_colr.c
3  *
4  * \brief Raster Library - Get raster row (colors)
5  *
6  * (C) 1999-2009 by the GRASS Development Team
7  *
8  * This program is free software under the GNU General Public
9  * License (>=v2). Read the file COPYING that comes with GRASS
10  * for details.
11  *
12  * \author USACERL and many others
13  */
14 
15 #include <grass/gis.h>
16 #include <grass/raster.h>
17 
18 #include "R.h"
19 
20 /*!
21  * \brief Reads a row of raster data and converts it to RGB.
22  *
23  * Reads a row of raster data and converts it to red, green and blue
24  * components according to the <em>colors</em> parameter. This
25  * provides a convenient way to treat a raster layer as a color image
26  * without having to explicitly cater for each of <tt>CELL</tt>,
27  * <tt>FCELL</tt> and <tt>DCELL</tt> types.
28  *
29  * \param fd field descriptor
30  * \param row row number
31  * \param colors pointer to Colors structure which holds color info
32  * \param[out] red red value
33  * \param[out] grn green value
34  * \param[out] blu blue value
35  * \param[out] nul null value
36  *
37  * \return void
38  */
39 void Rast_get_row_colors(int fd, int row, struct Colors *colors,
40  unsigned char *red, unsigned char *grn,
41  unsigned char *blu, unsigned char *nul)
42 {
43  int cols = Rast_window_cols();
44  int type = Rast_get_map_type(fd);
45  int size = Rast_cell_size(type);
46  void *array;
47  unsigned char *set;
48  void *p;
49  int i;
50 
51  array = G_malloc(cols * size);
52 
53  Rast_get_row(fd, array, row, type);
54 
55  if (nul)
56  for (i = 0, p = array; i < cols; i++, p = G_incr_void_ptr(p, size))
57  nul[i] = Rast_is_null_value(p, type);
58 
59  set = G_malloc(cols);
60 
61  Rast_lookup_colors(array, red, grn, blu, set, cols, colors, type);
62 
63  G_free(array);
64  G_free(set);
65 }
#define G_malloc(n)
Definition: defs/gis.h:112
void Rast_get_row_colors(int fd, int row, struct Colors *colors, unsigned char *red, unsigned char *grn, unsigned char *blu, unsigned char *nul)
Reads a row of raster data and converts it to RGB.
Definition: get_row_colr.c:39
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:149
#define G_incr_void_ptr(ptr, size)
Definition: defs/gis.h:100
size_t Rast_cell_size(RASTER_MAP_TYPE)
Returns size of a raster cell in bytes.
Definition: alloc_cell.c:39
void Rast_get_row(int, void *, int, RASTER_MAP_TYPE)
Get raster row.
void Rast_lookup_colors(const void *, unsigned char *, unsigned char *, unsigned char *, unsigned char *, int, struct Colors *, RASTER_MAP_TYPE)
Lookup an array of colors.
Definition: color_look.c:79
Definition: gis.h:665
int Rast_window_cols(void)
Number of columns in active window.
RASTER_MAP_TYPE Rast_get_map_type(int)
Determine raster type from descriptor.
Definition: raster/open.c:918
int Rast_is_null_value(const void *, RASTER_MAP_TYPE)
To check if a raster value is set to NULL.
Definition: null_val.c:179