24 #include "CUnit/Basic.h" 35 char *path =
"../regress/loader/testraster.tif";
42 CU_ASSERT(data != NULL);
43 memset(data, 0,
sizeof(
uint8_t) * width * height);
51 CU_ASSERT(band != NULL);
80 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
86 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
107 CU_ASSERT(band != NULL);
110 CU_ASSERT(rast != NULL);
122 CU_ASSERT_EQUAL(extband, 2);
128 for (x = 0; x < width; x++) {
129 for (y = 0; y < height; y++) {
131 CU_ASSERT_DOUBLE_EQUAL(val, 0, 1.);
157 CU_ASSERT(data != NULL);
166 CU_ASSERT(band != NULL);
175 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
180 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
204 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
210 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
231 CU_ASSERT(data != NULL);
240 CU_ASSERT(band != NULL);
248 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
254 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
260 CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
266 CU_ASSERT_DOUBLE_EQUAL(val, 3, DBL_EPSILON);
290 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
296 CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
302 CU_ASSERT_DOUBLE_EQUAL(val, 3, DBL_EPSILON);
323 CU_ASSERT(data != NULL);
332 CU_ASSERT(band != NULL);
340 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
346 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
352 CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
358 CU_ASSERT_DOUBLE_EQUAL(val, 4, DBL_EPSILON);
364 CU_ASSERT_DOUBLE_EQUAL(val, 8, DBL_EPSILON);
370 CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
390 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
396 CU_ASSERT_DOUBLE_EQUAL(val, 3, DBL_EPSILON);
402 CU_ASSERT_DOUBLE_EQUAL(val, 7, DBL_EPSILON);
408 CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
429 CU_ASSERT(data != NULL);
438 CU_ASSERT(band != NULL);
446 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
452 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
458 CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
464 CU_ASSERT_DOUBLE_EQUAL(val, 4, DBL_EPSILON);
470 CU_ASSERT_DOUBLE_EQUAL(val, 8, DBL_EPSILON);
476 CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
482 CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
488 CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
504 CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
510 CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
516 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
537 CU_ASSERT(data != NULL);
546 CU_ASSERT(band != NULL);
554 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
560 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
566 CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
572 CU_ASSERT_DOUBLE_EQUAL(val, 4, DBL_EPSILON);
578 CU_ASSERT_DOUBLE_EQUAL(val, 8, DBL_EPSILON);
584 CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
590 CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
596 CU_ASSERT_DOUBLE_EQUAL(val, -127, DBL_EPSILON);
602 CU_ASSERT_DOUBLE_EQUAL(val, 127, DBL_EPSILON);
630 CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
636 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
642 CU_ASSERT_DOUBLE_EQUAL(val, -127, DBL_EPSILON);
648 CU_ASSERT_DOUBLE_EQUAL(val, 127, DBL_EPSILON);
669 CU_ASSERT(data != NULL);
678 CU_ASSERT(band != NULL);
686 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
692 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
698 CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
704 CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
710 CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
731 CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
737 CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
758 CU_ASSERT(data != NULL);
767 CU_ASSERT(band != NULL);
775 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
781 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
787 CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
793 CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
799 CU_ASSERT_DOUBLE_EQUAL(val, -32767, DBL_EPSILON);
805 CU_ASSERT_DOUBLE_EQUAL(val, 32767, DBL_EPSILON);
837 CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
843 CU_ASSERT_DOUBLE_EQUAL(val, -32767, DBL_EPSILON);
849 CU_ASSERT_DOUBLE_EQUAL(val, 32767, DBL_EPSILON);
870 CU_ASSERT(data != NULL);
879 CU_ASSERT(band != NULL);
887 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
893 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
899 CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
905 CU_ASSERT_DOUBLE_EQUAL(val, 4294967295UL, DBL_EPSILON);
927 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
933 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
939 CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
945 CU_ASSERT_DOUBLE_EQUAL(val, 4294967295UL, DBL_EPSILON);
966 CU_ASSERT(data != NULL);
975 CU_ASSERT(band != NULL);
983 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
989 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
995 CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
1002 CU_ASSERT_DOUBLE_EQUAL(val, 2147483647, DBL_EPSILON);
1006 CU_ASSERT_EQUAL(err,
ES_NONE);
1011 CU_ASSERT_EQUAL(err,
ES_NONE);
1021 CU_ASSERT_EQUAL(err,
ES_NONE);
1023 CU_ASSERT_EQUAL(err,
ES_NONE);
1024 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1027 CU_ASSERT_EQUAL(err,
ES_NONE);
1029 CU_ASSERT_EQUAL(err,
ES_NONE);
1030 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1033 CU_ASSERT_EQUAL(err,
ES_NONE);
1035 CU_ASSERT_EQUAL(err,
ES_NONE);
1036 CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
1039 CU_ASSERT_EQUAL(err,
ES_NONE);
1041 CU_ASSERT_EQUAL(err,
ES_NONE);
1042 CU_ASSERT_DOUBLE_EQUAL(val, 2147483647, DBL_EPSILON);
1063 CU_ASSERT(data != NULL);
1072 CU_ASSERT(band != NULL);
1077 CU_ASSERT_EQUAL(err,
ES_NONE);
1078 CU_ASSERT(!clamped);
1080 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1083 CU_ASSERT_EQUAL(err,
ES_NONE);
1084 CU_ASSERT(!clamped);
1086 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1089 CU_ASSERT_EQUAL(err,
ES_NONE);
1090 CU_ASSERT(!clamped);
1092 CU_ASSERT_DOUBLE_EQUAL(val, 65535.5, DBL_EPSILON);
1095 CU_ASSERT_EQUAL(err,
ES_NONE);
1096 CU_ASSERT(!clamped);
1098 CU_ASSERT_DOUBLE_EQUAL(val, 0.0060000000521540, DBL_EPSILON);
1103 CU_ASSERT_EQUAL(err,
ES_NONE);
1105 CU_ASSERT_EQUAL(err,
ES_NONE);
1106 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1109 CU_ASSERT_EQUAL(err,
ES_NONE);
1111 CU_ASSERT_EQUAL(err,
ES_NONE);
1112 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1115 CU_ASSERT_EQUAL(err,
ES_NONE);
1117 CU_ASSERT_EQUAL(err,
ES_NONE);
1118 CU_ASSERT_DOUBLE_EQUAL(val, 65535.5, DBL_EPSILON);
1121 CU_ASSERT_EQUAL(err,
ES_NONE);
1123 CU_ASSERT_EQUAL(err,
ES_NONE);
1124 CU_ASSERT_DOUBLE_EQUAL(val, 0.0060000000521540, DBL_EPSILON);
1145 CU_ASSERT(data != NULL);
1154 CU_ASSERT(band != NULL);
1159 CU_ASSERT_EQUAL(err,
ES_NONE);
1160 CU_ASSERT(!clamped);
1162 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1165 CU_ASSERT_EQUAL(err,
ES_NONE);
1166 CU_ASSERT(!clamped);
1168 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1171 CU_ASSERT_EQUAL(err,
ES_NONE);
1172 CU_ASSERT(!clamped);
1174 CU_ASSERT_DOUBLE_EQUAL(val, 65535.56, DBL_EPSILON);
1177 CU_ASSERT_EQUAL(err,
ES_NONE);
1178 CU_ASSERT(!clamped);
1180 CU_ASSERT_DOUBLE_EQUAL(val, 0.006, DBL_EPSILON);
1185 CU_ASSERT_EQUAL(err,
ES_NONE);
1187 CU_ASSERT_EQUAL(err,
ES_NONE);
1188 CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1191 CU_ASSERT_EQUAL(err,
ES_NONE);
1193 CU_ASSERT_EQUAL(err,
ES_NONE);
1194 CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1197 CU_ASSERT_EQUAL(err,
ES_NONE);
1199 CU_ASSERT_EQUAL(err,
ES_NONE);
1200 CU_ASSERT_DOUBLE_EQUAL(val, 65535.56, DBL_EPSILON);
1203 CU_ASSERT_EQUAL(err,
ES_NONE);
1205 CU_ASSERT_EQUAL(err,
ES_NONE);
1206 CU_ASSERT_DOUBLE_EQUAL(val, 0.006, DBL_EPSILON);
1225 CU_ASSERT(rast != NULL);
1230 CU_ASSERT(band != NULL);
1232 for (y = 0; y < maxY; y++) {
1233 for (x = 0; x < maxX; x++)
1238 CU_ASSERT_EQUAL(err,
ES_NONE);
1239 CU_ASSERT_EQUAL(nvals, maxX);
1240 CU_ASSERT_EQUAL(((int8_t *) vals)[3], 3);
1244 CU_ASSERT_EQUAL(err,
ES_NONE);
1245 CU_ASSERT_EQUAL(nvals, 1);
1246 CU_ASSERT_EQUAL(((int8_t *) vals)[0], 24);
1250 CU_ASSERT_NOT_EQUAL(err,
ES_NONE);
1259 CU_pSuite suite = CU_add_suite(
"band_basics", NULL, NULL);
void band_basics_suite_setup(void)
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.
void * rtalloc(size_t size)
Wrappers used for managing memory.
static void test_band_pixtype_1BB()
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
void rt_band_destroy(rt_band band)
Destroy a raster band.
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
const char * rt_band_get_ext_path(rt_band band)
Return band's external path (only valid when rt_band_is_offline returns non-zero).
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)
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 ...
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
void rt_raster_set_scale(rt_raster raster, double scaleX, double scaleY)
Set scale in projection units.
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.
void rt_raster_set_offsets(rt_raster raster, double x, double y)
Set insertion points in projection units.
#define PG_ADD_TEST(suite, testfunc)
rt_errorstate rt_band_load_offline_data(rt_band band)
Load offline band's data.
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.
int rt_band_get_hasnodata_flag(rt_band band)
Get hasnodata flag value.
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
rt_raster rt_raster_new(uint32_t width, uint32_t height)
Construct a raster with given dimensions.
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.
rt_errorstate rt_band_get_ext_band_num(rt_band band, uint8_t *bandnum)
Return bands' external band number (only valid when rt_band_is_offline returns non-zero).
static void test_band_pixtype_4BUI()
void rt_band_set_hasnodata_flag(rt_band band, int flag)
Set hasnodata flag value.
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
static void test_band_metadata()
static void test_band_pixtype_8BUI()
static void test_band_pixtype_16BUI()
void rtdealloc(void *mem)
rt_pixtype rt_band_get_pixtype(rt_band band)
Return pixeltype of this band.
int rt_raster_add_band(rt_raster raster, rt_band band, int index)
Add band data to a raster.
int rt_band_get_isnodata_flag(rt_band band)
Get isnodata flag value.
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's value.
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.