PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ rt_band_get_pixel_line()

rt_errorstate rt_band_get_pixel_line ( rt_band  band,
int  x,
int  y,
uint16_t  len,
void **  vals,
uint16_t *  nvals 
)

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 1004 of file rt_band.c.

References ovdump::data, ES_ERROR, ES_NONE, rt_band_t::height, rt_band_t::pixtype, RASTER_DEBUGF, rt_band_get_data(), rt_pixtype_size(), rtalloc(), rterror(), rtwarn(), and rt_band_t::width.

Referenced by RASTER_tile(), RASTER_union_transfn(), and test_band_get_pixel_line().

1009  {
1010  uint8_t *_vals = NULL;
1011  int pixsize = 0;
1012  uint8_t *data = NULL;
1013  uint32_t offset = 0;
1014  uint16_t _nvals = 0;
1015  int maxlen = 0;
1016  uint8_t *ptr = NULL;
1017 
1018  assert(NULL != band);
1019  assert(vals != NULL && nvals != NULL);
1020 
1021  /* initialize to no values */
1022  *nvals = 0;
1023 
1024  if (
1025  x < 0 || x >= band->width ||
1026  y < 0 || y >= band->height
1027  ) {
1028  rtwarn("Attempting to get pixel values with out of range raster coordinates: (%d, %d)", x, y);
1029  return ES_ERROR;
1030  }
1031 
1032  if (len < 1)
1033  return ES_NONE;
1034 
1035  data = rt_band_get_data(band);
1036  if (data == NULL) {
1037  rterror("rt_band_get_pixel_line: Cannot get band data");
1038  return ES_ERROR;
1039  }
1040 
1041  /* +1 for the nodata value */
1042  offset = x + (y * band->width);
1043  RASTER_DEBUGF(4, "offset = %d", offset);
1044 
1045  pixsize = rt_pixtype_size(band->pixtype);
1046  RASTER_DEBUGF(4, "pixsize = %d", pixsize);
1047 
1048  /* cap _nvals so that it doesn't overflow */
1049  _nvals = len;
1050  maxlen = band->width * band->height;
1051 
1052  if (((int) (offset + _nvals)) > maxlen) {
1053  _nvals = maxlen - offset;
1054  rtwarn("Limiting returning number values to %d", _nvals);
1055  }
1056  RASTER_DEBUGF(4, "_nvals = %d", _nvals);
1057 
1058  ptr = data + (offset * pixsize);
1059 
1060  _vals = rtalloc(_nvals * pixsize);
1061  if (_vals == NULL) {
1062  rterror("rt_band_get_pixel_line: Could not allocate memory for pixel values");
1063  return ES_ERROR;
1064  }
1065 
1066  /* copy pixels */
1067  memcpy(_vals, ptr, _nvals * pixsize);
1068 
1069  *vals = _vals;
1070  *nvals = _nvals;
1071 
1072  return ES_NONE;
1073 }
rt_pixtype pixtype
Definition: librtcore.h:2265
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
Definition: rt_context.c:199
void * rtalloc(size_t size)
Wrappers used for managing memory.
Definition: rt_context.c:171
data
Definition: ovdump.py:103
uint16_t height
Definition: librtcore.h:2268
unsigned int uint32_t
Definition: uthash.h:78
void rtwarn(const char *fmt,...)
Definition: rt_context.c:224
#define RASTER_DEBUGF(level, msg,...)
Definition: librtcore.h:299
uint16_t width
Definition: librtcore.h:2267
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
Definition: rt_pixel.c:39
unsigned char uint8_t
Definition: uthash.h:79
void * rt_band_get_data(rt_band band)
Get pointer to raster band data.
Definition: rt_band.c:302
Here is the call graph for this function:
Here is the caller graph for this function: