PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_band_pixtype_4BUI()

static void test_band_pixtype_4BUI ( )
static

Definition at line 309 of file cu_band_basics.c.

References ovdump::band, ovdump::data, ES_NONE, PT_4BUI, 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(), rtalloc(), pixval::x, and pixval::y.

Referenced by band_basics_suite_setup().

309  {
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 }
band
Definition: ovdump.py:57
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
data
Definition: ovdump.py:103
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:185
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
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_band.c:534
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
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
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
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
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
unsigned char uint8_t
Definition: uthash.h:79
Here is the call graph for this function:
Here is the caller graph for this function: