PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ test_band_pixtype_2BUI()

static void test_band_pixtype_2BUI ( )
static

Definition at line 224 of file cu_band_basics.c.

224 {
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
242 width, height,
243 pixtype,
244 0, 0,
245 data
246 );
247 CU_ASSERT(band != NULL);
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}
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:64
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition rt_band.c:826
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition rt_context.c:191
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition rt_band.c:799
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition rt_band.c:1551
rt_pixtype
Definition librtcore.h:188
@ PT_2BUI
Definition librtcore.h:190
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition rt_band.c:892
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition rt_band.c:1140
@ ES_NONE
Definition librtcore.h:182
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition rt_band.c:499
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition rt_band.c:2067
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:818
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition rt_band.c:808
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition rt_pixel.c:40

References ES_NONE, PT_2BUI, rt_band_destroy(), rt_band_get_height(), rt_band_get_nodata(), rt_band_get_ownsdata_flag(), rt_band_get_pixel(), rt_band_get_width(), rt_band_new_inline(), rt_band_set_nodata(), rt_band_set_ownsdata_flag(), rt_band_set_pixel(), rt_pixtype_size(), and rtalloc().

Referenced by band_basics_suite_setup().

Here is the call graph for this function:
Here is the caller graph for this function: