PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ test_band_pixtype_16BUI()

static void test_band_pixtype_16BUI ( )
static

Definition at line 656 of file cu_band_basics.c.

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

656  {
657  rt_pixtype pixtype = PT_16BUI;
658  uint8_t *data = NULL;
659  rt_band band = NULL;
660  int width = 5;
661  int height = 5;
662  int err = 0;
663  int clamped = 0;
664  double val = 0;
665  int x;
666  int y;
667 
668  /* inline band */
669  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
670  CU_ASSERT(data != NULL);
671  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
672 
673  band = rt_band_new_inline(
674  width, height,
675  pixtype,
676  0, 0,
677  data
678  );
679  CU_ASSERT(band != NULL);
680  rt_band_set_ownsdata_flag(band, 1);
681  CU_ASSERT(rt_band_get_ownsdata_flag(band));
682 
683  err = rt_band_set_nodata(band, 1, &clamped);
684  CU_ASSERT_EQUAL(err, ES_NONE);
685  CU_ASSERT(!clamped);
686  rt_band_get_nodata(band, &val);
687  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
688 
689  err = rt_band_set_nodata(band, 0, &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, 0, DBL_EPSILON);
694 
695  err = rt_band_set_nodata(band, 31, &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, 31, DBL_EPSILON);
700 
701  err = rt_band_set_nodata(band, 255, &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, 255, DBL_EPSILON);
706 
707  err = rt_band_set_nodata(band, 65535, &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, 65535, DBL_EPSILON);
712 
713  err = rt_band_set_nodata(band, 65536, &clamped); /* out of range */
714  CU_ASSERT_EQUAL(err, ES_NONE);
715  CU_ASSERT(clamped);
716 
717  /* out of value range */
718  err = rt_band_set_pixel(band, 0, 0, 65536, &clamped);
719  CU_ASSERT_EQUAL(err, ES_NONE);
720  CU_ASSERT(clamped);
721 
722  /* out of dimensions range */
723  err = rt_band_set_pixel(band, rt_band_get_width(band), 0, 0, &clamped);
724  CU_ASSERT((err != ES_NONE));
725 
726  for (x=0; x<rt_band_get_width(band); ++x) {
727  for (y=0; y<rt_band_get_height(band); ++y) {
728  err = rt_band_set_pixel(band, x, y, 255, NULL);
729  CU_ASSERT_EQUAL(err, ES_NONE);
730  err = rt_band_get_pixel(band, x, y, &val, NULL);
731  CU_ASSERT_EQUAL(err, ES_NONE);
732  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
733 
734  err = rt_band_set_pixel(band, x, y, 65535, 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, 65535, DBL_EPSILON);
739  }
740  }
741 
742  rt_band_destroy(band);
743 }
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:685
rt_pixtype
Definition: librtcore.h:185
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:336
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1682
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_band.c:619
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:611
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1173
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition: rt_band.c:592
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition: rt_band.c:601
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:59
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:926
unsigned char uint8_t
Definition: uthash.h:79
Here is the call graph for this function:
Here is the caller graph for this function: