63 rterror(
"rt_pixtype_size: Unknown pixeltype %d", pixtype);
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)
137 rterror(
"rt_pixtype_name: Unknown pixeltype %d", pixtype);
180 return (
double) -FLT_MAX;
183 return (
double) -DBL_MAX;
186 rterror(
"rt_pixtype_get_min_value: Unknown pixeltype %d", pixtype);
204 double val,
double refval,
207 assert(isequal != NULL);
256 rterror(
"rt_pixtype_compare_clamped_values: Unknown pixeltype %d", pixtype);
291 uint16_t distancex, uint16_t distancey,
298 uint32_t dim[2] = {0};
299 double **values = NULL;
300 int **nodatas = NULL;
305 assert(npixel != NULL &&
count > 0);
306 assert(
value != NULL);
307 assert(nodata != NULL);
310 dim[0] = distancex * 2 + 1;
311 dim[1] = distancey * 2 + 1;
316 if (dim[0] != mask->
dimx || dim[1] != mask->
dimy) {
317 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]);
322 rterror(
"rt_pixel_set_array: Invalid mask");
329 values =
rtalloc(
sizeof(
double *) * dim[1]);
330 nodatas =
rtalloc(
sizeof(
int *) * dim[1]);
332 if (values == NULL || nodatas == NULL) {
333 rterror(
"rt_pixel_set_to_array: Could not allocate memory for 2D array");
338 for (i = 0; i < dim[1]; i++) {
339 values[i] =
rtalloc(
sizeof(
double) * dim[0]);
340 nodatas[i] =
rtalloc(
sizeof(
int) * dim[0]);
342 if (values[i] == NULL || nodatas[i] == NULL) {
343 rterror(
"rt_pixel_set_to_array: Could not allocate memory for dimension of 2D array");
345 if (values[i] == NULL) {
346 for (j = 0; j < i; j++) {
352 for (j = 0; j <= i; j++) {
366 memset(values[i], 0,
sizeof(
double) * dim[0]);
369 for (j = 0; j < dim[0]; j++)
374 zero[0] =
x - distancex;
375 zero[1] =
y - distancey;
378 for (i = 0; i <
count; i++) {
379 if (npixel[i].nodata)
382 _x = npixel[i].
x - zero[0];
383 _y = npixel[i].
y - zero[1];
390 values[_y][_x] = npixel[i].
value;
405 values[_y][_x] = npixel[i].
value;
412 if(mask->
nodata[_y][_x] == 1) {
418 values[_y][_x] = npixel[i].
value * mask->
values[_y][_x];
424 RASTER_DEBUGF(4,
"(x, y, nodata, value) = (%d, %d, %d, %f)", _x, _y, nodatas[_y][_x], values[_y][_x]);
428 *nodata = &(*nodatas);
void rterror(const char *fmt,...)
Wrappers used for reporting errors and info.
void * rtalloc(size_t size)
Wrappers used for managing memory.
#define RASTER_DEBUGF(level, msg,...)
int8_t rt_util_clamp_to_8BSI(double value)
uint8_t rt_util_clamp_to_1BB(double value)
int32_t rt_util_clamp_to_32BSI(double value)
uint8_t rt_util_clamp_to_2BUI(double value)
uint8_t rt_util_clamp_to_8BUI(double value)
rt_errorstate
Enum definitions.
int16_t rt_util_clamp_to_16BSI(double value)
uint8_t rt_util_clamp_to_4BUI(double value)
void rtdealloc(void *mem)
uint16_t rt_util_clamp_to_16BUI(double value)
uint32_t rt_util_clamp_to_32BUI(double value)
float rt_util_clamp_to_32F(double value)
This library is the generic raster handling section of PostGIS.
rt_pixtype rt_pixtype_index_from_name(const char *pixname)
double rt_pixtype_get_min_value(rt_pixtype pixtype)
Return minimum value possible for pixel type.
int rt_pixtype_alignment(rt_pixtype pixtype)
Return alignment requirements for data in the given pixel type.
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.
rt_errorstate rt_pixel_set_to_array(rt_pixel npixel, uint32_t count, rt_mask mask, int x, int y, uint16_t distancex, uint16_t distancey, double ***value, int ***nodata, int *dimx, int *dimy)
const char * rt_pixtype_name(rt_pixtype pixtype)
int rt_pixtype_size(rt_pixtype pixtype)
Return size in bytes of a value in the given pixtype.