PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_band_pixtype_32BUI()

static void test_band_pixtype_32BUI ( )
static

Definition at line 856 of file cu_band_basics.c.

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

856  {
857  rt_pixtype pixtype = PT_32BUI;
858  uint8_t *data = NULL;
859  rt_band band = NULL;
860  int width = 5;
861  int height = 5;
862  int err = 0;
863  int clamped = 0;
864  double val = 0;
865  int x;
866  int y;
867 
868  /* inline band */
869  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
870  CU_ASSERT(data != NULL);
871  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
872 
873  band = rt_band_new_inline(
874  width, height,
875  pixtype,
876  0, 0,
877  data
878  );
879  CU_ASSERT(band != NULL);
880  rt_band_set_ownsdata_flag(band, 1);
881  CU_ASSERT(rt_band_get_ownsdata_flag(band));
882 
883  err = rt_band_set_nodata(band, 1, &clamped);
884  CU_ASSERT_EQUAL(err, ES_NONE);
885  CU_ASSERT(!clamped);
886  rt_band_get_nodata(band, &val);
887  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
888 
889  err = rt_band_set_nodata(band, 0, &clamped);
890  CU_ASSERT_EQUAL(err, ES_NONE);
891  CU_ASSERT(!clamped);
892  rt_band_get_nodata(band, &val);
893  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
894 
895  err = rt_band_set_nodata(band, 65535, &clamped);
896  CU_ASSERT_EQUAL(err, ES_NONE);
897  CU_ASSERT(!clamped);
898  rt_band_get_nodata(band, &val);
899  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
900 
901  err = rt_band_set_nodata(band, 4294967295UL, &clamped);
902  CU_ASSERT_EQUAL(err, ES_NONE);
903  CU_ASSERT(!clamped);
904  rt_band_get_nodata(band, &val);
905  CU_ASSERT_DOUBLE_EQUAL(val, 4294967295UL, DBL_EPSILON);
906 
907  /* out of range */
908  err = rt_band_set_nodata(band, 4294967296ULL, &clamped);
909  CU_ASSERT_EQUAL(err, ES_NONE);
910  CU_ASSERT(clamped);
911 
912  /* out of value range */
913  err = rt_band_set_pixel(band, 0, 0, 4294967296ULL, &clamped);
914  CU_ASSERT_EQUAL(err, ES_NONE);
915  CU_ASSERT(clamped);
916 
917  /* out of dimensions range */
918  err = rt_band_set_pixel(band, rt_band_get_width(band), 0, 4294967296ULL, NULL);
919  CU_ASSERT((err != ES_NONE));
920 
921  for (x=0; x<rt_band_get_width(band); ++x) {
922  for (y=0; y<rt_band_get_height(band); ++y) {
923  err = rt_band_set_pixel(band, x, y, 1, NULL);
924  CU_ASSERT_EQUAL(err, ES_NONE);
925  err = rt_band_get_pixel(band, x, y, &val, NULL);
926  CU_ASSERT_EQUAL(err, ES_NONE);
927  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
928 
929  err = rt_band_set_pixel(band, x, y, 0, NULL);
930  CU_ASSERT_EQUAL(err, ES_NONE);
931  err = rt_band_get_pixel(band, x, y, &val, NULL);
932  CU_ASSERT_EQUAL(err, ES_NONE);
933  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
934 
935  err = rt_band_set_pixel(band, x, y, 65535, NULL);
936  CU_ASSERT_EQUAL(err, ES_NONE);
937  err = rt_band_get_pixel(band, x, y, &val, NULL);
938  CU_ASSERT_EQUAL(err, ES_NONE);
939  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
940 
941  err = rt_band_set_pixel(band, x, y, 4294967295UL, NULL);
942  CU_ASSERT_EQUAL(err, ES_NONE);
943  err = rt_band_get_pixel(band, x, y, &val, NULL);
944  CU_ASSERT_EQUAL(err, ES_NONE);
945  CU_ASSERT_DOUBLE_EQUAL(val, 4294967295UL, DBL_EPSILON);
946  }
947  }
948 
949  rt_band_destroy(band);
950 }
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: