GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
get_row_colr.c
Go to the documentation of this file.
1 #include <grass/gis.h>
2 #include "G.h"
3 
4 
23 int
24 G_get_raster_row_colors(int fd, int row, struct Colors *colors,
25  unsigned char *red, unsigned char *grn,
26  unsigned char *blu, unsigned char *nul)
27 {
28  static void *array;
29  static int array_size;
30  static unsigned char *set;
31  static int set_size;
32 
33  int cols = G__.window.cols;
34  int type = G__.fileinfo[fd].map_type;
35  int size = G_raster_size(type);
36  void *p;
37  int i;
38 
39  if (array_size < cols * size) {
40  array_size = cols * size;
41  array = (DCELL *) G_realloc(array, array_size);
42  }
43 
44  if (set_size < cols) {
45  set_size = cols;
46  set = G_realloc(set, set_size);
47  }
48 
49  if (G_get_raster_row(fd, array, row, type) < 0)
50  return -1;
51 
52  if (nul)
53  for (i = 0, p = array; i < cols; i++, p = G_incr_void_ptr(p, size))
54  nul[i] = G_is_null_value(p, type);
55 
56  G_lookup_raster_colors(array, red, grn, blu, set, cols, colors, type);
57 
58  return 0;
59 }