[GRASS-SVN] r43955 - grass/branches/develbranch_6/raster/r.proj.seg

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 17 15:05:46 EDT 2010


Author: neteler
Date: 2010-10-17 12:05:45 -0700 (Sun, 17 Oct 2010)
New Revision: 43955

Modified:
   grass/branches/develbranch_6/raster/r.proj.seg/bilinear.c
   grass/branches/develbranch_6/raster/r.proj.seg/bilinear_f.c
   grass/branches/develbranch_6/raster/r.proj.seg/cubic.c
   grass/branches/develbranch_6/raster/r.proj.seg/cubic_f.c
Log:
glynn: Don't store pointer to cache blocks which may be replaced (backport of r43944)

Modified: grass/branches/develbranch_6/raster/r.proj.seg/bilinear.c
===================================================================
--- grass/branches/develbranch_6/raster/r.proj.seg/bilinear.c	2010-10-17 18:10:45 UTC (rev 43954)
+++ grass/branches/develbranch_6/raster/r.proj.seg/bilinear.c	2010-10-17 19:05:45 UTC (rev 43955)
@@ -22,46 +22,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) {
 	G_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 (G_is_f_null_value(cellp)) {
+		G_set_null_value(obufptr, 1, cell_type);
+		return;
+	    }
+	    c[i][j] = *cellp;
+	}
 
-    /* check for NULL values */
-    if (G_is_f_null_value(c00) ||
-	G_is_f_null_value(c01) ||
-	G_is_f_null_value(c10) || G_is_f_null_value(c11)) {
-	G_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 = G_interp_bilinear(t, u, *c00, *c01, *c10, *c11);
+    result = G_interp_bilinear(t, u, c[0][0], c[0][1], c[1][0], c[1][1]);
 
     G_set_raster_value_f(obufptr, result, cell_type);
 }

Modified: grass/branches/develbranch_6/raster/r.proj.seg/bilinear_f.c
===================================================================
--- grass/branches/develbranch_6/raster/r.proj.seg/bilinear_f.c	2010-10-17 18:10:45 UTC (rev 43954)
+++ grass/branches/develbranch_6/raster/r.proj.seg/bilinear_f.c	2010-10-17 19:05:45 UTC (rev 43955)
@@ -21,7 +21,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);
@@ -39,9 +39,10 @@
         G_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 (G_is_f_null_value(obufptr))
-        G_set_raster_value_f(obufptr, *cellp, cell_type);
+        G_set_raster_value_f(obufptr, cell, cell_type);
 }

Modified: grass/branches/develbranch_6/raster/r.proj.seg/cubic.c
===================================================================
--- grass/branches/develbranch_6/raster/r.proj.seg/cubic.c	2010-10-17 18:10:45 UTC (rev 43954)
+++ grass/branches/develbranch_6/raster/r.proj.seg/cubic.c	2010-10-17 19:05:45 UTC (rev 43955)
@@ -25,13 +25,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);
@@ -45,16 +45,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 (G_is_f_null_value(cellp[i][j])) {
+	    const FCELL *cellp = CPTR(ibuffer, row - 1 + i, col - 1 + j);
+	    if (G_is_f_null_value(cellp)) {
 		G_set_null_value(obufptr, 1, cell_type);
 		return;
 	    }
+	    cell[i][j] = *cellp;
 	}
 
     /* do the interpolation  */
@@ -62,9 +59,8 @@
     u = *row_idx - 0.5 - row;
 
     for (i = 0; i < 4; i++) {
-	FCELL **tmp = cellp[i];
-
-	val[i] = G_interp_cubic(t, *tmp[0], *tmp[1], *tmp[2], *tmp[3]);
+	const FCELL *tmp = cell[i];
+	val[i] = G_interp_cubic(t, tmp[0], tmp[1], tmp[2], tmp[3]);
     }
 
     result = G_interp_cubic(u, val[0], val[1], val[2], val[3]);

Modified: grass/branches/develbranch_6/raster/r.proj.seg/cubic_f.c
===================================================================
--- grass/branches/develbranch_6/raster/r.proj.seg/cubic_f.c	2010-10-17 18:10:45 UTC (rev 43954)
+++ grass/branches/develbranch_6/raster/r.proj.seg/cubic_f.c	2010-10-17 19:05:45 UTC (rev 43955)
@@ -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,13 +40,14 @@
         G_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 (G_is_f_null_value(obufptr)) {
         p_bilinear(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
         /* fallback to nearest if bilinear is null */
-		if (G_is_f_null_value(obufptr))
-            G_set_raster_value_f(obufptr, *cellp, cell_type);
+	if (G_is_f_null_value(obufptr))
+            G_set_raster_value_f(obufptr, cell, cell_type);
     }
 }



More information about the grass-commit mailing list