3
* bilinear_f.c -- use bilinear interpolation with fallback for given row, col
6
* bilinear interpolation for the given row, column indices.
7
* If the interpolated value (but not the nearest) is null,
8
* it falls back to nearest neighbor.
14
void p_bilinear_f(struct cache *ibuffer, /* input buffer */
15
void *obufptr, /* ptr in output buffer */
16
int cell_type, /* raster map type of obufptr */
17
double *row_idx, /* row index */
18
double *col_idx, /* column index */
19
struct Cell_head *cellhd /* cell header of input layer */
22
/* start nearest neighbor to do some basic tests */
23
int row, col; /* row/col of nearest neighbor */
26
/* cut indices to integer */
27
row = (int)floor(*row_idx);
28
col = (int)floor(*col_idx);
30
/* check for out of bounds - if out of bounds set NULL value */
31
if (row < 0 || row >= cellhd->rows || col < 0 || col >= cellhd->cols) {
32
G_set_null_value(obufptr, 1, cell_type);
36
cellp = CPTR(ibuffer, row, col);
37
/* if nearest is null, all the other interps will be null */
38
if (G_is_d_null_value(cellp)) {
39
G_set_null_value(obufptr, 1, cell_type);
44
p_bilinear(ibuffer, obufptr, cell_type, row_idx, col_idx, cellhd);
45
/* fallback to nearest if bilinear is null */
46
if (G_is_d_null_value(obufptr))
47
G_set_raster_value_d(obufptr, cell, cell_type);