Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom16.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom16.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom16.c	(revision 13436)
@@ -1,6 +1,15 @@
 # include "Ximage.h"
-# define XPIX(x,Rx,S) (x*S + Rx)
-# define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
 # define FRAC(a) ((a) - (int)(a))
+
+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 CreateZoom16 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
@@ -9,9 +18,9 @@
   int i_start, i_end, j_start, j_end;
   int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY;
+  int dx, dy, DX, DY, pixelN;
   double expand, zoomscale, Rx, Ry;
   int expand_in, expand_out;
   unsigned char *out_pix, *out_pix2, *data;
-  unsigned char *in_pix,  *in_pix2;
+  float *imdata, *in_pix,  *in_pix2;
   unsigned char pixel1[256], pixel2[256];
   unsigned char pixvalue1, pixvalue2;
@@ -37,4 +46,13 @@
   back1 = 0x0000ff & back;
   back2 = 0x0000ff & (back >> 8);
+  // define the color transform parameters
+  MaxValue = graphic[0].Npixels - 1;
+  if (image[0].range != 0.0) {
+    slope = graphic[0].Npixels / image[0].range;
+    start = graphic[0].Npixels * image[0].zero / image[0].range;
+  } else {
+    slope = 1.0;
+    start = image[0].zero;
+  }
 
   zoomscale = MAX (5, image[0].expand + 5);
@@ -56,5 +74,6 @@
 
   data = out_pix = (unsigned char *) image[0].zoom.data;
-  in_pix  = (unsigned char *) (image[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
+  imdata  = (float *) 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) **********/
@@ -91,12 +110,13 @@
     if (expand_out == 1) {
       for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=2) {
-	out_pix[0] = pixel1[*in_pix2];
-	out_pix[1] = pixel2[*in_pix2];
+	pixelN = PixelLookup(*in_pix2);
+	out_pix[0] = pixel1[pixelN];
+	out_pix[1] = pixel2[pixelN];
       }
-    }
-    else {
+    } else {
       for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 2*expand_out) { 
-	pixvalue1 = pixel1[*in_pix2];
-	pixvalue2 = pixel2[*in_pix2];
+	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)) {
@@ -129,6 +149,6 @@
   }
 
-  image[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, 16, ZPixmap, 0, 
-					image[0].zoom.data, image[0].zoom.dx, image[0].zoom.dy, 32, 0);
+  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);
   
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom24.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom24.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom24.c	(revision 13436)
@@ -1,6 +1,15 @@
 # include "Ximage.h"
-# define XPIX(x,Rx,S) (x*S + Rx)
-# define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
 # define FRAC(a) ((a) - (int)(a))
+
+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 CreateZoom24 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
@@ -9,9 +18,9 @@
   int i_start, i_end, j_start, j_end;
   int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY;
+  int dx, dy, DX, DY, pixelN;
   double expand, zoomscale, Rx, Ry;
   int expand_in, expand_out;
   unsigned char *out_pix, *out_pix2, *data;
-  unsigned char *in_pix,  *in_pix2;
+  float *imdata, *in_pix, *in_pix2;
   unsigned char pixel1[256], pixel2[256], pixel3[256];
   unsigned char pixvalue1, pixvalue2, pixvalue3;
@@ -41,4 +50,14 @@
   back3 = 0x0000ff & (back >> 16);
 
+  // define the color transform parameters
+  MaxValue = graphic[0].Npixels - 1;
+  if (image[0].range != 0.0) {
+    slope = graphic[0].Npixels / image[0].range;
+    start = graphic[0].Npixels * image[0].zero / image[0].range;
+  } else {
+    slope = 1.0;
+    start = image[0].zero;
+  }
+
   zoomscale = MAX (5, image[0].expand + 5);
   expand = 1 / zoomscale;
@@ -59,5 +78,6 @@
 
   data = out_pix = (unsigned char *) image[0].zoom.data;
-  in_pix  = (unsigned char *) (image[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
+  imdata  = (float *) 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) **********/
@@ -97,14 +117,15 @@
     if (expand_out == 1) {
       for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) {
-	out_pix[0] = pixel1[*in_pix2];
-	out_pix[1] = pixel2[*in_pix2];
-	out_pix[2] = pixel3[*in_pix2];
+	pixelN = PixelLookup(*in_pix2);
+	out_pix[0] = pixel1[pixelN];
+	out_pix[1] = pixel2[pixelN];
+	out_pix[2] = pixel3[pixelN];
       }
-    }
-    else {
+    } else {
       for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) { 
-	pixvalue1 = pixel1[*in_pix2];
-	pixvalue2 = pixel2[*in_pix2];
-	pixvalue3 = pixel3[*in_pix2];
+	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) {
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom32.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom32.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom32.c	(revision 13436)
@@ -1,6 +1,15 @@
 # include "Ximage.h"
-# define XPIX(x,Rx,S) (x*S + Rx)
-# define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
 # define FRAC(a) ((a) - (int)(a))
+
+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 CreateZoom32 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
@@ -9,9 +18,9 @@
   int i_start, i_end, j_start, j_end;
   int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY;
+  int dx, dy, DX, DY, pixelN;
   double expand, zoomscale, Rx, Ry;
   int expand_in, expand_out;
-  unsigned int *out_pix, *out_pix2, *data;
-  unsigned char  *in_pix,  *in_pix2;
+  unsigned int *out_pix, *out_pix2;
+  float *imdata, *in_pix, *in_pix2;
   unsigned long pixel[256], pixvalue;
   unsigned long back;
@@ -28,4 +37,14 @@
   }
   back = graphic[0].back;
+
+  // define the color transform parameters
+  MaxValue = graphic[0].Npixels - 1;
+  if (image[0].range != 0.0) {
+    slope = graphic[0].Npixels / image[0].range;
+    start = graphic[0].Npixels * image[0].zero / image[0].range;
+  } else {
+    slope = 1.0;
+    start = image[0].zero;
+  }
 
   zoomscale = MAX (5, image[0].expand + 5);
@@ -49,6 +68,6 @@
 
   out_pix = (unsigned int *) image[0].zoom.data;
-  data = (unsigned int *) image[0].zoom.data;
-  in_pix  = (unsigned char *) (image[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
+  imdata  = (float *) 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) **********/
@@ -81,10 +100,12 @@
     if (expand_out == 1) {
       for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
-	out_pix[0] = pixel[*in_pix2];
+	pixelN = PixelLookup(*in_pix2);
+	out_pix[0] = pixel[pixelN];
       }
     }
     else {
       for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
-	pixvalue = *(pixel + *in_pix2);
+	pixelN   = PixelLookup(*in_pix2);
+	pixvalue = pixel[pixelN];
 	out_pix2 = out_pix;
 	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom8.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom8.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/CreateZoom8.c	(revision 13436)
@@ -1,6 +1,15 @@
 # include "Ximage.h"
-# define XPIX(x,Rx,S) (x*S + Rx)
-# define ZPIX(value,Rz1,Rz2) (value*Rz1 - Rz2)
 # define FRAC(a) ((a) - (int)(a))
+
+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 CreateZoom8 (KapaImageWidget *image, Graphic *graphic, double x, double y) {
@@ -9,9 +18,9 @@
   int i_start, i_end, j_start, j_end;
   int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY;
+  int dx, dy, DX, DY, pixelN;
   double expand, zoomscale, Rx, Ry;
   int expand_in, expand_out;
-  char  *out_pix, *out_pix2;
-  char  *in_pix,  *in_pix2;
+  unsigned char *out_pix, *out_pix2;
+  float *imdata, *in_pix, *in_pix2;
   unsigned long pixel[256], pixvalue;
   unsigned long back;
@@ -30,30 +39,18 @@
   back = graphic[0].back;
 
+  // define the color transform parameters
+  MaxValue = graphic[0].Npixels - 1;
+  if (image[0].range != 0.0) {
+    slope = graphic[0].Npixels / image[0].range;
+    start = graphic[0].Npixels * image[0].zero / image[0].range;
+  } else {
+    slope = 1.0;
+    start = 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].matrix.Naxis[0];
-  DY = image[0].matrix.Naxis[1];
-  Rx = 0.5*(DX - (dx - 1)*expand) - x;
-  Ry = 0.5*(DY - (dy - 1)*expand) - y;
-  data coords of 0,0 point in pic array 
-  X = 0.5*image[0].matrix.Naxis[0] - expand*((int)(0.5*image[0].zoom.dx + 0.5) - 0.0) - image[0].X;
-  Y = 0.5*image[0].matrix.Naxis[1] - expand*((int)(0.5*image[0].zoom.dy + 0.5) - 0.0) - image[0].Y;  
-  i_start = MIN (MAX (-Rx / expand, 0), dx - expand_out + 1);
-  j_start = MIN (MAX (-Ry / expand, 0), 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 = image[0].zoom.data;
-  in_pix  = (char *) (image[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
-
-  */
 
   dx = image[0].zoom.dx;
@@ -72,5 +69,6 @@
 
   out_pix = (char *) image[0].zoom.data;
-  in_pix  = (char *) (image[0].matrix.buffer) + DX*(int)MAX(Ry,0) + (int)MAX(Rx,0);
+  imdata  = (float *) 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) **********/
@@ -100,10 +98,12 @@
     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 {
+      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) { 
-	pixvalue = *(pixel + *in_pix2);
+	pixelN   = PixelLookup(*in_pix2);
+	pixvalue = pixel[pixelN];
 	out_pix2 = out_pix;
 	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
@@ -131,5 +131,5 @@
   
   /**** fill in top area ****/
-  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - image[0].zoom.data < dx*dy); j++, out_pix++) { 
+  for (j = 0; (j < dx*(dy - j_end)) && (out_pix - (unsigned char *) image[0].zoom.data < dx*dy); j++, out_pix++) { 
     *out_pix = back;
   }
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/JPEGit24.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/JPEGit24.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/JPEGit24.c	(revision 13436)
@@ -5,4 +5,15 @@
 # define WHITE_G 255
 # define WHITE_B 255
+
+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);
+}
 
 // XXX this currently writes out the jpeg for just the active image
@@ -21,9 +32,10 @@
   int i_start, i_end, j_start, j_end;
   int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY;
+  int dx, dy, DX, DY, pixelN;
   int status, Nbytes, quality;
   int expand_in, expand_out;
   double expand, Rx, Ry, X, Y;
-  unsigned char *out_pix, *in_pix, *in_pix_ref;
+  unsigned char *out_pix;
+  float *imdata, *in_pix, *in_pix_ref;
   unsigned char pixel1[256], pixel2[256], pixel3[256];
   char filename[1024];
@@ -70,4 +82,14 @@
   }
 
+  // define the color transform parameters
+  MaxValue = graphic[0].Npixels - 1;
+  if (image[0].range != 0.0) {
+    slope = graphic[0].Npixels / image[0].range;
+    start = graphic[0].Npixels * image[0].zero / image[0].range;
+  } else {
+    slope = 1.0;
+    start = image[0].zero;
+  }
+
   expand = expand_in = expand_out = 1.0;
   if (image[0].expand == 0) /* set up expansions */
@@ -123,5 +145,6 @@
   ALLOCATE (line_buffer, JSAMPLE, 3*dx);
 
-  in_pix_ref  = (unsigned char *) (image[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+  imdata = (float *) image[0].matrix.buffer;
+  in_pix_ref = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
 
   /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
@@ -154,8 +177,9 @@
     /*** fill in the picture region ***/
     for (i = i_start; i < i_end; i+=expand_out, in_pix+=expand_in) {
+      pixelN = PixelLookup(*in_pix);
       for (ii = 0; ii < expand_out; ii++, out_pix+=3) {
-	out_pix[0] = pixel1[*in_pix];
-	out_pix[1] = pixel2[*in_pix];
-	out_pix[2] = pixel3[*in_pix];
+	out_pix[0] = pixel1[pixelN];
+	out_pix[1] = pixel2[pixelN];
+	out_pix[2] = pixel3[pixelN];
       }
     }
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap16.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap16.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap16.c	(revision 13436)
@@ -1,4 +1,14 @@
 # include "Ximage.h"
-# define FRAC(a) ((a) - (int)(a))
+
+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) {
@@ -7,18 +17,18 @@
   int i_start, i_end, j_start, j_end;
   int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY;
+  int dx, dy, DX, DY, pixelN;
   double expand, Rx, Ry, X, Y;
   int expand_in, expand_out;
   unsigned char *out_pix, *out_pix2, *data;
-  unsigned char *in_pix,  *in_pix2;
-  unsigned char pixel1[256], pixel2[256], pixel3[256];
+  float *imdata, *in_pix, *in_pix2;
+  unsigned char pixel1[256], pixel2[256];
   unsigned char pixvalue1, pixvalue2;
   unsigned long back;
   unsigned char back1, back2;
 
+  // local array for pixel values (is this working??)
   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);
+    pixel1[i] = 0x00ff &  graphic[0].cmap[i].pixel;
+    pixel2[i] = 0x00ff & (graphic[0].cmap[i].pixel >> 8);
   }
   back = graphic[0].back;
@@ -26,4 +36,15 @@
   back2 = 0x00ff & (back >> 8);
 
+  // define the color transform parameters
+  MaxValue = graphic[0].Npixels - 1;
+  if (image[0].range != 0.0) {
+    slope = graphic[0].Npixels / image[0].range;
+    start = graphic[0].Npixels * image[0].zero / image[0].range;
+  } else {
+    slope = 1.0;
+    start = image[0].zero;
+  }
+
+  // set up expansions
   expand = expand_in = expand_out = 1.0;
   if (image[0].expand == 0) /* set up expansions */
@@ -40,4 +61,5 @@
   }
 
