GRASS Programmer's Manual  6.4.2(2012)
alloc_cell.c
Go to the documentation of this file.
00001 
00017 #include <math.h>
00018 #include <grass/gis.h>
00019 
00020 /* convert type "RASTER_MAP_TYPE" into index */
00021 #define F2I(map_type) \
00022         (map_type == CELL_TYPE ? 0 : (map_type == FCELL_TYPE ? 1 : 2))
00023 
00024 static int type_size[3] = { sizeof(CELL), sizeof(FCELL), sizeof(DCELL) };
00025 
00026 
00038 size_t G_raster_size(RASTER_MAP_TYPE data_type)
00039 {
00040     return (type_size[F2I(data_type)]);
00041 }
00042 
00043 
00064 CELL *G_allocate_cell_buf(void)
00065 {
00066     return (CELL *) G_calloc(G_window_cols() + 1, sizeof(CELL));
00067 }
00068 
00069 
00081 void *G_allocate_raster_buf(RASTER_MAP_TYPE data_type)
00082 {
00083     return (void *)G_calloc(G_window_cols() + 1, G_raster_size(data_type));
00084 }
00085 
00086 
00096 CELL *G_allocate_c_raster_buf(void)
00097 {
00098     return (CELL *) G_calloc(G_window_cols() + 1, sizeof(CELL));
00099 }
00100 
00101 
00111 FCELL *G_allocate_f_raster_buf(void)
00112 {
00113     return (FCELL *) G_calloc(G_window_cols() + 1, sizeof(FCELL));
00114 }
00115 
00116 
00126 DCELL *G_allocate_d_raster_buf(void)
00127 {
00128     return (DCELL *) G_calloc(G_window_cols() + 1, sizeof(DCELL));
00129 }
00130 
00131 
00141 char *G_allocate_null_buf(void)
00142 {
00143     return (char *)G_calloc(G_window_cols() + 1, sizeof(char));
00144 }
00145 
00146 
00156 unsigned char *G__allocate_null_bits(int cols)
00157 {
00158     return (unsigned char *)G_calloc(G__null_bitstream_size(cols) + 1,
00159                                      sizeof(unsigned char));
00160 }
00161 
00162 
00171 int G__null_bitstream_size(int cols)
00172 {
00173     if (cols <= 0)
00174         return -1;
00175 
00176     return (cols / 8 + (cols % 8 != 0));
00177 }
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines