[GRASS-SVN] r38069 - in grass/trunk: display/d.extract display/d.graph display/d.grid display/d.labels display/d.path display/d.rast display/d.thematic.area display/d.vect display/d.vect.chart include lib/display lib/gis lib/nviz lib/raster ps/ps.map vector/v.to.rast

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 25 04:27:18 EDT 2009


Author: martinl
Date: 2009-06-25 04:27:18 -0400 (Thu, 25 Jun 2009)
New Revision: 38069

Added:
   grass/trunk/lib/gis/color_str.c
Removed:
   grass/trunk/lib/raster/color_str.c
Modified:
   grass/trunk/display/d.extract/main.c
   grass/trunk/display/d.graph/do_graph.c
   grass/trunk/display/d.graph/main.c
   grass/trunk/display/d.grid/fiducial.c
   grass/trunk/display/d.labels/color.c
   grass/trunk/display/d.path/main.c
   grass/trunk/display/d.rast/display.c
   grass/trunk/display/d.thematic.area/main.c
   grass/trunk/display/d.thematic.area/plot1.c
   grass/trunk/display/d.vect.chart/main.c
   grass/trunk/display/d.vect/area.c
   grass/trunk/display/d.vect/main.c
   grass/trunk/display/d.vect/plot1.c
   grass/trunk/include/gisdefs.h
   grass/trunk/include/raster.h
   grass/trunk/lib/display/tran_colr.c
   grass/trunk/lib/nviz/nviz.c
   grass/trunk/lib/raster/color_hist.c
   grass/trunk/ps/ps.map/do_labels.c
   grass/trunk/ps/ps.map/main.c
   grass/trunk/ps/ps.map/ps_vareas.c
   grass/trunk/ps/ps.map/ps_vlines.c
   grass/trunk/ps/ps.map/ps_vpoints.c
   grass/trunk/ps/ps.map/r_border.c
   grass/trunk/ps/ps.map/r_plt.c
   grass/trunk/ps/ps.map/r_text.c
   grass/trunk/ps/ps.map/r_vareas.c
   grass/trunk/ps/ps.map/r_vlines.c
   grass/trunk/ps/ps.map/r_vpoints.c
   grass/trunk/ps/ps.map/r_wind.c
   grass/trunk/vector/v.to.rast/support.c
Log:
color_str.c moved back to libgis (modules fixed)


Modified: grass/trunk/display/d.extract/main.c
===================================================================
--- grass/trunk/display/d.extract/main.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.extract/main.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -78,14 +78,14 @@
 	G_fatal_error(_("No graphics device selected"));
 
     color = G_standard_color_rgb(BLACK);