+  // define the image boundaries
   dx = image[0].picture.dx;
   dy = image[0].picture.dy;
@@ -76,5 +98,6 @@
 
   data = out_pix = (unsigned char *) image[0].picture.data;
-  in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+  imdata  = (float *) matrix[0].buffer;
+  in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
 
   /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
@@ -105,12 +128,14 @@
     if (expand_out == 1) {
       for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=2) {
-	out_pix[0] = pixel1[*in_pix2];
-	out_pix[1] = pixel2[*in_pix2];
+	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) { 
-	pixvalue1 = pixel1[*in_pix2];
-	pixvalue2 = pixel2[*in_pix2];
+	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)) {
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap24.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap24.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap24.c	(revision 13436)
@@ -1,4 +1,14 @@
 # include "Ximage.h"
-# define FRAC(a) ((a) - (int)(a))
+
+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) {
@@ -7,9 +17,9 @@
   int i_start, i_end, j_start, j_end;
   int dropback, extra;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY;
+  int dx, dy, DX, DY, pixelN;
   double expand, Rx, Ry, X, Y;
   int expand_in, expand_out;
   unsigned char *out_pix, *out_pix2, *data;
-  unsigned char *in_pix,  *in_pix2;
+  float *imdata, *in_pix, *in_pix2;
   unsigned char pixel1[256], pixel2[256], pixel3[256];
   unsigned char pixvalue1, pixvalue2, pixvalue3;
@@ -17,4 +27,5 @@
   unsigned char back1, back2, back3;
 
+  // local arrays for pixel values
   for (i = 0; i < 256; i++) { /* set up pixel array */
     pixel1[i] = 0x0000ff &  graphic[0].cmap[i].pixel;
@@ -27,4 +38,15 @@
   back3 = 0x0000ff & (back >> 16);
 
+  // define the color transform parameters
+  MaxValue = graphic[0].Npixels - 1;
+  if (image[0].range != 0.0) {
+    slope = graphic[0].Npixels / image[0].range;
+    start = graphic[0].Npixels * image[0].zero / image[0].range;
+  } else {
+    slope = 1.0;
+    start = image[0].zero;
+  }
+
+  // set up expansions
   expand = expand_in = expand_out = 1.0;
   if (image[0].expand == 0) /* set up expansions */
@@ -78,5 +100,6 @@
 
   data = out_pix = (unsigned char *) image[0].picture.data;
-  in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+  imdata  = (float *) matrix[0].buffer;
+  in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
 
   /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
@@ -110,14 +133,15 @@
     if (expand_out == 1) {
       for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix+=3) {
-	out_pix[0] = pixel1[*in_pix2];
-	out_pix[1] = pixel2[*in_pix2];
-	out_pix[2] = pixel3[*in_pix2];
+	pixelN = PixelLookup(*in_pix2);
+	out_pix[0] = pixel1[pixelN];
+	out_pix[1] = pixel2[pixelN];
+	out_pix[2] = pixel3[pixelN];
       }
-    }
-    else {
+    } else {
       for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= 3*expand_out) { 
-	pixvalue1 = pixel1[*in_pix2];
-	pixvalue2 = pixel2[*in_pix2];
-	pixvalue3 = pixel3[*in_pix2];
+	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) {
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap32.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap32.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap32.c	(revision 13436)
@@ -1,4 +1,14 @@
 # include "Ximage.h"
-# define FRAC(a) ((a) - (int)(a))
+
+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 Remap32 (Graphic *graphic, KapaImageWidget *image, Matrix *matrix) {
@@ -7,19 +17,31 @@
   int i_start, i_end, j_start, j_end;
   int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY;
+  int dx, dy, DX, DY, pixelN;
   double expand, Rx, Ry, X, Y;
   int expand_in, expand_out;
   unsigned int *out_pix, *out_pix2;
-  unsigned char *in_pix,  *in_pix2;
+  float *imdata, *in_pix, *in_pix2;
   unsigned long pixel[256], pixvalue;
   unsigned long back;
 
-  for (i = 0; i < 256; i++) { /* set up pixel array */
+  // local array for pixel values
+  for (i = 0; i < 256; 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].range != 0.0) {
+    slope = graphic[0].Npixels / image[0].range;
+    start = graphic[0].Npixels * image[0].zero / image[0].range;
+  } else {
+    slope = 1.0;
+    start = image[0].zero;
+  }
+
+  // set up expansions
   expand = expand_in = expand_out = 1.0;
-  if (image[0].expand == 0) /* set up expansions */
+  if (image[0].expand == 0) 
     image[0].expand = 1;
   if (image[0].expand > 0) {
@@ -34,4 +56,5 @@
   }
 
+  // define the image boundaries
   dx = image[0].picture.dx;
   dy = image[0].picture.dy;
@@ -69,5 +92,6 @@
 
   out_pix = (unsigned int *) image[0].picture.data;
-  in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+  imdata  = (float *) matrix[0].buffer;
+  in_pix  = &imdata[DX*(int)MAX(Y,0) + (int)MAX(X,0)];
 
   /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
@@ -92,11 +116,12 @@
     if (expand_out == 1) {
       for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
-	*out_pix = pixel[*in_pix2];
+	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) { 
-	pixvalue = pixel[*in_pix2];
+	pixelN   = PixelLookup(*in_pix2);
+	pixvalue = pixel[pixelN];
 	out_pix2 = out_pix;
 	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap8.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap8.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/Remap8.c	(revision 13436)
@@ -1,4 +1,14 @@
 # include "Ximage.h"
-# define FRAC(a) ((a) - (int)(a))
+
+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) {
@@ -7,17 +17,29 @@
   int i_start, i_end, j_start, j_end;
   int dropback;  /* this is a bit of a kludge... */
-  int dx, dy, DX, DY;
+  int dx, dy, DX, DY, pixelN;
   double expand, Rx, Ry, X, Y;
   int expand_in, expand_out;
   unsigned char *out_pix, *out_pix2;
-  unsigned char *in_pix,  *in_pix2;
+  float *imdata, *in_pix,  *in_pix2;
   unsigned long pixel[256], pixvalue;
   unsigned long back;
 
-  for (i = 0; i < 256; i++) { /* set up pixel array */
+  // local array for pixel values
+  for (i = 0; i < 256; 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].range != 0.0) {
+    slope = graphic[0].Npixels / image[0].range;
+    start = graphic[0].Npixels * image[0].zero / image[0].range;
+  } else {
+    slope = 1.0;
+    start = image[0].zero;
+  }
+
+  // set up expansions
   expand = expand_in = expand_out = 1.0;
   if (image[0].expand == 0) /* set up expansions */
@@ -34,8 +56,10 @@
   }
 
+  // define the image boundaries
   dx = image[0].picture.dx;
   dy = image[0].picture.dy;
   DX = matrix[0].Naxis[0];
   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);
@@ -69,5 +93,6 @@
 
   out_pix = (unsigned char *) image[0].picture.data;
-  in_pix  = (unsigned char *) matrix[0].buffer + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+  imdata  = (float *) matrix[0].buffer;
+  in_pix  = &imdata[(int)(DX*(int)MAX(Y,0) + (int)MAX(X,0))];
 
   /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
@@ -92,11 +117,11 @@
     if (expand_out == 1) {
       for (i = i_start; i < i_end; i++, in_pix2+= expand_in, out_pix++) {
-	*out_pix = pixel[*in_pix2];
+	pixelN = PixelLookup(*in_pix2);
+	*out_pix = pixel[pixelN];
       }
-      /* *out_pix = *(pixel + *in_pix2);  */
-    }
-    else {
+    } else {
       for (i = i_start; i < i_end; i+= expand_out, in_pix2++, out_pix+= expand_out) { 
-	pixvalue = pixel[*in_pix2];
+	pixelN   = PixelLookup(*in_pix2);
+	pixvalue = pixel[pixelN];
 	out_pix2 = out_pix;
 	for (jj = 0; jj < expand_out; jj++, out_pix2+=(dx-expand_out)) {
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetGraphData.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetGraphData.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/SetGraphData.c	(revision 13436)
@@ -34,4 +34,22 @@
 		  &graph[0].data.ymin, 
 		  &graph[0].data.ymax);
+
+  KiiScanMessage (sock, "%f %f %f %f", 
+		  &graph[0].data.coords.pc1_1, &graph[0].data.coords.pc2_2,
+		  &graph[0].data.coords.pc1_2, &graph[0].data.coords.pc2_1);
+
+  KiiScanMessage (sock, "%d %d %s", 
+		  &graph[0].data.flipeast, &graph[0].data.flipnorth,
+		  graph[0].data.coords.ctype);
+
+  KiiScanMessage (sock, "%lf %lf %f %f %f %f", 
+		  &graph[0].data.coords.crval1,
+		  &graph[0].data.coords.crval2,
+		  &graph[0].data.coords.crpix1,
+		  &graph[0].data.coords.crpix2,
+		  &graph[0].data.coords.cdelt1,
+		  &graph[0].data.coords.cdelt2);
+
+
 
   xmin = graph[0].data.xmin;
@@ -77,8 +95,25 @@
 		  graph[0].data.etype, graph[0].data.ebar, graph[0].data.color, 
 		  graph[0].data.lweight, graph[0].data.size);
+
   KiiSendMessage (sock, "%g %g %g %g", 
 		  graph[0].data.xmin, graph[0].data.xmax, 
 		  graph[0].data.ymin, graph[0].data.ymax);
 
+  KiiSendMessage (sock, "%g %g %g %g", 
+		  graph[0].data.coords.pc1_1, graph[0].data.coords.pc2_2,
+		  graph[0].data.coords.pc1_2, graph[0].data.coords.pc2_1);
+
+  KiiSendMessage (sock, "%d %d %s", 
+		  graph[0].data.flipeast, graph[0].data.flipnorth,
+		  graph[0].data.coords.ctype);
+
+  KiiSendMessage (sock, "%g %g %g %g %g %g", 
+		  graph[0].data.coords.crval1,
+		  graph[0].data.coords.crval2,
+		  graph[0].data.coords.crpix1,
+		  graph[0].data.coords.crpix2,
+		  graph[0].data.coords.cdelt1,
+		  graph[0].data.coords.cdelt2);
+
   return (TRUE);
 }
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/UpdatePointer.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/UpdatePointer.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/UpdatePointer.c	(revision 13436)
@@ -6,4 +6,5 @@
   int textpad;
   double  x, y, z;
+  float *data;
   char line[100];
   Section *section;
@@ -18,17 +19,15 @@
   if (image[0].MovePointer && InPicture ((XButtonEvent *)event, &image[0].picture)) {
 
+    data = (float *) image[0].matrix.buffer;
     Screen_to_Image (&x, &y, (double)event[0].x, (double)event[0].y, image);
 
-    if ((x >= 0) && (x < image[0].matrix.Naxis[0]) && (y >= 0) && (y < image[0].matrix.Naxis[1])) {
-      /*
-      X = event[0].x - image[0].picture.x;
-      Y = event[0].y - image[0].picture.y;
-      pix = MIN (MAX (X + Y*image[0].picture.dx, 0), image[0].picture.dx*image[0].picture.dy - 1);
-      z = image[0].range * image[0].picture.data[pix] / image[0].Npixels + image[0].zero;
-      */
-      z = -1;
-    }
-    else
-      z = -1;
+    z = -1;
+    if (x < 0) goto skip;
+    if (x >= image[0].matrix.Naxis[0]) goto skip;
+    if (y < 0) goto skip;
+    if (y >= image[0].matrix.Naxis[1]) goto skip;
+    z = data[(int)(y)*image[0].matrix.Naxis[0] + (int)(x)];
+
+  skip:
     image[0].x = x;
     image[0].y = y;
@@ -45,5 +44,4 @@
     CrossHairs (graphic, image);
     XFlush (graphic[0].display);
-    
   }
   
@@ -56,5 +54,5 @@
     XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].fore);
     bzero (line, 100);
-    sprintf (line, "%25.2f", z);
+    sprintf (line, "%22.3f", z);
     XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
                  image[0].text_x + PAD1, image[0].text_y + textpad + PAD1, 
Index: /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/bDrawOverlay.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/bDrawOverlay.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/kapa2/src/bDrawOverlay.c	(revision 13436)
@@ -23,10 +23,4 @@
     expand = fabs((double)image[0].expand);
   }
-  /* 
-     X = 0.5*image[0].matrix.Naxis[0] - expand*((int)(0.5*image[0].picture.dx + 0.5) - 0.0) - image[0].X;
-     Y = 0.5*image[0].matrix.Naxis[1] - expand*((int)(0.5*image[0].picture.dy + 0.5) - 0.0) - image[0].Y;  
-     X0 =  (image[0].X + 1 - (int)(0.5*image[0].matrix.Naxis[0] + 0.5) - X + (int)X)/expand + image[0].picture.x + 0.5*image[0].picture.dx;
-     Y0 =  (image[0].Y + 1 - (int)(0.5*image[0].matrix.Naxis[1] + 0.5) - Y + (int)Y)/expand + image[0].picture.y + 0.5*image[0].picture.dy;
-  */
 
   Image_to_Screen (&X0, &Y0, 0.0, 0.0, image);
Index: /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KapaWindow.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KapaWindow.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KapaWindow.c	(revision 13436)
@@ -120,7 +120,25 @@
 		  data[0].etype, data[0].ebar, data[0].color, 
 		  data[0].lweight, data[0].size);
+
   KiiSendMessage (fd, "%g %g %g %g", 
 		  data[0].xmin, data[0].xmax, 
 		  data[0].ymin, data[0].ymax);
+
+  KiiSendMessage (fd, "%g %g %g %g", 
+		  data[0].coords.pc1_1, data[0].coords.pc2_2,
+		  data[0].coords.pc1_2, data[0].coords.pc2_1);
+
+  KiiSendMessage (fd, "%d %d %s", 
+		  data[0].flipeast, data[0].flipnorth,
+		  data[0].coords.ctype);
+
+  KiiSendMessage (fd, "%g %g %g %g %g %g", 
+		  data[0].coords.crval1,
+		  data[0].coords.crval2,
+		  data[0].coords.crpix1,
+		  data[0].coords.crpix2,
+		  data[0].coords.cdelt1,
+		  data[0].coords.cdelt2);
+
   KiiWaitAnswer (fd, "DONE");
   return (TRUE);
@@ -138,7 +156,25 @@
 		  &data[0].etype, &data[0].ebar, &data[0].color, 
 		  &data[0].lweight, &data[0].size);
+
   KiiScanMessage (fd, "%lf %lf %lf %lf", 
 		  &data[0].xmin, &data[0].xmax, 
 		  &data[0].ymin, &data[0].ymax);
+
+  KiiScanMessage (fd, "%f %f %f %f", 
+		  &data[0].coords.pc1_1, &data[0].coords.pc2_2,
+		  &data[0].coords.pc1_2, &data[0].coords.pc2_1);
+
+  KiiScanMessage (fd, "%d %d %s", 
+		  &data[0].flipeast, &data[0].flipnorth,
+		  data[0].coords.ctype);
+
+  KiiScanMessage (fd, "%lf %lf %f %f %f %f", 
+		  &data[0].coords.crval1,
+		  &data[0].coords.crval2,
+		  &data[0].coords.crpix1,
+		  &data[0].coords.crpix2,
+		  &data[0].coords.cdelt1,
+		  &data[0].coords.cdelt2);
+
   KiiWaitAnswer (fd, "DONE");
   return (TRUE);
@@ -240,5 +276,5 @@
 
   KiiSendCommand (fd, 4, "GLIM"); 
-  KiiScanMessage (fd, "%lf %lf", dx, dy); 
+  KiiScanMessage (fd, "%f %f", dx, dy); 
   KiiWaitAnswer (fd, "DONE");
   return (TRUE);
Index: /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KiiPicture.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KiiPicture.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/libkapa/src/KiiPicture.c	(revision 13436)
@@ -2,4 +2,39 @@
 
 int KiiNewPicture1D (int fd, KiiImage *image, KapaImageData *data, Coords *coords) {
+
+  int i;
+  int Npix, Ncolors, NNcolors, size;
+  float *in, min, max;
+  char *out, *outbuffer;
+  double a1, a2;
+
+  Npix = image[0].Nx*image[0].Ny;
+
+  KiiSendCommand (fd, 4, "READ"); /* tell kapa to look for the incoming image */
+  KiiScanMessage (fd, "%d", &Ncolors);
+
+  in = image[0].data1d;
+
+  /* these are for a future upgrade */
+  min = max = 0.0;
+  size = Npix*sizeof(float);
+
+  /* done with the conversion, now send kapa the converted picture */
+  KiiSendMessage (fd, "%8d %8d", image[0].Nx, image[0].Ny);
+  KiiSendMessage (fd, "-32 1 0.0 1.0");
+  KiiSendMessage (fd, "%f %f %s %s", data[0].zero, data[0].range, data[0].name, data[0].file);
+  KiiSendMessage (fd, "%f %f %d ", min, max, size);
+  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval1, coords[0].crpix1, coords[0].cdelt1, coords[0].pc1_1, coords[0].pc1_2);
+  KiiSendMessage (fd, "%f %f %g %g %g ", coords[0].crval2, coords[0].crpix2, coords[0].cdelt2, coords[0].pc2_1, coords[0].pc2_2);
+  KiiSendMessage (fd, "%s", coords[0].ctype);
+
+  /* send the image data */
+  write (fd, image[0].data1d, size);
+
+  KiiWaitAnswer (fd, "DONE");
+  return (TRUE);
+}
+
+int KiiNewPicture1D_8bit (int fd, KiiImage *image, KapaImageData *data, Coords *coords) {
 
   int i;
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dmt.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dmt.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/dvo/dmt.c	(revision 13436)
@@ -4,5 +4,5 @@
 int dmt (int argc, char **argv) {
   
-  int i, m, k, N, SaveVectors;
+  int i, m, k, N, kapa, SaveVectors;
   int Nsec, Nsecfilt, NPTS;
   double Radius;
Index: /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/style_args.c
===================================================================
--- /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/style_args.c	(revision 13435)
+++ /branches/kapa-mods-2007-05/Ohana/src/opihi/lib.data/style_args.c	(revision 13436)
@@ -4,20 +4,22 @@
 int style_args (Graphdata *graphmode, int *argc, char **argv, int *kapa) {
   
-  int N, Ngraph;
-  char *name;
+  int N;
+  char *colorName;
+  char *kapaName;
 
-  name = NULL;
+  kapaName = NULL;
   if ((N = get_argument (*argc, argv, "-n"))) {
     remove_argument (N, argc, argv);
-    name = strcreate (argv[N]);
+    kapaName = strcreate (argv[N]);
     remove_argument (N, argc, argv);
   }
-  if (!GetGraph (graphmode, kapa, name)) return (FALSE);
-  FREE (name);
+  if (!GetGraph (graphmode, kapa, kapaName)) return (FALSE);
+  FREE (kapaName);
 
   if (*argc == 1) {
-    name = KapaColorName (graphmode[0].color);
-    gprint (GP_ERR, "current style (%d): -x %d -c %s -pt %d -lt %d -lw %f -sz %f\n", Ngraph,
-	     graphmode[0].style, name, graphmode[0].ptype, 
+    kapaName = GetKapaName();
+    colorName = KapaColorName (graphmode[0].color);
+    gprint (GP_ERR, "current style (%s): -x %d -c %s -pt %d -lt %d -lw %f -sz %f\n", kapaName,
+	     graphmode[0].style, colorName, graphmode[0].ptype, 
 	     graphmode[0].ltype, graphmode[0].lweight,
 	     graphmode[0].size);
