From c39e4120a5a3b8e990bd21b5f6ada02fab43495e Mon Sep 17 00:00:00 2001 From: chariot Date: Tue, 16 Jun 1987 09:25:57 +0000 Subject: slipt window_dumpo  into 3 subroutines, window_wdump, bitmap_wsize, and get_XColors --- xc/programs/xwd/xwd.c | 230 ++++++++++++++++++++++++++++---------------------- 1 file changed, 131 insertions(+), 99 deletions(-) (limited to 'xc/programs/xwd') diff --git a/xc/programs/xwd/xwd.c b/xc/programs/xwd/xwd.c index 144e394b0..1a0214311 100644 --- a/xc/programs/xwd/xwd.c +++ b/xc/programs/xwd/xwd.c @@ -37,7 +37,7 @@ */ #ifndef lint -static char *rcsid_xwd_c = "$Header: xwd.c,v 1.14 87/06/16 07:28:27 chariot Locked $"; +static char *rcsid_xwd_c = "$Header: xwd.c,v 1.15 87/06/16 07:39:00 chariot Locked $"; #endif /*% @@ -135,30 +135,22 @@ char *calloc(); #include "XWDFile.h" -#define UBPS (sizeof(short)/2) /* useful bytes per short */ -#define BitmapSize(width, height) (((((width) + 15) >> 3) &~ 1) * (height) * UBPS) -#define XYPixmapSize(width, height, planes) (BitmapSize(width, height) * (planes)) -/*% -#define BZPixmapSize(width, height) ((width) * (height)) -#define WZPixmapSize(width, height) (((width) * (height)) << 1) -%*/ - #define DONT_KNOW_YET 17 Window_Dump(window, out) Window window; FILE *out; { - register int i, *histbuffer; - register u_short *wbuffer; - register char *buffer, *cbuffer; + register int i; + register char *cbuffer; + XColor *pixcolors; unsigned buffer_size; unsigned int virt_width, virt_height; int virt_x, virt_y; int win_name_size; int header_size; -/*% int ncolors = 0; %*/ + int ncolors = 0; int depth; int offset; long plane_mask; @@ -219,27 +211,7 @@ Window_Dump(window, out) /* * Determine the pixmap size. */ - if (format == XYBitmap) - buffer_size = BitmapSize(virt_width, virt_height); - -/*% - else if (format == XYPixmap) { - buffer_size = XYPixmapSize(virt_width, virt_height, - DisplayPlanes(dpy, screen)); - if (debug) - outl("xwd: Pixmap in XYFormat, size %d bytes.\n", buffer_size); - } - else if (DisplayPlanes(dpy, screen) < 9) { - buffer_size = BZPixmapSize(virt_width, virt_height); - if (debug) - outl("xwd: Pixmap in byte ZFormat, size %d bytes.\n", buffer_size); - } - else { - buffer_size = WZPixmapSize(virt_width, virt_height); - if (debug) - outl("xwd: Pixmap in word ZFormat, size %d bytes.\n", buffer_size); - } -%*/ + buffer_size = Pixmap_Size(virt_width, virt_height); /* * Snarf the pixmap with XGetImage. @@ -258,67 +230,11 @@ Window_Dump(window, out) if (debug) outl("xwd: Getting pixmap.\n"); /* - * Find the number of colors used, then write them out to the file. + * Get XColors of all pixels used in the pixmap */ -/*% ncolors = 0; - if(DisplayPlanes(dpy, screen) > 1) { - if(DisplayPlanes(dpy, screen) < 9) { - histbuffer = (int *)calloc(256, sizeof(int)); - bzero(histbuffer, 256*sizeof(int)); - pixcolors = (XColor *)calloc(1, sizeof(XColor)); - for(i=0; idata, &pixcolors, buffer_size); - else -if(DisplayPlanes(dpy, screen) > 16) - Error("Unable to handle more than 16 planes at this time"); -%*/ /* reread in XY format if necessary */ /*% if(format == XYPixmap) { @@ -331,7 +247,6 @@ if(DisplayPlanes(dpy, screen) > 16) %*/ /*% } - free(histbuffer); } %*/ @@ -398,12 +313,6 @@ if(DisplayPlanes(dpy, screen) > 16) if(ncolors > 0) free(pixcolors); %*/ - /* - * Free the pixmap buffer. - */ - if (debug) outl("xwd: Freeing pixmap buffer.\n"); - free(buffer); - /* * Free window name string. */ @@ -438,3 +347,126 @@ Error(string) exit(1); } + + +/* + * Determine the pixmap size. + */ +#define UBPS (sizeof(short)/2) /* useful bytes per short */ +#define BitmapSize(width, height) (((((width) + 15) >> 3) &~ 1) * (height) * UBPS) +#define XYPixmapSize(width, height, planes) (BitmapSize(width, height) * (planes)) +#define BZPixmapSize(width, height) ((width) * (height)) +#define WZPixmapSize(width, height) (((width) * (height)) << 1) + +int Pixmap_Size(width, height) + int width, height; +{ + int buffer_size; + + if (format == XYBitmap) + buffer_size = BitmapSize(width, height); + +#ifdef COLOR + + else if (format == XYPixmap) { + buffer_size = XYPixmapSize(width, height, + DisplayPlanes(dpy, screen)); + if (debug) + outl("xwd: Pixmap in XYFormat, size %d bytes.\n", buffer_size); + } + else if (DisplayPlanes(dpy, screen) < 9) { + buffer_size = BZPixmapSize(width, height); + if (debug) + outl("xwd: Pixmap in byte ZFormat, size %d bytes.\n", + buffer_size); + } + else { + buffer_size = WZPixmapSize(width, height); + if (debug) + outl("xwd: Pixmap in word ZFormat, size %d bytes.\n", + buffer_size); + } +#endif + + return(buffer_size); +} + + +/* + * Get the XColors of all pixels in image - returns # of colors + */ +int Get_XColors(buffer, pixcolors, buffer_size) + char *buffer; + XColor *pixcolors[]; /* RETURNED */ + int buffer_size; +{ + register int i, *histbuffer; + register u_short *wbuffer; + register char *buffer; + int ncolors = 0; + + if (DisplayPlanes(dpy,screen)<2) + return(0); + +#ifdef COLOR + + if(DisplayPlanes(dpy, screen) < 9) { + histbuffer = (int *)calloc(256, sizeof(int)); + bzero(histbuffer, 256*sizeof(int)); + *pixcolors = (XColor *)calloc(1, sizeof(XColor)); + for(i=0; i 16) + Fatal_Error("Unable to handle more than 16 planes at this time"); + + free(histbuffer); + +#endif + + return(ncolors); +} -- cgit v1.2.3