Index: /branches/eam_branches/20090715/Ohana/src/kapa2/include/constants.h
===================================================================
--- /branches/eam_branches/20090715/Ohana/src/kapa2/include/constants.h	(revision 24799)
+++ /branches/eam_branches/20090715/Ohana/src/kapa2/include/constants.h	(revision 24800)
@@ -11,5 +11,5 @@
 
 # define NCHANNELS 3
-# define NPIXELS_DYNAMIC 128
+# define NPIXELS_DYNAMIC 4600
 
 // XXX for the moment, this is set to match the values in SetColorScale3D_CC
Index: /branches/eam_branches/20090715/Ohana/src/kapa2/include/structures.h
===================================================================
--- /branches/eam_branches/20090715/Ohana/src/kapa2/include/structures.h	(revision 24799)
+++ /branches/eam_branches/20090715/Ohana/src/kapa2/include/structures.h	(revision 24800)
@@ -21,5 +21,5 @@
   Window         window;
   Visual        *visual;
-  int            visualclass; // is visual dynamic? (XXX change name?)
+  int            dynamicColors; // is visual dynamic?
   int            Nbits;	      // pixel depth in bits (8, 16, 24, 32)
   GC             gc;
Index: /branches/eam_branches/20090715/Ohana/src/kapa2/src/CheckVisual.c
===================================================================
--- /branches/eam_branches/20090715/Ohana/src/kapa2/src/CheckVisual.c	(revision 24799)
+++ /branches/eam_branches/20090715/Ohana/src/kapa2/src/CheckVisual.c	(revision 24800)
@@ -10,5 +10,5 @@
 
   int i, Nfound, N;
-  int isColor, isDefault, isDynamic;
+  int isColor, isDefault;
   XVisualInfo *visual_list, visual_temp;
   unsigned long planes[3];
@@ -34,29 +34,20 @@
   }
   
-// skip the default and the PseudoColor visuals, go for TrueColor first
-# if (0)
-  /* check default visual first */ 
-  for (i = 0; (i < Nfound) && (graphic[0].visual != visual_list[i].visual); i++);
-  if (i == Nfound) {
-    fprintf (stderr, "default visual not found??\n");
-    exit (0);
-  }
-# endif
-
   // set these based on selected visual
-  isColor = isDefault = isDynamic = FALSE;
-
-# if (0)
-  // attempt to select the most desirable type of visual: Default as PseudoColor (XXX is it still true?)
-  if (DEBUG) fprintf (stderr, "default visual class is %d\n", visual_list[i].class);
-  if (visual_list[i].class == PseudoColor) {
-    isColor = isDefault = isDynamic = TRUE;
-    graphic[0].visual = visual_list[i].visual;
-    graphic[0].visualclass = TRUE;
-    goto test_pixels;
-  }
-# endif
-
-  // attempt to select the most desirable type of visual: TrueColor (XXX is it still true?)
+  isColor = isDefault = FALSE;
+
+  // attempt to select the most desirable type of visual: DirectColor
+  for (i = 0; (i < Nfound) && (visual_list[i].class != DirectColor); i++);
+  if (i != Nfound) {
+    isColor = TRUE;
+    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
+    isDefault = (graphic[0].visual == visual_list[i].visual);
+    graphic[0].visual = visual_list[i].visual;
+    graphic[0].dynamicColors = TRUE;
+    if (DEBUG) fprintf (stderr, "got DirectColor visual\n");
+    goto test_pixels;
+  }
+
+  // attempt to select the most desirable type of visual: TrueColor
   for (i = 0; (i < Nfound) && (visual_list[i].class != TrueColor); i++);
   if (i != Nfound) {
@@ -65,5 +56,6 @@
     isDefault = (graphic[0].visual == visual_list[i].visual);
     graphic[0].visual = visual_list[i].visual;
-    graphic[0].visualclass = FALSE;
+    graphic[0].dynamicColors = FALSE;
+    if (DEBUG) fprintf (stderr, "got TrueColor visual\n");
     goto test_pixels;
   }
