Debian Codegraph @

imagery/i.ortho.photo/i.ortho.rectify/bilinear_f.c

raw symbols SCIP
1 /*
2 * Name
3 * bilinear_f.c -- use bilinear interpolation with fallback for given row, col
4 *
5 * Description
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.
9 */
10
11 #include <math.h>
12 #include "global.h"
13
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 */
20 )
21 {
22 /* start nearest neighbor to do some basic tests */
23 int row, col; /* row/col of nearest neighbor */
24 DCELL *cellp, cell;
25
26 /* cut indices to integer */
27 row = (int)floor(*row_idx);
28 col = (int)floor(*col_idx);
29
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 Rast_set_null_value(obufptr, 1, cell_type);
33 return;
34 }
35
36 cellp = CPTR(ibuffer, row, col);
37 /* if nearest is null, all the other interps will be null */
38 if (Rast_is_d_null_value(cellp)) {
39 Rast_set_null_value(obufptr, 1, cell_type);
40 return;
41 }
42 cell = *cellp;
43
44 p_bilinear(ibuffer, obufptr, cell_type, row_idx, col_idx, cellhd);
45 /* fallback to nearest if bilinear is null */
46 if (Rast_is_d_null_value(obufptr))
47 Rast_set_d_value(obufptr, cell, cell_type);
48 }