Index: trunk/Ohana/src/kapa2/Makefile
===================================================================
--- trunk/Ohana/src/kapa2/Makefile	(revision 22713)
+++ trunk/Ohana/src/kapa2/Makefile	(revision 25757)
@@ -48,7 +48,8 @@
 $(SRC)/Layout.$(ARCH).o		  	  $(SRC)/Sections.$(ARCH).o	      \
 $(SRC)/Graphs.$(ARCH).o                   $(SRC)/SetGraphSize.$(ARCH).o       \
-$(SRC)/Resize.$(ARCH).o                   $(SRC)/ErasePlots.$(ARCH).o         \
-$(SRC)/EraseImage.$(ARCH).o         	  $(SRC)/SetToolbox.$(ARCH).o         \
+$(SRC)/Resize.$(ARCH).o                   $(SRC)/Relocate.$(ARCH).o           \
+$(SRC)/ErasePlots.$(ARCH).o               $(SRC)/EraseImage.$(ARCH).o         \
 $(SRC)/EraseCurrentPlot.$(ARCH).o         $(SRC)/EraseSections.$(ARCH).o      \
+$(SRC)/SetToolbox.$(ARCH).o                                                   \
 $(SRC)/SetSection.$(ARCH).o		  $(SRC)/DefineSection.$(ARCH).o      \
 $(SRC)/SetLimits.$(ARCH).o                $(SRC)/SetFont.$(ARCH).o            \
@@ -79,7 +80,4 @@
 $(SRC)/ColorHistogram.$(ARCH).o           $(SRC)/CreateWide.$(ARCH).o
 
-#$(SRC)/CreateZoom8.$(ARCH).o              $(SRC)/CreateZoom16.$(ARCH).o       \
-#$(SRC)/CreateZoom24.$(ARCH).o             $(SRC)/CreateZoom32.$(ARCH).o       \
-
 OBJ  =  $(KAPA)
 
Index: trunk/Ohana/src/kapa2/include/constants.h
===================================================================
--- trunk/Ohana/src/kapa2/include/constants.h	(revision 22713)
+++ trunk/Ohana/src/kapa2/include/constants.h	(revision 25757)
@@ -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: trunk/Ohana/src/kapa2/include/prototypes.h
===================================================================
--- trunk/Ohana/src/kapa2/include/prototypes.h	(revision 22713)
+++ trunk/Ohana/src/kapa2/include/prototypes.h	(revision 25757)
@@ -55,4 +55,5 @@
 int           LoadTextlines       PROTO((int sock));
 int           Resize              PROTO((int sock));
+int           Relocate            PROTO((int sock));
 int           GetLimits           PROTO((int sock));
 int           SetLimits           PROTO((int sock));
@@ -178,6 +179,6 @@
 void          Image_to_Picture    PROTO((double *x1, double *y1, double x2, double y2, Picture *picture));
 void          Image_to_Screen     PROTO((double *x1, double *y1, double x2, double y2, Picture *picture));
-void          Picture_Lower 	  PROTO((int *i_start, int *j_start, Matrix *matrix, Picture *picture));
-void          Picture_Upper 	  PROTO((int *i_end, int *j_end, Matrix *matrix, Picture *picture));
+void          Picture_Lower 	  PROTO((int *i_start, int *j_start, int *I_start, int *J_start, Matrix *matrix, Picture *picture));
+void          Picture_Upper 	  PROTO((int *i_end, int *j_end, int i_start, int j_start, Matrix *matrix, Picture *picture));
 
 void          DragColorbar        PROTO((Graphic *graphic, KapaImageWidget *image, XButtonEvent *mouse_event));
Index: trunk/Ohana/src/kapa2/include/structures.h
===================================================================
--- trunk/Ohana/src/kapa2/include/structures.h	(revision 22713)
+++ trunk/Ohana/src/kapa2/include/structures.h	(revision 25757)
@@ -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;
@@ -94,5 +94,5 @@
   int      DX, DY;	      // size of displayed picture (must be updated with new images...)
   int      expand;	      // zoomscale
-  double   X,  Y;	      // center of image in picture
+  double   Xc,  Yc;	      // center of image in picture
   char     flipx, flipy;      // parity (0 = +; 1 = -)
   XImage  *pix;
Index: trunk/Ohana/src/kapa2/src/ButtonFunctions.c
===================================================================
--- trunk/Ohana/src/kapa2/src/ButtonFunctions.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/ButtonFunctions.c	(revision 25757)
@@ -44,6 +44,6 @@
 int Recenter (Graphic *graphic, KapaImageWidget *image) {
 
-  image[0].picture.X = 0.5*image[0].image[0].matrix.Naxis[0];
-  image[0].picture.Y = 0.5*image[0].image[0].matrix.Naxis[1];
+  image[0].picture.Xc = 0.5*image[0].image[0].matrix.Naxis[0];
+  image[0].picture.Yc = 0.5*image[0].image[0].matrix.Naxis[1];
  
   Remap (graphic, image);
@@ -56,4 +56,5 @@
 
   image[0].picture.expand = 1;
+  image[0].zoom.expand = 5;
   Remap (graphic, image);
   Refresh ();
@@ -64,7 +65,8 @@
 int RecenterRescale (Graphic *graphic, KapaImageWidget *image) {
 
-  image[0].picture.X = 0.5*image[0].image[0].matrix.Naxis[0];
-  image[0].picture.Y = 0.5*image[0].image[0].matrix.Naxis[1];
+  image[0].picture.Xc = 0.5*image[0].image[0].matrix.Naxis[0];
+  image[0].picture.Yc = 0.5*image[0].image[0].matrix.Naxis[1];
   image[0].picture.expand = 1;
+  image[0].zoom.expand = 5;
  
   Remap (graphic, image);
Index: trunk/Ohana/src/kapa2/src/Center.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Center.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/Center.c	(revision 25757)
@@ -16,8 +16,10 @@
   if (image == NULL) return (TRUE);
 
-  image[0].picture.X = X;
-  image[0].picture.Y = Y;
+  // enforce integer center here?
+  image[0].picture.Xc = X;
+  image[0].picture.Yc = Y;
   if ((zoom != 0) && (zoom != -1)) {
     image[0].picture.expand = zoom;
+    image[0].zoom.expand = MIN(image[0].zoom.dx / 5.5, MAX(5, 2*zoom));
   }
 
Index: trunk/Ohana/src/kapa2/src/CheckPipe.c
===================================================================
--- trunk/Ohana/src/kapa2/src/CheckPipe.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/CheckPipe.c	(revision 25757)
@@ -131,4 +131,10 @@
   }
 
+  if (!strcmp (word, "MOVE")) {
+    status = Relocate (sock);
+    KiiSendCommand (sock, 4, "DONE");
+    FINISHED (status);
+  }
+
   if (!strcmp (word, "GLIM")) {
     GetLimits (sock);
Index: trunk/Ohana/src/kapa2/src/CheckVisual.c
===================================================================
--- trunk/Ohana/src/kapa2/src/CheckVisual.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/CheckVisual.c	(revision 25757)
@@ -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,8 @@
   }
   
-// 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: TrueColor
   for (i = 0; (i < Nfound) && (visual_list[i].class != TrueColor); i++);
   if (i != Nfound) {
@@ -65,5 +44,18 @@
     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;
+  }
+
+  // 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;
   }
