[GRASS-SVN] r47614 - grass/trunk/raster/r.colors.out

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Aug 14 04:45:36 EDT 2011


Author: martinl
Date: 2011-08-14 01:45:36 -0700 (Sun, 14 Aug 2011)
New Revision: 47614

Removed:
   grass/trunk/raster/r.colors.out/local_proto.h
   grass/trunk/raster/r.colors.out/write_colors.c
Modified:
   grass/trunk/raster/r.colors.out/raster3d_main.c
   grass/trunk/raster/r.colors.out/raster_main.c
Log:
r[3].colors.out updated to use Rast_print_colors()


Deleted: grass/trunk/raster/r.colors.out/local_proto.h
===================================================================
--- grass/trunk/raster/r.colors.out/local_proto.h	2011-08-14 08:38:30 UTC (rev 47613)
+++ grass/trunk/raster/r.colors.out/local_proto.h	2011-08-14 08:45:36 UTC (rev 47614)
@@ -1,8 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/raster3d.h>
-#include <grass/raster.h>
-#include <grass/glocale.h>
-
-void write_colors(struct Colors *, struct FPRange*, const char *, int);
\ No newline at end of file

Modified: grass/trunk/raster/r.colors.out/raster3d_main.c
===================================================================
--- grass/trunk/raster/r.colors.out/raster3d_main.c	2011-08-14 08:38:30 UTC (rev 47613)
+++ grass/trunk/raster/r.colors.out/raster3d_main.c	2011-08-14 08:45:36 UTC (rev 47614)
@@ -1,13 +1,13 @@
 
 /****************************************************************************
  *
- * MODULE:       r.colors.out
+ * MODULE:       r3.colors.out
  *
  * AUTHOR(S):    Glynn Clements
  *
- * PURPOSE:      Allows export of the color table for a raster map layer.
+ * PURPOSE:      Allows export of the color table for a 3D raster map.
  *
- * COPYRIGHT:    (C) 2008, 2010 Glynn Clements and the GRASS Development Team
+ * COPYRIGHT:    (C) 2008, 2010-2011 Glynn Clements and the GRASS Development Team
  *
  *               This program is free software under the GNU General
  *               Public License (>=v2). Read the file COPYING that
@@ -15,7 +15,12 @@
  *
  ***************************************************************************/
 
-#include "local_proto.h"
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/raster3d.h>
+#include <grass/glocale.h>
 
 /* Run in raster3d mode */
 int main(int argc, char **argv)
@@ -29,6 +34,9 @@
     {
 	struct Flag *p;
     } flag;
+
+    const char *file;
+    FILE * fp;
     struct Colors colors;
     struct FPRange range;
     
@@ -39,9 +47,10 @@
     G_add_keyword(_("color table"));
     G_add_keyword(_("export"));
     module->description =
-    _("Exports the color table associated with a raster3d map layer.");
+	_("Exports the color table associated with a 3D raster map.");
 
     opt.map = G_define_standard_option(G_OPT_R3_MAP);
+    
     opt.file = G_define_standard_option(G_OPT_F_OUTPUT);
     opt.file->key = "rules";
     opt.file->label = _("Path to output rules file");
@@ -55,11 +64,24 @@
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
+    file = opt.file->answer;
+    
     if (Rast3d_read_colors(opt.map->answer, "", &colors) < 0)
-        G_fatal_error(_("Unable to read color table for raster3d map <%s>"), opt.map->answer);
+        G_fatal_error(_("Unable to read color table for raster3d map <%s>"),
+		      opt.map->answer);
+    
     Rast3d_read_range(opt.map->answer, "", &range);
-
-    write_colors(&colors, &range, opt.file->answer, flag.p->answer ? 1 : 0);
-
+    
+    if (!file || strcmp(file, "-") == 0)
+	fp = stdout;
+    else {
+	fp = fopen(file, "w");
+	if (!fp)
+	    G_fatal_error(_("Unable to open output file <%s>"), file);
+    }
+    
+    Rast_print_colors(&colors, range.min, range.max, fp,
+		      flag.p->answer ? 1 : 0);
+    
     exit(EXIT_SUCCESS);
 }

Modified: grass/trunk/raster/r.colors.out/raster_main.c
===================================================================
--- grass/trunk/raster/r.colors.out/raster_main.c	2011-08-14 08:38:30 UTC (rev 47613)
+++ grass/trunk/raster/r.colors.out/raster_main.c	2011-08-14 08:45:36 UTC (rev 47614)
@@ -5,9 +5,9 @@
  *
  * AUTHOR(S):    Glynn Clements
  *
- * PURPOSE:      Allows export of the color table for a raster map layer.
+ * PURPOSE:      Allows export of the color table for a raster map.
  *
- * COPYRIGHT:    (C) 2008, 2010 Glynn Clements and the GRASS Development Team
+ * COPYRIGHT:    (C) 2008, 2010-2011 Glynn Clements and the GRASS Development Team
  *
  *               This program is free software under the GNU General
  *               Public License (>=v2). Read the file COPYING that
@@ -15,7 +15,11 @@
  *
  ***************************************************************************/
 
