[mapserver-commits] r11378 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Wed Mar 30 00:55:36 EDT 2011


Author: sdlime
Date: 2011-03-29 21:55:36 -0700 (Tue, 29 Mar 2011)
New Revision: 11378

Modified:
   trunk/mapserver/mapfile.c
   trunk/mapserver/maputil.c
Log:
Allow specification of an alpha channel in HEX colors via mapfile or attribute binding (experimental).

Modified: trunk/mapserver/mapfile.c
===================================================================
--- trunk/mapserver/mapfile.c	2011-03-30 04:50:24 UTC (rev 11377)
+++ trunk/mapserver/mapfile.c	2011-03-30 04:55:36 UTC (rev 11378)
@@ -384,14 +384,15 @@
   } else {
     if((symbol = getSymbol(2, MS_NUMBER, MS_STRING)) == -1) return MS_FAILURE;
   }
+
   color->alpha=255;
-
   if(symbol == MS_NUMBER) {
     color->red = (int) msyynumber;
     if(getInteger(&(color->green)) == -1) return MS_FAILURE;
     if(getInteger(&(color->blue)) == -1) return MS_FAILURE;
   } else if(symbol == MS_STRING) {
-    if(msyystring_buffer[0] == '#' && strlen(msyystring_buffer) == 7) { /* got a hex color */
+    int len = strlen(msyystring_buffer);
+    if(msyystring_buffer[0] == '#' && (len == 7 || len == 9)) { /* got a hex color w/optional alpha */
       hex[0] = msyystring_buffer[1];
       hex[1] = msyystring_buffer[2];
       color->red = msHexToInt(hex);
@@ -401,6 +402,11 @@
       hex[0] = msyystring_buffer[5];
       hex[1] = msyystring_buffer[6];
       color->blue = msHexToInt(hex);
+      if(len == 9) {
+        hex[0] = msyystring_buffer[7];
+        hex[1] = msyystring_buffer[8];
+        color->alpha = msHexToInt(hex);
+      }
     } else {
        /* TODO: consider named colors here */
        msSetError(MS_SYMERR, "Invalid hex color (%s):(line %d)", "loadColor()", msyystring_buffer, msyylineno); 

Modified: trunk/mapserver/maputil.c
===================================================================
--- trunk/mapserver/maputil.c	2011-03-30 04:50:24 UTC (rev 11377)
+++ trunk/mapserver/maputil.c	2011-03-30 04:55:36 UTC (rev 11378)
@@ -71,9 +71,11 @@
 
 static int bindColorAttribute(colorObj *attribute, char *value)
 {
-  if(!value || strlen(value) == 0) return MS_FAILURE;
+  int len;
 
-  if(value[0] == '#' && strlen(value) == 7) { /* got a hex color */
+  if(!value || ((len = strlen(value)) == 0)) return MS_FAILURE;
+  
+  if(value[0] == '#' && (len == 7 || len == 9)) { /* got a hex color */
     char hex[2];
 
     hex[0] = value[1];
@@ -85,7 +87,11 @@
     hex[0] = value[5];
     hex[1] = value[6];
     attribute->blue = msHexToInt(hex);
-
+    if(len == 9) {
+      hex[0] = value[7];
+      hex[1] = value[8];
+      attribute->alpha = msHexToInt(hex);
+    }
     return MS_SUCCESS;
   } else { /* try a space delimited string */
     char **tokens=NULL;



More information about the mapserver-commits mailing list