@@ -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: trunk/Ohana/src/kapa2/src/CheckVisual.test.c
===================================================================
--- trunk/Ohana/src/kapa2/src/CheckVisual.test.c	(revision 25757)
+++ trunk/Ohana/src/kapa2/src/CheckVisual.test.c	(revision 25757)
@@ -0,0 +1,174 @@
+# include "Ximage.h"
+
+/* DirectColor doesn't seem to work, even though it is available:
+   I cannot use XAllocColorCells to get pixels under DirectColor
+*/
+
+/* static int try_visual[] = {5, 3, 1, 4, 2, 0}; */
+
+int TryVisualType (int *isColor, int *isDefault, Graphic *graphic, int Nvisual, XVisualInfo *visual_list, int VisualType, char *name) {
+
+    int i;
+
+    for (i = 0; i < Nvisual; i++) {
+	if (visual_list[i].class != VisualType) continue;
+
+	*isColor = FALSE;
+	if (VisualType == DirectColor) *isColor = TRUE;
+	if (VisualType == PseudoColor) *isColor = TRUE;
+	if (VisualType == TrueColor)   *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].dynamicColors = FALSE;
+	if (VisualType == DirectColor) graphic[0].dynamicColors = TRUE;
+	if (VisualType == PseudoColor) graphic[0].dynamicColors = TRUE;
+	if (VisualType == GrayScale) graphic[0].dynamicColors = TRUE;
+
+	if (DEBUG) fprintf (stderr, "got %s visual\n", name);
+	return (TRUE);
+    }
+    return (FALSE);
+}
+
+void CheckVisual (Graphic *graphic, int *argc, char **argv) {
+
+  int i, Nvisual, N;
+  int isColor, isDefault;
+  XVisualInfo *visual_list, visual_temp;
+  unsigned long planes[3];
+  XPixmapFormatValues *pixmaps;
+  int Npixmaps, Npixels;
+
+  if (DEBUG) {
+    fprintf (stderr, "DirectColor: %d\n", DirectColor);
+    fprintf (stderr, "PseudoColor: %d\n", PseudoColor);
+    fprintf (stderr, "TrueColor:   %d\n", TrueColor);
+    fprintf (stderr, "GrayScale:   %d\n", GrayScale);
+    fprintf (stderr, "StaticColor: %d\n", StaticColor);
+    fprintf (stderr, "StaticGray:  %d\n", StaticGray);
+  }
+
+  visual_temp.screen = graphic[0].screen;
+  
+  /* find available visuals */
+  visual_list = XGetVisualInfo (graphic[0].display, VisualScreenMask, &visual_temp, &Nvisual);
+  if (Nvisual == 0) {
+    fprintf (stderr, "error finding useful visual\n");
+    exit (2);
+  }
+  
+  // set these based on selected visual
+  isColor = isDefault = FALSE;
+
+  if (TryVisualType (&isColor, &isDefault, graphic, Nvisual, visual_list, TrueColor,   "TrueColor"))   goto test_pixels;
+  if (TryVisualType (&isColor, &isDefault, graphic, Nvisual, visual_list, DirectColor, "DirectColor")) goto test_pixels;
+  if (TryVisualType (&isColor, &isDefault, graphic, Nvisual, visual_list, PseudoColor, "PseudoColor")) goto test_pixels;
+  if (TryVisualType (&isColor, &isDefault, graphic, Nvisual, visual_list, GrayScale,   "GrayScale"))   goto test_pixels;
+  if (TryVisualType (&isColor, &isDefault, graphic, Nvisual, visual_list, StaticColor, "StaticColor")) goto test_pixels;
+  if (TryVisualType (&isColor, &isDefault, graphic, Nvisual, visual_list, StaticGray,  "StaticGray"))  goto test_pixels;
+
+  fprintf (stderr, "error finding valid visual\n");
+  exit (2);
+
+  test_pixels:
+
+  /* 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 */
+
+  /* NEED TO ADD A COUPLE LINES DEFINING THE VARIOUS HARD COLORS (BLACK, WHITE, AND THE OVERLAYS) */
+
+  // allow user to force a private colormap
+  if ((N = get_argument (*argc, argv, "-private"))) {
+    remove_argument(N, argc, argv);
+    isDefault = FALSE;
+  } 
+
+  // 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, allocMode);
+  }
+
+  if (graphic[0].dynamicColors) {
+    Npixels = NPIXELS_DYNAMIC;
+    if ((N = get_argument (*argc, argv, "-ncolors"))) {
+      remove_argument(N, argc, argv);
+      Npixels = atoi (argv[N]);
+      remove_argument(N, argc, argv);
+    } 
+
+    /* allocate color cells */
+    ALLOCATE (graphic[0].pixels, unsigned long, Npixels);
+    ALLOCATE (graphic[0].cmap,   XColor,        Npixels);
+    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, 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];
+      }
+    }
+
+    /* insufficient cells, can we make a private colormap? */
+    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, allocMode);
+
+      for (graphic[0].Npixels = NPIXELS_DYNAMIC; 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)) {
+	  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);
+	exit (0);
+      } 
+      if (graphic[0].Npixels < 16) {
+	fprintf (stderr, "can't even allocate enough cells in private colormap\n");
+	exit (0);
+      }
+    }
+  } else {
+    Npixels = NPIXELS_STATIC;
+    if ((N = get_argument (*argc, argv, "-ncolors"))) {
+      remove_argument(N, argc, argv);
+      Npixels = atoi (argv[N]);
+      remove_argument(N, argc, argv);
+    } 
+
+    // XXX allocate the unsigned long *pixels here and above
+    ALLOCATE (graphic[0].pixels, unsigned long, Npixels);
+    ALLOCATE (graphic[0].cmap,   XColor,        Npixels);
+    graphic[0].Npixels = Npixels;
+  }
+
+  if ((N = get_argument (*argc, argv, "-colorcount"))) {
+    fprintf (stderr, "kii can grab %d colors\n", graphic[0].Npixels);
+    exit (0);
+  } 
+  
+  pixmaps = XListPixmapFormats (graphic[0].display, &Npixmaps);
+  for (i = 0; i < Npixmaps; i++) {
+    if (pixmaps[i].depth == graphic[0].depth) {
+      graphic[0].Nbits = pixmaps[i].bits_per_pixel;
+    }
+  }
+}
Index: trunk/Ohana/src/kapa2/src/CreateZoom16.c
===================================================================
--- trunk/Ohana/src/kapa2/src/CreateZoom16.c	(revision 22713)
+++ 	(revision )
@@ -1,144 +1,0 @@
-# include "Ximage.h"
-
-void CreateZoom16 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
-
-# if (0)
-  int i, j, ii, jj;
-  int i_start, i_end, j_start, j_end;
-  int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY, pixelN;
-  double expand, zoomscale, Rx, Ry;
-  int expand_in, expand_out;
-  unsigned char *out_pix, *out_pix2, *data;
-  float *imdata, *in_pix,  *in_pix2;
-  unsigned char pixel1[256], pixel2[256];
-  unsigned char pixvalue1, pixvalue2;
-  unsigned long back;
-  unsigned char back1, back2;
-
-  dx = image[0].zoom.dx;
-  dy = image[0].zoom.dy;
-
-  if (image[0].image[0].matrix.size == 0) {  /* create a test pattern */
-    REALLOCATE (image[0].zoom.data, char, 2*dy*dx);
-    bzero (image[0].zoom.data, image[0].zoom.dx*image[0].zoom.dy);
-    image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
-				       image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 16, 0);
-    return;
-  }
-
-  for (i = 0; i < 256; i++) { /* set up pixel array */
-    pixel1[i] = 0x0000ff &  graphic[0].cmap[i].pixel;
-    pixel2[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 8);
-  }
-  back = graphic[0].back;
-  back1 = 0x0000ff & back;
-  back2 = 0x0000ff & (back >> 8);
-  // define the color transform parameters
-  MaxValue = graphic[0].Npixels - 1;
-  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;
-  } else {
-    slope = 1.0;
-    start = image[0].image[0].zero;
-  }
-
-  zoomscale = MAX (5, image[0].expand + 5);
-  expand = 1 / zoomscale;
-  expand_out = (int) zoomscale;
-  expand_in  = 1;
-
-  DX = image[0].image[0].matrix.Naxis[0];
-  DY = image[0].image[0].matrix.Naxis[1];
-  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
-  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
-
-  i_start = MIN (MAX (-Rx / expand, (1 - FRAC(Rx)) / expand), dx - expand_out + 1);
-  j_start = MIN (MAX (-Ry / expand, (1 - FRAC(Ry)) / expand), dy - expand_out + 1);
-  i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
-  j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
-  dropback = expand_out - (i_end - i_start) % expand_out;
-  if ((i_end - i_start) % expand_out == 0) dropback = 0;
-
-  data = out_pix = (unsigned char *) image[0].zoom.data;
-  imdata  = (float *) image[0].image[0].matrix.buffer;
-  in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
-
-  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
-
-  if ((i_end < i_start) || (j_end < j_start)) {
-    for (j = 0; j < dx*dy; j++, out_pix++) 
-      *out_pix = back;
-    return;
-  } 
-  
-  /**** fill in bottom area ****/
-  for (j = 0; j < j_start; j++) {
-    for (i = 0; i < dx; i++, out_pix+=2) {
-      out_pix[0] = back1;
-      out_pix[1] = back2;
-    }
-  }
-
-  for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {
-    out_pix = &data[2*j*dx];
-
-    /**** fill in area to the left of the picture ****/
-    for (jj = 0; jj < expand_out; jj++) { 
-      out_pix2 = out_pix + 2*jj*dx;
-      for (i = 0; i < i_start; i++, out_pix2+=2) {
-	out_pix2[0] = back1;
-	out_pix2[1] = back2;
-      }
-    }
-    out_pix += 2*i_start;
-    
-    /*** fill in the picture region ***/
-    in_pix2 = in_pix;
-    if (expand_out == 1) {
-      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=2) {
-	pixelN = PixelLookup(*in_pix2);
-	out_pix[0] = pixel1[pixelN];
-	out_pix[1] = pixel2[pixelN];
-      }
-    } else {
-      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 2*expand_out) { 
-	pixelN = PixelLookup(*in_pix2);
-	pixvalue1 = pixel1[pixelN];
-	pixvalue2 = pixel2[pixelN];
-	out_pix2 = out_pix;
-	for (jj = 0; jj < expand_out; jj++, out_pix2+=2*(dx-expand_out)) {
-	  for (ii = 0; ii < expand_out; ii++, out_pix2+=2) {
-	    out_pix2[0] = pixvalue1; 
-	    out_pix2[1] = pixvalue2; 
-	  }
-	}
-      }
-    }
-    out_pix -= 2*dropback;
-    
-    /**** fill in area to the right of the picture ****/
-    for (jj = 0; jj < expand_out; jj++) {
-      out_pix2 = out_pix + 2*jj*dx;
-      for (i = i_end; i < dx; i++, out_pix2+=2) {
-	out_pix2[0] = back1;
-	out_pix2[1] = back2;
-      }
-    }
-  } 
-  
-  out_pix = &data[2*j_end*dx];
-  /**** fill in top area ****/
-  for (j = 0; j < (dy - j_end); j++) {
-    for (i = 0; i < dx; i++, out_pix+=2) { 
-      out_pix[0] = back1;
-      out_pix[1] = back2;
-    }
-  }
-
-  image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
-					image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 16, 0);
-  
-# endif
-}
Index: trunk/Ohana/src/kapa2/src/CreateZoom24.c
===================================================================
--- trunk/Ohana/src/kapa2/src/CreateZoom24.c	(revision 22713)
+++ 	(revision )
@@ -1,178 +1,0 @@
-# include "Ximage.h"
-
-void CreateZoom24 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
-
-# if (0)
-  int i, j, ii, jj, extra;
-  int i_start, i_end, j_start, j_end;
-  int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY, pixelN;
-  double expand, zoomscale, Rx, Ry;
-  int expand_in, expand_out;
-  unsigned char *out_pix, *out_pix2, *data;
-  float *imdata, *in_pix, *in_pix2;
-  unsigned char pixel1[256], pixel2[256], pixel3[256];
-  unsigned char pixvalue1, pixvalue2, pixvalue3;
-  unsigned long back;
-  unsigned char back1, back2, back3;
-
-  dx = image[0].zoom.dx;
-  dy = image[0].zoom.dy;
-  extra = 4 - (dx * 3) % 4;
-
-  if (image[0].image[0].matrix.size == 0) {  /* create a test pattern */
-    REALLOCATE (image[0].zoom.data, char, dy*(3*dx+extra));
-    bzero (image[0].zoom.data, image[0].zoom.dx*image[0].zoom.dy);
-    image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
-				       image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 32, 0);
-    return;
-  }
-
-  for (i = 0; i < 256; i++) { /* set up pixel array */
-    pixel1[i] = 0x0000ff &  graphic[0].cmap[i].pixel;
-    pixel2[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 8);
-    pixel3[i] = 0x0000ff & (graphic[0].cmap[i].pixel >> 16);
-  }
-  back = graphic[0].back;
-  back1 = 0x0000ff & back;
-  back2 = 0x0000ff & (back >> 8);
-  back3 = 0x0000ff & (back >> 16);
-
-  // define the color transform parameters
-  MaxValue = graphic[0].Npixels - 1;
-  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;
-  } else {
-    slope = 1.0;
-    start = image[0].image[0].zero;
-  }
-
-  zoomscale = MAX (5, image[0].expand + 5);
-  expand = 1 / zoomscale;
-  expand_out = (int) zoomscale;
-  expand_in  = 1;
-
-  DX = image[0].image[0].matrix.Naxis[0];
-  DY = image[0].image[0].matrix.Naxis[1];
-  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
-  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
-
-  i_start = MIN (MAX (-Rx / expand, (1 - FRAC(Rx)) / expand), dx - expand_out + 1);
-  j_start = MIN (MAX (-Ry / expand, (1 - FRAC(Ry)) / expand), dy - expand_out + 1);
-  i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
-  j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
-  dropback = expand_out - (i_end - i_start) % expand_out;
-  if ((i_end - i_start) % expand_out == 0) dropback = 0;
-
-  data = out_pix = (unsigned char *) image[0].zoom.data;
-  imdata  = (float *) image[0].image[0].matrix.buffer;
-  in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
-
-  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
-
-  if ((i_end < i_start) || (j_end < j_start)) {
-    for (j = 0; j < dx*dy; j++, out_pix++) 
-      *out_pix = back;
-    return;
-  } 
-  
-  /**** fill in bottom area ****/
-  for (j = 0; j < j_start; j++) {
-    for (i = 0; i < dx; i++, out_pix+=3) {
-      out_pix[0] = back1;
-      out_pix[1] = back2;
-      out_pix[2] = back3;
-    }
-    out_pix += extra;
-  }
-
-  for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {
-    out_pix = &data[j*(3*dx+extra)];
-
-    /**** fill in area to the left of the picture ****/
-    for (jj = 0; jj < expand_out; jj++) { 
-      out_pix2 = out_pix + jj*(3*dx + extra);
-      for (i = 0; i < i_start; i++, out_pix2+=3) {
-	out_pix2[0] = back1;
-	out_pix2[1] = back2;
-	out_pix2[2] = back3;
-      }
-    }
-    out_pix += 3*i_start;
-    
-    /*** fill in the picture region ***/
-    in_pix2 = in_pix;
-    if (expand_out == 1) {
-      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) {
-	pixelN = PixelLookup(*in_pix2);
-	out_pix[0] = pixel1[pixelN];
-	out_pix[1] = pixel2[pixelN];
-	out_pix[2] = pixel3[pixelN];
-      }
-    } else {
-      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) { 
-	pixelN   = PixelLookup(*in_pix2);
-	pixvalue1 = pixel1[pixelN];
-	pixvalue2 = pixel2[pixelN];
-	pixvalue3 = pixel3[pixelN];
-	out_pix2 = out_pix;
-	for (jj = 0; jj < expand_out; jj++, out_pix2+=3*(dx-expand_out)+extra) {
-	  for (ii = 0; ii < expand_out; ii++, out_pix2+=3) {
-	    out_pix2[0] = pixvalue1; 
-	    out_pix2[1] = pixvalue2; 
-	    out_pix2[2] = pixvalue3; 
-	  }
-	}
-      }
-    }
-    out_pix -= 3*dropback;
-    
-    /**** fill in area to the right of the picture ****/
-    for (jj = 0; jj < expand_out; jj++) {
-      out_pix2 = out_pix + jj*(3*dx+extra);
-      for (i = i_end; i < dx; i++, out_pix2+=3) {
-	out_pix2[0] = back1;
-	out_pix2[1] = back2;
-	out_pix2[2] = back3;
-      }
-    }
-  } 
-  
-  /*
-  if ((j_end - j_start) % expand_out > 0)
-    out_pix -= (expand_out - (j_end - j_start) % expand_out);
-  */
-
-  out_pix = &data[j_end*(3*dx+extra)];
-  /**** fill in top area ****/
-  for (j = 0; j < (dy - j_end); j++) {
-    for (i = 0; i < dx; i++, out_pix+=3) { 
-      out_pix[0] = back1;
-      out_pix[1] = back2;
-      out_pix[2] = back3;
-    }
-    out_pix+=extra;
-  }
-
-  /*
-  out_pix = (unsigned char *) image[0].zoom.data;
-  for (i = 0; i < dx*dy; i++) {
-    out_pix[3*i + 0] = back1;
-    out_pix[3*i + 1] = back2;
-    out_pix[3*i + 2] = back3;
-  }
-  for (j = 0; j < dy/2; j++) {
-    for (i = 0; i < dx; i++) {
-      out_pix[j*(extra + 3*dx) + 3*i + 0] = pixel1[10];
-      out_pix[j*(extra + 3*dx) + 3*i + 1] = pixel2[10];
-      out_pix[j*(extra + 3*dx) + 3*i + 2] = pixel3[10];
-    }
-
-  }
-  */
-  image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, 24, ZPixmap, 0, 
-					image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 32, 0);
-  
-# endif
-}
Index: trunk/Ohana/src/kapa2/src/CreateZoom32.c
===================================================================
--- trunk/Ohana/src/kapa2/src/CreateZoom32.c	(revision 22713)
+++ 	(revision )
@@ -1,138 +1,0 @@
-# include "Ximage.h"
-
-void CreateZoom32 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
-
-  int i, j, ii, jj;
-  int i_start, i_end, j_start, j_end;
-  int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY;
-  double expand, Ix, Iy;
-  int expand_in, expand_out;
-  unsigned int *out_pix, *out_pix2;
-  unsigned short *in_pix, *in_pix2;
-  unsigned long *pixel, pixvalue;
-  unsigned long back;
-
-  if (image[0].image[0].matrix.size == 0) {  /* create a test pattern */
-    REALLOCATE (image[0].zoom.data, char, 4*image[0].zoom.dx*image[0].zoom.dy);
-    image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
-				       image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 32, 0);
-    return;
-  }
-
-  ALLOCATE (pixel, unsigned long, graphic[0].Npixels);
-
-  // local array for pixel values
-  for (i = 0; i < graphic[0].Npixels; i++) { 
-    pixel[i] = graphic[0].cmap[i].pixel;
-  }
-  back = graphic[0].back;
-
-  // set up expansions
-  assert ((image[0].zoom.expand >= 1) || (image[0].zoom.expand <= -2));
-  expand = expand_in = expand_out = 1.0;
-  if (image[0].zoom.expand > 0) {
-    expand = 1 / (1.0*image[0].zoom.expand);
-    expand_out = image[0].zoom.expand;
-    expand_in  = 1;
-  }
-  if (image[0].zoom.expand < 0) {
-    expand = fabs((double)image[0].zoom.expand);
-    expand_out = 1;
-    expand_in  = -image[0].zoom.expand;
-  }
-
-  // define the image sizes
-  dx = image[0].zoom.dx;
-  dy = image[0].zoom.dy;
-  DX = image[0].image[0].matrix.Naxis[0];
-  DY = image[0].image[0].matrix.Naxis[1];
-  
-  // x, y are the closest lit screen pixel to 0,0
-  Picture_Lower (&i_start, &j_start, &image[0].image[0].matrix, &image[0].zoom);
-
-  // x, y are the closest lit screen pixel to dx, dy
-  Picture_Upper (&i_end, &j_end, &image[0].image[0].matrix, &image[0].zoom);
-
-  // Ix,Iy are the first displayed image pixel
-  Picture_to_Image (&Ix, &Iy, i_start, j_start, &image[0].zoom);
-
-  dropback = expand_out - (i_end - i_start) % expand_out;
-  if ((i_end - i_start) % expand_out == 0) dropback = 0;
-
-  out_pix = (unsigned int *) image[0].zoom.data;
-  in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
-
-  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
-
-  // XXX can we just drop this?
-  if ((i_end < i_start) || (j_end < j_start)) {
-    for (j = 0; j < dx*dy; j++, out_pix++) 
-      *out_pix = back;
-    return;
-  } 
-
-  /**** fill in bottom area ****/
-  for (j = 0; j < dx*j_start; j++, out_pix++) {
-    *out_pix = back;
-  }
-
-  for (j = j_start; j < j_end; j+= expand_out, out_pix+=(expand_out-1)*dx, in_pix += expand_in*DX) {
-
-    /**** fill in area to the left of the picture ****/
-    for (jj = 0; (i_start > 0) && (jj < expand_out); jj++) { 
-      out_pix2 = out_pix + jj*dx;
-      for (i = 0; i < i_start; i++, out_pix2++) {
-	*out_pix2 = back;
-      }
-    }
-    out_pix += i_start;
-    
-    /*** fill in the picture region ***/
-    in_pix2 = in_pix;
-    if (expand_out == 1) {
-      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
-	*out_pix = pixel[*in_pix2];
-      }
-    } else {
-      // equiv to : out_pix += (i_end - i_start) + [expand_out - (i_end - i_start) % expand_out]
-      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
-	pixvalue = pixel[*in_pix2];
-	out_pix2 = out_pix;
-	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
-	  for (ii = 0; ii < expand_out; ii++, out_pix2++) {
-	    *out_pix2 = pixvalue; 
-	  }
-	}
-      }
-    }
-    out_pix -= dropback;
-    
-    /**** fill in area to the right of the picture ****/
-    for (jj = 0; jj < expand_out; jj++) {
-      out_pix2 = out_pix + jj*dx;
-      for (i = i_end; i < dx; i++, out_pix2++) {
-	*out_pix2 = back;
-      }
-    }
-    out_pix += (dx - i_end);
-    assert (out_pix - (unsigned int *)image[0].zoom.data <= dx*dy);
-  } 
-  assert (out_pix - (unsigned int *)image[0].zoom.data <= dx*dy);
-  
-  if ((j_end - j_start) % expand_out > 0)
-    out_pix -= (expand_out - (j_end - j_start) % expand_out);
-  
-  assert (out_pix - (unsigned int *)image[0].zoom.data <= dx*dy);
-
-  /**** fill in top area ****/
-  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned int *)image[0].zoom.data < dx*dy); j++, out_pix++) { 
-    *out_pix = back;
-  }
-  assert (out_pix - (unsigned int *)image[0].zoom.data <= dx*dy);
-
-  image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
-					image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 32, 0);
-  
-  free (pixel);
-}
Index: trunk/Ohana/src/kapa2/src/CreateZoom8.c
===================================================================
--- trunk/Ohana/src/kapa2/src/CreateZoom8.c	(revision 22713)
+++ 	(revision )
@@ -1,130 +1,0 @@
-# include "Ximage.h"
-
-void CreateZoom8 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
-
-# if (0)
-  int i, j, ii, jj;
-  int i_start, i_end, j_start, j_end;
-  int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY, pixelN;
-  double expand, zoomscale, Rx, Ry;
-  int expand_in, expand_out;
-  unsigned char *out_pix, *out_pix2;
-  float *imdata, *in_pix, *in_pix2;
-  unsigned long pixel[256], pixvalue;
-  unsigned long back;
-
-  if (image[0].image[0].matrix.size == 0) {  /* create a test pattern */
-    REALLOCATE (image[0].zoom.data, char, image[0].zoom.dx*image[0].zoom.dy);
-    bzero (image[0].zoom.data, image[0].zoom.dx*image[0].zoom.dy);
-    image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
-				       image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 8, 0);
-    return;
-  }
-
-  for (i = 0; i < 256; i++) { /* set up pixel array */
-    pixel[i] = graphic[0].cmap[i].pixel;
-  }
-  back = graphic[0].back;
-
-  // define the color transform parameters
-  MaxValue = graphic[0].Npixels - 1;
-  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;
-  } else {
-    slope = 1.0;
-    start = image[0].image[0].zero;
-  }
-
-  zoomscale = MAX (5, image[0].expand + 5);
-  expand = 1 / zoomscale;
-  expand_out = (int) zoomscale;
-  expand_in  = 1;
-
-  dx = image[0].zoom.dx;
-  dy = image[0].zoom.dy;
-  DX = image[0].image[0].matrix.Naxis[0];
-  DY = image[0].image[0].matrix.Naxis[1];
-  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
-  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
-
-  i_start = MIN (MAX (-Rx / expand, (1 - FRAC(Rx)) / expand), dx - expand_out + 1);
-  j_start = MIN (MAX (-Ry / expand, (1 - FRAC(Ry)) / expand), dy - expand_out + 1);
-  i_end   = MAX (MIN ((DX-Rx) / expand, dx - expand_out + 1), 0);
-  j_end   = MAX (MIN ((DY-Ry) / expand, dy - expand_out + 1), 0);
-  dropback = expand_out - (i_end - i_start) % expand_out;
-  if ((i_end - i_start) % expand_out == 0) dropback = 0;
-
-  out_pix = (unsigned char *) image[0].zoom.data;
-  imdata  = (float *) image[0].image[0].matrix.buffer;
-  in_pix  = &imdata[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
-
-  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
-
-  if ((i_end < i_start) || (j_end < j_start)) {
-    for (j = 0; j < dx*dy; j++, out_pix++) 
-      *out_pix = back;
-    return;
-  } 
-  
-  /**** fill in bottom area ****/
-  for (j = 0; j < dx*j_start; j++, out_pix++) 
-    *out_pix = back;
-  
-  for (j = j_start; j < j_end; j+= expand_out, out_pix+=(expand_out-1)*dx, in_pix += expand_in*DX) {
-
-    /**** fill in area to the left of the picture ****/
-    for (jj = 0; jj < expand_out; jj++) { 
-      out_pix2 = out_pix + jj*dx;
-      for (i = 0; i < i_start; i++, out_pix2++) {
-	*out_pix2 = back;
-      }
-    }
-    out_pix += i_start;
-    
-    /*** fill in the picture region ***/
-    in_pix2 = in_pix;
-    if (expand_out == 1) {
-      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
-	pixelN = PixelLookup(*in_pix2);
-	*out_pix = pixel[pixelN];
-      }
-    } else {
-      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
-	pixelN   = PixelLookup(*in_pix2);
-	pixvalue = pixel[pixelN];
-	out_pix2 = out_pix;
-	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
-	  for (ii = 0; ii < expand_out; ii++, out_pix2++) {
-	    *out_pix2 = pixvalue;
-	  }
-	}
-      }
-    }
-    out_pix -= dropback;
-    
-    /**** fill in area to the right of the picture ****/
-    for (jj = 0; jj < expand_out; jj++) {
-      out_pix2 = out_pix + jj*dx;
-      for (i = i_end; i < dx; i++, out_pix2++) {
-	*out_pix2 = back;
-      }
-    }
-    out_pix += (dx - i_end);
-    
-  } 
-  
-  if ((j_end - j_start) % expand_out > 0)
-    out_pix -= expand_out - (j_end - j_start) % expand_out;
-  
-  /**** fill in top area ****/
-  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned char *) image[0].zoom.data < dx*dy); j++, out_pix++) { 
-    *out_pix = back;
-  }
-
-  image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
-					image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 8, 0);
-  
-# endif
-}
Index: trunk/Ohana/src/kapa2/src/CursorOps.c
===================================================================
--- trunk/Ohana/src/kapa2/src/CursorOps.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/CursorOps.c	(revision 25757)
@@ -2,4 +2,5 @@
 
 // input coordinates are relative to the picture bounding box
