Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Name
3 * cubic_f.c -- use cubic interpolation with fallback for given row, col
4 *
5 * Description
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.
10 */
11
12 #include <math.h>
13 #include "global.h"
14
15 void p_cubic_f(struct cache *ibuffer, /* input buffer */
16 void *obufptr, /* ptr in output buffer */
17 int cell_type, /* raster map type of obufptr */
18 double *row_idx, /* row index */
19 double *col_idx, /* column index */
20 struct Cell_head *cellhd /* cell header of input layer */
21 )
22 {
23 /* start nearest neighbor to do some basic tests */
24 int row, col; /* row/col of nearest neighbor */
25 DCELL *cellp, cell;
26
27 /* cut indices to integer */
28 row = (int)floor(*row_idx);
29 col = (int)floor(*col_idx);
30
31 /* check for out of bounds - if out of bounds set NULL value */
32 if (row < 0 || row >= cellhd->rows || col < 0 || col >= cellhd->cols) {
33 Rast_set_null_value(obufptr, 1, cell_type);
34 return;
35 }
36
37 cellp = CPTR(ibuffer, row, col);
38 /* if nearest is null, all the other interps will be null */
39 if (Rast_is_d_null_value(cellp)) {
40 Rast_set_null_value(obufptr, 1, cell_type);
41 return;
42 }
43 cell = *cellp;
44
45 p_cubic(ibuffer, obufptr, cell_type, row_idx, col_idx, cellhd);
46 /* fallback to bilinear if cubic is null */
47 if (Rast_is_d_null_value(obufptr)) {
48 p_bilinear(ibuffer, obufptr, cell_type, row_idx, col_idx, cellhd);
49 /* fallback to nearest if bilinear is null */
50 if (Rast_is_d_null_value(obufptr))
51 Rast_set_d_value(obufptr, cell, cell_type);
52 }
53 }