-#include "local_proto.h"
+#include <stdlib.h>
+#include <string.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/glocale.h>
 
 /* Run in raster mode */
 int main(int argc, char **argv)
@@ -29,6 +33,9 @@
     {
 	struct Flag *p;
     } flag;
+
+    const char *file;
+    FILE * fp;
     struct Colors colors;
     struct FPRange range;
 
@@ -39,7 +46,7 @@
     G_add_keyword(_("color table"));
     G_add_keyword(_("export"));
     module->description =
-    _("Exports the color table associated with a raster map layer.");
+	_("Exports the color table associated with a raster map.");
    
     opt.map = G_define_standard_option(G_OPT_R_MAP);
     
@@ -56,11 +63,24 @@
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
+    file = opt.file->answer;
+    
     if (Rast_read_colors(opt.map->answer, "", &colors) < 0)
-        G_fatal_error(_("Unable to read color table for raster map <%s>"), opt.map->answer);
+        G_fatal_error(_("Unable to read color table for raster map <%s>"),
+		      opt.map->answer);
+
     Rast_read_fp_range(opt.map->answer, "", &range);
-
-    write_colors(&colors, &range, opt.file->answer, flag.p->answer ? 1 : 0);
-
+    
+    if (!file || strcmp(file, "-") == 0)
+	fp = stdout;
+    else {
+	fp = fopen(file, "w");
+	if (!fp)
+	    G_fatal_error(_("Unable to open output file <%s>"), file);
+    }
+    
+    Rast_print_colors(&colors, range.min, range.max, fp,
+		      flag.p->answer ? 1 : 0);
+    
     exit(EXIT_SUCCESS);
 }

Deleted: grass/trunk/raster/r.colors.out/write_colors.c
===================================================================
--- grass/trunk/raster/r.colors.out/write_colors.c	2011-08-14 08:38:30 UTC (rev 47613)
+++ grass/trunk/raster/r.colors.out/write_colors.c	2011-08-14 08:45:36 UTC (rev 47614)
@@ -1,93 +0,0 @@
-
-/****************************************************************************
- *
- * MODULE:       r.colors.out
- *
- * AUTHOR(S):    Glynn Clements
- *
- * PURPOSE:      Allows export of the color table for a raster map layer.
- *
- * COPYRIGHT:    (C) 2008, 2010 Glynn Clements and the GRASS Development Team
- *
- *               This program is free software under the GNU General
- *               Public License (>=v2). Read the file COPYING that
- *               comes with GRASS for details.
- *
- ***************************************************************************/
-
-#include "local_proto.h"
-
-static FILE *fp;
-static DCELL min, max;
-
-static void write_rule(DCELL *val, int r, int g, int b, int perc)
-{
-    static DCELL v0;
-    static int r0 = -1, g0 = -1, b0 = -1;
-
-    if (v0 == *val && r0 == r && g0 == g && b0 == b)
-	return;
-    v0 = *val, r0 = r, g0 = g, b0 = b;
-
-    if (perc)
-	fprintf(fp, "%g%% %d:%d:%d\n", 100 * (*val - min) / (max - min), r, g, b);
-    else
-	fprintf(fp, "%g %d:%d:%d\n", *val, r, g, b);
-}
-
-void write_colors(struct Colors *colors, struct FPRange*range, const char *file, 
-                  int perc)
-{
-    int i, count = 0;;
-
-    Rast_get_fp_range_min_max(range, &min, &max);
-
-    if (!file || strcmp(file, "-") == 0)
-	fp = stdout;
-    else {
-	fp = fopen(file, "w");
-	if (!fp)
-	    G_fatal_error(_("Unable to open output file <%s>"), file);
-    }
-
-    if (colors->version < 0) {
-	/* 3.0 format */
-	CELL lo, hi;
-
-	Rast_get_c_color_range(&lo, &hi, colors);
-
-	for (i = lo; i <= hi; i++) {
-	    unsigned char r, g, b, set;
-	    DCELL val = (DCELL) i;
-	    Rast_lookup_c_colors(&i, &r, &g, &b, &set, 1, colors);
-	    write_rule(&val, r, g, b, perc);
-	}
-    }
-    else {
-	count = Rast_colors_count(colors);
-
-	for (i = 0; i < count; i++) {
-	    DCELL val1, val2;
-	    unsigned char r1, g1, b1, r2, g2, b2;
-
-	    Rast_get_fp_color_rule(
-		&val1, &r1, &g1, &b1,
-		&val2, &r2, &g2, &b2,
-		colors, count - 1 - i);
-
-	    write_rule(&val1, r1, g1, b1, perc);
-	    write_rule(&val2, r2, g2, b2, perc);
-	}
-    }
-
-    {
-	int r, g, b;
-	Rast_get_null_value_color(&r, &g, &b, colors);
-	fprintf(fp, "nv %d:%d:%d\n", r, g, b);
-	Rast_get_default_color(&r, &g, &b, colors);
-	fprintf(fp, "default %d:%d:%d\n", r, g, b);
-    }
-
-    if (fp != stdout)
-	fclose(fp);
-}



More information about the grass-commit mailing list