>>>>> Hamish  <[EMAIL PROTECTED]> writes:

[...]

 > RGBA_Color was recently added (as was RGB support for modules' CLI
 > options) so 1) it could be used to pass RGB arround without having to
 > call the display library and 2) we could handle a color value of
 > 'none' without needing to pass a separate variable or rely on the
 > palette index number set to -1. Currently the alpha channel is just
 > set to 0 or 255 for full-transparency ('none') or full-opacity.

        Could the attached (untested) patch be of any help?

diff --git a/display/d.extract/extract.c b/display/d.extract/extract.c
index b3a3205..52fa478 100644
--- a/display/d.extract/extract.c
+++ b/display/d.extract/extract.c
@@ -16,9 +16,13 @@
 #define M_DEL   3
 #define M_END   4
 
-int display ( struct Map_info *Map, struct ilist *List, const struct color_rgb *color );
+static int display (struct Map_info *Map, struct ilist *List,
+		    const struct RGBA_Color *color);
 
-int extract ( struct Map_info *In, struct Map_info *Out, int type, const struct color_rgb *color, const struct color_rgb *hcolor )
+int
+extract (struct Map_info *In, struct Map_info *Out, int type,
+	 const struct RGBA_Color *color,
+	 const struct RGBA_Color *hcolor)
 {
     int i, button, mode, line;
     int screen_x, screen_y, cur_screen_x, cur_screen_y;
@@ -105,8 +109,9 @@ int extract ( struct Map_info *In, struct Map_info *Out, int type, const struct
     return 1;
 }
 
-int 
-display ( struct Map_info *Map, struct ilist *List, const struct color_rgb *color )
+static int
+display (struct Map_info *Map, struct ilist *List,
+         const struct RGBA_Color *color)
 {
     int i, j, line, type;
     struct line_pnts *Points;
@@ -116,7 +121,7 @@ display ( struct Map_info *Map, struct ilist *List, const struct color_rgb *colo
     G_debug (1, "msize = %f\n", msize);
     
     Points = Vect_new_line_struct ();
-    R_RGB_color(color->r, color->g, color->b);
+    R_RGBA_color (color);
 
     for ( i = 0; i < List->n_values; i++ ) {
         line = abs(List->value[i]);
diff --git a/display/d.extract/main.c b/display/d.extract/main.c
index ee06c18..cffb769 100644
--- a/display/d.extract/main.c
+++ b/display/d.extract/main.c
@@ -25,7 +25,8 @@
 #include <grass/dbmi.h>
 #include <grass/glocale.h>
 
-int extract(struct Map_info *, struct Map_info *, int, const struct color_rgb *, const struct color_rgb *);
+int extract (struct Map_info *, struct Map_info *, int,
+	     const struct RGBA_Color *, const struct RGBA_Color *);
 
 int main(int argc, char **argv)
 {
@@ -35,7 +36,7 @@ int main(int argc, char **argv)
     char *mapset;
     struct Map_info In, Out;
     int type;
-    struct color_rgb color, hcolor;
+    struct RGBA_Color color, hcolor;
     int r, g, b;
     struct field_info *Fi, *Fin;
     int i, n, tbtype, ret;
@@ -76,19 +77,12 @@ int main(int argc, char **argv)
     if (R_open_driver() != 0)
 	G_fatal_error(_("No graphics device selected"));
 
-    color = G_standard_color_rgb(BLACK);
-    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 (G_str_to_color(hcolor_opt->answer, &r, &g, &b)) {
-	hcolor.r = r;
-	hcolor.g = g;
-	hcolor.b = b;
-    }
+    G_rgba_color_standard (&color,      BLACK);
+    G_rgba_color_standard (&hcolor,     RED);
+
+    /* FIXME: watch out for NONEs here! */
+    G_rgba_color_parse    (&color,      color_opt->answer);
+    G_rgba_color_parse    (&hcolor,     hcolor_opt->answer);
 
     mapset = G_find_vector2(input->answer, NULL);
 
diff --git a/display/d.path/main.c b/display/d.path/main.c
index bf35b47..32d0d30 100644
--- a/display/d.path/main.c
+++ b/display/d.path/main.c
@@ -36,7 +36,7 @@ int main(int argc, char **argv)
     char   *mapset;
     struct Map_info Map;
     int    type, afield, nfield, geo;
-    struct color_rgb color, hcolor, bgcolor;
+    struct RGBA_Color color, hcolor, bgcolor;
     int    r, g, b;
     int    use_mouse;
     double x1,y1,x2,y2;
@@ -157,26 +157,14 @@ int main(int argc, char **argv)
     if (R_open_driver() != 0)
        G_fatal_error (_("No graphics device selected"));
 
-    color = G_standard_color_rgb(BLACK);
-    if ( G_str_to_color(color_opt->answer, &r, &g, &b) ) {
-	color.r = r;
-	color.g = g;
-	color.b = b;
-    }
+    G_rgba_color_standard (&color,      BLACK);
+    G_rgba_color_standard (&hcolor,     RED);
+    G_rgba_color_standard (&bgcolor,    WHITE);
 
-    hcolor = G_standard_color_rgb(RED);
-    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 ( G_str_to_color(bgcolor_opt->answer, &r, &g, &b) ) {
-	bgcolor.r = r;
-	bgcolor.g = g;
-	bgcolor.b = b;
-    }
+    /* FIXME: watch out for NONEs here! */
+    G_rgba_color_parse    (&color,      color_opt->answer);
+    G_rgba_color_parse    (&hcolor,     hcolor_opt->answer);
+    G_rgba_color_parse    (&bgcolor,    bgcolor_opt->answer);
 
     if ( geo_f->answer ) 
     {
diff --git a/display/d.path/proto.h b/display/d.path/proto.h
index 0260e9a..6cfcec0 100644
--- a/display/d.path/proto.h
+++ b/display/d.path/proto.h
@@ -1,5 +1,9 @@
-int path(  struct Map_info *, const struct color_rgb *,
-	   const struct color_rgb *, const struct color_rgb *, int );
+int path (struct Map_info *,
+	  const struct RGBA_Color *,
+	  const struct RGBA_Color *,
+	  const struct RGBA_Color *,
+	  int);
 
-int coor_path(  struct Map_info *, const struct color_rgb *, int,
-		double, double, double, double );
+int coor_path (struct Map_info *,
+	       const struct RGBA_Color *,
+	       int, double, double, double, double);
diff --git a/display/d.path/select.c b/display/d.path/select.c
index 0ceac92..e685b48 100644
--- a/display/d.path/select.c
+++ b/display/d.path/select.c
@@ -12,12 +12,15 @@
 
 #define WDTH 5
 
-int display ( struct Map_info *Map, struct line_pnts *,
-	      const struct color_rgb *, int, int, int );
-
-int path ( struct Map_info *Map, const struct color_rgb *color,
-	   const struct color_rgb *hcolor, const struct color_rgb *bgcolor,
-	   int be_bold )
+static int display (struct Map_info *Map, struct line_pnts *,
+		    const struct RGBA_Color *, int, int, int);
+
+int
+path (struct Map_info *Map,
+      const struct RGBA_Color *color,
+      const struct RGBA_Color *hcolor, 
+      const struct RGBA_Color *bgcolor,
+      int be_bold)
 {
     int button, ret;
     int screen_x, screen_y ;
@@ -68,7 +71,7 @@ int path ( struct Map_info *Map, const struct color_rgb *color,
 	    
             display ( Map, Points, color, from_node, to_node, be_bold );
 		
-	    R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
+	    R_RGBA_color (bgcolor);
 	    if ( !from_node ) 
 	        G_plot_line(Points->x[0], Points->y[0], Points->x[1], Points->y[1]);
 
@@ -80,7 +83,7 @@ int path ( struct Map_info *Map, const struct color_rgb *color,
 	switch ( button )	{
 	    case 1:
 		if ( from_disp ) {
-		    R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
+		    R_RGBA_color (bgcolor);
 		    G_plot_icon( fx, fy, G_ICON_BOX, 0.0, msize);
                 }
 		if ( node > 0 ) {
@@ -92,14 +95,14 @@ int path ( struct Map_info *Map, const struct color_rgb *color,
 		    fy = y;
 		    from_node = 0;
 		}
-		R_RGB_color(hcolor->r, hcolor->g, hcolor->b);
+		R_RGBA_color (hcolor);
 		G_plot_icon( fx, fy, G_ICON_BOX, 0.0, msize);
 		R_flush();
 		from_disp = 1;
 	        break;
 	    case 2:
 		if ( to_disp ) {
-		    R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
+		    R_RGBA_color (bgcolor);
 		    G_plot_icon( tx, ty, G_ICON_CROSS, 0.0, msize);
                 }
 		if ( node > 0 ) {
@@ -111,18 +114,18 @@ int path ( struct Map_info *Map, const struct color_rgb *color,
 		    ty = y;
 		    to_node = 0;
 		}
-		R_RGB_color(hcolor->r, hcolor->g, hcolor->b);
+		R_RGBA_color (hcolor);
 		G_plot_icon( tx, ty, G_ICON_CROSS, 0.0, msize);
 		R_flush();
 		to_disp = 1;
 	        break;
 	    case 3:
 		if ( from_disp ) {
-		    R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
+		    R_RGBA_color (bgcolor);
 		    G_plot_icon( fx, fy, G_ICON_BOX, 0.0, msize);
 		}
 		if ( to_disp ) {
-		    R_RGB_color(bgcolor->r, bgcolor->g, bgcolor->b);
+		    R_RGBA_color (bgcolor);
 		    G_plot_icon( tx, ty, G_ICON_CROSS, 0.0, msize);
 		}
 	        return 1;
@@ -156,12 +159,13 @@ int path ( struct Map_info *Map, const struct color_rgb *color,
 }
 
 
-int display ( struct Map_info *Map, struct line_pnts *Points,
-	      const struct color_rgb *color, int first, int last, int be_bold )
+static int
+display (struct Map_info *Map, struct line_pnts *Points,
+	 const struct RGBA_Color *color, int first, int last, int be_bold)
 {
     int i, from, to;
 
-    R_RGB_color(color->r, color->g, color->b);
+    R_RGBA_color (color);
 
     if ( first ) from = 0; else from = 1;
     if ( last ) to = Points->n_points; else to = Points->n_points - 1;
@@ -180,9 +184,12 @@ int display ( struct Map_info *Map, struct line_pnts *Points,
 
 /* Same as path() but get start/stop from the command line (for non-interactive use)
     Hamish Bowman March 2007 */
-int coor_path ( struct Map_info *Map, const struct color_rgb *hcolor,
-		int be_bold, double start_x, double start_y,
-		double end_x, double end_y )
+int
+coor_path (struct Map_info *Map,
+	   const struct RGBA_Color *hcolor,
+	   int be_bold,
+	   double start_x, double start_y,
+	   double end_x,   double end_y)
 {
     int ret;
     double nx, ny, fx, fy, tx, ty, msize, maxdist;
@@ -227,7 +234,7 @@ int coor_path ( struct Map_info *Map, const struct color_rgb *hcolor,
 	fx = start_x;
 	fy = start_y;
     }
-    R_RGB_color(hcolor->r, hcolor->g, hcolor->b);
+    R_RGBA_color (hcolor);
     G_plot_icon( fx, fy, G_ICON_BOX, 0.0, msize);
 
 
@@ -243,7 +250,7 @@ int coor_path ( struct Map_info *Map, const struct color_rgb *hcolor,
 	tx = end_x;
 	ty = end_y;
     }
-    R_RGB_color(hcolor->r, hcolor->g, hcolor->b);
+    R_RGBA_color (hcolor);
     G_plot_icon( tx, ty, G_ICON_CROSS, 0.0, msize);
 
 
diff --git a/display/d.vect/area.c b/display/d.vect/area.c
index 929892c..51ece73 100644
--- a/display/d.vect/area.c
+++ b/display/d.vect/area.c
@@ -13,12 +13,14 @@
 #include "plot.h"
 #include "local_proto.h"
 
-int darea ( struct Map_info *Map, struct cat_list *Clist,
-	    const struct color_rgb *bcolor, const struct color_rgb *fcolor, 
-	    int chcat, int id_flag, int table_colors_flag, int cats_color_flag,
-	    struct Cell_head *window, char *rgb_column, int default_width,
-	    char *width_column, double width_scale) {
-
+int
+darea (struct Map_info *Map, struct cat_list *Clist,
+       const struct RGBA_Color *bcolor,
+       const struct RGBA_Color *fcolor,
+       int chcat, int id_flag, int table_colors_flag, int cats_color_flag,
+       struct Cell_head *window, char *rgb_column, int default_width,
+       char *width_column, double width_scale)
+{
     int    num, area, isle, n_isles, n_points;
     double xl, yl;
     struct line_pnts *Points, *IPoints;
@@ -307,7 +309,7 @@ int darea ( struct Map_info *Map, struct cat_list *Clist,
 
 	if ( fcolor ) {
 	  if (!table_colors_flag && !cats_color_flag) {
-	    R_RGB_color(fcolor->r, fcolor->g, fcolor->b);
+	    R_RGBA_color (fcolor);
 	    plot_polygon ( Points->x, Points->y, Points->n_points);
 	  }
 	  else {
@@ -315,7 +317,7 @@ int darea ( struct Map_info *Map, struct cat_list *Clist,
 	      R_RGB_color ((unsigned char) red, (unsigned char) grn, (unsigned char) blu);
 	    }
 	    else {
-	      R_RGB_color(fcolor->r, fcolor->g, fcolor->b);
+	      R_RGBA_color (fcolor);
 	    }
 	    if (cat >= 0) {
 	      plot_polygon ( Points->x, Points->y, Points->n_points);
@@ -331,7 +333,7 @@ int darea ( struct Map_info *Map, struct cat_list *Clist,
 	      R_RGB_color ((unsigned char) red, (unsigned char) grn, (unsigned char) blu);
 	    }
 	    else {
-	      R_RGB_color(bcolor->r, bcolor->g, bcolor->b);
+	      R_RGBA_color (bcolor);
 	    }
 	    /*use different user defined render methods*/
 	    plot_polyline ( Points->x, Points->y, Points->n_points);
diff --git a/display/d.vect/local_proto.h b/display/d.vect/local_proto.h
index e950dca..4a438c0 100644
--- a/display/d.vect/local_proto.h
+++ b/display/d.vect/local_proto.h
@@ -3,11 +3,17 @@
 
 FILE *open_vect(char *, char *);
 int close_vect(FILE *);
-int plot1(struct Map_info *, int, int, struct cat_list *, const struct color_rgb *, const struct color_rgb *, int, SYMBOL *, int, int, int, int, char *, int, char *, double);
+int plot1 (struct Map_info *, int, int, struct cat_list *,
+	   const struct RGBA_Color *, const struct RGBA_Color *,
+	   int, SYMBOL *, int, int, int, int,
+	   char *, int, char *, double);
 int label(struct Map_info *, int, int, struct cat_list *, LATTR *, int);
 int topo(struct Map_info *, int, int, LATTR *);
 int dir(struct Map_info *, int, struct cat_list *, int);
-int darea(struct Map_info *, struct cat_list *, const struct color_rgb *, const struct color_rgb *, int, int, int, int, struct Cell_head *, char *, int, char *, double);
+int darea (struct Map_info *, struct cat_list *,
+	   const struct RGBA_Color *, const struct RGBA_Color *,
+	   int, int, int, int, struct Cell_head *,
+	   char *, int, char *, double);
 int attr(struct Map_info *, int, char *, struct cat_list *, LATTR *, int);
 int zcoor(struct Map_info *, int, LATTR *);
 int test_bg_color (const char*);
diff --git a/display/d.vect/main.c b/display/d.vect/main.c
index 0da0235..06498f0 100644
--- a/display/d.vect/main.c
+++ b/display/d.vect/main.c
@@ -28,6 +28,16 @@
 #include "plot.h"
 #include "local_proto.h"
 
+/* consider this one for inclusion into a library? */
+static void
+p_arg_color (struct RGBA_Color *colorp, const char *s)
+{
+    if (G_rgba_color_parse (colorp, s) < 0) {
+	/* . */
+	G_fatal_error (_("Unknown color: [%s]"), s);
+    }
+}
+
 /* adopted from r.colors */
 static char *icon_files(void)
 {
@@ -85,8 +95,7 @@ main (int argc, char **argv)
 	int i, stat = 0, type, area, display;
 	int chcat = 0;
 	int r, g, b;
-	int has_color, has_fcolor;
-	struct color_rgb color, fcolor;
+	struct RGBA_Color color, fcolor;
 	int size;
 	int default_width;
 	double width_scale;
@@ -412,31 +421,12 @@ main (int argc, char **argv)
 			 "the '-c' flag will be ignored!"));
  	}
 
-	color = G_standard_color_rgb(WHITE);
-	ret =  G_str_to_color(color_opt->answer, &r, &g, &b);
-	if ( ret == 1 ) {
-	    has_color = 1;
-	    color.r = r;
-	    color.g = g;
-	    color.b = b;
-	} else if ( ret == 2 ) { /* none */
-	    has_color = 0;
-	} else if ( ret == 0 ) { /* error */
-	    G_fatal_error(_("Unknown color: [%s]"), color_opt->answer);
-	}
-	
-	fcolor = G_standard_color_rgb(WHITE);
-	ret = G_str_to_color(fcolor_opt->answer, &r, &g, &b);
-        if ( ret == 1 ) {
-	    has_fcolor = 1;
-	    fcolor.r = r;
-	    fcolor.g = g;
-	    fcolor.b = b;
-	} else if ( ret == 2 ) { /* none */
-	    has_fcolor = 0;
-	} else if ( ret == 0 ) { /* error */
-	    G_fatal_error(_("Unknown color: [%s]"), fcolor_opt->answer);
-	}
+	G_rgba_color_standard (&color,  WHITE);
+	G_rgba_color_standard (&fcolor, WHITE);
+
+	/* NB: NONEs are handled by the functions to be called */
+	p_arg_color           (&color,  color_opt->answer)
+	p_arg_color           (&fcolor, fcolor_opt->answer)
 
 	size = atoi (size_opt->answer);
 	Symb = S_read ( icon_opt->answer );
@@ -486,6 +476,7 @@ main (int argc, char **argv)
         else
 	if (cat_opt->answer)
 	  {
+	    int ret;
 	    if ( Clist->field < 1 )
 		G_fatal_error(_("'layer' must be > 0 for 'cats'."));
 	    chcat = 1;  
@@ -636,8 +627,8 @@ main (int argc, char **argv)
 
 	    if ( area ) {
 		if ( level >= 2 ) {
-		    stat = darea ( &Map, Clist,
-			has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat,
+		    stat = darea (
+			&Map, Clist, &color, &fcolor, chcat,
 			(int) id_flag->answer, table_acolors_flag->answer,
 			cats_acolors_flag->answer, &window, rgbcol_opt->answer,
 			default_width, wcolumn_opt->answer, width_scale );
@@ -651,8 +642,9 @@ main (int argc, char **argv)
 		if ( id_flag->answer && level < 2 ) {
 		    G_warning(_("Cannot display lines by id, topology not available"));
 		} else {
-		    stat = plot1 ( &Map, type, area, Clist,
-			has_color ? &color : NULL, has_fcolor ? &fcolor : NULL, chcat, Symb,
+		    stat = plot1 (
+			&Map, type, area, Clist, &color, &fcolor, chcat,
+			Symb,
 			size, (int) id_flag->answer, table_acolors_flag->answer,
 			cats_acolors_flag->answer, rgbcol_opt->answer, default_width,
 			wcolumn_opt->answer, width_scale) ;
@@ -661,8 +653,8 @@ main (int argc, char **argv)
 		}
 	    }
 
-	    if ( has_color ) {
-		R_RGB_color(color.r, color.g, color.b);
+	    if (color.a != RGBA_COLOR_NONE) {
+		R_RGBA_color (&color);
 		if ( display & DISP_DIR )
 		    stat = dir ( &Map, type, Clist, chcat );
 	    }
diff --git a/display/d.vect/plot1.c b/display/d.vect/plot1.c
index 0208935..b5167c4 100644
--- a/display/d.vect/plot1.c
+++ b/display/d.vect/plot1.c
@@ -14,6 +14,8 @@
 #define RENDER_POLYLINE 0
 #define RENDER_POLYGON  1
 
+#define COPY_ARY(d, s, c) (memcpy ((d), (s), (c) * sizeof (*(d))))
+
 int palette_ncolors = 16;
 
 struct rgb_color palette[16] =  {
@@ -130,12 +132,12 @@ void plot_polygon(double *xf, double *yf, int n)
 /* *************************************************************** */
 /* *************************************************************** */
 /* *************************************************************** */
-int plot1 (
-    struct Map_info *Map, int type, int area,  struct cat_list *Clist,
-    const struct color_rgb *color, const struct color_rgb *fcolor,
-    int chcat, SYMBOL *Symb, int size, int id_flag,
-    int table_colors_flag, int cats_color_flag, char *rgb_column,
-    int default_width, char *width_column, double width_scale)
+int
+plot1 (struct Map_info *Map, int type, int area, struct cat_list *Clist,
+       const struct RGBA_Color *color, const struct RGBA_Color *fcolor,
+       int chcat, SYMBOL *Symb, int size, int id_flag,
+       int table_colors_flag, int cats_color_flag, char *rgb_column,
+       int default_width, char *width_column, double width_scale)
 {
     int i, ltype, nlines = 0, line, cat = -1;
     double *x, *y;
@@ -158,28 +160,20 @@ int plot1 (
     unsigned char which;
     int width;
 
+    /* BTW, why to G_malloc () these? */
     line_color = G_malloc(sizeof(RGBA_Color));
     fill_color = G_malloc(sizeof(RGBA_Color));
     primary_color = G_malloc(sizeof(RGBA_Color));
 
     primary_color->a = RGBA_COLOR_OPAQUE;
 
-/* change function prototype to pass RGBA_Color instead of color_rgb? */
-    if(color) {
-	line_color->r = color->r;
-	line_color->g = color->g;
-	line_color->b = color->b;
-	line_color->a = RGBA_COLOR_OPAQUE;
-    }
+    if (color)
+	COPY_ARY (line_color, color, 1);
     else
 	line_color->a = RGBA_COLOR_NONE;
 
-    if(fcolor) {
-	fill_color->r = fcolor->r;
-	fill_color->g = fcolor->g;
-	fill_color->b = fcolor->b;
-	fill_color->a = RGBA_COLOR_OPAQUE;
-    }
+    if (fcolor)
+	COPY_ARY (fill_color, fcolor, 1);
     else
 	fill_color->a = RGBA_COLOR_NONE;
 
@@ -265,7 +259,7 @@ int plot1 (
     /* Is it necessary to reset line/label color in each loop ? */
 
     if ( color && !table_colors_flag && !cats_color_flag)
-	R_RGB_color(color->r, color->g, color->b);
+	R_RGBA_color (color);
 
     if ( Vect_level ( Map ) >= 2 )
 	nlines = Vect_get_num_lines ( Map );
@@ -460,12 +454,12 @@ int plot1 (
 
 	} else if (color || custom_rgb) {
 	    if (!table_colors_flag && !cats_color_flag)
-		R_RGB_color(color->r, color->g, color->b);
+		R_RGBA_color (color);
 	    else {
 		if (custom_rgb)
 		    R_RGB_color((unsigned char)red, (unsigned char)grn, (unsigned char)blu);
 		else
-		    R_RGB_color(color->r, color->g, color->b);
+		    R_RGBA_color (color);
 	    }
 
 	    /* Plot the lines */
diff --git a/imagery/i.vpoints/plot.c b/imagery/i.vpoints/plot.c
index fa1fbb9..03310c8 100644
--- a/imagery/i.vpoints/plot.c
+++ b/imagery/i.vpoints/plot.c
@@ -21,7 +21,6 @@ int plot (char *name, char *mapset, struct line_pnts *Points)
     struct Map_info P_map;
     SYMBOL *Symb;
     RGBA_Color *linecolor_rgb, *fillcolor_rgb;
-    struct color_rgb rgb;
     int ix, iy;
 
     Vect_set_open_level (2);
@@ -43,11 +42,7 @@ int plot (char *name, char *mapset, struct line_pnts *Points)
     linecolor_rgb = G_malloc(sizeof(RGB_Color));
     fillcolor_rgb = G_malloc(sizeof(RGB_Color));
 
-    rgb = G_standard_color_rgb(line_color);
-    linecolor_rgb->r = rgb.r;
-    linecolor_rgb->g = rgb.g;
-    linecolor_rgb->b = rgb.b;
-    linecolor_rgb->a = RGBA_COLOR_OPAQUE;
+    G_rgba_color_standard (linecolor_rgb, line_color);
     fillcolor_rgb->a = RGBA_COLOR_NONE;
 
 
@@ -104,7 +99,6 @@ int plot_warp(char *name, char *mapset, struct line_pnts *Points,
     struct Map_info P_map;
     SYMBOL *Symb;
     RGBA_Color *linecolor_rgb, *fillcolor_rgb;
-    struct color_rgb rgb;
     int ix, iy;
 
     Vect_set_open_level (2);
@@ -126,11 +120,7 @@ int plot_warp(char *name, char *mapset, struct line_pnts *Points,
     linecolor_rgb = G_malloc(sizeof(RGB_Color));
     fillcolor_rgb = G_malloc(sizeof(RGB_Color));
 
-    rgb = G_standard_color_rgb(line_color);
-    linecolor_rgb->r = rgb.r;
-    linecolor_rgb->g = rgb.g;
-    linecolor_rgb->b = rgb.b;
-    linecolor_rgb->a = RGBA_COLOR_OPAQUE;
+    G_rgba_color_standard (linecolor_rgb, line_color);
     fillcolor_rgb->a = RGBA_COLOR_NONE;
 
 
diff --git a/include/colors.h b/include/colors.h
index c7c45c5..6bd3f15 100644
--- a/include/colors.h
+++ b/include/colors.h
@@ -43,6 +43,8 @@ extern int G_num_standard_colors(void);
 extern struct color_rgb G_standard_color_rgb(int n);
 extern int G_num_standard_color_names(void);
 extern const struct color_name *G_standard_color_name(int n);
+extern void G_rgba_color_standard (struct RGBA_Color *colorp, int i);
+extern int  G_rgba_color_parse (struct RGBA_Color *colorp, const char *s);
 
 #endif 
 
diff --git a/include/raster.h b/include/raster.h
index f33a358..4a0aa57 100644
--- a/include/raster.h
+++ b/include/raster.h
@@ -1,6 +1,7 @@
 #ifndef _GRASS_RASTER_H
 #define _GRASS_RASTER_H
 
+#include <grass/colors.h>	/* for struct RGBA_Color */
 #include <grass/monitors.h>
 
 /* common.c */
@@ -66,6 +67,7 @@ void R_get_num_colors(int *);
 
 void R_standard_color(int);
 void R_RGB_color(unsigned char,unsigned char,unsigned char);
+void R_RGBA_color (const struct RGBA_Color *);
 
 void R_line_width(int);
 void R_erase(void);
diff --git a/lib/display/tran_colr.c b/lib/display/tran_colr.c
index c9342f5..8d424ea 100644
--- a/lib/display/tran_colr.c
+++ b/lib/display/tran_colr.c
@@ -8,10 +8,13 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-static struct color_rgb *colors;
+static struct RGBA_Color *colors;
 static int ncolors;
 static int nalloc;
 
+#define MALLOC_ARY(p, c)  ((p) = G_malloc       ((c) * sizeof (*(p))))
+#define REALLOC_ARY(p, c) ((p) = G_realloc ((p), (c) * sizeof (*(p))))
+
 /*!
  * \brief color name to number
  *
@@ -76,7 +79,7 @@ static int translate_or_add_color(const char *str)
     {
 	ncolors = G_num_standard_colors();
 	nalloc = 2 * ncolors;
-	colors = G_malloc(nalloc * sizeof(struct color_rgb));
+	MALLOC_ARY (colors, nalloc);
 	for (i = 0; i < ncolors; i++)
 	    colors[i] = G_standard_color_rgb(i);
     }
@@ -99,14 +102,17 @@ static int translate_or_add_color(const char *str)
     if (ncolors >= nalloc)
     {
 	nalloc *= 2;
-	colors = G_realloc(colors, nalloc * sizeof(struct color_rgb));
+	REALLOC_ARY (colors, nalloc);
     }
 
     index = ncolors++;
-
-    colors[index].r = red;
-    colors[index].g = grn;
-    colors[index].b = blu;
+    {
+      struct RGBA_Color *p = colors + index;
+      p->r = red;
+      p->g = grn;
+      p->b = blu;
+      p->a = RGBA_COLOR_OPAQUE;
+    }
 
     return index;
 }
@@ -159,7 +165,7 @@ int D_raster_use_color(int color)
 
     if (color < ncolors)
     {
-	const struct color_rgb *c = &colors[color];
+	const struct RGBA_Color *c = &colors[color];
 	R_RGB_color(c->r, c->g, c->b);
 	return 1;
     }
diff --git a/lib/driver/Color.c b/lib/driver/Color.c
index fcdedfc..e1b7921 100644
--- a/lib/driver/Color.c
+++ b/lib/driver/Color.c
@@ -23,12 +23,13 @@ void COM_Color_RGB(unsigned char r, unsigned char g, unsigned char b)
 
 void COM_Standard_color(int number)
 {
-	struct color_rgb rgb;
+	struct RGBA_Color rgba;
 
-	if (number < 0 || number >= G_num_standard_colors())
+	if (G_rgba_color_standard (&color, number) != 0) {
+		/* . */
 		return;
+	}
 
-	rgb = G_standard_color_rgb(number);
-	COM_Color_RGB(rgb.r, rgb.g, rgb.b);
+	COM_Color_RGB (rgba.r, rgba.g, rgba.b);
 }
 
diff --git a/lib/gis/color_str.c b/lib/gis/color_str.c
index 5521d71..ed617a8 100644
--- a/lib/gis/color_str.c
+++ b/lib/gis/color_str.c
@@ -2,6 +2,8 @@
 #include <grass/gis.h>
 #include <grass/colors.h>
 
+#define COPY_ARY(d, s, c) (memcpy ((d), (s), (c) * sizeof (*(d))))
+
 /* The order in this table is important! It will be indexed by color number */
 static const struct color_rgb standard_colors_rgb[] =
 {
@@ -53,6 +55,25 @@ struct color_rgb G_standard_color_rgb(int n)
     return standard_colors_rgb[n];
 }
 
+int
+G_rgba_color_standard (int i, struct RGBA_Color *colorp)
+{
+    struct color_rgb *p = standard_colors_rgb + i;
+
+    if (i < 0 || i >= G_num_standard_colors ()) {
+	/* . */
+	return -1;
+    }
+
+    colorp->r = p->r;
+    colorp->g = p->g;
+    colorp->b = p->b;
+    colorp->a = RGBA_COLOR_OPAQUE;
+
+    /* . */
+    return 0;
+}
+
 int G_num_standard_color_names(void)
 {
     return sizeof(standard_color_names) / sizeof(standard_color_names[0]);
@@ -115,3 +136,25 @@ int G_str_to_color(const char *str, int *red, int *grn, int *blu)
     return 0;
 }
 
+int
+G_rgba_color_parse (struct RGBA_Color *colorp, const char *s)
+{
+    /* returns: -1 on error */
+    /*           0 on success, real color */
+    /*          +1 on NONE */
+    struct RGBA_Color bs;
+    int rv;
+
+    rv = G_str_to_color (s, &(bs.r), &(bs.g), &(bs.b));
+    if (rv != 1 && rv != 2) {
+	/* an error */
+	/* . */
+	return -1;
+    }
+    bs->a = (rv == 2 ? RGBA_COLOR_NONE : RGBA_COLOR_OPAQUE);
+
+    COPY_ARY (colorp, &bs, 1);
+
+    /* . */
+    return (rv == 2 ? 1 : 0);
+}
diff --git a/lib/raster/com_proto.c b/lib/raster/com_proto.c
index 811f50c..1205fd6 100644
--- a/lib/raster/com_proto.c
+++ b/lib/raster/com_proto.c
@@ -112,6 +112,17 @@ void R_RGB_color(unsigned char red, unsigned char grn, unsigned char blu)
 }
 
 /*!
+ * \brief select color
+ *
+ * Behaves like R_RGB_color, but operates on a pointer to a const struct
+ * RGBA_Color value.
+ */
+void R_RGBA_color (const struct RGBA_Color *colorp)
+{
+	trans->RGB_color (colorp->r, colorp->g, colorp->b);
+}
+
+/*!
  * \brief change the width of line
  *
  * Changes the <b>width</b> of line to be used in subsequent draw commands.
_______________________________________________
grass-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/grass-dev

Reply via email to