43 {
45 int pixbytes = 0;
47 size_t sz = 0;
48 size_t v = 0;
49
50 assert(NULL != ptr);
51 assert(NULL != end);
52
54 if (!band) {
55 rterror(
"rt_band_from_wkb: Out of memory allocating rt_band during WKB parsing");
56 return NULL;
57 }
59
60 if (end - *ptr < 1) {
61 rterror(
"rt_band_from_wkb: Premature end of WKB on band reading (%s:%d)",
62 __FILE__, __LINE__);
64 return NULL;
65 }
67
71 return NULL;
72 }
73
79 band->height = height;
80
81 RASTER_DEBUGF(3,
" Band pixtype:%s, offline:%d, hasnodata:%d",
85 );
86
87
89 if (((*ptr) + pixbytes) >= end) {
90 rterror(
"rt_band_from_wkb: Premature end of WKB on band novalue reading");
92 return NULL;
93 }
94
95
96 switch (
band->pixtype) {
99 break;
100 }
103 break;
104 }
107 break;
108 }
111 break;
112 }
115 break;
116 }
119 break;
120 }
123 break;
124 }
127 break;
128 }
131 break;
132 }
135 break;
136 }
139 break;
140 }
143 break;
144 }
145 default: {
146 rterror(
"rt_band_from_wkb: Unknown pixeltype %d",
band->pixtype);
148 return NULL;
149 }
150 }
151
152 RASTER_DEBUGF(3,
" Nodata value: %g, pixbytes: %d, ptr @ %p, end @ %p",
153 band->nodataval, pixbytes, *ptr, end);
154
156 if (((*ptr) + 1) >= end) {
157 rterror(
"rt_band_from_wkb: Premature end of WKB on offline "
158 "band data bandNum reading (%s:%d)",
159 __FILE__, __LINE__
160 );
162 return NULL;
163 }
164
166 band->data.offline.mem = NULL;
167
168 {
169
170 sz = 0;
171 while ((*ptr)[sz] && &((*ptr)[sz]) < end) ++sz;
172 if (&((*ptr)[sz]) >= end) {
173 rterror(
"rt_band_from_wkb: Premature end of WKB on band offline path reading");
175 return NULL;
176 }
177
178
180
182 if (
band->data.offline.path == NULL) {
183 rterror(
"rt_band_from_wkb: Out of memory allocating for offline path of band");
185 return NULL;
186 }
187
188 memcpy(
band->data.offline.path, *ptr, sz);
189 band->data.offline.path[sz] =
'\0';
190
192 band->data.offline.path, sz);
193
194 *ptr += sz + 1;
195
196
197
198
199 }
200
202 }
203
204
205 sz = (size_t)width * height * pixbytes;
206 if (((*ptr) + sz) > end) {
207 rterror(
"rt_band_from_wkb: Premature end of WKB on band data reading (%s:%d)",
208 __FILE__, __LINE__);
210 return NULL;
211 }
212
214 if (!
band->data.mem) {
215 rterror(
"rt_band_from_wkb: Out of memory during band creation in WKB parser");
217 return NULL;
218 }
219
221 memcpy(
band->data.mem, *ptr, sz);
222 *ptr += sz;
223
224
225
226 if (pixbytes > 1) {
228 void (*flipper)(uint8_t*) = 0;
229 uint8_t *flipme = NULL;
230
231 if (pixbytes == 2)
233 else if (pixbytes == 4)
235 else if (pixbytes == 8)
237 else {
238 rterror(
"rt_band_from_wkb: Unexpected pix bytes %d", pixbytes);
240 return NULL;
241 }
242
243 flipme =
band->data.mem;
244 sz = (size_t)width * height;
245 for (v = 0; v < sz; ++v) {
246 flipper(flipme);
247 flipme += pixbytes;
248 }
249 }
250 }
251
252 else if (
256 ) {
258 uint8_t val;
259
260 sz = (size_t)width*height;
261 for (v = 0; v < sz; ++v) {
262 val = ((uint8_t*)
band->data.mem)[v];
263 if (val > maxVal) {
264 rterror(
"rt_band_from_wkb: Invalid value %d for pixel of type %s",
267 return NULL;
268 }
269 }
270 }
271
272
273
274
275
277}
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,...)
float rt_util_float16_to_float(uint16_t value)
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