GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
alloc_cell.c
Go to the documentation of this file.
1 
17 #include <math.h>
18 #include <grass/gis.h>
19 
20 /* convert type "RASTER_MAP_TYPE" into index */
21 #define F2I(map_type) \
22  (map_type == CELL_TYPE ? 0 : (map_type == FCELL_TYPE ? 1 : 2))
23 
24 static int type_size[3] = { sizeof(CELL), sizeof(FCELL), sizeof(DCELL) };
25 
26 
38 size_t G_raster_size(RASTER_MAP_TYPE data_type)
39 {
40  return (type_size[F2I(data_type)]);
41 }
42 
43 
65 {
66  return (CELL *) G_calloc(G_window_cols() + 1, sizeof(CELL));
67 }
68 
69 
81 void *G_allocate_raster_buf(RASTER_MAP_TYPE data_type)
82 {
83  return (void *)G_calloc(G_window_cols() + 1, G_raster_size(data_type));
84 }
85 
86 
97 {
98  return (CELL *) G_calloc(G_window_cols() + 1, sizeof(CELL));
99 }
100 
101 
112 {
113  return (FCELL *) G_calloc(G_window_cols() + 1, sizeof(FCELL));
114 }
115 
116 
127 {
128  return (DCELL *) G_calloc(G_window_cols() + 1, sizeof(DCELL));
129 }
130 
131 
142 {
143  return (char *)G_calloc(G_window_cols() + 1, sizeof(char));
144 }
145 
146 
156 unsigned char *G__allocate_null_bits(int cols)
157 {
158  return (unsigned char *)G_calloc(G__null_bitstream_size(cols) + 1,
159  sizeof(unsigned char));
160 }
161 
162 
172 {
173  if (cols <= 0)
174  return -1;
175 
176  return (cols / 8 + (cols % 8 != 0));
177 }
CELL * G_allocate_c_raster_buf(void)
Allocates memory for a raster map of type CELL.
Definition: alloc_cell.c:96
FCELL * G_allocate_f_raster_buf(void)
Allocates memory for a raster map of type FCELL.
Definition: alloc_cell.c:111
char * G_allocate_null_buf(void)
Allocates memory for a null buffer.
Definition: alloc_cell.c:141
CELL * G_allocate_cell_buf(void)
Allocate memory for a CELL type raster map.
Definition: alloc_cell.c:64
size_t G_raster_size(RASTER_MAP_TYPE data_type)
Returns size of a raster CELL in bytes.
Definition: alloc_cell.c:38
#define F2I(map_type)
Definition: alloc_cell.c:21
int G_window_cols(void)
Number of columns in active window.
Definition: window_map.c:306
unsigned char * G__allocate_null_bits(int cols)
Allocates memory for null bits.
Definition: alloc_cell.c:156
void * G_allocate_raster_buf(RASTER_MAP_TYPE data_type)
Allocate memory for a raster map of type data_type.
Definition: alloc_cell.c:81
int G__null_bitstream_size(int cols)
Determines null bitstream size.
Definition: alloc_cell.c:171
tuple cols
DCELL * G_allocate_d_raster_buf(void)
Allocates memory for a raster map of type DCELL.
Definition: alloc_cell.c:126