PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_band_pixtype_8BUI()

static void test_band_pixtype_8BUI ( )
static

Definition at line 415 of file cu_band_basics.c.

References ovdump::band, ovdump::data, ES_NONE, PT_8BUI, 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().

415  {
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 }
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: