63 rterror(
"rt_pixtype_size: Unknown pixeltype %d", pixtype);
81 assert(pixname && strlen(pixname) > 0);
83 if (strcmp(pixname,
"1BB") == 0)
85 else if (strcmp(pixname,
"2BUI") == 0)
87 else if (strcmp(pixname,
"4BUI") == 0)
89 else if (strcmp(pixname,
"8BSI") == 0)
91 else if (strcmp(pixname,
"8BUI") == 0)
93 else if (strcmp(pixname,
"16BSI") == 0)
95 else if (strcmp(pixname,
"16BUI") == 0)
97 else if (strcmp(pixname,
"32BSI") == 0)
99 else if (strcmp(pixname,
"32BUI") == 0)
101 else if (strcmp(pixname,
"32BF") == 0)
103 else if (strcmp(pixname,
"64BF") == 0)
135 rterror(
"rt_pixtype_name: Unknown pixeltype %d", pixtype);
178 return (
double) -FLT_MAX;
181 return (
double) -DBL_MAX;
184 rterror(
"rt_pixtype_get_min_value: Unknown pixeltype %d", pixtype);
202 double val,
double refval,
205 assert(isequal != NULL);
254 rterror(
"rt_pixtype_compare_clamped_values: Unknown pixeltype %d", pixtype);
289 uint16_t distancex, uint16_t distancey,
297 double **values = NULL;
298 int **nodatas = NULL;
303 assert(npixel != NULL && count > 0);
304 assert(value != NULL);
305 assert(nodata != NULL);
308 dim[0] = distancex * 2 + 1;
309 dim[1] = distancey * 2 + 1;
314 if (dim[0] != mask->
dimx || dim[1] != mask->
dimy) {
315 rterror(
"rt_pixel_set_array: mask dimensions %d x %d do not match given dims %d x %d", mask->
dimx, mask->
dimy, dim[0], dim[1]);
320 rterror(
"rt_pixel_set_array: Invalid mask");
327 values =
rtalloc(
sizeof(
double *) * dim[1]);
328 nodatas =
rtalloc(
sizeof(
int *) * dim[1]);
330 if (values == NULL || nodatas == NULL) {
331 rterror(
"rt_pixel_set_to_array: Could not allocate memory for 2D array");
336 for (i = 0; i < dim[1]; i++) {
337 values[i] =
rtalloc(
sizeof(
double) * dim[0]);
338 nodatas[i] =
rtalloc(
sizeof(
int) * dim[0]);
340 if (values[i] == NULL || nodatas[i] == NULL) {
341 rterror(
"rt_pixel_set_to_array: Could not allocate memory for dimension of 2D array");
343 if (values[i] == NULL) {
344 for (j = 0; j < i; j++) {
350 for (j = 0; j <= i; j++) {
364 memset(values[i], 0,
sizeof(
double) * dim[0]);
367 for (j = 0; j < dim[0]; j++)
372 zero[0] = x - distancex;
373 zero[1] = y - distancey;
376 for (i = 0; i <
count; i++) {
377 if (npixel[i].nodata)
380 _x = npixel[i].
x - zero[0];
381 _y = npixel[i].
y - zero[1];
383 RASTER_DEBUGF(4,
"absolute x,y: %d x %d", npixel[i].x, npixel[i].y);
388 values[_y][_x] = npixel[i].
value;
402 values[_y][_x] = npixel[i].
value;
409 if(mask->
nodata[_y][_x] == 1) {
415 values[_y][_x] = npixel[i].
value * mask->
values[_y][_x];
421 RASTER_DEBUGF(4,
"(x, y, nodata, value) = (%d, %d, %d, %f)", _x, _y, nodatas[_y][_x], values[_y][_x]);
425 *nodata = &(*nodatas);
int32_t rt_util_clamp_to_32BSI(double value)
rt_errorstate rt_pixel_set_to_array(rt_pixel npixel, int count, rt_mask mask, int x, int y, uint16_t distancex, uint16_t distancey, double ***value, int ***nodata, int *dimx, int *dimy)
uint32_t rt_util_clamp_to_32BUI(double value)
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
rt_errorstate
Enum definitions.
uint16_t rt_util_clamp_to_16BUI(double value)
const char * rt_pixtype_name(rt_pixtype pixtype)
int8_t rt_util_clamp_to_8BSI(double value)
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
#define RASTER_DEBUGF(level, msg,...)
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
uint8_t rt_util_clamp_to_4BUI(double value)
uint8_t rt_util_clamp_to_8BUI(double value)
uint8_t rt_util_clamp_to_1BB(double value)
void rtdealloc(void *mem)
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.
This library is the generic raster handling section of PostGIS.
uint8_t rt_util_clamp_to_2BUI(double value)
float rt_util_clamp_to_32F(double value)
rt_errorstate rt_pixtype_compare_clamped_values(rt_pixtype pixtype, double val, double refval, int *isequal)
Returns 1 if clamped values are equal, 0 if not equal, -1 if error.
int rt_pixtype_alignment(rt_pixtype pixtype)
Return alignment requirements for data in the given pixel type.
int16_t rt_util_clamp_to_16BSI(double value)