PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ test_band_pixtype_32BSI()

static void test_band_pixtype_32BSI ( )
static

Definition at line 953 of file cu_band_basics.c.

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

953  {
954  rt_pixtype pixtype = PT_32BSI;
955  uint8_t *data = NULL;
956  rt_band band = NULL;
957  int width = 5;
958  int height = 5;
959  int err = 0;
960  int clamped = 0;
961  double val = 0;
962  int x;
963  int y;
964 
965  /* inline band */
966  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
967  CU_ASSERT(data != NULL);
968  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
969 
970  band = rt_band_new_inline(
971  width, height,
972  pixtype,
973  0, 0,
974  data
975  );
976  CU_ASSERT(band != NULL);
977  rt_band_set_ownsdata_flag(band, 1);
978  CU_ASSERT(rt_band_get_ownsdata_flag(band));
979 
980  err = rt_band_set_nodata(band, 1, &clamped);
981  CU_ASSERT_EQUAL(err, ES_NONE);
982  CU_ASSERT(!clamped);
983  rt_band_get_nodata(band, &val);
984  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
985 
986  err = rt_band_set_nodata(band, 0, &clamped);
987  CU_ASSERT_EQUAL(err, ES_NONE);
988  CU_ASSERT(!clamped);
989  rt_band_get_nodata(band, &val);
990  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
991 
992  err = rt_band_set_nodata(band, 65535, &clamped);
993  CU_ASSERT_EQUAL(err, ES_NONE);
994  CU_ASSERT(!clamped);
995  rt_band_get_nodata(band, &val);
996  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
997 
998  err = rt_band_set_nodata(band, 2147483647, &clamped);
999  CU_ASSERT_EQUAL(err, ES_NONE);
1000  CU_ASSERT(!clamped);
1001  rt_band_get_nodata(band, &val);
1002  /*printf("32BSI pix is %ld\n", (long int)val);*/
1003  CU_ASSERT_DOUBLE_EQUAL(val, 2147483647, DBL_EPSILON);
1004 
1005  /* out of range */
1006  err = rt_band_set_nodata(band, 2147483648UL, &clamped);
1007  CU_ASSERT_EQUAL(err, ES_NONE);
1008  CU_ASSERT(clamped);
1009 
1010  /* out of value range */
1011  err = rt_band_set_pixel(band, 0, 0, 2147483648UL, &clamped);
1012  CU_ASSERT_EQUAL(err, ES_NONE);
1013  CU_ASSERT(clamped);
1014 
1015  /* out of dimensions range */
1016  err = rt_band_set_pixel(band, rt_band_get_width(band), 0, 0, NULL);
1017  CU_ASSERT((err != ES_NONE));
1018 
1019  for (x=0; x<rt_band_get_width(band); ++x) {
1020  for (y=0; y<rt_band_get_height(band); ++y) {
1021  err = rt_band_set_pixel(band, x, y, 1, NULL);
1022  CU_ASSERT_EQUAL(err, ES_NONE);
1023  err = rt_band_get_pixel(band, x, y, &val, NULL);
1024  CU_ASSERT_EQUAL(err, ES_NONE);
1025  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
1026 
1027  err = rt_band_set_pixel(band, x, y, 0, NULL);
1028  CU_ASSERT_EQUAL(err, ES_NONE);
1029  err = rt_band_get_pixel(band, x, y, &val, NULL);
1030  CU_ASSERT_EQUAL(err, ES_NONE);
1031  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
1032 
1033  err = rt_band_set_pixel(band, x, y, 65535, NULL);
1034  CU_ASSERT_EQUAL(err, ES_NONE);
1035  err = rt_band_get_pixel(band, x, y, &val, NULL);
1036  CU_ASSERT_EQUAL(err, ES_NONE);
1037  CU_ASSERT_DOUBLE_EQUAL(val, 65535, DBL_EPSILON);
1038 
1039  err = rt_band_set_pixel(band, x, y, 2147483647, NULL);
1040  CU_ASSERT_EQUAL(err, ES_NONE);
1041  err = rt_band_get_pixel(band, x, y, &val, NULL);
1042  CU_ASSERT_EQUAL(err, ES_NONE);
1043  CU_ASSERT_DOUBLE_EQUAL(val, 2147483647, DBL_EPSILON);
1044  }
1045  }
1046 
1047  rt_band_destroy(band);
1048 }
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: