[GRASS-SVN] r43973 - grass/trunk/imagery/i.rectify
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Oct 18 11:30:41 EDT 2010
Author: mmetz
Date: 2010-10-18 08:30:41 -0700 (Mon, 18 Oct 2010)
New Revision: 43973
Modified:
grass/trunk/imagery/i.rectify/bilinear.c
grass/trunk/imagery/i.rectify/bilinear_f.c
grass/trunk/imagery/i.rectify/cubic.c
grass/trunk/imagery/i.rectify/cubic_f.c
Log:
apply r43944 to i.rectify: Glynn: Don't store pointer to cache blocks which may be replaced
Modified: grass/trunk/imagery/i.rectify/bilinear.c
===================================================================
--- grass/trunk/imagery/i.rectify/bilinear.c 2010-10-18 15:12:24 UTC (rev 43972)
+++ grass/trunk/imagery/i.rectify/bilinear.c 2010-10-18 15:30:41 UTC (rev 43973)
@@ -23,50 +23,38 @@
struct Cell_head *cellhd /* information of output map */
)
{
- int row0, /* lower row index for interp */
- row1, /* upper row index for interp */
- col0, /* lower column index for interp */
- col1; /* upper column index for interp */
- DCELL t, u, /* intermediate slope */
- tu, /* t * u */
- result; /* result of interpolation */
- DCELL *c00, *c01, *c10, *c11;
+ int row; /* row indices for interp */
+ int col; /* column indices for interp */
+ int i, j;
+ DCELL t, u; /* intermediate slope */
+ DCELL result; /* result of interpolation */
+ DCELL c[2][2];
- /* cut indices to integer and get nearest cells */
- /* example: *row_idx = 2.1
- * nearest rows are 1 and 2, not 2 and 3 */
- *row_idx -= 0.5;
- *col_idx -= 0.5;
- row0 = (int)floor(*row_idx);
- col0 = (int)floor(*col_idx);
- row1 = row0 + 1;
- col1 = col0 + 1;
+ /* cut indices to integer */
+ row = (int)floor(*row_idx - 0.5);
+ col = (int)floor(*col_idx - 0.5);
/* check for out of bounds - if out of bounds set NULL value and return */
- if (row0 < 0 || row1 >= cellhd->rows || col0 < 0 || col1 >= cellhd->cols) {
+ if (row < 0 || row + 1 >= cellhd->rows || col < 0 || col + 1 >= cellhd->cols) {
Rast_set_null_value(obufptr, 1, cell_type);
return;
}
- c00 = CPTR(ibuffer, row0, col0);
- c01 = CPTR(ibuffer, row0, col1);
- c10 = CPTR(ibuffer, row1, col0);
- c11 = CPTR(ibuffer, row1, col1);
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 2; j++) {
+ const DCELL *cellp = CPTR(ibuffer, row + i, col + j);
+ if (Rast_is_f_null_value(cellp)) {
+ Rast_set_null_value(obufptr, 1, cell_type);
+ return;
+ }
+ c[i][j] = *cellp;
+ }
- /* check for NULL values */
- if (Rast_is_f_null_value(c00) ||
- Rast_is_f_null_value(c01) ||
- Rast_is_f_null_value(c10) || Rast_is_f_null_value(c11)) {
- Rast_set_null_value(obufptr, 1, cell_type);
- return;
- }
-
/* do the interpolation */
- t = *col_idx - col0;
- u = *row_idx - row0;
- tu = t * u;
+ t = *col_idx - 0.5 - col;
+ u = *row_idx - 0.5 - row;
- result = Rast_interp_bilinear(t, u, *c00, *c01, *c10, *c11);
+ result = Rast_interp_bilinear(t, u, c[0][0], c[0][1], c[1][0], c[1][1]);
Rast_set_d_value(obufptr, result, cell_type);
}
Modified: grass/trunk/imagery/i.rectify/bilinear_f.c
===================================================================
--- grass/trunk/imagery/i.rectify/bilinear_f.c 2010-10-18 15:12:24 UTC (rev 43972)
+++ grass/trunk/imagery/i.rectify/bilinear_f.c 2010-10-18 15:30:41 UTC (rev 43973)
@@ -23,7 +23,7 @@
{
/* start nearest neighbor to do some basic tests */
int row, col; /* row/col of nearest neighbor */
- DCELL *cellp;
+ DCELL *cellp, cell;
/* cut indices to integer */
row = (int)floor(*row_idx);
@@ -41,9 +41,10 @@
Rast_set_null_value(obufptr, 1, cell_type);
return;
}
-
- p_bilinear(ibuffer, obufptr, cell_type, row_idx, col_idx, cellhd);
+ cell = *cellp;
+
+ p_bilinear(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
/* fallback to nearest if bilinear is null */
if (Rast_is_d_null_value(obufptr))
- Rast_set_d_value(obufptr, *cellp, cell_type);
+ Rast_set_d_value(obufptr, cell, cell_type);
}
Modified: grass/trunk/imagery/i.rectify/cubic.c
===================================================================
--- grass/trunk/imagery/i.rectify/cubic.c 2010-10-18 15:12:24 UTC (rev 43972)
+++ grass/trunk/imagery/i.rectify/cubic.c 2010-10-18 15:30:41 UTC (rev 43973)
@@ -25,24 +25,17 @@
struct Cell_head *cellhd /* information of output map */
)
{
- int row, /* row indices for interp */
- col; /* column indices for interp */
+ int row; /* row indices for interp */
+ int col; /* column indices for interp */
int i, j;
- DCELL t, u, /* intermediate slope */
- result, /* result of interpolation */
- val[4]; /* buffer for temporary values */
- DCELL *cellp[4][4];
+ DCELL t, u; /* intermediate slope */
+ DCELL result; /* result of interpolation */
+ DCELL val[4]; /* buffer for temporary values */
+ DCELL cell[4][4];
- /* cut indices to integer and get nearest cells */
- /* example: *row_idx = 2.1
- * nearest rows are 0, 1, 2 and 3, not 1, 2, 3 and 4
- * row 0 streches from 0 to 1, row 4 from 4 to 5
- * 2.1 - 1 = 1.1
- * 4 - 2.1 = 1.9 */
- *row_idx -= 0.5;
- *col_idx -= 0.5;
- row = (int)floor(*row_idx);
- col = (int)floor(*col_idx);
+ /* cut indices to integer */
+ row = (int)floor(*row_idx - 0.5);
+ col = (int)floor(*col_idx - 0.5);
/* check for out of bounds of map - if out of bounds set NULL value */
if (row - 1 < 0 || row + 2 >= cellhd->rows ||
@@ -52,26 +45,21 @@
}
for (i = 0; i < 4; i++)
- for (j = 0; j < 4; j++)
- cellp[i][j] = CPTR(ibuffer, row - 1 + i, col - 1 + j);
-
- /* check for NULL value */
- for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++) {
- if (Rast_is_d_null_value(cellp[i][j])) {
+ const DCELL *cellp = CPTR(ibuffer, row - 1 + i, col - 1 + j);
+ if (Rast_is_d_null_value(cellp)) {
Rast_set_null_value(obufptr, 1, cell_type);
return;
}
+ cell[i][j] = *cellp;
}
/* do the interpolation */
- t = *col_idx - col;
- u = *row_idx - row;
+ t = *col_idx - 0.5 - col;
+ u = *row_idx - 0.5 - row;
for (i = 0; i < 4; i++) {
- DCELL **tmp = cellp[i];
-
- val[i] = Rast_interp_cubic(t, *tmp[0], *tmp[1], *tmp[2], *tmp[3]);
+ val[i] = Rast_interp_cubic(t, cell[i][0], cell[i][1], cell[i][2], cell[i][3]);
}
result = Rast_interp_cubic(u, val[0], val[1], val[2], val[3]);
Modified: grass/trunk/imagery/i.rectify/cubic_f.c
===================================================================
--- grass/trunk/imagery/i.rectify/cubic_f.c 2010-10-18 15:12:24 UTC (rev 43972)
+++ grass/trunk/imagery/i.rectify/cubic_f.c 2010-10-18 15:30:41 UTC (rev 43973)
@@ -24,7 +24,7 @@
{
/* start nearest neighbor to do some basic tests */
int row, col; /* row/col of nearest neighbor */
- DCELL *cellp;
+ DCELL *cellp, cell;
/* cut indices to integer */
row = (int)floor(*row_idx);
@@ -42,6 +42,7 @@
Rast_set_null_value(obufptr, 1, cell_type);
return;
}
+ cell = *cellp;
p_cubic(ibuffer, obufptr, cell_type, row_idx, col_idx, cellhd);
/* fallback to bilinear if cubic is null */
More information about the grass-commit
mailing list