Browse Source

Add G_abs_log_colors
Fix signature of G_make_grey_scale_fp_colors (double -> DCELL)



git-svn-id: https://svn.osgeo.org/grass/grass/trunk@34350 15284696-431f-4ddb-bdfa-cd5b030d7da7

Glynn Clements 16 years ago
parent
commit
6eef217538
3 changed files with 73 additions and 4 deletions
  1. 2 1
      include/gisdefs.h
  2. 1 1
      lib/gis/color_compat.c
  3. 70 2
      lib/gis/color_xform.c

+ 2 - 1
include/gisdefs.h

@@ -206,7 +206,7 @@ int G_make_bgyr_fp_colors(struct Colors *, DCELL, DCELL);
 int G_make_byg_colors(struct Colors *, CELL, CELL);
 int G_make_byg_colors(struct Colors *, CELL, CELL);
 int G_make_byg_fp_colors(struct Colors *, DCELL, DCELL);
 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_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_colors(struct Colors *, CELL, CELL);
 int G_make_gyr_fp_colors(struct Colors *, DCELL, DCELL);
 int G_make_gyr_fp_colors(struct Colors *, DCELL, DCELL);
 int G_make_rainbow_colors(struct Colors *, CELL, CELL);
 int G_make_rainbow_colors(struct Colors *, CELL, CELL);
@@ -357,6 +357,7 @@ int G_histogram_eq_colors(struct Colors *, struct Colors *,
 void G_histogram_eq_colors_fp(struct Colors *,
 void G_histogram_eq_colors_fp(struct Colors *,
 			      struct Colors *, struct FP_stats *);
 			      struct Colors *, struct FP_stats *);
 int G_log_colors(struct Colors *, struct Colors *, int);
 int G_log_colors(struct Colors *, struct Colors *, int);
+int G_abs_log_colors(struct Colors *, struct Colors *, int);
 
 
 /* commas.c */
 /* commas.c */
 int G_insert_commas(char *);
 int G_insert_commas(char *);

+ 1 - 1
lib/gis/color_compat.c

@@ -132,7 +132,7 @@ int G_make_grey_scale_colors(struct Colors *colors, CELL min, CELL max)
     return G_make_colors(colors, "grey", min, max);
     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);
     return G_make_fp_colors(colors, "grey", min, max);
 }
 }

+ 70 - 2
lib/gis/color_xform.c

@@ -232,8 +232,9 @@ int G_log_colors(struct Colors *dst, struct Colors *src, int samples)
 	}
 	}
 
 
 	if (i > 0)
 	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;
 	prev = x;
 
 
@@ -244,3 +245,70 @@ int G_log_colors(struct Colors *dst, struct Colors *src, int samples)
 
 
     return 0;
     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;
+}
+