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