40 {
42 int pixbytes = 0;
44 unsigned long sz = 0;
45 uint32_t v = 0;
46
47 assert(NULL != ptr);
48 assert(NULL != end);
49
51 if (!band) {
52 rterror(
"rt_band_from_wkb: Out of memory allocating rt_band during WKB parsing");
53 return NULL;
54 }
56
57 if (end - *ptr < 1) {
58 rterror(
"rt_band_from_wkb: Premature end of WKB on band reading (%s:%d)",
59 __FILE__, __LINE__);
61 return NULL;
62 }
64
68 return NULL;
69 }
70
76 band->height = height;
77
78 RASTER_DEBUGF(3,
" Band pixtype:%s, offline:%d, hasnodata:%d",
82 );
83
84
86 if (((*ptr) + pixbytes) >= end) {
87 rterror(
"rt_band_from_wkb: Premature end of WKB on band novalue reading");
89 return NULL;
90 }
91
92
93 switch (
band->pixtype) {
96 break;
97 }
100 break;
101 }
104 break;
105 }
108 break;
109 }
112 break;
113 }
116 break;
117 }
120 break;
121 }
124 break;
125 }
128 break;
129 }
132 break;
133 }
136 break;
137 }
138 default: {
139 rterror(
"rt_band_from_wkb: Unknown pixeltype %d",
band->pixtype);
141 return NULL;
142 }
143 }
144
145 RASTER_DEBUGF(3,
" Nodata value: %g, pixbytes: %d, ptr @ %p, end @ %p",
146 band->nodataval, pixbytes, *ptr, end);
147
149 if (((*ptr) + 1) >= end) {
150 rterror(
"rt_band_from_wkb: Premature end of WKB on offline "
151 "band data bandNum reading (%s:%d)",
152 __FILE__, __LINE__
153 );
155 return NULL;
156 }
157
159 band->data.offline.mem = NULL;
160
161 {
162
163 sz = 0;
164 while ((*ptr)[sz] && &((*ptr)[sz]) < end) ++sz;
165 if (&((*ptr)[sz]) >= end) {
166 rterror(
"rt_band_from_wkb: Premature end of WKB on band offline path reading");
168 return NULL;
169 }
170
171
173
175 if (
band->data.offline.path == NULL) {
176 rterror(
"rt_band_from_wkb: Out of memory allocating for offline path of band");
178 return NULL;
179 }
180
181 memcpy(
band->data.offline.path, *ptr, sz);
182 band->data.offline.path[sz] =
'\0';
183
185 band->data.offline.path, sz);
186
187 *ptr += sz + 1;
188
189
190
191
192 }
193
195 }
196
197
198 sz = width * height * pixbytes;
199 if (((*ptr) + sz) > end) {
200 rterror(
"rt_band_from_wkb: Premature end of WKB on band data reading (%s:%d)",
201 __FILE__, __LINE__);
203 return NULL;
204 }
205
207 if (!
band->data.mem) {
208 rterror(
"rt_band_from_wkb: Out of memory during band creation in WKB parser");
210 return NULL;
211 }
212
214 memcpy(
band->data.mem, *ptr, sz);
215 *ptr += sz;
216
217
218
219 if (pixbytes > 1) {
221 void (*flipper)(uint8_t*) = 0;
222 uint8_t *flipme = NULL;
223
224 if (pixbytes == 2)
226 else if (pixbytes == 4)
228 else if (pixbytes == 8)
230 else {
231 rterror(
"rt_band_from_wkb: Unexpected pix bytes %d", pixbytes);
233 return NULL;
234 }
235
236 flipme =
band->data.mem;
237 sz = width * height;
238 for (v = 0; v < sz; ++v) {
239 flipper(flipme);
240 flipme += pixbytes;
241 }
242 }
243 }
244
245 else if (
249 ) {
251 uint8_t val;
252
253 sz = width*height;
254 for (v = 0; v < sz; ++v) {
255 val = ((uint8_t*)
band->data.mem)[v];
256 if (val > maxVal) {
257 rterror(
"rt_band_from_wkb: Invalid value %d for pixel of type %s",
260 return NULL;
261 }
262 }
263 }
264
265
266
267
268
270}
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
#define RASTER_DEBUGF(level, msg,...)
const char * rt_pixtype_name(rt_pixtype pixtype)
void rt_band_destroy(rt_band band)
Destroy a raster band.
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
uint8_t isMachineLittleEndian(void)
void flip_endian_32(uint8_t *d)
void flip_endian_16(uint8_t *d)
uint8_t read_uint8(const uint8_t **from)
double read_float64(const uint8_t **from, uint8_t littleEndian)
float read_float32(const uint8_t **from, uint8_t littleEndian)
void flip_endian_64(uint8_t *d)
int8_t read_int8(const uint8_t **from)
int16_t read_int16(const uint8_t **from, uint8_t littleEndian)
int32_t read_int32(const uint8_t **from, uint8_t littleEndian)
uint32_t read_uint32(const uint8_t **from, uint8_t littleEndian)
uint16_t read_uint16(const uint8_t **from, uint8_t littleEndian)
#define BANDTYPE_HAS_NODATA(x)
#define BANDTYPE_IS_OFFDB(x)
#define BANDTYPE_IS_NODATA(x)
#define BANDTYPE_PIXTYPE_MASK