PostGIS  2.5.0dev-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 1089 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().

1094  {
1095  uint8_t *_vals = NULL;
1096  int pixsize = 0;
1097  uint8_t *data = NULL;
1098  uint32_t offset = 0;
1099  uint16_t _nvals = 0;
1100  int maxlen = 0;
1101  uint8_t *ptr = NULL;
1102 
1103  assert(NULL != band);
1104  assert(vals != NULL && nvals != NULL);
1105 
1106  /* initialize to no values */
1107  *nvals = 0;
1108 
1109  if (
1110  x < 0 || x >= band->width ||
1111  y < 0 || y >= band->height
1112  ) {
1113  rtwarn("Attempting to get pixel values with out of range raster coordinates: (%d, %d)", x, y);
1114  return ES_ERROR;
1115  }
1116 
1117  if (len < 1)
1118  return ES_NONE;
1119 
1120  data = rt_band_get_data(band);
1121  if (data == NULL) {
1122  rterror("rt_band_get_pixel_line: Cannot get band data");
1123  return ES_ERROR;
1124  }
1125 
1126  /* +1 for the nodata value */
1127  offset = x + (y * band->width);
1128  RASTER_DEBUGF(4, "offset = %d", offset);
1129 
1130  pixsize = rt_pixtype_size(band->pixtype);
1131  RASTER_DEBUGF(4, "pixsize = %d", pixsize);
1132 
1133  /* cap _nvals so that it doesn't overflow */
1134  _nvals = len;
1135  maxlen = band->width * band->height;
1136 
1137  if (((int) (offset + _nvals)) > maxlen) {
1138  _nvals = maxlen - offset;
1139  rtwarn("Limiting returning number values to %d", _nvals);
1140  }
1141  RASTER_DEBUGF(4, "_nvals = %d", _nvals);
1142 
1143  ptr = data + (offset * pixsize);
1144 
1145  _vals = rtalloc(_nvals * pixsize);
1146  if (_vals == NULL) {
1147  rterror("rt_band_get_pixel_line: Could not allocate memory for pixel values");
1148  return ES_ERROR;
1149  }
1150 
1151  /* copy pixels */
1152  memcpy(_vals, ptr, _nvals * pixsize);
1153 
1154  *vals = _vals;
1155  *nvals = _nvals;
1156 
1157  return ES_NONE;
1158 }
rt_pixtype pixtype
Definition: librtcore.h:2294
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:2297
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:2296
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:396
Here is the call graph for this function:
Here is the caller graph for this function: