Get values of multiple pixels.
Unlike rt_band_get_pixel, values in vals are of the band's pixel type so cannot be assumed to be double. Function uses memcpy.
It is important to be careful when using this function as the number of values being fetched may exceed a pixel "row". Remember that the band values are stored in a stream (1-D array) regardless of what the raster's width and height might be. So, getting a number of values may cross multiple pixel "rows".
- Parameters
-
| band | : the band to get pixel value from |
| x | : pixel column (0-based) |
| y | : pixel row (0-based) |
| len | : the number of pixels to get |
| **vals | : the pixel values |
| *nvals | : the number of pixel values being returned |
- Returns
- ES_NONE on success, ES_ERROR on error
Definition at line 1288 of file rt_band.c.
1293 {
1294 uint8_t *_vals = NULL;
1295 int pixsize = 0;
1296 uint8_t *
data = NULL;
1297 uint32_t offset = 0;
1298 uint16_t _nvals = 0;
1299 int maxlen = 0;
1300 uint8_t *ptr = NULL;
1301
1302 assert(NULL != band);
1303 assert(vals != NULL && nvals != NULL);
1304
1305
1306 *nvals = 0;
1307
1308 if (
1309 x < 0 || x >=
band->width ||
1310 y < 0 || y >=
band->height
1311 ) {
1312 rtwarn(
"Attempting to get pixel values with out of range raster coordinates: (%d, %d)", x, y);
1314 }
1315
1316 if (len < 1)
1318
1320 if (data == NULL) {
1321 rterror(
"rt_band_get_pixel_line: Cannot get band data");
1323 }
1324
1325
1326 offset =
x + (
y *
band->width);
1328
1331
1332
1333 _nvals = len;
1334 maxlen =
band->width *
band->height;
1335
1336 if (((int) (offset + _nvals)) > maxlen) {
1337 _nvals = maxlen - offset;
1338 rtwarn(
"Limiting returning number values to %d", _nvals);
1339 }
1341
1342 ptr =
data + ((size_t)offset * pixsize);
1343
1344 _vals =
rtalloc((
size_t)_nvals * pixsize);
1345 if (_vals == NULL) {
1346 rterror(
"rt_band_get_pixel_line: Could not allocate memory for pixel values");
1348 }
1349
1350
1351 memcpy(_vals, ptr, (size_t)_nvals * pixsize);
1352
1353 *vals = _vals;
1354 *nvals = _nvals;
1355
1357}
void rterror(const char *fmt,...) __attribute__((format(printf
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
#define RASTER_DEBUGF(level, msg,...)
void void void rtwarn(const char *fmt,...) __attribute__((format(printf
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
References ES_ERROR, ES_NONE, RASTER_DEBUGF, rt_band_get_data(), rt_pixtype_size(), rtalloc(), rterror(), and rtwarn().
Referenced by RASTER_tile(), RASTER_union_transfn(), and test_band_get_pixel_line().