Index: /trunk/Ohana/src/kapa2/include/structures.h
===================================================================
--- /trunk/Ohana/src/kapa2/include/structures.h	(revision 16227)
+++ /trunk/Ohana/src/kapa2/include/structures.h	(revision 16228)
@@ -90,5 +90,9 @@
 
 typedef struct {
-  int      dx, dy, x, y;
+  int      x, y;	      // location of picture in graphic
+  int      dx, dy;	      // size of picture
+  int      DX, DY;	      // size of displayed picture (must be updated with new images...)
+  int      expand;	      // zoomscale
+  double   Xo, Yo;	      // image pixel at screen center
   XImage  *pix;
   char    *data;
@@ -183,7 +187,6 @@
   int      DecimalDegrees;
 
-  double   X, Y;           /* image pixel at screen center */
-  int      expand;         /* zoomscale */
-  double   x, y, z;        /* last pointer coords */
+  // double   X, Y;           /* image pixel at screen center */
+  // double   x, y, z;        /* last pointer coords */
 
   Overlay  overlay[NOVERLAYS];
Index: /trunk/Ohana/src/kapa2/src/ButtonFunctions.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/ButtonFunctions.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/ButtonFunctions.c	(revision 16228)
@@ -56,5 +56,5 @@
 int Rescale (Graphic *graphic, KapaImageWidget *image) {
 
-  image[0].expand = 1;
+  image[0].picture.expand = 1;
   Remap (graphic, image);
   Refresh ();
@@ -66,7 +66,7 @@
 int RecenterRescale (Graphic *graphic, KapaImageWidget *image) {
 
-  image[0].X = 0;
-  image[0].Y = 0;
-  image[0].expand = 1;
+  image[0].picture.X = 0;
+  image[0].picture.Y = 0;
+  image[0].picture.expand = 1;
  
   Remap (graphic, image);
Index: /trunk/Ohana/src/kapa2/src/Center.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/Center.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/Center.c	(revision 16228)
@@ -16,8 +16,8 @@
   if (image == NULL) return (TRUE);
 
-  image[0].X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
-  image[0].Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
+  image[0].picture.X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
+  image[0].picture.Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
   if ((zoom != 0) && (zoom != -1)) {
-    image[0].expand = zoom;
+    image[0].picture.expand = zoom;
   }
 
Index: /trunk/Ohana/src/kapa2/src/CreateZoom32.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/CreateZoom32.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/CreateZoom32.c	(revision 16228)
@@ -8,5 +8,5 @@
   int dropback;  /* this is a bit of a kludge... */
   int dx, dy, DX, DY;
-  double expand, zoomscale, Rx, Ry;
+  double expand, zoomscale, Ix, Iy;
   int expand_in, expand_out;
   unsigned int *out_pix, *out_pix2;
@@ -40,12 +40,13 @@
   DY = image[0].image[0].matrix.Naxis[1];
   
-  /* Rx,Ry are the screen coordinates of the first image pixel */
-  Rx = x - expand*(int)(0.5*(dx + 1)) + 1;
-  Ry = y - expand*(int)(0.5*(dy + 1)) + 1;
+  /* Ix,Iy are the image coordinates of the first image pixel */
+  // x,y is the image coordinate of the zoombox center
+  Ix = x - expand*(int)(0.5*(dx + 1)) + 1;
+  Iy = 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);
+  i_start = MIN (MAX (-Ix / expand, (1 - FRAC(Ix)) / expand), dx - expand_out + 1);
+  j_start = MIN (MAX (-Iy / expand, (1 - FRAC(Iy)) / expand), dy - expand_out + 1);
+  i_end   = MAX (MIN ((DX-Ix) / expand, dx - expand_out + 1), 0);
+  j_end   = MAX (MIN ((DY-Iy) / expand, dy - expand_out + 1), 0);
 
   dropback = expand_out - (i_end - i_start) % expand_out;
@@ -53,5 +54,5 @@
 
   out_pix = (unsigned int *) image[0].zoom.data;
-  in_pix  = &image[0].pixmap[DX*(int)MAX(Ry,0) + (int)MAX(Rx,0)];
+  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) **********/
Index: /trunk/Ohana/src/kapa2/src/CrossHairs.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/CrossHairs.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/CrossHairs.c	(revision 16228)
@@ -7,5 +7,5 @@
   double zoomscale;
 
-  zoomscale = MAX (5, image[0].expand + 5);
+  zoomscale = image[0].zoom;
   x0 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale - 2.5) + image[0].zoom.x;
   x5 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale - 0.5) + image[0].zoom.x;
Index: /trunk/Ohana/src/kapa2/src/CursorOps.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/CursorOps.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/CursorOps.c	(revision 16228)
@@ -1,22 +1,25 @@
 # include "Ximage.h"
 
-void Screen_to_Image (double *x1, double *y1, double x2, double y2, KapaImageWidget *image) {
+void Screen_to_Image (double *x1, double *y1, double x2, double y2, Picture *picture) {
 
   double expand;
 
   expand = 1.0;
-  if (image[0].expand > 0) {
-    expand = 1 / (1.0*image[0].expand);
-  }
-  if (image[0].expand < 0) {
-    expand = fabs((double)image[0].expand);
+  if (picture[0].expand > 0) {
+    expand = 1 / (1.0*picture[0].expand);
+  } else {
+    expand = fabs((double)picture[0].expand);
   }
   
-  *x1 = expand*(x2 - image[0].picture.x - 0.5*image[0].picture.dx) + 0.5*image[0].image[0].matrix.Naxis[0] - image[0].X;
-  *y1 = expand*(y2 - image[0].picture.y - 0.5*image[0].picture.dy) + 0.5*image[0].image[0].matrix.Naxis[1] - image[0].Y;
-  
+  // pixel coordinates in picture frame
+  xs = x2 - picture[0].x;
+  ys = y2 - picture[0].y;
+
+  // picture[0].X,Y is the offset relative to picture[0].Xo,Yo
+  *x1 = expand*(xs - 0.5*picture[0].dx) + picture[0].Xo - picture[0].X;
+  *y1 = expand*(ys - 0.5*picture[0].dy) + picture[0].Yo - picture[0].Y;
 }
 
-void Image_to_Screen (double *x1, double *y1, double x2, double y2, KapaImageWidget *image) {
+void Image_to_Screen (double *x1, double *y1, double x2, double y2, Picture *picture) {
 
   double expand;
@@ -24,14 +27,17 @@
   /* notice that here, expand is the reciprocal of the expand above */
   expand = 1.0;
-  if (image[0].expand > 0) {
-    expand = abs(image[0].expand);
-  }
-  if (image[0].expand < 0) {
-    expand = 1 / ((double)abs(image[0].expand));
+  if (picture[0].expand > 0) {
+    expand = picture[0].expand;
+  } else {
+    expand = 1 / fabs((double)image[0].expand);
   }
   
-  *x1 = (x2 - 0.5*image[0].image[0].matrix.Naxis[0] + image[0].X) * expand + image[0].picture.x + 0.5*image[0].picture.dx;
-  *y1 = (y2 - 0.5*image[0].image[0].matrix.Naxis[1] + image[0].Y) * expand + image[0].picture.y + 0.5*image[0].picture.dy;
-  
+  // pixel coordinates in picture frame
+  xs = expand*(x2 - picture[0].Xo + picture[0].X) + 0.5*picture[0].dx;
+  ys = expand*(y2 - picture[0].Yo + picture[0].Y) + 0.5*picture[0].dy;
+
+  // pixel coordinates in screen frame
+  *x1 = xs + picture[0].x;
+  *y1 = ys + picture[0].y;
 }
 
Index: /trunk/Ohana/src/kapa2/src/Image.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/Image.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/Image.c	(revision 16228)
@@ -47,7 +47,17 @@
   }
 
-  image[0].X = 0.0;
-  image[0].Y = 0.0;
-  image[0].expand = 1;
+  // set the center and expansion for the pictures:
+  image[0].picture.X      = 0.0;
+  image[0].picture.Y      = 0.0;
+  image[0].picture.expand = 1;
+
+  image[0].zoom.X      	  = 0.0;
+  image[0].zoom.Y      	  = 0.0;
+  image[0].zoom.expand 	  = +5;
+
+  image[0].wide.X      	  = 0.0;
+  image[0].wide.Y      	  = 0.0;
+  image[0].wide.expand 	  = -5;
+
   image[0].location = 4;
 
Index: /trunk/Ohana/src/kapa2/src/InterpretKeys.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/InterpretKeys.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/InterpretKeys.c	(revision 16228)
@@ -60,5 +60,5 @@
       if (event[0].x > image[0].picture.x + image[0].picture.dx) goto skip_cursor;
       if (event[0].y > image[0].picture.y + image[0].picture.dy) goto skip_cursor;
-      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
+      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, &image[0].picture);
       XY_to_RD (&R, &D, X, Y, &image[0].image[0].coords);
 
@@ -123,7 +123,7 @@
     case XK_KP_Begin:
     case XK_Return:
-      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
-      X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
-      Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
+      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, &image[0].picture);
+      X = 0.5*image[0].picture.DX - X;
+      Y = 0.5*image[0].picture.DY - Y;
       Reorient (graphic, image, X, Y, 0);
       break;
Index: /trunk/Ohana/src/kapa2/src/InterpretPresses.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/InterpretPresses.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/InterpretPresses.c	(revision 16228)
@@ -34,5 +34,5 @@
       if (event[0].x > image[0].picture.x + image[0].picture.dx) goto skip_cursor;
       if (event[0].y > image[0].picture.y + image[0].picture.dy) goto skip_cursor;
-      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, image);
+      Screen_to_Image (&X, &Y, (double)event[0].x, (double)event[0].y, &image[0].picture);
 
       XY_to_RD (&R, &D, X, Y, &image[0].image[0].coords);
@@ -101,5 +101,5 @@
   double X, Y;
 
-  Screen_to_Image (&X, &Y, (double)mouse_event[0].x, (double)mouse_event[0].y, image);
+  Screen_to_Image (&X, &Y, (double)mouse_event[0].x, (double)mouse_event[0].y, &image[0].picture);
   X = 0.5*image[0].image[0].matrix.Naxis[0] - X;
   Y = 0.5*image[0].image[0].matrix.Naxis[1] - Y;
Index: /trunk/Ohana/src/kapa2/src/LoadPicture.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/LoadPicture.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/LoadPicture.c	(revision 16228)
@@ -32,4 +32,8 @@
   gfits_free_matrix (&image[0].image[0].matrix);
   gfits_create_matrix (&header, &image[0].image[0].matrix);
+
+  // reference point for image is the center pixel
+  image[0].picture.Xo = 0.5*header.Naxis[0];
+  image[0].picture.Yo = 0.5*header.Naxis[1];
 
   fcntl (sock, F_SETFL, O_NONBLOCK);  
Index: /trunk/Ohana/src/kapa2/src/PSOverlay.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/PSOverlay.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/PSOverlay.c	(revision 16228)
@@ -16,5 +16,5 @@
   }
 
-  Image_to_Screen (&X0, &Y0, 0.0, 0.0, image);
+  Image_to_Screen (&X0, &Y0, 0.0, 0.0, &image[0].picture);
   X0 -= image[0].picture.x;
   Y0 -= image[0].picture.y;
Index: /trunk/Ohana/src/kapa2/src/PaintOverlay.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/PaintOverlay.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/PaintOverlay.c	(revision 16228)
@@ -18,5 +18,5 @@
   }
 
-  Image_to_Screen (&X0, &Y0, 0.0, 0.0, image);
+  Image_to_Screen (&X0, &Y0, 0.0, 0.0, &image[0].picture);
 
   Xmin = image[0].picture.x;
Index: /trunk/Ohana/src/kapa2/src/Remap16.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/Remap16.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/Remap16.c	(revision 16228)
@@ -1,14 +1,3 @@
 # include "Ximage.h"
