[GRASS-SVN] r34391 - in grass/branches/develbranch_6: include lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Nov 19 06:46:13 EST 2008


Author: hamish
Date: 2008-11-19 06:46:13 -0500 (Wed, 19 Nov 2008)
New Revision: 34391

Modified:
   grass/branches/develbranch_6/include/gisdefs.h
   grass/branches/develbranch_6/lib/gis/color_compat.c
   grass/branches/develbranch_6/lib/gis/color_xform.c
Log:
Add G_abs_log_colors
Fix signature of G_make_grey_scale_fp_colors (double -> DCELL)
 [Glynn; merge from trunk]


Modified: grass/branches/develbranch_6/include/gisdefs.h
===================================================================
--- grass/branches/develbranch_6/include/gisdefs.h	2008-11-19 11:41:15 UTC (rev 34390)
+++ grass/branches/develbranch_6/include/gisdefs.h	2008-11-19 11:46:13 UTC (rev 34391)
@@ -237,7 +237,7 @@
 int G_make_byg_colors(struct Colors *, CELL, CELL);
 int G_make_byg_fp_colors(struct Colors *, DCELL, DCELL);
 int G_make_grey_scale_colors(struct Colors *, CELL, CELL);
-int G_make_grey_scale_fp_colors(struct Colors *, double, double);
+int G_make_grey_scale_fp_colors(struct Colors *, DCELL, DCELL);
 int G_make_gyr_colors(struct Colors *, CELL, CELL);
 int G_make_gyr_fp_colors(struct Colors *, DCELL, DCELL);
 int G_make_rainbow_colors(struct Colors *, CELL, CELL);
@@ -388,6 +388,7 @@
 void G_histogram_eq_colors_fp(struct Colors *,
 			      struct Colors *, struct FP_stats *);
 int G_log_colors(struct Colors *, struct Colors *, int);
+int G_abs_log_colors(struct Colors *, struct Colors *, int);
 
 /* commas.c */
 int G_insert_commas(char *);

Modified: grass/branches/develbranch_6/lib/gis/color_compat.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/color_compat.c	2008-11-19 11:41:15 UTC (rev 34390)
+++ grass/branches/develbranch_6/lib/gis/color_compat.c	2008-11-19 11:46:13 UTC (rev 34391)
@@ -132,7 +132,7 @@
     return G_make_colors(colors, "grey", min, max);
 }
 
-int G_make_grey_scale_fp_colors(struct Colors *colors, double min, double max)
+int G_make_grey_scale_fp_colors(struct Colors *colors, DCELL min, DCELL max)
 {
     return G_make_fp_colors(colors, "grey", min, max);
 }

Modified: grass/branches/develbranch_6/lib/gis/color_xform.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/color_xform.c	2008-11-19 11:41:15 UTC (rev 34390)
+++ grass/branches/develbranch_6/lib/gis/color_xform.c	2008-11-19 11:46:13 UTC (rev 34391)
@@ -232,8 +232,9 @@
 	}
 
 	if (i > 0)
-	    G_add_d_raster_color_rule(&prev, red, grn, blu, &x, red2, grn2,
-				      blu2, dst);
+	    G_add_d_raster_color_rule(&prev, red, grn, blu,
+				      &x, red2, grn2, blu2,
+				      dst);
 
 	prev = x;
 
@@ -244,3 +245,70 @@
 
     return 0;
 }
+
+/*!
+ * \brief make logarithmically-scaled version of an existing color table, allowing for signed values
+ *
+ *  \param dst
+ *  \param src
+ *  \param samples
+ *  \return int
+ */
+
+int G_abs_log_colors(struct Colors *dst, struct Colors *src, int samples)
+{
+    DCELL min, max;
+    double lmin, lmax;
+    DCELL amax, lamax;
+    int red, grn, blu;
+    DCELL prev;
+    int i;
+
+    G_init_colors(dst);
+
+    G_get_d_color_range(&min, &max, src);
+
+    lmin = log(fabs(min) + 1.0);
+    lmax = log(fabs(max) + 1.0);
+
+    amax = fabs(min) > fabs(max) ? fabs(min) : fabs(max);
+    lamax = lmin > lmax ? lmin : lmax;
+
+    G_get_default_color(&red, &grn, &blu, src);
+    G_set_default_color(red, grn, blu, dst);
+
+    G_get_null_value_color(&red, &grn, &blu, src);
+    G_set_null_value_color(red, grn, blu, dst);
+
+    for (i = 0; i <= samples; i++) {
+	int red2, grn2, blu2;
+	double lx;
+	DCELL x, y;
+
+	y = min + (max - min) * i / samples;
+	G_get_d_raster_color(&y, &red2, &grn2, &blu2, src);
+
+	if (i == 0)
+	    x = 1;
+	else if (i == samples)
+	    x = amax;
+	else {
+	    lx = 0 + lamax * i / samples;
+	    x = exp(lx);
+	}
+
+	if (i > 0)
+	    G_add_d_raster_color_rule(&prev, red, grn, blu,
+				      &x, red2, grn2, blu2,
+				      dst);
+
+	prev = x;
+
+	red = red2;
+	grn = grn2;
+	blu = blu2;
+    }
+
+    return 0;
+}
+



More information about the grass-commit mailing list