+// XXX pre-calculate fexpand, Xc, Yc when expand is set?
 void Picture_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) {
 
@@ -14,10 +15,14 @@
   
   // pixel coordinates in picture frame
-  dx = expand*(x2 - 0.5*picture[0].dx);
-  dy = expand*(y2 - 0.5*picture[0].dy);
+  dx = expand*(x2 - (int)(0.5*picture[0].dx));
+  dy = expand*(y2 - (int)(0.5*picture[0].dy));
+
+  // set the true center (image and screen pixel boundaries must be aligned)
+  // Xc = (int)(picture[0].Xc / expand) * expand;
+  // Yc = (int)(picture[0].Yc / expand) * expand;
 
   // picture[0].X,Y is the image coordinate in the center of the picture
-  *x1 = picture[0].flipx ? picture[0].X - dx : picture[0].X + dx;
-  *y1 = picture[0].flipy ? picture[0].Y - dy : picture[0].Y + dy;
+  *x1 = picture[0].flipx ? picture[0].Xc - dx : picture[0].Xc + dx;
+  *y1 = picture[0].flipy ? picture[0].Yc - dy : picture[0].Yc + dy;
 }
 
@@ -46,10 +51,14 @@
   }
   
+  // set the true center (image and screen pixel boundaries must be aligned)
+  // Xc = ((int)(picture[0].Xc * expand)) / expand;
+  // Yc = ((int)(picture[0].Yc * expand)) / expand;
+
   // pixel coordinates in picture frame
-  dx = picture[0].flipx ? picture[0].X - x2 : x2 - picture[0].X;
-  dy = picture[0].flipy ? picture[0].Y - y2 : y2 - picture[0].Y;
+  dx = picture[0].flipx ? picture[0].Xc - x2 : x2 - picture[0].Xc;
+  dy = picture[0].flipy ? picture[0].Yc - y2 : y2 - picture[0].Yc;
     
-  *x1 = expand*dx + 0.5*picture[0].dx;
-  *y1 = expand*dy + 0.5*picture[0].dy;
+  *x1 = expand*dx + (int)(0.5*picture[0].dx);
+  *y1 = expand*dy + (int)(0.5*picture[0].dy);
 }
 
@@ -66,5 +75,5 @@
 
 // input coordinates are relative to the picture bounding box
-void Picture_Lower (int *i_start, int *j_start, Matrix *matrix, Picture *picture) {
+void Picture_Lower (int *i_start, int *j_start, int *I_start, int *J_start, Matrix *matrix, Picture *picture) {
 
   double Ix, Iy, Sx, Sy;
@@ -72,8 +81,4 @@
   // Ix, Iy are the image coordinates of the specified screen pixel
   Picture_to_Image (&Ix, &Iy, 0.0, 0.0, picture);
-
-  // Ix, Iy are now limited to valid image coordinates
-  Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]);
-  Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
 
   // round up (down) to nearest pixel boundary
@@ -84,4 +89,12 @@
     Iy = picture[0].flipy ? (int)(Iy) : (int)(Iy) + 1;
   }
+
+  // Ix, Iy are now limited to valid image coordinates
+  Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]);
+  Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
+
+  // I_start, J_start are the first displayed image pixel 
+  *I_start = Ix;
+  *J_start = Iy;
 
   // Sx, Sy are the screen coordinates of the Ix,Iy pixel
@@ -94,6 +107,7 @@
   
 // input coordinates are relative to the picture bounding box
