PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_band_pixtype_8BSI()

static void test_band_pixtype_8BSI ( )
static

Definition at line 523 of file cu_band_basics.c.

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

523  {
524  rt_pixtype pixtype = PT_8BSI;
525  uint8_t *data = NULL;
526  rt_band band = NULL;
527  int width = 5;
528  int height = 5;
529  int err = 0;
530  int clamped = 0;
531  double val = 0;
532  int x;
533  int y;
534 
535  /* inline band */
536  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
537  CU_ASSERT(data != NULL);
538  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
539 
540  band = rt_band_new_inline(
541  width, height,
542  pixtype,
543  0, 0,
544  data
545  );
546  CU_ASSERT(band != NULL);
547  rt_band_set_ownsdata_flag(band, 1);
548  CU_ASSERT(rt_band_get_ownsdata_flag(band));
549 
550  err = rt_band_set_nodata(band, 1, &clamped);
551  CU_ASSERT_EQUAL(err, ES_NONE);
552  CU_ASSERT(!clamped);
553  rt_band_get_nodata(band, &val);
554  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
555 
556  err = rt_band_set_nodata(band, 0, &clamped);
557  CU_ASSERT_EQUAL(err, ES_NONE);
558  CU_ASSERT(!clamped);
559  rt_band_get_nodata(band, &val);
560  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
561 
562  err = rt_band_set_nodata(band, 2, &clamped);
563  CU_ASSERT_EQUAL(err, ES_NONE);
564  CU_ASSERT(!clamped);
565  rt_band_get_nodata(band, &val);
566  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
567 
568  err = rt_band_set_nodata(band, 4, &clamped);
569  CU_ASSERT_EQUAL(err, ES_NONE);
570  CU_ASSERT(!clamped);
571  rt_band_get_nodata(band, &val);
572  CU_ASSERT_DOUBLE_EQUAL(val, 4, DBL_EPSILON);
573 
574  err = rt_band_set_nodata(band, 8, &clamped);
575  CU_ASSERT_EQUAL(err, ES_NONE);
576  CU_ASSERT(!clamped);
577  rt_band_get_nodata(band, &val);
578  CU_ASSERT_DOUBLE_EQUAL(val, 8, DBL_EPSILON);
579 
580  err = rt_band_set_nodata(band, 15, &clamped);
581  CU_ASSERT_EQUAL(err, ES_NONE);
582  CU_ASSERT(!clamped);
583  rt_band_get_nodata(band, &val);
584  CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
585 
586  err = rt_band_set_nodata(band, 31, &clamped);
587  CU_ASSERT_EQUAL(err, ES_NONE);
588  CU_ASSERT(!clamped);
589  rt_band_get_nodata(band, &val);
590  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
591 
592  err = rt_band_set_nodata(band, -127, &clamped);
593  CU_ASSERT_EQUAL(err, ES_NONE);
594  CU_ASSERT(!clamped);
595  rt_band_get_nodata(band, &val);
596  CU_ASSERT_DOUBLE_EQUAL(val, -127, DBL_EPSILON);
597 
598  err = rt_band_set_nodata(band, 127, &clamped);
599  CU_ASSERT_EQUAL(err, ES_NONE);
600  CU_ASSERT(!clamped);
601  rt_band_get_nodata(band, &val);
602  CU_ASSERT_DOUBLE_EQUAL(val, 127, DBL_EPSILON);
603 
604  /* out of range (-127..127) */
605  err = rt_band_set_nodata(band, -129, &clamped);
606  CU_ASSERT_EQUAL(err, ES_NONE);
607  CU_ASSERT(clamped);
608 
609  /* out of range (-127..127) */
610  err = rt_band_set_nodata(band, 129, &clamped);
611  CU_ASSERT_EQUAL(err, ES_NONE);
612  CU_ASSERT(clamped);
613 
614  /* out of range (-127..127) */
615  err = rt_band_set_pixel(band, 0, 0, -129, &clamped);
616  CU_ASSERT_EQUAL(err, ES_NONE);
617  CU_ASSERT(clamped);
618 
619  /* out of range (-127..127) */
620  err = rt_band_set_pixel(band, 0, 0, 129, &clamped);
621  CU_ASSERT_EQUAL(err, ES_NONE);
622  CU_ASSERT(clamped);
623 
624  for (x=0; x<rt_band_get_width(band); ++x) {
625  for (y=0; y<rt_band_get_height(band); ++y) {
626  err = rt_band_set_pixel(band, x, y, 31, NULL);
627  CU_ASSERT_EQUAL(err, ES_NONE);
628  err = rt_band_get_pixel(band, x, y, &val, NULL);
629  CU_ASSERT_EQUAL(err, ES_NONE);
630  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
631 
632  err = rt_band_set_pixel(band, x, y, 1, NULL);
633  CU_ASSERT_EQUAL(err, ES_NONE);
634  err = rt_band_get_pixel(band, x, y, &val, NULL);
635  CU_ASSERT_EQUAL(err, ES_NONE);
636  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
637 
638  err = rt_band_set_pixel(band, x, y, -127, NULL);
639  CU_ASSERT_EQUAL(err, ES_NONE);
640  err = rt_band_get_pixel(band, x, y, &val, NULL);
641  CU_ASSERT_EQUAL(err, ES_NONE);
642  CU_ASSERT_DOUBLE_EQUAL(val, -127, DBL_EPSILON);
643 
644  err = rt_band_set_pixel(band, x, y, 127, NULL);
645  CU_ASSERT_EQUAL(err, ES_NONE);
646  err = rt_band_get_pixel(band, x, y, &val, NULL);
647  CU_ASSERT_EQUAL(err, ES_NONE);
648  CU_ASSERT_DOUBLE_EQUAL(val, 127, DBL_EPSILON);
649  }
650  }
651 
652  rt_band_destroy(band);
653 }
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: