PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ test_band_pixtype_16BSI()

static void test_band_pixtype_16BSI ( )
static

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

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