-void Picture_Upper (int *i_end, int *j_end, Matrix *matrix, Picture *picture) {
+void Picture_Upper (int *i_end, int *j_end, int i_start, int j_start, Matrix *matrix, Picture *picture) {
 
+  int nExtra;
   double Ix, Iy, Sx, Sy;
 
@@ -101,15 +115,19 @@
   Picture_to_Image (&Ix, &Iy, picture[0].dx, picture[0].dy, picture);
 
+  // round down (up) to nearest pixel boundary
+  if (Ix > (int)(Ix)) {
+    Ix = picture[0].flipx ? (int)(Ix) + 1: (int)(Ix);
+  }
+  if (Iy > (int)(Iy)) {
+    Iy = picture[0].flipy ? (int)(Iy) + 1: (int)(Iy);
+  }
+
   // Ix, Iy are now limited to valid image coordinates
   Ix = MIN (MAX (Ix, 0), matrix[0].Naxis[0]);
   Iy = MIN (MAX (Iy, 0), matrix[0].Naxis[1]);
 
-  // round down (up) to nearest pixel boundary
-  if (Ix > (int)(Ix)) {
-    Ix = picture[0].flipx ? (int)(Ix) + 1 : (int)(Ix);
-  }
-  if (Iy > (int)(Iy)) {
-    Iy = picture[0].flipy ? (int)(Iy) + 1: (int)(Iy);
-  }
+  // I_end, J_end are the last displayed image pixel 
+  // *I_end = Ix;
+  // *J_end = Iy;
 
   // Sx, Sy are the screen coordinates of the Ix,Iy pixel
@@ -119,3 +137,11 @@
   *i_end = MIN (MAX (Sx, 0), picture[0].dx);
   *j_end = MIN (MAX (Sy, 0), picture[0].dy);
+
+  // round off error can leave us with a small number of extra pixels here.
+  if (picture[0].expand > 1) {
+    nExtra = (*i_end - i_start) % picture[0].expand;
+    *i_end -= nExtra;
+    nExtra = (*j_end - j_start) % picture[0].expand;
+    *j_end -= nExtra;
+  }
 }
Index: trunk/Ohana/src/kapa2/src/DragColorbar.c
===================================================================
--- trunk/Ohana/src/kapa2/src/DragColorbar.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/DragColorbar.c	(revision 25757)
@@ -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: trunk/Ohana/src/kapa2/src/Image.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Image.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/Image.c	(revision 25757)
@@ -48,18 +48,18 @@
 
   // set the center and expansion for the pictures:
-  image[0].picture.X      = 0.0;
-  image[0].picture.Y      = 0.0;
+  image[0].picture.Xc     = 0.0;
+  image[0].picture.Yc     = 0.0;
   image[0].picture.expand = 1;
   image[0].picture.flipx  = FALSE;
   image[0].picture.flipy  = FALSE;
 
-  image[0].zoom.X      	  = 0.0;
-  image[0].zoom.Y      	  = 0.0;
-  image[0].zoom.expand 	  = +5;
+  image[0].zoom.Xc     	  = 0.0;
+  image[0].zoom.Yc     	  = 0.0;
+  image[0].zoom.expand 	  = 5;
   image[0].zoom.flipx  	  = FALSE;
   image[0].zoom.flipy  	  = FALSE;
 
-  image[0].wide.X      	  = 0.0;
-  image[0].wide.Y      	  = 0.0;
+  image[0].wide.Xc     	  = 0.0;
+  image[0].wide.Yc     	  = 0.0;
   image[0].wide.expand 	  = -5;
   image[0].wide.flipx  	  = FALSE;
@@ -144,8 +144,10 @@
 		  image[0].picture.dx+1, image[0].picture.dy+1);
   
-  XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
-	     image[0].picture.pix, 0, 0, 
-	     image[0].picture.x + 1, image[0].picture.y + 1, 
-	     image[0].picture.dx, image[0].picture.dy);
+  if (image[0].picture.pix) {
+    XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
+	       image[0].picture.pix, 0, 0, 
+	       image[0].picture.x + 1, image[0].picture.y + 1, 
+	       image[0].picture.dx, image[0].picture.dy);
+  }
 
   for (i = 0; i < NOVERLAYS; i++) {
@@ -156,13 +158,16 @@
 
   if (image[0].location) {
-    XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
-	       image[0].cmapbar.pix, 0, 0, 
-	       image[0].cmapbar.x, image[0].cmapbar.y, 
-	       image[0].cmapbar.dx, image[0].cmapbar.dy);
-
-    XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
-	       image[0].wide.pix, 0, 0, 
-	       image[0].wide.x, image[0].wide.y, 
-	       image[0].wide.dx, image[0].wide.dy);
+    if (image[0].cmapbar.pix) {
+      XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
+		 image[0].cmapbar.pix, 0, 0, 
+		 image[0].cmapbar.x, image[0].cmapbar.y, 
+		 image[0].cmapbar.dx, image[0].cmapbar.dy);
+    }
+    if (image[0].wide.pix) {
+	XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
+		   image[0].wide.pix, 0, 0, 
+		   image[0].wide.x, image[0].wide.y, 
+		   image[0].wide.dx, image[0].wide.dy);
+    }
 
     CrossHairs (graphic, &image[0].zoom);
Index: trunk/Ohana/src/kapa2/src/InterpretKeys.c
===================================================================
--- trunk/Ohana/src/kapa2/src/InterpretKeys.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/InterpretKeys.c	(revision 25757)
@@ -93,5 +93,5 @@
       SetColorScale (graphic, image);
       Remap (graphic, image);
-      Reorient (graphic, image, image[0].picture.X, image[0].picture.Y, 0);
+      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
       break;
 
@@ -100,5 +100,5 @@
       SetColorScale (graphic, image);
       Remap (graphic, image);
-      Reorient (graphic, image, image[0].picture.X, image[0].picture.Y, 0);
+      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
       break;
 
@@ -107,5 +107,5 @@
       SetColorScale (graphic, image);
       Remap (graphic, image);
-      Reorient (graphic, image, image[0].picture.X, image[0].picture.Y, 0);
+      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
       break;
 
@@ -113,9 +113,11 @@
     case XK_Home:
       image[0].picture.expand = 1;
-      Reorient (graphic, image, image[0].picture.X, image[0].picture.Y, 0);
+      image[0].zoom.expand = 5;
+      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
       break;
     case XK_KP_End:
     case XK_End:
       image[0].picture.expand = 1;
+      image[0].zoom.expand = 5;
       Reorient (graphic, image, 0.5*image[0].image[0].matrix.Naxis[0], 0.5*image[0].image[0].matrix.Naxis[1], 0);
       break;
@@ -128,25 +130,25 @@
     case XK_Prior:
     case XK_KP_Prior:
-      Reorient (graphic, image, image[0].picture.X, image[0].picture.Y, +1);
+      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, +1);
       break;
     case XK_Next:
     case XK_KP_Next:
-      Reorient (graphic, image, image[0].picture.X, image[0].picture.Y, -1);
+      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, -1);
       break;
     case XK_Up:
     case XK_KP_Up:
-      Reorient (graphic, image, image[0].picture.X, image[0].picture.Y + offset, 0);
+      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc + offset, 0);
       break;
     case XK_Down:
     case XK_KP_Down:
-      Reorient (graphic, image, image[0].picture.X, image[0].picture.Y - offset, 0);
+      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc - offset, 0);
       break;
     case XK_Left:
     case XK_KP_Left:
-      Reorient (graphic, image, image[0].picture.X + offset, image[0].picture.Y, 0);
+      Reorient (graphic, image, image[0].picture.Xc + offset, image[0].picture.Yc, 0);
       break;
     case XK_Right:
     case XK_KP_Right:
-      Reorient (graphic, image, image[0].picture.X - offset, image[0].picture.Y, 0);
+      Reorient (graphic, image, image[0].picture.Xc - offset, image[0].picture.Yc, 0);
       break;
 
@@ -160,5 +162,5 @@
       SetColorScale (graphic, image);
       Remap (graphic, image);
-      Reorient (graphic, image, image[0].picture.X, image[0].picture.Y, 0);
+      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
       break;
     case XK_KP_Subtract:
@@ -171,5 +173,5 @@
       SetColorScale (graphic, image);
       Remap (graphic, image);
-      Reorient (graphic, image, image[0].picture.X, image[0].picture.Y, 0);
+      Reorient (graphic, image, image[0].picture.Xc, image[0].picture.Yc, 0);
       break;
 
Index: trunk/Ohana/src/kapa2/src/JPEGit24.c
===================================================================
--- trunk/Ohana/src/kapa2/src/JPEGit24.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/JPEGit24.c	(revision 25757)
@@ -22,4 +22,5 @@
   int ii, i, j;
   int i_start, i_end, j_start, j_end;
+  int I_start, J_start;
   int dropback;  /* this is a bit of a kludge... */
   int dx, dy, DX, DY, inDX, inDY;
@@ -95,17 +96,17 @@
   DY = image[0].image[0].matrix.Naxis[1];
 
-  // x, y are the closest lit screen pixel to 0,0
-  Picture_Lower (&i_start, &j_start, &image[0].image[0].matrix, &image[0].picture);
-
-  // x, y are the closest lit screen pixel to dx, dy
-  Picture_Upper (&i_end, &j_end, &image[0].image[0].matrix, &image[0].picture);
-
-  if (i_end < i_start) MY_SWAP_INT (i_start, i_end);
-  if (j_end < j_start) MY_SWAP_INT (j_start, j_end);
-
-  // Ix,Iy are the first displayed image pixel
-  Picture_to_Image (&Ix, &Iy, i_start, j_start, &image[0].picture);
-  Ix = MIN (MAX (0, Ix), DX - 1);
-  Iy = MIN (MAX (0, Iy), DY - 1);
+  // i_start, j_start are the closest lit screen pixel to 0,0
+  // I_start, J_start are the image pixel corresponding to i_start, j_start
+  Picture_Lower (&i_start, &j_start, &I_start, &J_start, &image[0].image[0].matrix, &image[0].picture);
+
+  // i_end, j_end are the closest lit screen pixel to dx, dy
+  // I_end, J_end are the image pixel corresponding to i_end, j_end
+  Picture_Upper (&i_end, &j_end, i_start, j_start, &image[0].image[0].matrix, &image[0].picture);
+
+  assert (i_start <= i_end);
+  assert (j_start <= j_end);
+
+  Ix = image[0].picture.flipx ? I_start - 1 : I_start;
+  Iy = image[0].picture.flipy ? J_start - 1 : J_start;
 
   inDX = image[0].picture.flipx ? -1 : +1;
Index: trunk/Ohana/src/kapa2/src/LoadPicture.c
===================================================================
--- trunk/Ohana/src/kapa2/src/LoadPicture.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/LoadPicture.c	(revision 25757)
@@ -25,6 +25,7 @@
   Yoffset = 0.0;
   if (image[0].image[0].matrix.size) {
-    Xoffset = image[0].picture.X - 0.5*image[0].image[0].matrix.Naxis[0];
-    Yoffset = image[0].picture.Y - 0.5*image[0].image[0].matrix.Naxis[1];
+    // XXX enforce int center here?
+    Xoffset = image[0].picture.Xc - 0.5*image[0].image[0].matrix.Naxis[0];
+    Yoffset = image[0].picture.Yc - 0.5*image[0].image[0].matrix.Naxis[1];
   }
 
@@ -49,6 +50,6 @@
 
   // reference point for image is the center pixel