-    if (Rast_str_to_color(color_opt->answer, &r, &g, &b)) {
+    if (G_str_to_color(color_opt->answer, &r, &g, &b)) {
 	color.r = r;
 	color.g = g;
 	color.b = b;
     }
 
     hcolor = G_standard_color_rgb(RED);
-    if (Rast_str_to_color(hcolor_opt->answer, &r, &g, &b)) {
+    if (G_str_to_color(hcolor_opt->answer, &r, &g, &b)) {
 	hcolor.r = r;
 	hcolor.g = g;
 	hcolor.b = b;

Modified: grass/trunk/display/d.graph/do_graph.c
===================================================================
--- grass/trunk/display/d.graph/do_graph.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.graph/do_graph.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -99,7 +99,7 @@
     }
 
     /* Parse and select color */
-    color = Rast_str_to_color(in_color, &R, &G, &B);
+    color = G_str_to_color(in_color, &R, &G, &B);
     if (color == 0) {
 	G_warning(_("[%s]: No such color"), in_color);
 	/* store for backup */
@@ -339,7 +339,7 @@
     size *= yincr;
 
     /* parse line color */
-    ret = Rast_str_to_color(line_color_str, &R, &G, &B);
+    ret = G_str_to_color(line_color_str, &R, &G, &B);
     line_color->r = (unsigned char)R;
     line_color->g = (unsigned char)G;
     line_color->b = (unsigned char)B;
@@ -356,7 +356,7 @@
     }
 
     /* parse fill color */
-    ret = Rast_str_to_color(fill_color_str, &R, &G, &B);
+    ret = G_str_to_color(fill_color_str, &R, &G, &B);
     fill_color->r = (unsigned char)R;
     fill_color->g = (unsigned char)G;
     fill_color->b = (unsigned char)B;

Modified: grass/trunk/display/d.graph/main.c
===================================================================
--- grass/trunk/display/d.graph/main.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.graph/main.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -101,7 +101,7 @@
 
     /* Parse and select color */
     if (opt2->answer != NULL) {
-	color = Rast_str_to_color(opt2->answer, &R, &G, &B);
+	color = G_str_to_color(opt2->answer, &R, &G, &B);
 
 	if (color == 0)
 	    G_fatal_error(_("[%s]: No such color"), opt2->answer);

Modified: grass/trunk/display/d.grid/fiducial.c
===================================================================
--- grass/trunk/display/d.grid/fiducial.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.grid/fiducial.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -34,7 +34,7 @@
 
     if (D_color_number_to_RGB(color, &R, &G, &B) == 0)
 	/* fall back to black on failure */
-	Rast_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
+	G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
 
     line_color->r = (unsigned char)R;
     line_color->g = (unsigned char)G;

Modified: grass/trunk/display/d.labels/color.c
===================================================================
--- grass/trunk/display/d.labels/color.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.labels/color.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -53,7 +53,7 @@
     int r, g, b;
     int ret;
 
-    ret = Rast_str_to_color(clr_str, &r, &g, &b);
+    ret = G_str_to_color(clr_str, &r, &g, &b);
 
     if (ret == 1) {
 	color->a = RGBA_COLOR_OPAQUE;

Modified: grass/trunk/display/d.path/main.c
===================================================================
--- grass/trunk/display/d.path/main.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.path/main.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -153,21 +153,21 @@
 	G_fatal_error(_("No graphics device selected"));
 
     color = G_standard_color_rgb(BLACK);
-    if (Rast_str_to_color(color_opt->answer, &r, &g, &b)) {
+    if (G_str_to_color(color_opt->answer, &r, &g, &b)) {
 	color.r = r;
 	color.g = g;
 	color.b = b;
     }
 
     hcolor = G_standard_color_rgb(RED);
-    if (Rast_str_to_color(hcolor_opt->answer, &r, &g, &b)) {
+    if (G_str_to_color(hcolor_opt->answer, &r, &g, &b)) {
 	hcolor.r = r;
 	hcolor.g = g;
 	hcolor.b = b;
     }
 
     bgcolor = G_standard_color_rgb(WHITE);
-    if (Rast_str_to_color(bgcolor_opt->answer, &r, &g, &b)) {
+    if (G_str_to_color(bgcolor_opt->answer, &r, &g, &b)) {
 	bgcolor.r = r;
 	bgcolor.g = g;
 	bgcolor.b = b;

Modified: grass/trunk/display/d.rast/display.c
===================================================================
--- grass/trunk/display/d.rast/display.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.rast/display.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -22,7 +22,7 @@
 	G_fatal_error(_("Color file for <%s> not available"), name);
 
     if (bg) {
-	if (Rast_str_to_color(bg, &r, &g, &b) != 1) {
+	if (G_str_to_color(bg, &r, &g, &b) != 1) {
 	    G_warning(_("[%s]: No such color"), bg);
 	    r = g = b = 255;
 	}

Modified: grass/trunk/display/d.thematic.area/main.c
===================================================================
--- grass/trunk/display/d.thematic.area/main.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.thematic.area/main.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -272,7 +272,7 @@
 
     /*get border line color */
     bcolor = G_standard_color_rgb(WHITE);
-    ret = Rast_str_to_color(bcolor_opt->answer, &r, &g, &b);
+    ret = G_str_to_color(bcolor_opt->answer, &r, &g, &b);
     if (ret == 1) {
 	has_color = 1;
 	bcolor.r = r;
@@ -347,7 +347,7 @@
 		G_fatal_error(_("Not enough colors or error in color specifications.\nNeed %i colors."),
 			      nclass);
 
-	    ret = Rast_str_to_color(colors_opt->answers[i], &r, &g, &b);
+	    ret = G_str_to_color(colors_opt->answers[i], &r, &g, &b);
 	    if (!ret)
 		G_fatal_error(_("Error interpreting color %s"),
 			      colors_opt->answers[i]);

Modified: grass/trunk/display/d.thematic.area/plot1.c
===================================================================
--- grass/trunk/display/d.thematic.area/plot1.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.thematic.area/plot1.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -267,7 +267,7 @@
 			G_debug(3, "element %d: colorstring: %s", line,
 				colorstring);
 
-			if (Rast_str_to_color(colorstring, &red, &grn, &blu) ==
+			if (G_str_to_color(colorstring, &red, &grn, &blu) ==
 			    1) {
 			    custom_rgb = TRUE;
 			    G_debug(3, "element:%d  cat %d r:%d g:%d b:%d",

Modified: grass/trunk/display/d.vect/area.c
===================================================================
--- grass/trunk/display/d.vect/area.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.vect/area.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -267,7 +267,7 @@
 			G_debug(3, "area %d: colorstring: %s", area,
 				colorstring);
 
-			if (Rast_str_to_color(colorstring, &red, &grn, &blu) ==
+			if (G_str_to_color(colorstring, &red, &grn, &blu) ==
 			    1) {
 			    rgb = 1;
 			    G_debug(3, "area:%d  cat %d r:%d g:%d b:%d", area,

Modified: grass/trunk/display/d.vect/main.c
===================================================================
--- grass/trunk/display/d.vect/main.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.vect/main.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -393,7 +393,7 @@
     }
 
     color = G_standard_color_rgb(WHITE);
-    ret = Rast_str_to_color(color_opt->answer, &r, &g, &b);
+    ret = G_str_to_color(color_opt->answer, &r, &g, &b);
     if (ret == 1) {
 	has_color = 1;
 	color.r = r;
@@ -408,7 +408,7 @@
     }
 
     fcolor = G_standard_color_rgb(WHITE);
-    ret = Rast_str_to_color(fcolor_opt->answer, &r, &g, &b);
+    ret = G_str_to_color(fcolor_opt->answer, &r, &g, &b);
     if (ret == 1) {
 	has_fcolor = 1;
 	fcolor.r = r;
@@ -533,20 +533,20 @@
 	lattr.field = Clist->field;
 
     lattr.color.R = lattr.color.G = lattr.color.B = 255;
-    if (Rast_str_to_color(lcolor_opt->answer, &r, &g, &b)) {
+    if (G_str_to_color(lcolor_opt->answer, &r, &g, &b)) {
 	lattr.color.R = r;
 	lattr.color.G = g;
 	lattr.color.B = b;
     }
     lattr.has_bgcolor = 0;
-    if (Rast_str_to_color(bgcolor_opt->answer, &r, &g, &b) == 1) {
+    if (G_str_to_color(bgcolor_opt->answer, &r, &g, &b) == 1) {
 	lattr.has_bgcolor = 1;
 	lattr.bgcolor.R = r;
 	lattr.bgcolor.G = g;
 	lattr.bgcolor.B = b;
     }
     lattr.has_bcolor = 0;
-    if (Rast_str_to_color(bcolor_opt->answer, &r, &g, &b) == 1) {
+    if (G_str_to_color(bcolor_opt->answer, &r, &g, &b) == 1) {
 	lattr.has_bcolor = 1;
 	lattr.bcolor.R = r;
 	lattr.bcolor.G = g;

Modified: grass/trunk/display/d.vect/plot1.c
===================================================================
--- grass/trunk/display/d.vect/plot1.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.vect/plot1.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -284,7 +284,7 @@
 			G_debug(3, "element %d: colorstring: %s", line,
 				colorstring);
 
-			if (Rast_str_to_color(colorstring, &red, &grn, &blu) ==
+			if (G_str_to_color(colorstring, &red, &grn, &blu) ==
 			    1) {
 			    custom_rgb = TRUE;
 			    G_debug(3, "element:%d  cat %d r:%d g:%d b:%d",

Modified: grass/trunk/display/d.vect.chart/main.c
===================================================================
--- grass/trunk/display/d.vect.chart/main.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/display/d.vect.chart/main.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -171,7 +171,7 @@
     field = atoi(field_opt->answer);
 
     /* Outline color */
-    ret = Rast_str_to_color(ocolor_opt->answer, &r, &g, &b);
+    ret = G_str_to_color(ocolor_opt->answer, &r, &g, &b);
     if (ret == 1) {
 	ocolor.none = 0;
 	ocolor.r = r;
@@ -215,7 +215,7 @@
 	    if (colors_opt->answers[i] == NULL)
 		break;
 
-	    ret = Rast_str_to_color(colors_opt->answers[i], &r, &g, &b);
+	    ret = G_str_to_color(colors_opt->answers[i], &r, &g, &b);
 	    if (ret == 1) {
 		colors[i].none = 0;
 		colors[i].r = r;

Modified: grass/trunk/include/gisdefs.h
===================================================================
--- grass/trunk/include/gisdefs.h	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/include/gisdefs.h	2009-06-25 08:27:18 UTC (rev 38069)
@@ -117,6 +117,13 @@
 /* clicker.c */
 void G_clicker(void);
 
+/* color_str.c */
+int G_num_standard_colors(void);
+struct color_rgb G_standard_color_rgb(int);
+int G_num_standard_color_names(void);
+const struct color_name *G_standard_color_name(int);
+int G_str_to_color(const char *, int *, int *, int *);
+
 /* commas.c */
 int G_insert_commas(char *);
 void G_remove_commas(char *);

Modified: grass/trunk/include/raster.h
===================================================================
--- grass/trunk/include/raster.h	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/include/raster.h	2009-06-25 08:27:18 UTC (rev 38069)
@@ -250,9 +250,6 @@
 void Rast_shift_colors(int, struct Colors *);
 void Rast_shift_d_colors(DCELL, struct Colors *);
 
-/* color_str.c */
-int Rast_str_to_color(const char *, int *, int *, int *);
-
 /* color_write.c */
 int Rast_write_colors(const char *, const char *, struct Colors *);
 void Rast__write_colors(FILE *, struct Colors *);

Modified: grass/trunk/lib/display/tran_colr.c
===================================================================
--- grass/trunk/lib/display/tran_colr.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/lib/display/tran_colr.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -57,7 +57,7 @@
 	    colors[i] = G_standard_color_rgb(i);
     }
 
-    ret = Rast_str_to_color(str, &red, &grn, &blu);
+    ret = G_str_to_color(str, &red, &grn, &blu);
 
     /* None color */
     if (ret == 2)

Copied: grass/trunk/lib/gis/color_str.c (from rev 38068, grass/trunk/lib/raster/color_str.c)
===================================================================
--- grass/trunk/lib/gis/color_str.c	                        (rev 0)
+++ grass/trunk/lib/gis/color_str.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -0,0 +1,150 @@
+/*!
+   \file gis/color_str.c
+
+   \brief GIS library - color management, named color to RGB triplet
+
+   (C) 2001-2008 by 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.
+
+   \author Original author CERL
+ */
+
+#include <string.h>
+
+#include <grass/gis.h>
+#include <grass/colors.h>
+
+/* The order in this table is important! It will be indexed by color number */
+static const struct color_rgb standard_colors_rgb[] = {
+    {0, 0, 0},			/* This is a dummy value to make lookup easier */
+    {0, 0, 0},			/* BLACK   */
+    {255, 0, 0},		/* RED     */
+    {0, 255, 0},		/* GREEN   */
+    {0, 0, 255},		/* BLUE    */
+    {255, 255, 0},		/* YELLOW  */
+    {0, 255, 255},		/* CYAN    */
+    {255, 0, 255},		/* MAGENTA */
+    {255, 255, 255},		/* WHITE   */
+    {128, 128, 128},		/* GRAY    */
+    {255, 128, 0},		/* ORANGE  */
+    {100, 128, 255},		/* AQUA    */
+    {0, 128, 255},		/* INDIGO  */
+    {128, 0, 255},		/* VIOLET  */
+    {180, 77, 25}		/* BROWN   */
+};
+
+/* The order in this table has no meaning. */
+static const struct color_name standard_color_names[] = {
+    {"black", BLACK},
+    {"red", RED},
+    {"green", GREEN},
+    {"blue", BLUE},
+    {"yellow", YELLOW},
+    {"cyan", CYAN},
+    {"magenta", MAGENTA},
+    {"white", WHITE},
+    {"grey", GREY},
+    {"gray", GRAY},
+    {"orange", ORANGE},
+    {"aqua", AQUA},
+    {"indigo", INDIGO},
+    {"violet", VIOLET},
+    {"purple", PURPLE},
+    {"brown", BROWN}
+};
+
+/*!
+   \brief Get number of named colors (RGB triplets)
+
+   \return number of colors
+ */
+int G_num_standard_colors(void)
+{
+    return sizeof(standard_colors_rgb) / sizeof(standard_colors_rgb[0]);
+}
+
+/*!
+   \brief Get RGB triplet of given color
+
+   \param n color index
+ */
+struct color_rgb G_standard_color_rgb(int n)
+{
+    return standard_colors_rgb[n];
+}
+
+/*!
+   \brief Get number of named colors (color names)
+
+   \return number of colors
+ */
+int G_num_standard_color_names(void)
+{
+    return sizeof(standard_color_names) / sizeof(standard_color_names[0]);
+}
+
+/*!
+   \brief Get color name
+
+   \param n color index
+ */
+const struct color_name *G_standard_color_name(int n)
+{
+    return &standard_color_names[n];
+}
+
+/*! 
+   \brief Parse color string and set red,green,blue
+
+   \param str color string
+   \param[out] red red value
+   \param[out] grn green value
+   \param[out] blu blue value
+
+   \return 1 OK
+   \return 2 NONE 
+   \return 0 on error 
+ */
+int G_str_to_color(const char *str, int *red, int *grn, int *blu)
+{
+    char buf[100];
+    int num_names = G_num_standard_color_names();
+    int i;
+
+    strcpy(buf, str);
+    G_chop(buf);
+
+    G_debug(3, "G_str_to_color(): str = '%s'", buf);
+
+    if (G_strcasecmp(buf, "NONE") == 0)
+	return 2;
+
+    if (sscanf(buf, "%d%*[,:; ]%d%*[,:; ]%d", red, grn, blu) == 3) {
+	if (*red < 0 || *red > 255 ||
+	    *grn < 0 || *grn > 255 || *blu < 0 || *blu > 255)
+	    return 0;
+
+	return 1;
+    }
+
+    /* Look for this color in the standard (preallocated) colors */
+    for (i = 0; i < num_names; i++) {
+	const struct color_name *name = &standard_color_names[i];
+
+	if (G_strcasecmp(buf, name->name) == 0) {
+	    struct color_rgb rgb = standard_colors_rgb[name->number];
+
+	    *red = (int)rgb.r;
+	    *grn = (int)rgb.g;
+	    *blu = (int)rgb.b;
+
+	    return 1;
+	}
+    }
+
+    return 0;
+}

Modified: grass/trunk/lib/nviz/nviz.c
===================================================================
--- grass/trunk/lib/nviz/nviz.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/lib/nviz/nviz.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -73,7 +73,7 @@
 {
     int red, grn, blu;
 
-    if (Rast_str_to_color(color_str, &red, &grn, &blu) != 1) {
+    if (G_str_to_color(color_str, &red, &grn, &blu) != 1) {
 	G_warning(_("Invalid color (%s), using \"white\" as default"),
 		  color_str);
 	red = grn = blu = 255;

Modified: grass/trunk/lib/raster/color_hist.c
===================================================================
--- grass/trunk/lib/raster/color_hist.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/lib/raster/color_hist.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -40,7 +40,7 @@
 
     Rast_init_colors(colors);
 
-    Rast_str_to_color(DEFAULT_BG_COLOR, &R, &G, &B);
+    G_str_to_color(DEFAULT_BG_COLOR, &R, &G, &B);
     Rast_set_null_value_color(R, G, B, colors);
 
     total = 0;
@@ -108,7 +108,7 @@
 
     Rast_init_colors(colors);
 
-    Rast_str_to_color(DEFAULT_BG_COLOR, &R, &G, &B);
+    G_str_to_color(DEFAULT_BG_COLOR, &R, &G, &B);
     Rast_set_null_value_color(R, G, B, colors);
 
     total = 0;

Deleted: grass/trunk/lib/raster/color_str.c
===================================================================
--- grass/trunk/lib/raster/color_str.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/lib/raster/color_str.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -1,150 +0,0 @@
-/*!
-   \file color_str.c
-
-   \brief Raster library - color management, named color to RGB triplet
-
-   (C) 2001-2008 by 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.
-
-   \author Original author CERL
- */
-
-#include <string.h>
-
-#include <grass/gis.h>
-#include <grass/colors.h>
-
-/* The order in this table is important! It will be indexed by color number */
-static const struct color_rgb standard_colors_rgb[] = {
-    {0, 0, 0},			/* This is a dummy value to make lookup easier */
-    {0, 0, 0},			/* BLACK   */
-    {255, 0, 0},		/* RED     */
-    {0, 255, 0},		/* GREEN   */
-    {0, 0, 255},		/* BLUE    */
-    {255, 255, 0},		/* YELLOW  */
-    {0, 255, 255},		/* CYAN    */
-    {255, 0, 255},		/* MAGENTA */
-    {255, 255, 255},		/* WHITE   */
-    {128, 128, 128},		/* GRAY    */
-    {255, 128, 0},		/* ORANGE  */
-    {100, 128, 255},		/* AQUA    */
-    {0, 128, 255},		/* INDIGO  */
-    {128, 0, 255},		/* VIOLET  */
-    {180, 77, 25}		/* BROWN   */
-};
-
-/* The order in this table has no meaning. */
-static const struct color_name standard_color_names[] = {
-    {"black", BLACK},
-    {"red", RED},
-    {"green", GREEN},
-    {"blue", BLUE},
-    {"yellow", YELLOW},
-    {"cyan", CYAN},
-    {"magenta", MAGENTA},
-    {"white", WHITE},
-    {"grey", GREY},
-    {"gray", GRAY},
-    {"orange", ORANGE},
-    {"aqua", AQUA},
-    {"indigo", INDIGO},
-    {"violet", VIOLET},
-    {"purple", PURPLE},
-    {"brown", BROWN}
-};
-
-/*!
-   \brief Get number of named colors (RGB triplets)
-
-   \return number of colors
- */
-int G_num_standard_colors(void)
-{
-    return sizeof(standard_colors_rgb) / sizeof(standard_colors_rgb[0]);
-}
-
-/*!
-   \brief Get RGB triplet of given color
-
-   \param n color index
- */
-struct color_rgb G_standard_color_rgb(int n)
-{
-    return standard_colors_rgb[n];
-}
-
-/*!
-   \brief Get number of named colors (color names)
-
-   \return number of colors
- */
-int G_num_standard_color_names(void)
-{
-    return sizeof(standard_color_names) / sizeof(standard_color_names[0]);
-}
-
-/*!
-   \brief Get color name
-
-   \param n color index
- */
-const struct color_name *G_standard_color_name(int n)
-{
-    return &standard_color_names[n];
-}
-
-/*! 
-   \brief Parse color string and set red,green,blue
-
-   \param str color string
-   \param[out] red red value
-   \param[out] grn green value
-   \param[out] blu blue value
-
-   \return 1 OK
-   \return 2 NONE 
-   \return 0 on error 
- */
-int Rast_str_to_color(const char *str, int *red, int *grn, int *blu)
-{
-    char buf[100];
-    int num_names = G_num_standard_color_names();
-    int i;
-
-    strcpy(buf, str);
-    G_chop(buf);
-
-    G_debug(3, "Rast_str_to_color(): str = '%s'", buf);
-
-    if (G_strcasecmp(buf, "NONE") == 0)
-	return 2;
-
-    if (sscanf(buf, "%d%*[,:; ]%d%*[,:; ]%d", red, grn, blu) == 3) {
-	if (*red < 0 || *red > 255 ||
-	    *grn < 0 || *grn > 255 || *blu < 0 || *blu > 255)
-	    return 0;
-
-	return 1;
-    }
-
-    /* Look for this color in the standard (preallocated) colors */
-    for (i = 0; i < num_names; i++) {
-	const struct color_name *name = &standard_color_names[i];
-
-	if (G_strcasecmp(buf, name->name) == 0) {
-	    struct color_rgb rgb = standard_colors_rgb[name->number];
-
-	    *red = (int)rgb.r;
-	    *grn = (int)rgb.g;
-	    *blu = (int)rgb.b;
-
-	    return 1;
-	}
-    }
-
-    return 0;
-}

Modified: grass/trunk/ps/ps.map/do_labels.c
===================================================================
--- grass/trunk/ps/ps.map/do_labels.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/do_labels.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -239,7 +239,7 @@
 	}
 
 	if (FIELD("color")) {
-	    ret = Rast_str_to_color(value, &r, &g, &b);
+	    ret = G_str_to_color(value, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&color, r, g, b);
 	    else
@@ -249,7 +249,7 @@
 	}
 
 	if (FIELD("hcolor")) {
-	    ret = Rast_str_to_color(value, &r, &g, &b);
+	    ret = G_str_to_color(value, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&hcolor, r, g, b);
 	    else if (ret == 2)
@@ -280,7 +280,7 @@
 	    /*
 	       if(strncmp(value, "none", 4)==0) opaque = 0;
 	     */
-	    ret = Rast_str_to_color(value, &r, &g, &b);
+	    ret = G_str_to_color(value, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&background, r, g, b);
 	    else if (ret == 2)
@@ -290,7 +290,7 @@
 	}
 
 	if (FIELD("border")) {
-	    ret = Rast_str_to_color(value, &r, &g, &b);
+	    ret = G_str_to_color(value, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&border, r, g, b);
 	    else if (ret == 2)

Modified: grass/trunk/ps/ps.map/main.c
===================================================================
--- grass/trunk/ps/ps.map/main.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/main.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -712,7 +712,7 @@
 	if (KEY("maskcolor")) {
 	    int ret, r, g, b;
 
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1) {
 		PS.mask_r = r / 255.0;
 		PS.mask_g = g / 255.0;

Modified: grass/trunk/ps/ps.map/ps_vareas.c
===================================================================
--- grass/trunk/ps/ps.map/ps_vareas.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/ps_vareas.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -104,7 +104,7 @@
     else {
 	rgbstring = db_get_string(cv_rgb->val.s);
 	if (rgbstring == NULL ||
-	    Rast_str_to_color(rgbstring, &red, &grn, &blu) != 1) {
+	    G_str_to_color(rgbstring, &red, &grn, &blu) != 1) {
 	    G_warning(_("Invalid RGB color definition in column <%s> for category [%d]"),
 		      vector.layer[vec].rgbcol, cat);
 	    rgbstring = NULL;

Modified: grass/trunk/ps/ps.map/ps_vlines.c
===================================================================
--- grass/trunk/ps/ps.map/ps_vlines.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/ps_vlines.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -121,7 +121,7 @@
 	    else {
 		rgbstring = db_get_string(cv_rgb->val.s);
 		if (rgbstring == NULL ||
-		    Rast_str_to_color(rgbstring, &red, &grn, &blu) != 1) {
+		    G_str_to_color(rgbstring, &red, &grn, &blu) != 1) {
 		    G_warning(_("Invalid RGB color definition in column <%s> for category [%d]"),
 			      vector.layer[vec].rgbcol, cat);
 		    rgbstring = NULL;

Modified: grass/trunk/ps/ps.map/ps_vpoints.c
===================================================================
--- grass/trunk/ps/ps.map/ps_vpoints.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/ps_vpoints.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -202,7 +202,7 @@
 	    else {
 		rgbstring = db_get_string(cv_rgb->val.s);
 		if (rgbstring == NULL ||
-		    Rast_str_to_color(rgbstring, &red, &grn, &blu) != 1) {
+		    G_str_to_color(rgbstring, &red, &grn, &blu) != 1) {
 		    G_warning(_("Invalid RGB color definition in column <%s> for category [%d]"),
 			      vector.layer[vec].rgbcol, cat);
 		    rgbstring = NULL;

Modified: grass/trunk/ps/ps.map/r_border.c
===================================================================
--- grass/trunk/ps/ps.map/r_border.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/r_border.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -44,7 +44,7 @@
 	    continue;
 
 	if (KEY("color")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1) {
 		color_R = r / 255.;
 		color_G = g / 255.;

Modified: grass/trunk/ps/ps.map/r_plt.c
===================================================================
--- grass/trunk/ps/ps.map/r_plt.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/r_plt.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -45,7 +45,7 @@
 	    continue;
 	}
 	if (KEY("color")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1) {
 		color_R = r;
 		color_G = g;
@@ -59,7 +59,7 @@
 	    continue;
 	}
 	if (KEY("fcolor")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1) {
 		fcolor_R = r;
 		fcolor_G = g;
@@ -221,7 +221,7 @@
 	}
 
 	if (KEY("color")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1) {
 		color_R = r;
 		color_G = g;
@@ -293,7 +293,7 @@
 	}
 
 	if (KEY("color")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1) {
 		color_R = r;
 		color_G = g;
@@ -308,7 +308,7 @@
 	}
 
 	if (KEY("fcolor")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1) {
 		fcolor_R = r;
 		fcolor_G = g;

Modified: grass/trunk/ps/ps.map/r_text.c
===================================================================
--- grass/trunk/ps/ps.map/r_text.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/r_text.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -98,7 +98,7 @@
 	}
 
 	if (KEY("color")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&color, r, g, b);
 	    else if (ret == 2)
@@ -110,7 +110,7 @@
 	}
 
 	if (KEY("hcolor")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&hcolor, r, g, b);
 	    else if (ret == 2)
@@ -124,7 +124,7 @@
 	}
 
 	if (KEY("background")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&background, r, g, b);
 	    else if (ret == 2) {
@@ -138,7 +138,7 @@
 	}
 
 	if (KEY("border")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&border, r, g, b);
 	    else if (ret == 2)

Modified: grass/trunk/ps/ps.map/r_vareas.c
===================================================================
--- grass/trunk/ps/ps.map/r_vareas.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/r_vareas.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -126,7 +126,7 @@
 	}
 
 	if (KEY("color")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&(vector.layer[vec].color), r, g, b);
 	    else if (ret == 2)
@@ -144,7 +144,7 @@
 	}
 
 	if (KEY("fcolor")) {	/* area color */
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&(vector.layer[vec].fcolor), r, g, b);
 	    else if (ret == 2)

Modified: grass/trunk/ps/ps.map/r_vlines.c
===================================================================
--- grass/trunk/ps/ps.map/r_vlines.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/r_vlines.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -248,7 +248,7 @@
 	}
 
 	if (KEY("color")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&(vector.layer[vec].color), r, g, b);
 	    else if (ret == 2)
@@ -266,7 +266,7 @@
 	}
 
 	if (KEY("hcolor")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&(vector.layer[vec].hcolor), r, g, b);
 	    else if (ret == 2)

Modified: grass/trunk/ps/ps.map/r_vpoints.c
===================================================================
--- grass/trunk/ps/ps.map/r_vpoints.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/r_vpoints.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -149,7 +149,7 @@
 	}
 
 	if (KEY("color")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&(vector.layer[vec].color), r, g, b);
 	    else if (ret == 2)
@@ -161,7 +161,7 @@
 	}
 
 	if (KEY("fcolor")) {	/* fill color */
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1)
 		set_color(&(vector.layer[vec].fcolor), r, g, b);
 	    else if (ret == 2)

Modified: grass/trunk/ps/ps.map/r_wind.c
===================================================================
--- grass/trunk/ps/ps.map/r_wind.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/ps/ps.map/r_wind.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -54,7 +54,7 @@
 
 
 	if (KEY("color")) {
-	    ret = Rast_str_to_color(data, &r, &g, &b);
+	    ret = G_str_to_color(data, &r, &g, &b);
 	    if (ret == 1) {
 		color_R = r;
 		color_G = g;

Modified: grass/trunk/vector/v.to.rast/support.c
===================================================================
--- grass/trunk/vector/v.to.rast/support.c	2009-06-24 21:14:16 UTC (rev 38068)
+++ grass/trunk/vector/v.to.rast/support.c	2009-06-25 08:27:18 UTC (rev 38069)
@@ -163,7 +163,7 @@
 	if (*colorstring != '\0') {
 	    G_debug(3, "element colorstring: %s", colorstring);
 
-	    if (Rast_str_to_color(colorstring, &red, &grn, &blu) == 1) {
+	    if (G_str_to_color(colorstring, &red, &grn, &blu) == 1) {
 		G_debug(3, "cat %d r:%d g:%d b:%d", cat, red, grn, blu);
 	    }
 	    else {



More information about the grass-commit mailing list