Changeset 7040 for trunk/Ohana/src/kapa/graph/PPMit.c
- Timestamp:
- May 2, 2006, 9:19:22 AM (20 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/kapa/graph/PPMit.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/kapa/graph/PPMit.c
r2473 r7040 1 1 # include "Ximage.h" 2 # define NPALETTE 93 2 4 3 int PPMit () { 5 4 6 5 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; 16 9 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 24 12 /* expect a line telling the number of bytes and a filename */ 25 13 status = read (sock, filename, 16); … … 29 17 filename[status] = 0; /* make the string easy to parse */ 30 18 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 43 19 f = fopen (filename, "w"); 44 20 if (f == (FILE *) NULL) { … … 47 23 } 48 24 25 palette = KapaPNGPalette (&Npalette); 26 27 dx = graphic.dx; 28 dy = graphic.dy; 29 49 30 fprintf (f, "P6\n"); 50 31 fprintf (f, "%d %d\n", dx, dy); 51 32 fprintf (f, "255\n"); 52 33 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); 54 48 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); 84 50 return (TRUE); 85 51
Note:
See TracChangeset
for help on using the changeset viewer.
