42 {
44 int pixbytes = 0;
46 size_t sz = 0;
47 size_t v = 0;
48
49 assert(NULL != ptr);
50 assert(NULL != end);
51
53 if (!band) {
54 rterror(
"rt_band_from_wkb: Out of memory allocating rt_band during WKB parsing");
55 return NULL;
56 }
58
59 if (end - *ptr < 1) {
60 rterror(
"rt_band_from_wkb: Premature end of WKB on band reading (%s:%d)",
61 __FILE__, __LINE__);
63 return NULL;
64 }
66
70 return NULL;
71 }
72
78 band->height = height;
79
80 RASTER_DEBUGF(3,
" Band pixtype:%s, offline:%d, hasnodata:%d",
84 );
85
86
88 if (((*ptr) + pixbytes) >= end) {
89 rterror(
"rt_band_from_wkb: Premature end of WKB on band novalue reading");
91 return NULL;
92 }
93
94
95 switch (
band->pixtype) {
98 break;
99 }
102 break;
103 }
106 break;
107 }
110 break;
111 }
114 break;
115 }
118 break;
119 }
122 break;
123 }
126 break;
127 }
130 break;
131 }
134 break;
135 }
138 break;
139 }
140 default: {
141 rterror(
"rt_band_from_wkb: Unknown pixeltype %d",
band->pixtype);
143 return NULL;
144 }
145 }
146
147 RASTER_DEBUGF(3,
" Nodata value: %g, pixbytes: %d, ptr @ %p, end @ %p",
148 band->nodataval, pixbytes, *ptr, end);
149
151 if (((*ptr) + 1) >= end) {
152 rterror(
"rt_band_from_wkb: Premature end of WKB on offline "
153 "band data bandNum reading (%s:%d)",
154 __FILE__, __LINE__
155 );
157 return NULL;
158 }
159
161 band->data.offline.mem = NULL;
162
163 {
164
165 sz = 0;
166 while ((*ptr)[sz] && &((*ptr)[sz]) < end) ++sz;
167 if (&((*ptr)[sz]) >= end) {
168 rterror(
"rt_band_from_wkb: Premature end of WKB on band offline path reading");
170 return NULL;
171 }
172
173
175
177 if (
band->data.offline.path == NULL) {
178 rterror(
"rt_band_from_wkb: Out of memory allocating for offline path of band");
180 return NULL;
181 }
182
183 memcpy(
band->data.offline.path, *ptr, sz);
184 band->data.offline.path[sz] =
'\0';
185
187 band->data.offline.path, sz);
188
189 *ptr += sz + 1;
190
191
192
193
194 }
195
197 }
198
199
200 sz = (size_t)width * height * pixbytes;
201 if (((*ptr) + sz) > end) {
202 rterror(
"rt_band_from_wkb: Premature end of WKB on band data reading (%s:%d)",
203 __FILE__, __LINE__);
205 return NULL;
206 }
207
209 if (!
band->data.mem) {
210 rterror(
"rt_band_from_wkb: Out of memory during band creation in WKB parser");
212 return NULL;
213 }
214
216 memcpy(
band->data.mem, *ptr, sz);
217 *ptr += sz;
218
219
220
221 if (pixbytes > 1) {
223 void (*flipper)(uint8_t*) = 0;
224 uint8_t *flipme = NULL;
225
226 if (pixbytes == 2)
228 else if (pixbytes == 4)
230 else if (pixbytes == 8)
232 else {
233 rterror(
"rt_band_from_wkb: Unexpected pix bytes %d", pixbytes);
235 return NULL;
236 }
237
238 flipme =
band->data.mem;
239 sz = (size_t)width * height;
240 for (v = 0; v < sz; ++v) {
241 flipper(flipme);
242 flipme += pixbytes;
243 }
244 }
245 }
246
247 else if (
251 ) {
253 uint8_t val;
254
255 sz = (size_t)width*height;
256 for (v = 0; v < sz; ++v) {
257 val = ((uint8_t*)
band->data.mem)[v];
258 if (val > maxVal) {
259 rterror(
"rt_band_from_wkb: Invalid value %d for pixel of type %s",
262 return NULL;
263 }
264 }
265 }
266
267
268
269
270
272}
void rterror(const char *fmt,...) __attribute__((format(printf
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