GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72636
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 }
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:149
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 Rast_lookup_colors(const void *raster, unsigned char *red, unsigned char *grn, unsigned char *blu, unsigned char *set, int n, struct Colors *colors, RASTER_MAP_TYPE map_type)
Lookup an array of colors.
Definition: color_look.c:79
void Rast_get_row(int fd, void *buf, int row, RASTER_MAP_TYPE data_type)
Get raster row.
fd
Definition: d/range.c:69
size_t Rast_cell_size(RASTER_MAP_TYPE data_type)
Returns size of a raster cell in bytes.
Definition: alloc_cell.c:39
int Rast_window_cols(void)
Number of columns in active window.
int Rast_is_null_value(const void *rast, RASTER_MAP_TYPE data_type)
To check if a raster value is set to NULL.
Definition: null_val.c:179
Definition: gis.h:643
RASTER_MAP_TYPE Rast_get_map_type(int fd)
Determine raster type from descriptor.
Definition: raster/open.c:907
void * G_incr_void_ptr(const void *ptr, size_t size)
Advance void pointer.
Definition: gis/alloc.c:186