[GRASS-SVN] r43944 - grass/trunk/raster/r.proj

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 17 05:34:59 EDT 2010


Author: glynn
Date: 2010-10-17 02:34:59 -0700 (Sun, 17 Oct 2010)
New Revision: 43944

Modified:
   grass/trunk/raster/r.proj/bilinear.c
   grass/trunk/raster/r.proj/bilinear_f.c
   grass/trunk/raster/r.proj/cubic.c
   grass/trunk/raster/r.proj/cubic_f.c
Log:
Don't store pointer to cache blocks which may be replaced


Modified: grass/trunk/raster/r.proj/bilinear.c
===================================================================
--- grass/trunk/raster/r.proj/bilinear.c	2010-10-17 08:58:46 UTC (rev 43943)
+++ grass/trunk/raster/r.proj/bilinear.c	2010-10-17 09:34:59 UTC (rev 43944)
@@ -23,46 +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 */
-    FCELL t, u,			/* intermediate slope            */
-      tu,			/* t * u                         */
-      result;			/* result of interpolation       */
-    FCELL *c00, *c01, *c10, *c11;
+    int row;			/* row indices for interp        */
+    int col;			/* column indices for interp     */
+    int i, j;
+    FCELL t, u;			/* intermediate slope            */
+    FCELL result;		/* result of interpolation       */
+    FCELL c[2][2];
 
     /* cut indices to integer */
-    row0 = (int)floor(*row_idx - 0.5);
-    col0 = (int)floor(*col_idx - 0.5);
-    row1 = row0 + 1;
-    col1 = col0 + 1;
+    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 FCELL *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 - 0.5 - col0;
-    u = *row_idx - 0.5 - 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_f_value(obufptr, result, cell_type);
 }

Modified: grass/trunk/raster/r.proj/bilinear_f.c
===================================================================
--- grass/trunk/raster/r.proj/bilinear_f.c	2010-10-17 08:58:46 UTC (rev 43943)
+++ grass/trunk/raster/r.proj/bilinear_f.c	2010-10-17 09:34:59 UTC (rev 43944)
@@ -22,7 +22,7 @@
 {
     /* start nearest neighbor to do some basic tests */
     int row, col;		/* row/col of nearest neighbor   */
-    FCELL *cellp;
+    FCELL *cellp, cell;
 
     /* cut indices to integer */
     row = (int)floor(*row_idx);
@@ -40,9 +40,10 @@
         Rast_set_null_value(obufptr, 1, cell_type);
         return;
     }
-    
+    cell = *cellp;
+
     p_bilinear(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
     /* fallback to nearest if bilinear is null */
     if (Rast_is_f_null_value(obufptr))
-        Rast_set_f_value(obufptr, *cellp, cell_type);
+        Rast_set_f_value(obufptr, cell, cell_type);
 }

Modified: grass/trunk/raster/r.proj/cubic.c
===================================================================
--- grass/trunk/raster/r.proj/cubic.c	2010-10-17 08:58:46 UTC (rev 43943)
+++ grass/trunk/raster/r.proj/cubic.c	2010-10-17 09:34:59 UTC (rev 43944)
@@ -26,13 +26,13 @@
 	     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;
-    FCELL t, u,			/* intermediate slope            */
-      result,			/* result of interpolation       */
-      val[4];			/* buffer for temporary values   */
-    FCELL *cellp[4][4];
+    FCELL t, u;			/* intermediate slope            */
+    FCELL result;		/* result of interpolation       */
+      FCELL val[4];		/* buffer for temporary values   */
+    FCELL cell[4][4];
 
     /* cut indices to integer */
     row = (int)floor(*row_idx - 0.5);
@@ -46,16 +46,13 @@
     }
 
     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_f_null_value(cellp[i][j])) {
+	    const FCELL *cellp = CPTR(ibuffer, row - 1 + i, col - 1 + j);
+	    if (Rast_is_f_null_value(cellp)) {
 		Rast_set_null_value(obufptr, 1, cell_type);
 		return;
 	    }
+	    cell[i][j] = *cellp;
 	}
 
     /* do the interpolation  */
@@ -63,9 +60,8 @@
     u = *row_idx - 0.5 - row;
 
     for (i = 0; i < 4; i++) {
-	FCELL **tmp = cellp[i];
-
-	val[i] = Rast_interp_cubic(t, *tmp[0], *tmp[1], *tmp[2], *tmp[3]);
+	const FCELL *tmp = cell[i];
+	val[i] = Rast_interp_cubic(t, tmp[0], tmp[1], tmp[2], tmp[3]);
     }
 
     result = Rast_interp_cubic(u, val[0], val[1], val[2], val[3]);

Modified: grass/trunk/raster/r.proj/cubic_f.c
===================================================================
--- grass/trunk/raster/r.proj/cubic_f.c	2010-10-17 08:58:46 UTC (rev 43943)
+++ grass/trunk/raster/r.proj/cubic_f.c	2010-10-17 09:34:59 UTC (rev 43944)
@@ -23,7 +23,7 @@
 {
     /* start nearest neighbor to do some basic tests */
     int row, col;		/* row/col of nearest neighbor   */
-    FCELL *cellp;
+    FCELL *cellp, cell;
 
     /* cut indices to integer */
     row = (int)floor(*row_idx);
@@ -41,13 +41,14 @@
         Rast_set_null_value(obufptr, 1, cell_type);
         return;
     }
-    
+    cell = *cellp;
+
     p_cubic(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
     /* fallback to bilinear if cubic is null */
     if (Rast_is_f_null_value(obufptr)) {
         p_bilinear(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
         /* fallback to nearest if bilinear is null */
 	if (Rast_is_f_null_value(obufptr))
-            Rast_set_f_value(obufptr, *cellp, cell_type);
+            Rast_set_f_value(obufptr, cell, cell_type);
     }
 }



More information about the grass-commit mailing list