| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include <math.h> |
| 14 |
#include "global.h" |
| 15 |
|
| 16 |
void p_bilinear(struct cache *ibuffer, |
| 17 |
void *obufptr, |
| 18 |
int cell_type, |
| 19 |
double *row_idx, |
| 20 |
double *col_idx, |
| 21 |
struct Cell_head *cellhd |
| 22 |
) |
| 23 |
{ |
| 24 |
int row; |
| 25 |
int col; |
| 26 |
int i, j; |
| 27 |
double t, u; |
| 28 |
DCELL result; |
| 29 |
DCELL c[2][2]; |
| 30 |
|
| 31 |
|
| 32 |
row = (int)floor(*row_idx - 0.5); |
| 33 |
col = (int)floor(*col_idx - 0.5); |
| 34 |
|
| 35 |
|
| 36 |
if (row < 0 || row + 1 >= cellhd->rows || col < 0 || |
| 37 |
col + 1 >= cellhd->cols) { |
| 38 |
Rast_set_null_value(obufptr, 1, cell_type); |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
for (i = 0; i < 2; i++) |
| 43 |
for (j = 0; j < 2; j++) { |
| 44 |
const DCELL *cellp = CPTR(ibuffer, row + i, col + j); |
| 45 |
|
| 46 |
if (Rast_is_d_null_value(cellp)) { |
| 47 |
Rast_set_null_value(obufptr, 1, cell_type); |
| 48 |
return; |
| 49 |
} |
| 50 |
c[i][j] = *cellp; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
t = *col_idx - 0.5 - col; |
| 55 |
u = *row_idx - 0.5 - row; |
| 56 |
|
| 57 |
result = Rast_interp_bilinear(t, u, c[0][0], c[0][1], c[1][0], c[1][1]); |
| 58 |
|
| 59 |
Rast_set_d_value(obufptr, result, cell_type); |
| 60 |
} |