PostGIS  2.5.1dev-r@@SVN_REVISION@@

◆ test_band_pixtype_8BUI()

static void test_band_pixtype_8BUI ( )
static

Definition at line 422 of file cu_band_basics.c.

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

422  {
423  rt_pixtype pixtype = PT_8BUI;
424  uint8_t *data = NULL;
425  rt_band band = NULL;
426  int width = 5;
427  int height = 5;
428  int err = 0;
429  int clamped = 0;
430  double val = 0;
431  int x;
432  int y;
433 
434  /* inline band */
435  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
436  CU_ASSERT(data != NULL);
437  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
438 
439  band = rt_band_new_inline(
440  width, height,
441  pixtype,
442  0, 0,
443  data
444  );
445  CU_ASSERT(band != NULL);
446  rt_band_set_ownsdata_flag(band, 1);
447  CU_ASSERT(rt_band_get_ownsdata_flag(band));
448 
449  err = rt_band_set_nodata(band, 1, &clamped);
450  CU_ASSERT_EQUAL(err, ES_NONE);
451  CU_ASSERT(!clamped);
452  rt_band_get_nodata(band, &val);
453  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
454 
455  err = rt_band_set_nodata(band, 0, &clamped);
456  CU_ASSERT_EQUAL(err, ES_NONE);
457  CU_ASSERT(!clamped);
458  rt_band_get_nodata(band, &val);
459  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
460 
461  err = rt_band_set_nodata(band, 2, &clamped);
462  CU_ASSERT_EQUAL(err, ES_NONE);
463  CU_ASSERT(!clamped);
464  rt_band_get_nodata(band, &val);
465  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
466 
467  err = rt_band_set_nodata(band, 4, &clamped);
468  CU_ASSERT_EQUAL(err, ES_NONE);
469  CU_ASSERT(!clamped);
470  rt_band_get_nodata(band, &val);
471  CU_ASSERT_DOUBLE_EQUAL(val, 4, DBL_EPSILON);
472 
473  err = rt_band_set_nodata(band, 8, &clamped);
474  CU_ASSERT_EQUAL(err, ES_NONE);
475  CU_ASSERT(!clamped);
476  rt_band_get_nodata(band, &val);
477  CU_ASSERT_DOUBLE_EQUAL(val, 8, DBL_EPSILON);
478 
479  err = rt_band_set_nodata(band, 15, &clamped);
480  CU_ASSERT_EQUAL(err, ES_NONE);
481  CU_ASSERT(!clamped);
482  rt_band_get_nodata(band, &val);
483  CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
484 
485  err = rt_band_set_nodata(band, 31, &clamped);
486  CU_ASSERT_EQUAL(err, ES_NONE);
487  CU_ASSERT(!clamped);
488  rt_band_get_nodata(band, &val);
489  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
490 
491  err = rt_band_set_nodata(band, 255, &clamped);
492  CU_ASSERT_EQUAL(err, ES_NONE);
493  CU_ASSERT(!clamped);
494  rt_band_get_nodata(band, &val);
495  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
496 
497  err = rt_band_set_nodata(band, 256, &clamped); /* out of value range */
498  CU_ASSERT_EQUAL(err, ES_NONE);
499  CU_ASSERT(clamped);
500 
501  err = rt_band_set_pixel(band, 0, 0, 256, &clamped); /* out of value range */
502  CU_ASSERT_EQUAL(err, ES_NONE);
503  CU_ASSERT(clamped);
504 
505  for (x=0; x<rt_band_get_width(band); ++x) {
506  for (y=0; y<rt_band_get_height(band); ++y) {
507  err = rt_band_set_pixel(band, x, y, 31, NULL);
508  CU_ASSERT_EQUAL(err, ES_NONE);
509  err = rt_band_get_pixel(band, x, y, &val, NULL);
510  CU_ASSERT_EQUAL(err, ES_NONE);
511  CU_ASSERT_DOUBLE_EQUAL(val, 31, DBL_EPSILON);
512 
513  err = rt_band_set_pixel(band, x, y, 255, NULL);
514  CU_ASSERT_EQUAL(err, ES_NONE);
515  err = rt_band_get_pixel(band, x, y, &val, NULL);
516  CU_ASSERT_EQUAL(err, ES_NONE);
517  CU_ASSERT_DOUBLE_EQUAL(val, 255, DBL_EPSILON);
518 
519  err = rt_band_set_pixel(band, x, y, 1, NULL);
520  CU_ASSERT_EQUAL(err, ES_NONE);
521  err = rt_band_get_pixel(band, x, y, &val, NULL);
522  CU_ASSERT_EQUAL(err, ES_NONE);
523  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
524  }
525  }
526 
527  rt_band_destroy(band);
528 }
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:733
rt_pixtype
Definition: librtcore.h:185
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
void rt_band_set_ownsdata_flag(rt_band band, int flag)
Definition: rt_band.c:667
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
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
uint16_t rt_band_get_width(rt_band band)
Return width of this band.
Definition: rt_band.c:640
uint16_t rt_band_get_height(rt_band band)
Return height of this band.
Definition: rt_band.c:649
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
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:974
unsigned char uint8_t
Definition: uthash.h:79
Here is the call graph for this function:
Here is the caller graph for this function: