PostGIS  2.5.0dev-r@@SVN_REVISION@@

◆ test_band_pixtype_16BSI()

static void test_band_pixtype_16BSI ( )
static

Definition at line 745 of file cu_band_basics.c.

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

745  {
746  rt_pixtype pixtype = PT_16BSI;
747  uint8_t *data = NULL;
748  rt_band band = NULL;
749  int width = 5;
750  int height = 5;
751  int err = 0;
752  int clamped = 0;
753  double val = 0;
754  int x;
755  int y;
756 
757  /* inline band */
758  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
759  CU_ASSERT(data != NULL);
760  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
761 
762  band = rt_band_new_inline(
763  width, height,
764  pixtype,
765  0, 0,
766  data
767  );
768  CU_ASSERT(band != NULL);
769  rt_band_set_ownsdata_flag(band, 1);
770  CU_ASSERT(rt_band_get_ownsdata_flag(band));
771 
772  err = rt_band_set_nodata(band, 1, &clamped);
773  CU_ASSERT_EQUAL(err, ES_NONE);
774  CU_ASSERT(!clamped);
775  rt_band_get_nodata(band, &val);
776  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
777 
778  err = rt_band_set_nodata(band, 0, &clamped);
779  CU_ASSERT_EQUAL(err, ES_NONE);
780  CU_ASSERT(!clamped);
781  rt_band_get_nodata(band, &val);
782  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
783 
784  err = rt_band_set_nodata(band, 31, &clamped);
785  CU_ASSERT_EQUAL(err, ES_NONE);
786  CU_ASSERT(!clamped);
787  rt_band_get_nodata(band, &val);
788  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
789 
790  err = rt_band_set_nodata(band, 255, &clamped);
791  CU_ASSERT_EQUAL(err, ES_NONE);
792  CU_ASSERT(!clamped);
793  rt_band_get_nodata(band, &val);
794  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
795 
796  err = rt_band_set_nodata(band, -32767, &clamped);
797  CU_ASSERT_EQUAL(err, ES_NONE);
798  CU_ASSERT(!clamped);
799  rt_band_get_nodata(band, &val);
800  CU_ASSERT_DOUBLE_EQUAL(val, -32767, DBL_EPSILON);
801 
802  err = rt_band_set_nodata(band, 32767, &clamped);
803  CU_ASSERT_EQUAL(err, ES_NONE);
804  CU_ASSERT(!clamped);
805  rt_band_get_nodata(band, &val);
806  CU_ASSERT_DOUBLE_EQUAL(val, 32767, DBL_EPSILON);
807 
808  /* out of range (-32767..32767) */
809  err = rt_band_set_nodata(band, -32769, &clamped);
810  CU_ASSERT_EQUAL(err, ES_NONE);
811  CU_ASSERT(clamped);
812 
813  /* out of range (-32767..32767) */
814  err = rt_band_set_nodata(band, 32769, &clamped);
815  CU_ASSERT_EQUAL(err, ES_NONE);
816  CU_ASSERT(clamped);
817 
818  /* out of range (-32767..32767) */
819  err = rt_band_set_pixel(band, 0, 0, -32769, &clamped);
820  CU_ASSERT_EQUAL(err, ES_NONE);
821  CU_ASSERT(clamped);
822 
823  /* out of range (-32767..32767) */
824  err = rt_band_set_pixel(band, 0, 0, 32769, &clamped);
825  CU_ASSERT_EQUAL(err, ES_NONE);
826  CU_ASSERT(clamped);
827 
828  /* out of dimensions range */
829  err = rt_band_set_pixel(band, rt_band_get_width(band), 0, 0, NULL);
830  CU_ASSERT((err != ES_NONE));
831 
832  for (x=0; x<rt_band_get_width(band); ++x) {
833  for (y=0; y<rt_band_get_height(band); ++y) {
834  err = rt_band_set_pixel(band, x, y, 255, NULL);
835  CU_ASSERT_EQUAL(err, ES_NONE);
836  err = rt_band_get_pixel(band, x, y, &val, NULL);
837  CU_ASSERT_EQUAL(err, ES_NONE);
838  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
839 
840  err = rt_band_set_pixel(band, x, y, -32767, NULL);
841  CU_ASSERT_EQUAL(err, ES_NONE);
842  err = rt_band_get_pixel(band, x, y, &val, NULL);
843  CU_ASSERT_EQUAL(err, ES_NONE);
844  CU_ASSERT_DOUBLE_EQUAL(val, -32767, DBL_EPSILON);
845 
846  err = rt_band_set_pixel(band, x, y, 32767, NULL);
847  CU_ASSERT_EQUAL(err, ES_NONE);
848  err = rt_band_get_pixel(band, x, y, &val, NULL);
849  CU_ASSERT_EQUAL(err, ES_NONE);
850  CU_ASSERT_DOUBLE_EQUAL(val, 32767, DBL_EPSILON);
851  }
852  }
853 
854  rt_band_destroy(band);
855 }
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: