PostGIS  2.2.8dev-r@@SVN_REVISION@@
cu_band_basics.c
Go to the documentation of this file.
1 /*
2  * PostGIS Raster - Raster Types for PostGIS
3  * http://trac.osgeo.org/postgis/wiki/WKTRaster
4  *
5  * Copyright (C) 2012 Regents of the University of California
6  * <bkpark@ucdavis.edu>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  *
22  */
23 
24 #include "CUnit/Basic.h"
25 #include "cu_tester.h"
26 
27 static void test_band_metadata() {
28  rt_raster rast = NULL;
29  uint8_t *data = NULL;
30  rt_band band = NULL;
31  int width = 5;
32  int height = 5;
33  int temp = 0;
34  double val = 0;
35  char *path = "../regress/loader/testraster.tif";
36  uint8_t extband = 0;
37  int x;
38  int y;
39 
40  /* inline band */
41  data = rtalloc(sizeof(uint8_t) * width * height);
42  CU_ASSERT(data != NULL);
43  memset(data, 0, sizeof(uint8_t) * width * height);
44 
45  band = rt_band_new_inline(
46  width, height,
47  PT_8BUI,
48  0, 0,
49  data
50  );
51  CU_ASSERT(band != NULL);
52 
53  /* isoffline */
54  CU_ASSERT(!rt_band_is_offline(band));
55 
56  /* data */
57  CU_ASSERT(rt_band_get_data(band) != NULL);
58 
59  /* ownsdata */
60  CU_ASSERT(!rt_band_get_ownsdata_flag(band));
62  CU_ASSERT(rt_band_get_ownsdata_flag(band));
63 
64  /* dimensions */
65  CU_ASSERT_EQUAL(rt_band_get_width(band), width);
66  CU_ASSERT_EQUAL(rt_band_get_height(band), height);
67 
68  /* pixtype */
69  CU_ASSERT_EQUAL(rt_band_get_pixtype(band), PT_8BUI);
70 
71  /* hasnodata */
72  CU_ASSERT(!rt_band_get_hasnodata_flag(band));
74  CU_ASSERT(rt_band_get_hasnodata_flag(band));
75 
76  /* nodataval */
77  CU_ASSERT_EQUAL(rt_band_set_nodata(band, 0, &temp), ES_NONE);
78  CU_ASSERT(!temp);
79  CU_ASSERT_EQUAL(rt_band_get_nodata(band, &val), ES_NONE);
80  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
81 
82  /* clamped nodataval */
83  CU_ASSERT_EQUAL(rt_band_set_nodata(band, -1, &temp), ES_NONE);
84  CU_ASSERT(temp);
85  CU_ASSERT_EQUAL(rt_band_get_nodata(band, &val), ES_NONE);
86  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
87 
88  /* isnodata */
89  CU_ASSERT(!rt_band_get_isnodata_flag(band));
91  CU_ASSERT(rt_band_get_isnodata_flag(band));
92 
93  rt_band_destroy(band);
94  band = NULL;
95  data = NULL;
96  rast = NULL;
97 
98  /* offline band */
99  width = 10;
100  height = 10;
101  band = rt_band_new_offline(
102  width, height,
103  PT_8BUI,
104  0, 0,
105  2, path
106  );
107  CU_ASSERT(band != NULL);
108 
109  rast = rt_raster_new(width, height);
110  CU_ASSERT(rast != NULL);
111  rt_raster_set_offsets(rast, 80, 80);
112  CU_ASSERT_NOT_EQUAL(rt_raster_add_band(rast, band, 0), -1);
113 
114  /* isoffline */
115  CU_ASSERT(rt_band_is_offline(band));
116 
117  /* ext path */
118  CU_ASSERT_STRING_EQUAL(rt_band_get_ext_path(band), path);
119 
120  /* ext band number */
121  CU_ASSERT_EQUAL(rt_band_get_ext_band_num(band, &extband), ES_NONE);
122  CU_ASSERT_EQUAL(extband, 2);
123 
124  /* band data */
125  CU_ASSERT_EQUAL(rt_band_load_offline_data(band), ES_NONE);
126  CU_ASSERT(rt_band_get_data(band) != NULL);
127 
128  for (x = 0; x < width; x++) {
129  for (y = 0; y < height; y++) {
130  CU_ASSERT_EQUAL(rt_band_get_pixel(band, x, y, &val, NULL), ES_NONE);
131  CU_ASSERT_DOUBLE_EQUAL(val, 0, 1.);
132  }
133  }
134 
135  /* test rt_band_check_is_nodata */
136  rtdealloc(band->data.offline.mem);
137  band->data.offline.mem = NULL;
138  CU_ASSERT_EQUAL(rt_band_check_is_nodata(band), FALSE);
139 
140  cu_free_raster(rast);
141 }
142 
143 static void test_band_pixtype_1BB() {
144  rt_pixtype pixtype = PT_1BB;
145  uint8_t *data = NULL;
146  rt_band band = NULL;
147  int width = 5;
148  int height = 5;
149  int err = 0;
150  int clamped = 0;
151  double val = 0;
152  int x;
153  int y;
154 
155  /* inline band */
156  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
157  CU_ASSERT(data != NULL);
158  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
159 
160  band = rt_band_new_inline(
161  width, height,
162  pixtype,
163  0, 0,
164  data
165  );
166  CU_ASSERT(band != NULL);
167  rt_band_set_ownsdata_flag(band, 1);
168  CU_ASSERT(rt_band_get_ownsdata_flag(band));
169 
170  err = rt_band_set_nodata(band, 1, &clamped);
171  CU_ASSERT_EQUAL(err, ES_NONE);
172  CU_ASSERT(!clamped);
173 
174  rt_band_get_nodata(band, &val);
175  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
176  err = rt_band_set_nodata(band, 0, &clamped);
177  CU_ASSERT_EQUAL(err, ES_NONE);
178  CU_ASSERT(!clamped);
179  rt_band_get_nodata(band, &val);
180  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
181 
182  err = rt_band_set_nodata(band, 2, &clamped);
183  CU_ASSERT_EQUAL(err, ES_NONE);
184  CU_ASSERT(clamped);
185 
186  err = rt_band_set_nodata(band, 3, &clamped);
187  CU_ASSERT_EQUAL(err, ES_NONE);
188  CU_ASSERT(clamped);
189 
190  err = rt_band_set_pixel(band, 0, 0, 2, &clamped);
191  CU_ASSERT_EQUAL(err, ES_NONE);
192  CU_ASSERT(clamped);
193 
194  err = rt_band_set_pixel(band, 0, 0, 3, &clamped);
195  CU_ASSERT_EQUAL(err, ES_NONE);
196  CU_ASSERT(clamped);
197 
198  for (x = 0; x < rt_band_get_width(band); ++x) {
199  for ( y = 0; y < rt_band_get_height(band); ++y) {
200  err = rt_band_set_pixel(band, x, y, 1, NULL);
201  CU_ASSERT_EQUAL(err, ES_NONE);
202  err = rt_band_get_pixel(band, x, y, &val, NULL);
203  CU_ASSERT_EQUAL(err, ES_NONE);
204  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
205 
206  err = rt_band_set_pixel(band, x, y, 0, NULL);
207  CU_ASSERT_EQUAL(err, ES_NONE);
208  err = rt_band_get_pixel(band, x, y, &val, NULL);
209  CU_ASSERT_EQUAL(err, ES_NONE);
210  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
211  }
212  }
213 
214  rt_band_destroy(band);
215 }
216 
217 static void test_band_pixtype_2BUI() {
218  rt_pixtype pixtype = PT_2BUI;
219  uint8_t *data = NULL;
220  rt_band band = NULL;
221  int width = 5;
222  int height = 5;
223  int err = 0;
224  int clamped = 0;
225  double val = 0;
226  int x;
227  int y;
228 
229  /* inline band */
230  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
231  CU_ASSERT(data != NULL);
232  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
233 
234  band = rt_band_new_inline(
235  width, height,
236  pixtype,
237  0, 0,
238  data
239  );
240  CU_ASSERT(band != NULL);
241  rt_band_set_ownsdata_flag(band, 1);
242  CU_ASSERT(rt_band_get_ownsdata_flag(band));
243 
244  err = rt_band_set_nodata(band, 1, &clamped);
245  CU_ASSERT_EQUAL(err, ES_NONE);
246  CU_ASSERT(!clamped);
247  rt_band_get_nodata(band, &val);
248  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
249 
250  err = rt_band_set_nodata(band, 0, &clamped);
251  CU_ASSERT_EQUAL(err, ES_NONE);
252  CU_ASSERT(!clamped);
253  rt_band_get_nodata(band, &val);
254  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
255 
256  err = rt_band_set_nodata(band, 2, &clamped);
257  CU_ASSERT_EQUAL(err, ES_NONE);
258  CU_ASSERT(!clamped);
259  rt_band_get_nodata(band, &val);
260  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
261 
262  err = rt_band_set_nodata(band, 3, &clamped);
263  CU_ASSERT_EQUAL(err, ES_NONE);
264  CU_ASSERT(!clamped);
265  rt_band_get_nodata(band, &val);
266  CU_ASSERT_DOUBLE_EQUAL(val, 3, DBL_EPSILON);
267 
268  err = rt_band_set_nodata(band, 4, &clamped); /* invalid: out of range */
269  CU_ASSERT_EQUAL(err, ES_NONE);
270  CU_ASSERT(clamped);
271 
272  err = rt_band_set_nodata(band, 5, &clamped); /* invalid: out of range */
273  CU_ASSERT_EQUAL(err, ES_NONE);
274  CU_ASSERT(clamped);
275 
276  err = rt_band_set_pixel(band, 0, 0, 4, &clamped); /* out of range */
277  CU_ASSERT_EQUAL(err, ES_NONE);
278  CU_ASSERT(clamped);
279 
280  err = rt_band_set_pixel(band, 0, 0, 5, &clamped); /* out of range */
281  CU_ASSERT_EQUAL(err, ES_NONE);
282  CU_ASSERT(clamped);
283 
284  for (x=0; x<rt_band_get_width(band); ++x) {
285  for (y=0; y<rt_band_get_height(band); ++y) {
286  err = rt_band_set_pixel(band, x, y, 1, NULL);
287  CU_ASSERT_EQUAL(err, ES_NONE);
288  err = rt_band_get_pixel(band, x, y, &val, NULL);
289  CU_ASSERT_EQUAL(err, ES_NONE);
290  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
291 
292  err = rt_band_set_pixel(band, x, y, 2, NULL);
293  CU_ASSERT_EQUAL(err, ES_NONE);
294  err = rt_band_get_pixel(band, x, y, &val, NULL);
295  CU_ASSERT_EQUAL(err, ES_NONE);
296  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
297 
298  err = rt_band_set_pixel(band, x, y, 3, NULL);
299  CU_ASSERT_EQUAL(err, ES_NONE);
300  err = rt_band_get_pixel(band, x, y, &val, NULL);
301  CU_ASSERT_EQUAL(err, ES_NONE);
302  CU_ASSERT_DOUBLE_EQUAL(val, 3, DBL_EPSILON);
303  }
304  }
305 
306  rt_band_destroy(band);
307 }
308 
309 static void test_band_pixtype_4BUI() {
310  rt_pixtype pixtype = PT_4BUI;
311  uint8_t *data = NULL;
312  rt_band band = NULL;
313  int width = 5;
314  int height = 5;
315  int err = 0;
316  int clamped = 0;
317  double val = 0;
318  int x;
319  int y;
320 
321  /* inline band */
322  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
323  CU_ASSERT(data != NULL);
324  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
325 
326  band = rt_band_new_inline(
327  width, height,
328  pixtype,
329  0, 0,
330  data
331  );
332  CU_ASSERT(band != NULL);
333  rt_band_set_ownsdata_flag(band, 1);
334  CU_ASSERT(rt_band_get_ownsdata_flag(band));
335 
336  err = rt_band_set_nodata(band, 1, &clamped);
337  CU_ASSERT_EQUAL(err, ES_NONE);
338  CU_ASSERT(!clamped);
339  rt_band_get_nodata(band, &val);
340  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
341 
342  err = rt_band_set_nodata(band, 0, &clamped);
343  CU_ASSERT_EQUAL(err, ES_NONE);
344  CU_ASSERT(!clamped);
345  rt_band_get_nodata(band, &val);
346  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
347 
348  err = rt_band_set_nodata(band, 2, &clamped);
349  CU_ASSERT_EQUAL(err, ES_NONE);
350  CU_ASSERT(!clamped);
351  rt_band_get_nodata(band, &val);
352  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
353 
354  err = rt_band_set_nodata(band, 4, &clamped);
355  CU_ASSERT_EQUAL(err, ES_NONE);
356  CU_ASSERT(!clamped);
357  rt_band_get_nodata(band, &val);
358  CU_ASSERT_DOUBLE_EQUAL(val, 4, DBL_EPSILON);
359 
360  err = rt_band_set_nodata(band, 8, &clamped);
361  CU_ASSERT_EQUAL(err, ES_NONE);
362  CU_ASSERT(!clamped);
363  rt_band_get_nodata(band, &val);
364  CU_ASSERT_DOUBLE_EQUAL(val, 8, DBL_EPSILON);
365 
366  err = rt_band_set_nodata(band, 15, &clamped);
367  CU_ASSERT_EQUAL(err, ES_NONE);
368  CU_ASSERT(!clamped);
369  rt_band_get_nodata(band, &val);
370  CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
371 
372  err = rt_band_set_nodata(band, 16, &clamped); /* out of value range */
373  CU_ASSERT_EQUAL(err, ES_NONE);
374  CU_ASSERT(clamped);
375 
376  err = rt_band_set_nodata(band, 17, &clamped); /* out of value range */
377  CU_ASSERT_EQUAL(err, ES_NONE);
378  CU_ASSERT(clamped);
379 
380  err = rt_band_set_pixel(band, 0, 0, 35, &clamped); /* out of value range */
381  CU_ASSERT_EQUAL(err, ES_NONE);
382  CU_ASSERT(clamped);
383 
384  for (x=0; x<rt_band_get_width(band); ++x) {
385  for (y=0; y<rt_band_get_height(band); ++y) {
386  err = rt_band_set_pixel(band, x, y, 1, NULL);
387  CU_ASSERT_EQUAL(err, ES_NONE);
388  err = rt_band_get_pixel(band, x, y, &val, NULL);
389  CU_ASSERT_EQUAL(err, ES_NONE);
390  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
391 
392  err = rt_band_set_pixel(band, x, y, 3, NULL);
393  CU_ASSERT_EQUAL(err, ES_NONE);
394  err = rt_band_get_pixel(band, x, y, &val, NULL);
395  CU_ASSERT_EQUAL(err, ES_NONE);
396  CU_ASSERT_DOUBLE_EQUAL(val, 3, DBL_EPSILON);
397 
398  err = rt_band_set_pixel(band, x, y, 7, NULL);
399  CU_ASSERT_EQUAL(err, ES_NONE);
400  err = rt_band_get_pixel(band, x, y, &val, NULL);
401  CU_ASSERT_EQUAL(err, ES_NONE);
402  CU_ASSERT_DOUBLE_EQUAL(val, 7, DBL_EPSILON);
403 
404  err = rt_band_set_pixel(band, x, y, 15, NULL);
405  CU_ASSERT_EQUAL(err, ES_NONE);
406  err = rt_band_get_pixel(band, x, y, &val, NULL);
407  CU_ASSERT_EQUAL(err, ES_NONE);
408  CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
409  }
410  }
411 
412  rt_band_destroy(band);
413 }
414 
415 static void test_band_pixtype_8BUI() {
416  rt_pixtype pixtype = PT_8BUI;
417  uint8_t *data = NULL;
418  rt_band band = NULL;
419  int width = 5;
420  int height = 5;
421  int err = 0;
422  int clamped = 0;
423  double val = 0;
424  int x;
425  int y;
426 
427  /* inline band */
428  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
429  CU_ASSERT(data != NULL);
430  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
431 
432  band = rt_band_new_inline(
433  width, height,
434  pixtype,
435  0, 0,
436  data
437  );
438  CU_ASSERT(band != NULL);
439  rt_band_set_ownsdata_flag(band, 1);
440  CU_ASSERT(rt_band_get_ownsdata_flag(band));
441 
442  err = rt_band_set_nodata(band, 1, &clamped);
443  CU_ASSERT_EQUAL(err, ES_NONE);
444  CU_ASSERT(!clamped);
445  rt_band_get_nodata(band, &val);
446  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
447 
448  err = rt_band_set_nodata(band, 0, &clamped);
449  CU_ASSERT_EQUAL(err, ES_NONE);
450  CU_ASSERT(!clamped);
451  rt_band_get_nodata(band, &val);
452  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
453 
454  err = rt_band_set_nodata(band, 2, &clamped);
455  CU_ASSERT_EQUAL(err, ES_NONE);
456  CU_ASSERT(!clamped);
457  rt_band_get_nodata(band, &val);
458  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
459 
460  err = rt_band_set_nodata(band, 4, &clamped);
461  CU_ASSERT_EQUAL(err, ES_NONE);
462  CU_ASSERT(!clamped);
463  rt_band_get_nodata(band, &val);
464  CU_ASSERT_DOUBLE_EQUAL(val, 4, DBL_EPSILON);
465 
466  err = rt_band_set_nodata(band, 8, &clamped);
467  CU_ASSERT_EQUAL(err, ES_NONE);
468  CU_ASSERT(!clamped);
469  rt_band_get_nodata(band, &val);
470  CU_ASSERT_DOUBLE_EQUAL(val, 8, DBL_EPSILON);
471 
472  err = rt_band_set_nodata(band, 15, &clamped);
473  CU_ASSERT_EQUAL(err, ES_NONE);
474  CU_ASSERT(!clamped);
475  rt_band_get_nodata(band, &val);
476  CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
477 
478  err = rt_band_set_nodata(band, 31, &clamped);
479  CU_ASSERT_EQUAL(err, ES_NONE);
480  CU_ASSERT(!clamped);
481  rt_band_get_nodata(band, &val);
482  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
483 
484  err = rt_band_set_nodata(band, 255, &clamped);
485  CU_ASSERT_EQUAL(err, ES_NONE);
486  CU_ASSERT(!clamped);
487  rt_band_get_nodata(band, &val);
488  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
489 
490  err = rt_band_set_nodata(band, 256, &clamped); /* out of value range */
491  CU_ASSERT_EQUAL(err, ES_NONE);
492  CU_ASSERT(clamped);
493 
494  err = rt_band_set_pixel(band, 0, 0, 256, &clamped); /* out of value range */
495  CU_ASSERT_EQUAL(err, ES_NONE);
496  CU_ASSERT(clamped);
497 
498  for (x=0; x<rt_band_get_width(band); ++x) {
499  for (y=0; y<rt_band_get_height(band); ++y) {
500  err = rt_band_set_pixel(band, x, y, 31, NULL);
501  CU_ASSERT_EQUAL(err, ES_NONE);
502  err = rt_band_get_pixel(band, x, y, &val, NULL);
503  CU_ASSERT_EQUAL(err, ES_NONE);
504  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
505 
506  err = rt_band_set_pixel(band, x, y, 255, NULL);
507  CU_ASSERT_EQUAL(err, ES_NONE);
508  err = rt_band_get_pixel(band, x, y, &val, NULL);
509  CU_ASSERT_EQUAL(err, ES_NONE);
510  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
511 
512  err = rt_band_set_pixel(band, x, y, 1, NULL);
513  CU_ASSERT_EQUAL(err, ES_NONE);
514  err = rt_band_get_pixel(band, x, y, &val, NULL);
515  CU_ASSERT_EQUAL(err, ES_NONE);
516  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
517  }
518  }
519 
520  rt_band_destroy(band);
521 }
522 
523 static void test_band_pixtype_8BSI() {
524  rt_pixtype pixtype = PT_8BSI;
525  uint8_t *data = NULL;
526  rt_band band = NULL;
527  int width = 5;
528  int height = 5;
529  int err = 0;
530  int clamped = 0;
531  double val = 0;
532  int x;
533  int y;
534 
535  /* inline band */
536  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
537  CU_ASSERT(data != NULL);
538  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
539 
540  band = rt_band_new_inline(
541  width, height,
542  pixtype,
543  0, 0,
544  data
545  );
546  CU_ASSERT(band != NULL);
547  rt_band_set_ownsdata_flag(band, 1);
548  CU_ASSERT(rt_band_get_ownsdata_flag(band));
549 
550  err = rt_band_set_nodata(band, 1, &clamped);
551  CU_ASSERT_EQUAL(err, ES_NONE);
552  CU_ASSERT(!clamped);
553  rt_band_get_nodata(band, &val);
554  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
555 
556  err = rt_band_set_nodata(band, 0, &clamped);
557  CU_ASSERT_EQUAL(err, ES_NONE);
558  CU_ASSERT(!clamped);
559  rt_band_get_nodata(band, &val);
560  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
561 
562  err = rt_band_set_nodata(band, 2, &clamped);
563  CU_ASSERT_EQUAL(err, ES_NONE);
564  CU_ASSERT(!clamped);
565  rt_band_get_nodata(band, &val);
566  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
567 
568  err = rt_band_set_nodata(band, 4, &clamped);
569  CU_ASSERT_EQUAL(err, ES_NONE);
570  CU_ASSERT(!clamped);
571  rt_band_get_nodata(band, &val);
572  CU_ASSERT_DOUBLE_EQUAL(val, 4, DBL_EPSILON);
573 
574  err = rt_band_set_nodata(band, 8, &clamped);
575  CU_ASSERT_EQUAL(err, ES_NONE);
576  CU_ASSERT(!clamped);
577  rt_band_get_nodata(band, &val);
578  CU_ASSERT_DOUBLE_EQUAL(val, 8, DBL_EPSILON);
579 
580  err = rt_band_set_nodata(band, 15, &clamped);
581  CU_ASSERT_EQUAL(err, ES_NONE);
582  CU_ASSERT(!clamped);
583  rt_band_get_nodata(band, &val);
584  CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
585 
586  err = rt_band_set_nodata(band, 31, &clamped);
587  CU_ASSERT_EQUAL(err, ES_NONE);
588  CU_ASSERT(!clamped);
589  rt_band_get_nodata(band, &val);
590  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
591 
592  err = rt_band_set_nodata(band, -127, &clamped);
593  CU_ASSERT_EQUAL(err, ES_NONE);
594  CU_ASSERT(!clamped);
595  rt_band_get_nodata(band, &val);
596  CU_ASSERT_DOUBLE_EQUAL(val, -127, DBL_EPSILON);
597 
598  err = rt_band_set_nodata(band, 127, &clamped);
599  CU_ASSERT_EQUAL(err, ES_NONE);
600  CU_ASSERT(!clamped);
601  rt_band_get_nodata(band, &val);
602  CU_ASSERT_DOUBLE_EQUAL(val, 127, DBL_EPSILON);
603 
604  /* out of range (-127..127) */
605  err = rt_band_set_nodata(band, -129, &clamped);
606  CU_ASSERT_EQUAL(err, ES_NONE);
607  CU_ASSERT(clamped);
608 
609  /* out of range (-127..127) */
610  err = rt_band_set_nodata(band, 129, &clamped);
611  CU_ASSERT_EQUAL(err, ES_NONE);
612  CU_ASSERT(clamped);
613 
614  /* out of range (-127..127) */
615  err = rt_band_set_pixel(band, 0, 0, -129, &clamped);
616  CU_ASSERT_EQUAL(err, ES_NONE);
617  CU_ASSERT(clamped);
618 
619  /* out of range (-127..127) */
620  err = rt_band_set_pixel(band, 0, 0, 129, &clamped);
621  CU_ASSERT_EQUAL(err, ES_NONE);
622  CU_ASSERT(clamped);
623 
624  for (x=0; x<rt_band_get_width(band); ++x) {
625  for (y=0; y<rt_band_get_height(band); ++y) {
626  err = rt_band_set_pixel(band, x, y, 31, NULL);
627  CU_ASSERT_EQUAL(err, ES_NONE);
628  err = rt_band_get_pixel(band, x, y, &val, NULL);
629  CU_ASSERT_EQUAL(err, ES_NONE);
630  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
631 
632  err = rt_band_set_pixel(band, x, y, 1, NULL);
633  CU_ASSERT_EQUAL(err, ES_NONE);
634  err = rt_band_get_pixel(band, x, y, &val, NULL);
635  CU_ASSERT_EQUAL(err, ES_NONE);
636  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
637 
638  err = rt_band_set_pixel(band, x, y, -127, NULL);
639  CU_ASSERT_EQUAL(err, ES_NONE);
640  err = rt_band_get_pixel(band, x, y, &val, NULL);
641  CU_ASSERT_EQUAL(err, ES_NONE);
642  CU_ASSERT_DOUBLE_EQUAL(val, -127, DBL_EPSILON);
643 
644  err = rt_band_set_pixel(band, x, y, 127, NULL);
645  CU_ASSERT_EQUAL(err, ES_NONE);
646  err = rt_band_get_pixel(band, x, y, &val, NULL);
647  CU_ASSERT_EQUAL(err, ES_NONE);
648  CU_ASSERT_DOUBLE_EQUAL(val, 127, DBL_EPSILON);
649  }
650  }
651 
652  rt_band_destroy(band);
653 }
654 
655 static void test_band_pixtype_16BUI() {
656  rt_pixtype pixtype = PT_16BUI;
657  uint8_t *data = NULL;
658  rt_band band = NULL;
659  int width = 5;
660  int height = 5;
661  int err = 0;
662  int clamped = 0;
663  double val = 0;
664  int x;
665  int y;
666 
667  /* inline band */
668  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
669  CU_ASSERT(data != NULL);
670  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
671 
672  band = rt_band_new_inline(
673  width, height,
674  pixtype,
675  0, 0,
676  data
677  );
678  CU_ASSERT(band != NULL);
679  rt_band_set_ownsdata_flag(band, 1);
680  CU_ASSERT(rt_band_get_ownsdata_flag(band));
681 
682  err = rt_band_set_nodata(band, 1, &clamped);
683  CU_ASSERT_EQUAL(err, ES_NONE);
684  CU_ASSERT(!clamped);
685  rt_band_get_nodata(band, &val);
686  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
687 
688  err = rt_band_set_nodata(band, 0, &clamped);
689  CU_ASSERT_EQUAL(err, ES_NONE);
690  CU_ASSERT(!clamped);
691  rt_band_get_nodata(band, &val);
692  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
693 
694  err = rt_band_set_nodata(band, 31, &clamped);
695  CU_ASSERT_EQUAL(err, ES_NONE);
696  CU_ASSERT(!clamped);
697  rt_band_get_nodata(band, &val);
698  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
699 
700  err = rt_band_set_nodata(band, 255, &clamped);
701  CU_ASSERT_EQUAL(err, ES_NONE);
702  CU_ASSERT(!clamped);
703  rt_band_get_nodata(band, &val);
704  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
705 
706  err = rt_band_set_nodata(band, 65535, &clamped);
707  CU_ASSERT_EQUAL(err, ES_NONE);
708  CU_ASSERT(!clamped);
709  rt_band_get_nodata(band, &val);
710  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
711 
712  err = rt_band_set_nodata(band, 65536, &clamped); /* out of range */
713  CU_ASSERT_EQUAL(err, ES_NONE);
714  CU_ASSERT(clamped);
715 
716  /* out of value range */
717  err = rt_band_set_pixel(band, 0, 0, 65536, &clamped);
718  CU_ASSERT_EQUAL(err, ES_NONE);
719  CU_ASSERT(clamped);
720 
721  /* out of dimensions range */
722  err = rt_band_set_pixel(band, rt_band_get_width(band), 0, 0, &clamped);
723  CU_ASSERT((err != ES_NONE));
724 
725  for (x=0; x<rt_band_get_width(band); ++x) {
726  for (y=0; y<rt_band_get_height(band); ++y) {
727  err = rt_band_set_pixel(band, x, y, 255, NULL);
728  CU_ASSERT_EQUAL(err, ES_NONE);
729  err = rt_band_get_pixel(band, x, y, &val, NULL);
730  CU_ASSERT_EQUAL(err, ES_NONE);
731  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
732 
733  err = rt_band_set_pixel(band, x, y, 65535, NULL);
734  CU_ASSERT_EQUAL(err, ES_NONE);
735  err = rt_band_get_pixel(band, x, y, &val, NULL);
736  CU_ASSERT_EQUAL(err, ES_NONE);
737  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
738  }
739  }
740 
741  rt_band_destroy(band);
742 }
743 
744 static void test_band_pixtype_16BSI() {
745  rt_pixtype pixtype = PT_16BSI;
746  uint8_t *data = NULL;
747  rt_band band = NULL;
748  int width = 5;
749  int height = 5;
750  int err = 0;
751  int clamped = 0;
752  double val = 0;
753  int x;
754  int y;
755 
756  /* inline band */
757  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
758  CU_ASSERT(data != NULL);
759  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
760 
761  band = rt_band_new_inline(
762  width, height,
763  pixtype,
764  0, 0,
765  data
766  );
767  CU_ASSERT(band != NULL);
768  rt_band_set_ownsdata_flag(band, 1);
769  CU_ASSERT(rt_band_get_ownsdata_flag(band));
770 
771  err = rt_band_set_nodata(band, 1, &clamped);
772  CU_ASSERT_EQUAL(err, ES_NONE);
773  CU_ASSERT(!clamped);
774  rt_band_get_nodata(band, &val);
775  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
776 
777  err = rt_band_set_nodata(band, 0, &clamped);
778  CU_ASSERT_EQUAL(err, ES_NONE);
779  CU_ASSERT(!clamped);
780  rt_band_get_nodata(band, &val);
781  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
782 
783  err = rt_band_set_nodata(band, 31, &clamped);
784  CU_ASSERT_EQUAL(err, ES_NONE);
785  CU_ASSERT(!clamped);
786  rt_band_get_nodata(band, &val);
787  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
788 
789  err = rt_band_set_nodata(band, 255, &clamped);
790  CU_ASSERT_EQUAL(err, ES_NONE);
791  CU_ASSERT(!clamped);
792  rt_band_get_nodata(band, &val);
793  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
794 
795  err = rt_band_set_nodata(band, -32767, &clamped);
796  CU_ASSERT_EQUAL(err, ES_NONE);
797  CU_ASSERT(!clamped);
798  rt_band_get_nodata(band, &val);
799  CU_ASSERT_DOUBLE_EQUAL(val, -32767, DBL_EPSILON);
800 
801  err = rt_band_set_nodata(band, 32767, &clamped);
802  CU_ASSERT_EQUAL(err, ES_NONE);
803  CU_ASSERT(!clamped);
804  rt_band_get_nodata(band, &val);
805  CU_ASSERT_DOUBLE_EQUAL(val, 32767, DBL_EPSILON);
806 
807  /* out of range (-32767..32767) */
808  err = rt_band_set_nodata(band, -32769, &clamped);
809  CU_ASSERT_EQUAL(err, ES_NONE);
810  CU_ASSERT(clamped);
811 
812  /* out of range (-32767..32767) */
813  err = rt_band_set_nodata(band, 32769, &clamped);
814  CU_ASSERT_EQUAL(err, ES_NONE);
815  CU_ASSERT(clamped);
816 
817  /* out of range (-32767..32767) */
818  err = rt_band_set_pixel(band, 0, 0, -32769, &clamped);
819  CU_ASSERT_EQUAL(err, ES_NONE);
820  CU_ASSERT(clamped);
821 
822  /* out of range (-32767..32767) */
823  err = rt_band_set_pixel(band, 0, 0, 32769, &clamped);
824  CU_ASSERT_EQUAL(err, ES_NONE);
825  CU_ASSERT(clamped);
826 
827  /* out of dimensions range */
828  err = rt_band_set_pixel(band, rt_band_get_width(band), 0, 0, NULL);
829  CU_ASSERT((err != ES_NONE));
830 
831  for (x=0; x<rt_band_get_width(band); ++x) {
832  for (y=0; y<rt_band_get_height(band); ++y) {
833  err = rt_band_set_pixel(band, x, y, 255, NULL);
834  CU_ASSERT_EQUAL(err, ES_NONE);
835  err = rt_band_get_pixel(band, x, y, &val, NULL);
836  CU_ASSERT_EQUAL(err, ES_NONE);
837  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
838 
839  err = rt_band_set_pixel(band, x, y, -32767, NULL);
840  CU_ASSERT_EQUAL(err, ES_NONE);
841  err = rt_band_get_pixel(band, x, y, &val, NULL);
842  CU_ASSERT_EQUAL(err, ES_NONE);
843  CU_ASSERT_DOUBLE_EQUAL(val, -32767, DBL_EPSILON);
844 
845  err = rt_band_set_pixel(band, x, y, 32767, NULL);
846  CU_ASSERT_EQUAL(err, ES_NONE);
847  err = rt_band_get_pixel(band, x, y, &val, NULL);
848  CU_ASSERT_EQUAL(err, ES_NONE);
849  CU_ASSERT_DOUBLE_EQUAL(val, 32767, DBL_EPSILON);
850  }
851  }
852 
853  rt_band_destroy(band);
854 }
855 
856 static void test_band_pixtype_32BUI() {
857  rt_pixtype pixtype = PT_32BUI;
858  uint8_t *data = NULL;
859  rt_band band = NULL;
860  int width = 5;
861  int height = 5;
862  int err = 0;
863  int clamped = 0;
864  double val = 0;
865  int x;
866  int y;
867 
868  /* inline band */
869  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
870  CU_ASSERT(data != NULL);
871  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
872 
873  band = rt_band_new_inline(
874  width, height,
875  pixtype,
876  0, 0,
877  data
878  );
879  CU_ASSERT(band != NULL);
880  rt_band_set_ownsdata_flag(band, 1);
881  CU_ASSERT(rt_band_get_ownsdata_flag(band));
882 
883  err = rt_band_set_nodata(band, 1, &clamped);
884  CU_ASSERT_EQUAL(err, ES_NONE);
885  CU_ASSERT(!clamped);
886  rt_band_get_nodata(band, &val);
887  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
888 
889  err = rt_band_set_nodata(band, 0, &clamped);
890  CU_ASSERT_EQUAL(err, ES_NONE);
891  CU_ASSERT(!clamped);
892  rt_band_get_nodata(band, &val);
893  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
894 
895  err = rt_band_set_nodata(band, 65535, &clamped);
896  CU_ASSERT_EQUAL(err, ES_NONE);
897  CU_ASSERT(!clamped);
898  rt_band_get_nodata(band, &val);
899  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
900 
901  err = rt_band_set_nodata(band, 4294967295UL, &clamped);
902  CU_ASSERT_EQUAL(err, ES_NONE);
903  CU_ASSERT(!clamped);
904  rt_band_get_nodata(band, &val);
905  CU_ASSERT_DOUBLE_EQUAL(val, 4294967295UL, DBL_EPSILON);
906 
907  /* out of range */
908  err = rt_band_set_nodata(band, 4294967296ULL, &clamped);
909  CU_ASSERT_EQUAL(err, ES_NONE);
910  CU_ASSERT(clamped);
911 
912  /* out of value range */
913  err = rt_band_set_pixel(band, 0, 0, 4294967296ULL, &clamped);
914  CU_ASSERT_EQUAL(err, ES_NONE);
915  CU_ASSERT(clamped);
916 
917  /* out of dimensions range */
918  err = rt_band_set_pixel(band, rt_band_get_width(band), 0, 4294967296ULL, NULL);
919  CU_ASSERT((err != ES_NONE));
920 
921  for (x=0; x<rt_band_get_width(band); ++x) {
922  for (y=0; y<rt_band_get_height(band); ++y) {
923  err = rt_band_set_pixel(band, x, y, 1, NULL);
924  CU_ASSERT_EQUAL(err, ES_NONE);
925  err = rt_band_get_pixel(band, x, y, &val, NULL);
926  CU_ASSERT_EQUAL(err, ES_NONE);
927  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
928 
929  err = rt_band_set_pixel(band, x, y, 0, NULL);
930  CU_ASSERT_EQUAL(err, ES_NONE);
931  err = rt_band_get_pixel(band, x, y, &val, NULL);
932  CU_ASSERT_EQUAL(err, ES_NONE);
933  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
934 
935  err = rt_band_set_pixel(band, x, y, 65535, NULL);
936  CU_ASSERT_EQUAL(err, ES_NONE);
937  err = rt_band_get_pixel(band, x, y, &val, NULL);
938  CU_ASSERT_EQUAL(err, ES_NONE);
939  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
940 
941  err = rt_band_set_pixel(band, x, y, 4294967295UL, NULL);
942  CU_ASSERT_EQUAL(err, ES_NONE);
943  err = rt_band_get_pixel(band, x, y, &val, NULL);
944  CU_ASSERT_EQUAL(err, ES_NONE);
945  CU_ASSERT_DOUBLE_EQUAL(val, 4294967295UL, DBL_EPSILON);
946  }
947  }
948 
949  rt_band_destroy(band);
950 }
951 
952 static void test_band_pixtype_32BSI() {
953  rt_pixtype pixtype = PT_32BSI;
954  uint8_t *data = NULL;
955  rt_band band = NULL;
956  int width = 5;
957  int height = 5;
958  int err = 0;
959  int clamped = 0;
960  double val = 0;
961  int x;
962  int y;
963 
964  /* inline band */
965  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
966  CU_ASSERT(data != NULL);
967  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
968 
969  band = rt_band_new_inline(
970  width, height,
971  pixtype,
972  0, 0,
973  data
974  );
975  CU_ASSERT(band != NULL);
976  rt_band_set_ownsdata_flag(band, 1);
977  CU_ASSERT(rt_band_get_ownsdata_flag(band));
978 
979  err = rt_band_set_nodata(band, 1, &clamped);
980  CU_ASSERT_EQUAL(err, ES_NONE);
981  CU_ASSERT(!clamped);
982  rt_band_get_nodata(band, &val);
983  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
984 
985  err = rt_band_set_nodata(band, 0, &clamped);
986  CU_ASSERT_EQUAL(err, ES_NONE);
987  CU_ASSERT(!clamped);
988  rt_band_get_nodata(band, &val);
989  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
990 
991  err = rt_band_set_nodata(band, 65535, &clamped);
992  CU_ASSERT_EQUAL(err, ES_NONE);
993  CU_ASSERT(!clamped);
994  rt_band_get_nodata(band, &val);
995  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
996 
997  err = rt_band_set_nodata(band, 2147483647, &clamped);
998  CU_ASSERT_EQUAL(err, ES_NONE);
999  CU_ASSERT(!clamped);
1000  rt_band_get_nodata(band, &val);
1001  /*printf("32BSI pix is %ld\n", (long int)val);*/
1002  CU_ASSERT_DOUBLE_EQUAL(val, 2147483647, DBL_EPSILON);
1003 
1004  /* out of range */
1005  err = rt_band_set_nodata(band, 2147483648UL, &clamped);
1006  CU_ASSERT_EQUAL(err, ES_NONE);
1007  CU_ASSERT(clamped);
1008 
1009  /* out of value range */
1010  err = rt_band_set_pixel(band, 0, 0, 2147483648UL, &clamped);
1011  CU_ASSERT_EQUAL(err, ES_NONE);
1012  CU_ASSERT(clamped);
1013 
1014  /* out of dimensions range */
1015  err = rt_band_set_pixel(band, rt_band_get_width(band), 0, 0, NULL);
1016  CU_ASSERT((err != ES_NONE));
1017 
1018  for (x=0; x<rt_band_get_width(band); ++x) {
1019  for (y=0; y<rt_band_get_height(band); ++y) {
1020  err = rt_band_set_pixel(band, x, y, 1, NULL);
1021  CU_ASSERT_EQUAL(err, ES_NONE);
1022  err = rt_band_get_pixel(band, x, y, &val, NULL);
1023  CU_ASSERT_EQUAL(err, ES_NONE);
1024  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1025 
1026  err = rt_band_set_pixel(band, x, y, 0, NULL);
1027  CU_ASSERT_EQUAL(err, ES_NONE);
1028  err = rt_band_get_pixel(band, x, y, &val, NULL);
1029  CU_ASSERT_EQUAL(err, ES_NONE);
1030  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1031 
1032  err = rt_band_set_pixel(band, x, y, 65535, NULL);
1033  CU_ASSERT_EQUAL(err, ES_NONE);
1034  err = rt_band_get_pixel(band, x, y, &val, NULL);
1035  CU_ASSERT_EQUAL(err, ES_NONE);
1036  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
1037 
1038  err = rt_band_set_pixel(band, x, y, 2147483647, NULL);
1039  CU_ASSERT_EQUAL(err, ES_NONE);
1040  err = rt_band_get_pixel(band, x, y, &val, NULL);
1041  CU_ASSERT_EQUAL(err, ES_NONE);
1042  CU_ASSERT_DOUBLE_EQUAL(val, 2147483647, DBL_EPSILON);
1043  }
1044  }
1045 
1046  rt_band_destroy(band);
1047 }
1048 
1049 static void test_band_pixtype_32BF() {
1050  rt_pixtype pixtype = PT_32BF;
1051  uint8_t *data = NULL;
1052  rt_band band = NULL;
1053  int width = 5;
1054  int height = 5;
1055  int err = 0;
1056  int clamped = 0;
1057  double val = 0;
1058  int x;
1059  int y;
1060 
1061  /* inline band */
1062  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
1063  CU_ASSERT(data != NULL);
1064  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
1065 
1066  band = rt_band_new_inline(
1067  width, height,
1068  pixtype,
1069  0, 0,
1070  data
1071  );
1072  CU_ASSERT(band != NULL);
1073  rt_band_set_ownsdata_flag(band, 1);
1074  CU_ASSERT(rt_band_get_ownsdata_flag(band));
1075 
1076  err = rt_band_set_nodata(band, 1, &clamped);
1077  CU_ASSERT_EQUAL(err, ES_NONE);
1078  CU_ASSERT(!clamped);
1079  rt_band_get_nodata(band, &val);
1080  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1081 
1082  err = rt_band_set_nodata(band, 0, &clamped);
1083  CU_ASSERT_EQUAL(err, ES_NONE);
1084  CU_ASSERT(!clamped);
1085  rt_band_get_nodata(band, &val);
1086  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1087 
1088  err = rt_band_set_nodata(band, 65535.5, &clamped);
1089  CU_ASSERT_EQUAL(err, ES_NONE);
1090  CU_ASSERT(!clamped);
1091  rt_band_get_nodata(band, &val);
1092  CU_ASSERT_DOUBLE_EQUAL(val, 65535.5, DBL_EPSILON);
1093 
1094  err = rt_band_set_nodata(band, 0.006, &clamped);
1095  CU_ASSERT_EQUAL(err, ES_NONE);
1096  CU_ASSERT(!clamped);
1097  rt_band_get_nodata(band, &val);
1098  CU_ASSERT_DOUBLE_EQUAL(val, 0.0060000000521540, DBL_EPSILON);
1099 
1100  for (x=0; x<rt_band_get_width(band); ++x) {
1101  for (y=0; y<rt_band_get_height(band); ++y) {
1102  err = rt_band_set_pixel(band, x, y, 1, NULL);
1103  CU_ASSERT_EQUAL(err, ES_NONE);
1104  err = rt_band_get_pixel(band, x, y, &val, NULL);
1105  CU_ASSERT_EQUAL(err, ES_NONE);
1106  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1107 
1108  err = rt_band_set_pixel(band, x, y, 0, NULL);
1109  CU_ASSERT_EQUAL(err, ES_NONE);
1110  err = rt_band_get_pixel(band, x, y, &val, NULL);
1111  CU_ASSERT_EQUAL(err, ES_NONE);
1112  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1113 
1114  err = rt_band_set_pixel(band, x, y, 65535.5, NULL);
1115  CU_ASSERT_EQUAL(err, ES_NONE);
1116  err = rt_band_get_pixel(band, x, y, &val, NULL);
1117  CU_ASSERT_EQUAL(err, ES_NONE);
1118  CU_ASSERT_DOUBLE_EQUAL(val, 65535.5, DBL_EPSILON);
1119 
1120  err = rt_band_set_pixel(band, x, y, 0.006, NULL);
1121  CU_ASSERT_EQUAL(err, ES_NONE);
1122  err = rt_band_get_pixel(band, x, y, &val, NULL);
1123  CU_ASSERT_EQUAL(err, ES_NONE);
1124  CU_ASSERT_DOUBLE_EQUAL(val, 0.0060000000521540, DBL_EPSILON);
1125  }
1126  }
1127 
1128  rt_band_destroy(band);
1129 }
1130 
1131 static void test_band_pixtype_64BF() {
1132  rt_pixtype pixtype = PT_64BF;
1133  uint8_t *data = NULL;
1134  rt_band band = NULL;
1135  int width = 5;
1136  int height = 5;
1137  int err = 0;
1138  int clamped = 0;
1139  double val = 0;
1140  int x;
1141  int y;
1142 
1143  /* inline band */
1144  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
1145  CU_ASSERT(data != NULL);
1146  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
1147 
1148  band = rt_band_new_inline(
1149  width, height,
1150  pixtype,
1151  0, 0,
1152  data
1153  );
1154  CU_ASSERT(band != NULL);
1155  rt_band_set_ownsdata_flag(band, 1);
1156  CU_ASSERT(rt_band_get_ownsdata_flag(band));
1157 
1158  err = rt_band_set_nodata(band, 1, &clamped);
1159  CU_ASSERT_EQUAL(err, ES_NONE);
1160  CU_ASSERT(!clamped);
1161  rt_band_get_nodata(band, &val);
1162  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1163 
1164  err = rt_band_set_nodata(band, 0, &clamped);
1165  CU_ASSERT_EQUAL(err, ES_NONE);
1166  CU_ASSERT(!clamped);
1167  rt_band_get_nodata(band, &val);
1168  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1169 
1170  err = rt_band_set_nodata(band, 65535.56, &clamped);
1171  CU_ASSERT_EQUAL(err, ES_NONE);
1172  CU_ASSERT(!clamped);
1173  rt_band_get_nodata(band, &val);
1174  CU_ASSERT_DOUBLE_EQUAL(val, 65535.56, DBL_EPSILON);
1175 
1176  err = rt_band_set_nodata(band, 0.006, &clamped);
1177  CU_ASSERT_EQUAL(err, ES_NONE);
1178  CU_ASSERT(!clamped);
1179  rt_band_get_nodata(band, &val);
1180  CU_ASSERT_DOUBLE_EQUAL(val, 0.006, DBL_EPSILON);
1181 
1182  for (x=0; x<rt_band_get_width(band); ++x) {
1183  for (y=0; y<rt_band_get_height(band); ++y) {
1184  err = rt_band_set_pixel(band, x, y, 1, NULL);
1185  CU_ASSERT_EQUAL(err, ES_NONE);
1186  err = rt_band_get_pixel(band, x, y, &val, NULL);
1187  CU_ASSERT_EQUAL(err, ES_NONE);
1188  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1189 
1190  err = rt_band_set_pixel(band, x, y, 0, NULL);
1191  CU_ASSERT_EQUAL(err, ES_NONE);
1192  err = rt_band_get_pixel(band, x, y, &val, NULL);
1193  CU_ASSERT_EQUAL(err, ES_NONE);
1194  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1195 
1196  err = rt_band_set_pixel(band, x, y, 65535.56, NULL);
1197  CU_ASSERT_EQUAL(err, ES_NONE);
1198  err = rt_band_get_pixel(band, x, y, &val, NULL);
1199  CU_ASSERT_EQUAL(err, ES_NONE);
1200  CU_ASSERT_DOUBLE_EQUAL(val, 65535.56, DBL_EPSILON);
1201 
1202  err = rt_band_set_pixel(band, x, y, 0.006, NULL);
1203  CU_ASSERT_EQUAL(err, ES_NONE);
1204  err = rt_band_get_pixel(band, x, y, &val, NULL);
1205  CU_ASSERT_EQUAL(err, ES_NONE);
1206  CU_ASSERT_DOUBLE_EQUAL(val, 0.006, DBL_EPSILON);
1207  }
1208  }
1209 
1210  rt_band_destroy(band);
1211 }
1212 
1214  rt_raster rast;
1215  rt_band band;
1216  int maxX = 5;
1217  int maxY = 5;
1218  int x = 0;
1219  int y = 0;
1220  void *vals = NULL;
1221  uint16_t nvals = 0;
1222  int err = 0;
1223 
1224  rast = rt_raster_new(maxX, maxY);
1225  CU_ASSERT(rast != NULL);
1226 
1227  rt_raster_set_scale(rast, 1, -1);
1228 
1229  band = cu_add_band(rast, PT_8BSI, 0, 0);
1230  CU_ASSERT(band != NULL);
1231 
1232  for (y = 0; y < maxY; y++) {
1233  for (x = 0; x < maxX; x++)
1234  rt_band_set_pixel(band, x, y, x + (y * maxX), NULL);
1235  }
1236 
1237  err = rt_band_get_pixel_line(band, 0, 0, maxX, &vals, &nvals);
1238  CU_ASSERT_EQUAL(err, ES_NONE);
1239  CU_ASSERT_EQUAL(nvals, maxX);
1240  CU_ASSERT_EQUAL(((int8_t *) vals)[3], 3);
1241  rtdealloc(vals);
1242 
1243  err = rt_band_get_pixel_line(band, 4, 4, maxX, &vals, &nvals);
1244  CU_ASSERT_EQUAL(err, ES_NONE);
1245  CU_ASSERT_EQUAL(nvals, 1);
1246  CU_ASSERT_EQUAL(((int8_t *) vals)[0], 24);
1247  rtdealloc(vals);
1248 
1249  err = rt_band_get_pixel_line(band, maxX, maxY, maxX, &vals, &nvals);
1250  CU_ASSERT_NOT_EQUAL(err, ES_NONE);
1251 
1252  cu_free_raster(rast);
1253 }
1254 
1255 /* register tests */
1256 void band_basics_suite_setup(void);
1258 {
1259  CU_pSuite suite = CU_add_suite("band_basics", NULL, NULL);
1273 }
1274 
void band_basics_suite_setup(void)
band
Definition: ovdump.py:57
static void test_band_get_pixel_line()
static void test_band_pixtype_8BSI()
int rt_band_is_offline(rt_band band)
Return non-zero if the given band data is on the filesystem.
Definition: rt_band.c:228
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
data
Definition: ovdump.py:103
static void test_band_pixtype_1BB()
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:600
rt_pixtype
Definition: librtcore.h:197
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:242
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1597
const char * rt_band_get_ext_path(rt_band band)
Return band&#39;s external path (only valid when rt_band_is_offline returns non-zero).
Definition: rt_band.c:265
void cu_free_raster(rt_raster raster)
rt_band cu_add_band(rt_raster raster, rt_pixtype pixtype, int hasnodata, double nodataval)
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_band.c:534
static void test_band_pixtype_32BUI()
int rt_band_get_ownsdata_flag(rt_band band)
Return 0 (FALSE) or non-zero (TRUE) indicating if rt_band is responsible for managing the memory for ...
Definition: rt_band.c:526
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1088
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
Definition: rt_raster.c:137
rt_errorstate rt_band_get_pixel_line(rt_band band, int x, int y, uint16_t len, void **vals, uint16_t *nvals)
Get values of multiple pixels.
Definition: rt_band.c:1004
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
Definition: rt_raster.c:199
union rt_band_t::@6 data
#define PG_ADD_TEST(suite, testfunc)
rt_errorstate rt_band_load_offline_data(rt_band band)
Load offline band&#39;s data.
Definition: rt_band.c:331
static void test_band_pixtype_16BSI()
static void test_band_pixtype_32BF()
int rt_band_check_is_nodata(rt_band band)
Returns TRUE if the band is only nodata values.
Definition: rt_band.c:1619
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
Definition: rt_band.c:541
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition: rt_band.c:507
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition: rt_band.c:516
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:302
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
Definition: rt_raster.c:48
rt_band rt_band_new_inline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t *data)
Create an in-db rt_band with no data.
Definition: rt_band.c:58
rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum)
Return bands&#39; external band number (only valid when rt_band_is_offline returns non-zero).
Definition: rt_band.c:278
static void test_band_pixtype_4BUI()
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
Definition: rt_band.c:548
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
static void test_band_metadata()
static void test_band_pixtype_8BUI()
int32_t offline
Definition: librtcore.h:2278
static void test_band_pixtype_16BUI()
void rtdealloc(void *mem)
Definition: rt_context.c:186
#define FALSE
Definition: dbfopen.c:168
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
Definition: rt_band.c:498
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
Definition: rt_raster.c:405
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
Definition: rt_band.c:581
static void test_band_pixtype_64BF()
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel&#39;s value.
Definition: rt_band.c:841
static void test_band_pixtype_32BSI()
static void test_band_pixtype_2BUI()
rt_band rt_band_new_offline(uint16_t width, uint16_t height, rt_pixtype pixtype, uint32_t hasnodata, double nodataval, uint8_t bandNum, const char *path)
Create an out-db rt_band.
Definition: rt_band.c:119