Index: /trunk/Ohana/src/kii/Makefile
===================================================================
--- /trunk/Ohana/src/kii/Makefile	(revision 2466)
+++ /trunk/Ohana/src/kii/Makefile	(revision 2466)
@@ -0,0 +1,124 @@
+include ../../Configure
+HOME 	=	$(ROOT)/src/kii
+PROGRAM =       kii
+
+default: $(PROGRAM)
+
+INC	=	$(HOME)/include
+BIN	=	$(HOME)/bin
+BDIR	=	$(HOME)/button
+CDIR	=	$(HOME)/colorbar
+EDIR	=	$(HOME)/event
+MDIR	=	$(HOME)/misc
+ODIR	=	$(HOME)/overlay
+PDIR	=	$(HOME)/picture
+SDIR	=	$(HOME)/setup
+ZDIR	=	$(HOME)/zoom
+DESTBIN	=	$(LBIN)
+DESTLIB	=	$(LLIB)
+DESTINC	=	$(LINC)
+DESTMAN	=	$(LMAN)
+#
+INCS	= 	-I$(INC) -I$(LINC) -I$(XINC) -I$(LINC)/$(ARCH)
+LIBS	= 	-L$(LLIB) $(XLIB) -lohana -lFITS -ljpeg -lX11 -lsocket -lnsl -lm
+# LIBS	= 	-L$(LLIB) $(XLIB) -lohana -lFITS -ljpeg -lX11 -lsocket -lnsl -lm -static
+CFLAGS  =	-o $*.$(ARCH).o $(INCS) 
+CCFLAGS	=	$(INCS) $(LIBS) 
+
+# local source / object files ########################
+BOBJ = \
+$(BDIR)/ButtonFunctions.$(ARCH).o         $(BDIR)/InButton.$(ARCH).o           \
+$(BDIR)/CheckButtons.$(ARCH).o     	  $(BDIR)/InPicture.$(ARCH).o          \
+$(BDIR)/DrawButton.$(ARCH).o       	  $(BDIR)/InvertButton.$(ARCH).o       \
+$(BDIR)/FlashButton.$(ARCH).o      	  $(BDIR)/PSit.$(ARCH).o		\
+$(BDIR)/JPEGit.$(ARCH).o
+
+COBJ = \
+$(CDIR)/CreateColorbar.$(ARCH).o          $(CDIR)/SetColormap.$(ARCH).o        \
+$(CDIR)/DragColorbar.$(ARCH).o
+
+EOBJ = \
+$(EDIR)/CheckPipe.$(ARCH).o               $(EDIR)/Stop.$(ARCH).o               \
+$(EDIR)/EventLoop.$(ARCH).o         	  $(EDIR)/Reconfig.$(ARCH).o           \
+$(EDIR)/InterpretKeys.$(ARCH).o     	  $(EDIR)/Refresh.$(ARCH).o            \
+$(EDIR)/InterpretPresses.$(ARCH).o  	  $(EDIR)/FlushDisplay.$(ARCH).o
+
+MOBJ = \
+$(MDIR)/hh_hms.$(ARCH).o		  
+
+OOBJ = \
+$(ODIR)/EraseOverlay.$(ARCH).o            $(ODIR)/PaintOverlay.$(ARCH).o       \
+$(ODIR)/LoadOverlay.$(ARCH).o   	  $(ODIR)/SaveOverlay.$(ARCH).o        \
+$(ODIR)/DrawOverlay.$(ARCH).o		  $(ODIR)/CSaveOverlay.$(ARCH).o 	\
+$(ODIR)/PaintTickmarks.$(ARCH).o          $(ODIR)/LoadTickmarks.$(ARCH).o
+
+POBJ = \
+$(PDIR)/CreatePicture.$(ARCH).o           $(PDIR)/Reorient.$(ARCH).o           \
+$(PDIR)/NewPicture.$(ARCH).o        	  $(PDIR)/Center.$(ARCH).o             \
+$(PDIR)/PositionPictures.$(ARCH).o  	  $(PDIR)/StatusBox.$(ARCH).o          \
+$(PDIR)/cursor.$(ARCH).o 							\
+$(PDIR)/CursorOps.$(ARCH).o 		  $(PDIR)/Resize.$(ARCH).o 		\
+$(PDIR)/Remap8.$(ARCH).o 		  $(PDIR)/Remap24.$(ARCH).o 		\
+$(PDIR)/Remap.$(ARCH).o             	  $(PDIR)/Remap32.$(ARCH).o		\
+$(PDIR)/Remap16.$(ARCH).o
+
+SOBJ = \
+$(SDIR)/CheckColors.$(ARCH).o             $(SDIR)/MakeGC.$(ARCH).o             \
+$(SDIR)/CheckDisplayName.$(ARCH).o  	  $(SDIR)/MapWindow.$(ARCH).o          \
+$(SDIR)/CheckFontName.$(ARCH).o     	  $(SDIR)/NameWindow.$(ARCH).o         \
+$(SDIR)/CheckGeometry.$(ARCH).o     	  $(SDIR)/OpenDisplay.$(ARCH).o        \
+$(SDIR)/CloseDisplay.$(ARCH).o      	  $(SDIR)/QuitX.$(ARCH).o              \
+$(SDIR)/CreateWindow.$(ARCH).o      	  $(SDIR)/SetNormalHints.$(ARCH).o     \
+$(SDIR)/DefineLayout.$(ARCH).o      	  $(SDIR)/SetUpDisplay.$(ARCH).o       \
+$(SDIR)/DrawBitmap.$(ARCH).o        	  $(SDIR)/SetUpWindow.$(ARCH).o        \
+$(SDIR)/GetColor.$(ARCH).o          	  $(SDIR)/SetWMHints.$(ARCH).o         \
+$(SDIR)/LoadFont.$(ARCH).o          	  $(SDIR)/TopWindow.$(ARCH).o          \
+$(SDIR)/MakeColormap.$(ARCH).o      	  $(SDIR)/Ximage.$(ARCH).o             \
+$(SDIR)/MakeCursor.$(ARCH).o              $(SDIR)/CheckVisual.$(ARCH).o
+
+ZOBJ = \
+$(ZDIR)/UpdatePointer.$(ARCH).o      \
+$(ZDIR)/CrossHairs.$(ARCH).o		  $(ZDIR)/UpdateStatusBox.$(ARCH).o	\
+$(ZDIR)/CreateZoom.$(ARCH).o              $(ZDIR)/CreateZoom32.$(ARCH).o        \
+$(ZDIR)/CreateZoom8.$(ARCH).o             $(ZDIR)/CreateZoom24.$(ARCH).o	\
+$(ZDIR)/CreateZoom16.$(ARCH).o
+
+
+OBJ  =  $(BOBJ) $(COBJ) $(EOBJ) $(MOBJ) $(OOBJ) $(POBJ) $(SOBJ) $(ZOBJ)
+
+# dependancy rules for include files ########################
+$(OBJ): $(INC)/Ximage.h \
+	$(INC)/constants.h \
+	$(INC)/structures.h \
+	$(INC)/prototypes.h
+
+#### nothing program-dependant below ####
+# dependancy rules for binary code ##########################
+$(PROGRAM): $(BIN)/$(PROGRAM).$(ARCH)
+
+$(BIN)/$(PROGRAM).$(ARCH): $(OBJ)
+	$(CC) $(OBJ) -o $(BIN)/$(PROGRAM).$(ARCH) $(CCFLAGS)
+
+install: $(DESTBIN)/$(PROGRAM)
+
+$(DESTBIN)/$(PROGRAM): $(BIN)/$(PROGRAM).$(ARCH)
+	rm -f $(DESTBIN)/$(PROGRAM)
+	cp $(BIN)/$(PROGRAM).$(ARCH) $(DESTBIN)/$(PROGRAM)
+
+# utilities #################################################
+clean:
+	rm -f $(BIN)/*.$(ARCH)
+	rm -f `find . -name "*.o"`
+	rm -f `find . -name "*~"`
+	rm -f `find . -name "#*"`
+
+dist: clean
+	rm -f */*.*.o
+	rm -f $(BIN)/$(PROGRAM).*
+
+.SUFFIXES: .$(ARCH).o
+
+.c.$(ARCH).o:
+	$(CC) $(CFLAGS) -c $<
+
+
Index: /trunk/Ohana/src/kii/button/ButtonFunctions.c
===================================================================
--- /trunk/Ohana/src/kii/button/ButtonFunctions.c	(revision 2466)
+++ /trunk/Ohana/src/kii/button/ButtonFunctions.c	(revision 2466)
@@ -0,0 +1,120 @@
+# include "Ximage.h"
+
+static char *GREY = "greyscale";
+static char *PUNS = "Puns";
+static char *RAINBOW = "Rainbow";
+
+int greycolors (Graphic *graphic, Layout *layout) {
+  char *name;
+  name = GREY;
+  SetColormap (graphic, layout, name);
+  CreateColorbar (layout, graphic);
+  Remap (graphic, layout, &layout[0].matrix);
+  CreateZoom (layout, graphic, 0, 0); 
+  return (TRUE);
+}
+
+int puns (Graphic *graphic, Layout *layout) {
+  char *name;
+  name = PUNS;
+  SetColormap (graphic, layout, name);
+  CreateColorbar (layout, graphic);
+  Remap (graphic, layout, &layout[0].matrix);
+  CreateZoom (layout, graphic, 0, 0); 
+  return (TRUE);
+}
+
+int rainbow (Graphic *graphic, Layout *layout) {
+  char *name;
+  name = RAINBOW;
+  SetColormap (graphic, layout, name);
+  CreateColorbar (layout, graphic);
+  Remap (graphic, layout, &layout[0].matrix);
+  CreateZoom (layout, graphic, 0, 0); 
+  return (TRUE);
+}
+
+int Recenter (Graphic *graphic, Layout *layout) {
+
+  layout[0].X = 0;
+  layout[0].Y = 0;
+ 
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int Rescale (Graphic *graphic, Layout *layout) {
+
+  layout[0].expand = 1;
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int RecenterRescale (Graphic *graphic, Layout *layout) {
+
+  layout[0].X = 0;
+  layout[0].Y = 0;
+  layout[0].expand = 1;
+ 
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int ToggleDEG (Graphic *graphic, Layout *layout) {
+
+  DECIMAL_DEG = DECIMAL_DEG ^ TRUE;
+  StatusBox (graphic, layout);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+/*********** overlay_button functions ************/
+int Overlay0 (Graphic *graphic, Layout *layout) {
+
+  OVERLAY[0] = OVERLAY[0] ^ TRUE;
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int Overlay1 (Graphic *graphic, Layout *layout) {
+
+  OVERLAY[1] = OVERLAY[1] ^ TRUE;
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int Overlay2 (Graphic *graphic, Layout *layout) {
+
+  OVERLAY[2] = OVERLAY[2] ^ TRUE;
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+int Overlay3 (Graphic *graphic, Layout *layout) {
+
+  OVERLAY[3] = OVERLAY[3] ^ TRUE;
+  Refresh (graphic, layout, 0);
+  FlushDisplay (graphic[0].display);
+  return (TRUE);
+
+}
+
+/* this routine is NOT independent of the number of overlays */
+
+
Index: /trunk/Ohana/src/kii/button/CheckButtons.c
===================================================================
--- /trunk/Ohana/src/kii/button/CheckButtons.c	(revision 2466)
+++ /trunk/Ohana/src/kii/button/CheckButtons.c	(revision 2466)
@@ -0,0 +1,57 @@
+# include "Ximage.h"
+# define PAD_X 10
+# define PAD_Y 10
+# define NPLANES 1
+# define NPIXELS 255
+
+/******** Here we test the Buttons specific to this program  *******/
+Button *
+CheckButtons (event, layout)
+XButtonEvent  event[];
+Layout        layout[];
+{
+
+  int i;
+  Button *button;
+  button = (Button *) NULL;
+
+  if (InButton (event, &layout[0].recenter_button)) 
+    button = &layout[0].recenter_button;
+
+  if (InButton (event, &layout[0].grey_button)) 
+    button = &layout[0].grey_button;
+
+  if (InButton (event, &layout[0].rainbow_button)) 
+    button = &layout[0].rainbow_button;
+
+  if (InButton (event, &layout[0].puns_button)) 
+    button = &layout[0].puns_button;
+
+  if (InButton (event, &layout[0].PS_button)) 
+    button = &layout[0].PS_button;
+
+  if (InButton (event, &layout[0].hms_button)) 
+    button = &layout[0].hms_button;
+
+  for (i = 0; i < NOVERLAYS; i++) {
+    if (InButton (event, &layout[0].overlay_button[i])) 
+      button = &layout[0].overlay_button[i];
+  }
+
+  return (button);
+
+}
+
+
+/* To define a button, you must:
+
+   0) add the button to the Layout structure in structures.h
+   1) place the info about the button in PositionPicture.c
+   2) (make any bitmaps needed and put them in buttons.h
+   3) place an entry in CheckButtons.c
+   4) Add the button to Refresh.c
+   5) create the button's function
+   6) add it to the Makefile
+   7) add it to the prototypes
+
+*/
Index: /trunk/Ohana/src/kii/button/DrawButton.c
===================================================================
--- /trunk/Ohana/src/kii/button/DrawButton.c	(revision 2466)
+++ /trunk/Ohana/src/kii/button/DrawButton.c	(revision 2466)
@@ -0,0 +1,44 @@
+# include "Ximage.h"
+
+void
+DrawButton (graphic, button)
+Graphic graphic[];
+Button button[];
+{
+  
+  int y, dX;
+  
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+  XFillRectangle (graphic[0].display, 
+		  graphic[0].window,
+		  graphic[0].gc,
+		  button[0].x,  button[0].y,
+		  button[0].dx, button[0].dy);
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  XDrawRectangle (graphic[0].display, 
+		  graphic[0].window,
+		  graphic[0].gc,
+		  button[0].x,  button[0].y,
+		  button[0].dx, button[0].dy);
+
+  if (button[0].text) {
+    dX = XTextWidth (graphic[0].font, button[0].bitmap, strlen(button[0].bitmap));
+    y = button[0].y + (button[0].dy + graphic[0].font[0].ascent)/2;
+    XDrawString (graphic[0].display, 
+		 graphic[0].window, 
+		 graphic[0].gc, 
+		 button[0].x + (button[0].dx - dX) / 2, y,
+		 button[0].bitmap, strlen(button[0].bitmap));
+  }
+  else {
+    DrawBitmap (graphic, 
+		button[0].x + (button[0].dx - button[0].width) / 2 + 1, 
+		button[0].y + (button[0].dy - button[0].height) / 2 + 1, 
+		button[0].width, button[0].height, 
+		button[0].bitmap, 1);
+  }
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+}
+
Index: /trunk/Ohana/src/kii/button/FlashButton.c
===================================================================
--- /trunk/Ohana/src/kii/button/FlashButton.c	(revision 2466)
+++ /trunk/Ohana/src/kii/button/FlashButton.c	(revision 2466)
@@ -0,0 +1,22 @@
+# include "Ximage.h"
+
+void FlashButton (Graphic *graphic, Button *button) {
+
+  unsigned long black, white;
+
+  black =  graphic[0].black;
+  white =  graphic[0].white;
+  graphic[0].black = white;
+  graphic[0].white = black;
+
+  DrawButton (graphic, button);
+  XFlush (graphic[0].display);
+/*  usleep (20000);  removed - not a standard C sleep command, apparently! */
+  
+  graphic[0].black = black;
+  graphic[0].white = white;
+  DrawButton (graphic, button);
+  XFlush (graphic[0].display);
+
+}
+
Index: /trunk/Ohana/src/kii/button/InButton.c
===================================================================
--- /trunk/Ohana/src/kii/button/InButton.c	(revision 2466)
+++ /trunk/Ohana/src/kii/button/InButton.c	(revision 2466)
@@ -0,0 +1,22 @@
+# include "Ximage.h"
+
+int
+InButton (button_event, button)
+XButtonEvent *button_event;
+Button button[];
+{
+
+  int answer;
+  int x, y;
+
+  x = button_event[0].x;
+  y = button_event[0].y;
+  
+  answer = ((x >= button[0].x) && (x <= button[0].x + button[0].dx) &&
+	    (y >= button[0].y) && (y <= button[0].y + button[0].dy));
+
+  return (answer);
+
+}
+
+/*** make this a macro? ***/
Index: /trunk/Ohana/src/kii/button/InPicture.c
===================================================================
--- /trunk/Ohana/src/kii/button/InPicture.c	(revision 2466)
+++ /trunk/Ohana/src/kii/button/InPicture.c	(revision 2466)
@@ -0,0 +1,21 @@
+# include "Ximage.h"
+
+int
+InPicture (button_event, picture)
+XButtonEvent *button_event;
+Picture picture[];
+{
+
+  int answer;
+  int x, y;
+
+  x = button_event[0].x;
+  y = button_event[0].y;
+  
+  answer = ((x >= picture[0].x) && (x <= picture[0].x + picture[0].dx) &&
+	    (y >= picture[0].y) && (y <= picture[0].y + picture[0].dy));
+
+  return (answer);
+
+}
+
Index: /trunk/Ohana/src/kii/button/InvertButton.c
===================================================================
--- /trunk/Ohana/src/kii/button/InvertButton.c	(revision 2466)
+++ /trunk/Ohana/src/kii/button/InvertButton.c	(revision 2466)
@@ -0,0 +1,20 @@
+# include "Ximage.h"
+
+void InvertButton (Graphic *graphic, Button *button) {
+
+  unsigned long black, white;
+
+  black =  graphic[0].black;
+  white =  graphic[0].white;
+
+  graphic[0].black = white;
+  graphic[0].white = black;
+
+  DrawButton (graphic, button);
+  FlushDisplay (graphic[0].display);
+  
+  graphic[0].black = black;
+  graphic[0].white = white;
+
+}
+
Index: /trunk/Ohana/src/kii/button/JPEGit.c
===================================================================
--- /trunk/Ohana/src/kii/button/JPEGit.c	(revision 2466)
+++ /trunk/Ohana/src/kii/button/JPEGit.c	(revision 2466)
@@ -0,0 +1,153 @@
+# include "Ximage.h"
+# include "jpeglib.h"
+
+int JPEGit (Graphic *graphic, Layout *layout) {
+  
+  struct jpeg_compress_struct cinfo;
+  struct jpeg_error_mgr jerr;
+  JSAMPROW row_pointer[1];	/* pointer to JSAMPLE row[s] */
+  JSAMPLE *image_buffer;	/* Points to data for current line */
+
+  int j, k, m;
+  unsigned char *buff;
+  double Nchar, Npix, start, slope, frac;
+  int quality;
+  unsigned long pcolor;
+
+  char filename[1024];
+  int Nbytes, status;
+
+  XImage *tmpimage;
+
+  FILE *f;
+  
+  /* expect a line telling the number of bytes and a filename */
+  status = read (layout[0].Ximage, filename, 16);
+  filename[16] = 0;
+  sscanf (filename, "%*s %d", &Nbytes);
+  status = read (layout[0].Ximage, filename, Nbytes);
+  filename[status] = 0; /* make the string easy to parse */
+
+  /* 
+  switch (graphic[0].Nbits) {
+  case 8:
+    break;
+  case 16:
+    fprintf (stderr, "converter to 16 bit not yet implemented\n");
+    return (TRUE);
+    break;
+  case 24:
+    fprintf (stderr, "converter to 24 bit not yet implemented\n");
+    return (TRUE);
+    break;
+  case 32:
+    fprintf (stderr, "converter to 32 bit not yet implemented\n");
+    return (TRUE);
+    break;
+  }
+  */
+
+  /* set up the error handler , initialize the JPEG compression object. */
+  cinfo.err = jpeg_std_error (&jerr);
+  jpeg_create_compress (&cinfo);
+
+  f = fopen (filename, "w");
+  if (f == (FILE *) NULL) {
+    fprintf (stderr, "failed to open %s for output\n", filename);
+    return (TRUE);
+  }
+  jpeg_stdio_dest(&cinfo, f);
+  
+  quality = 75;
+  cinfo.image_width = layout[0].picture.dx; 	/* image width and height, in pixels */
+  cinfo.image_height = layout[0].picture.dy;
+# ifdef GREYSCALE
+  cinfo.input_components = 1;		        /* # of color components per pixel */
+  cinfo.in_color_space = JCS_GRAYSCALE; 	/* colorspace of input image */
+# else 
+  cinfo.input_components = 3;		        
+  cinfo.in_color_space = JCS_RGB; 	
+# endif
+  jpeg_set_defaults (&cinfo);
+  jpeg_set_quality (&cinfo, quality, TRUE       /* limit to baseline-JPEG values */);
+  jpeg_start_compress (&cinfo, TRUE);
+
+  ALLOCATE (image_buffer, JSAMPLE, 3*layout[0].picture.dx);
+  buff = (unsigned char *)layout[0].picture.data;
+  slope = layout[0].slope;
+  start = layout[0].start;
+  Nchar = 255.0;                                /* range of output values */
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+  
+  {
+    XWindowAttributes WindowAttributes;
+    Pixmap tmp_pixmap;
+    Window tmp_window;
+    
+    XGetWindowAttributes (graphic[0].display, graphic[0].window, &WindowAttributes);
+    
+    tmp_pixmap = XCreatePixmap (graphic[0].display, graphic[0].window, graphic[0].dx, graphic[0].dy, WindowAttributes.depth);
+
+    tmp_window = graphic[0].window;
+    graphic[0].window = tmp_pixmap;
+
+    Refresh (graphic, layout, 0);
+
+    tmpimage = XGetImage (graphic[0].display, graphic[0].window, layout[0].picture.x+1, layout[0].picture.y+1, layout[0].picture.dx, layout[0].picture.dy, 0xffffffff, ZPixmap);
+
+    for (j = 0; (j < layout[0].picture.dy) && (cinfo.next_scanline < cinfo.image_height); j++) {
+      for (k = 0; k < layout[0].picture.dx; k++) {
+	pcolor = XGetPixel (tmpimage, k, j);
+	if (pcolor == layout[0].white) { 
+	  image_buffer[3*k+0] = Nchar;
+	  image_buffer[3*k+1] = Nchar;
+	  image_buffer[3*k+2] = Nchar;
+	  continue;
+	}
+	if (pcolor == layout[0].overlay[0].color) { 
+	  image_buffer[3*k+0] = Nchar;
+	  image_buffer[3*k+1] = 0;
+	  image_buffer[3*k+2] = 0;
+	  continue;
+	}
+	if (pcolor == layout[0].overlay[1].color) { 
+	  image_buffer[3*k+0] = 0;
+	  image_buffer[3*k+1] = Nchar;
+	  image_buffer[3*k+2] = 0;
+	  continue;
+	}
+	if (pcolor == layout[0].overlay[2].color) { 
+	  image_buffer[3*k+0] = 0;
+	  image_buffer[3*k+1] = 0;
+	  image_buffer[3*k+2] = Nchar;
+	  continue;
+	}
+	if (pcolor == layout[0].overlay[3].color) { 
+	  image_buffer[3*k+0] = Nchar;
+	  image_buffer[3*k+1] = Nchar;
+	  image_buffer[3*k+2] = 0;
+	  continue;
+	}
+	for (m = 0; (layout[0].cmap[m].pixel != pcolor) && (m < Npix); m++);
+	/* val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix); */
+	image_buffer[3*k+0] = layout[0].cmap[m].red / 256;
+	image_buffer[3*k+1] = layout[0].cmap[m].green / 256;
+	image_buffer[3*k+2] = layout[0].cmap[m].blue / 256;
+      }
+      row_pointer[0] = image_buffer;
+      (void) jpeg_write_scanlines (&cinfo, row_pointer, 1);
+    }
+    graphic[0].window = tmp_window;
+    XFreePixmap (graphic[0].display, tmp_pixmap);
+  }
+
+  XDestroyImage (tmpimage);
+
+  jpeg_finish_compress (&cinfo);
+  fclose (f);
+  jpeg_destroy_compress (&cinfo);
+
+  return (TRUE);
+
+}
Index: /trunk/Ohana/src/kii/button/PSit.c
===================================================================
--- /trunk/Ohana/src/kii/button/PSit.c	(revision 2466)
+++ /trunk/Ohana/src/kii/button/PSit.c	(revision 2466)
@@ -0,0 +1,238 @@
+# include "Ximage.h"
+/* Notice: we are using a fixed border size of 10 pt */
+void ConvertPixmap8  (Layout *layout, FILE *f);
+void ConvertPixmap16 (Layout *layout, FILE *f);
+void ConvertPixmap24 (Layout *layout, FILE *f);
+void ConvertPixmap32 (Layout *layout, FILE *f);
+
+int PSit (Graphic *graphic, Layout *layout, int Raw) {
+  
+  FILE *f;
+  int i;
+  double scale;
+  char filename[1024];
+  int Nbytes, status;
+
+  /* expect a line telling the number of bytes and a filename */
+  status = read (layout[0].Ximage, filename, 16);
+  filename[16] = 0;
+  sscanf (filename, "%*s %d", &Nbytes);
+  status = read (layout[0].Ximage, filename, Nbytes);
+  filename[status] = 0; /* make the string easy to parse */
+
+  f = fopen (filename, "w");
+  if (f == (FILE *) NULL) {
+    fprintf (stderr, "failed to open %s for output\n", filename);
+    return (TRUE);
+  }
+  
+  scale = MIN ((500.0/(double)layout[0].picture.dx), (700.0/(double)layout[0].picture.dy));
+  if (!Raw) {
+    fprintf (f, "%%!PS-Adobe-2.0 EPSF-2.0\n");
+    fprintf (f, "%%%%Title: %s\n", layout[0].file);
+    fprintf (f, "%%%%Creator: Ki'i (0.95)\n");
+    fprintf (f, "%%%%BoundingBox: 10 40 %d %d \n", (int)(scale*layout[0].picture.dx + 30), (int)(scale*layout[0].picture.dy + 60));
+    fprintf (f, "%%%%Pages: 1\n");
+    fprintf (f, "%%%%DocumentFonts:\n");
+    fprintf (f, "%%%%EndComments\n");
+    fprintf (f, "%%%%EndProlog\n");
+    fprintf (f, "%%%%Page: 1 1\n\n");
+
+  }
+
+  fprintf (f, "gsave %% encloses picture\n");
+  fprintf (f, "%% local abbreviations\n");
+  fprintf (f, "/Times-Roman findfont 18 scalefont setfont\n");
+  fprintf (f, "/T {moveto show stroke} def\n");
+  fprintf (f, "/B { newpath moveto dup 0 exch rlineto exch dup 0 rlineto exch -1 mul\n");
+  fprintf (f, " 0 exch rlineto -1 mul 0 rlineto closepath stroke } def\n");
+  fprintf (f, "/C {0 360 arc stroke} def\n");
+  fprintf (f, "/L {newpath moveto lineto stroke} def\n\n");
+
+  if (!Raw) {
+    fprintf (f, " 20 50 translate\n");
+    fprintf (f, "  %f  %f scale\n", scale, scale);
+  }
+
+  fprintf (f, " newpath 0 0 moveto %d 0 lineto %d %d lineto 0 %d lineto closepath clip\n\n", 
+	   layout[0].picture.dx, layout[0].picture.dx, layout[0].picture.dy, layout[0].picture.dy);
+  fprintf (f, "gsave %% encloses image\n");
+  fprintf (f, "%d %d 8\n", layout[0].picture.dx, layout[0].picture.dy);
+  fprintf (f, "[1 0 0 1 0 0]\n");
+  fprintf (f, "{currentfile %d string readhexstring pop} image\n\n", layout[0].picture.dx);
+
+  /******** First we draw the picture itself ********/
+  switch (graphic[0].Nbits) {
+  case 8:
+    ConvertPixmap8 (layout, f);
+    break;
+  case 16:
+    ConvertPixmap16 (layout, f);
+    break;
+  case 24:
+    ConvertPixmap24 (layout, f);
+    break;
+  case 32:
+    ConvertPixmap32 (layout, f);
+    break;
+  }
+
+  fprintf (f, "grestore %% end of image\n");
+  fprintf (f, "stroke\n");
+  fprintf (f, "%% plot overlay objects\n");
+  fprintf (f, "1 setgray\n");
+
+  for (i = 0; i < NOVERLAYS; i++) {
+    if (OVERLAY[i]) {
+      fprintf (f, "%% overlay %d\n", i);
+      DrawOverlay (graphic, layout, i, f, 0);
+    }
+  }
+  fprintf (f, "0 setgray\n");
+  for (i = 0; i < NOVERLAYS; i++) {
+    if (OVERLAY[i]) {
+      fprintf (f, "%% overlay %d\n", i);
+      DrawOverlay (graphic, layout, i, f, 1);
+    }
+  }
+  
+  fprintf (f, "grestore %% end of picture\n");
+
+  if (!Raw) fprintf (f, "showpage\n");
+
+  fclose (f);
+
+  return (TRUE);
+
+}
+
+void ConvertPixmap8 (Layout *layout, FILE *f) {
+
+  int i, k, m, val;
+  double Nchar, Npix, start, slope, frac;
+  char *buff;
+
+  Nchar = 255.0;
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+  /* start at the last line, print lines in decending order */
+  buff = (unsigned char *)layout[0].picture.data + layout[0].picture.dx*(layout[0].picture.dy - 1);
+  slope = layout[0].slope;
+  start = layout[0].start;
+
+  for (i = 0; i < layout[0].picture.dy; i++) {
+    for (k = 0; k < layout[0].picture.dx; k++, buff++) {
+      if (*buff == layout[0].white) 
+	val = Nchar;
+      else {
+	for (m = 0; (layout[0].cmap[m].pixel != *buff) && (m < Npix); m++);
+	val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
+      }
+      fprintf (f, "%02x", val);
+      if (!((k+1) % 40)) fprintf (f, "\n"); 
+    }
+    fprintf (f, "\n");
+    buff -= 2*layout[0].picture.dx;
+  }
+  return;
+}
+
+void ConvertPixmap16 (Layout *layout, FILE *f) {
+
+  int i, k, m, val;
+  double Nchar, Npix, start, slope, frac;
+  unsigned short *buff;
+
+  Nchar = 255.0;
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+  /* start at the last line, print lines in decending order */
+  buff = (unsigned short *)layout[0].picture.data + layout[0].picture.dx*(layout[0].picture.dy - 1);
+  slope = layout[0].slope;
+  start = layout[0].start;
+
+  for (i = 0; i < layout[0].picture.dy; i++) {
+    for (k = 0; k < layout[0].picture.dx; k++, buff++) {
+      if (*buff == layout[0].white) 
+	val = Nchar;
+      else {
+	for (m = 0; (layout[0].cmap[m].pixel != *buff) && (m < Npix); m++);
+	val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
+      }
+      fprintf (f, "%02x", val);
+      if (!((k+1) % 40)) fprintf (f, "\n"); 
+    }
+    fprintf (f, "\n");
+    buff -= 2*layout[0].picture.dx;
+  }
+  return;
+}
+
+void ConvertPixmap24 (Layout *layout, FILE *f) {
+
+  int i, k, m, dx, dy, val, extra;
+  unsigned char *buff;
+  unsigned long color, byte;
+  double Nchar, Npix, start, slope, frac;
+
+  Nchar = 255.0;
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+  dx = layout[0].picture.dx;
+  dy = layout[0].picture.dy;
+  extra = 4 - (dx * 3) % 4;
+  /* start at the last line, print lines in decending order */
+  buff = &layout[0].picture.data[(dy - 1)*(3*dx + extra)];
+  slope = layout[0].slope;
+  start = layout[0].start;
+
+  for (i = 0; i < dy; i++) {
+    for (k = 0; k < dx; k++, buff+=3) {
+      color = 0;
+      byte = buff[2];
+      color = (byte << 16);
+      byte = buff[1];
+      color |= (byte << 8);
+      byte = buff[0];
+      color |= byte;
+      for (m = 0; (layout[0].cmap[m].pixel != color) && (m < Npix); m++);
+      val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
+      fprintf (f, "%02x", val);
+      if (!((k+1) % 40)) fprintf (f, "\n"); 
+    }
+    fprintf (f, "\n");
+    buff -= 2*3*dx + extra;
+  }
+  return;
+}
+
+void ConvertPixmap32 (Layout *layout, FILE *f) {
+
+  int i, k, m, val;
+  double Nchar, Npix, start, slope, frac;
+  unsigned int *buff;
+
+  Nchar = 255.0;
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+  /* start at the last line, print lines in decending order */
+  buff = (unsigned int *)layout[0].picture.data + layout[0].picture.dx*(layout[0].picture.dy - 1);
+  slope = layout[0].slope;
+  start = layout[0].start;
+
+  for (i = 0; i < layout[0].picture.dy; i++) {
+    for (k = 0; k < layout[0].picture.dx; k++, buff++) {
+      if (*buff == layout[0].white) 
+	val = Nchar;
+      else {
+	for (m = 0; (layout[0].cmap[m].pixel != *buff) && (m < Npix); m++);
+	val = Nchar - frac * MIN (MAX (start + m * slope, 0), Npix);
+      }
+      fprintf (f, "%02x", val);
+      if (!((k+1) % 40)) fprintf (f, "\n"); 
+    }
+    fprintf (f, "\n");
+    buff -= 2*layout[0].picture.dx;
+  }
+  return;
+}
Index: /trunk/Ohana/src/kii/colorbar/CreateColorbar.c
===================================================================
--- /trunk/Ohana/src/kii/colorbar/CreateColorbar.c	(revision 2466)
+++ /trunk/Ohana/src/kii/colorbar/CreateColorbar.c	(revision 2466)
@@ -0,0 +1,73 @@
+# include "Ximage.h"
+
+void CreateColorbar (Layout *layout, Graphic *graphic) {
+
+  int i, j, dx, dy, extra, start;
+  unsigned long  pixvalue;
+  unsigned int  *out24;
+  unsigned char *out8;
+
+  dx = layout[0].cmapbar.dx;
+  dy = layout[0].cmapbar.dy;
+
+  /* create the cmap scale */
+  switch (graphic[0].Nbits) {
+  case 8:
+    REALLOCATE (layout[0].cmapbar.data, char, dx*dy);
+    out8 = (unsigned char *) layout[0].cmapbar.data;
+    for (i = 0; i < dx; i++) {
+      pixvalue = layout[0].cmap[(int)(i*layout[0].Npixels/dx)].pixel;
+      for (j = 0; j < dy; j++) {
+	out8[j*dx + i] = pixvalue;
+      }
+    }
+    layout[0].cmapbar.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].cmapbar.data, dx, dy, 8, 0);
+    break;
+
+  case 16:
+    REALLOCATE (layout[0].cmapbar.data, char, 2*dy*dx);
+    out8 = layout[0].cmapbar.data;
+    for (i = 0; i < dx; i++) {
+      pixvalue = layout[0].cmap[(int)(i*layout[0].Npixels/dx)].pixel;
+      for (j = 0; j < dy; j++) {
+	start = 2*j*dx + 2*i;
+	out8[start + 0] = 0x0000ff & pixvalue;
+	out8[start + 1] = 0x0000ff & (pixvalue >> 8);
+      }
+    }
+    layout[0].cmapbar.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].cmapbar.data, dx, dy, 16, 0);
+    break;
+
+  case 24:
+    extra = 4 - (dx * 3) % 4;
+    REALLOCATE (layout[0].cmapbar.data, char, dy*(3*dx + extra));
+    out8 = layout[0].cmapbar.data;
+    for (i = 0; i < dx; i++) {
+      pixvalue = layout[0].cmap[(int)(i*layout[0].Npixels/dx)].pixel;
+      for (j = 0; j < dy; j++) {
+	start = j*(3*dx+extra) + 3*i;
+	out8[start + 0] = 0x0000ff & pixvalue;
+	out8[start + 1] = 0x0000ff & (pixvalue >> 8);
+	out8[start + 2] = 0x0000ff & (pixvalue >> 16);
+      }
+    }
+    layout[0].cmapbar.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].cmapbar.data, dx, dy, 32, 0);
+    break;
+
+  case 32:
+    REALLOCATE (layout[0].cmapbar.data, char, 4*dx*dy);
+    out24 = (unsigned int *) layout[0].cmapbar.data;
+    for (i = 0; i < dx; i++) {
+      pixvalue = layout[0].cmap[(int)(i*layout[0].Npixels/dx)].pixel;
+      for (j = 0; j < dy; j++) {
+	out24[j*dx + i] = pixvalue;
+      }
+    }
+    layout[0].cmapbar.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].cmapbar.data, dx, dy, 32, 0);
+    break;
+  }
+}
Index: /trunk/Ohana/src/kii/colorbar/DragColorbar.c
===================================================================
--- /trunk/Ohana/src/kii/colorbar/DragColorbar.c	(revision 2466)
+++ /trunk/Ohana/src/kii/colorbar/DragColorbar.c	(revision 2466)
@@ -0,0 +1,107 @@
+# include "Ximage.h"
+/* future expansion: warp mouse to the right spot for the current settings */
+
+void DragColorbar (Graphic *graphic, Layout *layout, XButtonEvent *mouse_event) {
+
+  double          frac_x, oldfrac_x, frac_y, oldfrac_y, start, slope;
+  int             X, Y;
+  XEvent          event;
+  XMotionEvent   *move;
+  int             xstatus, Npix, center;
+
+  if (!graphic[0].visualclass) return;
+
+  X = mouse_event[0].x;
+  Y = mouse_event[0].y;
+  Npix = layout[0].Npixels;
+  slope = layout[0].slope;
+  start = layout[0].start;
+  oldfrac_x = 10;
+  
+  while (1) {
+    frac_x = X / (1.0*graphic[0].dx);
+    frac_x = MAX (0, frac_x);
+    frac_x = MIN (1, frac_x);
+    frac_y = Y / (1.0*graphic[0].dy);
+    frac_y = MAX (0, frac_y);
+    frac_y = MIN (1, frac_y);
+    switch (mouse_event[0].button) {
+    case 1:
+      center = frac_x*Npix;
+      slope = Npix / (1 + 4*frac_y*frac_y*Npix);
+      start = Npix/2.0 - center*slope;
+      break;
+    case 2:
+      start = 0;
+      slope = 1;
+      break;
+    case 3:
+      center = (Npix/2.0 - start) / slope;
+      slope = Npix / (1 + 4*frac_x*frac_x*Npix);
+      start = Npix/2.0 - center*slope;
+      break;
+    }
+
+    if ((frac_x != oldfrac_x) || (frac_y != oldfrac_y)) {
+      ResetColorbar (graphic, layout, start, slope);
+    }
+    oldfrac_x = frac_x;
+    oldfrac_y = frac_y;
+      
+    if ((xstatus = XCheckMaskEvent (graphic[0].display, EVENT_MASK, &event))) {
+      
+      switch (event.type)  {
+	
+      case MotionNotify:
+	if ((xstatus = XPending (graphic[0].display)) < 2) {
+	  move = (XMotionEvent *) &event;
+	  X = move[0].x;
+	  Y = move[0].y;
+	}
+	break;
+	
+      case ButtonPress:
+      case ButtonRelease:
+	layout[0].start = start;	
+	layout[0].slope = slope;
+	return;
+	break;
+	
+      }
+    }
+  }
+  
+}
+
+void ResetColorbar (Graphic *graphic, Layout *layout, double start, double slope) {
+
+  int i, j;
+  XColor cmap[256];
+
+  if (!graphic[0].visualclass) return;
+
+  for (i = 0; i < layout[0].Npixels; i++) {
+    cmap[i] = layout[0].cmap[i];
+    j = start + i * slope;
+    if (j < 0) {
+      cmap[i].red = layout[0].cmap[0].red;
+      cmap[i].blue = layout[0].cmap[0].blue;
+      cmap[i].green = layout[0].cmap[0].green;
+    }
+    else {
+      if (j >= layout[0].Npixels) {
+	cmap[i].red = layout[0].cmap[layout[0].Npixels-1].red;
+	cmap[i].blue = layout[0].cmap[layout[0].Npixels-1].blue;
+	cmap[i].green = layout[0].cmap[layout[0].Npixels-1].green;
+      }
+      else {
+	cmap[i].red = layout[0].cmap[j].red;
+	cmap[i].blue = layout[0].cmap[j].blue;
+	cmap[i].green = layout[0].cmap[j].green;
+      }
+    }
+  }
+
+  XStoreColors(graphic[0].display, graphic[0].colormap, cmap, layout[0].Npixels);
+
+}
Index: /trunk/Ohana/src/kii/colorbar/SetColormap.c
===================================================================
--- /trunk/Ohana/src/kii/colorbar/SetColormap.c	(revision 2466)
+++ /trunk/Ohana/src/kii/colorbar/SetColormap.c	(revision 2466)
@@ -0,0 +1,97 @@
+# include "Ximage.h"
+
+int SetColormap (Graphic *graphic, Layout *layout, char *name) {
+
+  int i;
+
+  /* greyscale */
+  if ((!strcmp (name, "grayscale")) || (!strcmp (name, "greyscale"))) {
+    for (i = 0; i < layout[0].Npixels; i++) {  
+      layout[0].cmap[i].red = 256*(255 - 255*i/layout[0].Npixels);
+      layout[0].cmap[i].green = 256*(255 - 255*i/layout[0].Npixels);
+      layout[0].cmap[i].blue = 256*(255 - 255*i/layout[0].Npixels);
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    goto store_colors;
+  }
+  /* heat */
+  if (!strcmp (name, "Puns")) {
+    for (i = 0; i < (int)(0.25*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].green = 0;
+      layout[0].cmap[i].blue = 0;
+      layout[0].cmap[i].red = MIN (256*255, 256*255*2*i/(1.0*layout[0].Npixels));  
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.25*layout[0].Npixels); i < (int)(0.50*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].red = MIN (256*255, 256*255*2*i/(1.0*layout[0].Npixels));
+      layout[0].cmap[i].green = MIN (256*255, 256*255*2*(i/(1.0*layout[0].Npixels) - 0.25));
+      layout[0].cmap[i].blue = 0;
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.50*layout[0].Npixels); i < (int)(0.75*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].red = 256*255;
+      layout[0].cmap[i].green = MIN (256*255, 256*255*2*(i/(1.0*layout[0].Npixels) - 0.25));
+      layout[0].cmap[i].blue = MIN (256*255, 256*255*2*(i/(1.0*layout[0].Npixels) - 0.50));
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.75*layout[0].Npixels); i < layout[0].Npixels; i++) {  
+      layout[0].cmap[i].red = 256*255;
+      layout[0].cmap[i].green = 256*255;
+      layout[0].cmap[i].blue = MIN (256*255, 256*255*2*(i/(1.0*layout[0].Npixels) - 0.50));
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    goto store_colors;
+  }
+  /* -grayscale */
+  if ((!strcmp (name, "-grayscale")) || (!strcmp (name, "-greyscale"))) {
+    for (i = 0; i < layout[0].Npixels; i++) {  
+      layout[0].cmap[i].red = 256*(255*i/layout[0].Npixels);
+      layout[0].cmap[i].green = 256*(255*i/layout[0].Npixels);
+      layout[0].cmap[i].blue = 256*(255*i/layout[0].Npixels);
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    goto store_colors;
+  }
+  /* rainbow */
+  if (!strcmp (name, "Rainbow")) {
+    for (i = 0; i < (int)(0.25*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].red = 0;
+      layout[0].cmap[i].green = 0;
+      layout[0].cmap[i].blue = 256*(255*4*(i/(1.0*layout[0].Npixels)));  
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.25*layout[0].Npixels); i < (int)(0.50*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].red = 256*(255*4*((i/(1.0*layout[0].Npixels)) - 0.25));
+      layout[0].cmap[i].green = 0;
+      layout[0].cmap[i].blue = 256*(255*4*(0.50 - (i/(1.0*layout[0].Npixels))));
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.50*layout[0].Npixels); i < (int)(0.75*layout[0].Npixels); i++) {  
+      layout[0].cmap[i].red = 256*255;
+      layout[0].cmap[i].green = 256*(255*4*((i/(1.0*layout[0].Npixels)) - 0.50));
+      layout[0].cmap[i].blue = 0;
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    for (i = (int)(0.75*layout[0].Npixels); i < layout[0].Npixels; i++) {  
+      layout[0].cmap[i].red = 256*255;
+      layout[0].cmap[i].green = 256*255;
+      layout[0].cmap[i].blue = 256*(255*4*((i/(1.0*layout[0].Npixels)) - 0.75));
+      layout[0].cmap[i].flags = DoRed | DoGreen | DoBlue;
+    }
+    goto store_colors;
+  }
+  return (FALSE);
+
+ store_colors:
+  if (graphic[0].visualclass) {
+    XStoreColors(graphic[0].display, graphic[0].colormap, layout[0].cmap, layout[0].Npixels);
+  } else {
+    for (i = 0; i < layout[0].Npixels; i++) {
+      if (XAllocColor (graphic[0].display, graphic[0].colormap, &layout[0].cmap[i]) == 0) {
+	fprintf (stderr, "error on %d\n", i);
+      }
+    }
+  }
+  return (TRUE);
+}
+
Index: /trunk/Ohana/src/kii/event/CheckPipe.c
===================================================================
--- /trunk/Ohana/src/kii/event/CheckPipe.c	(revision 2466)
+++ /trunk/Ohana/src/kii/event/CheckPipe.c	(revision 2466)
@@ -0,0 +1,117 @@
+# include "Ximage.h"
+# define STRCONST(A) ((int)(0x1000000*A[0] + 0x10000*A[1] + 0x100*A[2] + 0x1*A[3]))
+
+int CheckPipe (Graphic *graphic, Layout *layout) {
+
+  int status;
+  char buffer[1024];
+
+  /* attempt to read 4 bytes from stdin */
+
+  status = read (layout[0].Ximage, buffer, 4);
+  buffer[4] = 0;
+
+  switch (status) {
+  case -1:
+    /* no input from pipe: continue */
+    return (TRUE);
+    break;
+
+  case 0:
+    fprintf (stderr, "pipe has died!\n");
+    return (FALSE);
+    break;
+
+  case 4:
+/*    fprintf (stderr, "got signal %s from pipe\n", buffer);    */
+    break;
+
+  default:
+    fprintf (stderr, "weird signal: too many or few bytes!  %d\n", status);
+    return (TRUE);
+    break;
+  }
+
+  
+  if (!strcmp (buffer, "QUIT")) {
+    /* fprintf (stderr, "Goodbye!\n"); */
+    return (FALSE);
+  }
+  
+  if (!strcmp (buffer, "READ")) {
+    status = NewPicture (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "CURS")) {
+    status = cursor (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "ERAS")) {
+    status = EraseOverlay (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "LOAD")) {
+    status = LoadOverlay (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "TICK")) {
+    status = LoadTickmarks (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "SAVE")) {
+    status = SaveOverlay (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "PSIT")) {
+    status = PSit (graphic, layout, 0);
+    write (layout[0].Ximage, "DONE", 4);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "PSRW")) {
+    status = PSit (graphic, layout, 1);
+    write (layout[0].Ximage, "DONE", 4);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "JPEG")) {
+    status = JPEGit (graphic, layout);
+    write (layout[0].Ximage, "DONE", 4);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "RSIZ")) {
+    status = Resize (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "CSVE")) {
+    status = CSaveOverlay (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "CENT")) {
+    status = Center (graphic, layout);
+    return (status);
+  }
+
+  if (!strcmp (buffer, "NPIX")) {
+    sprintf (buffer, "NPIX:   %8d", layout[0].Npixels);
+    write (layout[0].Ximage, buffer, 16);
+    return (TRUE);
+  }
+
+  fprintf (stderr, "unknown signal %s\n", buffer);
+
+  return (TRUE);
+
+}
+
+
+    
Index: /trunk/Ohana/src/kii/event/EventLoop.c
===================================================================
--- /trunk/Ohana/src/kii/event/EventLoop.c	(revision 2466)
+++ /trunk/Ohana/src/kii/event/EventLoop.c	(revision 2466)
@@ -0,0 +1,94 @@
+# include "Ximage.h"
+# define MAX_STRING 100
+/* WARNING: this is defined because the HP UX installation i have does not
+seem to know this structure, though it should */
+# ifdef DUMMY
+struct Ktimeval {
+  unsigned long tv_sec;         /* seconds */
+  long          tv_usec;        /* and microseconds */
+};
+# endif
+
+int EventLoop (Graphic *graphic, Layout *layout) {
+  
+  XEvent          event;
+  int             status;
+  
+  /* gettimeofday (&then, (struct timeval *) NULL); */
+
+  Refresh (graphic, layout, 1);
+
+  status = TRUE;
+  while (status) {
+    
+    if (!CheckPipe (graphic, layout))
+      return (FALSE);
+    
+    if (XEventsQueued (graphic[0].display, QueuedAfterFlush) < 1) {
+      usleep (10000);
+      continue;
+    }
+
+    if (XCheckMaskEvent (graphic[0].display, EVENT_MASK, &event)) {
+
+      switch (event.type)  {
+	
+      case MotionNotify:
+	if (XEventsQueued (graphic[0].display, QueuedAlready) < 2) {
+	  UpdatePointer (graphic, layout, (XMotionEvent *) &event);
+	}
+	break;
+      case ButtonPress:
+	status = InterpretPresses (graphic, layout, (XButtonEvent *) &event);
+	break;
+	
+      case Expose:
+	if (XEventsQueued (graphic[0].display, QueuedAlready) < 2) {
+	  Refresh (graphic, layout, 1);
+	}
+	break;
+	/* if (event.xexpose.count == 0) */
+	
+      case ConfigureNotify:
+	status = Reconfig (graphic, layout, &event);
+	/*
+	if (XEventsQueued (graphic[0].display, QueuedAlready) < 2) {
+	  status = Reconfig (graphic, layout, &event);
+	}
+	*/
+	break;
+	
+      case KeyPress:
+	status = InterpretKeys (graphic, layout, &event);
+	break;
+	
+      case MappingNotify:
+	if (XEventsQueued (graphic[0].display, QueuedAlready) < 2) {
+	  XRefreshKeyboardMapping ((XMappingEvent *) &event);
+	}
+	break;
+	
+      }
+    }
+  }
+  return (status);
+}
+
+/*     
+while (XPending (graphic[0].display) {
+if (readfds && display_mask) { 
+*/
+/*
+  while (1) {
+    fprintf (stderr, "window in EventLoop: %x  %d\n", graphic[0].display, graphic[0].window);
+    XNextEvent (graphic[0].display, &event);
+    if (event.type == ClientMessage) {
+      fprintf (stderr, "choice 1\n");
+    }
+    
+    if (event.xclient.send_event) {
+      fprintf (stderr, "choice 2\n");
+    }
+  }
+*/
+  
Index: /trunk/Ohana/src/kii/event/FlushDisplay.c
===================================================================
--- /trunk/Ohana/src/kii/event/FlushDisplay.c	(revision 2466)
+++ /trunk/Ohana/src/kii/event/FlushDisplay.c	(revision 2466)
@@ -0,0 +1,32 @@
+# include "Ximage.h"
+
+static struct timeval reftime; 
+static char reftimeset = FALSE;
+# define DTIME(A,B) ((A.tv_sec - B.tv_sec) + 1e-6*(A.tv_usec - B.tv_usec))
+
+void FlushDisplay (Display *display) {
+
+  struct timeval now;
+  int flush;
+  double dtime;
+
+  flush = FALSE;
+  if (!reftimeset) {
+    flush = TRUE;
+    gettimeofday (&reftime, NULL);
+  } 
+
+  gettimeofday (&now, NULL);
+  dtime = DTIME (now, reftime);
+
+  if (dtime > 0.1) {
+    flush = TRUE;
+  }
+
+  if (flush) {
+    XFlush (display);
+    reftime = now;
+  }
+
+}
+
Index: /trunk/Ohana/src/kii/event/InterpretKeys.c
===================================================================
--- /trunk/Ohana/src/kii/event/InterpretKeys.c	(revision 2466)
+++ /trunk/Ohana/src/kii/event/InterpretKeys.c	(revision 2466)
@@ -0,0 +1,44 @@
+# include "Ximage.h"
+
+int 
+InterpretKeys (graphic, layout, event)
+Graphic        graphic[];
+Layout         layout[];
+XEvent        *event;
+{
+
+  int    status;
+  KeySym keysym;
+  char            string[10];
+  XComposeStatus  composestatus;
+
+  XLookupString ((XKeyEvent *)event, string, 9, &keysym, &composestatus);
+
+  switch (keysym) {
+
+  case XK_Tab:
+    MOVE_POINTER = MOVE_POINTER ^ TRUE;
+    if (MOVE_POINTER) UpdatePointer (graphic, layout, (XMotionEvent *)event);
+    status = TRUE;
+    break;
+
+  default:
+    status = TRUE;
+  }
+
+  return (status);
+
+}
+
+
+
+
+/************* the stuff below this line is old - remove eventually */
+/*
+  case XK_Right:
+  case XK_Left:
+  this is all old, but a good example for putting in the cursor motion.
+
+    break;
+*/
+
Index: /trunk/Ohana/src/kii/event/InterpretPresses.c
===================================================================
--- /trunk/Ohana/src/kii/event/InterpretPresses.c	(revision 2466)
+++ /trunk/Ohana/src/kii/event/InterpretPresses.c	(revision 2466)
@@ -0,0 +1,51 @@
+# include "Ximage.h"
+
+int InterpretPresses (Graphic *graphic, Layout *layout, XButtonEvent *event) {
+
+  int             status, done, this_button;
+  Button         *button;
+
+  status = TRUE;
+  this_button = event[0].button;
+  
+  if ((event[0].type == ButtonPress) && InPicture (event, &layout[0].picture)) {
+    Reorient (graphic, layout, event);
+  }
+
+  if ((event[0].type == ButtonPress) && InPicture (event, &layout[0].cmapbar)) {
+    DragColorbar (graphic, layout, event);
+  }
+
+  /* if on an exisiting button, Invert, wait for release, then go (or not) */
+  if ((button = CheckButtons (event, layout)) != (Button *) NULL) {
+    InvertButton (graphic, button); 
+    done = FALSE;
+    while (!done) { /* wait for release of this button */
+      XNextEvent (graphic[0].display, (XEvent *) event);
+      if ((event[0].type == ButtonRelease) && (event[0].button == this_button)) {
+	done = TRUE;
+      }
+    }
+    DrawButton (graphic, button);
+    if (InButton (event, button)) {
+      switch (event[0].button) {
+      case 1:
+	status = button[0].function_1(graphic, layout);
+	break;
+      case 2:
+	status = button[0].function_2(graphic, layout);
+	break;
+      case 3:
+	status = button[0].function_3(graphic, layout);
+	break;
+      }
+    }
+    else {
+      return (status);
+    }
+  }
+
+  return (status);
+
+}
+
Index: /trunk/Ohana/src/kii/event/NextEvent.c
===================================================================
--- /trunk/Ohana/src/kii/event/NextEvent.c	(revision 2466)
+++ /trunk/Ohana/src/kii/event/NextEvent.c	(revision 2466)
@@ -0,0 +1,20 @@
+# include "Ximage.h"
+
+/************** NextEvent *************/
+void
+NextEvent (graphic, event, keysym)
+Graphic graphic[];
+XEvent *event;
+KeySym *keysym;
+{
+  int status;
+
+  status = FALSE;
+
+  while (!status) {
+    XNextEvent (graphic[0].display, event);
+    status = ParseEvent (graphic, event, keysym);
+  }
+}
+
+
Index: /trunk/Ohana/src/kii/event/ParseEvent.c
===================================================================
--- /trunk/Ohana/src/kii/event/ParseEvent.c	(revision 2466)
+++ /trunk/Ohana/src/kii/event/ParseEvent.c	(revision 2466)
@@ -0,0 +1,61 @@
+# include "Ximage.h"
+
+/************** ParseEvent *************/
+int
+ParseEvent (graphic, event, keysym)
+Graphic graphic[];
+XEvent *event;
+KeySym *keysym;
+{
+
+  XComposeStatus composestatus;
+  char string[10];
+  int status;
+ 
+  status = FALSE;
+  switch (event[0].type) {
+  case ButtonPress:
+    status = TRUE;
+    break;
+  case ButtonRelease:
+    status = TRUE;
+    break;
+  case ClientMessage:
+    status = TRUE;
+    break;
+  case MotionNotify:
+    status = TRUE;
+    break;
+  case PropertyNotify:
+    status = TRUE;
+    break;
+  case SelectionClear:
+    status = TRUE;
+    break;
+  case SelectionNotify:
+    status = TRUE;
+    break;
+  case SelectionRequest:
+    status = TRUE;
+    break;
+  case ConfigureNotify:
+    if ((graphic[0].dx != event[0].xconfigure.width) || 
+	(graphic[0].dy != event[0].xconfigure.height))
+      status = TRUE;
+    break;
+  case Expose:
+    status = TRUE;
+    if (event[0].xexpose.count != 0)
+      status = FALSE;
+    break;
+  case KeyPress:
+    status = TRUE;
+    XLookupString ((XKeyEvent *)event, string, 9, keysym, &composestatus);
+    break;
+  case MappingNotify:
+    XRefreshKeyboardMapping ((XMappingEvent *)event);
+    break;
+  }
+
+  return (status);
+}
Index: /trunk/Ohana/src/kii/event/Reconfig.c
===================================================================
--- /trunk/Ohana/src/kii/event/Reconfig.c	(revision 2466)
+++ /trunk/Ohana/src/kii/event/Reconfig.c	(revision 2466)
@@ -0,0 +1,19 @@
+# include "Ximage.h"
+# define MAX_STRING 100
+
+int Reconfig (Graphic *graphic, Layout *layout, XEvent *event) {
+  
+  if ((graphic[0].dx == event[0].xconfigure.width) &&
+      (graphic[0].dy == event[0].xconfigure.height)) 
+    return (TRUE);
+
+  graphic[0].dx = MAX(event[0].xconfigure.width,  MIN_WIDTH); 
+  graphic[0].dy = MAX(event[0].xconfigure.height, MIN_HEIGHT);
+
+  PositionPictures (layout, graphic);
+  CreateColorbar (layout, graphic);
+  CreatePicture (layout, graphic);
+  Remap (graphic, layout, &layout[0].matrix); 
+  Refresh (graphic, layout, 1);
+  return (TRUE);
+}
Index: /trunk/Ohana/src/kii/event/Refresh.c
===================================================================
--- /trunk/Ohana/src/kii/event/Refresh.c	(revision 2466)
+++ /trunk/Ohana/src/kii/event/Refresh.c	(revision 2466)
@@ -0,0 +1,55 @@
+# include "Ximage.h"
+# define NPOINTS 10
+
+void Refresh (Graphic *graphic, Layout *layout, int mode) {
+
+  int i;
+
+  XSetForeground (graphic[0].display, graphic[0].gc, layout[0].black);
+  XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		  layout[0].picture.x, layout[0].picture.y, 
+		  layout[0].picture.dx + 1, layout[0].picture.dy + 1);
+  
+  XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
+	     layout[0].picture.pix, 0, 0, 
+	     layout[0].picture.x + 1, layout[0].picture.y + 1, 
+	     layout[0].picture.dx, layout[0].picture.dy);
+
+  XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
+	     layout[0].cmapbar.pix, 0, 0, 
+	     layout[0].cmapbar.x, layout[0].cmapbar.y, 
+	     layout[0].cmapbar.dx, layout[0].cmapbar.dy);
+
+  CrossHairs (graphic, layout);
+
+  for (i = 0; i < NOVERLAYS; i++) {
+    if (OVERLAY[i])
+      PaintOverlay (graphic, layout, i);
+  }
+  PaintTickmarks (graphic, layout);
+
+  if (mode == 1) {
+    /* erase everything below zoom box, then draw */
+    XSetForeground (graphic[0].display, graphic[0].gc, layout[0].white);
+    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		    layout[0].text_x, layout[0].text_x, layout[0].zoom.dx, graphic[0].dy); 
+    
+    DrawButton (graphic, &layout[0].PS_button);
+    DrawButton (graphic, &layout[0].recenter_button);
+    DrawButton (graphic, &layout[0].grey_button);
+    DrawButton (graphic, &layout[0].rainbow_button);
+    DrawButton (graphic, &layout[0].puns_button);
+    DrawButton (graphic, &layout[0].hms_button);
+
+    for (i = 0; i < NOVERLAYS; i++) {
+      DrawButton (graphic, &layout[0].overlay_button[i]);
+    }
+  }
+
+  StatusBox (graphic, layout);
+
+  FlushDisplay (graphic[0].display);
+}
+
+/* this routine is independent of the number of overlays */
+
Index: /trunk/Ohana/src/kii/event/Stop.c
===================================================================
--- /trunk/Ohana/src/kii/event/Stop.c	(revision 2466)
+++ /trunk/Ohana/src/kii/event/Stop.c	(revision 2466)
@@ -0,0 +1,19 @@
+# include "Ximage.h"
+# define XBorder 10
+# define YBorder 2
+
+int
+Stop (graphic, layout)
+Graphic   graphic[];
+Layout    layout[];
+{
+  return (FALSE);
+}
+
+
+
+
+
+
+/******  this function looks stupid, but it has to be like this:
+  it is called as a pointer to function **/
Index: /trunk/Ohana/src/kii/include/Ximage.h
===================================================================
--- /trunk/Ohana/src/kii/include/Ximage.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/Ximage.h	(revision 2466)
@@ -0,0 +1,5 @@
+# include <Xohana.h>
+# include <loneos.h>
+# include "constants.h"
+# include "structures.h"
+# include "prototypes.h"
Index: /trunk/Ohana/src/kii/include/buttons.h
===================================================================
--- /trunk/Ohana/src/kii/include/buttons.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/buttons.h	(revision 2466)
@@ -0,0 +1,120 @@
+#define PS_width 25
+#define PS_height 25
+static char PS_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x81, 0x3f, 0x00,
+   0x82, 0x67, 0x60, 0x00, 0x02, 0x26, 0x40, 0x00, 0x02, 0x24, 0x40, 0x00,
+   0x02, 0x24, 0x00, 0x00, 0x02, 0x24, 0x00, 0x00, 0x02, 0x24, 0x00, 0x00,
+   0x02, 0x24, 0x00, 0x00, 0x02, 0x64, 0x00, 0x00, 0x02, 0xc6, 0x00, 0x00,
+   0x82, 0x07, 0x07, 0x00, 0xfe, 0x01, 0x0c, 0x00, 0x02, 0x00, 0x18, 0x00,
+   0x02, 0x00, 0x20, 0x00, 0x02, 0x00, 0x60, 0x00, 0x02, 0x00, 0x40, 0x00,
+   0x02, 0x00, 0xc0, 0x00, 0x02, 0x10, 0x80, 0x00, 0x02, 0x10, 0xc0, 0x00,
+   0x02, 0x60, 0x60, 0x00, 0x02, 0x80, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00}; 
+#define grey_width 25
+#define grey_height 25
+static char grey_bits[] = {
+   0x90, 0x40, 0xf7, 0x01, 0x04, 0xaa, 0xad, 0x01, 0x68, 0xd5, 0xfe, 0x01,
+   0x82, 0x28, 0xdb, 0x01, 0x10, 0xd2, 0x75, 0x01, 0x40, 0xad, 0xee, 0x01,
+   0xac, 0x50, 0xbf, 0x01, 0x00, 0xaa, 0xf9, 0x01, 0x52, 0xd5, 0xd6, 0x01,
+   0x80, 0x28, 0x6f, 0x01, 0x28, 0xd2, 0xfd, 0x01, 0x44, 0xad, 0xba, 0x01,
+   0x90, 0x50, 0xf7, 0x01, 0x02, 0xaa, 0xcd, 0x01, 0x68, 0xd5, 0x7e, 0x01,
+   0x80, 0x28, 0xfb, 0x01, 0x14, 0xd2, 0xb5, 0x01, 0x40, 0xad, 0xee, 0x01,
+   0xaa, 0x50, 0xdf, 0x01, 0x00, 0xaa, 0x79, 0x01, 0x50, 0xd5, 0xf6, 0x01,
+   0x84, 0x28, 0xaf, 0x01, 0x28, 0xd2, 0xfd, 0x01, 0x40, 0xad, 0xda, 0x01,
+   0x90, 0x50, 0x77, 0x01};
+#define rainbow_width 25
+#define rainbow_height 25
+static char rainbow_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x80, 0xff, 0x00, 0x00, 0x70, 0x00, 0x01, 0x00, 0x0c, 0x7f, 0x00,
+   0x00, 0xe3, 0x80, 0x01, 0xc0, 0x9c, 0xff, 0x00, 0x20, 0x62, 0x00, 0x01,
+   0x90, 0x99, 0xff, 0x00, 0x48, 0x76, 0x00, 0x01, 0x24, 0x09, 0x00, 0x00,
+   0x94, 0x06, 0x00, 0x00, 0x52, 0x01, 0x00, 0x00, 0xaa, 0x00, 0x00, 0x00,
+   0xa5, 0x00, 0x00, 0x00, 0x55, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
+   0x2a, 0x00, 0x00, 0x00, 0x2a, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00,
+   0x15, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00, 0x15, 0x00, 0x00, 0x00,
+   0x15, 0x00, 0x00, 0x00};
+#define recenter_width 25
+#define recenter_height 25
+static char recenter_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00,
+   0x80, 0xef, 0x03, 0x00, 0xe0, 0x00, 0x0e, 0x00, 0x30, 0x00, 0x18, 0x00,
+   0x10, 0x00, 0x10, 0x00, 0x18, 0x00, 0x30, 0x00, 0x08, 0x00, 0x20, 0x00,
+   0x0c, 0x00, 0x60, 0x00, 0x0c, 0x38, 0x60, 0x00, 0x0c, 0x7c, 0x60, 0x00,
+   0x04, 0x7c, 0x40, 0x00, 0x0c, 0x7c, 0x60, 0x00, 0x0c, 0x38, 0x60, 0x00,
+   0x0c, 0x00, 0x60, 0x00, 0x08, 0x00, 0x20, 0x00, 0x18, 0x00, 0x30, 0x00,
+   0x10, 0x00, 0x10, 0x00, 0x30, 0x00, 0x18, 0x00, 0xe0, 0x00, 0x0e, 0x00,
+   0x80, 0xef, 0x03, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define puns_width 25
+#define puns_height 25
+static char puns_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x07, 0xd8, 0x01,
+   0x00, 0x0c, 0x37, 0x00, 0xf8, 0xc9, 0x6f, 0x00, 0x0c, 0xde, 0xf0, 0x00,
+   0x06, 0x5b, 0x1f, 0x00, 0x7b, 0xd9, 0x0c, 0x00, 0xc9, 0x70, 0x06, 0x00,
+   0x81, 0x71, 0x03, 0x00, 0x78, 0xb9, 0x39, 0x00, 0xc8, 0xdb, 0x0f, 0x00,
+   0x84, 0xf7, 0x7f, 0x00, 0x04, 0xff, 0xc3, 0x00, 0xe6, 0xfe, 0x8e, 0x00,
+   0x9a, 0x7d, 0x0b, 0x00, 0x08, 0xbc, 0x01, 0x00, 0x08, 0xfc, 0x3f, 0x00,
+   0x0c, 0xff, 0x78, 0x00, 0x84, 0x39, 0x60, 0x00, 0x40, 0x38, 0x40, 0x00,
+   0x60, 0x38, 0x40, 0x00, 0x20, 0x38, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x00,
+   0x00, 0xd6, 0x00, 0x00};
+#define red_width 25
+#define red_height 25
+static char red_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0xfc, 0x03, 0x00,
+   0x20, 0x07, 0x06, 0x00, 0xe0, 0x00, 0x0c, 0x00, 0x20, 0x00, 0x08, 0x00,
+   0x20, 0x00, 0x08, 0x00, 0x20, 0x00, 0x08, 0x00, 0x20, 0x00, 0x08, 0x00,
+   0x20, 0x00, 0x0c, 0x00, 0x20, 0x00, 0x06, 0x00, 0x20, 0x80, 0x01, 0x00,
+   0x20, 0xe0, 0x00, 0x00, 0x20, 0x7e, 0x00, 0x00, 0xe0, 0xc3, 0x00, 0x00,
+   0x20, 0xc0, 0x00, 0x00, 0x20, 0x80, 0x00, 0x00, 0x20, 0x80, 0x01, 0x00,
+   0x20, 0x00, 0x01, 0x00, 0x20, 0x00, 0x01, 0x00, 0x20, 0x00, 0x03, 0x00,
+   0x20, 0x00, 0x06, 0x00, 0x20, 0x00, 0x0c, 0x00, 0x20, 0x00, 0x18, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define green_width 25
+#define green_height 25
+static char green_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0x00,
+   0x00, 0x06, 0x04, 0x00, 0x80, 0x03, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0x40, 0x80, 0x0f, 0x00, 0x40, 0xc0, 0x30, 0x00,
+   0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00, 0x40, 0x00,
+   0x40, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x80, 0x01, 0x08, 0x00,
+   0x00, 0x03, 0x08, 0x00, 0x00, 0x7e, 0x0e, 0x00, 0x00, 0xc0, 0x03, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define blue_width 25
+#define blue_height 25
+static char blue_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0xfe, 0x00, 0x00,
+   0xc0, 0x83, 0x07, 0x00, 0xc0, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x08, 0x00,
+   0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00,
+   0x40, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x04, 0x00, 0x40, 0x00, 0x02, 0x00,
+   0x40, 0x80, 0x07, 0x00, 0x40, 0xe0, 0x0c, 0x00, 0xc0, 0x3f, 0x08, 0x00,
+   0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00, 0x40, 0x00, 0x08, 0x00,
+   0x40, 0x00, 0x0c, 0x00, 0x40, 0x00, 0x06, 0x00, 0x40, 0x00, 0x02, 0x00,
+   0xc0, 0x80, 0x03, 0x00, 0x40, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define yellow_width 25
+#define yellow_height 25
+static char yellow_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x18, 0x00,
+   0x80, 0x01, 0x0c, 0x00, 0x00, 0x03, 0x06, 0x00, 0x00, 0x02, 0x02, 0x00,
+   0x00, 0x84, 0x01, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00,
+   0x00, 0x30, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
+   0x00, 0x10, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
+   0x00, 0x20, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00,
+   0x00, 0x30, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00,
+   0x00, 0x30, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x00, 0x00, 0x00, 0x00};
+#define hms_width 25
+#define hms_height 25
+static char hms_bits[] = {
+   0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+   0x02, 0x00, 0x00, 0x00, 0x02, 0x01, 0xf0, 0x00, 0x1e, 0xef, 0x89, 0x00,
+   0x22, 0x11, 0x09, 0x00, 0x22, 0x11, 0x71, 0x00, 0x22, 0x11, 0x81, 0x00,
+   0x22, 0x11, 0x89, 0x00, 0x22, 0x01, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00,
+   0x1e, 0xc7, 0xf1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x80, 0x80, 0x00,
+   0x40, 0x80, 0x80, 0x00, 0x40, 0x80, 0x80, 0x00, 0x40, 0x80, 0x80, 0x00,
+   0x40, 0x80, 0x80, 0x00, 0x5c, 0xb8, 0xb8, 0x00, 0x62, 0xc4, 0xc4, 0x00,
+   0x42, 0x84, 0x84, 0x00, 0x42, 0x84, 0x84, 0x00, 0x62, 0xc4, 0xc4, 0x00,
+   0x5c, 0xb9, 0xb8, 0x00};
Index: /trunk/Ohana/src/kii/include/constants.h
===================================================================
--- /trunk/Ohana/src/kii/include/constants.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/constants.h	(revision 2466)
@@ -0,0 +1,27 @@
+# define PAD1  5
+# define PAD2  3
+# define TEXTPAD 25
+# define COLORPAD 10
+# define TEXT_Y 15
+# define ZOOM_X 170
+# define ZOOM_Y 170
+# define NOVERLAYS 4
+/* number of overlays is defined here.
+   the number is also crucial in the following files:
+   PositionPictures.c
+   MakeColormap.c
+   prototypes.h
+*/
+
+# define EVENT_MASK (long) (ButtonPressMask | ClientMessage | ButtonReleaseMask | KeyPressMask | ExposureMask | StructureNotifyMask | PointerMotionMask)
+# define DEFAULT_CURSOR XC_crosshair
+# define BORDER_WIDTH 2
+# define MIN_WIDTH 10
+# define MIN_HEIGHT 20
+# define AssignText(X,T) allocate (X, char, strlen (T)); strcpy (X, T);
+# define AssignData(X,T,N) allocate (X, char, N); bcopy (T, X, N);
+
+int OVERLAY[NOVERLAYS];
+int MOVE_POINTER;
+int DECIMAL_DEG;
+int DEBUG;
Index: /trunk/Ohana/src/kii/include/icons/R0.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/R0.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/R0.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define R0_width 9
+#define R0_height 6
+static char R0_bits[] = {
+   0x00, 0x00, 0x7c, 0x00, 0x82, 0x00, 0x01, 0x01, 0x82, 0x00, 0x7c, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/R1.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/R1.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/R1.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define R1_width 9
+#define R1_height 6
+static char R1_bits[] = {
+   0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xff, 0x01, 0x02, 0x01, 0x04, 0x01};
Index: /trunk/Ohana/src/kii/include/icons/R2.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/R2.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/R2.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define R2_width 9
+#define R2_height 6
+static char R2_bits[] = {
+   0x00, 0x00, 0x0e, 0x01, 0x11, 0x01, 0x21, 0x01, 0x41, 0x01, 0x86, 0x01};
Index: /trunk/Ohana/src/kii/include/icons/R3.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/R3.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/R3.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define R3_width 9
+#define R3_height 6
+static char R3_bits[] = {
+   0x00, 0x00, 0xe3, 0x00, 0x15, 0x01, 0x19, 0x01, 0x11, 0x01, 0x81, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/R4.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/R4.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/R4.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define R4_width 9
+#define R4_height 6
+static char R4_bits[] = {
+   0x00, 0x00, 0x40, 0x00, 0xff, 0x01, 0x44, 0x00, 0x58, 0x00, 0x60, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/R5.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/R5.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/R5.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define R5_width 9
+#define R5_height 6
+static char R5_bits[] = {
+   0x00, 0x00, 0xf1, 0x00, 0x09, 0x01, 0x09, 0x01, 0x11, 0x01, 0x9f, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/R6.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/R6.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/R6.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define R6_width 9
+#define R6_height 6
+static char R6_bits[] = {
+   0x00, 0x00, 0xe2, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xfe, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/R7.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/R7.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/R7.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define R7_width 9
+#define R7_height 6
+static char R7_bits[] = {
+   0x00, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x31, 0x00, 0xc1, 0x01, 0x01, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/R8.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/R8.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/R8.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define R8_width 9
+#define R8_height 6
+static char R8_bits[] = {
+   0x00, 0x00, 0xee, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xee, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/R9.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/R9.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/R9.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define R9_width 9
+#define R9_height 6
+static char R9_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x8e, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/Rd.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/Rd.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/Rd.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define Rd_width 9
+#define Rd_height 6
+static char Rd_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0xc0, 0x01, 0x80, 0x00, 0x00, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/Re.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/Re.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/Re.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define Re_width 9
+#define Re_height 6
+static char Re_bits[] = {
+   0x00, 0x00, 0xb0, 0x00, 0x28, 0x01, 0x28, 0x01, 0x28, 0x01, 0xf0, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/Rm.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/Rm.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/Rm.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define Rm_width 9
+#define Rm_height 6
+static char Rm_bits[] = {
+   0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/Rp.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/Rp.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/Rp.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define Rp_width 9
+#define Rp_height 6
+static char Rp_bits[] = {
+   0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x7c, 0x00, 0x10, 0x00, 0x10, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/arrow.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/arrow.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/arrow.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define arrow_width 6
+#define arrow_height 9
+static char arrow_bits[] = {
+   0x00, 0x02, 0x06, 0x0e, 0x1e, 0x0e, 0x06, 0x02, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/back.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/back.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/back.h	(revision 2466)
@@ -0,0 +1,6 @@
+#define back_width 16
+#define back_height 16
+static char back_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00, 0x3c, 0x00, 0x3f, 0xc0, 0x3f,
+   0xf0, 0x3f, 0xfc, 0x3f, 0xfc, 0x3f, 0xf0, 0x3f, 0xc0, 0x3f, 0x00, 0x3f,
+   0x00, 0x3c, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/down.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/down.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/down.h	(revision 2466)
@@ -0,0 +1,4 @@
+#define down_width 9
+#define down_height 6
+static char down_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/fore.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/fore.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/fore.h	(revision 2466)
@@ -0,0 +1,6 @@
+#define fore_width 16
+#define fore_height 16
+static char fore_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x3c, 0x00, 0xfc, 0x00, 0xfc, 0x03,
+   0xfc, 0x0f, 0xfc, 0x3f, 0xfc, 0x3f, 0xfc, 0x0f, 0xfc, 0x03, 0xfc, 0x00,
+   0x3c, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/icon.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/icon.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/icon.h	(revision 2466)
@@ -0,0 +1,13 @@
+#define icon_width 30
+#define icon_height 30
+static char icon_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x01, 0x00,
+   0x00, 0xfe, 0x0f, 0x00, 0x00, 0xff, 0x1f, 0x00, 0xc0, 0x0f, 0x7e, 0x00,
+   0xe0, 0x01, 0xf0, 0x00, 0xe0, 0xff, 0xff, 0x00, 0xf0, 0xff, 0xff, 0x01,
+   0xb8, 0xff, 0xbf, 0x03, 0xb8, 0x03, 0xb8, 0x03, 0xb8, 0xe3, 0xb8, 0x03,
+   0x9c, 0xf3, 0x39, 0x07, 0x9c, 0xfb, 0x3b, 0x07, 0x9c, 0xfb, 0x3b, 0x07,
+   0x9c, 0xfb, 0x3b, 0x07, 0x9c, 0xf3, 0x39, 0x07, 0xb8, 0xe3, 0xb8, 0x03,
+   0xb8, 0x03, 0xb8, 0x03, 0xb8, 0xff, 0xbf, 0x03, 0xf0, 0xff, 0xff, 0x01,
+   0xe0, 0xff, 0xff, 0x00, 0xe0, 0x01, 0xf0, 0x00, 0xc0, 0x0f, 0x7e, 0x00,
+   0x00, 0xff, 0x1f, 0x00, 0x00, 0xfe, 0x0f, 0x00, 0x00, 0xf0, 0x01, 0x00,
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Index: /trunk/Ohana/src/kii/include/icons/stop.h
===================================================================
--- /trunk/Ohana/src/kii/include/icons/stop.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/icons/stop.h	(revision 2466)
@@ -0,0 +1,6 @@
+#define stop_width 16
+#define stop_height 16
+static char stop_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
+   0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f, 0xf8, 0x1f,
+   0xf8, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
Index: /trunk/Ohana/src/kii/include/prototypes.h
===================================================================
--- /trunk/Ohana/src/kii/include/prototypes.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/prototypes.h	(revision 2466)
@@ -0,0 +1,103 @@
+int SetColormap (Graphic *graphic, Layout *layout, char *name);
+void FlushDisplay (Display *display);
+int Recenter (Graphic *graphic, Layout *layout);
+void DrawOverlay (Graphic *graphic, Layout *layout, int N, FILE *f, int extra);
+int cursor (Graphic *graphic, Layout *layout);
+int PSit (Graphic *graphic, Layout *layout, int Raw);
+int JPEGit (Graphic *graphic, Layout *layout);
+int Resize (Graphic *graphic, Layout *layout);
+int Center (Graphic *graphic, Layout *layout);
+int LoadTickmarks (Graphic *graphic, Layout *layout);
+void PaintTickmarks (Graphic *graphic, Layout *layout);
+void Screen_to_Image (double *x1, double *y1, double x2, double y2, Layout *layout);
+void Image_to_Screen (double *x1, double *y1, double x2, double y2, Layout *layout);
+void UpdateStatusBox (Graphic *graphic, Layout *layout, double x, double y, double z, int mode);
+void Remap8 (Graphic *graphic, Layout *layout, Matrix *matrix);
+void Remap16 (Graphic *graphic, Layout *layout, Matrix *matrix);
+void Remap24 (Graphic *graphic, Layout *layout, Matrix *matrix);
+void Remap32 (Graphic *graphic, Layout *layout, Matrix *matrix);
+void CheckVisual (Graphic *graphic, int *argc, char **argv);
+void CreateZoom8 (Layout *layout, Graphic *graphic, double x, double y);
+void CreateZoom16 (Layout *layout, Graphic *graphic, double x, double y);
+void CreateZoom24 (Layout *layout, Graphic *graphic, double x, double y);
+void CreateZoom32 (Layout *layout, Graphic *graphic, double x, double y);
+
+/***** Prototypes for image ***************/
+
+void          PositionPictures    PROTO((Layout *, Graphic *));
+void          CreateColorbar      PROTO((Layout *, Graphic *));
+void          CreatePicture       PROTO((Layout *, Graphic *));
+void          CreateZoom          PROTO((Layout *, Graphic *, double, double));
+void          Remap               PROTO((Graphic *, Layout *, Matrix  *));
+int           NewPicture          PROTO((Graphic *, Layout *));
+void          Reorient            PROTO((Graphic *, Layout *, XButtonEvent *));
+int           UpdatePointer       PROTO((Graphic *, Layout *, XMotionEvent *));
+void          CrossHairs          PROTO((Graphic *, Layout *));
+int           LoadOverlay         PROTO((Graphic *, Layout *));
+int           SaveOverlay         PROTO((Graphic *, Layout *));
+int           CSaveOverlay         PROTO((Graphic *, Layout *));
+int           EraseOverlay        PROTO((Graphic *, Layout *));
+void          StatusBox           PROTO((Graphic *, Layout *));
+void          PaintOverlay        PROTO((Graphic *, Layout *, int));
+
+/***** Prototypes for action ***************/
+
+int           CheckPipe           PROTO((Graphic *, Layout *));
+void          DefineLayout        PROTO((Layout *, Graphic *, int, char **));
+int           EventLoop           PROTO((Graphic *, Layout *));
+int           InPicture           PROTO((XButtonEvent *, Picture *));
+int           InterpretKeys       PROTO((Graphic *, Layout *, XEvent *));
+int           InterpretPresses    PROTO((Graphic *, Layout *, XButtonEvent *));
+int           Reconfig            PROTO((Graphic *, Layout *, XEvent *));
+void          Refresh             PROTO((Graphic *, Layout *, int));
+int           Stop                PROTO((Graphic *, Layout *));
+int           PSit                PROTO((Graphic *, Layout *, int));
+int           get_argument        PROTO((int, char **, char *));
+int           remove_argument     PROTO((int, int *, char **));
+void          DragColorbar        PROTO((Graphic *, Layout *, XButtonEvent *));
+void          ResetColorbar       PROTO((Graphic *, Layout *, double, double));
+void          MakeColormap        PROTO((Graphic *, Layout *, int, char **));
+
+/***** Prototypes for button ***************/
+
+Button       *CheckButtons        PROTO((XButtonEvent *, Layout *));
+void          DrawButton          PROTO((Graphic *, Button *));
+void          FlashButton         PROTO((Graphic *, Button *));
+int           InButton            PROTO((XButtonEvent *, Button *));
+void          InvertButton        PROTO((Graphic *, Button *));
+int           greycolors          PROTO((Graphic *, Layout *));
+int           rainbow             PROTO((Graphic *, Layout *));
+int           puns                PROTO((Graphic *, Layout *));
+int           Recenter            PROTO((Graphic *, Layout *));
+int           RecenterRescale     PROTO((Graphic *, Layout *));
+int           Rescale             PROTO((Graphic *, Layout *));
+int           ToggleDEG           PROTO((Graphic *, Layout *));
+int           Overlay0            PROTO((Graphic *, Layout *));
+int           Overlay1            PROTO((Graphic *, Layout *));
+int           Overlay2            PROTO((Graphic *, Layout *));
+int           Overlay3            PROTO((Graphic *, Layout *));
+
+/***** Prototypes for xtools ***************/
+
+void          CheckColors         PROTO((Graphic *, int *, char **));
+void          CheckDisplayName    PROTO((int *, char **, char *));
+void          CheckFontName       PROTO((int *, char **, char *));
+void          CheckGeometry       PROTO((int *, char **, Graphic *));
+void          CloseDisplay        PROTO((Graphic *));
+void          CreateWindow        PROTO((Graphic *, Window, int, long));
+void          DrawBitmap          PROTO((Graphic *, int, int, int, int, char *, int));
+unsigned long GetColor            PROTO((Display *, char *, Colormap, unsigned long));
+void          LoadFont            PROTO((Graphic *, int *, char **, char *));
+void          MakeCursor          PROTO((Graphic *, unsigned int));
+void          MakeGC              PROTO((Graphic *));
+void          MapWindow           PROTO((Graphic *));
+void          NameWindow          PROTO((Graphic *, char *));
+Display      *OpenDisplay         PROTO((char *, int *));
+void          QuitX               PROTO((Display *, char *, char *));
+void          SetNormalHints      PROTO((Graphic *));
+void          SetUpDisplay        PROTO((Graphic *, int *, char **));
+void          SetUpWindow         PROTO((Graphic *, int *, char **));
+void          SetWMHints          PROTO((Graphic *, Icon *));
+void          TopWindow           PROTO((Graphic *, Icon *));
+
+void          hh_hms              PROTO((char *, double, double, char));
Index: /trunk/Ohana/src/kii/include/rotletters.h
===================================================================
--- /trunk/Ohana/src/kii/include/rotletters.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/rotletters.h	(revision 2466)
@@ -0,0 +1,56 @@
+#define R0_width 9
+#define R0_height 6
+static char R0_bits[] = {
+   0x00, 0x00, 0x7c, 0x00, 0x82, 0x00, 0x01, 0x01, 0x82, 0x00, 0x7c, 0x00};
+#define R1_width 9
+#define R1_height 6
+static char R1_bits[] = {
+   0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xff, 0x01, 0x02, 0x01, 0x04, 0x01};
+#define R2_width 9
+#define R2_height 6
+static char R2_bits[] = {
+   0x00, 0x00, 0x0e, 0x01, 0x11, 0x01, 0x21, 0x01, 0x41, 0x01, 0x86, 0x01};
+#define R3_width 9
+#define R3_height 6
+static char R3_bits[] = {
+   0x00, 0x00, 0xe3, 0x00, 0x15, 0x01, 0x19, 0x01, 0x11, 0x01, 0x81, 0x00};
+#define R4_width 9
+#define R4_height 6
+static char R4_bits[] = {
+   0x00, 0x00, 0x40, 0x00, 0xff, 0x01, 0x44, 0x00, 0x58, 0x00, 0x60, 0x00};
+#define R5_width 9
+#define R5_height 6
+static char R5_bits[] = {
+   0x00, 0x00, 0xf1, 0x00, 0x09, 0x01, 0x09, 0x01, 0x11, 0x01, 0x9f, 0x00};
+#define R6_width 9
+#define R6_height 6
+static char R6_bits[] = {
+   0x00, 0x00, 0xe2, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xfe, 0x00};
+#define R7_width 9
+#define R7_height 6
+static char R7_bits[] = {
+   0x00, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x31, 0x00, 0xc1, 0x01, 0x01, 0x00};
+#define R8_width 9
+#define R8_height 6
+static char R8_bits[] = {
+   0x00, 0x00, 0xee, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xee, 0x00};
+#define R9_width 9
+#define R9_height 6
+static char R9_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x8e, 0x00};
+#define Rd_width 9
+#define Rd_height 6
+static char Rd_bits[] = {
+   0x00, 0x00, 0x00, 0x00, 0x80, 0x00, 0xc0, 0x01, 0x80, 0x00, 0x00, 0x00};
+#define Re_width 9
+#define Re_height 6
+static char Re_bits[] = {
+   0x00, 0x00, 0xb0, 0x00, 0x28, 0x01, 0x28, 0x01, 0x28, 0x01, 0xf0, 0x00};
+#define Rm_width 9
+#define Rm_height 6
+static char Rm_bits[] = {
+   0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00};
+#define Rp_width 9
+#define Rp_height 6
+static char Rp_bits[] = {
+   0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x7c, 0x00, 0x10, 0x00, 0x10, 0x00};
Index: /trunk/Ohana/src/kii/include/structures.h
===================================================================
--- /trunk/Ohana/src/kii/include/structures.h	(revision 2466)
+++ /trunk/Ohana/src/kii/include/structures.h	(revision 2466)
@@ -0,0 +1,129 @@
+/**************** Graphic carries X info around ****************/
+typedef struct {
+  Display       *display;
+  int            screen;
+  int            depth;
+  Window         window;
+  Visual        *visual;
+  int            visualclass;
+  GC             gc;
+  XFontStruct   *font;
+  Cursor         cursor;
+  int            x,  y;
+  int            dx, dy;
+  Colormap       colormap;
+  unsigned long  Npixels, pixels[256];
+  int            Nbits;
+  /*
+  unsigned long  fore;
+  unsigned long  back;
+  */
+  unsigned long  black, white;
+} Graphic;
+
+/**************** X related "widget" structures ****************/
+typedef struct {
+  int      x, y, dx, dy;      /* position and size */
+  int      text;              /* does this have a picture or text? */
+  int      width, height;
+  char    *bitmap;          /* picture on button */
+  int    (*function_1) ();  /* mouse_button 1 function */
+  int    (*function_2) ();  /* mouse_button 2 function */
+  int    (*function_3) ();  /* mouse_button 3 function */
+} Button;
+
+typedef struct {
+  int      x, y, dx, dy;   /* position and size */
+  char    *label;          /* label on TextLine */
+  char     text[1024];     /* words of TextLine */
+  char     old_text[1024]; /* words of TextLine */
+  int      outline;        /* draw an outline?  */ 
+  int      cursor;         /* location of cursor (if selected) */
+  int    (*function) ();   /* textline function */
+} TextLine;
+
+typedef char STRING[1024];
+
+typedef struct {
+  int      x, y, dx, dy;   /* position and size */
+  STRING  *text;           /* words of TextLine */
+  int      Nlines;
+  int      outline;        /* draw an outline?  */ 
+  int      cursor_line;    /* cursor line */
+  int      cursor_x;       /* location of cursor (if selected) */
+  int      cursor_y;       /* location of cursor (if selected) */
+  int    (*function) ();   /* textline function */
+} TextBox;
+
+/**************** general structures ****************/
+typedef struct {
+  Pixmap pixmap;
+  int    width;
+  int    height;
+  char  *bits;
+} Icon;
+
+typedef struct {
+  int      dx, dy, x, y;
+  XImage  *pix;
+  char    *data;
+} Picture;
+
+typedef struct {
+  char type[10];
+  double x, y;
+  double dx, dy;
+  double angle;
+  char  *text;
+} Object;
+
+typedef struct {
+  int Nobjects;
+  unsigned long color;
+  Object *objects;
+} Overlay;
+  
+/******** Here we define the Layout struct specific to this program  *******/
+typedef struct {
+  /* objects on the mana window */
+  Picture  picture;
+  Picture  cmapbar;
+  Picture  zoom;
+  Button   PS_button;
+  Button   recenter_button;
+  Button   hms_button; /* toggle HMS/DECIMAL mode (DECIMAL_DEG macro) */
+  Button   grey_button;
+  Button   rainbow_button;
+  Button   puns_button;
+  Button   overlay_button[NOVERLAYS];
+  Overlay  overlay[NOVERLAYS];
+  Overlay  tickmarks;
+  int      text_x, text_y;
+
+  /* file descriptor for socket connection to mana */
+  int Ximage; 
+
+  /* data mana needs */
+  Matrix   matrix;         /* data for picture */
+  double   X, Y;           /* image pixel at screen center */
+  int      expand;         /* zoomscale */
+  double   zero, range;    /* zero, range for picture to cmap */
+  double   max, min;       /* zero, range for data to z-value */
+  double   start, slope;   /* zero, range for cmap to pixels */
+  double   x, y, z;        /* last pointer coords */
+  Coords   coords;
+  char     file[1024];     /* name of file */
+  char     buffer_name[1024];  /* name of buffer */
+
+  /* fundamental pieces */
+  unsigned long  black;
+  unsigned long  white;
+  XColor   cmap[256];
+  int      Npixels;
+
+} Layout;
+
+
+/* this routine is independent of the number of overlays */
+
+
Index: /trunk/Ohana/src/kii/misc/hh_hms.c
===================================================================
--- /trunk/Ohana/src/kii/misc/hh_hms.c	(revision 2466)
+++ /trunk/Ohana/src/kii/misc/hh_hms.c	(revision 2466)
@@ -0,0 +1,28 @@
+# include "Ximage.h"
+
+void hh_hms (char *line, double ra, double dec, char sep) {
+
+  int h, m, flag;
+  double s;
+  
+  ra /= 15.0;  /* convert from degrees to hours */
+  flag = SIGN(ra);
+  ra *= flag;
+  h = ra;
+  m = 60.000001*(ra - h);
+  s = 3600*(ra - h - m / 60.0);
+  if (flag > 0)
+    sprintf (line, " %02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
+  else
+    sprintf (line, "-%02d%c%02d%c%04.1f  ", h, sep, m, sep, s);
+  
+  flag = SIGN(dec);
+  dec *= flag;
+  h = dec;
+  m = 60.000001*(dec - h);
+  s = 3600*(dec - h - m / 60.0);
+  if (flag > 0)
+    sprintf (&line[13], " %02d%c%02d%c%04.1f", h, sep, m, sep, s);
+  else
+    sprintf (&line[13], "-%02d%c%02d%c%04.1f", h, sep, m, sep, s);
+}
Index: /trunk/Ohana/src/kii/notes
===================================================================
--- /trunk/Ohana/src/kii/notes	(revision 2466)
+++ /trunk/Ohana/src/kii/notes	(revision 2466)
@@ -0,0 +1,4 @@
+1/31/94: totally revamped the overlay function -- made two overlays,
+red and green.  Added two buttons to toggle them on and off.  Made
+functions for mana to "load" and "save" files with overlay objects
+defined.  Made contour function for mana.  
Index: /trunk/Ohana/src/kii/overlay/CSaveOverlay.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/CSaveOverlay.c	(revision 2466)
+++ /trunk/Ohana/src/kii/overlay/CSaveOverlay.c	(revision 2466)
@@ -0,0 +1,51 @@
+# include "Ximage.h"
+
+/*************/
+int CSaveOverlay (Graphic *graphic, Layout *layout) {
+
+  char buffer[256], filename[256];
+  int i, status, Nbytes, N;
+  double ra, dec, ra1, dec1, x1, y1, dra, ddec;
+  FILE *f;
+
+  status = read (layout[0].Ximage, buffer, 16); 
+  buffer[16] = 0; 
+  sscanf (buffer, "%*s %d", &Nbytes); 
+  status = read (layout[0].Ximage, buffer, Nbytes); 
+  buffer[Nbytes] = 0; 
+  sscanf (buffer, "%*s %d %s", &N, filename);
+  
+  f = fopen (filename, "w");
+  if (f == NULL) {
+    fprintf (stderr, "could not open %s\n", filename);
+    return (TRUE);
+  }
+
+  for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+    if (!strcmp (layout[0].overlay[N].objects[i].type, "LINE")) {
+      XY_to_RD (&ra, &dec, layout[0].overlay[N].objects[i].x, layout[0].overlay[N].objects[i].y, &layout[0].coords);
+      x1 = layout[0].overlay[N].objects[i].x + layout[0].overlay[N].objects[i].dx;
+      y1 = layout[0].overlay[N].objects[i].y + layout[0].overlay[N].objects[i].dy;
+      XY_to_RD (&ra1, &dec1, x1, y1, &layout[0].coords);
+      dra = (ra1 - ra);
+      ddec = (dec1 - dec);
+    } else {
+      XY_to_RD (&ra, &dec, layout[0].overlay[N].objects[i].x, layout[0].overlay[N].objects[i].y, &layout[0].coords);
+      x1 = layout[0].overlay[N].objects[i].x;
+      y1 = layout[0].overlay[N].objects[i].y + layout[0].overlay[N].objects[i].dy;
+      XY_to_RD (&ra1, &dec1, x1, y1, &layout[0].coords);
+      ddec = fabs (dec1 - dec);
+      x1 = layout[0].overlay[N].objects[i].x + layout[0].overlay[N].objects[i].dx;
+      y1 = layout[0].overlay[N].objects[i].y;
+      XY_to_RD (&ra1, &dec1, x1, y1, &layout[0].coords);
+      dra = cos (dec*RAD_DEG) * fabs (ra1 - ra);
+    }
+    fprintf (f, "%s %lf %lf %lf %lf\n", layout[0].overlay[N].objects[i].type, ra, dec, dra, ddec);
+   }
+  fclose (f);
+  return (TRUE);
+}
+
+
+/* this routine is independent of the number of overlays */
+
Index: /trunk/Ohana/src/kii/overlay/DrawOverlay.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/DrawOverlay.c	(revision 2466)
+++ /trunk/Ohana/src/kii/overlay/DrawOverlay.c	(revision 2466)
@@ -0,0 +1,81 @@
+# include "Ximage.h"
+# define INFRONT 3
+
+void DrawOverlay (Graphic *graphic, Layout *layout, int N, FILE *f, int extra) {
+
+  int i;
+  double X, Y, dX, dY;
+  int Xmin, Ymin, Xmax, Ymax;
+  double expand, X0, Y0;
+ 
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+  }
+  /*  
+  X0 =  (layout[0].X + 1 - 0.5*layout[0].matrix.Naxis[0])/expand + 0.5*layout[0].picture.dx;
+  Y0 =  (layout[0].Y + 1 - 0.5*layout[0].matrix.Naxis[1])/expand + 0.5*layout[0].picture.dy;
+  */
+  Image_to_Screen (&X0, &Y0, 0.0, 0.0, layout);
+  X0 -= layout[0].picture.x;
+  Y0 -= layout[0].picture.y;
+
+  Xmin = 0;
+  Ymin = 0;
+  Xmax = layout[0].picture.dx;
+  Ymax = layout[0].picture.dy;
+
+  for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+    if (N == INFRONT) {
+      X  = layout[0].overlay[N].objects[i].x * Xmax;
+      Y  = layout[0].overlay[N].objects[i].y * Ymax;
+      dX = layout[0].overlay[N].objects[i].dx * Xmax;
+      dY = layout[0].overlay[N].objects[i].dy * Ymax;
+    } else {
+      X  = (layout[0].overlay[N].objects[i].x)/expand + X0;
+      Y =  Ymax - (layout[0].overlay[N].objects[i].y)/expand - Y0;
+      dX = (layout[0].overlay[N].objects[i].dx)/expand;
+      dY = (layout[0].overlay[N].objects[i].dy)/expand;
+    }
+    
+    if (!strcmp (layout[0].overlay[N].objects[i].type, "LINE")) {
+      if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
+	  ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
+	continue;
+      }
+      fprintf (f, " %6.1f %6.1f %6.1f %6.1f L\n", X + extra, Y + extra, (X+dX + extra), (Y-dY + extra));
+      continue;
+    }
+    if (!strcmp (layout[0].overlay[N].objects[i].type, "TEXT")) {
+      if (((X < Xmin) && (X + dX < Xmin)) || ((X > Xmax) && (X + dX > Xmax)) ||
+	  ((Y < Ymin) && (Y + dY < Ymin)) || ((Y > Ymax) && (Y + dY > Ymax))) {
+	continue;
+      }
+      fprintf (f, "(%s) %6.1f %6.1f T\n", layout[0].overlay[N].objects[i].text, X + extra, Y + extra); 
+      continue;
+    }
+    if (!strcmp (layout[0].overlay[N].objects[i].type, "BOX")) {
+      if (((X - 0.5*dX < Xmin) && (X + 0.5*dX < Xmin)) || ((X - 0.5*dX > Xmax) && (X + 0.5*dX > Xmax)) ||
+	  ((Y - 0.5*dY < Ymin) && (Y + 0.5*dY < Ymin)) || ((Y - 0.5*dY > Ymax) && (Y + 0.5*dY > Ymax))) {
+	continue;
+      }
+      fprintf (f, " %6.1f %6.1f %6.1f %6.1f B\n", (dX + 2*extra), (dY + 2*extra), (X - 0.5*dX - extra), (Y - 0.5*dY - extra));
+      continue;
+    }
+    if (!strcmp (layout[0].overlay[N].objects[i].type, "CIRCLE")) {
+      if (((X - dX < Xmin) && (X + dX < Xmin)) || ((X - dX > Xmax) && (X + dX > Xmax)) ||
+	  ((Y - dY < Ymin) && (Y + dY < Ymin)) || ((Y - dY > Ymax) && (Y + dY > Ymax))) {
+	continue;
+      }
+      fprintf (f, " %6.1f %6.1f %6.1f C\n", X, Y, fabs(dX + extra));
+      continue;
+    }
+    fprintf (stderr, "don't know %s, skipping\n", layout[0].overlay[N].objects[i].type);
+  }
+  
+}
+
+/* this routine is independent of the number of overlays */
+
Index: /trunk/Ohana/src/kii/overlay/EraseOverlay.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/EraseOverlay.c	(revision 2466)
+++ /trunk/Ohana/src/kii/overlay/EraseOverlay.c	(revision 2466)
@@ -0,0 +1,27 @@
+# include "Ximage.h"
+
+int EraseOverlay (Graphic *graphic, Layout *layout) {
+
+  char buffer[256];
+  int i, status, N;
+
+  status = read (layout[0].Ximage, buffer, 16); 
+  buffer[16] = 0; 
+  sscanf (buffer, "%*s %d", &N); 
+  if (N > NOVERLAYS) {
+    REALLOCATE (layout[0].tickmarks.objects, Object, 1);
+    layout[0].tickmarks.Nobjects = 0;
+  } else {
+    for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+      if (!strcmp (layout[0].overlay[N].objects[i].type, "TEXT")) {
+	free (layout[0].overlay[N].objects[i].text);
+      }
+    }
+    REALLOCATE (layout[0].overlay[N].objects, Object, 1);
+    layout[0].overlay[N].Nobjects = 0;
+    OVERLAY[N] = FALSE;
+  }
+
+  Refresh (graphic, layout, 0);
+  return (TRUE);
+}
Index: /trunk/Ohana/src/kii/overlay/LoadOverlay.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/LoadOverlay.c	(revision 2466)
+++ /trunk/Ohana/src/kii/overlay/LoadOverlay.c	(revision 2466)
@@ -0,0 +1,102 @@
+# include "Ximage.h"
+
+int LoadOverlay (graphic, layout)
+     Graphic graphic[];
+     Layout  layout[];
+{
+  
+  char line[17], *buffer, *buff, type[16], string[128];
+  double x, y, dx, dy;
+  int Nin, bytes, status;
+  int i, N, NOBJECTS, Nobjects, Nstart, done;
+
+  ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
+  bzero (buffer, 65536);
+  done = FALSE;
+
+  fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
+
+  status = read (layout[0].Ximage, line, 16); 
+  line[16] = 0; 
+  sscanf (line, "%*s %d", &N); 
+  Nstart = layout[0].overlay[N].Nobjects;
+
+  while (!done) {
+    status = read (layout[0].Ximage, line, 16); 
+    line[16] = 0; 
+    
+    if (!strncmp (line, "DONE", 4)) {
+      done = TRUE;
+      break;
+    }
+
+    if (!strncmp (line, "NLINES", 6)) {
+      sscanf (line, "%*s %d", &Nin);
+      buff = buffer;
+      bytes = 128*Nin;
+      fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+      while (bytes > 0) { 
+	status = read (layout[0].Ximage, buff, bytes);
+	if (status == 0) {  /* No more pipe */
+	  fprintf (stderr, "error: pipe closed\n");
+	  free (buffer);
+	  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+	  return (FALSE);
+	}
+	if (status != -1) { /* pipe has data */
+	  bytes -= status;
+	  buff = (char *)(buff + status);
+	}
+      }
+      fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
+      /* parse buffer data */
+      NOBJECTS = layout[0].overlay[N].Nobjects + Nin;
+      Nobjects = layout[0].overlay[N].Nobjects;
+      REALLOCATE (layout[0].overlay[N].objects, Object, NOBJECTS);
+      for (i = 0; i < Nin; i++) {
+	sscanf (&buffer[i*128], "%s %lf %lf %lf %lf\n", type, &x, &y, &dx, &dy);
+
+	if (strcasecmp (type, "TEXT") && strcasecmp (type, "LINE") && strcasecmp (type, "BOX") && strcasecmp (type, "CIRCLE")) {  /* skip */
+	  fprintf (stderr, "don't know %s, skipping\n", type);
+	  continue;
+	}
+
+	if (!strcasecmp (type, "TEXT")) { /* end of objects */
+	  sscanf (&buffer[i*128], "%s %lf %lf %s\n", type, &x, &y, string);
+	}
+	
+	strcpy (layout[0].overlay[N].objects[Nobjects].type, type);
+	layout[0].overlay[N].objects[Nobjects].x = x;
+	layout[0].overlay[N].objects[Nobjects].y = y;
+	if (!strcmp (type, "TEXT")) {
+	  layout[0].overlay[N].objects[Nobjects].dx = 0;
+	  layout[0].overlay[N].objects[Nobjects].dy = 0;
+	  layout[0].overlay[N].objects[Nobjects].text = strcreate (string);
+	} else {
+	  layout[0].overlay[N].objects[Nobjects].dx = dx;
+	  layout[0].overlay[N].objects[Nobjects].dy = dy;
+	}
+	Nobjects++;
+      }
+      REALLOCATE (layout[0].overlay[N].objects, Object, MAX(Nobjects, 1));
+      layout[0].overlay[N].Nobjects = Nobjects;
+    }
+  }
+
+  free (buffer);
+  REALLOCATE (layout[0].overlay[N].objects, Object, MAX (1, layout[0].overlay[N].Nobjects));
+  OVERLAY[N] = TRUE;
+  /*  Refresh (graphic, layout, 0); */
+  for (i = 0; i < NOVERLAYS; i++) {
+    if (OVERLAY[i])
+      PaintOverlay (graphic, layout, i);
+  }
+  PaintTickmarks (graphic, layout);
+  XFlush (graphic[0].display);
+  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+  return (TRUE);
+
+}
+
+
+/* this routine is independent of the number of overlays */
Index: /trunk/Ohana/src/kii/overlay/LoadTickmarks.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/LoadTickmarks.c	(revision 2466)
+++ /trunk/Ohana/src/kii/overlay/LoadTickmarks.c	(revision 2466)
@@ -0,0 +1,64 @@
+# include "Ximage.h"
+
+int LoadTickmarks (Graphic *graphic, Layout *layout) {
+  
+  char line[129], type[16];
+  double x, y, dx, dy;
+  int status, NOBJECTS, Nobjects, done;
+
+  fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
+
+  Nobjects = layout[0].tickmarks.Nobjects;
+  NOBJECTS = Nobjects + 100;
+  REALLOCATE (layout[0].tickmarks.objects, Object, NOBJECTS);
+  
+  done = FALSE;
+  while (!done) {
+    status = read (layout[0].Ximage, line, 128); 
+    line[128] = 0; 
+
+    if (!strncmp (line, "DONE", 4)) {
+      done = TRUE;
+      break;
+    }
+    
+    sscanf (line, "%s %lf %lf %lf %lf\n", type, &x, &y, &dx, &dy);
+    
+    if (strcmp (type, "TEXT") && strcmp (type, "LINE") && strcmp (type, "BOX") && strcmp (type, "CIRCLE")) {  /* skip */
+      fprintf (stderr, "don't know %s, skipping\n", type);
+      continue;
+    }
+    
+    strcpy (layout[0].tickmarks.objects[Nobjects].type, type);
+    layout[0].tickmarks.objects[Nobjects].x = x;
+    layout[0].tickmarks.objects[Nobjects].y = y;
+    layout[0].tickmarks.objects[Nobjects].dx = dx;
+    layout[0].tickmarks.objects[Nobjects].dy = dy;
+    
+    if (!strcmp (type, "TEXT")) { /* dx = Nchar, dy = angle (not yet used) */
+      status = read (layout[0].Ximage, line, 128); 
+      line[128] = 0; 
+      ALLOCATE (layout[0].tickmarks.objects[Nobjects].text, char, (int) dx + 1);
+      strncpy (layout[0].tickmarks.objects[Nobjects].text, line, (int) dx);
+      layout[0].tickmarks.objects[Nobjects].text[(int)dx] = 0;
+    }      
+    
+    Nobjects++;
+    if (Nobjects >= NOBJECTS) {
+      NOBJECTS = Nobjects + 100;
+      REALLOCATE (layout[0].tickmarks.objects, Object, NOBJECTS);
+    }
+
+  }
+
+  REALLOCATE (layout[0].tickmarks.objects, Object, MAX(Nobjects, 1));
+  layout[0].tickmarks.Nobjects = Nobjects;
+
+  Refresh (graphic, layout, 0);
+  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+  return (TRUE);
+  
+}
+
+
+/* this routine is independent of the number of overlays */
Index: /trunk/Ohana/src/kii/overlay/PaintOverlay.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/PaintOverlay.c	(revision 2466)
+++ /trunk/Ohana/src/kii/overlay/PaintOverlay.c	(revision 2466)
@@ -0,0 +1,84 @@
+# include "Ximage.h"
+# define INFRONT 4
+
+void PaintOverlay (Graphic *graphic, Layout *layout, int N) {
+
+  int i;
+  int dX, dY, dx, dy;
+  int X, Y, Xmin, Ymin, Xmax, Ymax, Xrange, Yrange;
+  double expand, X0, Y0;
+ 
+  XSetForeground (graphic[0].display, graphic[0].gc, layout[0].overlay[N].color);
+  
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+  }
+  /* 
+  X = 0.5*layout[0].matrix.Naxis[0] - expand*((int)(0.5*layout[0].picture.dx + 0.5) - 0.0) - layout[0].X;
+  Y = 0.5*layout[0].matrix.Naxis[1] - expand*((int)(0.5*layout[0].picture.dy + 0.5) - 0.0) - layout[0].Y;  
+  X0 =  (layout[0].X + 1 - (int)(0.5*layout[0].matrix.Naxis[0] + 0.5) - X + (int)X)/expand + layout[0].picture.x + 0.5*layout[0].picture.dx;
+  Y0 =  (layout[0].Y + 1 - (int)(0.5*layout[0].matrix.Naxis[1] + 0.5) - Y + (int)Y)/expand + layout[0].picture.y + 0.5*layout[0].picture.dy;
+  */
+
+  Image_to_Screen (&X0, &Y0, 0.0, 0.0, layout);
+
+  Xmin = layout[0].picture.x;
+  Ymin = layout[0].picture.y;
+  Xmax = layout[0].picture.x + layout[0].picture.dx;
+  Ymax = layout[0].picture.y + layout[0].picture.dy;
+  Xrange = layout[0].picture.dx;
+  Yrange = layout[0].picture.dy;
+
+  for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+    if (N == INFRONT) {
+      X  = layout[0].overlay[N].objects[i].x * Xrange + Xmin;
+      Y  = layout[0].overlay[N].objects[i].y * Yrange + Ymin;
+      dX = layout[0].overlay[N].objects[i].dx * Xrange;
+      dY = layout[0].overlay[N].objects[i].dy * Yrange;
+    } else {
+      X  = layout[0].overlay[N].objects[i].x/expand + X0;
+      Y =  layout[0].overlay[N].objects[i].y/expand + Y0;
+      dX = layout[0].overlay[N].objects[i].dx/expand;
+      dY = layout[0].overlay[N].objects[i].dy/expand;
+    }
+    if ((X + dX < Xmin) || (X - dX > Xmax) ||
+	(Y + dY < Ymin) || (Y - dY > Ymax)) {
+      continue;
+    }
+
+    /* for a LINE, (x, y) is the start, (dx, dy) is the distance to end
+       for a CIRCLE (x, y) is the center, (dx, dy) is the radius 
+       for a BOX (x, y) is the center, (dx, dy) is the width */
+
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "LINE")) {
+      XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
+      continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "TEXT")) {
+      XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, layout[0].overlay[N].objects[i].text, strlen(layout[0].overlay[N].objects[i].text));
+      continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "BOX")) {
+      dx = MAX (abs(dX),2) / 2;
+      dy = MAX (abs(dY),2) / 2;
+      XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy);
+       continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "CIRCLE")) {
+      dx = MAX (abs(dX),2);
+      dy = MAX (abs(dY),2);
+      XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, (X - dx), (Y - dy), 2*dx, 2*dy, 0, 23040);
+      continue;
+    }
+    fprintf (stderr, "don't know %s, skipping (PO)\n", layout[0].overlay[N].objects[i].type);
+  }
+  
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+}
+
+/* this routine is independent of the number of overlays */
+
Index: /trunk/Ohana/src/kii/overlay/PaintTickmarks.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/PaintTickmarks.c	(revision 2466)
+++ /trunk/Ohana/src/kii/overlay/PaintTickmarks.c	(revision 2466)
@@ -0,0 +1,66 @@
+# include "Ximage.h"
+# define INFRONT 3
+/* # include "rotletters.h" */
+
+void PaintTickmarks (Graphic *graphic, Layout *layout) {
+
+  int i;
+  int X, Y, dX, dY;
+  int Xmin, Ymin, Xmax, Ymax, Xrange, Yrange;
+ 
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+  Xmin = layout[0].picture.x;
+  Ymin = layout[0].picture.y;
+  Xmax = layout[0].picture.x + layout[0].picture.dx;
+  Ymax = layout[0].picture.y + layout[0].picture.dy;
+  Xrange = layout[0].picture.dx;
+  Yrange = layout[0].picture.dy;
+
+  for (i = 0; i < layout[0].tickmarks.Nobjects; i++) {
+    X  = layout[0].tickmarks.objects[i].x * Xrange + Xmin;
+    Y  = layout[0].tickmarks.objects[i].y * Yrange + Ymin;
+    dX = layout[0].tickmarks.objects[i].dx * Xrange;
+    dY = layout[0].tickmarks.objects[i].dy * Yrange;
+
+    if (!strcmp (layout[0].tickmarks.objects[i].type, "LINE")) {
+      XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, (X+dX), (Y+dY));
+      continue;
+    }
+    if (!strcmp (layout[0].tickmarks.objects[i].type, "TEXT")) {
+      if (layout[0].tickmarks.objects[i].dy == 0) {
+	XSetForeground (graphic[0].display, graphic[0].gc, layout[0].white);
+	XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-11, 6*strlen(layout[0].tickmarks.objects[i].text), 11); 
+	XSetForeground (graphic[0].display, graphic[0].gc, layout[0].black);
+	XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, layout[0].tickmarks.objects[i].text, strlen(layout[0].tickmarks.objects[i].text));
+      }
+      if (layout[0].tickmarks.objects[i].dy == 90) {
+	XSetForeground (graphic[0].display, graphic[0].gc, layout[0].white);
+	XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y-6*strlen(layout[0].tickmarks.objects[i].text), 11, 6*strlen(layout[0].tickmarks.objects[i].text)); 
+	XSetForeground (graphic[0].display, graphic[0].gc, layout[0].black);
+	/* XDrawRotString (graphic[0].display, graphic[0].window, graphic[0].gc, X, Y, layout[0].tickmarks.objects[i].text, strlen(layout[0].tickmarks.objects[i].text)); */
+      }
+      continue;
+    }
+    if (!strcmp (layout[0].tickmarks.objects[i].type, "BOX")) {
+      XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, (int)(X - 0.5*dX), (int)(Y - 0.5*dY), abs(dX), abs(dY));
+       continue;
+    }
+    if (!strcmp (layout[0].tickmarks.objects[i].type, "CIRCLE")) {
+      XDrawArc (graphic[0].display, graphic[0].window, graphic[0].gc, X - dX, Y - dY, abs(2*dX), abs(2*dY), 0, 23040);
+      continue;
+    }
+    fprintf (stderr, "don't know %s, skipping (PO)\n", layout[0].tickmarks.objects[i].type);
+  }
+  
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+}
+
+/* this routine is independent of the number of overlays */
+
+
+/*
+XDrawRotString (dpy, win, gc, X, Y, text, len)
+     
+*/
Index: /trunk/Ohana/src/kii/overlay/SaveOverlay.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/SaveOverlay.c	(revision 2466)
+++ /trunk/Ohana/src/kii/overlay/SaveOverlay.c	(revision 2466)
@@ -0,0 +1,41 @@
+# include "Ximage.h"
+
+/*************/
+int 
+SaveOverlay (graphic, layout)
+     Graphic graphic[];
+     Layout  layout[];
+{
+
+  char buffer[256], filename[256];
+  int i, status, Nbytes, N;
+  FILE *f;
+
+  status = read (layout[0].Ximage, buffer, 16); 
+  buffer[16] = 0; 
+  sscanf (buffer, "%*s %d", &Nbytes); 
+  status = read (layout[0].Ximage, buffer, Nbytes); 
+  buffer[Nbytes] = 0; 
+  sscanf (buffer, "%*s %d %s", &N, filename);
+  
+  f = fopen (filename, "w");
+  if (f == NULL) {
+    fprintf (stderr, "could not open %s\n", filename);
+    return (TRUE);
+  }
+
+  for (i = 0; i < layout[0].overlay[N].Nobjects; i++) {
+    fprintf (f, "%s %lf %lf %lf %lf\n", 
+	     layout[0].overlay[N].objects[i].type,
+	     layout[0].overlay[N].objects[i].x,
+	     layout[0].overlay[N].objects[i].y,
+	     layout[0].overlay[N].objects[i].dx,
+	     layout[0].overlay[N].objects[i].dy);
+  }
+  fclose (f);
+  return (TRUE);
+}
+
+
+/* this routine is independent of the number of overlays */
+
Index: /trunk/Ohana/src/kii/picture/Center.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Center.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/Center.c	(revision 2466)
@@ -0,0 +1,28 @@
+# include "Ximage.h"
+
+int Center (Graphic *graphic, Layout *layout) {
+
+  char buffer[1024];
+  int status, zoom, Nbytes;
+  double X, Y;
+
+  status = read (layout[0].Ximage, buffer, 16); 
+  buffer[16] = 0; 
+  sscanf (buffer, "%*s %d", &Nbytes); 
+  status = read (layout[0].Ximage, buffer, Nbytes); 
+  buffer[status] = 0; /* make the string easy to parse */ 
+  sscanf (buffer, "%lf %lf %d", &X,  &Y, &zoom);
+
+  layout[0].X = 0.5*layout[0].matrix.Naxis[0] - X;
+  layout[0].Y = 0.5*layout[0].matrix.Naxis[1] - Y;
+  if ((zoom != 0) && (zoom != -1)) {
+    layout[0].expand = zoom;
+  }
+
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+
+  XFlush (graphic[0].display);
+  return (TRUE);
+}
+
Index: /trunk/Ohana/src/kii/picture/CreatePicture.c
===================================================================
--- /trunk/Ohana/src/kii/picture/CreatePicture.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/CreatePicture.c	(revision 2466)
@@ -0,0 +1,67 @@
+# include "Ximage.h"
+
+void CreatePicture (Layout *layout, Graphic *graphic) {
+
+  int i, j, extra;
+  char *c;
+  unsigned int *l;
+  unsigned int start, start1, start2, start3;
+
+  start = layout[0].white;
+
+  switch (graphic[0].Nbits) {
+  case 8:
+    REALLOCATE (layout[0].picture.data, char, layout[0].picture.dx*layout[0].picture.dy);
+    c = layout[0].picture.data;
+    for (i = 0; i < (layout[0].picture.dx*layout[0].picture.dy); i++, c++)
+      *c = start;
+    layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 8, 0);
+    break;
+
+  case 16:
+    REALLOCATE (layout[0].picture.data, char, 2*layout[0].picture.dy*layout[0].picture.dx);
+    c = layout[0].picture.data;
+    start1 = 0x0000ff & (start);
+    start2 = 0x0000ff & (start >> 8);
+    for (i = 0; i < layout[0].picture.dy; i++) {
+      for (j = 0; j < layout[0].picture.dx; j++, c+=2) {
+	c[0] = start1;
+	c[1] = start2;
+      }
+    }
+    layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 16, 0);
+    break;
+
+  case 24:
+    extra = 4 - (layout[0].picture.dx * 3) % 4;
+    REALLOCATE (layout[0].picture.data, char, layout[0].picture.dy*(3*layout[0].picture.dx+extra));
+    c = (unsigned char *) layout[0].picture.data;
+    start1 = 0x0000ff & (start);
+    start2 = 0x0000ff & (start >> 8);
+    start3 = 0x0000ff & (start >> 16);
+    for (i = 0; i < layout[0].picture.dy; i++) {
+      for (j = 0; j < layout[0].picture.dx; j++, c+=3) {
+	c[0] = start1;
+	c[1] = start2;
+	c[2] = start3;
+      }
+      c+=extra;
+    }
+    layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 24, 0);
+    break;
+
+  case 32:
+    ALLOCATE (layout[0].picture.data, char, (4*layout[0].picture.dx*layout[0].picture.dy + 32));
+    memset (layout[0].picture.data, 0xbd, 4*layout[0].picture.dx*layout[0].picture.dy + 30);
+    l = (unsigned int *) layout[0].picture.data;
+    for (i = 0; i < (layout[0].picture.dx*layout[0].picture.dy); i++, l++)
+      *l = start;
+    layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					  layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 32, 0);
+    break;
+  }
+    
+}
Index: /trunk/Ohana/src/kii/picture/CursorOps.c
===================================================================
--- /trunk/Ohana/src/kii/picture/CursorOps.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/CursorOps.c	(revision 2466)
@@ -0,0 +1,35 @@
+# include "Ximage.h"
+
+void Screen_to_Image (double *x1, double *y1, double x2, double y2, Layout *layout) {
+
+  double expand;
+
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+  }
+  
+  *x1 = expand*(x2 - layout[0].picture.x - 0.5*layout[0].picture.dx) + 0.5*layout[0].matrix.Naxis[0] - layout[0].X;
+  *y1 = expand*(y2 - layout[0].picture.y - 0.5*layout[0].picture.dy) + 0.5*layout[0].matrix.Naxis[1] - layout[0].Y;
+  
+}
+
+void Image_to_Screen (double *x1, double *y1, double x2, double y2, Layout *layout) {
+
+  double expand;
+
+  /* notice that here, expand is the reciprocal of the expand above */
+  if (layout[0].expand > 0) {
+    expand = abs(layout[0].expand);
+  }
+  if (layout[0].expand < 0) {
+    expand = 1 / ((double)abs(layout[0].expand));
+  }
+  
+  *x1 = (x2 - 0.5*layout[0].matrix.Naxis[0] + layout[0].X) * expand + layout[0].picture.x + 0.5*layout[0].picture.dx;
+  *y1 = (y2 - 0.5*layout[0].matrix.Naxis[1] + layout[0].Y) * expand + layout[0].picture.y + 0.5*layout[0].picture.dy;
+  
+}
+
Index: /trunk/Ohana/src/kii/picture/NewPicture.c
===================================================================
--- /trunk/Ohana/src/kii/picture/NewPicture.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/NewPicture.c	(revision 2466)
@@ -0,0 +1,84 @@
+# include "Ximage.h"
+# define SCAN \
+  status = read (layout[0].Ximage, buffer, 16); \
+  buffer[16] = 0; \
+  sscanf (buffer, "%*s %d", &Nbytes); \
+  status = read (layout[0].Ximage, buffer, Nbytes); \
+  buffer[status] = 0; /* make the string easy to parse */ \
+  (DEBUG) && fprintf (stderr, "buffer: <%s>\n", buffer); \
+
+int NewPicture (Graphic *graphic, Layout *layout) {
+
+  Header header;
+  char buffer[1024], *buff;
+  int status, bytes_left, Nbytes;
+ 
+  fits_free_matrix (&layout[0].matrix);
+  sprintf (buffer, "NCOLOR: %6d ", layout[0].Npixels);
+  write (layout[0].Ximage, buffer, 16);
+
+  fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
+
+  header.Naxes = 2;
+  SCAN;
+  sscanf (buffer, "%d %d %d %d %lf %lf",
+	  &header.Naxis[0], &header.Naxis[1], &header.bitpix, 
+	  &header.unsign,   &header.bzero,    &header.bscale);
+
+  SCAN;
+  sscanf (buffer, "%lf %lf %lf %lf %d", &layout[0].zero, &layout[0].range, &layout[0].min,  &layout[0].max, &header.size);
+
+  SCAN;
+  sscanf (buffer, "%lf %f %f %f %f", &layout[0].coords.crval1, &layout[0].coords.crpix1, &layout[0].coords.cdelt1, &layout[0].coords.pc1_1, &layout[0].coords.pc1_2);
+	  
+  SCAN;
+  sscanf (buffer, "%lf %f %f %f %f", &layout[0].coords.crval2, &layout[0].coords.crpix2, &layout[0].coords.cdelt2, &layout[0].coords.pc2_1, &layout[0].coords.pc2_2);
+	  
+  SCAN;
+  sscanf (buffer, "%s %s %s", layout[0].coords.ctype, layout[0].file, layout[0].buffer_name);
+
+  fits_create_matrix (&header, &layout[0].matrix);
+
+  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+
+  status = 1;
+  buff = layout[0].matrix.buffer;
+  bytes_left = header.size;
+  layout[0].matrix.size = 0;
+  while (bytes_left > 0) {
+    status = read (layout[0].Ximage, buff, bytes_left);
+    if (status == 0) {  /* No more pipe */
+      fprintf (stderr, "error: pipe closed\n");
+      return (FALSE);
+    }
+    if (status != -1) { /* pipe has data */
+      layout[0].matrix.size += status;
+      bytes_left -= status;
+      buff = (char *)(buff + status);
+    }
+  }
+
+  (DEBUG) && fprintf (stderr, "read %d bytes\n", layout[0].matrix.size);
+  /* it it not obvious this condition should kill kii, but ... */
+  if (layout[0].matrix.size != header.size) {  
+    fprintf (stderr, "error: expected %d bytes, but got only %d\n", header.size, layout[0].matrix.size);
+    return (FALSE);
+  }
+
+  Remap (graphic, layout, &layout[0].matrix);
+  (DEBUG) && fprintf (stderr, "remapped image\n");
+  Refresh (graphic, layout, 0);
+  
+  (DEBUG) && fprintf (stderr, "refreshed\n");
+  XFlush (graphic[0].display);
+
+  return (TRUE);
+
+}
+
+/*
+   layout[0].X = 0;
+   layout[0].Y = 0;
+   layout[0].expand = 1;
+*/
+  
Index: /trunk/Ohana/src/kii/picture/PositionPictures.c
===================================================================
--- /trunk/Ohana/src/kii/picture/PositionPictures.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/PositionPictures.c	(revision 2466)
@@ -0,0 +1,152 @@
+# include "Ximage.h" 
+# include "buttons.h"
+# define BUTTON_WIDTH 28
+# define BUTTON_HEIGHT 28
+
+void PositionPictures (Layout *layout, Graphic *graphic) {
+
+  layout[0].cmapbar.dx = graphic[0].dx - 2*PAD1; 
+  layout[0].cmapbar.dy = COLORPAD;
+  layout[0].cmapbar.x = PAD1;
+  layout[0].cmapbar.y = PAD1;
+
+  layout[0].zoom.dx = ZOOM_X; 
+  layout[0].zoom.dy = ZOOM_Y;
+  layout[0].zoom.x = graphic[0].dx - PAD1 - ZOOM_X;
+  layout[0].zoom.y = layout[0].cmapbar.y + layout[0].cmapbar.dy + PAD2;
+
+  layout[0].picture.dx = layout[0].zoom.x - 2*PAD1 - 25; 
+  layout[0].picture.dy = graphic[0].dy - 2*PAD1 - PAD2 - COLORPAD - 25;
+  layout[0].picture.x = PAD1 + 25;
+  layout[0].picture.y = PAD1 + PAD2 + COLORPAD;
+
+  /** everything below is tied in x-dir to the zoom box **/
+  layout[0].text_x = layout[0].zoom.x;
+  layout[0].text_y = layout[0].zoom.y + layout[0].zoom.dy + PAD2;
+
+  /*  layout[0].PS_button.y = graphic[0].dy - BUTTON_HEIGHT - PAD1; */
+  layout[0].PS_button.x = layout[0].zoom.x + 5;
+  layout[0].PS_button.y = 2*ZOOM_Y;
+  layout[0].PS_button.dx = BUTTON_WIDTH;
+  layout[0].PS_button.dy = BUTTON_HEIGHT;
+  layout[0].PS_button.text = FALSE;
+  layout[0].PS_button.width = PS_width;
+  layout[0].PS_button.height = PS_height;
+  layout[0].PS_button.bitmap = PS_bits;
+  layout[0].PS_button.function_1 = PSit;
+  layout[0].PS_button.function_2 = PSit;
+  layout[0].PS_button.function_3 = PSit;
+
+  /** everything below is tied to the PS_button in y-dir **/
+  layout[0].grey_button.x = layout[0].PS_button.x + layout[0].PS_button.dx + PAD1;
+  layout[0].grey_button.y = layout[0].PS_button.y;
+  layout[0].grey_button.dx = BUTTON_WIDTH;
+  layout[0].grey_button.dy = BUTTON_HEIGHT;
+  layout[0].grey_button.text = FALSE;
+  layout[0].grey_button.width = grey_width;
+  layout[0].grey_button.height = grey_height;
+  layout[0].grey_button.bitmap = grey_bits;
+  layout[0].grey_button.function_1 = greycolors;
+  layout[0].grey_button.function_2 = greycolors;
+  layout[0].grey_button.function_3 = greycolors;
+
+  layout[0].rainbow_button.x = layout[0].grey_button.x + layout[0].grey_button.dx + PAD1;
+  layout[0].rainbow_button.y = layout[0].PS_button.y;
+  layout[0].rainbow_button.dx = BUTTON_WIDTH;
+  layout[0].rainbow_button.dy = BUTTON_HEIGHT;
+  layout[0].rainbow_button.text = FALSE;
+  layout[0].rainbow_button.width = rainbow_width;
+  layout[0].rainbow_button.height = rainbow_height;
+  layout[0].rainbow_button.bitmap = rainbow_bits;
+  layout[0].rainbow_button.function_1 = rainbow;
+  layout[0].rainbow_button.function_2 = rainbow;
+  layout[0].rainbow_button.function_3 = rainbow;
+
+  layout[0].puns_button.x = layout[0].rainbow_button.x + layout[0].rainbow_button.dx + PAD1;
+  layout[0].puns_button.y = layout[0].PS_button.y;
+  layout[0].puns_button.dx = BUTTON_WIDTH;
+  layout[0].puns_button.dy = BUTTON_HEIGHT;
+  layout[0].puns_button.text = FALSE;
+  layout[0].puns_button.width = puns_width;
+  layout[0].puns_button.height = puns_height;
+  layout[0].puns_button.bitmap = puns_bits;
+  layout[0].puns_button.function_1 = puns;
+  layout[0].puns_button.function_2 = puns;
+  layout[0].puns_button.function_3 = puns;
+
+  layout[0].recenter_button.x = layout[0].puns_button.x + layout[0].puns_button.dx + PAD1;
+  layout[0].recenter_button.y = layout[0].PS_button.y;
+  layout[0].recenter_button.dx = BUTTON_WIDTH;
+  layout[0].recenter_button.dy = BUTTON_HEIGHT;
+  layout[0].recenter_button.text = FALSE;
+  layout[0].recenter_button.width = recenter_width;
+  layout[0].recenter_button.height = recenter_height;
+  layout[0].recenter_button.bitmap = recenter_bits;
+  layout[0].recenter_button.function_1 = Recenter;
+  layout[0].recenter_button.function_2 = RecenterRescale;
+  layout[0].recenter_button.function_3 = Rescale;
+
+  layout[0].overlay_button[0].x = layout[0].zoom.x + 5;
+  layout[0].overlay_button[0].y = layout[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+  layout[0].overlay_button[0].dx = BUTTON_WIDTH;
+  layout[0].overlay_button[0].dy = BUTTON_HEIGHT;
+  layout[0].overlay_button[0].text = FALSE;
+  layout[0].overlay_button[0].width = red_width;
+  layout[0].overlay_button[0].height = red_height;
+  layout[0].overlay_button[0].bitmap = red_bits;
+  layout[0].overlay_button[0].function_1 = Overlay0;
+  layout[0].overlay_button[0].function_2 = Overlay0;
+  layout[0].overlay_button[0].function_3 = Overlay0;
+		   	   
+  layout[0].overlay_button[1].x = layout[0].overlay_button[0].x + layout[0].overlay_button[0].dx + PAD1;
+  layout[0].overlay_button[1].y = layout[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+  layout[0].overlay_button[1].dx = BUTTON_WIDTH;
+  layout[0].overlay_button[1].dy = BUTTON_HEIGHT;
+  layout[0].overlay_button[1].text = FALSE;
+  layout[0].overlay_button[1].width = green_width;
+  layout[0].overlay_button[1].height = green_height;
+  layout[0].overlay_button[1].bitmap = green_bits;
+  layout[0].overlay_button[1].function_1 = Overlay1;
+  layout[0].overlay_button[1].function_2 = Overlay1;
+  layout[0].overlay_button[1].function_3 = Overlay1;
+
+  layout[0].overlay_button[2].x = layout[0].overlay_button[1].x + layout[0].overlay_button[1].dx + PAD1;
+  layout[0].overlay_button[2].y = layout[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+  layout[0].overlay_button[2].dx = BUTTON_WIDTH;
+  layout[0].overlay_button[2].dy = BUTTON_HEIGHT;
+  layout[0].overlay_button[2].text = FALSE;
+  layout[0].overlay_button[2].width = blue_width;
+  layout[0].overlay_button[2].height = blue_height;
+  layout[0].overlay_button[2].bitmap = blue_bits;
+  layout[0].overlay_button[2].function_1 = Overlay2;
+  layout[0].overlay_button[2].function_2 = Overlay2;
+  layout[0].overlay_button[2].function_3 = Overlay2;
+		   	   
+  layout[0].overlay_button[3].x = layout[0].overlay_button[2].x + layout[0].overlay_button[2].dx + PAD1;
+  layout[0].overlay_button[3].y = layout[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+  layout[0].overlay_button[3].dx = BUTTON_WIDTH;
+  layout[0].overlay_button[3].dy = BUTTON_HEIGHT;
+  layout[0].overlay_button[3].text = FALSE;
+  layout[0].overlay_button[3].width = yellow_width;
+  layout[0].overlay_button[3].height = yellow_height;
+  layout[0].overlay_button[3].bitmap = yellow_bits;
+  layout[0].overlay_button[3].function_1 = Overlay3;
+  layout[0].overlay_button[3].function_2 = Overlay3;
+  layout[0].overlay_button[3].function_3 = Overlay3;
+
+  layout[0].hms_button.x = layout[0].overlay_button[3].x + layout[0].overlay_button[3].dx + PAD1;
+  layout[0].hms_button.y = layout[0].PS_button.y - BUTTON_HEIGHT - PAD1;
+  layout[0].hms_button.dx = BUTTON_WIDTH;
+  layout[0].hms_button.dy = BUTTON_HEIGHT;
+  layout[0].hms_button.text = FALSE;
+  layout[0].hms_button.width = hms_width;
+  layout[0].hms_button.height = hms_height;
+  layout[0].hms_button.bitmap = hms_bits;
+  layout[0].hms_button.function_1 = ToggleDEG;
+  layout[0].hms_button.function_2 = ToggleDEG;
+  layout[0].hms_button.function_3 = ToggleDEG;
+
+}
+
+
+/* this routine is dependent on the number of Overlays */
Index: /trunk/Ohana/src/kii/picture/Remap.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Remap.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/Remap.c	(revision 2466)
@@ -0,0 +1,21 @@
+# include "Ximage.h"
+
+void Remap (Graphic *graphic, Layout *layout, Matrix *matrix) {
+
+  switch (graphic[0].Nbits) {
+  case 8:
+    Remap8 (graphic, layout, matrix);
+    break;
+  case 16:
+    Remap16 (graphic, layout, matrix);
+    break;
+  case 24:
+    Remap24 (graphic, layout, matrix);
+    break;
+  case 32:
+    Remap32 (graphic, layout, matrix);
+    break;
+  }
+
+}
+
Index: /trunk/Ohana/src/kii/picture/Remap16.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Remap16.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/Remap16.c	(revision 2466)
@@ -0,0 +1,152 @@
+# include "Ximage.h"
+# define FRAC(a) ((a) - (int)(a))
+
+void Remap16 (Graphic *graphic, Layout *layout, Matrix *matrix) {
+
+  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, 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];
+  unsigned char pixvalue1, pixvalue2;
+  unsigned long white;
+  unsigned char white1, white2;
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel1[i] = 0x0000ff & layout[0].cmap[i].pixel;
+    pixel2[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 8);
+    pixel3[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 16);
+  }
+  white = layout[0].white;
+  white1 = 0x00ff & white;
+  white2 = 0x00ff & (white >> 8);
+
+  if (layout[0].expand == 0) /* set up expansions */
+    layout[0].expand = 1;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+    expand_out = layout[0].expand;
+    expand_in  = 1;
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+    expand_out = 1;
+    expand_in  = -layout[0].expand;
+  }
+
+  dx = layout[0].picture.dx;
+  dy = layout[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) - layout[0].X, 0);
+  if ((int)X != X) 
+    X = (int) X + 1;
+  else 
+    X = (int) X;
+  Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
+  if ((int)Y != Y) 
+    Y = (int) Y + 1;
+  else 
+    Y = (int) Y;
+
+  /* Rx,Ry are the screen coordinates of the first image pixel */
+  Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
+  Ry = (Y + layout[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);
+  
+  if (layout[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);
+  }    
+
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  data = out_pix = (unsigned char *) layout[0].picture.data;
+  in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  /**** fill in bottom area ****/
+  for (j = 0; j < j_start; j++) {
+    for (i = 0; i < dx; i++, out_pix+=2) {
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+    }
+  }
+  
+  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; (i_start > 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] = white1;
+	out_pix2[1] = white2;
+      }
+    }
+    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) {
+	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) { 
+	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)) {
+	  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] = white1;
+	out_pix2[1] = white2;
+      }
+    }
+  } 
+  
+  /*
+  if ((j_end - j_start) % expand_out > 0)
+    out_pix -= expand_out - (j_end - j_start) % expand_out;
+  */
+  
+  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] = white1;
+      out_pix[1] = white2;
+    }
+  }
+
+  layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 16, 0);
+}
+
Index: /trunk/Ohana/src/kii/picture/Remap24.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Remap24.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/Remap24.c	(revision 2466)
@@ -0,0 +1,163 @@
+# include "Ximage.h"
+# define FRAC(a) ((a) - (int)(a))
+
+void Remap24 (Graphic *graphic, Layout *layout, Matrix *matrix) {
+
+  int i, j, ii, jj;
+  int i_start, i_end, j_start, j_end;
+  int dropback, extra;  /* this is a bit of a kludge... */
+  int dx, dy, DX, DY;
+  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];
+  unsigned char pixvalue1, pixvalue2, pixvalue3;
+  unsigned long white;
+  unsigned char white1, white2, white3;
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel1[i] = 0x0000ff & layout[0].cmap[i].pixel;
+    pixel2[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 8);
+    pixel3[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 16);
+  }
+  white = layout[0].white;
+  white1 = 0x0000ff & white;
+  white2 = 0x0000ff & (white >> 8);
+  white3 = 0x0000ff & (white >> 16);
+
+  if (layout[0].expand == 0) /* set up expansions */
+    layout[0].expand = 1;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+    expand_out = layout[0].expand;
+    expand_in  = 1;
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+    expand_out = 1;
+    expand_in  = -layout[0].expand;
+  }
+
+  dx = layout[0].picture.dx;
+  dy = layout[0].picture.dy;
+  DX = matrix[0].Naxis[0];
+  DY = matrix[0].Naxis[1];
+  extra = 4 - (dx * 3) % 4;
+
+  /* X,Y are the image coordinates of the first image pixel */
+  X = MAX(0.5*(DX - dx*expand) - layout[0].X, 0);
+  if ((int)X != X) 
+    X = (int) X + 1;
+  else 
+    X = (int) X;
+  Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
+  if ((int)Y != Y) 
+    Y = (int) Y + 1;
+  else 
+    Y = (int) Y;
+
+  /* Rx,Ry are the screen coordinates of the first image pixel */
+  Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
+  Ry = (Y + layout[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);
+  
+  if (layout[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);
+  }    
+
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  data = out_pix = (unsigned char *) layout[0].picture.data;
+  in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  /**** fill in bottom area ****/
+  for (j = 0; j < j_start; j++) {
+    for (i = 0; i < dx; i++, out_pix+=3) {
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+      out_pix[2] = white3;
+    }
+    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; (i_start > 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] = white1;
+	out_pix2[1] = white2;
+	out_pix2[2] = white3;
+      }
+    }
+    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) {
+	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) { 
+	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) {
+	  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] = white1;
+	out_pix2[1] = white2;
+	out_pix2[2] = white3;
+      }
+    }
+  } 
+  
+  /*
+  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] = white1;
+      out_pix[1] = white2;
+      out_pix[2] = white3;
+    }
+    out_pix+=extra;
+  }
+
+  layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 32, 0);
+}
+
Index: /trunk/Ohana/src/kii/picture/Remap32.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Remap32.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/Remap32.c	(revision 2466)
@@ -0,0 +1,131 @@
+# include "Ximage.h"
+# define FRAC(a) ((a) - (int)(a))
+
+void Remap32 (Graphic *graphic, Layout *layout, Matrix *matrix) {
+
+  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, Rx, Ry, X, Y;
+  int expand_in, expand_out;
+  unsigned int *out_pix, *out_pix2;
+  unsigned char *in_pix,  *in_pix2;
+  unsigned long pixel[256], pixvalue;
+  unsigned long white;
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel[i] = layout[0].cmap[i].pixel;
+  }
+  white = layout[0].white;
+
+  if (layout[0].expand == 0) /* set up expansions */
+    layout[0].expand = 1;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+    expand_out = layout[0].expand;
+    expand_in  = 1;
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+    expand_out = 1;
+    expand_in  = -layout[0].expand;
+  }
+
+  dx = layout[0].picture.dx;
+  dy = layout[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) - layout[0].X, 0);
+  if ((int)X != X) 
+    X = (int) X + 1;
+  else 
+    X = (int) X;
+  Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
+  if ((int)Y != Y) 
+    Y = (int) Y + 1;
+  else 
+    Y = (int) Y;
+
+  /* Rx,Ry are the screen coordinates of the first image pixel */
+  Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
+  Ry = (Y + layout[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);
+  
+  if (layout[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);
+  }    
+
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  out_pix = (unsigned int *) layout[0].picture.data;
+  in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  /**** fill in bottom area ****/
+  for (j = 0; j < dx*j_start; j++, out_pix++) 
+    *out_pix = white;
+  
+  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 = white;
+      }
+    }
+    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];
+      }
+      /* *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];
+	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 = white;
+      }
+    }
+    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 int *)layout[0].picture.data < dx*dy); j++, out_pix++) { 
+    *out_pix = white;
+  }
+  layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 32, 0);
+}
+
Index: /trunk/Ohana/src/kii/picture/Remap8.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Remap8.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/Remap8.c	(revision 2466)
@@ -0,0 +1,131 @@
+# include "Ximage.h"
+# define FRAC(a) ((a) - (int)(a))
+
+void Remap8 (Graphic *graphic, Layout *layout, Matrix *matrix) {
+
+  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, Rx, Ry, X, Y;
+  int expand_in, expand_out;
+  unsigned char *out_pix, *out_pix2;
+  unsigned char *in_pix,  *in_pix2;
+  unsigned long pixel[256], pixvalue;
+  unsigned long white;
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel[i] = layout[0].cmap[i].pixel;
+  }
+  white = layout[0].white;
+
+  if (layout[0].expand == 0) /* set up expansions */
+    layout[0].expand = 1;
+  if (layout[0].expand > 0) {
+    expand = 1 / (1.0*layout[0].expand);
+    expand_out = layout[0].expand;
+    expand_in  = 1;
+  }
+  if (layout[0].expand < 0) {
+    expand = fabs((double)layout[0].expand);
+    expand_out = 1;
+    expand_in  = -layout[0].expand;
+  }
+
+  dx = layout[0].picture.dx;
+  dy = layout[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) - layout[0].X, 0);
+  if ((int)X != X) 
+    X = (int) X + 1;
+  else 
+    X = (int) X;
+  Y = MAX(0.5*(DY - dy*expand) - layout[0].Y, 0);
+  if ((int)Y != Y) 
+    Y = (int) Y + 1;
+  else 
+    Y = (int) Y;
+
+  /* Rx,Ry are the screen coordinates of the first image pixel */
+  Rx = (X + layout[0].X - 0.5*DX)/expand + 0.5*dx;
+  Ry = (Y + layout[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);
+  
+  if (layout[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);
+  }    
+
+  dropback = expand_out - (i_end - i_start) % expand_out;
+  if ((i_end - i_start) % expand_out == 0) dropback = 0;
+
+  out_pix = layout[0].picture.data;
+  in_pix  = (unsigned char *) (matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  /**** fill in bottom area ****/
+  for (j = 0; j < dx*j_start; j++, out_pix++) 
+    *out_pix = white;
+  
+  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 = white;
+      }
+    }
+    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];
+      }
+      /* *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];
+	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 = white;
+      }
+    }
+    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 *)layout[0].picture.data < dx*dy); j++, out_pix++) { 
+    *out_pix = white;
+  }
+  layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].picture.data, layout[0].picture.dx, layout[0].picture.dy, 8, 0);
+}
+
Index: /trunk/Ohana/src/kii/picture/Reorient.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Reorient.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/Reorient.c	(revision 2466)
@@ -0,0 +1,65 @@
+# include "Ximage.h"
+
+void Reorient (Graphic *graphic, Layout *layout, XButtonEvent *mouse_event) {
+
+  int x, y, dummy2;
+  double X0, Y0;
+  unsigned int dummy3;
+  Window dummy1;
+
+  if (layout[0].expand == 0)
+    layout[0].expand = 1;
+
+  Screen_to_Image (&X0, &Y0, (double)mouse_event[0].x, (double)mouse_event[0].y, layout);
+  X0 = 0.5*layout[0].matrix.Naxis[0] - X0;
+  Y0 = 0.5*layout[0].matrix.Naxis[1] - Y0;
+
+  switch (mouse_event[0].button) {
+  case 1:
+    if ((layout[0].X != X0) || (layout[0].Y != Y0)) {
+      layout[0].X = X0;
+      layout[0].Y = Y0;
+    }
+    break;
+  case 2: 
+    layout[0].expand--;
+    if ((layout[0].expand == 0) || (layout[0].expand == -1))
+      layout[0].expand = -2;
+    if (layout[0].expand < -30) {
+      fprintf (stderr, "can't get smaller!\n");
+      layout[0].expand = -30;
+      return;
+    }
+    layout[0].X = X0;
+    layout[0].Y = Y0;
+    break;
+  case 3:
+    layout[0].expand++;
+    if ((layout[0].expand == 0) || (layout[0].expand == -1))
+      layout[0].expand = 1;
+    if (layout[0].expand > 30) {
+      fprintf (stderr, "can't get bigger!\n");
+      layout[0].expand = 30;
+      return;
+    }
+    layout[0].X = X0;
+    layout[0].Y = Y0;
+    break;
+  }
+
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+ 
+# ifndef NOWARP  /* 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 > layout[0].picture.x) && (x < layout[0].picture.x + layout[0].picture.dx) &&
+      (y > layout[0].picture.y) && (y < layout[0].picture.y + layout[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, 
+		  layout[0].picture.x + 0.5*layout[0].picture.dx,
+		  layout[0].picture.y + 0.5*layout[0].picture.dy);
+  }
+# endif
+
+  XFlush (graphic[0].display);
+}
Index: /trunk/Ohana/src/kii/picture/Rescale.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Rescale.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/Rescale.c	(revision 2466)
@@ -0,0 +1,16 @@
+# include "Ximage.h"
+
+void
+Rescale (graphic, layout)
+Graphic graphic[];
+Layout  layout[];
+{
+
+  fprintf (stdout, "enter new zero, range: ");
+  fscanf (stdin, "%lf%lf", &layout[0].zero, &layout[0].range);
+
+  Remap (graphic, layout, &layout[0].matrix);
+  Refresh (graphic, layout, 0);
+  
+  XFlush (graphic[0].display);
+}
Index: /trunk/Ohana/src/kii/picture/Resize.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Resize.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/Resize.c	(revision 2466)
@@ -0,0 +1,42 @@
+# include "Ximage.h"
+# define SCAN \
+  status = read (layout[0].Ximage, buffer, 16); \
+  buffer[16] = 0; \
+  sscanf (buffer, "%*s %d", &Nbytes); \
+  status = read (layout[0].Ximage, buffer, Nbytes); \
+  buffer[status] = 0; /* make the string easy to parse */ \
+  (DEBUG) && fprintf (stderr, "buffer: <%s>\n", buffer); \
+
+
+int Resize (Graphic *graphic, Layout *layout) {
+ 
+  int status, Nbytes;
+  unsigned int NX, NY;
+  char buffer[128];
+
+  SCAN;
+  sscanf (buffer, "%d %d", &NX, &NY);
+
+  NX += ZOOM_X + 3*PAD1 + 25;
+  NY += 2*PAD1 + PAD2 + COLORPAD + 25;
+
+  if ((graphic[0].dx == NX) && (graphic[0].dy == NY)) 
+    return (TRUE);
+
+  /*  graphic[0].dx = MAX(NX,  MIN_WIDTH); 
+  graphic[0].dy = MAX(NY, MIN_HEIGHT); */
+  graphic[0].dx = MAX(NX, 50); 
+  graphic[0].dy = MAX(NY, 50); 
+
+  XResizeWindow (graphic[0].display, graphic[0].window, NX, NY);
+
+  PositionPictures (layout, graphic);
+  CreateColorbar (layout, graphic);
+  CreatePicture (layout, graphic);
+  Remap (graphic, layout, &layout[0].matrix); 
+
+  XClearWindow (graphic[0].display, graphic[0].window);
+  Refresh (graphic, layout, 1);
+
+  return (TRUE);
+}
Index: /trunk/Ohana/src/kii/picture/StatusBox.c
===================================================================
--- /trunk/Ohana/src/kii/picture/StatusBox.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/StatusBox.c	(revision 2466)
@@ -0,0 +1,27 @@
+# include "Ximage.h"
+
+void
+StatusBox (graphic, layout)
+Graphic        graphic[];
+Layout         layout[];
+{
+
+  double  x, y, z;
+
+  if (MOVE_POINTER) {
+    x = 0.5*layout[0].matrix.Naxis[0];
+    y = 0.5*layout[0].matrix.Naxis[1];
+    z = -1;
+    layout[0].x = x;
+    layout[0].y = y;
+    layout[0].z = z;
+  }
+  else {
+    x = layout[0].x;
+    y = layout[0].y;
+    z = layout[0].z;
+  }
+  
+  UpdateStatusBox (graphic, layout, x, y, z, 1);
+  
+}
Index: /trunk/Ohana/src/kii/picture/TestPicture.c
===================================================================
--- /trunk/Ohana/src/kii/picture/TestPicture.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/TestPicture.c	(revision 2466)
@@ -0,0 +1,59 @@
+# include "Ximage.h"
+
+int 
+TestPicture (graphic, layout)
+     Graphic graphic[];
+     Layout  layout[];
+{
+
+  Header header;
+  char buffer[1024], *buff;
+  int status, bytes_left, Nbytes, i, j;
+  double frac;
+
+  fits_free_matrix (&layout[0].matrix);
+
+  header.Naxes = 2;
+  header.Naxis[0] = 512;
+  header.Naxis[1] = 512;
+  header.bitpix = 8;
+  header.unsign = 0;
+  header.bzero = 0;
+  header.bscale = 1;
+
+  layout[0].zero = 0;
+  layout[0].range = layout[0].Npixels;
+  layout[0].min = 0; 
+  layout[0].max = layout[0].Npixels;
+  
+  fits_create_matrix (&header, &layout[0].matrix);
+
+  frac = layout[0].Npixels / (512.0*512.0);
+  buff = layout[0].matrix.buffer;
+  for (i = 0; i < 512; i++) {
+    for (j = 0; j < 512; j++, buff++) {
+      *buff = (int)(i*j*frac);
+    }
+  }
+
+/*
+  Remap (layout, &layout[0].matrix);
+  layout[0].picture.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].picture.data, 
+					layout[0].picture.dx, layout[0].picture.dy, 8, 0);
+
+  (DEBUG) && fprintf (stderr, "remapped image\n", layout[0].matrix.size);
+  Refresh (graphic, layout);
+  
+  (DEBUG) && fprintf (stderr, "refreshed\n", layout[0].matrix.size);
+  XFlush (graphic[0].display);
+*/
+}
+
+
+/*
+   layout[0].X = 0;
+   layout[0].Y = 0;
+   layout[0].expand = 1;
+*/
+  
Index: /trunk/Ohana/src/kii/picture/cursor.c
===================================================================
--- /trunk/Ohana/src/kii/picture/cursor.c	(revision 2466)
+++ /trunk/Ohana/src/kii/picture/cursor.c	(revision 2466)
@@ -0,0 +1,86 @@
+# include "Ximage.h"
+
+int cursor (Graphic *graphic, Layout *layout) {
+
+  XEvent          event;
+  KeySym          keysym;
+  int             status, xstatus, value;
+  XComposeStatus  composestatus;
+  char            string[10], line[500];
+  double          x, y;
+  char            buffer[1024];
+  
+  while (1) {
+    
+    status = read (layout[0].Ximage, buffer, 4);
+    buffer[4] = 0;
+    
+    switch (status) {
+    case -1:
+      /* no input from pipe: continue */
+      break;
+      
+    case 0:
+      fprintf (stderr, "pipe has died!\n");
+      return (FALSE);
+      break;
+
+    case 4:
+      if (!strcmp (buffer, "NCUR")) {  /* stop reading cursor */
+	return (TRUE);
+      }
+      break;
+
+    default:
+      fprintf (stderr, "weird signal: too many or few bytes!  %d\n", status);
+      return (TRUE);
+      break;
+    }
+
+    if ((xstatus = XCheckMaskEvent (graphic[0].display, EVENT_MASK, &event))) {
+      
+      switch (event.type)  {
+	
+      case ButtonPress:
+	status = InterpretPresses (graphic, layout, (XButtonEvent *) &event);
+	break;
+	
+      case Expose:
+	if (event.xexpose.count == 0)
+	  Refresh (graphic, layout, 1);
+	break;
+	
+      case ConfigureNotify:
+	status =  Reconfig (graphic, layout, &event);
+	break;
+	
+      case MappingNotify:
+	XRefreshKeyboardMapping ((XMappingEvent *) &event);
+	break;
+	
+      case MotionNotify:
+	if (XPending (graphic[0].display) < 2) {
+	  UpdatePointer (graphic, layout, (XMotionEvent *) &event);
+	}
+	break;
+
+      case KeyPress:
+	value = XLookupString ((XKeyEvent *) &event, string, 9, &keysym, &composestatus);
+
+	if ((event.xkey.x >= layout[0].picture.x) && (event.xkey.x <= layout[0].picture.x + layout[0].picture.dx) &&
+	    (event.xkey.y >= layout[0].picture.y) && (event.xkey.y <= layout[0].picture.y + layout[0].picture.dy)) {
+
+	  Screen_to_Image (&x, &y, (double)event.xkey.x, (double)event.xkey.y, layout);
+
+	  if (isprint(string[0]))
+	    sprintf (line, "%c %6.1f %6.1f ", string[0], x, y);
+	  else {
+	    sprintf (line, "X %6.1f %6.1f ", x, y);
+	    break;
+	  }
+	  write (layout[0].Ximage, line, 16);
+	}
+      }
+    }
+  }
+}
Index: /trunk/Ohana/src/kii/scrollbar/DownArrow.c
===================================================================
--- /trunk/Ohana/src/kii/scrollbar/DownArrow.c	(revision 2466)
+++ /trunk/Ohana/src/kii/scrollbar/DownArrow.c	(revision 2466)
@@ -0,0 +1,20 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int 
+DownArrow (button_event, height, width, SB_x, SB_y)
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+{
+
+  int answer, m_x, m_y;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_y > (height - SB_y)) && 
+	    (m_x > (width - SB_y)));
+    return (answer);
+
+}
+
+
Index: /trunk/Ohana/src/kii/scrollbar/LeftArrow.c
===================================================================
--- /trunk/Ohana/src/kii/scrollbar/LeftArrow.c	(revision 2466)
+++ /trunk/Ohana/src/kii/scrollbar/LeftArrow.c	(revision 2466)
@@ -0,0 +1,18 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int
+LeftArrow (button_event, height, width, SB_x, SB_y) 
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+{
+
+  int answer, m_x, m_y;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_x < SB_x) && (m_y < SB_x));
+  return (answer);
+
+}
+
Index: /trunk/Ohana/src/kii/scrollbar/RightArrow.c
===================================================================
--- /trunk/Ohana/src/kii/scrollbar/RightArrow.c	(revision 2466)
+++ /trunk/Ohana/src/kii/scrollbar/RightArrow.c	(revision 2466)
@@ -0,0 +1,20 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int
+RightArrow (button_event, height, width, SB_x, SB_y) 
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+{
+
+  int answer, m_x, m_y;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_x < SB_x) && 
+	    (m_y > (height - SB_x - SB_y)) && 
+	    (m_y < (height - SB_y)));
+  return (answer);
+
+}
+
Index: /trunk/Ohana/src/kii/scrollbar/ScrollBars.c
===================================================================
--- /trunk/Ohana/src/kii/scrollbar/ScrollBars.c	(revision 2466)
+++ /trunk/Ohana/src/kii/scrollbar/ScrollBars.c	(revision 2466)
@@ -0,0 +1,38 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+void
+ScrollBars (display, window, gc, height, width, SB_x, SB_y, f_x, f_y)
+Display *display;
+Window window;
+GC gc;
+int width, height, SB_x, SB_y;
+double f_x, f_y;
+{
+  
+  int x, y;
+
+  y = height - SB_y;
+  XDrawLine (display, window, gc, 0, y, width, y);
+  XDrawLine (display, window, gc, SB_x, 0, SB_x, height);
+  XDrawLine (display, window, gc, 0, SB_x, SB_x, SB_x);
+  x = width - SB_y;
+  y = height - SB_y;
+  XDrawLine (display, window, gc, x, y, x, height);
+  y = height - SB_x - SB_y;
+  XDrawLine (display, window, gc, 0, y, SB_x, y);
+  x = SB_y + SB_x;
+  y = height - SB_y;
+  XDrawLine (display, window, gc, x, y, x, height);
+  x = (width - 2*SB_y - SB_x) * f_x + SB_x + SB_y;
+  y = (height - 2*SB_x - SB_y) * f_y + SB_x;
+  XDrawLine (display, window, gc, x, height - SB_y, x, height);
+  XDrawLine (display, window, gc, x + 1, height - SB_y, x + 1, height);
+  XDrawLine (display, window, gc, 0, y, SB_x, y);
+  XDrawLine (display, window, gc, 0, y+1, SB_x, y+1);
+  y = height - SB_y;
+  XFillRectangle (display, window, gc, 0, y, SB_x, SB_y);
+
+}
+
+
Index: /trunk/Ohana/src/kii/scrollbar/UpArrow.c
===================================================================
--- /trunk/Ohana/src/kii/scrollbar/UpArrow.c	(revision 2466)
+++ /trunk/Ohana/src/kii/scrollbar/UpArrow.c	(revision 2466)
@@ -0,0 +1,20 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int
+UpArrow (button_event, height, width, SB_x, SB_y) 
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+{
+
+  int answer, m_x, m_y;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_y > (height - SB_y)) && 
+	    (m_x > SB_x) && 
+	    (m_x < (SB_x + SB_y)));
+  return (answer);
+
+}
+
Index: /trunk/Ohana/src/kii/scrollbar/xScrollBar.c
===================================================================
--- /trunk/Ohana/src/kii/scrollbar/xScrollBar.c	(revision 2466)
+++ /trunk/Ohana/src/kii/scrollbar/xScrollBar.c	(revision 2466)
@@ -0,0 +1,26 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int 
+xScrollBar (button_event, height, width, SB_x, SB_y, f)
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+double *f;
+{
+
+  int answer, m_x, m_y;
+  double f1, f2;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_x < SB_x) && 
+	    (m_y > SB_x) && 
+	    (m_y < (height - SB_x - SB_y)));
+  f1 = (double)(m_y - SB_x);
+  f2 = (double)(height - 2*SB_x - SB_y);
+  *f = f1 / f2;
+  return (answer);
+
+}
+
+
Index: /trunk/Ohana/src/kii/scrollbar/yScrollBar.c
===================================================================
--- /trunk/Ohana/src/kii/scrollbar/yScrollBar.c	(revision 2466)
+++ /trunk/Ohana/src/kii/scrollbar/yScrollBar.c	(revision 2466)
@@ -0,0 +1,26 @@
+# include "Ximage"
+# include "ScrollBars.h"
+
+int
+yScrollBar (button_event, height, width, SB_x, SB_y, f)
+XButtonEvent *button_event;
+int height, width, SB_x, SB_y;
+double *f;
+{
+
+  int answer, m_x, m_y;
+  double f1, f2;
+
+  m_x = button_event -> x;
+  m_y = button_event -> y;
+  answer = ((m_y > (height - SB_y)) && 
+	    (m_x > (SB_x + SB_y)) && 
+	    (m_x < (width - SB_y)));
+  f1 = (double)(m_x - SB_x - SB_y);
+  f2 = (double)(width - 2*SB_y - SB_x);
+  *f = f1 / f2;
+  return (answer);
+
+}
+
+	
Index: /trunk/Ohana/src/kii/setup/CheckColors.c
===================================================================
--- /trunk/Ohana/src/kii/setup/CheckColors.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/CheckColors.c	(revision 2466)
@@ -0,0 +1,40 @@
+# include "Ximage.h"
+
+/************** CheckColors *************/
+void CheckColors (Graphic *graphic, int *argc, char **argv) {
+
+  char *temp_name;
+  int N;
+
+  /* here we define the values for "black" (blackground) and "white" (whiteground)
+     if -fg, or -bg exist, or if Foreground or Background are set in .Xdefaults, 
+     use those.  blackground defaults to Black, whiteground defaults to White. */
+
+  graphic[0].black = BlackPixel (graphic[0].display, graphic[0].screen);
+  temp_name = XGetDefault (graphic[0].display, argv[0], "Foreground");
+  if ((N = get_argument (*argc, argv, "-fg"))) {
+    if (N + 1 < *argc) {
+      temp_name = argv[N+1];
+    } else {
+      fprintf (stderr, "error: usage is -fg color\n");
+      exit (0);
+    }
+  }
+  if (temp_name != (char *)NULL) 
+    graphic[0].black = GetColor (graphic[0].display, temp_name, graphic[0].colormap, graphic[0].black);
+
+  graphic[0].white = WhitePixel (graphic[0].display, graphic[0].screen);
+  temp_name = XGetDefault (graphic[0].display, argv[0], "Background");
+  if ((N = get_argument (*argc, argv, "-bg"))) {
+    if (N + 1 < *argc) {
+      temp_name = argv[N+1];
+    } else {
+      fprintf (stderr, "error: usage is -bg color\n");
+      exit (0);
+    }
+  }  
+  if (temp_name != (char *)NULL) 
+    graphic[0].white = GetColor (graphic[0].display, temp_name, graphic[0].colormap, graphic[0].white);
+ 
+}
+
Index: /trunk/Ohana/src/kii/setup/CheckDisplayName.c
===================================================================
--- /trunk/Ohana/src/kii/setup/CheckDisplayName.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/CheckDisplayName.c	(revision 2466)
@@ -0,0 +1,30 @@
+# include "Ximage.h"
+
+/************** CheckDisplayName *************/
+void CheckDisplayName (int *argc, char **argv, char *display_name) {
+
+  int N;
+
+  display_name[0] = 0;
+  if ((N = get_argument (*argc, argv, "-d"))) {
+    if (N + 1 < *argc) {
+      strcpy (display_name, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is [-display/-d] DisplayName\n");
+      exit (0);
+    }
+  }
+  if ((N = get_argument (*argc, argv, "-display"))) {
+    if (N + 1 < *argc) {
+      strcpy (display_name, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is [-display/-d] DisplayName\n");
+      exit (0);
+    }
+  }
+}
+
Index: /trunk/Ohana/src/kii/setup/CheckFontName.c
===================================================================
--- /trunk/Ohana/src/kii/setup/CheckFontName.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/CheckFontName.c	(revision 2466)
@@ -0,0 +1,29 @@
+# include "Ximage.h"
+
+/************** CheckFontName *************/
+void CheckFontName (int *argc, char **argv, char *fontname) {
+
+  int N;
+
+  if ((N = get_argument (*argc, argv, "-font"))) {
+    if (N + 1 < *argc) {
+      strcpy (fontname, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is -font fontname\n");
+      exit (0);
+    }
+  }   
+  if ((N = get_argument (*argc, argv, "-fn"))) {
+    if (N + 1 < *argc) {
+      strcpy (fontname, argv[N + 1]);
+      remove_argument(N, argc, argv);
+      remove_argument(N, argc, argv);
+    } else {
+      fprintf (stderr, "error: usage is -fn fontname\n");
+      exit (0);
+    }
+  }   
+}
+
Index: /trunk/Ohana/src/kii/setup/CheckGeometry.c
===================================================================
--- /trunk/Ohana/src/kii/setup/CheckGeometry.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/CheckGeometry.c	(revision 2466)
@@ -0,0 +1,50 @@
+# include "Ximage.h"
+
+/************** CheckGeometry *************/
+void CheckGeometry (int *argc, char **argv, Graphic *graphic) {
+
+  int status, x, y, N;
+  unsigned int dx, dy;
+  int X, Y, dX, dY;
+  char *temp_name;
+  
+  temp_name = XGetDefault (graphic[0].display, argv[0], "geometry");
+  if ((N = get_argument (*argc, argv, "-geom"))) {
+    if (N + 1 < *argc) {
+      temp_name = argv[N+1];
+    }
+    else {
+      fprintf (stderr, "error: usage is -geom DisplayName\n");
+      exit (0);
+    }
+  }
+  X = 10;
+  Y = 10;
+  dX = 512 + 2*PAD1 + PAD1 + ZOOM_X;
+  dY = 512 + 2*PAD1 + PAD2 + COLORPAD;
+  if (temp_name != (char *)NULL) {  
+    status = XParseGeometry (temp_name, &x, &y, &dx, &dy);
+    if (status & XValue)
+      X = x;
+    if (status & YValue)
+      Y = y;
+    if (status & WidthValue) {
+      dX = dx + 2*PAD1 + PAD1 + ZOOM_X;
+      dX = MAX (dX, MIN_WIDTH);
+    }
+    if (status & HeightValue) {
+      dY = dy + 2*PAD1 + PAD2 + COLORPAD + 42;
+      dY = MAX (dY, MIN_HEIGHT);
+    }
+    if (status & XNegative)
+      X  = DisplayWidth  (graphic[0].display, graphic[0].screen) - dX + X;
+    if (status & YNegative)
+      Y  = DisplayHeight (graphic[0].display, graphic[0].screen) - dY + Y;
+  }
+
+  graphic[0].x = X;
+  graphic[0].y = Y;
+  graphic[0].dx = dX;
+  graphic[0].dy = dY; 
+  
+}
Index: /trunk/Ohana/src/kii/setup/CheckVisual.c
===================================================================
--- /trunk/Ohana/src/kii/setup/CheckVisual.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/CheckVisual.c	(revision 2466)
@@ -0,0 +1,199 @@
+# include "Ximage.h"
+# define NPIXELS 64
+# define DEBUG 1
+
+/* 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}; */
+
+void CheckVisual (Graphic *graphic, int *argc, char **argv) {
+
+  int i, Nfound, N;
+  int col, def, dyn;
+  XVisualInfo *visual_list, visual_temp;
+  unsigned long planes[3];
+  XPixmapFormatValues *pixmaps;
+  int Npixmaps;
+
+  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, &Nfound);
+  if (Nfound == 0) {
+    fprintf (stderr, "error finding useful visual\n");
+    exit (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);
+  }
+
+  col = def = dyn = FALSE;
+  if (DEBUG) fprintf (stderr, "default visual class is %d\n", visual_list[i].class);
+  switch (visual_list[i].class) {
+  case PseudoColor:
+    col = def = dyn = TRUE;
+    graphic[0].visual = visual_list[i].visual;
+    graphic[0].visualclass = TRUE;
+    goto test_pixels;
+    break;
+  default:
+    break;
+  }
+
+  for (i = 0; i < Nfound; i++) {
+    switch (visual_list[i].class) {
+    case PseudoColor:
+      if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
+      col = dyn = TRUE;
+      if (graphic[0].visual == visual_list[i].visual) {
+	def = TRUE;
+      } else {
+	graphic[0].visual = visual_list[i].visual;
+      }
+      graphic[0].visualclass = TRUE;
+      goto test_pixels;
+      break;
+    default:
+      break;
+    }
+  }
+
+  for (i = 0; i < Nfound; i++) {
+    switch (visual_list[i].class) {
+    case GrayScale:
+      if (DEBUG) fprintf (stderr, "selected visual class is %d\n", visual_list[i].class);
+      dyn = TRUE;
+      if (graphic[0].visual == visual_list[i].visual) {
+	def = TRUE;
+      } else {
+	graphic[0].visual = visual_list[i].visual;
+      }
+      graphic[0].visualclass = TRUE;
+      goto test_pixels;
+      break;
+    default:
+      break;
+    }
+  }
+
+  for (i = 0; (i < Nfound) && (visual_list[i].class != TrueColor); i++);
+  if (i != Nfound) {
+    col = TRUE;
+    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
+    if (graphic[0].visual == visual_list[i].visual) {
+      def = TRUE;
+    } else {
+      graphic[0].visual = visual_list[i].visual;
+    }
+    graphic[0].visualclass = FALSE;
+    goto test_pixels;
+  }
+
+  for (i = 0; (i < Nfound) && (visual_list[i].class != StaticColor); i++);
+  if (i != Nfound) {
+    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
+    if (graphic[0].visual == visual_list[i].visual) {
+      def = TRUE;
+    } else {
+      graphic[0].visual = visual_list[i].visual;
+    }
+    graphic[0].visualclass = FALSE;
+    goto test_pixels;
+  }
+
+  for (i = 0; (i < Nfound) && (visual_list[i].class != StaticGray); i++);
+  if (i != Nfound) {
+    if (DEBUG) fprintf (stderr, "visual class is %d\n", visual_list[i].class);
+    if (graphic[0].visual == visual_list[i].visual) {
+      def = TRUE;
+    } else {
+      graphic[0].visual = visual_list[i].visual;
+    }
+    graphic[0].visualclass = FALSE;
+    goto test_pixels;
+  }
+
+  test_pixels:
+
+  /* need to make a colormap if 
+     1) the selected visual is not 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) */
+
+  if ((N = get_argument (*argc, argv, "-private"))) {
+    remove_argument(N, argc, argv);
+    def = FALSE;
+  } 
+
+  if (!def) {
+    graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
+  }
+
+  if (dyn) {
+    /* allocate color cells  */
+    for (graphic[0].Npixels = NPIXELS;
+	 ((graphic[0].Npixels >= 16) && 
+	  !XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 1, graphic[0].pixels, graphic[0].Npixels));
+	 graphic[0].Npixels -= 4) {
+      if (DEBUG) fprintf (stderr, "trying %d colors\n", (int) graphic[0].Npixels);
+    }
+
+
+    /* make private colormap  */
+    if (graphic[0].Npixels < 16) {
+      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);
+      for (graphic[0].Npixels = NPIXELS;
+	   ((graphic[0].Npixels >= 16) && 
+	    !XAllocColorCells (graphic[0].display, graphic[0].colormap, FALSE, planes, 1, graphic[0].pixels, graphic[0].Npixels));
+	   graphic[0].Npixels -= 4);
+
+      if ((N = get_argument (*argc, argv, "-colorcount"))) {
+	fprintf (stderr, "kii can grab %d colors\n", (int) graphic[0].Npixels);
+	exit (0);
+      } 
+      if (graphic[0].Npixels < 16) {
+	fprintf (stderr, "can't even allocate enough cells in private colormap\n");
+	exit (0);
+      }
+    }
+  }
+
+  if (!dyn) {
+    graphic[0].Npixels = 256;
+    fprintf (stderr, "can't use dynamic colors, color scrollbar inactive\n");
+    fprintf (stderr, " this can be avoided by using a dynamic visual class\n");
+    fprintf (stderr, " (see Kii help page for details)\n");
+  }
+
+  if ((N = get_argument (*argc, argv, "-colorcount"))) {
+    fprintf (stderr, "kii can grab %d colors\n", (int) 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/kii/setup/CloseDisplay.c
===================================================================
--- /trunk/Ohana/src/kii/setup/CloseDisplay.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/CloseDisplay.c	(revision 2466)
@@ -0,0 +1,14 @@
+# include "Ximage.h"
+
+/************** CloseDisplay *************/
+void
+CloseDisplay (graphic)
+Graphic *graphic;
+{
+  XFreeGC (graphic[0].display, graphic[0].gc);
+  XDestroySubwindows (graphic[0].display, graphic[0].window);
+  XDestroyWindow (graphic[0].display, graphic[0].window);
+  XFlush (graphic[0].display);
+  XCloseDisplay (graphic[0].display);
+}
+
Index: /trunk/Ohana/src/kii/setup/CreateWindow.c
===================================================================
--- /trunk/Ohana/src/kii/setup/CreateWindow.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/CreateWindow.c	(revision 2466)
@@ -0,0 +1,33 @@
+# include "Ximage.h"
+
+/************** CreateWindow *************/
+void
+CreateWindow (graphic, parent, border, events)
+Graphic       graphic[];
+Window        parent;
+int           border;
+long          events;
+{
+
+  XSetWindowAttributes attributes;
+  unsigned long attribute_mask;
+
+  attributes.background_pixel = graphic[0].white;
+  attributes.border_pixel     = graphic[0].black;
+  attributes.event_mask       = events;
+  attributes.colormap         = graphic[0].colormap;
+  attribute_mask              = CWBackPixel | CWBorderPixel | CWEventMask | CWColormap;
+
+  graphic[0].window = XCreateWindow (graphic[0].display, parent, 
+				     graphic[0].x, graphic[0].y, 
+				     graphic[0].dx, graphic[0].dy, 
+				     border, graphic[0].depth,
+				     InputOutput, graphic[0].visual, 
+				     attribute_mask, &attributes);
+
+  if (graphic[0].window == (Window) None)
+    QuitX (graphic[0].display, "", "error: could not open window");
+
+  XSelectInput (graphic[0].display, graphic[0].window, events);
+}
+
Index: /trunk/Ohana/src/kii/setup/DefineLayout.c
===================================================================
--- /trunk/Ohana/src/kii/setup/DefineLayout.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/DefineLayout.c	(revision 2466)
@@ -0,0 +1,69 @@
+# include "Ximage.h"
+
+void DefineLayout (Layout *layout, Graphic *graphic, int argc, char **argv) {
+
+  int i, status, N;
+  struct sockaddr_un Address;
+  char temp[100];
+
+  DEBUG = FALSE;
+  if ((N = get_argument (argc, argv, "-debug"))) {
+    remove_argument(N, &argc, argv);
+    DEBUG = TRUE;
+  }
+
+  /** initiate connection with mana **/
+  if (!DEBUG) {	
+    if (argc < 2) {
+      fprintf (stderr, "socket path not specified\n");
+      exit (0);
+    }
+    strcpy (Address.sun_path, argv[1]);
+    Address.sun_family = AF_UNIX;
+    layout[0].Ximage = socket (AF_UNIX, SOCK_STREAM, 0);
+    status = connect (layout[0].Ximage, (struct sockaddr *) &Address, (socklen_t) sizeof (Address));
+    if (status < 0) {
+      fprintf (stderr, "kii - unsuccessful connection: %d\n", status);
+      exit (0);
+    }
+    fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+    sprintf (temp, "rm -f %s", argv[1]);
+    system (temp);
+  }
+
+  PositionPictures (layout, graphic);
+  
+  /* get the display colors */
+  MakeColormap (graphic, layout, argc, argv);
+
+  /** set up a bunch of default things **/
+  layout[0].X = layout[0].Y = 0;
+  layout[0].expand = 1;
+  layout[0].zero = 0;
+  layout[0].range = 1;
+  layout[0].coords.Npolyterms = 0;
+  for (i = 0; i < NOVERLAYS; i++) {
+    layout[0].overlay[i].Nobjects = 0;
+    ALLOCATE (layout[0].overlay[i].objects, Object, 1);  /* allocate so later free will not crash! */
+    OVERLAY[i] = FALSE;
+  }
+  layout[0].matrix.size = 0; /* a flag to show there is no data in the matrix */
+
+  MOVE_POINTER = TRUE;
+  DECIMAL_DEG  = TRUE;
+  ALLOCATE (layout[0].matrix.buffer, char, 1);  /* allocate so later free will not crash! */
+  ALLOCATE (layout[0].picture.data, char, 1);   /* allocate so later free will not crash! */
+  ALLOCATE (layout[0].cmapbar.data, char, 1);   /* allocate so later free will not crash! */
+  ALLOCATE (layout[0].zoom.data, char, 1);      /* allocate so later free will not crash! */
+
+  CreatePicture (layout, graphic);
+  CreateColorbar (layout, graphic);
+  CreateZoom (layout, graphic, 0, 0); 
+}
+
+
+/* this routine is independent of the number of overlays */
+
+  /* cmap = the mapping of value to color in kii
+     colormap = the set of pixel -> color representation in X */
+
Index: /trunk/Ohana/src/kii/setup/DrawBitmap.c
===================================================================
--- /trunk/Ohana/src/kii/setup/DrawBitmap.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/DrawBitmap.c	(revision 2466)
@@ -0,0 +1,49 @@
+# include "Ximage.h"
+
+void
+DrawBitmap (graphic, x, y, dx, dy, bitmap, mode)
+Graphic     graphic[];
+int         x, y, dx, dy;
+char        bitmap[];
+int         mode;
+{
+
+  int i, j, byte_line, byte, bit, flag;
+  unsigned long int black, white;
+
+  if (mode == 0) {
+    black = graphic[0].black;
+    white = graphic[0].white;
+    graphic[0].black = white;
+    graphic[0].white = white;
+  }
+    
+  if (mode == 2) {
+    black = graphic[0].black;
+    white = graphic[0].white;
+    graphic[0].black = white;
+    graphic[0].white = black;
+  }
+    
+  
+  byte_line = (int) ((dx + 7) / 8);
+  for (i = 0; i < dy; i++) {
+    for (j = 0; j < dx; j++) {
+      byte = byte_line * i + (j / 8);
+      bit = j % 8;
+      flag = 0x01 & (bitmap[byte] >> bit);
+      if (flag)
+	XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+      else 
+	XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+      XDrawPoint (graphic[0].display, graphic[0].window, 
+		  graphic[0].gc, x + j, y + i);
+    }
+  }
+  if (mode == 0) {
+    graphic[0].black = black;
+    graphic[0].white = white;
+  }
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+}
+
Index: /trunk/Ohana/src/kii/setup/GetColor.c
===================================================================
--- /trunk/Ohana/src/kii/setup/GetColor.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/GetColor.c	(revision 2466)
@@ -0,0 +1,25 @@
+# include "Ximage.h"
+
+/************** GetColor *************/
+unsigned long 
+GetColor (display, name, colormap, default_color)
+Display  *display;
+char      name[];
+Colormap  colormap;
+unsigned long default_color;
+{
+
+  unsigned long color;
+  XColor rgbcolor, hardwarecolor;
+  int status;
+
+  color = default_color;
+  status = XLookupColor (display, colormap, name, &rgbcolor, &hardwarecolor);
+  if (status) {
+    status = XAllocColor (display, colormap, &hardwarecolor);
+    if (status) {
+      color = hardwarecolor.pixel;
+    }
+  }
+  return (color);
+}
Index: /trunk/Ohana/src/kii/setup/LoadFont.c
===================================================================
--- /trunk/Ohana/src/kii/setup/LoadFont.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/LoadFont.c	(revision 2466)
@@ -0,0 +1,31 @@
+# include "Ximage.h"
+
+/************** LoadFont *************/
+void
+LoadFont (graphic, argc, argv, default_name)
+Graphic   graphic[];
+int      *argc;
+char     *argv[];
+char      default_name[];
+{
+
+  char name[400];
+
+  strcpy (name, default_name);
+  CheckFontName (argc, argv, name);
+  graphic[0].font = XLoadQueryFont (graphic[0].display, name);
+  if (graphic[0].font == (XFontStruct *) NULL) {
+    fprintf (stderr, "Could not load fond %s, using %s\n", name, default_name);
+    graphic[0].font = XLoadQueryFont (graphic[0].display, default_name);
+    if (graphic[0].font == (XFontStruct *) NULL) {
+      graphic[0].font = XLoadQueryFont (graphic[0].display, "fixed");
+      fprintf (stderr, "Could not load fond %s, using %s\n", 
+	       default_name, "fixed");
+    }
+  }
+  if (graphic[0].font != (XFontStruct *) NULL) 
+    XSetFont (graphic[0].display, graphic[0].gc, graphic[0].font[0].fid);
+  else
+    QuitX (graphic[0].display, "Error: could not load font", name);
+}
+
Index: /trunk/Ohana/src/kii/setup/MakeColormap.c
===================================================================
--- /trunk/Ohana/src/kii/setup/MakeColormap.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/MakeColormap.c	(revision 2466)
@@ -0,0 +1,54 @@
+# include "Ximage.h"
+# define NPIXELS 64
+
+static char default_cmap[] = "grayscale";
+
+void MakeColormap (Graphic *graphic, Layout *layout, int argc, char **argv) {
+
+  int i, N, status;
+  char *temp_name;
+
+  /* hardwired colors - white, black -- for drawing text and overlay graphics */
+  layout[0].white = graphic[0].white;
+  layout[0].black = graphic[0].black;
+  layout[0].start = 0;
+  layout[0].slope = 1;
+  temp_name = XGetDefault (graphic[0].display, argv[0], "ROverlay");
+  layout[0].overlay[0].color = GetColor (graphic[0].display, (temp_name == (char *) NULL ? "red"    : temp_name), graphic[0].colormap, graphic[0].black);
+  temp_name = XGetDefault (graphic[0].display, argv[0], "GOverlay");
+  layout[0].overlay[1].color = GetColor (graphic[0].display, (temp_name == (char *) NULL ? "green"  : temp_name), graphic[0].colormap, graphic[0].black);
+  temp_name = XGetDefault (graphic[0].display, argv[0], "BOverlay");
+  layout[0].overlay[2].color = GetColor (graphic[0].display, (temp_name == (char *) NULL ? "blue"   : temp_name), graphic[0].colormap, graphic[0].black);
+  temp_name = XGetDefault (graphic[0].display, argv[0], "YOverlay");
+  layout[0].overlay[3].color = GetColor (graphic[0].display, (temp_name == (char *) NULL ? "yellow" : temp_name), graphic[0].colormap, graphic[0].black);
+
+  layout[0].Npixels = graphic[0].Npixels;
+  for (i = 0; i < layout[0].Npixels; i++) 
+    layout[0].cmap[i].pixel = graphic[0].pixels[i];
+
+  /* decide on a color map */
+  temp_name = XGetDefault (graphic[0].display, argv[0], "Colormap");
+  if ((N = get_argument (argc, argv, "-cm"))) {
+    if (N + 1 < argc) {
+      temp_name = argv[N+1];
+    } else {
+      fprintf (stderr, "error: usage is -cm ColormapName\n");
+      exit (1);
+    }
+  }
+  if (temp_name == (char *) NULL) temp_name = default_cmap;
+
+  status = SetColormap (graphic, layout, temp_name);
+  if (!status) {
+    fprintf (stderr, "invalid colormap, using default %s\n", default_cmap);
+    temp_name = default_cmap;
+    status = SetColormap (graphic, layout, temp_name);
+    if (!status) {
+      fprintf (stderr, "problem with default colormap\n");
+      exit (1);
+    }
+  }
+}
+
+/* this routine is NOT independent of the number of overlays */
+
Index: /trunk/Ohana/src/kii/setup/MakeCursor.c
===================================================================
--- /trunk/Ohana/src/kii/setup/MakeCursor.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/MakeCursor.c	(revision 2466)
@@ -0,0 +1,16 @@
+# include "Ximage.h"
+
+/************** MakeCursor *************/
+void
+MakeCursor  (graphic, which_cursor)
+Graphic      graphic[];
+unsigned int which_cursor;
+{
+
+  graphic[0].cursor = XCreateFontCursor (graphic[0].display, 
+					 (unsigned) which_cursor);
+  if (graphic[0].cursor != (Cursor) None)
+    XDefineCursor (graphic[0].display, graphic[0].window, graphic[0].cursor);
+}
+
+
Index: /trunk/Ohana/src/kii/setup/MakeGC.c
===================================================================
--- /trunk/Ohana/src/kii/setup/MakeGC.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/MakeGC.c	(revision 2466)
@@ -0,0 +1,15 @@
+# include "Ximage.h"
+
+/************** MakeGC *************/
+void MakeGC (Graphic *graphic) {
+
+  XGCValues gcvalues;
+
+  gcvalues.foreground = graphic[0].black;
+  gcvalues.background = graphic[0].white;
+  graphic[0].gc = XCreateGC (graphic[0].display, graphic[0].window, 
+			     GCForeground | GCBackground, &gcvalues);
+  if (graphic[0].gc == 0)
+    QuitX (graphic[0].display, "Error in creating a Graphics Context", "");
+}
+
Index: /trunk/Ohana/src/kii/setup/MapWindow.c
===================================================================
--- /trunk/Ohana/src/kii/setup/MapWindow.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/MapWindow.c	(revision 2466)
@@ -0,0 +1,13 @@
+# include "Ximage.h"
+
+/************** MapWindow *************/
+void
+MapWindow (graphic)
+Graphic    graphic[];
+{
+
+  XMapRaised (graphic[0].display, graphic[0].window);
+  XMapSubwindows (graphic[0].display, graphic[0].window);
+  XFlush (graphic[0].display);
+}
+
Index: /trunk/Ohana/src/kii/setup/NameWindow.c
===================================================================
--- /trunk/Ohana/src/kii/setup/NameWindow.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/NameWindow.c	(revision 2466)
@@ -0,0 +1,35 @@
+# include "Ximage.h"
+
+/************** NameWindow *************/
+void
+NameWindow (graphic, Name)
+Graphic     graphic[];
+char       *Name;
+{
+
+  char       *name;
+  char       *class_name;
+  char       *class_type;
+  XClassHint *classhints;
+
+  name = strrchr (Name, '/');
+  if (name != NULL) 
+    name ++;
+  else 
+    name = Name;
+  class_type = class_name = name;
+
+
+  classhints = XAllocClassHint ();
+
+  if (classhints != (XClassHint *) NULL)  {
+    classhints[0].res_name = class_name;
+    classhints[0].res_class = class_type;
+    XSetClassHint (graphic[0].display, graphic[0].window, classhints);
+    XFree (classhints);
+  }
+  
+  XStoreName (graphic[0].display, graphic[0].window, name);
+  XSetIconName (graphic[0].display, graphic[0].window, name);
+}
+
Index: /trunk/Ohana/src/kii/setup/OpenDisplay.c
===================================================================
--- /trunk/Ohana/src/kii/setup/OpenDisplay.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/OpenDisplay.c	(revision 2466)
@@ -0,0 +1,19 @@
+# include "Ximage.h"
+
+/************** OpenDisplay *************/
+Display *OpenDisplay (char *display_name, int *screen) {
+
+  Display *display;
+  
+  display = XOpenDisplay (display_name);
+  if (display != (Display *) NULL)
+    *screen = DefaultScreen (display);
+  if (display == (Display *) NULL) {
+    fprintf (stderr, "Error could not open X display to %s\n", 
+	     XDisplayName (display_name));
+    exit (0);
+  }
+
+  return (display);
+}
+
Index: /trunk/Ohana/src/kii/setup/QuitX.c
===================================================================
--- /trunk/Ohana/src/kii/setup/QuitX.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/QuitX.c	(revision 2466)
@@ -0,0 +1,15 @@
+# include "Ximage.h"
+
+/************** QuitX *************/
+void
+QuitX (display, error_message, error_file)
+Display *display;
+char error_message[], error_file[];
+{
+
+  fprintf (stderr, "Error: %s%s\n", error_message, error_file);
+  XCloseDisplay (display);
+  exit (0);
+}
+
+
Index: /trunk/Ohana/src/kii/setup/SetNormalHints.c
===================================================================
--- /trunk/Ohana/src/kii/setup/SetNormalHints.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/SetNormalHints.c	(revision 2466)
@@ -0,0 +1,30 @@
+# include "Ximage.h"
+
+/************** SetNormalHints  *************/
+void
+SetNormalHints (graphic)
+Graphic         graphic[];
+{
+
+  XSizeHints *sizehints;
+
+  sizehints = XAllocSizeHints ();
+
+  if (sizehints != (XSizeHints *) NULL)  {
+    sizehints[0].x = graphic[0].x;
+    sizehints[0].y = graphic[0].x;
+    sizehints[0].width = graphic[0].dx;
+    sizehints[0].height = graphic[0].dy;
+    sizehints[0].min_width = MIN_WIDTH;
+    sizehints[0].min_height = MIN_HEIGHT;    
+    sizehints[0].flags = USPosition | USSize | PMinSize;
+
+    sizehints[0].base_width = graphic[0].dx;
+    sizehints[0].base_height = graphic[0].dy;
+    sizehints[0].flags |= PBaseSize;
+    
+    XSetWMNormalHints (graphic[0].display, graphic[0].window, sizehints);
+    XFree (sizehints);
+  }
+}
+
Index: /trunk/Ohana/src/kii/setup/SetUpDisplay.c
===================================================================
--- /trunk/Ohana/src/kii/setup/SetUpDisplay.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/SetUpDisplay.c	(revision 2466)
@@ -0,0 +1,20 @@
+# include "Ximage.h"
+
+/************** SetUpDisplay *************/
+void SetUpDisplay (Graphic *graphic, int *argc, char **argv) {
+
+  char display_name[120];
+
+  CheckDisplayName (argc, argv, display_name); 
+
+  /* set default values */
+  graphic[0].display  = OpenDisplay (display_name, &graphic[0].screen);
+  graphic[0].colormap = DefaultColormap (graphic[0].display, graphic[0].screen);
+  graphic[0].depth    = DefaultDepth    (graphic[0].display, graphic[0].screen);
+  graphic[0].visual   = DefaultVisual   (graphic[0].display, graphic[0].screen);
+
+  /* get the basic colors */
+  CheckVisual (graphic, argc, argv);
+  CheckColors (graphic, argc, argv);
+}
+
Index: /trunk/Ohana/src/kii/setup/SetUpWindow.c
===================================================================
--- /trunk/Ohana/src/kii/setup/SetUpWindow.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/SetUpWindow.c	(revision 2466)
@@ -0,0 +1,33 @@
+# include "Ximage.h"
+# include "icons/icon.h"
+
+/************** SetUpWindow *************/
+void SetUpWindow (Graphic *graphic, int *argc, char **argv) {
+
+  int N;
+  Icon icon;
+
+  icon.width = icon_width;
+  icon.height = icon_height;
+  icon.bits = icon_bits;
+
+  CheckGeometry (argc, argv, graphic);
+  TopWindow (graphic, &icon);
+  LoadFont (graphic, argc, argv, "fixed"); 
+
+  XFlush (graphic[0].display);
+  XSetWindowBackground (graphic[0].display, graphic[0].window, graphic[0].white);
+
+  SetNormalHints (graphic);
+  SetWMHints (graphic, &icon);
+  NameWindow (graphic, "Ki'i");
+
+  if ((N = get_argument (*argc, argv, "-nomap"))) {
+    remove_argument(N, argc, argv);
+  } else {
+    MapWindow (graphic);
+  }  
+}
+
+
+
Index: /trunk/Ohana/src/kii/setup/SetWMHints.c
===================================================================
--- /trunk/Ohana/src/kii/setup/SetWMHints.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/SetWMHints.c	(revision 2466)
@@ -0,0 +1,27 @@
+# include "Ximage.h"
+
+/************** SetWMHints  *************/
+void
+SetWMHints (graphic, icon) 
+Graphic     graphic[];
+Icon        icon[];
+{
+  XWMHints *wmhints;
+
+  wmhints = XAllocWMHints ();
+  if (wmhints != (XWMHints *)NULL) {
+    wmhints[0].initial_state = NormalState;
+    wmhints[0].input = True;
+    if (icon[0].pixmap != (Pixmap) None) {
+      wmhints[0].icon_pixmap = icon[0].pixmap;
+      wmhints[0].icon_mask = icon[0].pixmap;
+      wmhints[0].flags = StateHint | InputHint | IconPixmapHint | IconMaskHint;
+    }
+    else 
+      wmhints[0].flags = StateHint | InputHint;
+    
+    XSetWMHints (graphic[0].display, graphic[0].window, wmhints);
+    XFree (wmhints);
+  }
+}
+
Index: /trunk/Ohana/src/kii/setup/TopWindow.c
===================================================================
--- /trunk/Ohana/src/kii/setup/TopWindow.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/TopWindow.c	(revision 2466)
@@ -0,0 +1,21 @@
+# include "Ximage.h"
+
+/************** TopWindow *************/
+void TopWindow (Graphic *graphic, Icon *icon) {
+
+  Window rootwindow;
+
+  rootwindow = RootWindow (graphic[0].display, graphic[0].screen);
+
+  CreateWindow (graphic, rootwindow, BORDER_WIDTH, EVENT_MASK);
+  MakeGC (graphic);
+  icon[0].pixmap = XCreateBitmapFromData (graphic[0].display,
+					graphic[0].window, 
+					icon[0].bits, 
+					icon[0].width, 
+					icon[0].height);
+  MakeCursor (graphic, DEFAULT_CURSOR);
+  XFreeCursor (graphic[0].display, graphic[0].cursor);
+  XFlush (graphic[0].display);
+}
+
Index: /trunk/Ohana/src/kii/setup/Ximage.c
===================================================================
--- /trunk/Ohana/src/kii/setup/Ximage.c	(revision 2466)
+++ /trunk/Ohana/src/kii/setup/Ximage.c	(revision 2466)
@@ -0,0 +1,22 @@
+# include "Ximage.h"
+
+int main (int argc, char **argv) {
+
+  Graphic graphic;
+  Layout  layout;
+  
+  bzero (&graphic, sizeof(Graphic));
+  bzero (&layout, sizeof(Layout));
+
+  SetUpDisplay (&graphic, &argc, argv);
+  SetUpWindow (&graphic, &argc, argv);
+
+  DefineLayout (&layout, &graphic, argc, argv);
+  EventLoop (&graphic, &layout);
+
+  XFlush (graphic.display);
+  XFreeFont (graphic.display, graphic.font); 
+  CloseDisplay (&graphic);
+  exit (0);
+}
+
Index: /trunk/Ohana/src/kii/textline/CheckTextLines.c
===================================================================
--- /trunk/Ohana/src/kii/textline/CheckTextLines.c	(revision 2466)
+++ /trunk/Ohana/src/kii/textline/CheckTextLines.c	(revision 2466)
@@ -0,0 +1,28 @@
+# include "Ximage.h"
+
+/******** Here we test the TextLines specific to this program  ****
+TextLine *
+CheckTextLines (graphic, event, layout)
+Graphic         graphic[];
+XEvent          event[];
+Layout          layout[];
+{
+
+  TextLine *textline;
+  textline = (TextLine *) NULL;
+
+  if (InTextLine (graphic, event, &layout[0].zero))
+    textline = &layout[0].zero;
+  if (InTextLine (graphic, event, &layout[0].range))
+    textline = &layout[0].range;
+  if (InTextLine (graphic, event, &layout[0].effects))
+    textline = &layout[0].effects;
+  if (InTextLine (graphic, event, &layout[0].command))
+    textline = &layout[0].command;
+
+  return (textline);
+
+}
+
+
+***/
Index: /trunk/Ohana/src/kii/textline/DrawCursor.c
===================================================================
--- /trunk/Ohana/src/kii/textline/DrawCursor.c	(revision 2466)
+++ /trunk/Ohana/src/kii/textline/DrawCursor.c	(revision 2466)
@@ -0,0 +1,45 @@
+# include "Ximage.h"
+# define XBorder 5
+# define YBorder 2
+
+
+
+DrawCursor (graphic, textline)    
+Graphic       graphic[];
+TextLine      textline[];
+{
+
+  int dx, label_width, DX, text_width, i;
+
+  label_width  = XTextWidth (graphic[0].font, 
+			     textline[0].label,
+			     strlen(textline[0].label));
+  
+  text_width  = XTextWidth (graphic[0].font, 
+			    textline[0].text,
+			    strlen(textline[0].text));
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+  if (label_width + text_width + 2*XBorder > textline[0].dx) {
+    DX = textline[0].dx - label_width - 2*XBorder - arrow_width;
+    for (i = 1; (i < strlen (textline[0].text)) && (text_width > DX); i++) {
+      text_width  = XTextWidth (graphic[0].font, 
+				&textline[0].text[i],
+				strlen(&textline[0].text[i]));
+    }
+    dx  = XTextWidth (graphic[0].font, &textline[0].text[i - 1], 
+		      textline[0].cursor - i + 1) + arrow_width;
+  }
+  else 
+    dx  = XTextWidth (graphic[0].font, textline[0].text, textline[0].cursor);
+
+  XDrawLine (graphic[0].display, 
+	     graphic[0].window, 
+	     graphic[0].gc, 
+	     textline[0].x + label_width + XBorder + dx, 
+	     textline[0].y + YBorder,
+	     textline[0].x + label_width + XBorder + dx, 
+	     textline[0].y + textline[0].dy - YBorder);
+
+}
Index: /trunk/Ohana/src/kii/textline/DrawTextBox.c
===================================================================
--- /trunk/Ohana/src/kii/textline/DrawTextBox.c	(revision 2466)
+++ /trunk/Ohana/src/kii/textline/DrawTextBox.c	(revision 2466)
@@ -0,0 +1,63 @@
+# include "Ximage.h"
+# define XBorder 10
+# define YBorder 2
+# define arrow_width 6
+# define arrow_height 9
+static char arrow_bits[] = {
+  0x00, 0x02, 0x06, 0x0e, 0x1e, 0x0e, 0x06, 0x02, 0x00};
+#define down_width 9
+#define down_height 6
+static char down_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00};
+
+/******************* DrawTextBox ****************/
+DrawTextBox (graphic, textbox)
+Graphic      graphic[];
+TextBox      textbox[];
+{
+
+  int X, Y, y, dy, Nlines, i;
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+  XFillRectangle (graphic[0].display, 
+		  graphic[0].window,
+		  graphic[0].gc,
+		  textbox[0].x  + 1,  textbox[0].y + 1,
+		  XBorder - 2, textbox[0].dy - 2);
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  if (textbox[0].outline) {
+    XDrawRectangle (graphic[0].display, 
+		    graphic[0].window,
+		    graphic[0].gc,
+		    textbox[0].x,  textbox[0].y,
+		    textbox[0].dx, textbox[0].dy);
+  }
+
+  dy = graphic[0].font[0].ascent + graphic[0].font[0].descent;
+  Nlines = (textbox[0].dy - 2*YBorder) / dy;
+
+  for (i = 0; (i < Nlines) && (i < textbox[0].Nlines); i++) {
+    y = textbox[0].y + graphic[0].font[0].ascent + dy*i + YBorder;
+    XDrawString (graphic[0].display, 
+		 graphic[0].window, 
+		 graphic[0].gc, 
+		 textbox[0].x + XBorder, y,
+		 textbox[0].text[i], 
+		 strlen(textbox[0].text[i]));
+  }
+
+  if (Nlines < textbox[0].Nlines) {
+    DrawBitmap (graphic, 
+		textbox[0].x + textbox[0].dx - down_width - 2,
+		textbox[0].y + textbox[0].dy - down_height - 2,
+		down_width, down_height, down_bits, 1);
+  }
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  if (textbox[0].cursor_line != -1) {
+    Y = textbox[0].y + dy*textbox[0].cursor_line + YBorder + (dy - arrow_height)/2;
+    X = textbox[0].x + (XBorder - arrow_width) / 2;
+    DrawBitmap (graphic, X, Y, arrow_width, arrow_height, arrow_bits, 1);
+  }
+}
+
Index: /trunk/Ohana/src/kii/textline/DrawTextLine.c
===================================================================
--- /trunk/Ohana/src/kii/textline/DrawTextLine.c	(revision 2466)
+++ /trunk/Ohana/src/kii/textline/DrawTextLine.c	(revision 2466)
@@ -0,0 +1,34 @@
+# include "Ximage.h"
+# define XBorder 5
+# define YBorder 2
+
+DrawTextLine (graphic, textline)
+Graphic  graphic[];
+TextLine textline[];
+{
+
+  int y;
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  if (textline[0].outline) {
+    XDrawRectangle (graphic[0].display, 
+		    graphic[0].window,
+		    graphic[0].gc,
+		    textline[0].x,  textline[0].y,
+		    textline[0].dx, textline[0].dy);
+  }
+
+  y = textline[0].y + (textline[0].dy + graphic[0].font[0].ascent) / 2;
+  XDrawString (graphic[0].display, 
+	       graphic[0].window, 
+	       graphic[0].gc, 
+	       textline[0].x + XBorder, y,
+	       textline[0].label, 
+	       strlen(textline[0].label));
+  RedrawString (graphic, textline);
+
+  if (textline[0].cursor != -1)
+    DrawCursor (graphic, textline);
+
+}
+
Index: /trunk/Ohana/src/kii/textline/InTextBox.c
===================================================================
--- /trunk/Ohana/src/kii/textline/InTextBox.c	(revision 2466)
+++ /trunk/Ohana/src/kii/textline/InTextBox.c	(revision 2466)
@@ -0,0 +1,57 @@
+# include "Ximage.h"
+# define XBorder 10
+# define YBorder 2
+# define arrow_width 6
+# define arrow_height 9
+static char arrow_bits[] = {
+  0x00, 0x02, 0x06, 0x0e, 0x1e, 0x0e, 0x06, 0x02, 0x00};
+#define down_width 9
+#define down_height 6
+static char down_bits[] = {
+   0x00, 0x00, 0xfe, 0x00, 0x7c, 0x00, 0x38, 0x00, 0x10, 0x00, 0x00, 0x00};
+
+/******************* InTextBox ****************/
+int
+InTextBox (graphic, event, textbox)
+Graphic          graphic[];
+XButtonEvent    *event;
+TextBox          textbox[];
+{
+
+  int answer;
+  int i, x, y, Y, X, dy;
+  int minX, maxX, minY, maxY;
+  
+  x = event[0].x;
+  y = event[0].y;
+  dy = graphic[0].font[0].ascent + graphic[0].font[0].descent;
+  
+  minX = textbox[0].x;
+  maxX = textbox[0].x + textbox[0].dx;
+  minY = textbox[0].y;
+  maxY = textbox[0].y + textbox[0].dy;
+  if (dy*textbox[0].Nlines + 2*YBorder < textbox[0].dy)
+    maxY = textbox[0].y + dy*textbox[0].Nlines + 2*YBorder;
+
+  answer = ((x >= minX) && (x <= maxX) && (y >= minY) && (y <= maxY));
+  
+  /* find the cursor position, erase the old arrow and draw a new arrow */
+  if (answer) {
+    if (textbox[0].cursor_line != -1) {
+      Y = textbox[0].y + dy*textbox[0].cursor_line + YBorder + (dy - arrow_height)/2;
+      X = textbox[0].x + (XBorder - arrow_width) / 2;
+      DrawBitmap (graphic, X, Y, arrow_width, arrow_height, arrow_bits, 0);
+    }
+    textbox[0].cursor_line = (y - textbox[0].y - YBorder)/dy;
+    X = textbox[0].x + (XBorder - arrow_width) / 2;
+    Y = textbox[0].y + dy*textbox[0].cursor_line + YBorder + (dy - arrow_height)/2;
+    DrawBitmap (graphic, X, Y, arrow_width, arrow_height, arrow_bits, 1);
+    textbox[0].cursor_x = x;
+    textbox[0].cursor_y = y;
+    XFlush (graphic[0].display);
+  }
+  
+  return (answer);
+  
+}
+
Index: /trunk/Ohana/src/kii/textline/InTextLine.c
===================================================================
--- /trunk/Ohana/src/kii/textline/InTextLine.c	(revision 2466)
+++ /trunk/Ohana/src/kii/textline/InTextLine.c	(revision 2466)
@@ -0,0 +1,58 @@
+# include "Ximage.h"
+# define XBorder 5
+# define YBorder 2
+
+int
+InTextLine (graphic, event, textline)
+Graphic          graphic[];
+XButtonEvent    *event;
+TextLine         textline[];
+{
+
+  int answer, done;
+  int i, x, dx, y, text_width, label_width;
+  int minX, maxX, minY, maxY;
+  char testline[1000];
+
+  x = event[0].x;
+  y = event[0].y;
+  
+  label_width  = XTextWidth (graphic[0].font, 
+			     textline[0].label,
+			     strlen(textline[0].label));
+  
+  minX = textline[0].x + XBorder + label_width;
+  maxX = textline[0].x + textline[0].dx;
+  minY = textline[0].y;
+  maxY = textline[0].y + textline[0].dy;
+
+  answer = ((x >= minX) && (x <= maxX) && (y >= minY) && (y <= maxY));
+
+  /* find the cursor position and draw a vertical bar */
+  if (answer) {
+    text_width  = XTextWidth (graphic[0].font, 
+			      textline[0].text,
+			      strlen(textline[0].text));
+    
+    if (x >= minX + text_width) {
+      textline[0].cursor = strlen (textline[0].text);
+    }
+    else {
+      for (i = 1, done = FALSE; (i <= strlen (textline[0].text)) && !done; i++) {
+	dx  = XTextWidth (graphic[0].font, 
+			  textline[0].text, i);
+	if (x < minX + dx) {
+	  textline[0].cursor = i - 1;
+	  done = TRUE;
+	}
+      }
+    }
+    DrawCursor (graphic, textline);
+  }    
+  XFlush (graphic[0].display);
+  
+  return (answer);
+  
+}
+
+
Index: /trunk/Ohana/src/kii/textline/RedrawString.c
===================================================================
--- /trunk/Ohana/src/kii/textline/RedrawString.c	(revision 2466)
+++ /trunk/Ohana/src/kii/textline/RedrawString.c	(revision 2466)
@@ -0,0 +1,73 @@
+# include "Ximage.h"
+# define XBorder 5
+# define YBorder 2
+
+
+#define arrow_width 6
+#define arrow_height 9
+RedrawString (graphic, textline)
+Graphic       graphic[];
+TextLine      textline[];
+{
+
+  int label_width, text_width, y, i, DX;
+  static char arrow_bits[] = {
+    0x00, 0x10, 0x18, 0x1c, 0x1e, 0x1c, 0x18, 0x10, 0x00};
+  
+  label_width  = XTextWidth (graphic[0].font, 
+			     textline[0].label,
+			     strlen(textline[0].label));
+  
+  text_width  = XTextWidth (graphic[0].font, 
+			    textline[0].text,
+			    strlen(textline[0].text));
+
+  if (label_width + text_width + 2*XBorder > textline[0].dx) {
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		    textline[0].x + XBorder + label_width, 
+		    textline[0].y + YBorder, 
+		    textline[0].dx - XBorder - label_width, 
+		    textline[0].dy - 2*YBorder + 1);
+    
+    DX = textline[0].dx - label_width - 2*XBorder - arrow_width;
+    for (i = 1; (i < strlen (textline[0].text)) && (text_width > DX); i++) {
+      text_width  = XTextWidth (graphic[0].font, 
+				&textline[0].text[i],
+				strlen(&textline[0].text[i]));
+    }
+
+    y = textline[0].y + (textline[0].dy + graphic[0].font[0].ascent) / 2;
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+    DrawBitmap (graphic, 
+		textline[0].x + XBorder + label_width,
+		textline[0].y + YBorder + (textline[0].dy - arrow_height)/2,
+		arrow_width, arrow_height, arrow_bits, 1);
+    XDrawString (graphic[0].display, 
+		 graphic[0].window, 
+		 graphic[0].gc, 
+		 textline[0].x + XBorder + label_width + arrow_width, y,
+		 &textline[0].text[i - 1], 
+		 strlen(&textline[0].text[i - 1]));
+    XFlush (graphic[0].display);
+  }
+  else {
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		    textline[0].x + XBorder + label_width, 
+		    textline[0].y + YBorder, 
+		    textline[0].dx - XBorder - label_width, 
+		    textline[0].dy - 2*YBorder + 1);
+    
+    y = textline[0].y + (textline[0].dy + graphic[0].font[0].ascent) / 2;
+    
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+    XDrawString (graphic[0].display, 
+		 graphic[0].window, 
+		 graphic[0].gc, 
+		 textline[0].x + XBorder + label_width, y,
+		 textline[0].text, 
+		 strlen(textline[0].text));
+  }
+
+}
Index: /trunk/Ohana/src/kii/textline/TextLineEntry.c
===================================================================
--- /trunk/Ohana/src/kii/textline/TextLineEntry.c	(revision 2466)
+++ /trunk/Ohana/src/kii/textline/TextLineEntry.c	(revision 2466)
@@ -0,0 +1,81 @@
+# include "Ximage.h"
+# define XBorder 5
+# define YBorder 2
+
+int 
+TextLineEntry (graphic, textline, keyevent)
+Graphic        graphic[];
+TextLine       textline[];
+XKeyEvent     *keyevent;
+{
+
+  int i, status, N;
+  char dummy[3];
+  XComposeStatus compose_status;
+  KeySym keysym;
+
+  status = TRUE;
+  strcpy (textline[0].old_text, textline[0].text);
+  bzero (&textline[0].text[strlen(textline[0].text)], 
+	 1024 - strlen(textline[0].text));
+  i = textline[0].cursor;
+
+
+  N = XLookupString (keyevent, dummy, 1, &keysym, &compose_status);
+  switch (keysym) {
+  case XK_BackSpace:
+  case XK_Delete:
+    if (textline[0].cursor > 0) {
+      bcopy (&textline[0].text[i], &textline[0].text[i - 1], 
+	     strlen(&textline[0].text[i]) + 1);
+      RedrawString (graphic, textline);
+      textline[0].cursor --;
+      DrawCursor (graphic, textline);
+    }
+    break;
+  case XK_Left:
+    RedrawString (graphic, textline);
+    textline[0].cursor --;
+    if (textline[0].cursor < 0)
+      textline[0].cursor = 0;
+    DrawCursor (graphic, textline);
+    break;
+  case XK_Right:
+    RedrawString (graphic, textline);
+    textline[0].cursor ++;
+    if (textline[0].cursor > strlen (textline[0].text))
+      textline[0].cursor = strlen (textline[0].text);
+    DrawCursor (graphic, textline);
+    break;
+  case XK_Return:
+    RedrawString (graphic, textline);
+    textline[0].cursor = -1;
+    status = FALSE;
+    break;
+  case XK_d:
+  case XK_D: 
+    if (dummy[0] == 4) { /* a control-d was typed! */
+      if (textline[0].cursor < strlen(textline[0].text)) {
+	bcopy (&textline[0].text[i + 1], &textline[0].text[i], 
+	       strlen(&textline[0].text[i]));
+	RedrawString (graphic, textline);
+	DrawCursor (graphic, textline);
+      }
+      break;  /* WARNING: this case MUST come before default.
+		 anything between this and default will be executed
+		 if no cntl-d is typed! */
+    }
+  default:
+    if (N != 0) {
+      bcopy (&textline[0].text[i], &textline[0].text[i + 1], 
+	     strlen(&textline[0].text[i]));
+      textline[0].text[i] = dummy[0];
+      RedrawString (graphic, textline);
+      textline[0].cursor ++;
+      DrawCursor (graphic, textline);
+    }
+  }
+  return (status);
+}
+
+
Index: /trunk/Ohana/src/kii/zoom/CreateZoom.c
===================================================================
--- /trunk/Ohana/src/kii/zoom/CreateZoom.c	(revision 2466)
+++ /trunk/Ohana/src/kii/zoom/CreateZoom.c	(revision 2466)
@@ -0,0 +1,26 @@
+# 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))
+
+void CreateZoom (Layout *layout, Graphic *graphic, double x, double y) {
+
+  switch (graphic[0].Nbits) {
+  case 8:
+    CreateZoom8 (layout, graphic, x, y);
+    break;
+
+  case 16:
+    CreateZoom16 (layout, graphic, x, y);
+    break;
+
+  case 24:
+    CreateZoom24 (layout, graphic, x, y);
+    break;
+
+  case 32:
+    CreateZoom32 (layout, graphic, x, y);
+    break;
+  }    
+
+}
Index: /trunk/Ohana/src/kii/zoom/CreateZoom.new
===================================================================
--- /trunk/Ohana/src/kii/zoom/CreateZoom.new	(revision 2466)
+++ /trunk/Ohana/src/kii/zoom/CreateZoom.new	(revision 2466)
@@ -0,0 +1,112 @@
+# include "Ximage.h"
+# define XPIX(x,Rx,S) (x*S + Rx)
+
+void
+CreateZoom (layout, graphic, x, y)
+Layout layout[];
+Graphic graphic[];
+double x, y;
+{
+
+  int i, j, ii, jj, X, Y;
+  int zvalue;
+  double value, expand, zero, range, zoomscale;
+  double X0, Y0, Rx, Ry, Rz1, Rz2;
+  int expand_int, dx, dy, DX, DY, Npixels, yfac;
+  Visual *visual = CopyFromParent;
+  unsigned long pixel;
+
+
+  /* create a test pattern image to put in layout[0].picture */
+  if (layout[0].matrix.size == 0) {
+    REALLOCATE (layout[0].zoom.data, char, layout[0].zoom.dx*layout[0].zoom.dy);
+    bzero (layout[0].zoom.data, layout[0].zoom.dx*layout[0].zoom.dy);
+  }
+  else {
+    for (i = 0; i < 256; i++) 
+      pixel[i] = layout[0].cmap[i].pixel;
+    white = layout[0].white;
+    
+    zoomscale = MAX (5, layout[0].expand + 5);
+    expand = 1 / zoomscale;
+    expand_out = (int) zoomscale;
+    expand_in  = 1;
+    
+    dx = layout[0].zoom.dx;
+    dy = layout[0].zoom.dy;
+    DX = layout[0].matrix.Naxis[0];
+    DY = layout[0].matrix.Naxis[1];
+    Rx = DX/2 - dx*expand/2.0 - X0;
+    Ry = DY/2 - dy*expand/2.0 - Y0;  
+    
+    /* reassign as much for speed as clarity here */
+    X0 = 0.5*layout[0].matrix.Naxis[0] - x;
+    Y0 = 0.5*layout[0].matrix.Naxis[1] - y;
+    dx = layout[0].picture.dx;
+    dy = layout[0].picture.dy;
+    DX = matrix[0].Naxis[0];
+    DY = matrix[0].Naxis[1];
+    Rx = DX/2 - dx*expand/2.0 - X0;
+    Ry = DY/2 - dy*expand/2.0 - Y0;
+    
+    i_start = MAX (-Rx / expand, 0);
+    j_start = MAX (-Ry / expand, 0);
+    i_end   = MIN ((DX - Rx)/expand, dx - expand_out + 1);
+    j_end   = MIN ((DY - Ry)/expand, dy - expand_out + 1);
+    
+    in_pix = (short *) matrix[0].buffer;
+    out_pix = layout[0].zoom.data;
+    for (j = 0; j < j_start; j++) {
+      for (i = 0; i < dx; i++, out_pix++) {
+	*out_pix = white;
+      }
+    }
+    
+  for (j = j_start; j < j_end; j+= expand_out) {
+    Y = XPIX (j, Ry, expand);
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix = layout[0].zoom.data + (j+jj)*dx;  /* fencepost errors? */
+      for (i = 0; i < i_start; i++, out_pix++) {
+	*out_pix = white;
+      }
+    }
+    out_pix = layout[0].zoom.data + j*dx + i_start;  
+    X = XPIX (i_start, Rx, expand);
+    in_pix2 = in_pix + DX*Y + X;
+    for (i = i_start; i < i_end; i+= expand_out, in_pix2+= expand_in) { 
+      zvalue = 0x003f & *in_pix2;
+      for (ii = 0; ii < expand_out; ii++, out_pix++) {
+	for (jj = 0; jj < expand_out; jj++) {
+	  *(out_pix + jj*dx) = *(pixel + zvalue);
+	}
+      }
+    }
+    for (jj = 0; jj < expand_out; jj++) {
+      out_pix = layout[0].zoom.data + (j+jj)*dx + i_end;  /* fencepost errors? */
+      for (i = i_end; i < dx; i++, out_pix++) {
+	*out_pix = white;
+      }
+    }
+  }
+  for (j = j_end; j < dy; j++) {
+    out_pix = layout[0].picture.data + j*dx;
+    for (i = 0; i < dx; i++, out_pix++) {
+      *out_pix = white;
+    }
+  }
+}
+	
+  /*** here, if expand is < 1 (fractional expansion), we sparsely sample the 
+    original image, instead of box averaging - do we like this?  well, 
+    it speeds things up alot! ***/
+
+
+
+
+  layout[0].zoom.pix = XCreateImage (graphic[0].display, visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].zoom.data, 
+					layout[0].zoom.dx, layout[0].zoom.dy, 8, 0);
+  
+}
+
+ 
Index: /trunk/Ohana/src/kii/zoom/CreateZoom16.c
===================================================================
--- /trunk/Ohana/src/kii/zoom/CreateZoom16.c	(revision 2466)
+++ /trunk/Ohana/src/kii/zoom/CreateZoom16.c	(revision 2466)
@@ -0,0 +1,134 @@
+# 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))
+
+void CreateZoom16 (Layout *layout, 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, zoomscale, Rx, Ry;
+  int expand_in, expand_out;
+  unsigned char *out_pix, *out_pix2, *data;
+  unsigned char *in_pix,  *in_pix2;
+  unsigned char pixel1[256], pixel2[256];
+  unsigned char pixvalue1, pixvalue2;
+  unsigned long white;
+  unsigned char white1, white2;
+
+  dx = layout[0].zoom.dx;
+  dy = layout[0].zoom.dy;
+
+  if (layout[0].matrix.size == 0) {  /* create a test pattern */
+    REALLOCATE (layout[0].zoom.data, char, 2*dy*dx);
+    bzero (layout[0].zoom.data, layout[0].zoom.dx*layout[0].zoom.dy);
+    layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+				       layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 16, 0);
+    return;
+  }
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel1[i] = 0x0000ff & layout[0].cmap[i].pixel;
+    pixel2[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 8);
+  }
+  white = layout[0].white;
+  white1 = 0x0000ff & white;
+  white2 = 0x0000ff & (white >> 8);
+
+  zoomscale = MAX (5, layout[0].expand + 5);
+  expand = 1 / zoomscale;
+  expand_out = (int) zoomscale;
+  expand_in  = 1;
+
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[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 *) layout[0].zoom.data;
+  in_pix  = (unsigned char *) (layout[0].matrix.buffer) + 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 = white;
+    return;
+  } 
+  
+  /**** fill in bottom area ****/
+  for (j = 0; j < j_start; j++) {
+    for (i = 0; i < dx; i++, out_pix+=2) {
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+    }
+  }
+
+  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] = white1;
+	out_pix2[1] = white2;
+      }
+    }
+    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) {
+	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) { 
+	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)) {
+	  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] = white1;
+	out_pix2[1] = white2;
+      }
+    }
+  } 
+  
+  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] = white1;
+      out_pix[1] = white2;
+    }
+  }
+
+  layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, 16, ZPixmap, 0, 
+					layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 32, 0);
+  
+}
Index: /trunk/Ohana/src/kii/zoom/CreateZoom24.c
===================================================================
--- /trunk/Ohana/src/kii/zoom/CreateZoom24.c	(revision 2466)
+++ /trunk/Ohana/src/kii/zoom/CreateZoom24.c	(revision 2466)
@@ -0,0 +1,167 @@
+# 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))
+
+void CreateZoom24 (Layout *layout, Graphic *graphic, double x, double y) {
+
+  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;
+  double expand, zoomscale, Rx, Ry;
+  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];
+  unsigned char pixvalue1, pixvalue2, pixvalue3;
+  unsigned long white;
+  unsigned char white1, white2, white3;
+
+  dx = layout[0].zoom.dx;
+  dy = layout[0].zoom.dy;
+  extra = 4 - (dx * 3) % 4;
+
+  if (layout[0].matrix.size == 0) {  /* create a test pattern */
+    REALLOCATE (layout[0].zoom.data, char, dy*(3*dx+extra));
+    bzero (layout[0].zoom.data, layout[0].zoom.dx*layout[0].zoom.dy);
+    layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+				       layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 32, 0);
+    return;
+  }
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel1[i] = 0x0000ff & layout[0].cmap[i].pixel;
+    pixel2[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 8);
+    pixel3[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 16);
+  }
+  white = layout[0].white;
+  white1 = 0x0000ff & white;
+  white2 = 0x0000ff & (white >> 8);
+  white3 = 0x0000ff & (white >> 16);
+
+  zoomscale = MAX (5, layout[0].expand + 5);
+  expand = 1 / zoomscale;
+  expand_out = (int) zoomscale;
+  expand_in  = 1;
+
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[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 *) layout[0].zoom.data;
+  in_pix  = (unsigned char *) (layout[0].matrix.buffer) + 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 = white;
+    return;
+  } 
+  
+  /**** fill in bottom area ****/
+  for (j = 0; j < j_start; j++) {
+    for (i = 0; i < dx; i++, out_pix+=3) {
+      out_pix[0] = white1;
+      out_pix[1] = white2;
+      out_pix[2] = white3;
+    }
+    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] = white1;
+	out_pix2[1] = white2;
+	out_pix2[2] = white3;
+      }
+    }
+    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) {
+	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) { 
+	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) {
+	  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] = white1;
+	out_pix2[1] = white2;
+	out_pix2[2] = white3;
+      }
+    }
+  } 
+  
+  /*
+  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] = white1;
+      out_pix[1] = white2;
+      out_pix[2] = white3;
+    }
+    out_pix+=extra;
+  }
+
+  /*
+  out_pix = (unsigned char *) layout[0].zoom.data;
+  for (i = 0; i < dx*dy; i++) {
+    out_pix[3*i + 0] = white1;
+    out_pix[3*i + 1] = white2;
+    out_pix[3*i + 2] = white3;
+  }
+  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];
+    }
+
+  }
+  */
+  layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, 24, ZPixmap, 0, 
+					layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 32, 0);
+  
+}
Index: /trunk/Ohana/src/kii/zoom/CreateZoom32.c
===================================================================
--- /trunk/Ohana/src/kii/zoom/CreateZoom32.c	(revision 2466)
+++ /trunk/Ohana/src/kii/zoom/CreateZoom32.c	(revision 2466)
@@ -0,0 +1,122 @@
+# 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))
+
+void CreateZoom32 (Layout *layout, 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, zoomscale, Rx, Ry;
+  int expand_in, expand_out;
+  unsigned int *out_pix, *out_pix2, *data;
+  unsigned char  *in_pix,  *in_pix2;
+  unsigned long pixel[256], pixvalue;
+  unsigned long white;
+
+  if (layout[0].matrix.size == 0) {  /* create a test pattern */
+    REALLOCATE (layout[0].zoom.data, char, 4*layout[0].zoom.dx*layout[0].zoom.dy);
+    layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+				       layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 32, 0);
+    return;
+  }
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel[i] = layout[0].cmap[i].pixel;
+  }
+  white = layout[0].white;
+
+  zoomscale = MAX (5, layout[0].expand + 5);
+  expand = 1 / zoomscale;
+  expand_out = (int) zoomscale;
+  expand_in  = 1;
+
+  dx = layout[0].zoom.dx;
+  dy = layout[0].zoom.dy;
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[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 int *) layout[0].zoom.data;
+  data = (unsigned int *) layout[0].zoom.data;
+  in_pix  = (unsigned char *) (layout[0].matrix.buffer) + 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 = white;
+    return;
+  } 
+  
+
+  /**** fill in bottom area ****/
+  for (j = 0; j < dx*j_start; j++, out_pix++) {
+    out_pix[0] = white;
+  }
+
+  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_pix[0] = white;
+      }
+    }
+    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[0] = pixel[*in_pix2];
+      }
+    }
+    else {
+      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[0] = 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[0] = white;
+      }
+    }
+    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 int *)layout[0].zoom.data < dx*dy); j++, out_pix++) { 
+    out_pix[0] = white;
+  }
+
+  out_pix = (unsigned int *)layout[0].zoom.data;
+  layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 32, 0);
+  
+}
Index: /trunk/Ohana/src/kii/zoom/CreateZoom8.c
===================================================================
--- /trunk/Ohana/src/kii/zoom/CreateZoom8.c	(revision 2466)
+++ /trunk/Ohana/src/kii/zoom/CreateZoom8.c	(revision 2466)
@@ -0,0 +1,140 @@
+# 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))
+
+void CreateZoom8 (Layout *layout, 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, zoomscale, Rx, Ry;
+  int expand_in, expand_out;
+  char  *out_pix, *out_pix2;
+  char  *in_pix,  *in_pix2;
+  unsigned long pixel[256], pixvalue;
+  unsigned long white;
+
+  if (layout[0].matrix.size == 0) {  /* create a test pattern */
+    REALLOCATE (layout[0].zoom.data, char, layout[0].zoom.dx*layout[0].zoom.dy);
+    bzero (layout[0].zoom.data, layout[0].zoom.dx*layout[0].zoom.dy);
+    layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+				       layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 8, 0);
+    return;
+  }
+
+  for (i = 0; i < 256; i++) { /* set up pixel array */
+    pixel[i] = layout[0].cmap[i].pixel;
+  }
+  white = layout[0].white;
+
+  zoomscale = MAX (5, layout[0].expand + 5);
+  expand = 1 / zoomscale;
+  expand_out = (int) zoomscale;
+  expand_in  = 1;
+
+  /*
+  dx = layout[0].zoom.dx;
+  dy = layout[0].zoom.dy;
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[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*layout[0].matrix.Naxis[0] - expand*((int)(0.5*layout[0].zoom.dx + 0.5) - 0.0) - layout[0].X;
+  Y = 0.5*layout[0].matrix.Naxis[1] - expand*((int)(0.5*layout[0].zoom.dy + 0.5) - 0.0) - layout[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 = layout[0].zoom.data;
+  in_pix  = (char *) (layout[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  */
+
+  dx = layout[0].zoom.dx;
+  dy = layout[0].zoom.dy;
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[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 = (char *) layout[0].zoom.data;
+  in_pix  = (char *) (layout[0].matrix.buffer) + 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 = white;
+    return;
+  } 
+  
+  /**** fill in bottom area ****/
+  for (j = 0; j < dx*j_start; j++, out_pix++) 
+    *out_pix = white;
+  
+  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 = white;
+      }
+    }
+    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 {
+      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 = white;
+      }
+    }
+    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 - layout[0].zoom.data < dx*dy); j++, out_pix++) { 
+    *out_pix = white;
+  }
+
+  layout[0].zoom.pix = XCreateImage (graphic[0].display, graphic[0].visual, graphic[0].depth, ZPixmap, 0, 
+					layout[0].zoom.data, layout[0].zoom.dx, layout[0].zoom.dy, 8, 0);
+  
+}
Index: /trunk/Ohana/src/kii/zoom/CrossHairs.c
===================================================================
--- /trunk/Ohana/src/kii/zoom/CrossHairs.c	(revision 2466)
+++ /trunk/Ohana/src/kii/zoom/CrossHairs.c	(revision 2466)
@@ -0,0 +1,66 @@
+# include "Ximage.h"
+
+void CrossHairs (Graphic *graphic, Layout *layout) {
+
+  int x0, x1, x5, x7;
+  int y0, y2, y4, y5;
+  double zoomscale;
+
+  zoomscale = MAX (5, layout[0].expand + 5);
+  x0 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale - 2.5) + layout[0].zoom.x;
+  x5 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale - 0.5) + layout[0].zoom.x;
+  x7 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale + 0.5) + layout[0].zoom.x;
+  x1 = (zoomscale) * (0.5 * (ZOOM_X + 1) / zoomscale + 2.5) + layout[0].zoom.x;
+						    	 
+  y4 = (zoomscale) * (0.5 * (ZOOM_Y + 1) / zoomscale - 2.5) + layout[0].zoom.y;
+  y2 = (zoomscale) * (0.5 * (ZOOM_Y + 1) / zoomscale - 0.5) + layout[0].zoom.y;
+  y0 = (zoomscale) * (0.5 * (ZOOM_Y + 1) / zoomscale + 0.5) + layout[0].zoom.y;
+  y5 = (zoomscale) * (0.5 * (ZOOM_Y + 1) / zoomscale + 2.5) + layout[0].zoom.y;
+
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x0, y0, x5, y0);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x5, y0, x5, y5);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7, y5, x7, y0);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7, y0, x1, y0);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x0, y2, x5, y2);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x5, y2, x5, y4);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7, y4, x7, y2);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7, y2, x1, y2);
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x0, y0+1, x5-1, y0+1);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x5-1, y0+1, x5-1, y5);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7+1, y5, x7+1, y0+1);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7+1, y0+1, x1, y0+1);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x0, y2-1, x5-1, y2-1);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x5-1, y2-1, x5-1, y4);
+
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7+1, y4, x7+1, y2-1);
+  XDrawLine (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	     x7+1, y2-1, x1, y2-1);
+
+  XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+
+}
Index: /trunk/Ohana/src/kii/zoom/UpdatePointer.c
===================================================================
--- /trunk/Ohana/src/kii/zoom/UpdatePointer.c	(revision 2466)
+++ /trunk/Ohana/src/kii/zoom/UpdatePointer.c	(revision 2466)
@@ -0,0 +1,58 @@
+# include "Ximage.h"
+# define FRAC(a) ((a) - (int)(a))
+
+int UpdatePointer (Graphic *graphic, Layout *layout, XMotionEvent *event) {
+
+  int textpad;
+  double  x, y, z;
+  char line[100];
+
+  if (MOVE_POINTER && InPicture ((XButtonEvent *)event, &layout[0].picture)) {
+
+    Screen_to_Image (&x, &y, (double)event[0].x, (double)event[0].y, layout);
+
+    if ((x >= 0) && (x < layout[0].matrix.Naxis[0]) && (y >= 0) && (y < layout[0].matrix.Naxis[1])) {
+      /*
+      X = event[0].x - layout[0].picture.x;
+      Y = event[0].y - layout[0].picture.y;
+      pix = MIN (MAX (X + Y*layout[0].picture.dx, 0), layout[0].picture.dx*layout[0].picture.dy - 1);
+      z = layout[0].range * layout[0].picture.data[pix] / layout[0].Npixels + layout[0].zero;
+      */
+      z = -1;
+    }
+    else
+      z = -1;
+    layout[0].x = x;
+    layout[0].y = y;
+    layout[0].z = z;
+    
+    UpdateStatusBox (graphic, layout, x, y, z, 0);
+    XFlush (graphic[0].display);
+      
+    CreateZoom (layout, graphic, x, y);  
+    XPutImage (graphic[0].display, graphic[0].window, graphic[0].gc,
+	       layout[0].zoom.pix, 0, 0, 
+	       layout[0].zoom.x, layout[0].zoom.y, 
+	       layout[0].zoom.dx, layout[0].zoom.dy);
+    CrossHairs (graphic, layout);
+    XFlush (graphic[0].display);
+    
+  }
+  
+  if (InPicture ((XButtonEvent *)event, &layout[0].cmapbar)) {
+    z = layout[0].zero  + layout[0].range * (event[0].x - layout[0].cmapbar.x) / layout[0].cmapbar.dx;
+    textpad = graphic[0].font[0].ascent;
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
+                  layout[0].text_x + 1, layout[0].text_y + 1, ZOOM_X - 2, textpad + PAD1 + 1);
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+    bzero (line, 100);
+    sprintf (line, "%25.2f", z);
+    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+                 layout[0].text_x + PAD1, layout[0].text_y + textpad + PAD1, 
+		 line, strlen(line));
+    
+  }
+
+  return (TRUE);
+}
Index: /trunk/Ohana/src/kii/zoom/UpdateStatusBox.c
===================================================================
--- /trunk/Ohana/src/kii/zoom/UpdateStatusBox.c	(revision 2466)
+++ /trunk/Ohana/src/kii/zoom/UpdateStatusBox.c	(revision 2466)
@@ -0,0 +1,63 @@
+# include "Ximage.h"
+
+void UpdateStatusBox (Graphic *graphic, Layout *layout, double x, double y, double z, int mode) {
+
+  int textpad;
+  double ra, dec; 
+  char line[100];
+
+  XY_to_RD (&ra, &dec, x, y, &layout[0].coords);
+
+  textpad = graphic[0].font[0].ascent;
+
+  if (mode) {
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
+		    layout[0].text_x, layout[0].text_y, ZOOM_X, 6*textpad+7*PAD1);  
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+    XDrawRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
+		    layout[0].text_x, layout[0].text_y, ZOOM_X, 6*textpad+7*PAD1);
+  
+    bzero (line, 100);
+    sprintf (line, "(%d x %d) @ %d                                         ", 
+	     layout[0].picture.dx, layout[0].picture.dy, layout[0].expand); 
+    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		 layout[0].text_x + PAD1, layout[0].text_y + 4*textpad + 4*PAD1, line, 25);
+    
+    bzero (line, 100);
+    sprintf (line, "%-25s", layout[0].file); 
+    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		 layout[0].text_x + PAD1, layout[0].text_y + 5*textpad + 5*PAD1, line, strlen(line));
+    
+    bzero (line, 100);
+    sprintf (line, "(%s)                                          ", layout[0].buffer_name); 
+    XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+		 layout[0].text_x + PAD1, layout[0].text_y + 6*textpad + 6*PAD1, line, 25);
+    
+  } else {
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].white);
+    XFillRectangle (graphic[0].display, graphic[0].window, graphic[0].gc,
+		    layout[0].text_x + 1, layout[0].text_y + 1, ZOOM_X - 2, 3*textpad+3*PAD1 +1);  
+    XSetForeground (graphic[0].display, graphic[0].gc, graphic[0].black);
+  }
+  bzero (line, 100);
+  sprintf (line, "%25.3f", z);
+  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	       layout[0].text_x + PAD1, layout[0].text_y + textpad + PAD1, line, strlen(line));
+  
+  bzero (line, 100);
+  sprintf (line, "%12.1f %12.1f", x, y);
+  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	       layout[0].text_x + PAD1, layout[0].text_y + 2*textpad + 2*PAD1, line, strlen(line));
+  
+  bzero (line, 100);
+  if (DECIMAL_DEG) {
+    sprintf (line, "%12.6f %12.6f", ra, dec); 
+  } else {
+    hh_hms (line, ra, dec, ':');
+  }
+  XDrawString (graphic[0].display, graphic[0].window, graphic[0].gc, 
+	       layout[0].text_x + PAD1, layout[0].text_y + 3*textpad + 3*PAD1, line, strlen(line));
+  
+ 
+}