@@ -72,9 +64,10 @@
   for (i = 0; (i < Nfound) && (visual_list[i].class != PseudoColor); i++);
   if (i != Nfound) {
-    isColor = isDynamic = TRUE;
+    isColor = TRUE;
     if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
     isDefault = (graphic[0].visual == visual_list[i].visual);
     graphic[0].visual = visual_list[i].visual;
-    graphic[0].visualclass = TRUE;
+    graphic[0].dynamicColors = TRUE;
+    if (DEBUG) fprintf (stderr, "got PseudoColor visual\n");
     goto test_pixels;
   }
@@ -83,9 +76,9 @@
   for (i = 0; (i < Nfound) && (visual_list[i].class != GrayScale); i++);
   if (i != Nfound) {
-    isDynamic = TRUE;
     if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
     isDefault = (graphic[0].visual == visual_list[i].visual);
     graphic[0].visual = visual_list[i].visual;
-    graphic[0].visualclass = TRUE;
+    graphic[0].dynamicColors = TRUE;
+    if (DEBUG) fprintf (stderr, "got GrayScale visual\n");
     goto test_pixels;
   }
@@ -97,5 +90,6 @@
     isDefault = (graphic[0].visual == visual_list[i].visual);
     graphic[0].visual = visual_list[i].visual;
-    graphic[0].visualclass = FALSE;
+    graphic[0].dynamicColors = FALSE;
+    if (DEBUG) fprintf (stderr, "got StaticColor visual\n");
     goto test_pixels;
   }
@@ -107,5 +101,6 @@
     isDefault = (graphic[0].visual == visual_list[i].visual);
     graphic[0].visual = visual_list[i].visual;
-    graphic[0].visualclass = FALSE;
+    graphic[0].dynamicColors = FALSE;
+    if (DEBUG) fprintf (stderr, "got StaticGray visual\n");
     goto test_pixels;
   }
@@ -115,4 +110,5 @@
   /* need to make a colormap if 
      1) the selected visual is not the default 
+        XXX not sure if I need to / am allowed to alloc a colormap if I've grabbed the default.
      2) there are not enough colors available */
 
@@ -125,11 +121,15 @@
   } 
 
-  // allocate a private colormap, if needed
+  // dynamic visual classes can accept AllocAll and can use XAllocColorCells while AllocNone must use XAllocColor
+  // int allocMode = graphic[0].dynamicColors ? AllocAll : AllocNone;
+  int allocMode = AllocNone;
+
+  // allocate a private colormap, if desired or needed
   if (!isDefault) {
     if (DEBUG) fprintf (stderr, "allocated private colormap\n");
-    graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
-  }
-
-  if (isDynamic) {
+    graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, allocMode);
+  }
+
+  if (graphic[0].dynamicColors) {
     Npixels = NPIXELS_DYNAMIC;
     if ((N = get_argument (*argc, argv, "-ncolors"))) {
@@ -144,6 +144,9 @@
     for (graphic[0].Npixels = Npixels; graphic[0].Npixels >= 16; graphic[0].Npixels -= 4) {
       if (DEBUG) fprintf (stderr, "trying %d colors\n", (int) graphic[0].Npixels);
-      if (XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 1, graphic[0].pixels, graphic[0].Npixels)) {
+      if (XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 0, graphic[0].pixels, graphic[0].Npixels)) {
 	break;
+      }
+      for (i = 0; i < graphic[0].Npixels; i++) {
+	graphic[0].cmap[i].pixel = graphic[0].pixels[i];
       }
     }
@@ -152,9 +155,10 @@
     if (graphic[0].Npixels < 16) {
       if (!isDefault) {
+	// We've already tried to allocate a colormap above...
 	fprintf (stderr, "can't allocate enough cells in private colormap\n");
 	exit (0);
       }
       if (DEBUG) fprintf (stderr, "can't allocate enough cells, using private colormap\n");
-      graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
+      graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, allocMode);
 
       for (graphic[0].Npixels = NPIXELS_DYNAMIC; graphic[0].Npixels >= 16; graphic[0].Npixels -= 4) {
@@ -163,6 +167,8 @@
 	  break;
 	}
-      }
-
+	for (i = 0; i < graphic[0].Npixels; i++) {
+	  graphic[0].cmap[i].pixel = graphic[0].pixels[i];
+	}
+      }
       if ((N = get_argument (*argc, argv, "-colorcount"))) {
 	fprintf (stderr, "kapa can grab %d colors\n", graphic[0].Npixels);
Index: /branches/eam_branches/20090715/Ohana/src/kapa2/src/DragColorbar.c
===================================================================
--- /branches/eam_branches/20090715/Ohana/src/kapa2/src/DragColorbar.c	(revision 24799)
+++ /branches/eam_branches/20090715/Ohana/src/kapa2/src/DragColorbar.c	(revision 24800)
@@ -10,5 +10,5 @@
   int             xstatus, Npix, center;
 
-  if (!graphic[0].visualclass) return;
+  if (!graphic[0].dynamicColors) return;
 
   X = mouse_event[0].x;
@@ -79,5 +79,5 @@
   XColor cmap[256];
 
-  if (!graphic[0].visualclass) return;
+  if (!graphic[0].dynamicColors) return;
 
   for (i = 0; i < graphic[0].Npixels; i++) {
@@ -88,4 +88,5 @@
       cmap[i].blue = graphic[0].cmap[0].blue;
       cmap[i].green = graphic[0].cmap[0].green;
+      cmap[i].flags = DoRed | DoGreen | DoBlue;
     }
     else {
@@ -94,4 +95,5 @@
 	cmap[i].blue = graphic[0].cmap[graphic[0].Npixels-1].blue;
 	cmap[i].green = graphic[0].cmap[graphic[0].Npixels-1].green;
+	cmap[i].flags = DoRed | DoGreen | DoBlue;
       }
       else {
@@ -99,4 +101,5 @@
 	cmap[i].blue = graphic[0].cmap[j].blue;
 	cmap[i].green = graphic[0].cmap[j].green;
+	cmap[i].flags = DoRed | DoGreen | DoBlue;
       }
     }
