Index: geovis/trunk/ColorMap.cpp
===================================================================
--- geovis/trunk/ColorMap.cpp	(revision 5118)
+++ geovis/trunk/ColorMap.cpp	(revision 5119)
@@ -34,15 +34,15 @@
             float x = (float)i/(height-1);
             float val = min + (max - min) * x;
-            osg::Vec4f rgb = map->getColor(val);
+            osg::Vec4f rgba = map->getColor(val);
+            float opacity = rgba[3];
             unsigned char color[3];
             if (opaque) {
-                color[0] = (unsigned char)(255. * (bgr ? rgb[2] : rgb[0]));
-                color[1] = (unsigned char)(255. * rgb[1]);
-                color[2] = (unsigned char)(255. * (bgr ? rgb[0] : rgb[2]));
+                color[0] = (unsigned char)(255. * (bgr ? rgba[2] : rgba[0]));
+                color[1] = (unsigned char)(255. * rgba[1]);
+                color[2] = (unsigned char)(255. * (bgr ? rgba[0] : rgba[2]));
             } else {
-                float opacity = rgb[3];
-                color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgb[2] : rgb[0]) * opacity));
-                color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgb[1] * opacity));
-                color[2] = (unsigned char)(255. * (bgColor[2] * (1.0 - opacity) + (bgr ? rgb[0] : rgb[2]) * opacity));
+                color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgba[2] : rgba[0]) * opacity));
+                color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgba[1] * opacity));
+                color[2] = (unsigned char)(255. * (bgColor[2] * (1.0 - opacity) + (bgr ? rgba[0] : rgba[2]) * opacity));
             }
             for (int j = 0; j < width; j++) {
@@ -50,5 +50,5 @@
                 dst += 3;
                 if (bytesPerPixel == 4) {
-                    *(dst++) = (unsigned char)255.;
+                    *(dst++) = (unsigned char)(255. * (opaque ? 1.0 : opacity));
                 }
             }
@@ -60,4 +60,5 @@
                 float val = min + (max - min) * x;
                 osg::Vec4f rgb = map->getColor(val);
+                double opacity = rgb[3];
                 unsigned char color[3];
                 if (opaque) {
@@ -66,5 +67,4 @@
                     color[2] = (unsigned char)(255. * (bgr ? rgb[0] : rgb[2]));
                 } else {
-                    double opacity = rgb[3];
                     color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgb[2] : rgb[0]) * opacity));
                     color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgb[1] * opacity));
@@ -74,5 +74,5 @@
                 dst += 3;
                 if (bytesPerPixel == 4) {
-                    *(dst++) = (unsigned char)255.;
+                    *(dst++) = (unsigned char)(255. * (opaque ? 1.0 : opacity));
                 }
             }
Index: geovis/trunk/RendererCmd.cpp
===================================================================
--- geovis/trunk/RendererCmd.cpp	(revision 5118)
+++ geovis/trunk/RendererCmd.cpp	(revision 5119)
@@ -743,5 +743,5 @@
           Tcl_Obj *const *objv)
 {
-    if (objc != 4) {
+    if (objc < 4) {
         Tcl_AppendResult(interp, "wrong # args: should be \"",
                 Tcl_GetString(objv[0]), " colormapName width height\"", (char*)NULL);
@@ -755,8 +755,20 @@
         return TCL_ERROR;
     }
-
     bool opaque = true;
+    if (objc > 4) {
+        if (GetBooleanFromObj(interp, objv[4], &opaque) != TCL_OK) {
+            return TCL_ERROR;
+        }
+    }
     float bgColor[3];
-    memset(bgColor, 0, sizeof(float)*3);
+    if (objc > 5) {
+        if (GetFloatFromObj(interp, objv[5], &bgColor[0]) != TCL_OK ||
+            GetFloatFromObj(interp, objv[6], &bgColor[1]) != TCL_OK ||
+            GetFloatFromObj(interp, objv[7], &bgColor[2]) != TCL_OK) {
+            return TCL_ERROR;
+        }
+    } else {
+        memset(bgColor, 0, sizeof(float)*3);
+    }
     osg::ref_ptr<osg::Image> imgData = new osg::Image();
 
Index: geovis/trunk/geovis_protocol.txt
===================================================================
--- geovis/trunk/geovis_protocol.txt	(revision 5118)
+++ geovis/trunk/geovis_protocol.txt	(revision 5119)
@@ -85,4 +85,11 @@
          <numberOfTableEntries> = integer or "default"
 
+legend <colormapName> <w> <h> <?opaque?> <?bgR?> <?bgG?> <?bgB?>
+       Render a legend colorbar.
+       <colormapName> - Name of the colormap defined with the colormap command
+       <w>,<h> - width and height of colorbar
+       <opaque> - If false, blend with background color
+       <bgR>,<bgG>,<bgB> - Background color (defaults to black)
+
 renderer render
          Force a new image to be rendered
