~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/gis/alloc_cell.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/**
3
 
 * \file alloc_cell.c
4
 
 *
5
 
 * \brief GIS Library - Raster allocation routines.
6
 
 *
7
 
 * (C) 2001-2008 by the GRASS Development Team
8
 
 *
9
 
 * This program is free software under the GNU General Public License
10
 
 * (>=v2). Read the file COPYING that comes with GRASS for details.
11
 
 *
12
 
 * \author GRASS GIS Development Team
13
 
 *
14
 
 * \date 1999-2008
15
 
 */
16
 
 
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
 
 
27
 
/**
28
 
 * \brief Returns size of a raster CELL in bytes.
29
 
 *
30
 
 * If <b>data_type</b> is CELL_TYPE, returns sizeof(CELL)
31
 
 * If <b>data_type</b> is FCELL_TYPE, returns sizeof(FCELL)
32
 
 * If <b>data_type</b> is DCELL_TYPE, returns sizeof(DCELL)
33
 
 *
34
 
 * \param[in] data_type
35
 
 * \return int
36
 
 */
37
 
 
38
 
size_t G_raster_size(RASTER_MAP_TYPE data_type)
39
 
{
40
 
    return (type_size[F2I(data_type)]);
41
 
}
42
 
 
43
 
 
44
 
/**
45
 
 * \brief Allocate memory for a CELL type raster map.
46
 
 *
47
 
 * This routine allocates a buffer of type CELL just large enough to 
48
 
 * hold one row of raster data based on the number of columns in the 
49
 
 * active region.<br>
50
 
 \code
51
 
 CELL *cell;
52
 
 cell = G_allocate_cell_buf ();
53
 
 \endcode
54
 
 * If larger buffers are required, the routine <i>G_malloc</i> can be used.
55
 
 * The routine is generally used with each open cell file.<br>
56
 
 * <b>Note:</b> <i>G_allocate_raster_buf()</i> or 
57
 
 * <i>G_alloc_c_raster_buf()</i> is preferred over 
58
 
 * <i>G_allocate_cell_buf()</i>.
59
 
 *
60
 
 * \return CELL * Pointer to allocated buffer
61
 
 * \return Prints error message and calls <i>exit()</i> on error
62
 
 */
63
 
 
64
 
CELL *G_allocate_cell_buf(void)
65
 
{
66
 
    return (CELL *) G_calloc(G_window_cols() + 1, sizeof(CELL));
67
 
}
68
 
 
69
 
 
70
 
/**
71
 
 * \brief Allocate memory for a raster map of type <b>data_type</b>.
72
 
 *
73
 
 * Allocate an array of CELL, FCELL, or DCELL (depending on 
74
 
 * <b>data_type</b>) based on the number of columns in the current 
75
 
 * region.
76
 
 *
77
 
 * \param[in] data_type
78
 
 * \return void * 
79
 
 */
80
 
 
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
 
 
87
 
/**
88
 
 * \brief Allocates memory for a raster map of type CELL.
89
 
 *
90
 
 * Allocate an array of CELL based on the number of columns in the 
91
 
 * current region.
92
 
 *
93
 
 * \return CELL * 
94
 
 */
95
 
 
96
 
CELL *G_allocate_c_raster_buf(void)
97
 
{
98
 
    return (CELL *) G_calloc(G_window_cols() + 1, sizeof(CELL));
99
 
}
100
 
 
101
 
 
102
 
/**
103
 
 * \brief Allocates memory for a raster map of type FCELL.
104
 
 *
105
 
 * Allocate an array of FCELL based on the number of columns in the 
106
 
 * current region.
107
 
 *
108
 
 * \return FCELL * 
109
 
 */
110
 
 
111
 
FCELL *G_allocate_f_raster_buf(void)
112
 
{
113
 
    return (FCELL *) G_calloc(G_window_cols() + 1, sizeof(FCELL));
114
 
}
115
 
 
116
 
 
117
 
/**
118
 
 * \brief Allocates memory for a raster map of type DCELL.
119
 
 *
120
 
 * Allocate an array of DCELL based on the number of columns in the 
121
 
 * current region.
122
 
 *
123
 
 * \return DCELL * 
124
 
 */
125
 
 
126
 
DCELL *G_allocate_d_raster_buf(void)
127
 
{
128
 
    return (DCELL *) G_calloc(G_window_cols() + 1, sizeof(DCELL));
129
 
}
130
 
 
131
 
 
132
 
/**
133
 
 * \brief Allocates memory for a null buffer.
134
 
 *
135
 
 * Allocate an array of char based on the number of columns in the 
136
 
 * current region.
137
 
 *
138
 
 * \return char * 
139
 
 */
140
 
 
141
 
char *G_allocate_null_buf(void)
142
 
{
143
 
    return (char *)G_calloc(G_window_cols() + 1, sizeof(char));
144
 
}
145
 
 
146
 
 
147
 
/**
148
 
 * \brief Allocates memory for null bits.
149
 
 *
150
 
 * Allocates an array of unsigned char based on <b>cols</b>.
151
 
 *
152
 
 * \param[in] cols number of columns in region
153
 
 * \return unsigned char *
154
 
 */
155
 
 
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
 
 
163
 
/**
164
 
 * \brief Determines null bitstream size.
165
 
 *
166
 
 * \param[in] cols number of columns
167
 
 * \return -1 if <b>cols</b> is invalid (<= 0)
168
 
 * \return size of null bistream
169
 
 */
170
 
 
171
 
int G__null_bitstream_size(int cols)
172
 
{
173
 
    if (cols <= 0)
174
 
        return -1;
175
 
 
176
 
    return (cols / 8 + (cols % 8 != 0));
177
 
}