PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_band_pixtype_8BSI()

static void test_band_pixtype_8BSI ( )
static

Definition at line 530 of file cu_band_basics.c.

530  {
531  rt_pixtype pixtype = PT_8BSI;
532  uint8_t *data = NULL;
533  rt_band band = NULL;
534  int width = 5;
535  int height = 5;
536  int err = 0;
537  int clamped = 0;
538  double val = 0;
539  int x;
540  int y;
541 
542  /* inline band */
543  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
544  CU_ASSERT(data != NULL);
545  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
546 
548  width, height,
549  pixtype,
550  0, 0,
551  data
552  );
553  CU_ASSERT(band != NULL);
555  CU_ASSERT(rt_band_get_ownsdata_flag(band));
556 
557  err = rt_band_set_nodata(band, 1, &clamped);
558  CU_ASSERT_EQUAL(err, ES_NONE);
559  CU_ASSERT(!clamped);
560  rt_band_get_nodata(band, &val);
561  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
562 
563  err = rt_band_set_nodata(band, 0, &clamped);
564  CU_ASSERT_EQUAL(err, ES_NONE);
565  CU_ASSERT(!clamped);
566  rt_band_get_nodata(band, &val);
567  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
568 
569  err = rt_band_set_nodata(band, 2, &clamped);
570  CU_ASSERT_EQUAL(err, ES_NONE);
571  CU_ASSERT(!clamped);
572  rt_band_get_nodata(band, &val);
573  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
574 
575  err = rt_band_set_nodata(band, 4, &clamped);
576  CU_ASSERT_EQUAL(err, ES_NONE);
577  CU_ASSERT(!clamped);
578  rt_band_get_nodata(band, &val);
579  CU_ASSERT_DOUBLE_EQUAL(val, 4, DBL_EPSILON);
580 
581  err = rt_band_set_nodata(band, 8, &clamped);
582  CU_ASSERT_EQUAL(err, ES_NONE);
583  CU_ASSERT(!clamped);
584  rt_band_get_nodata(band, &val);
585  CU_ASSERT_DOUBLE_EQUAL(val, 8, DBL_EPSILON);
586 
587  err = rt_band_set_nodata(band, 15, &clamped);
588  CU_ASSERT_EQUAL(err, ES_NONE);
589  CU_ASSERT(!clamped);
590  rt_band_get_nodata(band, &val);
591  CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
592 
593  err = rt_band_set_nodata(band, 31, &clamped);
594  CU_ASSERT_EQUAL(err, ES_NONE);
595  CU_ASSERT(!clamped);
596  rt_band_get_nodata(band, &val);
597  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
598 
599  err = rt_band_set_nodata(band, -127, &clamped);
600  CU_ASSERT_EQUAL(err, ES_NONE);
601  CU_ASSERT(!clamped);
602  rt_band_get_nodata(band, &val);
603  CU_ASSERT_DOUBLE_EQUAL(val, -127, DBL_EPSILON);
604 
605  err = rt_band_set_nodata(band, 127, &clamped);
606  CU_ASSERT_EQUAL(err, ES_NONE);
607  CU_ASSERT(!clamped);
608  rt_band_get_nodata(band, &val);
609  CU_ASSERT_DOUBLE_EQUAL(val, 127, DBL_EPSILON);
610 
611  /* out of range (-127..127) */
612  err = rt_band_set_nodata(band, -129, &clamped);
613  CU_ASSERT_EQUAL(err, ES_NONE);
614  CU_ASSERT(clamped);
615 
616  /* out of range (-127..127) */
617  err = rt_band_set_nodata(band, 129, &clamped);
618  CU_ASSERT_EQUAL(err, ES_NONE);
619  CU_ASSERT(clamped);
620 
621  /* out of range (-127..127) */
622  err = rt_band_set_pixel(band, 0, 0, -129, &clamped);
623  CU_ASSERT_EQUAL(err, ES_NONE);
624  CU_ASSERT(clamped);
625 
626  /* out of range (-127..127) */
627  err = rt_band_set_pixel(band, 0, 0, 129, &clamped);
628  CU_ASSERT_EQUAL(err, ES_NONE);
629  CU_ASSERT(clamped);
630 
631  for (x=0; x<rt_band_get_width(band); ++x) {
632  for (y=0; y<rt_band_get_height(band); ++y) {
633  err = rt_band_set_pixel(band, x, y, 31, NULL);
634  CU_ASSERT_EQUAL(err, ES_NONE);
635  err = rt_band_get_pixel(band, x, y, &val, NULL);
636  CU_ASSERT_EQUAL(err, ES_NONE);
637  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
638 
639  err = rt_band_set_pixel(band, x, y, 1, NULL);
640  CU_ASSERT_EQUAL(err, ES_NONE);
641  err = rt_band_get_pixel(band, x, y, &val, NULL);
642  CU_ASSERT_EQUAL(err, ES_NONE);
643  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
644 
645  err = rt_band_set_pixel(band, x, y, -127, NULL);
646  CU_ASSERT_EQUAL(err, ES_NONE);
647  err = rt_band_get_pixel(band, x, y, &val, NULL);
648  CU_ASSERT_EQUAL(err, ES_NONE);
649  CU_ASSERT_DOUBLE_EQUAL(val, -127, DBL_EPSILON);
650 
651  err = rt_band_set_pixel(band, x, y, 127, NULL);
652  CU_ASSERT_EQUAL(err, ES_NONE);
653  err = rt_band_get_pixel(band, x, y, &val, NULL);
654  CU_ASSERT_EQUAL(err, ES_NONE);
655  CU_ASSERT_DOUBLE_EQUAL(val, 127, DBL_EPSILON);
656  }
657  }
658 
660 }
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:63
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_band.c:667
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition: rt_band.c:640
rt_errorstate rt_band_get_pixel(rt_band band, int x, int y, double *value, int *nodata)
Get pixel value.
Definition: rt_band.c:1221
rt_pixtype
Definition: librtcore.h:185
@ PT_8BSI
Definition: librtcore.h:189
rt_errorstate rt_band_set_nodata(rt_band band, double val, int *converted)
Set nodata value.
Definition: rt_band.c:733
rt_errorstate rt_band_set_pixel(rt_band band, int x, int y, double val, int *converted)
Set single pixel's value.
Definition: rt_band.c:974
@ ES_NONE
Definition: librtcore.h:180
void rt_band_destroy(rt_band band)
Destroy a raster band.
Definition: rt_band.c:340
rt_errorstate rt_band_get_nodata(rt_band band, double *nodata)
Get NODATA value.
Definition: rt_band.c:1730
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:659
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition: rt_band.c:649
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
band
Definition: ovdump.py:57
data
Definition: ovdump.py:103
unsigned char uint8_t
Definition: uthash.h:79

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().

Here is the call graph for this function:
Here is the caller graph for this function: