GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
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 * SPDX-FileCopyrightText: 1999-2009 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author USACERL and many others
10 */
11
12#include <grass/gis.h>
13#include <grass/raster.h>
14
15#include "R.h"
16
17/*!
18 * \brief Reads a row of raster data and converts it to RGB.
19 *
20 * Reads a row of raster data and converts it to red, green and blue
21 * components according to the <em>colors</em> parameter. This
22 * provides a convenient way to treat a raster layer as a color image
23 * without having to explicitly cater for each of <tt>CELL</tt>,
24 * <tt>FCELL</tt> and <tt>DCELL</tt> types.
25 *
26 * \param fd field descriptor
27 * \param row row number
28 * \param colors pointer to Colors structure which holds color info
29 * \param[out] red red value
30 * \param[out] grn green value
31 * \param[out] blu blue value
32 * \param[out] nul null value
33 *
34 * \return void
35 */
36void Rast_get_row_colors(int fd, int row, struct Colors *colors,
37 unsigned char *red, unsigned char *grn,
38 unsigned char *blu, unsigned char *nul)
39{
40 int cols = Rast_window_cols();
41 int type = Rast_get_map_type(fd);
42 int size = Rast_cell_size(type);
43 void *array;
44 unsigned char *set;
45 void *p;
46 int i;
47
48 array = G_malloc(cols * size);
49
50 Rast_get_row(fd, array, row, type);
51
52 if (nul)
53 for (i = 0, p = array; i < cols; i++, p = G_incr_void_ptr(p, size))
54 nul[i] = Rast_is_null_value(p, type);
55
56 set = G_malloc(cols);
57
58 Rast_lookup_colors(array, red, grn, blu, set, cols, colors, type);
59
60 G_free(array);
61 G_free(set);
62}
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:145
#define G_malloc(n)
Definition defs/gis.h:136
#define G_incr_void_ptr(ptr, size)
Definition defs/gis.h:78
int Rast_is_null_value(const void *, RASTER_MAP_TYPE)
To check if a raster value is set to NULL.
Definition null_val.c:174
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:76
size_t Rast_cell_size(RASTER_MAP_TYPE)
Returns size of a raster cell in bytes.
Definition alloc_cell.c:35
int Rast_window_cols(void)
Number of columns in active window.
RASTER_MAP_TYPE Rast_get_map_type(int)
Determine raster type from descriptor.
void Rast_get_row(int, void *, int, RASTER_MAP_TYPE)
Get raster row.
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 gis.h:689