Index: trunk/Ohana/src/kii/picture/CreatePicture.c
===================================================================
--- trunk/Ohana/src/kii/picture/CreatePicture.c	(revision 5700)
+++ trunk/Ohana/src/kii/picture/CreatePicture.c	(revision 5852)
@@ -4,5 +4,5 @@
 
   int i, j, extra;
-  char *c;
+  unsigned char *c;
   unsigned int *l;
   unsigned int start, start1, start2, start3;
@@ -13,5 +13,5 @@
   case 8:
     REALLOCATE (layout[0].picture.data, char, layout[0].picture.dx*layout[0].picture.dy);
-    c = layout[0].picture.data;
+    c = (unsigned char *) layout[0].picture.data;
     for (i = 0; i < (layout[0].picture.dx*layout[0].picture.dy); i++, c++)
       *c = start;
@@ -22,5 +22,5 @@
   case 16:
     REALLOCATE (layout[0].picture.data, char, 2*layout[0].picture.dy*layout[0].picture.dx);
-    c = layout[0].picture.data;
+    c = (unsigned char *) layout[0].picture.data;
     start1 = 0x0000ff & (start);
     start2 = 0x0000ff & (start >> 8);
Index: trunk/Ohana/src/kii/picture/JPEGit24.c
===================================================================
--- trunk/Ohana/src/kii/picture/JPEGit24.c	(revision 5700)
+++ trunk/Ohana/src/kii/picture/JPEGit24.c	(revision 5852)
@@ -1,6 +1,4 @@
 # include "Ximage.h"
 # include "jpeglib.h"
-# include <png.h>
-# include "bDraw.h"
 
 # define WHITE_R 255
@@ -18,5 +16,5 @@
   int ii, i, j;
   int i_start, i_end, j_start, j_end;
-  int dropback, extra;  /* this is a bit of a kludge... */
+  int dropback;  /* this is a bit of a kludge... */
   int dx, dy, DX, DY;
   int status, Nbytes, quality;
@@ -194,5 +192,5 @@
     bDrawBuffer *buffer;
 
-    palette = MakePNGPalette (&Npalette);
+    palette = KapaPNGPalette (&Npalette);
 
     buffer = bDrawBufferCreate (dx, dy);
@@ -202,5 +200,5 @@
     }
 
-    white = GetColorByName ("white");
+    white = KapaColorByName ("white");
     for (j = 0; j < dy; j++) {
       for (i = 0; i < dx; i++) {
Index: trunk/Ohana/src/kii/picture/NewPicture.c
===================================================================
--- trunk/Ohana/src/kii/picture/NewPicture.c	(revision 5700)
+++ trunk/Ohana/src/kii/picture/NewPicture.c	(revision 5852)
@@ -1,44 +1,31 @@
 # 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;
+  char *buff;
+  int status, bytes_left, socket;
  
-  fits_free_matrix (&layout[0].matrix);
-  sprintf (buffer, "NCOLOR: %6d ", layout[0].Npixels);
-  write (layout[0].Ximage, buffer, 16);
+  socket = layout[0].Ximage;
 
-  fcntl (layout[0].Ximage, F_SETFL, !O_NONBLOCK);  
+  KiiSendMessage (socket, "%d", layout[0].Npixels);
+
+  fcntl (socket, 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);
+  KiiScanMessage (socket, "%d %d %d %d %lf %lf", &header.Naxis[0], &header.Naxis[1]);
+  KiiScanMessage (socket, "%d %d %d %d %lf %lf", &header.bitpix, &header.unsign, &header.bzero, &header.bscale);
+  KiiScanMessage (socket, "%lf %lf",  &layout[0].zero, &layout[0].range);
+  KiiScanMessage (socket, "%lf %lf %d", &layout[0].min,  &layout[0].max, &header.size);
+  KiiScanMessage (socket, "%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);
+  KiiScanMessage (socket, "%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);
+	  
+  KiiScanMessage (socket, "%s %s %s", layout[0].coords.ctype, layout[0].file, layout[0].buffer_name);
 
-  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_free_matrix (&layout[0].matrix);
   fits_create_matrix (&header, &layout[0].matrix);
 
-  fcntl (layout[0].Ximage, F_SETFL, O_NONBLOCK);  
+  fcntl (socket, F_SETFL, O_NONBLOCK);  
 
   status = 1;
@@ -47,5 +34,5 @@
   layout[0].matrix.size = 0;
   while (bytes_left > 0) {
-    status = read (layout[0].Ximage, buff, bytes_left);
+    status = read (socket, buff, bytes_left);
     if (status == 0) {  /* No more pipe */
       fprintf (stderr, "error: pipe closed\n");
@@ -59,5 +46,5 @@
   }
 
-  (DEBUG) && fprintf (stderr, "read %d bytes\n", layout[0].matrix.size);
+  if (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) {  
@@ -69,7 +56,7 @@
 
   Remap (graphic, layout, &layout[0].matrix);
-  (DEBUG) && fprintf (stderr, "remapped image\n");
+  if (DEBUG) fprintf (stderr, "remapped image\n");
   Refresh (graphic, layout, 0);
-  (DEBUG) && fprintf (stderr, "refreshed\n");
+  if (DEBUG) fprintf (stderr, "refreshed\n");
   XFlush (graphic[0].display);
 
Index: trunk/Ohana/src/kii/picture/Remap8.c
===================================================================
--- trunk/Ohana/src/kii/picture/Remap8.c	(revision 5700)
+++ trunk/Ohana/src/kii/picture/Remap8.c	(revision 5852)
@@ -68,6 +68,6 @@
   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);
+  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) **********/
Index: trunk/Ohana/src/kii/picture/Resize.c
===================================================================
--- trunk/Ohana/src/kii/picture/Resize.c	(revision 5700)
+++ trunk/Ohana/src/kii/picture/Resize.c	(revision 5852)
@@ -1,20 +1,9 @@
 # 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);
+  KiiScanMessage (layout[0].Ximage, "%d %d", &NX, &NY);
 
   NX += ZOOM_X + 3*PAD1 + 25;
