Index: trunk/Ohana/src/opihi/cmd.data/tvcontour.c
===================================================================
--- trunk/Ohana/src/opihi/cmd.data/tvcontour.c	(revision 4689)
+++ trunk/Ohana/src/opihi/cmd.data/tvcontour.c	(revision 5846)
@@ -42,34 +42,23 @@
 
 # define DUMP { \
-sprintf (&buffer[Nline*128], "%14s %20.10f %20.10f %20.10f %20.10f ", "LINE", Npix*x, Npix*y, Npix*dx, Npix*dy); \
-Nline ++; \
-if (Nline == 512) { \
-  SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline); \
-  write (Ximage, buffer, Nline*128); \
-  bzero (buffer, 65536); \
-  Nline = 0; \
-} \
-continue; }
-
-# define NUMP { \
-sprintf (&buffer[Nline*128], "%14s %20.10f %20.10f %20.10f %20.10f ", "LINE", Npix*x, Npix*y, Npix*dx, Npix*dy); \
-Nline ++; \
-if (Nline == 512) { \
-  SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline); \
-  write (Ximage, buffer, Nline*128); \
-  bzero (buffer, 65536); \
-  Nline = 0; \
-} }
+overlay[Noverlay].type = KII_OVERLAY_LINE; \
+overlay[Noverlay].x = Npix*x; \
+overlay[Noverlay].y = Npix*y; \
+overlay[Noverlay].dx = Npix*dx; \
+overlay[Noverlay].dy = Npix*dy; \
+Noverlay ++; \
+CHECK_REALLOCATE (overlay, KiiOverlay, NOVERLAY, Noverlay, 1000); \
+}
 
 int tvcontour (int argc, char **argv) {
 
-  int i, j, ii, jj, n, Npix, Nx, Ny, Nline;
+  int i, j, ii, jj, Npix, Nx, Ny;
   float level, d00, d01, d10, d11, tmp;
   float x, y, dx, dy;
   float *v00, *v01, *v10, *v11;
   float *Vout, *Vin, *matrix;
-  char *buffer;
-  int Ximage, Nimage, N;
+  int Ximage, Nimage, N, Noverlay, NOVERLAY;
   Buffer *buf;
+  KiiOverlay *overlay;
   
   Nimage = -1;
@@ -87,5 +76,4 @@
 
   if ((buf = SelectBuffer (argv[1], OLDBUFFER, TRUE)) == NULL) return (FALSE);
-  if (!SelectOverlay (argv[2], &n)) return (FALSE);
 
   level = atof (argv[3]);
@@ -115,15 +103,12 @@
       }
     }
-  }
-  else {
+  } else {
     fprintf (stderr, "using scale of 1\n");
     matrix = (float *)(buf[0].matrix.buffer);
   }
 
-  SendGraphCommand (Ximage, 4, "LOAD"); /* force Ximage to look for the incoming image */
-  SendGraphCommand (Ximage, 16, "OVERLAY %7d ", n);
-  ALLOCATE (buffer, char, 65536);  /* space for 512 lines of 128 bytes */
-  bzero (buffer, 65536);
-  Nline = 0;
+  Noverlay = 0;
+  NOVERLAY = 1000;
+  ALLOCATE (overlay, KiiOverlay, NOVERLAY);
 
   v00 = matrix;
@@ -150,18 +135,22 @@
 	  LL;
 	  DUMP;
+	  continue;
 	}
 	if ((d01 > 0) && (d11 <= 0)) { /* -  */
 	  HZ;
 	  DUMP;
+	  continue;
 	}
 	if ((d01 > 0) && (d11 > 0)) { /* /  */
 	  UL;
 	  DUMP;
+	  continue;
 	}
 	if ((d01 <= 0) && (d11 > 0)) { /* \\  */
 	  LL;
-	  NUMP;
+	  DUMP;
 	  UR;
 	  DUMP;
+	  continue;
 	}
       }
@@ -171,18 +160,22 @@
 	  LL;
 	  DUMP;
+	  continue;
 	}
 	if ((d01 <= 0) && (d11 > 0)) { /* -  */
 	  HZ;
 	  DUMP;
+	  continue;
 	}
 	if ((d01 <= 0) && (d11 <= 0)) { /* /  */
 	  UL;
 	  DUMP;
+	  continue;
 	}
 	if ((d01 > 0) && (d11 <= 0)) { /* //  */
 	  UL;
-	  NUMP;
+	  DUMP;
 	  LR;
 	  DUMP;
+	  continue;
 	}
       }
@@ -193,12 +186,15 @@
 	  LR;
 	  DUMP;
+	  continue;
 	}
 	if ((d01 <= 0) && (d11 > 0)) {
 	  UR;
 	  DUMP;
+	  continue;
 	}
 	if ((d01 > 0) && (d11 > 0)) {
 	  VT;
 	  DUMP;
+	  continue;
 	}
       }
@@ -208,12 +204,15 @@
 	  LR;
 	  DUMP;
+	  continue;
 	}
 	if ((d01 > 0) && (d11 <= 0)) {
 	  UR;
 	  DUMP;
+	  continue;
 	}
 	if ((d01 <= 0) && (d11 <= 0)) {
 	  VT;
 	  DUMP;
+	  continue;
 	}
       }
@@ -235,5 +234,5 @@
     if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
       x = i + (level - *v01)/(*v01 - *v00);
-      NUMP;
+      DUMP;
     }
   }
@@ -248,5 +247,5 @@
     if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
       x = i + (level - *v01)/(*v01 - *v00);
-      NUMP;
+      DUMP;
     }
   }
@@ -261,5 +260,5 @@
     if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
       y = j + (level - *v01)/(*v01 - *v00);
-      NUMP;
+      DUMP;
     }
   }
@@ -274,15 +273,10 @@
     if (((*v00 > level) && (*v01 <= level)) || ((*v00 <= level) && (*v01 > level))) {
       y = j + (level - *v01)/(*v01 - *v00);
-      NUMP;
+      DUMP;
     }
   }
   
-  if (Nline > 0) {
-    SendGraphCommand (Ximage, 16, "NLINES  %7d ", Nline); 
-    write (Ximage, buffer, Nline*128); 
-  }
-
-  free (buffer);
-  SendGraphCommand (Ximage, 16, "DONE"); 
+  KiiLoadOverlay (Ximage, overlay, Noverlay, argv[2]);
+  free (overlay);
 
   if (Npix != 1) free (matrix);