-
-static float slope = 1.0;
-static float start = 0.0;
-static int MaxValue = 255;
-
-// XXX inline this if needed
-static int PixelLookup(float value) {
-  int out;
-  out = MIN (MAX (slope * value - start, 0), MaxValue);
-  return (out);
-}
 
 void Remap16 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
@@ -17,22 +6,23 @@
   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, Rx, Ry, X, Y;
+  int dx, dy, DX, DY;
+  double expand, Sx, Sy, Ix, Iy;
   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 short *in_pix, *in_pix2;
+  unsigned char *pixel1, *pixel2;
   unsigned char pixvalue1, pixvalue2;
-  unsigned long back;
   unsigned char back1, back2;
 
+  ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
+  ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
+
   // local array for pixel values (is this working??)
-  for (i = 0; i < 256; i++) { /* set up pixel array */
+  for (i = 0; i < graphic[0].Npixels; i++) { /* set up pixel array */
     pixel1[i] = 0x00ff &  graphic[0].cmap[i].pixel;
     pixel2[i] = 0x00ff & (graphic[0].cmap[i].pixel >> 8);
   }
-  back = graphic[0].back;
-  back1 = 0x00ff & back;
-  back2 = 0x00ff & (back >> 8);
+  back1 = 0x00ff & (graphic[0].back >> 0);
+  back2 = 0x00ff & (graphic[0].back >> 8);
 
   // define the color transform parameters
@@ -68,28 +58,28 @@
 
   /* X,Y are the image coordinates of the first image pixel */
-  X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
-  if ((int)X != X) 
-    X = (int) X + 1;
+  Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
+  if ((int)Ix != Ix) 
+    Ix = (int) Ix + 1;
   else 
-    X = (int) X;
-  Y = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
-  if ((int)Y != Y) 
-    Y = (int) Y + 1;
+    Ix = (int) Ix;
+  Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
+  if ((int)Iy != Iy) 
+    Iy = (int) Iy + 1;
   else 
-    Y = (int) Y;
+    Iy = (int) Iy;
 
-  /* Rx,Ry are the screen coordinates of the first image pixel */
-  Rx = (X + image[0].X - 0.5*DX)/expand + 0.5*dx;
-  Ry = (Y + image[0].Y - 0.5*DY)/expand + 0.5*dy;
+  /* Sx,Sy are the screen coordinates of the first image pixel */
+  Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx;
+  Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy;
 
-  i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
-  j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
+  i_start = MIN (MAX (Sx, 0), dx - expand_out + 1);
+  j_start = MIN (MAX (Sy, 0), dy - expand_out + 1);
   
   if (image[0].expand > 0) {
-    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
-    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
+    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0);
+    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0);
   } else {
-    i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
-    j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
+    i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0);
+    j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0);
   }    
 
@@ -98,6 +88,5 @@
 
   data = out_pix = (unsigned char *) image[0].picture.data;
-  imdata  = (float *) matrix[0].buffer;
-  in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
+  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) **********/
@@ -128,14 +117,12 @@
     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];
+	out_pix[0] = pixel1[*in_pix2];
+	out_pix[1] = pixel2[*in_pix2];
       }
     }
     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];
+	pixvalue1 = pixel1[*in_pix2];
+	pixvalue2 = pixel2[*in_pix2];
 	out_pix2 = out_pix;
 	for (jj = 0; jj < expand_out; jj++, out_pix2+=2*(dx-expand_out)) {
@@ -175,4 +162,7 @@
   image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
 					image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 16, 0);
+
+  free (pixel1);
+  free (pixel2);
 }
 
Index: /trunk/Ohana/src/kapa2/src/Remap24.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/Remap24.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/Remap24.c	(revision 16228)
@@ -1,14 +1,3 @@
 # include "Ximage.h"
-
-static float slope = 1.0;
-static float start = 0.0;
-static int MaxValue = 255;
-
-// XXX inline this if needed
-static int PixelLookup(float value) {
-  int out;
-  out = MIN (MAX (slope * value - start, 0), MaxValue);
-  return (out);
-}
 
 void Remap24 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
@@ -17,34 +6,26 @@
   int i_start, i_end, j_start, j_end;
   int dropback, extra;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY, pixelN;
-  double expand, Rx, Ry, X, Y;
+  int dx, dy, DX, DY;
+  double expand, Sx, Sy, Ix, Iy;
   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 short *in_pix, *in_pix2;
+  unsigned char *pixel1, *pixel2, *pixel3;
   unsigned char pixvalue1, pixvalue2, pixvalue3;
-  unsigned long back;
   unsigned char back1, back2, back3;
 
+  ALLOCATE (pixel1, unsigned char, graphic[0].Npixels);
+  ALLOCATE (pixel2, unsigned char, graphic[0].Npixels);
+  ALLOCATE (pixel3, unsigned char, graphic[0].Npixels);
+
   // local arrays for pixel values
-  for (i = 0; i < 256; i++) { /* set up pixel array */
+  for (i = 0; i < graphic[0].Npixels; 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;
-  }
+  back1 = 0x0000ff & (graphic[0].back >>  0);
+  back2 = 0x0000ff & (graphic[0].back >>  8);
+  back3 = 0x0000ff & (graphic[0].back >> 16);
 
   // set up expansions
@@ -70,28 +51,28 @@
 
   /* X,Y are the image coordinates of the first image pixel */
-  X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
-  if ((int)X != X) 
-    X = (int) X + 1;
+  Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
+  if ((int)Ix != Ix) 
+    Ix = (int) Ix + 1;
   else 
-    X = (int) X;
-  Y = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
-  if ((int)Y != Y) 
-    Y = (int) Y + 1;
+    Ix = (int) Ix;
+  Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
+  if ((int)Iy != Iy) 
+    Iy = (int) Iy + 1;
   else 
-    Y = (int) Y;
+    Iy = (int) Iy;
 
-  /* Rx,Ry are the screen coordinates of the first image pixel */
-  Rx = (X + image[0].X - 0.5*DX)/expand + 0.5*dx;
-  Ry = (Y + image[0].Y - 0.5*DY)/expand + 0.5*dy;
+  /* Sx,Sy are the screen coordinates of the first image pixel */
+  Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx;
+  Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy;
 
-  i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
-  j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
+  i_start = MIN (MAX (Sx, 0), dx - expand_out + 1);
+  j_start = MIN (MAX (Sy, 0), dy - expand_out + 1);
   
   if (image[0].expand > 0) {
-    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
-    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
+    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0);
+    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0);
   } else {
-    i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
-    j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
+    i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0);
+    j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0);
   }    
 
@@ -100,6 +81,5 @@
 
   data = out_pix = (unsigned char *) image[0].picture.data;
-  imdata  = (float *) matrix[0].buffer;
-  in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
+  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) **********/
@@ -133,15 +113,13 @@
     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];
+	out_pix[0] = pixel1[*in_pix2];
+	out_pix[1] = pixel2[*in_pix2];
+	out_pix[2] = pixel3[*in_pix2];
       }
     } 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];
+	pixvalue1 = pixel1[*in_pix2];
+	pixvalue2 = pixel2[*in_pix2];
+	pixvalue3 = pixel3[*in_pix2];
 	out_pix2 = out_pix;
 	for (jj = 0; jj < expand_out; jj++, out_pix2+=3*(dx-expand_out)+extra) {
@@ -185,4 +163,8 @@
   image[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
 					image[0].picture.data, image[0].picture.dx, image[0].picture.dy, 32, 0);
+
+  free (pixel1);
+  free (pixel2);
+  free (pixel3);
 }
 
Index: /trunk/Ohana/src/kapa2/src/Remap32.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/Remap32.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/Remap32.c	(revision 16228)
@@ -7,5 +7,5 @@
   int dropback;  /* this is a bit of a kludge... */
   int dx, dy, DX, DY;
-  double expand, Rx, Ry, X, Y;
+  double expand, Sx, Sy, Ix, Iy;
   int expand_in, expand_out;
   unsigned int *out_pix, *out_pix2;
@@ -43,30 +43,31 @@
   DY = matrix[0].Naxis[1];
 
-  /* X,Y are the image coordinates of the first image pixel */
-  X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
-  if ((int)X != X) 
-    X = (int) X + 1;
-  else 
-    X = (int) X;
-  Y = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
-  if ((int)Y != Y) 
-    Y = (int) Y + 1;
-  else 
-    Y = (int) Y;
+  // Ix, Iy are the image coordinates of the 0,0 screen pixel
+  Screen_to_Image (&Ix, &Iy, 0.0, 0.0, &image[0].picture);
 
-  /* Rx,Ry are the screen coordinates of the first image pixel */
-  Rx = (X + image[0].X - 0.5*DX)/expand + 0.5*dx;
-  Ry = (Y + image[0].Y - 0.5*DY)/expand + 0.5*dy;
+  // Ix, Iy are now limited to valid image coordinates
+  Ix = MIN (MAX (Ix, 0), DX);
+  Iy = MIN (MAX (Iy, 0), DY);
 
-  i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
-  j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
-  
-  if (image[0].expand > 0) {
-    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
-    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
-  } else {
-    i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
-    j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
-  }    
+  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
+  Image_to_Screen (&Sx, &Sy, Ix,  Iy,  &image[0].picture);
+
+  // i_start, j_start are now limited to valid screen coordinates
+  i_start = MIN (MAX (Sx, 0), dx);
+  j_start = MIN (MAX (Sy, 0), dy);
+
+  // Ix, Iy are the image coordinates of the 0,0 screen pixel
+  Screen_to_Image (&Ix, &Iy, dx, dy, &image[0].picture);
+
+  // Ix, Iy are now limited to valid image coordinates
+  Ix = MIN (MAX (Ix, 0), DX);
+  Iy = MIN (MAX (Iy, 0), DY);
+
+  // Sx, Sy are the screen coordinates of the Ix,Iy pixel
+  Image_to_Screen (&Sx, &Sy, Ix,  Iy,  &image[0].picture);
+
+  // i_end, j_end are now limited to valid screen coordinates
+  i_end = MIN (MAX (Sx, 0), dx);
+  j_end = MIN (MAX (Sy, 0), dy);
 
   dropback = expand_out - (i_end - i_start) % expand_out;
@@ -74,5 +75,5 @@
 
   out_pix = (unsigned int *) image[0].picture.data;
-  in_pix  = &image[0].pixmap[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
+  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) **********/
Index: /trunk/Ohana/src/kapa2/src/Remap8.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/Remap8.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/Remap8.c	(revision 16228)
@@ -1,14 +1,3 @@
 # include "Ximage.h"
-
-static float slope = 1.0;
-static float start = 0.0;
-static int MaxValue = 255;
-
-// XXX inline this if needed
-static int PixelLookup(float value) {
-  int out;
-  out = MIN (MAX (slope * value - start, 0), MaxValue);
-  return (out);
-}
 
 void Remap8 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
@@ -18,26 +7,18 @@
   int dropback;  /* this is a bit of a kludge... */
   int dx, dy, DX, DY, pixelN;
-  double expand, Rx, Ry, X, Y;
+  double expand, Sx, Sy, Ix, Iy;
   int expand_in, expand_out;
   unsigned char *out_pix, *out_pix2;
-  float *imdata, *in_pix,  *in_pix2;
-  unsigned long pixel[256], pixvalue;
+  unsigned short *in_pix,  *in_pix2;
+  unsigned long *pixel, pixvalue;
   unsigned long back;
 
+  ALLOCATE (pixel, unsigned long, graphic[0].Npixels);
+
   // local array for pixel values
-  for (i = 0; i < 256; i++) {
+  for (i = 0; i < graphic[0].Npixels; i++) {
     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;
-  }
 
   // set up expansions
@@ -63,28 +44,28 @@
 
   /* X,Y are the image coordinates of the first image pixel */
-  X = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
-  if ((int)X != X) 
-    X = (int) X + 1;
+  Ix = MAX(0.5*(DX - dx*expand) - image[0].X, 0);
+  if ((int)Ix != Ix) 
+    Ix = (int) Ix + 1;
   else 
-    X = (int) X;
-  Y = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
-  if ((int)Y != Y) 
-    Y = (int) Y + 1;
+    Ix = (int) Ix;
+  Iy = MAX(0.5*(DY - dy*expand) - image[0].Y, 0);
+  if ((int)Iy != Iy) 
+    Iy = (int) Iy + 1;
   else 
-    Y = (int) Y;
+    Iy = (int) Iy;
 
-  /* Rx,Ry are the screen coordinates of the first image pixel */
-  Rx = (X + image[0].X - 0.5*DX)/expand + 0.5*dx;
-  Ry = (Y + image[0].Y - 0.5*DY)/expand + 0.5*dy;
+  /* Sx,Sy are the screen coordinates of the first image pixel */
+  Sx = (Ix + image[0].X - 0.5*DX)/expand + 0.5*dx;
+  Sy = (Iy + image[0].Y - 0.5*DY)/expand + 0.5*dy;
 
-  i_start = MIN (MAX (Rx, 0), dx - expand_out + 1);
-  j_start = MIN (MAX (Ry, 0), dy - expand_out + 1);
+  i_start = MIN (MAX (Sx, 0), dx - expand_out + 1);
+  j_start = MIN (MAX (Sy, 0), dy - expand_out + 1);
   
   if (image[0].expand > 0) {
-    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-X) + Rx), 0);
-    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Y) + Ry), 0);
+    i_end = MAX (MIN (i_start + ((int)(expand*(dx-i_start)))/expand, expand_out*(DX-Ix) + Sx), 0);
+    j_end = MAX (MIN (j_start + ((int)(expand*(dy-j_start)))/expand, expand_out*(DY-Iy) + Sy), 0);
   } else {
-    i_end = MAX (MIN (dx, (DX-X)/expand + Rx), 0);
-    j_end = MAX (MIN (dy, (DY-Y)/expand + Ry), 0);
+    i_end = MAX (MIN (dx, (DX-Ix)/expand + Sx), 0);
+    j_end = MAX (MIN (dy, (DY-Iy)/expand + Sy), 0);
   }    
 
@@ -93,6 +74,5 @@
 
   out_pix = (unsigned char *) image[0].picture.data;
-  imdata  = (float *) matrix[0].buffer;
-  in_pix  = &imdata[(int)(DX*(int)MAX(Y,0) + (int)MAX(X,0))];
+  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) **********/
@@ -117,11 +97,9 @@
     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];
+	*out_pix = pixel[*in_pix2];
       }
     } else {
       for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
-	pixelN   = PixelLookup(*in_pix2);
-	pixvalue = pixel[pixelN];
+	pixvalue = pixel[*in_pix2];
 	out_pix2 = out_pix;
 	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
Index: /trunk/Ohana/src/kapa2/src/Reorient.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/Reorient.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/Reorient.c	(revision 16228)
@@ -3,7 +3,11 @@
 void Reorient (Graphic *graphic, KapaImageWidget *image, double X, double Y, int mode) {
 
-  if (image[0].expand == 0) image[0].expand = 1;
+  Picture *picture;
 
-  if ((image[0].X == X) && (image[0].Y == Y) && (mode == 0)) {
+  picture = &image[0].picture;
+
+  if (picture[0].expand == 0) picture[0].expand = 1;
+
+  if ((picture[0].X == X) && (picture[0].Y == Y) && (mode == 0)) {
     Refresh ();
     XFlush (graphic[0].display);
@@ -13,32 +17,20 @@
   switch (mode) {
   case 0:
-    if ((image[0].X != X) || (image[0].Y != Y)) {
-      image[0].X = X;
-      image[0].Y = Y;
+    if ((picture[0].X != X) || (picture[0].Y != Y)) {
+      picture[0].X = X;
+      picture[0].Y = Y;
     }
     break;
   case -1: 
-    image[0].expand--;
-    if ((image[0].expand == 0) || (image[0].expand == -1))
-      image[0].expand = -2;
-    if (image[0].expand < -30) {
-      fprintf (stderr, "can't get smaller!\n");
-      image[0].expand = -30;
-      return;
-    }
-    image[0].X = X;
-    image[0].Y = Y;
+    picture[0].expand--;
+    if ((picture[0].expand == 0) || (picture[0].expand == -1)) picture[0].expand = -2;
+    picture[0].X = X;
+    picture[0].Y = Y;
     break;
   case +1:
-    image[0].expand++;
-    if ((image[0].expand == 0) || (image[0].expand == -1))
-      image[0].expand = 1;
-    if (image[0].expand > 30) {
-      fprintf (stderr, "can't get bigger!\n");
-      image[0].expand = 30;
-      return;
-    }
-    image[0].X = X;
-    image[0].Y = Y;
+    picture[0].expand++;
+    if ((picture[0].expand == 0) || (picture[0].expand == -1)) picture[0].expand = 1;
+    picture[0].X = X;
+    picture[0].Y = Y;
     break;
   }
@@ -49,14 +41,2 @@
   XFlush (graphic[0].display);
 }
-
-# if (0) /* the "warp" function seems to be a problem on SUNs for some reason */
-  XQueryPointer (graphic[0].display, graphic[0].window, &dummy1, &dummy1, &dummy2, &dummy2, &x, &y, &dummy3); 
-  if ((x > image[0].picture.x) && (x < image[0].picture.x + image[0].picture.dx) &&
-      (y > image[0].picture.y) && (y < image[0].picture.y + image[0].picture.dy) &&
-      ((mouse_event[0].button == 2) || (mouse_event[0].button == 3))) {
-    XWarpPointer (graphic[0].display, None, graphic[0].window, 0, 0, 0, 0, 
-		  image[0].picture.x + 0.5*image[0].picture.dx,
-		  image[0].picture.y + 0.5*image[0].picture.dy);
-  }
-# endif
-
Index: /trunk/Ohana/src/kapa2/src/SetImageData.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/SetImageData.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/SetImageData.c	(revision 16228)
@@ -125,6 +125,6 @@
   image = section->image;
 
-  Screen_to_Image (&Xmin, &Ymin, 0.0, 0.0, image);
-  Screen_to_Image (&Xmax, &Ymax, image[0].picture.dx, image[0].picture.dy, image);
+  Screen_to_Image (&Xmin, &Ymin, 0.0, 0.0, &image[0].picture);
+  Screen_to_Image (&Xmax, &Ymax, image[0].picture.dx, image[0].picture.dy, &image[0].picture);
 
   KiiSendMessage (sock, "%g %g %g %g", Xmin, Xmax, Ymin, Ymax);
Index: /trunk/Ohana/src/kapa2/src/UpdatePointer.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/UpdatePointer.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/UpdatePointer.c	(revision 16228)
@@ -1,4 +1,3 @@
 # include "Ximage.h"
-# define FRAC(a) ((a) - (int)(a))
 
 int UpdatePointer (Graphic *graphic, XMotionEvent *event) {
@@ -20,5 +19,5 @@
 
     data = (float *) image[0].image[0].matrix.buffer;
-    Screen_to_Image (&x, &y, (double)event[0].x, (double)event[0].y, image);
+    Screen_to_Image (&x, &y, (double)event[0].x, (double)event[0].y, &image[0].picture);
 
     z = -1;
@@ -30,7 +29,6 @@
 
   skip:
-    image[0].x = x;
-    image[0].y = y;
-    image[0].z = z;
+    image[0].zoom.X = x;
+    image[0].zoom.Y = Y;
     
     UpdateStatusBox (graphic, image, x, y, z, 0);
Index: /trunk/Ohana/src/kapa2/src/bDrawOverlay.c
===================================================================
--- /trunk/Ohana/src/kapa2/src/bDrawOverlay.c	(revision 16227)
+++ /trunk/Ohana/src/kapa2/src/bDrawOverlay.c	(revision 16228)
@@ -24,5 +24,5 @@
   }
 
-  Image_to_Screen (&X0, &Y0, 0.0, 0.0, image);
+  Image_to_Screen (&X0, &Y0, 0.0, 0.0, &image[0].picture);
   X0 -= image[0].picture.x;
   Y0 -= image[0].picture.y;
