[GRASS-SVN] r34350 - in grass/trunk: include lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 17 20:26:20 EST 2008
Author: glynn
Date: 2008-11-17 20:26:19 -0500 (Mon, 17 Nov 2008)
New Revision: 34350
Modified:
grass/trunk/include/gisdefs.h
grass/trunk/lib/gis/color_compat.c
grass/trunk/lib/gis/color_xform.c
Log:
Add G_abs_log_colors
Fix signature of G_make_grey_scale_fp_colors (double -> DCELL)
Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h 2008-11-17 22:01:12 UTC (rev 34349)
+++ grass/trunk/include/gisdefs.h 2008-11-18 01:26:19 UTC (rev 34350)
@@ -206,7 +206,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);
@@ -357,6 +357,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/trunk/lib/gis/color_compat.c
===================================================================
--- grass/trunk/lib/gis/color_compat.c 2008-11-17 22:01:12 UTC (rev 34349)
+++ grass/trunk/lib/gis/color_compat.c 2008-11-18 01:26:19 UTC (rev 34350)
@@ -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/trunk/lib/gis/color_xform.c
===================================================================
--- grass/trunk/lib/gis/color_xform.c 2008-11-17 22:01:12 UTC (rev 34349)
+++ grass/trunk/lib/gis/color_xform.c 2008-11-18 01:26:19 UTC (rev 34350)
@@ -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