Index: /branches/eam_branches/20091201/Ohana/src/kapa2/src/ColorHistogram.c
===================================================================
--- /branches/eam_branches/20091201/Ohana/src/kapa2/src/ColorHistogram.c	(revision 26624)
+++ /branches/eam_branches/20091201/Ohana/src/kapa2/src/ColorHistogram.c	(revision 26625)
@@ -174,5 +174,5 @@
     node->pixel = current[0];
     current[0] ++;
-    assert (current[0] <= Npixels);
+    assert (current[0] < Npixels);
     return TRUE;
   }
Index: /branches/eam_branches/20091201/Ohana/src/kapa2/src/SetColorScale.c
===================================================================
--- /branches/eam_branches/20091201/Ohana/src/kapa2/src/SetColorScale.c	(revision 26624)
+++ /branches/eam_branches/20091201/Ohana/src/kapa2/src/SetColorScale.c	(revision 26625)
@@ -34,12 +34,13 @@
   float slope;
   float start;
-  unsigned short MaxValue;
+  unsigned short MaxValue, NANValue;
   Matrix *matrix;
 
   // define the color transform parameters
-  MaxValue = graphic[0].Npixels - 1;
+  NANValue = graphic[0].Npixels - 1;
+  MaxValue = graphic[0].Npixels - 2;
   if (image[0].image[0].range != 0.0) {
-    slope = graphic[0].Npixels / image[0].image[0].range;
-    start = graphic[0].Npixels * image[0].image[0].zero / image[0].image[0].range;
+    slope = (graphic[0].Npixels - 1) / image[0].image[0].range;
+    start = slope * image[0].image[0].zero;
   } else {
     slope = 1.0;
@@ -63,7 +64,17 @@
   // convert pixel data values to pixel index values (0 - Npixel)
   for (i = 0; i < nPixels; i++, iData++, oData++) {
+    if (isnan(*iData) || isinf(*iData)) {
+      *oData = NANValue;
+      continue;
+    }
     value = *iData * slope - start;
-    if (value < 0) value = 0;
-    if (value > MaxValue) value = MaxValue;
+    if (value < 0) {
+      *oData = 0;
+      continue;
+    }
+    if (value > MaxValue) {
+      *oData = MaxValue;
+      continue;
+    }
     *oData = value;
   }
@@ -169,4 +180,13 @@
   if (DX != image[0].channel[KAPA_CHANNEL_BLUE].matrix.Naxis[0]) return FALSE;
   if (DY != image[0].channel[KAPA_CHANNEL_BLUE].matrix.Naxis[1]) return FALSE;
+
+  // XXX a bit bogus: we are going to store a special color at Npixels-1 for 
+  // marking the NAN pixels.  
+  { 
+      // XXX set pure green for now
+      graphic[0].cmap[graphic[0].Npixels-1].red = 0;
+      graphic[0].cmap[graphic[0].Npixels-1].green = 0xffff;
+      graphic[0].cmap[graphic[0].Npixels-1].blue = 0;
+  }  
 
   // create the top-level cube
@@ -214,5 +234,5 @@
   // convert histogram 3D values to cmap colors
   Npixels = 0;
-  CCNodeSetColorMap (cube, graphic[0].cmap, graphic[0].Npixels, &Npixels);
+  CCNodeSetColorMap (cube, graphic[0].cmap, graphic[0].Npixels - 1, &Npixels);
 
   // store the colors
Index: /branches/eam_branches/20091201/Ohana/src/kapa2/src/SetColormap.c
===================================================================
--- /branches/eam_branches/20091201/Ohana/src/kapa2/src/SetColormap.c	(revision 26624)
+++ /branches/eam_branches/20091201/Ohana/src/kapa2/src/SetColormap.c	(revision 26625)
@@ -10,4 +10,9 @@
     VAR = tmp; \
   } }   
+
+// the image arrives from the client program as an array of floats, stored in image->matrix.
+// whenever we load a new image or change tv channels, we need to map the currently active
+// image from float to pixel index (image->pixmap).  When we actually display (or change the
+// display of) an image, we simply remap the lit pixels (in Remap32.c, etc).
 
 int SetColormap (char *name) {
@@ -26,9 +31,18 @@
   }
 
+  // XXX a bit bogus: we are going to store a special color at Npixels-1 for 
+  // marking the NAN pixels.  
+  { 
+      // XXX set pure green for now
+      graphic[0].cmap[graphic[0].Npixels-1].red = 0;
+      graphic[0].cmap[graphic[0].Npixels-1].green = 0xffff;
+      graphic[0].cmap[graphic[0].Npixels-1].blue = 0;
+  }  
+
   // very simple color model: evenly spaced cube 
   if (!strcasecmp (name, "ruffcolor")) {
       graphic[0].nRed  = pow (graphic[0].Npixels, 0.333);
       graphic[0].nBlue = pow (graphic[0].Npixels, 0.333);
-      graphic[0].nGreen = graphic[0].Npixels / (graphic[0].nRed * graphic[0].nBlue);
+      graphic[0].nGreen = (graphic[0].Npixels - 1) / (graphic[0].nRed * graphic[0].nBlue);
 
       // red,green,blue are values in range 0x0000 to 0xffff
@@ -48,4 +62,5 @@
 	  }
       }
+      fprintf (stderr, "ruff Npix: %d vs %d\n", i, graphic[0].Npixels);
 
       // all other modes are 1D: set the flag:
@@ -58,9 +73,9 @@
 
   // red,green,blue are values in range 0x0000 to 0xffff
-  scale = 0xffff / (graphic[0].Npixels - 1);
+  scale = 0xffff / (graphic[0].Npixels - 2);
 
   /* greyscale */
   if ((!strcasecmp (name, "grayscale")) || (!strcasecmp (name, "greyscale"))) {
-    for (i = 0; i < graphic[0].Npixels; i++) {  
+    for (i = 0; i < graphic[0].Npixels - 1; i++) {  
       SETVALUE (graphic[0].cmap[i].red,   0xffff - i*scale, 0, 0xffff);
       SETVALUE (graphic[0].cmap[i].green, 0xffff - i*scale, 0, 0xffff);
@@ -72,5 +87,5 @@
   /* -grayscale */
   if ((!strcasecmp (name, "-grayscale")) || (!strcasecmp (name, "-greyscale"))) {
-    for (i = 0; i < graphic[0].Npixels; i++) {  
+    for (i = 0; i < graphic[0].Npixels - 1; i++) {  
       SETVALUE (graphic[0].cmap[i].red,   i*scale, 0, 0xffff);
       SETVALUE (graphic[0].cmap[i].green, i*scale, 0, 0xffff);
@@ -102,5 +117,5 @@
       graphic[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
     }
-    for (i = (int)(0.75*graphic[0].Npixels); i < graphic[0].Npixels; i++) {  
+    for (i = (int)(0.75*graphic[0].Npixels); i < graphic[0].Npixels - 1; i++) {  
       graphic[0].cmap[i].red   = 0xffff;
       graphic[0].cmap[i].green = 0xffff;
@@ -134,5 +149,5 @@
     }
     blueRef  = 0.75*graphic[0].Npixels*scale*4.0;
-    for (i = (int)(0.75*graphic[0].Npixels); i < graphic[0].Npixels; i++) {  
+    for (i = (int)(0.75*graphic[0].Npixels); i < graphic[0].Npixels - 1; i++) {  
       graphic[0].cmap[i].red   = 0xffff;
       graphic[0].cmap[i].green = 0xffff;
