[GRASS-SVN] r29944 - in grass/trunk: display/d.grid include lib/display

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Feb 4 03:19:17 EST 2008


Author: hamish
Date: 2008-02-04 03:19:15 -0500 (Mon, 04 Feb 2008)
New Revision: 29944

Modified:
   grass/trunk/display/d.grid/fiducial.c
   grass/trunk/include/display.h
   grass/trunk/lib/display/tran_colr.c
Log:
add D_color_number_to_RGB(), enable color change for d.grid -f,-c

Modified: grass/trunk/display/d.grid/fiducial.c
===================================================================
--- grass/trunk/display/d.grid/fiducial.c	2008-02-04 06:45:47 UTC (rev 29943)
+++ grass/trunk/display/d.grid/fiducial.c	2008-02-04 08:19:15 UTC (rev 29944)
@@ -33,8 +33,10 @@
     line_color = G_malloc(sizeof(RGBA_Color));
     fill_color = G_malloc(sizeof(RGBA_Color));
 
-    /* TODO: color->RGB values, for now just use DEFAULT_FG_COLOR */
-    G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
+    if( D_color_number_to_RGB(color, &R, &G, &B) == 0 )
+	/* fall back to black on failure */
+	G_str_to_color(DEFAULT_FG_COLOR, &R, &G, &B);
+
     line_color->r = (unsigned char) R;
     line_color->g = (unsigned char) G;
     line_color->b = (unsigned char) B;

Modified: grass/trunk/include/display.h
===================================================================
--- grass/trunk/include/display.h	2008-02-04 06:45:47 UTC (rev 29943)
+++ grass/trunk/include/display.h	2008-02-04 08:19:15 UTC (rev 29944)
@@ -125,6 +125,7 @@
 int D_allocate_color(void);
 int D_parse_color(const char *, int);
 int D_raster_use_color(int);
+int D_color_number_to_RGB(int, int *, int *, int *);
 
 /* window.c */
 int D_new_window(char *, int, int, int, int);

Modified: grass/trunk/lib/display/tran_colr.c
===================================================================
--- grass/trunk/lib/display/tran_colr.c	2008-02-04 06:45:47 UTC (rev 29943)
+++ grass/trunk/lib/display/tran_colr.c	2008-02-04 08:19:15 UTC (rev 29944)
@@ -166,3 +166,47 @@
 
     return 0;
 }
+
+
+/*!
+ * \brief get RGB values from color number
+ *
+ * Translates the color number provided by D_parse_color
+ * into 0-255 RGB values.
+ *
+ * Returns 1 if color can be used to draw (is good and
+ * isn't 'none'), 0 otherwise.
+ *
+ *  \param color_number
+ *  \param red
+ *  \param green
+ *  \param blue
+ *
+ *  \return int
+ */
+int D_color_number_to_RGB(int color, int *r, int *g, int *b)
+{
+    const struct color_rgb *c;
+
+    if (color <= 0)
+	return 0;
+
+    if (color < G_num_standard_colors()) {
+	struct color_rgb col = G_standard_color_rgb(color);
+	if(r) *r = col.r;
+	if(g) *g = col.g;
+	if(b) *b = col.b;
+
+	return 1;
+    }
+
+    if (color >= ncolors)
+	return 0;
+
+    c = &colors[color];
+    if(r) *r = c->r;
+    if(g) *g = c->g;
+    if(b) *b = c->b;
+
+    return 1;
+}



More information about the grass-commit mailing list