PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_band_pixtype_4BUI()

static void test_band_pixtype_4BUI ( )
static

Definition at line 316 of file cu_band_basics.c.

316  {
317  rt_pixtype pixtype = PT_4BUI;
318  uint8_t *data = NULL;
319  rt_band band = NULL;
320  int width = 5;
321  int height = 5;
322  int err = 0;
323  int clamped = 0;
324  double val = 0;
325  int x;
326  int y;
327 
328  /* inline band */
329  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
330  CU_ASSERT(data != NULL);
331  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
332 
334  width, height,
335  pixtype,
336  0, 0,
337  data
338  );
339  CU_ASSERT(band != NULL);
341  CU_ASSERT(rt_band_get_ownsdata_flag(band));
342 
343  err = rt_band_set_nodata(band, 1, &clamped);
344  CU_ASSERT_EQUAL(err, ES_NONE);
345  CU_ASSERT(!clamped);
346  rt_band_get_nodata(band, &val);
347  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
348 
349  err = rt_band_set_nodata(band, 0, &clamped);
350  CU_ASSERT_EQUAL(err, ES_NONE);
351  CU_ASSERT(!clamped);
352  rt_band_get_nodata(band, &val);
353  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
354 
355  err = rt_band_set_nodata(band, 2, &clamped);
356  CU_ASSERT_EQUAL(err, ES_NONE);
357  CU_ASSERT(!clamped);
358  rt_band_get_nodata(band, &val);
359  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
360 
361  err = rt_band_set_nodata(band, 4, &clamped);
362  CU_ASSERT_EQUAL(err, ES_NONE);
363  CU_ASSERT(!clamped);
364  rt_band_get_nodata(band, &val);
365  CU_ASSERT_DOUBLE_EQUAL(val, 4, DBL_EPSILON);
366 
367  err = rt_band_set_nodata(band, 8, &clamped);
368  CU_ASSERT_EQUAL(err, ES_NONE);
369  CU_ASSERT(!clamped);
370  rt_band_get_nodata(band, &val);
371  CU_ASSERT_DOUBLE_EQUAL(val, 8, DBL_EPSILON);
372 
373  err = rt_band_set_nodata(band, 15, &clamped);
374  CU_ASSERT_EQUAL(err, ES_NONE);
375  CU_ASSERT(!clamped);
376  rt_band_get_nodata(band, &val);
377  CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
378 
379  err = rt_band_set_nodata(band, 16, &clamped); /* out of value range */
380  CU_ASSERT_EQUAL(err, ES_NONE);
381  CU_ASSERT(clamped);
382 
383  err = rt_band_set_nodata(band, 17, &clamped); /* out of value range */
384  CU_ASSERT_EQUAL(err, ES_NONE);
385  CU_ASSERT(clamped);
386 
387  err = rt_band_set_pixel(band, 0, 0, 35, &clamped); /* out of value range */
388  CU_ASSERT_EQUAL(err, ES_NONE);
389  CU_ASSERT(clamped);
390 
391  for (x=0; x<rt_band_get_width(band); ++x) {
392  for (y=0; y<rt_band_get_height(band); ++y) {
393  err = rt_band_set_pixel(band, x, y, 1, NULL);
394  CU_ASSERT_EQUAL(err, ES_NONE);
395  err = rt_band_get_pixel(band, x, y, &val, NULL);
396  CU_ASSERT_EQUAL(err, ES_NONE);
397  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
398 
399  err = rt_band_set_pixel(band, x, y, 3, NULL);
400  CU_ASSERT_EQUAL(err, ES_NONE);
401  err = rt_band_get_pixel(band, x, y, &val, NULL);
402  CU_ASSERT_EQUAL(err, ES_NONE);
403  CU_ASSERT_DOUBLE_EQUAL(val, 3, DBL_EPSILON);
404 
405  err = rt_band_set_pixel(band, x, y, 7, NULL);
406  CU_ASSERT_EQUAL(err, ES_NONE);
407  err = rt_band_get_pixel(band, x, y, &val, NULL);
408  CU_ASSERT_EQUAL(err, ES_NONE);
409  CU_ASSERT_DOUBLE_EQUAL(val, 7, DBL_EPSILON);
410 
411  err = rt_band_set_pixel(band, x, y, 15, NULL);
412  CU_ASSERT_EQUAL(err, ES_NONE);
413  err = rt_band_get_pixel(band, x, y, &val, NULL);
414  CU_ASSERT_EQUAL(err, ES_NONE);
415  CU_ASSERT_DOUBLE_EQUAL(val, 15, DBL_EPSILON);
416  }
417  }
418 
420 }
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_4BUI
Definition: librtcore.h:188
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_4BUI, 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: