3
* cubic_f.c -- use cubic interpolation with fallback for given row, col
6
* cubic interpolation for the given row, column indices.
7
* If the interpolated value (but not the nearest) is null,
8
* it falls back to bilinear. If that interp value is null,
9
* it falls back to nearest neighbor.
12
#include <grass/gis.h>
13
#include <grass/raster.h>
16
void p_cubic_f(struct cache *ibuffer, /* input buffer */
17
void *obufptr, /* ptr in output buffer */
18
int cell_type, /* raster map type of obufptr */
19
double col_idx, /* column index */
20
double row_idx, /* row index */
21
struct Cell_head *cellhd /* cell header of input layer */
24
/* start nearest neighbor to do some basic tests */
25
int row, col; /* row/col of nearest neighbor */
28
/* cut indices to integer */
29
row = (int)floor(row_idx);
30
col = (int)floor(col_idx);
32
/* check for out of bounds - if out of bounds set NULL value */
33
if (row < 0 || row >= cellhd->rows || col < 0 || col >= cellhd->cols) {
34
Rast_set_null_value(obufptr, 1, cell_type);
38
cell = CVAL(ibuffer, row, col);
39
/* if nearest is null, all the other interps will be null */
40
if (Rast_is_f_null_value(&cell)) {
41
Rast_set_null_value(obufptr, 1, cell_type);
45
p_cubic(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
46
/* fallback to bilinear if cubic is null */
47
if (Rast_is_f_null_value(obufptr)) {
48
p_bilinear(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
49
/* fallback to nearest if bilinear is null */
50
if (Rast_is_f_null_value(obufptr))
51
Rast_set_f_value(obufptr, cell, cell_type);