Index: /branches/eam_branches/20090715/Ohana/src/kapa2/src/MakeColormap.c
===================================================================
--- /branches/eam_branches/20090715/Ohana/src/kapa2/src/MakeColormap.c	(revision 24799)
+++ /branches/eam_branches/20090715/Ohana/src/kapa2/src/MakeColormap.c	(revision 24800)
@@ -1,5 +1,6 @@
 # include "Ximage.h"
 
-static char default_cmap[] = "grayscale";
+// static char default_cmap[] = "grayscale";
+static char default_cmap[] = "heat";
 
 void MakeColormap (int argc, char **argv) {
Index: /branches/eam_branches/20090715/Ohana/src/kapa2/src/SetColorScale.c
===================================================================
--- /branches/eam_branches/20090715/Ohana/src/kapa2/src/SetColorScale.c	(revision 24799)
+++ /branches/eam_branches/20090715/Ohana/src/kapa2/src/SetColorScale.c	(revision 24800)
@@ -218,5 +218,5 @@
   // store the colors
   if (USE_XWINDOW) {
-    if (graphic[0].visualclass) {
+    if (graphic[0].dynamicColors) {
       XStoreColors(graphic[0].display, graphic[0].colormap, graphic[0].cmap, Npixels);
     } else {
Index: /branches/eam_branches/20090715/Ohana/src/kapa2/src/SetColormap.c
===================================================================
--- /branches/eam_branches/20090715/Ohana/src/kapa2/src/SetColormap.c	(revision 24799)
+++ /branches/eam_branches/20090715/Ohana/src/kapa2/src/SetColormap.c	(revision 24800)
@@ -146,9 +146,11 @@
  store_colors:
   if (!USE_XWINDOW) return (TRUE);
-  if (graphic[0].visualclass) {
-    XStoreColors(graphic[0].display, graphic[0].colormap, graphic[0].cmap, graphic[0].Npixels);
+  if (graphic[0].dynamicColors) {
+    if (!XStoreColors(graphic[0].display, graphic[0].colormap, graphic[0].cmap, graphic[0].Npixels)) {
+	fprintf (stderr, "error storing colors\n");
+    }
   } else {
     for (i = 0; i < graphic[0].Npixels; i++) {
-      if (XAllocColor (graphic[0].display, graphic[0].colormap, &graphic[0].cmap[i]) == 0) {
+      if (!XAllocColor (graphic[0].display, graphic[0].colormap, &graphic[0].cmap[i])) {
 	fprintf (stderr, "error on %d\n", i);
       }
