3
* bilinear.c -- use bilinear interpolation for given row, col
6
* bilinear interpolation for the given row, column indices.
7
* If the given row or column is outside the bounds of the input map,
8
* the point in the output map is set to NULL.
9
* If any of the 4 surrounding points to be used in the interpolation
10
* is NULL it is filled with is neighbor value
16
void p_bilinear(struct cache *ibuffer, /* input buffer */
17
void *obufptr, /* ptr in output buffer */
18
int cell_type, /* raster map type of obufptr */
19
double *row_idx, /* row index */
20
double *col_idx, /* column index */
21
struct Cell_head *cellhd /* information of output map */
24
int row; /* row indices for interp */
25
int col; /* column indices for interp */
27
double t, u; /* intermediate slope */
28
DCELL result; /* result of interpolation */
31
/* cut indices to integer */
32
row = (int)floor(*row_idx - 0.5);
33
col = (int)floor(*col_idx - 0.5);
35
/* check for out of bounds - if out of bounds set NULL value and return */
36
if (row < 0 || row + 1 >= cellhd->rows || col < 0 || col + 1 >= cellhd->cols) {
37
G_set_null_value(obufptr, 1, cell_type);
41
for (i = 0; i < 2; i++)
42
for (j = 0; j < 2; j++) {
43
const DCELL *cellp = CPTR(ibuffer, row + i, col + j);
44
if (G_is_d_null_value(cellp)) {
45
G_set_null_value(obufptr, 1, cell_type);
51
/* do the interpolation */
52
t = *col_idx - 0.5 - col;
53
u = *row_idx - 0.5 - row;
55
result = G_interp_bilinear(t, u, c[0][0], c[0][1], c[1][0], c[1][1]);
57
G_set_raster_value_d(obufptr, result, cell_type);