-  image[0].picture.X = 0.5*header.Naxis[0] + Xoffset;
-  image[0].picture.Y = 0.5*header.Naxis[1] + Yoffset;
+  image[0].picture.Xc = 0.5*header.Naxis[0] + Xoffset;
+  image[0].picture.Yc = 0.5*header.Naxis[1] + Yoffset;
 
   // choose expand for wide to guarantee we fit:
@@ -59,6 +60,6 @@
     image[0].wide.expand = 1.0 / wx;
   }    
-  image[0].wide.X = 0.5*header.Naxis[0];
-  image[0].wide.Y = 0.5*header.Naxis[1];
+  image[0].wide.Xc = 0.5*header.Naxis[0];
+  image[0].wide.Yc = 0.5*header.Naxis[1];
 
   fcntl (sock, F_SETFL, O_NONBLOCK);  
Index: trunk/Ohana/src/kapa2/src/MakeColormap.c
===================================================================
--- trunk/Ohana/src/kapa2/src/MakeColormap.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/MakeColormap.c	(revision 25757)
@@ -2,4 +2,5 @@
 
 static char default_cmap[] = "grayscale";
+// static char default_cmap[] = "heat";
 
 void MakeColormap (int argc, char **argv) {
Index: trunk/Ohana/src/kapa2/src/PSOverlay.c
===================================================================
--- trunk/Ohana/src/kapa2/src/PSOverlay.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/PSOverlay.c	(revision 25757)
@@ -80,11 +80,11 @@
 	  double sn = sin(angle);
 	  x0 = X + pX*dX*cs;
-	  y0 = Y + pY*dX*sn;
+	  y0 = Y - pY*dX*sn;
 	  // XXX dt should be based on the size of the ellipse...
 	  // 0.10 -> 60 segments on the ellipse
 	  # define DT 0.1
 	  for (t = DT; t < 2*M_PI + DT; t+=DT) {
-	    x1 = X + pX*dX*cos(t)*cs - pX*dY*sin(t)*sn;
-	    y1 = Y + pY*dX*cos(t)*sn + pY*dY*sin(t)*cs;
+	    x1 = X + pX*dX*cos(t)*cs + pX*dY*sin(t)*sn;
+	    y1 = Y - pY*dX*cos(t)*sn + pY*dY*sin(t)*cs;
 	    fprintf (f, " %6.1f %6.1f %6.1f %6.1f L\n", x0 + extra, y0 + extra, x1 + extra, y1 + extra);
 	    x0 = x1;
Index: trunk/Ohana/src/kapa2/src/PaintOverlay.c
===================================================================
--- trunk/Ohana/src/kapa2/src/PaintOverlay.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/PaintOverlay.c	(revision 25757)
@@ -9,5 +9,5 @@
  
   XSetForeground (graphic[0].display, graphic[0].gc, image[0].overlay[N].color);
-  XSetLineAttributes (graphic->display, graphic->gc, 2, LineSolid, CapNotLast, JoinMiter);
+  XSetLineAttributes (graphic->display, graphic->gc, 1, LineSolid, CapNotLast, JoinMiter);
   
   expand = 1.0;
@@ -72,11 +72,11 @@
 	  double sn = sin(angle);
 	  x0 = X + pX*dx*cs;
-	  y0 = Y - pY*dx*sn;
+	  y0 = Y + pY*dx*sn;
 	  // XXX dt should be based on the size of the ellipse...
 	  // 0.10 -> 60 segments on the ellipse
 	  # define DT 0.1
 	  for (t = DT; t < 2*M_PI + DT; t+=DT) {
-	    x1 = X + pX*dx*cos(t)*cs + pX*dy*sin(t)*sn;
-	    y1 = Y - pY*dx*cos(t)*sn + pY*dy*sin(t)*cs;
+	    x1 = X + pX*dx*cos(t)*cs - pX*dy*sin(t)*sn;
+	    y1 = Y + pY*dx*cos(t)*sn + pY*dy*sin(t)*cs;
 	    XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, x0, y0, x1, y1);
 	    x0 = x1;
Index: trunk/Ohana/src/kapa2/src/Relocate.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Relocate.c	(revision 25757)
+++ trunk/Ohana/src/kapa2/src/Relocate.c	(revision 25757)
@@ -0,0 +1,30 @@
+# include "Ximage.h"
+
+// XXX Should there be a base command + KiiMessage command?
+int Relocate (int sock) {
+ 
+  int i, Nsection;
+  int x, y, dX, dY;
+  Graphic *graphic;
+  Section *section;
+
+  graphic = GetGraphic();
+
+  KiiScanMessage (sock, "%d %d", &x, &y);
+
+  if (!USE_XWINDOW) return (TRUE);
+
+  dX = DisplayWidth  (graphic->display, graphic->screen);
+  dY = DisplayHeight (graphic->display, graphic->screen);
+
+  // let's not lose the window
+  x = MAX(0, MIN(x, dX - 10)); 
+  y = MAX(0, MIN(y, dY - 10)); 
+
+  XMoveWindow (graphic->display, graphic->window, x, y);
+
+  // if (USE_XWINDOW) XClearWindow (graphic->display, graphic->window);
+  // Refresh ();
+
+  return (TRUE);
+}
Index: trunk/Ohana/src/kapa2/src/Remap16.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Remap16.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/Remap16.c	(revision 25757)
@@ -1,3 +1,4 @@
 # include "Ximage.h"
+# define OUT_TYPE unsigned short
 
 # define MY_SWAP_BYTE(W) { \
@@ -10,15 +11,21 @@
   int i, j, ii, jj;
   int i_start, i_end, j_start, j_end;
-  int dropback;
+  int I_start, J_start;
+  int dropback, inDX, inDY;
   int dx, dy, DX, DY;
   double expand, Ix, Iy;
   int expand_in, expand_out;
-  unsigned short *out_pix, *out_pix2, *data;
+  OUT_TYPE *out_pix, *out_pix2, *data;
   unsigned short *in_pix, *in_pix2;
-  unsigned short *pixel, pixvalue;
-  unsigned short back;
+  OUT_TYPE *pixel, pixvalue;
+  OUT_TYPE back;
   int swap_client, swap_server, swap_bytes;
 
-  ALLOCATE (pixel, unsigned short, graphic[0].Npixels);
+  // just skip if there is no data
+  if (matrix[0].Naxes == 0) return;
+  if (matrix[0].Naxis[0] == 0) return;
+  if (matrix[0].Naxis[1] == 0) return;
+
+  ALLOCATE (pixel, OUT_TYPE, graphic[0].Npixels);
 
 # ifdef BYTE_SWAP
@@ -38,5 +45,4 @@
   back = 0xffff & graphic[0].back;
   if (swap_bytes) MY_SWAP_BYTE (back);
-  // XXX not certain this is the correct solution...
 
   // set up expansions
@@ -60,17 +66,25 @@
   DY = matrix[0].Naxis[1];
 
-  // x, y are the closest lit screen pixel to 0,0
-  Picture_Lower (&i_start, &j_start, matrix, picture);
+  // i_start, j_start are the closest lit screen pixel to 0,0
+  // I_start, J_start are the image pixel corresponding to i_start, j_start
+  Picture_Lower (&i_start, &j_start, &I_start, &J_start, matrix, picture);
 
-  // x, y are the closest lit screen pixel to dx, dy
-  Picture_Upper (&i_end, &j_end, matrix, picture);
+  // i_end, j_end are the closest lit screen pixel to dx, dy
+  // I_end, J_end are the image pixel corresponding to i_end, j_end
+  Picture_Upper (&i_end, &j_end, i_start, j_start, matrix, picture);
 
-  // Ix,Iy are the first displayed image pixel
-  Picture_to_Image (&Ix, &Iy, i_start, j_start, picture);
+  assert (i_start <= i_end);
+  assert (j_start <= j_end);
+
+  Ix = picture[0].flipx ? I_start - 1 : I_start;
+  Iy = picture[0].flipy ? J_start - 1 : J_start;
+
+  inDX = picture[0].flipx ? -1 : +1;
+  inDY = picture[0].flipy ? -1 : +1;
 
   dropback = expand_out - (i_end - i_start) % expand_out;
   if ((i_end - i_start) % expand_out == 0) dropback = 0;
 
-  data = out_pix = (unsigned short *) picture[0].data;
+  out_pix = data = (OUT_TYPE *) picture[0].data;
   in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
 
@@ -82,5 +96,5 @@
   }
   
-  for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {
+  for (j = j_start; j < j_end; j+= expand_out, in_pix += inDY*expand_in*DX) {
     out_pix = &data[j*dx];
 
@@ -97,9 +111,9 @@
     in_pix2 = in_pix;
     if (expand_out == 1) {
-      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
+      for (i = i_start; i < i_end; i++, in_pix2 += inDX*expand_in, out_pix++) {
 	*out_pix = pixel[*in_pix2];
       }
     } else {
-      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2 += inDX, out_pix+= expand_out) { 
 	pixvalue = pixel[*in_pix2];
 	out_pix2 = out_pix;
@@ -124,5 +138,5 @@
   /**** fill in top area ****/
   out_pix = &data[j_end*dx];
-  for (j = 0; j < (dy - j_end); j++) {
+  for (j = 0; j < dy - j_end; j++) {
     for (i = 0; i < dx; i++, out_pix++) { 
       *out_pix = back;
Index: trunk/Ohana/src/kapa2/src/Remap24.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Remap24.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/Remap24.c	(revision 25757)
@@ -5,5 +5,6 @@
   int i, j, ii, jj;
   int i_start, i_end, j_start, j_end;
-  int dropback, extra;
+  int I_start, J_start;
+  int dropback, extra, inDX, inDY;
   int dx, dy, DX, DY;
   double expand, Ix, Iy;
@@ -53,12 +54,20 @@
   extra = 4 - (dx * 3) % 4;
 
-  // x, y are the closest lit screen pixel to 0,0
-  Picture_Lower (&i_start, &j_start, matrix, picture);
+  // i_start, j_start are the closest lit screen pixel to 0,0
+  // I_start, J_start are the image pixel corresponding to i_start, j_start
+  Picture_Lower (&i_start, &j_start, &I_start, &J_start, matrix, picture);
 
-  // x, y are the closest lit screen pixel to dx, dy
-  Picture_Upper (&i_end, &j_end, matrix, picture);
+  // i_end, j_end are the closest lit screen pixel to dx, dy
+  // I_end, J_end are the image pixel corresponding to i_end, j_end
+  Picture_Upper (&i_end, &j_end, i_start, j_start, matrix, picture);
 
-  // Ix,Iy are the first displayed image pixel
-  Picture_to_Image (&Ix, &Iy, i_start, j_start, picture);
+  assert (i_start <= i_end);
+  assert (j_start <= j_end);
+
+  Ix = picture[0].flipx ? I_start - 1 : I_start;
+  Iy = picture[0].flipy ? J_start - 1 : J_start;
+
+  inDX = picture[0].flipx ? -1 : +1;
+  inDY = picture[0].flipy ? -1 : +1;
 
   dropback = expand_out - (i_end - i_start) % expand_out;
@@ -80,5 +89,5 @@
   }
   
-  for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {
+  for (j = j_start; j < j_end; j+= expand_out, in_pix += inDY*expand_in*DX) {
     out_pix = &data[j*(3*dx+extra)];
 
@@ -97,5 +106,5 @@
     in_pix2 = in_pix;
     if (expand_out == 1) {
-      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) {
+      for (i = i_start; i < i_end; i++, in_pix2+= inDX*expand_in, out_pix+=3) {
 	out_pix[0] = pixel1[*in_pix2];
 	out_pix[1] = pixel2[*in_pix2];
@@ -103,5 +112,5 @@
       }
     } else {
-      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) { 
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2 += inDX, out_pix+= 3*expand_out) { 
 	pixvalue1 = pixel1[*in_pix2];
 	pixvalue2 = pixel2[*in_pix2];
@@ -121,5 +130,4 @@
     /**** fill in area to the right of the picture ****/
     for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++) {
-      //    for (jj = 0; jj < expand_out; jj++) {
       out_pix2 = out_pix + jj*(3*dx+extra);
       for (i = i_end; i < dx; i++, out_pix2+=3) {
Index: trunk/Ohana/src/kapa2/src/Remap32.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Remap32.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/Remap32.c	(revision 25757)
@@ -1,11 +1,12 @@
 # include "Ximage.h"
+# define OUT_TYPE unsigned int
 
 # define MY_SWAP_INT(A,B) { int tmp; tmp = A; A = B; B = tmp; }
 
-# define MY_SWAP_WORD(W) { \
-  char tmp, *X; \
-  X = (char *) &W; \
-  tmp = X[0]; X[0] = X[3]; X[3] = tmp; \
-  tmp = X[1]; X[1] = X[2]; X[2] = tmp; }
+# define MY_SWAP_WORD(W) {			\
+    char tmp, *X;				\
+    X = (char *) &W;				\
+    tmp = X[0]; X[0] = X[3]; X[3] = tmp;	\
+    tmp = X[1]; X[1] = X[2]; X[2] = tmp; }
 
 void Remap32 (Graphic *graphic, KapaImageWidget *image, Picture *picture, Matrix *matrix) {
@@ -13,15 +14,21 @@
   int i, j, ii, jj;
   int i_start, i_end, j_start, j_end;
+  int I_start, J_start;
   int dropback, inDX, inDY;
   int dx, dy, DX, DY;
   double expand, Ix, Iy;
   int expand_in, expand_out;
-  unsigned int *out_pix, *out_pix2;
+  OUT_TYPE *out_pix, *out_pix2, *data;
   unsigned short *in_pix, *in_pix2;
-  unsigned long *pixel, pixvalue;
-  unsigned long back;
+  OUT_TYPE *pixel, pixvalue;
+  OUT_TYPE back;
   int swap_client, swap_server, swap_bytes;
 
-  ALLOCATE (pixel, unsigned long, graphic[0].Npixels);
+  // just skip if there is no data
+  if (matrix[0].Naxes == 0) return;
+  if (matrix[0].Naxis[0] == 0) return;
+  if (matrix[0].Naxis[1] == 0) return;
+
+  ALLOCATE (pixel, OUT_TYPE, graphic[0].Npixels);
 
 # ifdef BYTE_SWAP
@@ -43,5 +50,5 @@
 
   // set up expansions
-  assert ((picture[0].expand >= 1) || (picture[0].expand <= -1));
+  assert ((picture[0].expand >= 1) || (picture[0].expand <= -2));
   expand = expand_in = expand_out = 1.0;
   if (picture[0].expand > 0) {
@@ -62,22 +69,17 @@
   DY = matrix[0].Naxis[1];
 
-  // x, y are the closest lit screen pixel to 0,0
-  Picture_Lower (&i_start, &j_start, matrix, picture);
+  // i_start, j_start are the closest lit screen pixel to 0,0
+  // I_start, J_start are the image pixel corresponding to i_start, j_start
+  Picture_Lower (&i_start, &j_start, &I_start, &J_start, matrix, picture);
 
-  // x, y are the closest lit screen pixel to dx, dy
-  Picture_Upper (&i_end, &j_end, matrix, picture);
+  // i_end, j_end are the closest lit screen pixel to dx, dy
+  // I_end, J_end are the image pixel corresponding to i_end, j_end
+  Picture_Upper (&i_end, &j_end, i_start, j_start, matrix, picture);
 
-  if (i_end < i_start) MY_SWAP_INT (i_start, i_end);
-  if (j_end < j_start) MY_SWAP_INT (j_start, j_end);
+  assert (i_start <= i_end);
+  assert (j_start <= j_end);
 
-  // Ix,Iy are the first displayed image pixel
-  Picture_to_Image (&Ix, &Iy, i_start, j_start, picture);
-  Ix = MIN (MAX (0, Ix), DX - 1);
-  Iy = MIN (MAX (0, Iy), DY - 1);
-  // XXX not completely consistent with the i_start, i_end range...
-
-  // we need to offset because i_start points to the bottom edge of Ix
-  // if (picture[0].flipx) Ix -= 1.0;
-  // if (picture[0].flipy) Iy -= 1.0;
+  Ix = picture[0].flipx ? I_start - 1 : I_start;
+  Iy = picture[0].flipy ? J_start - 1 : J_start;
 
   inDX = picture[0].flipx ? -1 : +1;
@@ -87,5 +89,5 @@
   if ((i_end - i_start) % expand_out == 0) dropback = 0;
 
-  out_pix = (unsigned int *) picture[0].data;
+  out_pix = data = (OUT_TYPE *) picture[0].data;
   in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
 
@@ -97,5 +99,6 @@
   }
   
-  for (j = j_start; j < j_end; j+= expand_out, out_pix+=(expand_out-1)*dx, in_pix += inDY*expand_in*DX) {
+  for (j = j_start; j < j_end; j+= expand_out, in_pix += inDY*expand_in*DX) {
+    out_pix = &data[j*dx];
 
     /**** fill in area to the left of the picture ****/
@@ -126,9 +129,4 @@
     }
     out_pix -= dropback;
-    
-    // assert (in_pix2 - image[0].pixmap <= DX*DY);
-    // assert (in_pix2 - image[0].pixmap >= 0);
-    // assert (in_pix - image[0].pixmap <= DX*DY);
-    // assert (in_pix - image[0].pixmap >= 0);
 
     /**** fill in area to the right of the picture ****/
@@ -139,22 +137,16 @@
       }
     }
-    out_pix += (dx - i_end);
-    // assert (out_pix - (unsigned int *)picture[0].data <= dx*dy);
-    // assert (out_pix - (unsigned int *)picture[0].data >= 0);
   } 
-  
-  if ((j_end - j_start) % expand_out > 0)
-    out_pix -= expand_out - (j_end - j_start) % expand_out;
-  
-  // assert (out_pix - (unsigned int *)picture[0].data <= dx*dy);
-  // assert (out_pix - (unsigned int *)picture[0].data >= 0);
 
   /**** fill in top area ****/
-  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned int *)picture[0].data < dx*dy); j++, out_pix++) { 
-    *out_pix = back;
+  out_pix = &data[j_end*dx];
+  for (j = 0; j < dy - j_end; j++) {
+    for (i = 0; i < dx; i++, out_pix ++) {
+      *out_pix = back;
+    }
   }
 
   picture[0].pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
-					picture[0].data, picture[0].dx, picture[0].dy, 32, 0);
+				 picture[0].data, picture[0].dx, picture[0].dy, 32, 0);
 
   free (pixel);
Index: trunk/Ohana/src/kapa2/src/Remap8.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Remap8.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/Remap8.c	(revision 25757)
@@ -1,3 +1,4 @@
 # include "Ximage.h"
+# define OUT_TYPE unsigned char
 
 void Remap8 (Graphic *graphic, KapaImageWidget *image, Picture *picture, Matrix *matrix) {
@@ -5,14 +6,20 @@
   int i, j, ii, jj;
   int i_start, i_end, j_start, j_end;
-  int dropback;
+  int I_start, J_start;
+  int dropback, inDX, inDY;
   int dx, dy, DX, DY;
   double expand, Ix, Iy;
   int expand_in, expand_out;
-  unsigned char *out_pix, *out_pix2;
-  unsigned short *in_pix,  *in_pix2;
-  unsigned char *pixel, pixvalue;
-  unsigned char back;
+  OUT_TYPE *out_pix, *out_pix2, *data;
+  unsigned short *in_pix, *in_pix2;
+  OUT_TYPE *pixel, pixvalue;
+  OUT_TYPE back;
 
-  ALLOCATE (pixel, unsigned char, graphic[0].Npixels);
+  // just skip if there is no data
+  if (matrix[0].Naxes == 0) return;
+  if (matrix[0].Naxis[0] == 0) return;
+  if (matrix[0].Naxis[1] == 0) return;
+
+  ALLOCATE (pixel, OUT_TYPE, graphic[0].Npixels);
 
   // local array for pixel values
@@ -44,17 +51,25 @@
   DY = matrix[0].Naxis[1];
 
-  // x, y are the closest lit screen pixel to 0,0
-  Picture_Lower (&i_start, &j_start, matrix, picture);
+  // i_start, j_start are the closest lit screen pixel to 0,0
+  // I_start, J_start are the image pixel corresponding to i_start, j_start
+  Picture_Lower (&i_start, &j_start, &I_start, &J_start, matrix, picture);
 
-  // x, y are the closest lit screen pixel to dx, dy
-  Picture_Upper (&i_end, &j_end, matrix, picture);
+  // i_end, j_end are the closest lit screen pixel to dx, dy
+  // I_end, J_end are the image pixel corresponding to i_end, j_end
+  Picture_Upper (&i_end, &j_end, i_start, j_start, matrix, picture);
 
-  // Ix,Iy are the first displayed image pixel
-  Picture_to_Image (&Ix, &Iy, i_start, j_start, picture);
+  assert (i_start <= i_end);
+  assert (j_start <= j_end);
+
+  Ix = picture[0].flipx ? I_start - 1 : I_start;
+  Iy = picture[0].flipy ? J_start - 1 : J_start;
+
+  inDX = picture[0].flipx ? -1 : +1;
+  inDY = picture[0].flipy ? -1 : +1;
 
   dropback = expand_out - (i_end - i_start) % expand_out;
   if ((i_end - i_start) % expand_out == 0) dropback = 0;
 
-  out_pix = (unsigned char *) picture[0].data;
+  out_pix = data = (OUT_TYPE *) picture[0].data;
   in_pix  = &image[0].pixmap[DX*(int)MAX(Iy,0) + (int)MAX(Ix,0)];
 
@@ -66,5 +81,6 @@
   }
   
-  for (j = j_start; j < j_end; j+= expand_out, out_pix+=(expand_out-1)*dx, in_pix += expand_in*DX) {
+  for (j = j_start; j < j_end; j+= expand_out, in_pix += inDY*expand_in*DX) {
+    out_pix = &data[j*dx];
 
     /**** fill in area to the left of the picture ****/
@@ -80,12 +96,12 @@
     in_pix2 = in_pix;
     if (expand_out == 1) {
-      for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
+      for (i = i_start; i < i_end; i++, in_pix2 += inDX*expand_in, out_pix++) {
 	*out_pix = pixel[*in_pix2];
       }
     } else {
-      for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
+      for (i = i_start; i < i_end; i+= expand_out, in_pix2 += inDX, out_pix+= expand_out) { 
 	pixvalue = pixel[*in_pix2];
 	out_pix2 = out_pix;
-	for (jj = 0; (jj < expand_out) & (j + jj < dy); jj++, out_pix2+=(dx-expand_out)) {
+	for (jj = 0; (jj < expand_out) && (j + jj < dy); jj++, out_pix2+=(dx-expand_out)) {
 	  for (ii = 0; ii < expand_out; ii++, out_pix2++) {
 	    *out_pix2 = pixvalue;
@@ -103,14 +119,12 @@
       }
     }
-    out_pix += (dx - i_end);
-    
   } 
   
-  if ((j_end - j_start) % expand_out > 0)
-    out_pix -= expand_out - (j_end - j_start) % expand_out;
-  
   /**** fill in top area ****/
-  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned char *)picture[0].data < dx*dy); j++, out_pix++) { 
-    *out_pix = back;
+  out_pix = &data[j_end*dx];
+  for (j = 0; j < dy - j_end; j++) {
+    for (i = 0; i < dx; i++, out_pix++) {
+      *out_pix = back;
+    }
   }
   picture[0].pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
Index: trunk/Ohana/src/kapa2/src/Reorient.c
===================================================================
--- trunk/Ohana/src/kapa2/src/Reorient.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/Reorient.c	(revision 25757)
@@ -7,7 +7,10 @@
   picture = &image[0].picture;
 
-  if (picture[0].expand == 0) picture[0].expand = 1;
+  if (picture[0].expand == 0) {
+      picture[0].expand = 1;
+      image[0].zoom.expand = 5;
+  }
 
-  if ((picture[0].X == X) && (picture[0].Y == Y) && (mode == 0)) {
+  if ((picture[0].Xc == X) && (picture[0].Yc == Y) && (mode == 0)) {
     Refresh ();
     XFlush (graphic[0].display);
@@ -17,7 +20,7 @@
   switch (mode) {
   case 0:
-    if ((picture[0].X != X) || (picture[0].Y != Y)) {
-      picture[0].X = X;
-      picture[0].Y = Y;
+    if ((picture[0].Xc != X) || (picture[0].Yc != Y)) {
+      picture[0].Xc = X;
+      picture[0].Yc = Y;
     }
     break;
@@ -25,14 +28,15 @@
     picture[0].expand--;
     if ((picture[0].expand == 0) || (picture[0].expand == -1)) picture[0].expand = -2;
-    picture[0].X = X;
-    picture[0].Y = Y;
+    picture[0].Xc = X;
+    picture[0].Yc = Y;
     break;
   case +1:
     picture[0].expand++;
     if ((picture[0].expand == 0) || (picture[0].expand == -1)) picture[0].expand = 1;
-    picture[0].X = X;
-    picture[0].Y = Y;
+    picture[0].Xc = X;
+    picture[0].Yc = Y;
     break;
   }
+  image[0].zoom.expand = MIN(image[0].zoom.dx / 5.5, MAX(5, 2*picture[0].expand));
 
   Remap (graphic, image);
Index: trunk/Ohana/src/kapa2/src/SetColorScale.c
===================================================================
--- trunk/Ohana/src/kapa2/src/SetColorScale.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/SetColorScale.c	(revision 25757)
@@ -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: trunk/Ohana/src/kapa2/src/SetColormap.c
===================================================================
--- trunk/Ohana/src/kapa2/src/SetColormap.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/SetColormap.c	(revision 25757)
@@ -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);
       }
Index: trunk/Ohana/src/kapa2/src/SetUpGraphic.c
===================================================================
--- trunk/Ohana/src/kapa2/src/SetUpGraphic.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/SetUpGraphic.c	(revision 25757)
@@ -60,4 +60,5 @@
   graphic->color = KapaX11colors (graphic->display, graphic->colormap, graphic->fore, &Ncolors);
   if (MAP_WINDOW) MapWindow (graphic);
+
   return;
 }
Index: trunk/Ohana/src/kapa2/src/StatusBox.c
===================================================================
--- trunk/Ohana/src/kapa2/src/StatusBox.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/StatusBox.c	(revision 25757)
@@ -11,10 +11,10 @@
     y = 0.5*image[0].image[0].matrix.Naxis[1];
     // z = -1;
-    image[0].zoom.X = x;
-    image[0].zoom.Y = y;
+    image[0].zoom.Xc = x;
+    image[0].zoom.Yc = y;
     // image[0].z = z;
   } else {
-    x = image[0].zoom.X;
-    y = image[0].zoom.Y;
+    x = image[0].zoom.Xc;
+    y = image[0].zoom.Yc;
     // z = image[0].z;
   }
Index: trunk/Ohana/src/kapa2/src/UpdatePointer.c
===================================================================
--- trunk/Ohana/src/kapa2/src/UpdatePointer.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/UpdatePointer.c	(revision 25757)
@@ -29,6 +29,6 @@
 
   skip:
-    image[0].zoom.X = x;
-    image[0].zoom.Y = y;
+    image[0].zoom.Xc = x;
+    image[0].zoom.Yc = y;
     
     UpdateStatusBox (graphic, image, x, y, z, 0);
@@ -36,8 +36,10 @@
       
     CreateZoom (graphic, image);  
-    XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
-	       image[0].zoom.pix, 0, 0, 
-	       image[0].zoom.x, image[0].zoom.y, 
-	       image[0].zoom.dx, image[0].zoom.dy);
+    if (image[0].zoom.pix) {
+	XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
+		   image[0].zoom.pix, 0, 0, 
+		   image[0].zoom.x, image[0].zoom.y, 
+		   image[0].zoom.dx, image[0].zoom.dy);
+    }
     CrossHairs (graphic, &image[0].zoom);
     XFlush (graphic[0].display);
Index: trunk/Ohana/src/kapa2/src/UpdateStatusBox.c
===================================================================
--- trunk/Ohana/src/kapa2/src/UpdateStatusBox.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/UpdateStatusBox.c	(revision 25757)
@@ -48,5 +48,5 @@
   
   bzero (line, 100);
-  sprintf (line, "%10.1f %10.1f", x, y);
+  sprintf (line, "%10.2f %10.2f", x, y);
   XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
 	       image[0].text_x + PAD1, image[0].text_y + 2*textpad + 2*PAD1, line, strlen(line));
Index: trunk/Ohana/src/kapa2/src/bDrawOverlay.c
===================================================================
--- trunk/Ohana/src/kapa2/src/bDrawOverlay.c	(revision 22713)
+++ trunk/Ohana/src/kapa2/src/bDrawOverlay.c	(revision 25757)
@@ -81,11 +81,11 @@
 	  double sn = sin(angle);
 	  x0 = X + pX*dx*cs;
-	  y0 = Y - pY*dx*sn;
+	  y0 = Y + pY*dx*sn;
 	  // XXX dt should be based on the size of the ellipse...
 	  // 0.10 -> 60 segments on the ellipse
 	  # define DT 0.1
 	  for (t = DT; t < 2*M_PI + DT; t+=DT) {
-	    x1 = X + pX*dx*cos(t)*cs + pX*dy*sin(t)*sn;
-	    y1 = Y - pY*dx*cos(t)*sn + pY*dy*sin(t)*cs;
+	    x1 = X + pX*dx*cos(t)*cs - pX*dy*sin(t)*sn;
+	    y1 = Y + pY*dx*cos(t)*sn + pY*dy*sin(t)*cs;
 	    bDrawLine (x0, y0, x1, y1);
 	    x0 = x1;
Index: trunk/Ohana/src/kapa2/test/overlay.sh
===================================================================
--- trunk/Ohana/src/kapa2/test/overlay.sh	(revision 25757)
+++ trunk/Ohana/src/kapa2/test/overlay.sh	(revision 25757)
@@ -0,0 +1,10 @@
+
+macro checker
+  mcreate a 8 8
+  for ix 0 8
+    for iy 0 8
+      if (($ix + $iy) % 2) continue
+      a[$ix][$iy] = $ix + $iy
+    end
+  end
+end
