IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 2, 2006, 9:19:22 AM (20 years ago)
Author:
eugene
Message:

removed old junk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa/graph/PPMit.c

    r2473 r7040  
    11# include "Ximage.h"
    2 # define NPALETTE 9
    32
    43int PPMit () {
    54
    65  FILE *f;
    7   int pixval[NPALETTE], red[NPALETTE], blue[NPALETTE], green[NPALETTE];
    8   XColor color;
    9   int dx, dy;
    10   int i, j, k, m, found;
    11   XImage *tmpimage;
    12   unsigned long pixel;
    13   char filename[1024];
    14   int Nbytes, status;
    15   char *buffer;
     6  char *line, filename[1024];
     7  int Nbytes, status, dx, dy, i, j, Npalette, color;
     8  png_color *palette;
    169
    17   XWindowAttributes WindowAttributes;
    18   Pixmap tmp_pixmap;
    19   Window tmp_window;
    20  
    21   dx = graphic.dx;
    22   dy = graphic.dy;
    23  
     10  bDrawBuffer *buffer;
     11
    2412  /* expect a line telling the number of bytes and a filename */
    2513  status = read (sock, filename, 16);
     
    2917  filename[status] = 0; /* make the string easy to parse */
    3018
    31   ALLOCATE (buffer, char, 3*dx*dy);
    32 
    33   /* define the palette */
    34   for (i = 0; i < NPALETTE; i++) {
    35     color.pixel = graphic.color[i];
    36     XQueryColor (graphic.display, graphic.colormap, &color);
    37     red[i]     = (color.red >> 8);
    38     green[i]   = (color.green >> 8);
    39     blue[i]    = (color.blue >> 8);
    40     pixval[i]  = color.pixel;
    41   }
    42 
    4319  f = fopen (filename, "w");
    4420  if (f == (FILE *) NULL) {
     
    4723  }
    4824 
     25  palette = KapaPNGPalette (&Npalette);
     26
     27  dx = graphic.dx;
     28  dy = graphic.dy;
     29 
    4930  fprintf (f, "P6\n");
    5031  fprintf (f, "%d %d\n", dx, dy);
    5132  fprintf (f, "255\n");
    5233
    53   XGetWindowAttributes (graphic.display, graphic.window, &WindowAttributes);
     34  buffer = bDrawIt ();
     35
     36  ALLOCATE (line, char, 3*dx);
     37
     38  for (i = 0; i < dy; i++) {
     39    for (j = 0; j < dx; j++) {
     40      color = buffer[0].pixels[i][j];
     41      line[3*j + 0] = palette[color].red;
     42      line[3*j + 1] = palette[color].green;
     43      line[3*j + 2] = palette[color].blue;
     44    }
     45    fwrite (line, 3, dx, f);
     46  }
     47  fclose (f);
    5448 
    55   tmp_pixmap = XCreatePixmap (graphic.display, graphic.window, dx, dy, WindowAttributes.depth);
    56  
    57   tmp_window = graphic.window;
    58   graphic.window = tmp_pixmap;
    59  
    60   Refresh (1);
    61  
    62   tmpimage = XGetImage (graphic.display, graphic.window, 0, 0, dx, dy, 0xffffffff, ZPixmap);
    63   for (m = j = 0; j < dy; j++) {
    64     for (i = 0; i < dx; i++, m+=3) {
    65       pixel = XGetPixel (tmpimage, i, j);
    66       for (found = k = 0; (k < NPALETTE) && !found; k++) {
    67         if (pixel == pixval[k]) {
    68           found = TRUE;
    69           buffer[m+0] = red[k];
    70           buffer[m+1] = green[k];
    71           buffer[m+2] = blue[k];
    72         }
    73       }
    74     }
    75   }
    76   graphic.window = tmp_window;
    77   XFreePixmap (graphic.display, tmp_pixmap);
    78 
    79   fwrite (buffer, 3, dx*dy, f);
    80 
    81   XDestroyImage (tmpimage);
    82 
    83   fclose (f);
     49  bDrawBufferFree (buffer);
    8450  return (TRUE);
    8551
Note: See TracChangeset for help on using the changeset viewer.