PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ test_band_pixtype_2BUI()

static void test_band_pixtype_2BUI ( )
static

Definition at line 217 of file cu_band_basics.c.

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

217  {
218  rt_pixtype pixtype = PT_2BUI;
219  uint8_t *data = NULL;
220  rt_band band = NULL;
221  int width = 5;
222  int height = 5;
223  int err = 0;
224  int clamped = 0;
225  double val = 0;
226  int x;
227  int y;
228 
229  /* inline band */
230  data = rtalloc(rt_pixtype_size(pixtype) * width * height);
231  CU_ASSERT(data != NULL);
232  memset(data, 0, rt_pixtype_size(pixtype) * width * height);
233 
234  band = rt_band_new_inline(
235  width, height,
236  pixtype,
237  0, 0,
238  data
239  );
240  CU_ASSERT(band != NULL);
241  rt_band_set_ownsdata_flag(band, 1);
242  CU_ASSERT(rt_band_get_ownsdata_flag(band));
243 
244  err = rt_band_set_nodata(band, 1, &clamped);
245  CU_ASSERT_EQUAL(err, ES_NONE);
246  CU_ASSERT(!clamped);
247  rt_band_get_nodata(band, &val);
248  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
249 
250  err = rt_band_set_nodata(band, 0, &clamped);
251  CU_ASSERT_EQUAL(err, ES_NONE);
252  CU_ASSERT(!clamped);
253  rt_band_get_nodata(band, &val);
254  CU_ASSERT_DOUBLE_EQUAL(val, 0, DBL_EPSILON);
255 
256  err = rt_band_set_nodata(band, 2, &clamped);
257  CU_ASSERT_EQUAL(err, ES_NONE);
258  CU_ASSERT(!clamped);
259  rt_band_get_nodata(band, &val);
260  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
261 
262  err = rt_band_set_nodata(band, 3, &clamped);
263  CU_ASSERT_EQUAL(err, ES_NONE);
264  CU_ASSERT(!clamped);
265  rt_band_get_nodata(band, &val);
266  CU_ASSERT_DOUBLE_EQUAL(val, 3, DBL_EPSILON);
267 
268  err = rt_band_set_nodata(band, 4, &clamped); /* invalid: out of range */
269  CU_ASSERT_EQUAL(err, ES_NONE);
270  CU_ASSERT(clamped);
271 
272  err = rt_band_set_nodata(band, 5, &clamped); /* invalid: out of range */
273  CU_ASSERT_EQUAL(err, ES_NONE);
274  CU_ASSERT(clamped);
275 
276  err = rt_band_set_pixel(band, 0, 0, 4, &clamped); /* out of range */
277  CU_ASSERT_EQUAL(err, ES_NONE);
278  CU_ASSERT(clamped);
279 
280  err = rt_band_set_pixel(band, 0, 0, 5, &clamped); /* out of range */
281  CU_ASSERT_EQUAL(err, ES_NONE);
282  CU_ASSERT(clamped);
283 
284  for (x=0; x<rt_band_get_width(band); ++x) {
285  for (y=0; y<rt_band_get_height(band); ++y) {
286  err = rt_band_set_pixel(band, x, y, 1, NULL);
287  CU_ASSERT_EQUAL(err, ES_NONE);
288  err = rt_band_get_pixel(band, x, y, &val, NULL);
289  CU_ASSERT_EQUAL(err, ES_NONE);
290  CU_ASSERT_DOUBLE_EQUAL(val, 1, DBL_EPSILON);
291 
292  err = rt_band_set_pixel(band, x, y, 2, NULL);
293  CU_ASSERT_EQUAL(err, ES_NONE);
294  err = rt_band_get_pixel(band, x, y, &val, NULL);
295  CU_ASSERT_EQUAL(err, ES_NONE);
296  CU_ASSERT_DOUBLE_EQUAL(val, 2, DBL_EPSILON);
297 
298  err = rt_band_set_pixel(band, x, y, 3, NULL);
299  CU_ASSERT_EQUAL(err, ES_NONE);
300  err = rt_band_get_pixel(band, x, y, &val, NULL);
301  CU_ASSERT_EQUAL(err, ES_NONE);
302  CU_ASSERT_DOUBLE_EQUAL(val, 3, DBL_EPSILON);
303  }
304  }
305 
306  rt_band_destroy(band);
307 }
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: