PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_band_pixtype_16BUI()

static void test_band_pixtype_16BUI ( )
static

Definition at line 655 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().

655  {
656  rt_pixtype pixtype = PT_16BUI;
657  uint8_t *data = NULL;
658  rt_band band = NULL;
659  int width = 5;
660  int height = 5;
661  int err = 0;
662  int clamped = 0;
663  double val = 0;
664  int x;
665  int y;
666 
667  /* inline band */
668  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
669  CU_ASSERT(data != NULL);
670  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
671 
672  band = rt_band_new_inline(
673  width, height,
674  pixtype,
675  0, 0,
676  data
677  );
678  CU_ASSERT(band != NULL);
679  rt_band_set_ownsdata_flag(band, 1);
680  CU_ASSERT(rt_band_get_ownsdata_flag(band));
681 
682  err = rt_band_set_nodata(band, 1, &clamped);
683  CU_ASSERT_EQUAL(err, ES_NONE);
684  CU_ASSERT(!clamped);
685  rt_band_get_nodata(band, &val);
686  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
687 
688  err = rt_band_set_nodata(band, 0, &clamped);
689  CU_ASSERT_EQUAL(err, ES_NONE);
690  CU_ASSERT(!clamped);
691  rt_band_get_nodata(band, &val);
692  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
693 
694  err = rt_band_set_nodata(band, 31, &clamped);
695  CU_ASSERT_EQUAL(err, ES_NONE);
696  CU_ASSERT(!clamped);
697  rt_band_get_nodata(band, &val);
698  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
699 
700  err = rt_band_set_nodata(band, 255, &clamped);
701  CU_ASSERT_EQUAL(err, ES_NONE);
702  CU_ASSERT(!clamped);
703  rt_band_get_nodata(band, &val);
704  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
705 
706  err = rt_band_set_nodata(band, 65535, &clamped);
707  CU_ASSERT_EQUAL(err, ES_NONE);
708  CU_ASSERT(!clamped);
709  rt_band_get_nodata(band, &val);
710  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
711 
712  err = rt_band_set_nodata(band, 65536, &clamped); /* out of range */
713  CU_ASSERT_EQUAL(err, ES_NONE);
714  CU_ASSERT(clamped);
715 
716  /* out of value range */
717  err = rt_band_set_pixel(band, 0, 0, 65536, &clamped);
718  CU_ASSERT_EQUAL(err, ES_NONE);
719  CU_ASSERT(clamped);
720 
721  /* out of dimensions range */
722  err = rt_band_set_pixel(band, rt_band_get_width(band), 0, 0, &clamped);
723  CU_ASSERT((err != ES_NONE));
724 
725  for (x=0; x<rt_band_get_width(band); ++x) {
726  for (y=0; y<rt_band_get_height(band); ++y) {
727  err = rt_band_set_pixel(band, x, y, 255, NULL);
728  CU_ASSERT_EQUAL(err, ES_NONE);
729  err = rt_band_get_pixel(band, x, y, &val, NULL);
730  CU_ASSERT_EQUAL(err, ES_NONE);
731  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
732 
733  err = rt_band_set_pixel(band, x, y, 65535, NULL);
734  CU_ASSERT_EQUAL(err, ES_NONE);
735  err = rt_band_get_pixel(band, x, y, &val, NULL);
736  CU_ASSERT_EQUAL(err, ES_NONE);
737  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
738  }
739  }
740 
741  rt_band_destroy(band);
742 }
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: