Index: /trunk/Ohana/src/kii/Makefile
===================================================================
--- /trunk/Ohana/src/kii/Makefile	(revision 5699)
+++ /trunk/Ohana/src/kii/Makefile	(revision 5700)
@@ -50,6 +50,10 @@
 $(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
+$(ODIR)/DrawOverlay.$(ARCH).o		  $(ODIR)/CSaveOverlay.$(ARCH).o       \
+$(ODIR)/PaintTickmarks.$(ARCH).o          $(ODIR)/LoadTickmarks.$(ARCH).o      \
+$(ODIR)/bDrawColormap.$(ARCH).o           $(ODIR)/bDrawOverlay.$(ARCH).o       \
+$(ODIR)/bDrawFuncs.$(ARCH).o 		  $(ODIR)/bDrawRotFont.$(ARCH).o       \
+$(ODIR)/RotFont.$(ARCH).o
+
 
 POBJ = \
@@ -57,9 +61,9 @@
 $(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
+$(PDIR)/Remap16.$(ARCH).o		  $(PDIR)/JPEGit24.$(ARCH).o            \
+$(PDIR)/cursor.$(ARCH).o
 
 SOBJ = \
@@ -75,5 +79,6 @@
 $(SDIR)/LoadFont.$(ARCH).o          	  $(SDIR)/TopWindow.$(ARCH).o          \
 $(SDIR)/MakeColormap.$(ARCH).o      	  $(SDIR)/Ximage.$(ARCH).o             \
-$(SDIR)/MakeCursor.$(ARCH).o              $(SDIR)/CheckVisual.$(ARCH).o
+$(SDIR)/MakeCursor.$(ARCH).o              $(SDIR)/CheckVisual.$(ARCH).o	       \
+$(SDIR)/args.$(ARCH).o
 
 ZOBJ = \
Index: /trunk/Ohana/src/kii/button/ButtonFunctions.c
===================================================================
--- /trunk/Ohana/src/kii/button/ButtonFunctions.c	(revision 5699)
+++ /trunk/Ohana/src/kii/button/ButtonFunctions.c	(revision 5700)
@@ -12,4 +12,6 @@
   Remap (graphic, layout, &layout[0].matrix);
   CreateZoom (layout, graphic, 0, 0); 
+  Refresh (graphic, layout, 0);
+  XFlush (graphic[0].display);
   return (TRUE);
 }
@@ -22,4 +24,6 @@
   Remap (graphic, layout, &layout[0].matrix);
   CreateZoom (layout, graphic, 0, 0); 
+  Refresh (graphic, layout, 0);
+  XFlush (graphic[0].display);
   return (TRUE);
 }
@@ -32,4 +36,6 @@
   Remap (graphic, layout, &layout[0].matrix);
   CreateZoom (layout, graphic, 0, 0); 
+  Refresh (graphic, layout, 0);
+  XFlush (graphic[0].display);
   return (TRUE);
 }
Index: /trunk/Ohana/src/kii/button/PSit.c
===================================================================
--- /trunk/Ohana/src/kii/button/PSit.c	(revision 5699)
+++ /trunk/Ohana/src/kii/button/PSit.c	(revision 5700)
@@ -27,4 +27,9 @@
   }
   
+  if (!USE_XWINDOW) {
+    fprintf (stderr, "PS not working yet\n");
+    return (TRUE);
+  }
+
   scale = MIN ((500.0/(double)layout[0].picture.dx), (700.0/(double)layout[0].picture.dy));
   if (!Raw) {
@@ -63,4 +68,5 @@
 
   /******** First we draw the picture itself ********/
+  /* in !USE_XWINDOW, we'll have to change this to use the JPEG function */
   switch (graphic[0].Nbits) {
   case 8:
@@ -107,4 +113,131 @@
 }
 
+void ConvertPixmap (Layout *layout, File *f) {
+  
+  /* set up expansions */
+  expand = expand_in = expand_out = 1.0;
+  if (layout[0].expand == 0)
+    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 = layout[0].matrix.Naxis[0];
+  DY = layout[0].matrix.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;
+
+  /* output line buffer */
+  ALLOCATE (line_buffer, char, dx);
+
+  in_pix_ref  = (unsigned char *) (layout[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+
+  /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
+
+  Nchar = 255.0;
+  Npix = layout[0].Npixels;
+  frac = Nchar / Npix;
+
+  /**** fill in bottom area ****/
+  out_pix = line_buffer;
+  for (i = 0; i < dx; i++, out_pix++) {
+    *out_pix = WHITE;
+  }
+  for (j = 0; j < j_start; j++) {
+    for (i = 0; i < dx; i++) {
+      fprintf (f, "%02x", val);
+      if ((Npt % 40) == 0) {
+	fprintf (f, "\n");
+      }
+    }
+  }
+  
+  /*** fill in the image data region ***/
+  for (j = j_start; j < j_end; j+= expand_out, in_pix_ref += expand_in*DX) {
+    
+    /* create one output image line */
+    in_pix = in_pix_ref;
+    out_pix = line_buffer;
+
+    /**** fill in area to the left of the picture ****/
+    for (i = 0; i < i_start; i++, out_pix+=3) {
+      *out_pix = WHITE;
+    }
+    
+    /*** fill in the picture region ***/
+    for (i = i_start; i < i_end; i+=expand_out, in_pix+=expand_in) {
+      for (ii = 0; ii < expand_out; ii++, out_pix++) {
+	*out_pix = *in_pix*frac;
+      }
+    }
+    
+    /**** fill in area to the right of the picture ****/
+    for (i = i_end; i < dx; i++, out_pix++) {
+      *out_pix = WHITE;
+    }
+
+    /* write out the image line expand_out times */
+    for (j = 0; j < expand_out; j++) {
+      for (i = 0; i < dx; i++) {
+	fprintf (f, "%02x", val);
+	if ((Npt % 40) == 0) {
+	  fprintf (f, "\n");
+	}
+      }
+    }
+  }
+
+  /**** fill in top area ****/
+  out_pix = line_buffer;
+  for (i = 0; i < dx; i++, out_pix++) { 
+    *out_pix = WHITE;
+  }
+  for (j = j_end; j < dy; j++) {
+    for (i = 0; i < dx; i++) {
+      fprintf (f, "%02x", val);
+      if ((Npt % 40) == 0) {
+	fprintf (f, "\n");
+      }
+    }
+  }
+}
+
 void ConvertPixmap8 (Layout *layout, FILE *f) {
 
Index: /trunk/Ohana/src/kii/colorbar/SetColormap.c
===================================================================
--- /trunk/Ohana/src/kii/colorbar/SetColormap.c	(revision 5699)
+++ /trunk/Ohana/src/kii/colorbar/SetColormap.c	(revision 5700)
@@ -1,3 +1,6 @@
 # include "Ximage.h"
+
+/*** this function uses only private colormaps.  it should try the standard colormap
+     first to get better control over the smooth greyscales ***/
 
 int SetColormap (Graphic *graphic, Layout *layout, char *name) {
@@ -7,4 +10,5 @@
   /* greyscale */
   if ((!strcmp (name, "grayscale")) || (!strcmp (name, "greyscale"))) {
+    fprintf (stderr, "setting greyscale : %d\n", layout[0].Npixels);
     for (i = 0; i < layout[0].Npixels; i++) {  
       layout[0].cmap[i].red = 256*(255 - 255*i/layout[0].Npixels);
@@ -84,11 +88,15 @@
 
  store_colors:
+  if (!USE_XWINDOW) return (TRUE);
   if (graphic[0].visualclass) {
+    fprintf (stderr, "storing colors\n");
     XStoreColors(graphic[0].display, graphic[0].colormap, layout[0].cmap, layout[0].Npixels);
   } else {
     for (i = 0; i < layout[0].Npixels; i++) {
+      fprintf (stderr, "%04x %04x %04x  ->  ", layout[0].cmap[i].red, layout[0].cmap[i].green, layout[0].cmap[i].blue);
       if (XAllocColor (graphic[0].display, graphic[0].colormap, &layout[0].cmap[i]) == 0) {
 	fprintf (stderr, "error on %d\n", i);
       }
+      fprintf (stderr, "%04x %04x %04x\n", layout[0].cmap[i].red, layout[0].cmap[i].green, layout[0].cmap[i].blue);
     }
   }
Index: /trunk/Ohana/src/kii/event/CheckPipe.c
===================================================================
--- /trunk/Ohana/src/kii/event/CheckPipe.c	(revision 5699)
+++ /trunk/Ohana/src/kii/event/CheckPipe.c	(revision 5700)
@@ -89,4 +89,5 @@
 
   if (!strcmp (buffer, "PSIT")) {
+    /** this one needs work : ConvertPixmapN fails for !USE_XWINDOW */
     status = PSit (graphic, layout, 0);
     write (layout[0].Ximage, "DONE", 4);
@@ -95,4 +96,5 @@
 
   if (!strcmp (buffer, "PSRW")) {
+    /** this one needs work : ConvertPixmapN fails for !USE_XWINDOW */
     status = PSit (graphic, layout, 1);
     write (layout[0].Ximage, "DONE", 4);
Index: /trunk/Ohana/src/kii/include/alphabet.h
===================================================================
--- /trunk/Ohana/src/kii/include/alphabet.h	(revision 5700)
+++ /trunk/Ohana/src/kii/include/alphabet.h	(revision 5700)
@@ -0,0 +1,53 @@
+# include "../rotfont/times8.h"
+# include "../rotfont/times12.h"
+# include "../rotfont/times14.h"
+# include "../rotfont/times18.h"
+# include "../rotfont/times24.h"
+
+# include "../rotfont/courier8.h"
+# include "../rotfont/courier12.h"
+# include "../rotfont/courier14.h"
+# include "../rotfont/courier18.h"
+# include "../rotfont/courier24.h"
+
+# include "../rotfont/helvetica8.h"
+# include "../rotfont/helvetica12.h"
+# include "../rotfont/helvetica14.h"
+# include "../rotfont/helvetica18.h"
+# include "../rotfont/helvetica24.h"
+
+# include "../rotfont/symbol8.h"
+# include "../rotfont/symbol12.h"
+# include "../rotfont/symbol14.h"
+# include "../rotfont/symbol18.h"
+# include "../rotfont/symbol24.h"
+
+# define DEFFONT 1
+static FontSet HardwiredFonts[] = {
+  {times8font,  "times", 8},
+  {times12font, "times", 12},
+  {times14font, "times", 14},
+  {times18font, "times", 18},
+  {times24font, "times", 24},
+  
+  {courier8font,  "courier", 8},
+  {courier12font, "courier", 12},
+  {courier14font, "courier", 14},
+  {courier18font, "courier", 18},
+  {courier24font, "courier", 24},
+  
+  {helvetica8font,  "helvetica", 8},
+  {helvetica12font, "helvetica", 12},
+  {helvetica14font, "helvetica", 14},
+  {helvetica18font, "helvetica", 18},
+  {helvetica24font, "helvetica", 24},
+  
+  {symbol8font,  "symbol", 8},
+  {symbol12font, "symbol", 12},
+  {symbol14font, "symbol", 14},
+  {symbol18font, "symbol", 18},
+  {symbol24font, "symbol", 24}
+};
+
+/* put these as static in RotFont.c with accessor functions */
+# define NROT 256
Index: /trunk/Ohana/src/kii/include/bDraw.h
===================================================================
--- /trunk/Ohana/src/kii/include/bDraw.h	(revision 5700)
+++ /trunk/Ohana/src/kii/include/bDraw.h	(revision 5700)
@@ -0,0 +1,51 @@
+# include <png.h>
+
+typedef png_byte bDrawColor;
+
+typedef struct {
+  int Nx, Ny;
+  bDrawColor **pixels;
+} bDrawBuffer;
+
+# if (0)
+int bDrawObjects (Layout *layout);
+void bDrawConnect (Layout *layout, Gobjects *object);
+void bDrawClipLine (double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0);
+void bDrawHistogram (Layout *layout, Gobjects *object);
+void bDrawPoints (Layout *layout, Gobjects *object);
+void bDrawXErrors (Layout *layout, Gobjects *object);
+void bDrawYErrors (Layout *layout, Gobjects *object);
+int bDrawFrame (Layout *layout);
+void bDrawTick (double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int mode, int naxis);
+void bDrawLabels (Layout *layout);
+void bDrawPtext (Layout *layout);
+# endif
+
+bDrawBuffer *bDrawBufferCreate (int Nx, int Ny);
+void bDrawBufferFree (bDrawBuffer *buffer);
+void bDrawSetBuffer (bDrawBuffer *buffer);
+void bDrawSetStyle (bDrawColor color, int lw, int lt);
+void bDrawPoint (int x, int y);
+void bDrawPointf (float x, float y);
+
+void bDrawArc (double Xc, double Yc, double Xr, double Yr, double Ts, double Te);
+void bDrawCircle (double Xc, double Yc, double radius);
+void bDrawCircleFill (double xc, double yc, double radius);
+
+void bDrawLine (double x1, double y1, double x2, double y2);
+void bDrawLineWeight (int X1, int Y1, int X2, int Y2, int swapcoords);
+void bDrawLineBresen (int X1, int Y1, int X2, int Y2, int swapcoords);
+void bDrawLineHorizontal (int X1, int X2, int Y);
+void bDrawLineVertical (int X, int Y1, int Y2);
+
+png_color *MakePNGPalette (int *Npalette);
+bDrawColor GetColorByName (char *name);
+bDrawBuffer *bDrawIt ();
+
+void bDrawRectOpen (double x1, double y1, double x2, double y2);
+void bDrawRectFill (double x1, double y1, double x2, double y2);
+void bDrawTriOpen (double x1, double y1, double x2, double y2, double x3, double y3);
+void bDrawTriFill (double x1, double y1, double x2, double y2, double x3, double y3);
+int bDrawRotText (int x, int y, char *string, int pos, double angle);
+int bDrawRotBitmap (int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale);
+
Index: /trunk/Ohana/src/kii/include/constants.h
===================================================================
--- /trunk/Ohana/src/kii/include/constants.h	(revision 5699)
+++ /trunk/Ohana/src/kii/include/constants.h	(revision 5700)
@@ -25,4 +25,6 @@
 int DECIMAL_DEG;
 int DEBUG;
+int USE_XWINDOW;
+int MAP_WINDOW;
 
 # define EVENT_MASK (long) \
Index: /trunk/Ohana/src/kii/include/structures.h
===================================================================
--- /trunk/Ohana/src/kii/include/structures.h	(revision 5699)
+++ /trunk/Ohana/src/kii/include/structures.h	(revision 5700)
@@ -124,4 +124,14 @@
 } Layout;
 
+typedef struct {
+  int dx, dy, ascent;
+  unsigned char *bits;
+} RotFont;
+
+typedef struct {
+  RotFont *font;
+  char name[64];
+  int size;
+} FontSet;
 
 /* 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 5699)
+++ /trunk/Ohana/src/kii/overlay/EraseOverlay.c	(revision 5700)
@@ -24,6 +24,7 @@
   }
 
+  if (USE_XWINDOW) Refresh (graphic, layout, 0);
+
   fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
-  Refresh (graphic, layout, 0);
   return (TRUE);
 }
Index: /trunk/Ohana/src/kii/overlay/LoadOverlay.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/LoadOverlay.c	(revision 5699)
+++ /trunk/Ohana/src/kii/overlay/LoadOverlay.c	(revision 5700)
@@ -88,10 +88,12 @@
   OVERLAY[N] = TRUE;
   /*  Refresh (graphic, layout, 0); */
-  for (i = 0; i < NOVERLAYS; i++) {
-    if (OVERLAY[i])
-      PaintOverlay (graphic, layout, i);
+  if (USE_XWINDOW) {
+    for (i = 0; i < NOVERLAYS; i++) {
+      if (OVERLAY[i])
+	PaintOverlay (graphic, layout, i);
+    }
+    PaintTickmarks (graphic, layout);
+    XFlush (graphic[0].display);
   }
-  PaintTickmarks (graphic, layout);
-  XFlush (graphic[0].display);
   fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
   return (TRUE);
Index: /trunk/Ohana/src/kii/overlay/LoadTickmarks.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/LoadTickmarks.c	(revision 5699)
+++ /trunk/Ohana/src/kii/overlay/LoadTickmarks.c	(revision 5700)
@@ -55,5 +55,6 @@
   layout[0].tickmarks.Nobjects = Nobjects;
 
-  Refresh (graphic, layout, 0);
+  if (USE_XWINDOW) Refresh (graphic, layout, 0);
+
   fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
   return (TRUE);
Index: /trunk/Ohana/src/kii/overlay/RotFont.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/RotFont.c	(revision 5700)
+++ /trunk/Ohana/src/kii/overlay/RotFont.c	(revision 5700)
@@ -0,0 +1,124 @@
+# include "Ximage.h"
+# include "alphabet.h"
+  
+static int Nrotfonts;
+static FontSet *RotFonts;
+
+static char currentname[64];
+static int  currentsize;
+static double currentscale;
+static RotFont *currentfont;
+
+void InitRotFonts () {
+
+  int i, Nhardwired;
+
+  Nhardwired = sizeof (HardwiredFonts) / sizeof (FontSet);
+  
+  Nrotfonts = Nhardwired;
+  ALLOCATE (RotFonts, FontSet, Nrotfonts);
+  
+  for (i = 0; i < Nhardwired; i++) {
+    RotFonts[i] = HardwiredFonts[i];
+  }
+
+  currentfont = RotFonts[DEFFONT].font;
+  currentscale = 1.0;
+  strcpy (currentname, RotFonts[DEFFONT].name);
+  currentsize = RotFonts[DEFFONT].size;
+}
+
+int SetRotFont (char *name, int size) {
+  
+  int i, nsize, msize, bsize, bigger, dsize, match, good;
+
+  bigger = good = match = -1;
+  dsize = 10000;
+  bsize = 10000;
+  for (i = 0; i < Nrotfonts; i++) {
+    if (!strcasecmp (RotFonts[i].name, name)) {
+      good = i;
+      nsize = abs (RotFonts[i].size - size);
+      if (nsize < dsize) {
+	match = i;
+	dsize = nsize;
+      }
+      msize = RotFonts[i].size - size;
+      if ((msize < bsize) && (msize >= 0)) {
+	bigger = i;
+	bsize = msize;
+      }
+    }
+  }
+  
+  if ((match == -1) && (good != -1)) match = good;
+  if (bigger != -1) match = bigger;
+  if (match != -1) {
+    currentfont = RotFonts[match].font;
+    currentscale = (double) size / RotFonts[match].size;
+    currentsize = size;
+    strcpy (currentname, name);
+    return (TRUE);
+  } else {
+    fprintf (stderr, "no matching font\n");
+    return (FALSE);
+  }
+
+}
+  
+char *GetRotFont (int *size) {
+
+  *size = currentsize;
+  return (currentname);
+
+}
+
+RotFont *GetRotFontData (double *scale) {
+  *scale = currentscale;
+  return (currentfont);
+}
+
+int RotStrlen (char *c) {
+
+  int i, N, dX, code;
+  double scale; 
+  
+  scale = currentscale;
+
+  /* find string length */
+  dX = 0;
+
+  code = FALSE;
+  for (i = 0; i < strlen (c); i++) {
+    N = (int)(c[i]);
+    /* skip non-printing characters */
+    if ((N < 0) || (N >= NROT)) continue;
+
+    /* check for special characters */
+    if (!code) {
+      if (N == 94) { /* super-script */
+	scale *= 0.8;
+	continue;
+      }
+      if (N == 95) { /* sub-script */
+	scale *= 0.8;
+	continue;
+      }
+      if (N == 124) { /* normal-script */
+	scale = currentscale;
+	continue;
+      }
+      if (N == 92) { /* backslash */
+	code = TRUE;
+	continue;
+      } 
+      if (N == 38) { /* font-code */
+	i++;
+	continue;
+      }
+    }
+    code = FALSE;
+    dX += scale*currentfont[N].dx + 1;
+  }
+  return (dX);
+}
Index: /trunk/Ohana/src/kii/overlay/bDrawColormap.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/bDrawColormap.c	(revision 5700)
+++ /trunk/Ohana/src/kii/overlay/bDrawColormap.c	(revision 5700)
@@ -0,0 +1,73 @@
+# include "Ximage.h"
+# include "bDraw.h"
+
+/* this list must match the one in mana/include/package.h, and equiv
+ * we need to define library calls to the kapa and kii packages which mana
+ * and other programs would link against.  This would allow them to have 
+ * access to the list of available colors.  Or... we need to have mana, etc
+ * query kapa/kii about it list of colors...
+ */
+
+/* the three columns here are : (opihi name) : (X11 name) : (PostScript coordinate) */
+# define NGRAPHCOLORS 23
+static char GRAPHCOLORS[NGRAPHCOLORS][3][16] = {
+{"black",    	 "black",    	 "0.00 0.00 0.00"}, 
+{"white",    	 "white",    	 "1.00 1.00 1.00"}, 
+{"red",      	 "red",      	 "1.00 0.00 0.00"}, 
+{"pink",     	 "pink",     	 "1.00 0.75 0.80"}, 
+{"orange",   	 "orange",   	 "1.00 0.65 0.00"}, 
+{"yellow",   	 "yellow",   	 "1.00 1.00 0.00"}, 
+{"wheat",    	 "wheat",    	 "0.96 0.87 0.70"}, 
+{"gold",     	 "gold",     	 "1.00 0.84 0.00"}, 
+{"green",    	 "green",    	 "0.00 1.00 0.00"}, 
+{"darkgreen",	 "darkgreen",	 "0.00 0.40 0.00"}, 
+{"blue",     	 "blue",     	 "0.00 0.00 1.00"}, 
+{"skyblue",  	 "skyblue",  	 "0.53 0.81 0.92"}, 
+{"indigo",   	 "mediumpurple", "0.57 0.44 0.86"}, 
+{"violet",   	 "darkviolet", 	 "0.58 0.00 0.88"},
+{"grey10",   	 "grey10",   	 "0.10 0.10 0.10"},
+{"grey20",   	 "grey20",   	 "0.20 0.20 0.20"},
+{"grey30",   	 "grey30",   	 "0.30 0.30 0.30"},
+{"grey40",   	 "grey40",   	 "0.40 0.40 0.40"},
+{"grey50",   	 "grey50",   	 "0.50 0.50 0.50"},
+{"grey60",   	 "grey60",   	 "0.60 0.60 0.60"},
+{"grey70",   	 "grey70",   	 "0.70 0.70 0.70"},
+{"grey80",   	 "grey80",   	 "0.80 0.80 0.80"},
+{"grey90",   	 "grey90",   	 "0.90 0.90 0.90"}};
+
+png_color *MakePNGPalette (int *Npalette) {
+
+  int i;
+  float red, green, blue;
+  png_color *palette;
+
+  ALLOCATE (palette, png_color, NGRAPHCOLORS);
+
+  /* define the palette */
+  for (i = 0; i < NGRAPHCOLORS; i++) {
+    sscanf (GRAPHCOLORS[i][2], "%f %f %f", &red, &green, &blue);
+    palette[i].red = (0xff * red);
+    palette[i].green = (0xff * green);
+    palette[i].blue = (0xff * blue);
+  }
+  *Npalette = NGRAPHCOLORS;
+  return (palette);
+}
+
+/* default to black */
+bDrawColor GetColorByName (char *name) {
+
+  bDrawColor i;
+
+  for (i = 0; i < NGRAPHCOLORS; i++) {
+    if (!strcasecmp (name, GRAPHCOLORS[i][0])) return (i);
+  }
+  return (0);
+}
+
+/*
+
+kapa objects, bDraw, and png all use the same pallete sequence, defined by
+GRAPHCOLORS above.  the color correspond to a color sequence.  
+
+*/
Index: /trunk/Ohana/src/kii/overlay/bDrawFrame.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/bDrawFrame.c	(revision 5700)
+++ /trunk/Ohana/src/kii/overlay/bDrawFrame.c	(revision 5700)
@@ -0,0 +1,90 @@
+# include "Ximage.h"
+# include "bDraw.h"
+
+int bDrawFrame (Layout *layout) {
+  
+  int i, P, IsLabel, fontsize;
+  double fx, fy, dfx, dfy, range, major, minor, first, next;
+  char *fontname;
+
+  /* each axis is drawn independently */
+  fontname = GetRotFont (&fontsize);
+  for (i = 0; i < 4; i++) {
+    fx  = layout[0].axis[i].fx;
+    fy  = layout[0].axis[i].fy;
+    dfx = layout[0].axis[i].dfx;
+    dfy = layout[0].axis[i].dfy;
+    P = hypot ((double)layout[0].axis[(i+1)%2].dfx, (double)layout[0].axis[(i+1)%2].dfy);
+
+    if (layout[0].axis[i].isaxis) { 
+      bDrawLine (fx, fy, fx+dfx, fy+dfy); 
+    }
+    
+    if (layout[0].axis[i].areticks) {
+      range = layout[0].axis[i].max - layout[0].axis[i].min;
+
+      AxisTickScale (&layout[0].axis[i], &major, &minor);
+
+      first = minor*((int)(layout[0].axis[i].min/minor));
+      if ((range > 0) && (first < layout[0].axis[i].min)) {
+	first += minor;
+      }
+      if ((range < 0) && (first > layout[0].axis[i].min)) {
+	first -= minor;
+      }
+      for (next = first; ((range > 0) && (next <= layout[0].axis[i].max)) || ((range < 0) && (next >= layout[0].axis[i].max));) {
+	IsLabel = FALSE;
+	if ((fabs((int)(next/major) - (next/major)) < 0.5*(minor/major)) || 
+	    (fabs ((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major)) ||
+	    (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major)))
+	  IsLabel = layout[0].axis[i].islabel;
+	bDrawTick (fx, fy, dfx, dfy, P, layout[0].axis[i].min, layout[0].axis[i].max, next, IsLabel, i);
+	if (range > 0) 
+	  next += minor;
+	else 
+	  next -= minor;
+      }
+    }
+  }
+  return (TRUE);
+}
+
+void bDrawTick (double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int mode, int naxis) {
+  
+  int pos, dir, fontsize;
+  double size, n, x, y, dx, dy;
+  char string[64], *fontname;
+
+  pos = size = 0;
+
+  if (mode == 1) { size = MAX (0.02, 7.0 / P); }
+  if (mode == 0) { size = MAX (0.01, 4.0 / P); }
+  
+  n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
+  x = fx + (value-min)*dfx/(max - min);
+  y = fy + (value-min)*dfy/(max - min);
+
+  dir = +1;
+  if ((naxis == 0) || (naxis == 1)) dir *= -1;
+  dx = dir*size*dfy*n;	
+  dy = dir*size*dfx*n;
+  
+  bDrawLine (x, y, x+dx, y+dy);
+
+  if (mode == 1) {
+    fontname = GetRotFont (&fontsize);
+
+    /* temporarily assume rectilinear axes */
+    if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
+    if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
+
+    if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
+    if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
+
+    x = fx + (value-min)*dfx/(max - min) + dx;
+    y = fy + (value-min)*dfy/(max - min) + dy;
+    if (fabs(value) < 1e-14) { value = 0.0; }
+    sprintf (string, "%g", value);
+    bDrawRotText ((int)x, (int)y, string, pos, 0.0);
+  }
+}
Index: /trunk/Ohana/src/kii/overlay/bDrawFuncs.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/bDrawFuncs.c	(revision 5700)
+++ /trunk/Ohana/src/kii/overlay/bDrawFuncs.c	(revision 5700)
@@ -0,0 +1,418 @@
+# include "Ximage.h"
+# include "bDraw.h"
+
+static int bWeight;
+static int bType;
+static bDrawColor bColor;
+static bDrawBuffer *bBuffer;
+
+bDrawBuffer *bDrawBufferCreate (int Nx, int Ny) {
+
+  int i, j;
+  bDrawColor white;
+  bDrawBuffer *buffer;
+
+  white = GetColorByName ("white");
+
+  ALLOCATE (buffer, bDrawBuffer, 1);
+  buffer[0].Nx = Nx;
+  buffer[0].Ny = Ny;
+
+  ALLOCATE (buffer[0].pixels, bDrawColor *, Ny);
+  for (i = 0; i < Ny; i++) {
+    ALLOCATE (buffer[0].pixels[i], bDrawColor, Nx);
+    for (j = 0; j < Nx; j++) {
+      buffer[0].pixels[i][j] = white;
+    }
+  }
+  return (buffer);
+}
+
+void bDrawBufferFree (bDrawBuffer *buffer) {
+
+  int i;
+
+  for (i = 0; i < buffer[0].Ny; i++) {
+    free (buffer[0].pixels[i]);
+  }
+  free (buffer[0].pixels);
+  free (buffer);
+  return;
+}
+
+void bDrawSetBuffer (bDrawBuffer *buffer) {
+  bBuffer = buffer;
+  return;
+}
+
+void bDrawSetStyle (bDrawColor color, int lw, int lt) {
+  bColor = color;
+  bWeight = lw;
+  bType = lt;
+  return;
+}
+
+// draw a point in the current color 
+void bDrawPoint (int x, int y) {
+
+  if (x < 0) return;
+  if (y < 0) return;
+  if (x >= bBuffer[0].Nx) return;
+  if (y >= bBuffer[0].Ny) return;
+  bBuffer[0].pixels[y][x] = bColor;
+  return;
+}
+
+// draw a point in the current color 
+void bDrawPointf (float x, float y) {
+
+  bDrawPoint (ROUND(x), ROUND(y));
+  return;
+}
+
+void bDrawTriOpen (double x1, double y1, double x2, double y2, double x3, double y3) {
+
+  bDrawLine (x1, y1, x2, y2);
+  bDrawLine (x2, y2, x3, y3);
+  bDrawLine (x3, y3, x1, y1);
+
+  return;
+}
+
+void bDrawRectOpen (double x1, double y1, double x2, double y2) {
+
+  int X1, Y1, X2, Y2;
+
+  if (x1 > x2) SWAP (x1, x2);
+  if (y1 > y2) SWAP (y1, y2);
+
+  X1 = MIN (MAX (ROUND (x1), 0), bBuffer[0].Nx - 1);
+  X2 = MIN (MAX (ROUND (x2), 1), bBuffer[0].Nx);
+
+  Y1 = MIN (MAX (ROUND (y1), 0), bBuffer[0].Ny - 1);
+  Y2 = MIN (MAX (ROUND (y2), 1), bBuffer[0].Ny);
+
+  bDrawLineHorizontal (X1, X2, Y1);
+  bDrawLineHorizontal (X1, X2, Y2);
+  bDrawLineVertical (X1, Y1, Y2);
+  bDrawLineVertical (X2, Y1, Y2);
+  return;
+}
+
+void bDrawRectFill (double x1, double y1, double x2, double y2) {
+
+  int i;
+  int X1, Y1, X2, Y2;
+
+  if (x1 > x2) SWAP (x1, x2);
+  if (y1 > y2) SWAP (y1, y2);
+
+  X1 = MIN (MAX (ROUND (x1), 0), bBuffer[0].Nx - 1);
+  X2 = MIN (MAX (ROUND (x2), 1), bBuffer[0].Nx);
+
+  Y1 = MIN (MAX (ROUND (y1), 0), bBuffer[0].Ny - 1);
+  Y2 = MIN (MAX (ROUND (y2), 0), bBuffer[0].Ny);
+
+  for (i = Y1; i < Y2; i++) {
+    bDrawLineHorizontal (X1, X2, i);
+  } 
+  return;
+}
+
+// identify the quadrant and draw the correct line
+void bDrawLine (double x1, double y1, double x2, double y2) {
+
+  int FlipDirect, FlipCoords;
+  int X1, Y1, X2, Y2, dX, dY;
+
+  /* rather than draw the line from float positions, we find the closest
+     integer end-points and draw the line between those pixels */ 
+
+  X1 = ROUND(x1);
+  Y1 = ROUND(y1);
+  X2 = ROUND(x2);
+  Y2 = ROUND(y2);
+
+  dX = X2 - X1;
+  dY = Y2 - Y1;
+
+  FlipCoords = (abs(dX) < abs(dY));
+  FlipDirect = FlipCoords ? (y1 > y2) : (x1 > x2);
+
+  if (!FlipDirect && !FlipCoords) bDrawLineWeight (X1, Y1, X2, Y2, FALSE);
+  if ( FlipDirect && !FlipCoords) bDrawLineWeight (X2, Y2, X1, Y1, FALSE);
+  if (!FlipDirect &&  FlipCoords) bDrawLineWeight (Y1, X1, Y2, X2, TRUE);
+  if ( FlipDirect &&  FlipCoords) bDrawLineWeight (Y2, X2, Y1, X1, TRUE);
+
+  return;
+}
+
+// draw a series of lines to give the line weight
+void bDrawLineWeight (int X1, int Y1, int X2, int Y2, int swapcoords) {
+
+  int dN, dNs, dNe;
+
+  dNs = -0.5*(bWeight - 1); 
+  /* 0, 0, 0, -1, -1, -2, -2 */
+
+  dNe = +0.5*bWeight + 1; 
+  /* 1, 1, 2, 2, 2, 3, 3 */
+
+  for (dN = dNs; dN < dNe; dN++) {
+    bDrawLineBresen (X1, Y1 + dN, X2, Y2 + dN, swapcoords);
+  }
+  return;
+}
+
+// use the Bresenham line drawing technique
+// integer-only Bresenham line-draw version which is fast
+void bDrawLineBresen (int X1, int Y1, int X2, int Y2, int swapcoords) {
+
+  int X, Y, dX, dY;
+  int e, e2;
+  int N, DashOn;
+
+  dX = X2 - X1;
+  dY = Y2 - Y1;
+
+  DashOn = TRUE;
+
+  Y = Y1;
+  e = 0;
+  for (X = X1, N = 0; X <= X2; X++, N++) {
+    if (bType == 1) { DashOn = (N % 10) < 5; }
+    if (bType == 2) { DashOn = (N % 6) < 3; }
+    if (swapcoords) {
+      if (DashOn) bDrawPoint (Y,X);
+    } else {
+      if (DashOn) bDrawPoint (X,Y);
+    }
+    e += dY;
+    e2 = 2 * e;
+    if (e2 > dX) {
+      Y++;
+      e -= dX;
+    } 
+    if (e2 < -dX) {
+      Y--;
+      e += dX;
+    }
+  }
+  return;
+}
+
+void bDrawLineHorizontal (int X1, int X2, int Y) {
+  
+  int i;
+
+  for (i = X1; i < X2; i++) {
+    bBuffer[0].pixels[Y][i] = bColor;
+  }
+  return;
+}
+
+void bDrawLineVertical (int X, int Y1, int Y2) {
+  
+  int i;
+
+  for (i = Y1; i < Y2; i++) {
+    bBuffer[0].pixels[i][X] = bColor;
+  }
+  return;
+}
+
+void bDrawTriFill (double x1, double y1, double x2, double y2, double x3, double y3) {
+
+  bDrawTriOpen (x1, y1, x2, y2, x3, y3);
+  return;
+}
+
+void bDrawArc (double Xc, double Yc, double Xr, double Yr, double Ts, double Te) {
+
+  float t, dt;
+  int x, y;
+
+  /* drawing a complete circle */
+//  if ((fabs(Te - Ts) > 360.0) && (Xr == Yr)) {
+//    bDrawCircle (Xc, Yc, Xr);
+//    return;
+//  }
+
+  /* only draw a single loop */
+  if (fabs(Te - Ts) > 360.0) {
+    Te = 360.0;
+    Ts = 0.0;
+  }
+
+  /* smallest angle is 1/Rmax */
+  dt = MAX (fabs(Xr * sin(Ts*RAD_DEG)), fabs(Yr * cos(Ts*RAD_DEG)));
+  dt = 1.0 / dt;
+
+  for (t = Ts*RAD_DEG; t <= Te*RAD_DEG; t += dt) {
+    x = Xr*cos(t) + Xc;
+    y = Yr*sin(t) + Yc;
+
+    /* we could use the value of MAX(dy/dt,dx/dt) to set dt */
+    bDrawPoint (x,y);
+
+    dt = MAX (fabs(Xr * sin(t)), fabs(Yr * cos(t)));
+    dt = 1.0 / dt;
+  }
+  return;
+}
+
+// draw a series of circles to give line weight
+void bDrawCircle (double xc, double yc, double radius) {
+
+  int dN, dNs, dNe;
+
+  dNs = -0.5*(bWeight - 1); 
+  /* 0, 0, 0, -1, -1, -2, -2 */
+
+  dNe = +0.5*bWeight + 1; 
+  /* 1, 1, 2, 2, 2, 3, 3 */
+
+  for (dN = dNs; dN < dNe; dN++) {
+    bDrawCircle (xc, yc, radius + dN);
+  }
+  return;
+}
+
+// draw a pure circle  
+void bDrawCircleSingle (double xc, double yc, double radius) {
+
+  int Xc, Yc, Radius;
+  int x, y, d;
+
+  Xc = ROUND(xc);
+  Yc = ROUND(yc);
+  Radius = ROUND(radius);
+
+  x = 0;
+  y = Radius;
+
+  // d = 3 - 2*Radius;
+  d = 5 - 4*radius;
+
+  while (x <= y) {
+    bDrawPoint (Xc+x, Yc+y);
+    bDrawPoint (Xc+x, Yc-y);
+    bDrawPoint (Xc-x, Yc+y);
+    bDrawPoint (Xc-x, Yc-y);
+    bDrawPoint (Xc+y, Yc+x);
+    bDrawPoint (Xc+y, Yc-x);
+    bDrawPoint (Xc-y, Yc+x);
+    bDrawPoint (Xc-y, Yc-x);
+
+    if (d < 0) {
+      // d = d + 4*x + 6;
+      d = d + 8*x + 4;
+    } else {
+      // d = d + 4*(x-y) + 10;
+      d = d + 8*(x-y) + 8;
+      y--;
+    }
+    x++;
+  }
+}
+
+// draw a pure circle  
+void bDrawCircleFill (double xc, double yc, double radius) {
+
+  int Xc, Yc, Radius;
+  int x, y, d;
+
+  Xc = ROUND(xc);
+  Yc = ROUND(yc);
+  Radius = ROUND(radius);
+
+  x = 0;
+  y = Radius;
+
+  // d = 3 - 2*Radius;
+  d = 5 - 4*radius;
+
+  while (x <= y) {
+    bDrawLineHorizontal (Xc-x, Xc+x, Yc+y);
+    bDrawLineHorizontal (Xc-x, Xc+x, Yc-y);
+    bDrawLineHorizontal (Xc-y, Xc+y, Yc+x);
+    bDrawLineHorizontal (Xc-y, Xc+y, Yc-x);
+
+    if (d < 0) {
+      // d = d + 4*x + 6;
+      d = d + 8*x + 4;
+    } else {
+      // d = d + 4*(x-y) + 10;
+      d = d + 8*(x-y) + 8;
+      y--;
+    }
+    x++;
+  }
+}
+
+/* 
+the discriminant of inside or outside the circle is:
+
+f(x,y) = x^2 + y^2 - r^2
+
+- negative: (x,y) inside circle
+- positive: (x,y) outside circle
+
+given d(0) = f(x,y); find d(1) = f(x+1,y):
+d(1) = (x+1)^2 + y^2 - r^2
+d(1) = d(0) + 2x + 1
+(use d(1) if d(0) < 0, ie inside circle)
+
+given d(0) = f(x,y); find d(1) = f(x+1,y-1):
+d(1) = (x+1)^2 + (y-1)^2 - r^2
+d(1) = d(0) + 2x + 1 - 2y + 1
+d(1) = d(0) + 2(x-y) + 2
+
+* init d to f(1,r-1/2) instead of r, keeping the effective boundary 
+  between two pixels (also, an inside point)
+
+f(1,r-1/2) = 1 + (r-1/2)^2 - r^2 = 5/4 - r
+f(1,r-1/4) = 1 + (r-1/4)^2 - r^2 = 1 + r/2 + 1/16 = 17/16 + r/2
+
+f(1,r-x)   = 1 + (r-x)^2 - r^2 = 1 - 2xr + x^2 = A (3 - 2r)
+
+1+x^2 = 3A
+-2x = -2A
+
+A = x
+
+1 - 3x + x^2 = 0
+
+(3 +/- sqrt(9 - 4))/2 = (3 - sqrt(5))/2
+
+multiply all d values by 4 to get integer tests:
+
+d'(0) = 5 - 4r
+d'(in) = d' + 8x + 4
+d'(out) = d' + 8(x-y) + 8
+
+*/
+
+/* This is the Bresenham line-drawing algorithm for 1st and 4th quandrant
+   vectors with positive and negative slopes < 1. this is the sequence if we use
+   float errors and tests it is easy to understand, but slower than it could be
+
+  { 
+    float e, m;
+    m = dY / dX;
+    Y = Y1;
+    e = 0;
+    for (X = X1; X <= X2; X++) {
+      plot (X,Y);
+      e += m;
+      if (e > 0.5) {
+	Y++;
+	e -= 1.0;
+      }
+      if (e < -0.5) {
+	Y--;
+	e += 1.0;
+      }
+    }
+  }
+*/
Index: /trunk/Ohana/src/kii/overlay/bDrawOverlay.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/bDrawOverlay.c	(revision 5700)
+++ /trunk/Ohana/src/kii/overlay/bDrawOverlay.c	(revision 5700)
@@ -0,0 +1,94 @@
+# include "Ximage.h"
+# include "bDraw.h"
+# define INFRONT 4
+
+static char name[4][16] = {"red", "green", "blue", "yellow"};
+
+void bDrawOverlay (Layout *layout, int N) {
+
+  int i;
+  int dX, dY, dx, dy;
+  int X, Y, Xmin, Ymin, Xmax, Ymax, Xrange, Yrange;
+  double expand, X0, Y0;
+  bDrawColor color;
+ 
+  /* translate color to bDrawColors : layout[0].overlay[N].color */
+  color = GetColorByName (name[N]);
+  bDrawSetStyle (color, 0, 0);
+  
+  expand = 1.0;
+  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);
+  X0 -= layout[0].picture.x;
+  Y0 -= layout[0].picture.y;
+
+  Xmin = 0;
+  Ymin = 0;
+  Xmax = layout[0].picture.dx;
+  Ymax = 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;
+      Y  = layout[0].overlay[N].objects[i].y * Yrange;
+      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")) {
+      bDrawLine (X, Y, (X+dX), (Y+dY));
+      continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "TEXT")) {
+      bDrawRotText (X, Y, layout[0].overlay[N].objects[i].text, 8, 0.0);
+      continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "BOX")) {
+      dx = MAX (abs(dX),2) / 2;
+      dy = MAX (abs(dY),2) / 2;
+      bDrawRectOpen ((X-dx), (Y-dy), (X+dx), (Y+dy));
+      // bDrawRectOpen ((X-dx), (Y-dy), (X), (Y));
+       continue;
+    }
+    if (!strcasecmp (layout[0].overlay[N].objects[i].type, "CIRCLE")) {
+      dx = MAX (abs(dX),2);
+      dy = MAX (abs(dY),2);
+      bDrawArc (X, Y, dx, dy, 0, 360);
+      continue;
+    }
+    fprintf (stderr, "don't know %s, skipping (PO)\n", layout[0].overlay[N].objects[i].type);
+  }
+  
+  /* translate color to bDrawColors : layout[0].overlay[N].color */
+  bDrawSetStyle (color, 0, 0);
+}
+
+/* this routine is independent of the number of overlays */
+
Index: /trunk/Ohana/src/kii/overlay/bDrawRotFont.c
===================================================================
--- /trunk/Ohana/src/kii/overlay/bDrawRotFont.c	(revision 5700)
+++ /trunk/Ohana/src/kii/overlay/bDrawRotFont.c	(revision 5700)
@@ -0,0 +1,212 @@
+# include "Ximage.h"
+# include "bDraw.h"
+
+# define NROTCHARS 256
+# define XPROC(x,y) (scale*(cs*((x) - x0) - sn*((y) - y0)) + X0)
+# define YPROC(x,y) (scale*(cs*((y) - y0) + sn*((x) - x0)) + Y0)
+# define NEARINT(x) ((x < 0) ? ((int)(x - 0.5)) : ((int)(x + 0.5)))
+  
+static bDrawColor black;
+static bDrawColor white;
+
+int bDrawRotText (int x, int y, char *string, int pos, double angle) {
+
+  unsigned char *bitmap;
+  char *currentname, basename[64], *c; 
+  int i, dy, dx, N, X, Y, code;
+  int dX, Xoff, dY, Yoff, YoffBase;
+  int currentsize, basesize;
+  double cs, sn, currentscale;
+  RotFont *currentfont;
+
+  white = GetColorByName ("white");
+  black = GetColorByName ("black");
+
+  currentname = GetRotFont (&currentsize);
+  currentfont = GetRotFontData (&currentscale);
+  strcpy (basename, currentname);
+  basesize = currentsize;
+
+  /* strip leading whitespace */
+  for (c = string; (*c == ' ') || (*c == '\t'); c++);
+  if (*c == 0) return (FALSE);
+  
+  /* compute string length */
+  cs = cos(angle*RAD_DEG);
+  sn = sin(angle*RAD_DEG);
+  dX = RotStrlen (c);
+  dY = currentfont[65].ascent;
+
+  /* apply appropriate offset */
+  Xoff = Yoff = 0;
+  switch (pos) {
+  case 0: Xoff =     -dX; Yoff = dY; break;
+  case 1: Xoff = -0.5*dX; Yoff = dY; break;
+  case 2: Xoff =       0; Yoff = dY; break;
+  case 3: Xoff =     -dX; Yoff = 0.5*dY; break;
+  case 4: Xoff = -0.5*dX; Yoff = 0.5*dY; break;
+  case 5: Xoff =       0; Yoff = 0.5*dY; break;
+  case 6: Xoff =     -dX; Yoff = 0; break;
+  case 7: Xoff = -0.5*dX; Yoff = 0; break;
+  case 8: Xoff =       0; Yoff = 0; break;
+  }
+
+  code = FALSE;
+
+  YoffBase = Yoff;
+  /* draw characters one-by-one */
+  for (i = 0; i < strlen(c); i++) {
+    N = (int)(c[i]);
+    if ((N < 0) || (N >= NROTCHARS)) continue;
+
+    /* check for special characters */
+    if (!code) {
+      if (N == 94) {
+	SetRotFont (currentname, (int)(0.8*currentsize));
+	currentfont = GetRotFontData (&currentscale);
+	Yoff -= 0.5*currentscale*dY;
+	continue;
+      }
+      if (N == 95) { 
+	SetRotFont (currentname, (int)(0.8*currentsize));
+	currentfont = GetRotFontData (&currentscale);
+	Yoff += 0.5*currentscale*dY;
+	continue;
+      }
+      if (N == 124) {
+	SetRotFont (currentname, basesize);
+	currentfont = GetRotFontData (&currentscale);
+	Yoff = YoffBase;
+	continue;
+      }
+      if (N == 92) {
+	code = TRUE;
+	continue;
+      } 
+      if (N == 38) {
+	if (c[i+1] == 'h') {
+	  SetRotFont ("helvetica", currentsize);
+	  currentfont = GetRotFontData (&currentscale);
+	}
+	if (c[i+1] == 't') {
+	  SetRotFont ("times", currentsize);
+	  currentfont = GetRotFontData (&currentscale);
+	}
+	if (c[i+1] == 'c') {
+	  SetRotFont ("courier", currentsize);
+	  currentfont = GetRotFontData (&currentscale);
+	}
+	if (c[i+1] == 's') {
+	  SetRotFont ("symbol", currentsize);
+	  currentfont = GetRotFontData (&currentscale);
+	}
+	i++;
+	continue;
+      }
+    }
+    code = FALSE;
+
+    bitmap = currentfont[N].bits;
+    dx = currentfont[N].dx;
+    dy = currentfont[N].dy;
+    X = x + (int)(Xoff*cs - Yoff*sn) + (int)(currentscale*currentfont[N].ascent*sn);
+    Y = y + (int)(Xoff*sn + Yoff*cs) - (int)(currentscale*currentfont[N].ascent*cs);
+    bDrawRotBitmap (X, Y, dx, dy, bitmap, TRUE, angle, currentscale);
+    Xoff += 1 + (int)(currentscale*dx + 0.5);
+  }
+  SetRotFont (basename, basesize);
+  return (TRUE);
+}
+
+int bDrawRotBitmap (int x, int y, int dx, int dy, unsigned char *bitmap, int mode, double angle, double scale) {
+
+  int ii, jj, byte_line, byte, bit, flag;
+  bDrawColor color;
+  double i, j, cs, sn, rscale, tmp;
+  int X, Y, X0, X1, X2, Y0, Y1, Y2, x0, y0;
+
+  /* this mode option is nort actually used... */
+  if (mode) {
+    color = black;
+  } else {
+    color = white;
+  } 
+    
+  byte_line = (int) ((dx + 7) / 8);
+
+  cs = cos(angle*RAD_DEG);  sn = sin(angle*RAD_DEG);
+  rscale = 1.0 / scale;
+
+  X0 = 0;
+  Y0 = 0;
+  x0 = 0;
+  y0 = 0;
+
+  X2 = X1 = XPROC (0,0);
+  Y2 = Y1 = YPROC (0,0);
+
+  X = XPROC (dx,0);
+  Y = YPROC (dx,0);
+# ifdef DRAWBOXES
+  bDrawLine (x+X, y+Y, x+X1, y+Y1);
+  Xt = X;
+  Yt = Y;
+# endif
+  X1 = MIN (X, X1);
+  X2 = MAX (X, X2);
+  Y1 = MIN (Y, Y1);
+  Y2 = MAX (Y, Y2);
+
+  X = XPROC (dx,dy);
+  Y = YPROC (dx,dy);
+# ifdef DRAWBOXES
+  bDrawLine (x+X, y+Y, x+Xt, y+Yt);
+  Xt = X;
+  Yt = Y;
+# endif
+  Y1 = MIN (Y, Y1);
+  Y2 = MAX (Y, Y2);
+  X1 = MIN (X, X1);
+  X2 = MAX (X, X2);
+
+  X = XPROC (0,dy);
+  Y = YPROC (0,dy);
+# ifdef DRAWBOXES
+  bDrawLine (x+X, y+Y, x+Xt, y+Yt);
+  Xt = X;
+  Yt = Y;
+# endif
+  Y1 = MIN (Y, Y1);
+  Y2 = MAX (Y, Y2);
+  X1 = MIN (X, X1);
+  X2 = MAX (X, X2);
+
+  bDrawSetStyle (color, 0, 0);
+  if (scale > 1) {
+    for (i = X1; i <= X2; i+=1) {
+      for (j = Y1; j <= Y2; j+=1) {
+	tmp = rscale*(cs*(i - X0) + sn*(j - Y0)) + x0;  ii = NEARINT (tmp);
+	tmp = rscale*(cs*(j - Y0) - sn*(i - X0)) + y0;  jj = NEARINT (tmp);
+	if ((ii < 0) || (ii >= dx) || (jj < 0) || (jj >= dy)) continue;
+	byte = byte_line * jj + (ii / 8);
+	bit = ii % 8;
+	flag = 0x01 & (bitmap[byte] >> bit);
+	if (flag) bDrawPointf (x + i, y + j);
+      }
+    }
+  } else {
+    for (i = X1; i <= X2; i+=scale) {
+      for (j = Y1; j <= Y2; j+=scale) {
+	tmp = rscale*(cs*(i - X0) + sn*(j - Y0)) + x0;  ii = NEARINT (tmp);
+	tmp = rscale*(cs*(j - Y0) - sn*(i - X0)) + y0;  jj = NEARINT (tmp);
+	if ((ii < 0) || (ii >= dx) || (jj < 0) || (jj >= dy)) continue;
+	byte = byte_line * jj + (ii / 8);
+	bit = ii % 8;
+	flag = 0x01 & (bitmap[byte] >> bit);
+	if (flag) bDrawPointf (x + i, y + j);
+      }
+    }
+  }
+  bDrawSetStyle (black, 0, 0);
+  return (TRUE);
+}
Index: /trunk/Ohana/src/kii/picture/Center.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Center.c	(revision 5699)
+++ /trunk/Ohana/src/kii/picture/Center.c	(revision 5700)
@@ -21,9 +21,11 @@
   }
 
-  Remap (graphic, layout, &layout[0].matrix);
-  Refresh (graphic, layout, 0);
+  if (USE_XWINDOW) {
+    Remap (graphic, layout, &layout[0].matrix);
+    Refresh (graphic, layout, 0);
+    XFlush (graphic[0].display);
+  }
 
   fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
-  XFlush (graphic[0].display);
   return (TRUE);
 }
Index: /trunk/Ohana/src/kii/picture/JPEGit24.c
===================================================================
--- /trunk/Ohana/src/kii/picture/JPEGit24.c	(revision 5699)
+++ /trunk/Ohana/src/kii/picture/JPEGit24.c	(revision 5700)
@@ -1,6 +1,12 @@
 # include "Ximage.h"
 # include "jpeglib.h"
-
-void JPEGit24 (Graphic *graphic, Layout *layout) {
+# include <png.h>
+# include "bDraw.h"
+
+# define WHITE_R 255
+# define WHITE_G 255
+# define WHITE_B 255
+
+int JPEGit24 (Graphic *graphic, Layout *layout) {
 
   struct jpeg_compress_struct cinfo;
@@ -8,17 +14,16 @@
   JSAMPROW row_pointer[1];	/* pointer to JSAMPLE row[s] */
   JSAMPLE *image_buffer;	/* Points to data for current line */
-
-  int i, j, ii, jj;
+  JSAMPLE *line_buffer;	        /* Points to data for current line */
+
+  int ii, i, j;
   int i_start, i_end, j_start, j_end;
   int dropback, extra;  /* this is a bit of a kludge... */
   int dx, dy, DX, DY;
+  int status, Nbytes, quality;
+  int expand_in, expand_out;
   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 *out_pix, *in_pix, *in_pix_ref;
   unsigned char pixel1[256], pixel2[256], pixel3[256];
-  unsigned char pixvalue1, pixvalue2, pixvalue3;
-  unsigned long white;
-  unsigned char white1, white2, white3;
+  char filename[1024];
   FILE *f;
 
@@ -36,5 +41,5 @@
   f = fopen (filename, "w");
   if (f == (FILE *) NULL) {
-    fprintf (stderr, "failed to open %s for output\n", filename);
+    fprintf (stderr, "Kii: failed to open %s for output\n", filename);
     return (TRUE);
   }
@@ -55,17 +60,10 @@
   jpeg_start_compress (&cinfo, TRUE);
 
-  /* output line buffer */
-  ALLOCATE (image_buffer, JSAMPLE, 3*layout[0].picture.dx);
-
   /** cmap[i].pixel must be defined even if X is not used **/
   for (i = 0; i < 256; i++) { /* set up pixel array */
-    pixel1[i] = 0x0000ff & (layout[0].cmap[i].pixel >> 0);
-    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 >> 0);
-  white2 = 0x0000ff & (white >> 8);
-  white3 = 0x0000ff & (white >> 16);
+    pixel1[i] = layout[0].cmap[i].red >> 8;
+    pixel2[i] = layout[0].cmap[i].green >> 8;
+    pixel3[i] = layout[0].cmap[i].blue >> 8;
+  }
 
   expand = expand_in = expand_out = 1.0;
@@ -85,7 +83,6 @@
   dx = layout[0].picture.dx;
   dy = layout[0].picture.dy;
-  DX = layout[0].matrix[0].Naxis[0];
-  DY = layout[0].matrix[0].Naxis[1];
-  extra = 4 - (dx * 3) % 4;  /* why is this needed?? */
+  DX = layout[0].matrix.Naxis[0];
+  DY = layout[0].matrix.Naxis[1];
 
   /* X,Y are the image coordinates of the first image pixel */
@@ -119,13 +116,14 @@
   if ((i_end - i_start) % expand_out == 0) dropback = 0;
 
-  out_pix = image_buffer;
-  in_pix  = (unsigned char *) (layout[0].matrix[0].buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
+  /* output line buffer */
+  ALLOCATE (image_buffer, JSAMPLE, 3*dx*dy);
+  ALLOCATE (line_buffer, JSAMPLE, 3*dx);
+
+  in_pix_ref  = (unsigned char *) (layout[0].matrix.buffer) + DX*(int)MAX(Y,0) + (int)MAX(X,0);
 
   /********** below we do the mapping from buffer pixels (in) to picture pixels (out) **********/
 
-  /* we write the jpeg image data one row at a time */
-
   /**** fill in bottom area ****/
-  out_pix = image_buffer;
+  out_pix = line_buffer;
   for (i = 0; i < dx; i++, out_pix+=3) {
     out_pix[0] = WHITE_R;
@@ -134,13 +132,13 @@
   }
   for (j = 0; j < j_start; j++) {
-    row_pointer[0] = image_buffer;
-    (void) jpeg_write_scanlines (&cinfo, row_pointer, 1);
+    memcpy (&image_buffer[j*3*dx], line_buffer, 3*dx);
   }
   
   /*** fill in the image data region ***/
-  for (j = j_start; j < j_end; j+= expand_out, in_pix += expand_in*DX) {
+  for (j = j_start; j < j_end; j+= expand_out, in_pix_ref += expand_in*DX) {
     
     /* create one output image line */
-    out_pix = image_buffer;
+    in_pix = in_pix_ref;
+    out_pix = line_buffer;
 
     /**** fill in area to the left of the picture ****/
@@ -152,8 +150,10 @@
     
     /*** fill in the picture region ***/
-    for (i = i_start; i < i_end; i++, in_pix+=expand_in, out_pix+=3) {
-      out_pix[0] = pixel1[*in_pix];
-      out_pix[1] = pixel2[*in_pix];
-      out_pix[2] = pixel3[*in_pix];
+    for (i = i_start; i < i_end; i+=expand_out, in_pix+=expand_in) {
+      for (ii = 0; ii < expand_out; ii++, out_pix+=3) {
+	out_pix[0] = pixel1[*in_pix];
+	out_pix[1] = pixel2[*in_pix];
+	out_pix[2] = pixel3[*in_pix];
+      }
     }
     
@@ -167,11 +167,10 @@
     /* write out the image line expand_out times */
     for (i = 0; i < expand_out; i++) {
-      row_pointer[0] = image_buffer;
-      (void) jpeg_write_scanlines (&cinfo, row_pointer, 1);
+      memcpy (&image_buffer[(j + i)*3*dx], line_buffer, 3*dx);
     }
   }
 
   /**** fill in top area ****/
-  out_pix = image_buffer;
+  out_pix = line_buffer;
   for (i = 0; i < dx; i++, out_pix+=3) { 
     out_pix[0] = WHITE_R;
@@ -179,6 +178,43 @@
     out_pix[2] = WHITE_B;
   }
-  for (j = 0; j < (dy - j_end); j++) {
-    row_pointer[0] = image_buffer;
+  for (j = j_end; j < dy; j++) {
+    memcpy (&image_buffer[j*3*dx], line_buffer, 3*dx);
+  }
+
+
+  /* I need to write the overlay objects on the jpeg image.
+     if i can write / overwrite data in jpeg buffer, then do it here,
+     otherwise i need to create a temporary image buffer, then write the 
+     scanlines to that buffer */
+
+  {
+    int Npalette;
+    png_color *palette;
+    bDrawColor white, color;
+    bDrawBuffer *buffer;
+
+    palette = MakePNGPalette (&Npalette);
+
+    buffer = bDrawBufferCreate (dx, dy);
+    bDrawSetBuffer (buffer);
+    for (i = 0; i < NOVERLAYS; i++) {
+      if (OVERLAY[i]) bDrawOverlay (layout, i);
+    }
+
+    white = GetColorByName ("white");
+    for (j = 0; j < dy; j++) {
+      for (i = 0; i < dx; i++) {
+	color = buffer[0].pixels[j][i];
+	if (color == white) continue;
+	image_buffer[j*3*dx + 3*i + 0] = palette[color].red;
+	image_buffer[j*3*dx + 3*i + 1] = palette[color].green;
+	image_buffer[j*3*dx + 3*i + 2] = palette[color].blue;
+      }
+    }
+    bDrawBufferFree (buffer);
+  }
+
+  for (i = 0; i < dy; i++) {
+    row_pointer[0] = &image_buffer[i*3*dx];
     (void) jpeg_write_scanlines (&cinfo, row_pointer, 1);
   }
@@ -190,3 +226,2 @@
   return (TRUE);
 }
-
Index: /trunk/Ohana/src/kii/picture/NewPicture.c
===================================================================
--- /trunk/Ohana/src/kii/picture/NewPicture.c	(revision 5699)
+++ /trunk/Ohana/src/kii/picture/NewPicture.c	(revision 5700)
@@ -66,8 +66,9 @@
   }
 
+  if (!USE_XWINDOW) return (TRUE);
+
   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);
Index: /trunk/Ohana/src/kii/picture/Resize.c
===================================================================
--- /trunk/Ohana/src/kii/picture/Resize.c	(revision 5699)
+++ /trunk/Ohana/src/kii/picture/Resize.c	(revision 5700)
@@ -24,18 +24,18 @@
     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);
+  if (USE_XWINDOW) 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);
+  if (USE_XWINDOW) {
+    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/setup/CheckVisual.c
===================================================================
--- /trunk/Ohana/src/kii/setup/CheckVisual.c	(revision 5699)
+++ /trunk/Ohana/src/kii/setup/CheckVisual.c	(revision 5700)
@@ -1,5 +1,5 @@
 # include "Ximage.h"
 # define NPIXELS 64
-# define DEBUG 0
+# define DEBUG 1
 
 /* DirectColor doesn't seem to work, even though it is available:
@@ -143,4 +143,5 @@
 
   if (!def) {
+    if (DEBUG) fprintf (stderr, "allocated private colormap\n");
     graphic[0].colormap = XCreateColormap (graphic[0].display, RootWindow (graphic[0].display, graphic[0].screen), graphic[0].visual, AllocNone);
   }
Index: /trunk/Ohana/src/kii/setup/DefineLayout.c
===================================================================
--- /trunk/Ohana/src/kii/setup/DefineLayout.c	(revision 5699)
+++ /trunk/Ohana/src/kii/setup/DefineLayout.c	(revision 5700)
@@ -1,3 +1,5 @@
 # include "Ximage.h"
+
+static char default_colormap[] = "grayscale";
 
 void DefineLayout (Layout *layout, Graphic *graphic, int argc, char **argv) {
@@ -5,5 +7,5 @@
   int i, status, N;
   struct sockaddr_un Address;
-  char temp[100];
+  char temp[100], *temp_name;
 
   /** initiate connection with mana **/
@@ -29,5 +31,15 @@
   
   /* get the display colors */
-  MakeColormap (graphic, layout, argc, argv);
+  if (USE_XWINDOW) {
+    MakeColormap (graphic, layout, argc, argv);
+  } else {
+    temp_name = default_colormap;
+    if ((N = get_argument (argc, argv, "-cm"))) {
+      remove_argument (N, &argc, argv);
+      temp_name = argv[N];
+    }
+    layout[0].Npixels = 256;
+    SetColormap (graphic, layout, temp_name);
+  }
 
   /** set up a bunch of default things **/
@@ -51,7 +63,9 @@
   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); 
+  if (USE_XWINDOW) {
+    CreatePicture (layout, graphic);
+    CreateColorbar (layout, graphic);
+    CreateZoom (layout, graphic, 0, 0); 
+  }
 }
 
Index: /trunk/Ohana/src/kii/setup/SetUpWindow.c
===================================================================
--- /trunk/Ohana/src/kii/setup/SetUpWindow.c	(revision 5699)
+++ /trunk/Ohana/src/kii/setup/SetUpWindow.c	(revision 5700)
@@ -23,9 +23,5 @@
   NameWindow (graphic, "Ki'i");
 
-  if ((N = get_argument (*argc, argv, "-nomap"))) {
-    remove_argument(N, argc, argv);
-  } else {
-    MapWindow (graphic);
-  }  
+  if (MAP_WINDOW) MapWindow (graphic);
 }
 
Index: /trunk/Ohana/src/kii/setup/Ximage.c
===================================================================
--- /trunk/Ohana/src/kii/setup/Ximage.c	(revision 5699)
+++ /trunk/Ohana/src/kii/setup/Ximage.c	(revision 5700)
@@ -12,5 +12,12 @@
 
   if (USE_XWINDOW) SetUpDisplay (&graphic, &argc, argv);
-  if (USE_XWINDOW) SetUpWindow (&graphic, &argc, argv);
+  if (USE_XWINDOW) {
+    SetUpWindow (&graphic, &argc, argv);
+  } else {
+    graphic.x = 10;
+    graphic.y = 10;
+    graphic.dx = 512 + 2*PAD1 + PAD1 + ZOOM_X;
+    graphic.dy = 512 + 2*PAD1 + PAD2 + COLORPAD;
+  }
 
   DefineLayout (&layout, &graphic, argc, argv);
