diff --git a/dsimple.c b/dsimple.c index 2c407cd..4e028e4 100644 --- a/dsimple.c +++ b/dsimple.c @@ -65,7 +65,8 @@ int screen = 0; * Get_Display_Name (argc, argv) Look for -display, -d, or host:dpy (obselete) * If found, remove it from command line. Don't go past a lone -. */ -char *Get_Display_Name( +char +*Get_Display_Name( int *pargc, /* MODIFIED */ char **argv) /* MODIFIED */ { @@ -75,21 +76,21 @@ char *Get_Display_Name( int i; for (i = 1; i < argc; i++) { - char *arg = argv[i]; + char *arg = argv[i]; - if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) { - if (++i >= argc) usage (); + if (!strcmp (arg, "-display") || !strcmp (arg, "-d")) { + if (++i >= argc) usage (); - displayname = argv[i]; - *pargc -= 2; - continue; - } - if (!strcmp(arg,"-")) { - while (inext = NULL; lp->ptr.item = NULL; @@ -53,21 +54,23 @@ void zero_list(list_ptr lp) /** ------------------------------------------------------------------------ - Adds item to the list pointed to by lp. Finds the end of the - list, then mallocs a new list node onto the end of the list. - The item pointer in the new node is set to "item" passed in, - and the next pointer in the new node is set to NULL. - Returns 1 if successful, 0 if the malloc failed. + Adds item to the list pointed to by lp. Finds the end of the + list, then mallocs a new list node onto the end of the list. + The item pointer in the new node is set to "item" passed in, + and the next pointer in the new node is set to NULL. + Returns 1 if successful, 0 if the malloc failed. -------------------------------------------------------------------- **/ -int add_to_list(list_ptr lp, void *item) +int +add_to_list(list_ptr lp, void *item) { while (lp->next) { - lp = lp->next; + lp = lp->next; } - if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) { - return 0; + if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) { + return 0; } + lp->next->ptr.item = item; lp->next->next = NULL; @@ -76,16 +79,17 @@ int add_to_list(list_ptr lp, void *item) /** ------------------------------------------------------------------------ - Creates a new list and sets its pointers to NULL. - Returns a pointer to the new list. + Creates a new list and sets its pointers to NULL. + Returns a pointer to the new list. -------------------------------------------------------------------- **/ -list_ptr new_list () +list_ptr +new_list (void) { list_ptr lp; if ((lp = (list_ptr) malloc( sizeof( list_item)))) { - lp->next = NULL; - lp->ptr.item = NULL; + lp->next = NULL; + lp->ptr.item = NULL; } return lp; @@ -93,15 +97,16 @@ list_ptr new_list () /** ------------------------------------------------------------------------ - Creates a new list head, pointing to the same list as the one - passed in. If start_at_curr is TRUE, the new list's first item - is the "current" item (as set by calls to first/next_in_list()). - If start_at_curr is FALSE, the first item in the new list is the - same as the first item in the old list. In either case, the - curr pointer in the new list is the same as in the old list. - Returns a pointer to the new list head. + Creates a new list head, pointing to the same list as the one + passed in. If start_at_curr is TRUE, the new list's first item + is the "current" item (as set by calls to first/next_in_list()). + If start_at_curr is FALSE, the first item in the new list is the + same as the first item in the old list. In either case, the + curr pointer in the new list is the same as in the old list. + Returns a pointer to the new list head. -------------------------------------------------------------------- **/ -list_ptr dup_list_head(list_ptr lp, int start_at_curr) +list_ptr +dup_list_head(list_ptr lp, int start_at_curr) { list_ptr new_list; @@ -117,15 +122,15 @@ list_ptr dup_list_head(list_ptr lp, int start_at_curr) /** ------------------------------------------------------------------------ - Returns the number of items in the list. + Returns the number of items in the list. -------------------------------------------------------------------- **/ unsigned int list_length(list_ptr lp) { unsigned int count = 0; while (lp->next) { - count++; - lp = lp->next; + count++; + lp = lp->next; } return count; @@ -133,27 +138,27 @@ unsigned int list_length(list_ptr lp) /** ------------------------------------------------------------------------ - Scans thru list, looking for a node whose ptr.item is equal to - the "item" passed in. "Equal" here means the same address - no - attempt is made to match equivalent values stored in different - locations. If a match is found, that node is deleted from the - list. Storage for the node is freed, but not for the item itself. - Returns a pointer to the item, so the caller can free it if it - so desires. If a match is not found, returns NULL. + Scans thru list, looking for a node whose ptr.item is equal to + the "item" passed in. "Equal" here means the same address - no + attempt is made to match equivalent values stored in different + locations. If a match is found, that node is deleted from the + list. Storage for the node is freed, but not for the item itself. + Returns a pointer to the item, so the caller can free it if it + so desires. If a match is not found, returns NULL. -------------------------------------------------------------------- **/ void *delete_from_list(list_ptr lp, void *item) { list_ptr new_next; while (lp->next) { - if (lp->next->ptr.item == item) { - new_next = lp->next->next; - free (lp->next); - lp->next = new_next; - - return item; - } - lp = lp->next; + if (lp->next->ptr.item == item) { + new_next = lp->next->next; + free (lp->next); + lp->next = new_next; + + return item; + } + lp = lp->next; } return NULL; @@ -161,54 +166,57 @@ void *delete_from_list(list_ptr lp, void *item) /** ------------------------------------------------------------------------ - Deletes each node in the list *except the head*. This allows - the deletion of lists where the head is not malloced or created - with new_list(). If free_items is true, each item pointed to - from the node is freed, in addition to the node itself. + Deletes each node in the list *except the head*. This allows + the deletion of lists where the head is not malloced or created + with new_list(). If free_items is true, each item pointed to + from the node is freed, in addition to the node itself. -------------------------------------------------------------------- **/ -void delete_list(list_ptr lp, int free_items) +void +delete_list(list_ptr lp, int free_items) { list_ptr del_node; void *item; while (lp->next) { - del_node = lp->next; - item = del_node->ptr.item; - lp->next = del_node->next; - free (del_node); - if (free_items) { - free( item); - } + del_node = lp->next; + item = del_node->ptr.item; + lp->next = del_node->next; + free (del_node); + if (free_items) { + free( item); + } } } -void delete_list_destroying(list_ptr lp, void destructor(void *item)) +void +delete_list_destroying(list_ptr lp, void destructor(void *item)) { list_ptr del_node; void *item; while (lp->next) { - del_node = lp->next; - item = del_node->ptr.item; - lp->next = del_node->next; - free( del_node); - if (destructor) { - destructor( item); - } + del_node = lp->next; + item = del_node->ptr.item; + lp->next = del_node->next; + free(del_node); + if (destructor) { + destructor(item); + } } } /** ------------------------------------------------------------------------ - Returns a ptr to the first *item* (not list node) in the list. - Sets the list head node's curr ptr to the first node in the list. - Returns NULL if the list is empty. + Returns a ptr to the first *item* (not list node) in the list. + Sets the list head node's curr ptr to the first node in the list. + Returns NULL if the list is empty. -------------------------------------------------------------------- **/ -void * first_in_list(list_ptr lp) +void * +first_in_list(list_ptr lp) { if (! lp) { - return NULL; + return NULL; } lp->ptr.curr = lp->next; @@ -216,19 +224,20 @@ void * first_in_list(list_ptr lp) } /** ------------------------------------------------------------------------ - Returns a ptr to the next *item* (not list node) in the list. - Sets the list head node's curr ptr to the next node in the list. - first_in_list must have been called prior. - Returns NULL if no next item. + Returns a ptr to the next *item* (not list node) in the list. + Sets the list head node's curr ptr to the next node in the list. + first_in_list must have been called prior. + Returns NULL if no next item. -------------------------------------------------------------------- **/ -void * next_in_list(list_ptr lp) +void* +next_in_list(list_ptr lp) { if (! lp) { - return NULL; + return NULL; } if (lp->ptr.curr) { - lp->ptr.curr = lp->ptr.curr->next; + lp->ptr.curr = lp->ptr.curr->next; } return lp->ptr.curr ? lp->ptr.curr->ptr.item : NULL; diff --git a/multiVis.c b/multiVis.c index e5ed2c7..f08cd3c 100644 --- a/multiVis.c +++ b/multiVis.c @@ -1,12 +1,12 @@ /* $Xorg: multiVis.c,v 1.5 2001/02/09 02:06:03 xorgcvs Exp $ */ /** ------------------------------------------------------------------------ - This file contains functions to create a list of regions which - tile a specified window. Each region contains all visible - portions of the window which are drawn with the same visual. - If the window consists of subwindows of two different visual types, - there will be two regions in the list. The list can be traversed - to correctly pull an image of the window using XGetImage or the - Image Library. + This file contains functions to create a list of regions which + tile a specified window. Each region contains all visible + portions of the window which are drawn with the same visual. + If the window consists of subwindows of two different visual types, + there will be two regions in the list. The list can be traversed + to correctly pull an image of the window using XGetImage or the + Image Library. Copyright 1994 Hewlett-Packard Co. Copyright 1996, 1998 The Open Group @@ -63,69 +63,57 @@ typedef struct { Window win; Visual *vis; Colormap cmap; - int x_rootrel, y_rootrel; /* root relative location of window */ - int x_vis, y_vis; /* rt rel x,y of vis part, not parent clipped */ - int width, height; /* width and height of visible part */ - int border_width; /* border width of the window */ - Window parent; /* id of parent (for debugging) */ + int x_rootrel, y_rootrel; /* root relative location of window */ + int x_vis, y_vis; /* rt rel x,y of vis part, not parent clipped */ + int width, height; /* width and height of visible part */ + int border_width; /* border width of the window */ + Window parent; /* id of parent (for debugging) */ } image_win_type; /* Items in short list of regions that tile the grabbed area. May have multiple windows in the region. */ typedef struct { - Window win; /* lowest window of this visual */ + Window win; /* lowest window of this visual */ Visual *vis; Colormap cmap; - int x_rootrel, y_rootrel; /* root relative location of bottom window */ - int x_vis, y_vis; /* rt rel x,y of vis part, not parent clipped */ - int width, height; /* w & h of visible rect of bottom window */ - int border; /* border width of the window */ + int x_rootrel, y_rootrel; /* root relative location of bottom window */ + int x_vis, y_vis; /* rt rel x,y of vis part, not parent clipped */ + int width, height; /* w & h of visible rect of bottom window */ + int border; /* border width of the window */ Region visible_region; } image_region_type; /** ------------------------------------------------------------------------ - Returns TRUE if the two structs pointed to have the same "vis" & - "cmap" fields and s2 lies completely within s1. s1 and s2 can - point to structs of image_win_type or image_region_type. + Returns TRUE if the two structs pointed to have the same "vis" & + "cmap" fields and s2 lies completely within s1. s1 and s2 can + point to structs of image_win_type or image_region_type. ------------------------------------------------------------------------ **/ -#define SAME_REGIONS( s1, s2) \ - ((s1)->vis == (s2)->vis && (s1)->cmap == (s2)->cmap && \ - (s1)->x_vis <= (s2)->x_vis && \ - (s1)->y_vis <= (s2)->y_vis && \ - (s1)->x_vis + (s1)->width >= (s2)->x_vis + (s2)->width && \ - (s1)->y_vis + (s1)->height >= (s2)->y_vis + (s2)->height) +#define SAME_REGIONS( s1, s2) \ + ((s1)->vis == (s2)->vis && (s1)->cmap == (s2)->cmap && \ + (s1)->x_vis <= (s2)->x_vis && \ + (s1)->y_vis <= (s2)->y_vis && \ + (s1)->x_vis + (s1)->width >= (s2)->x_vis + (s2)->width && \ + (s1)->y_vis + (s1)->height >= (s2)->y_vis + (s2)->height) #ifndef MIN -#define MIN( a, b) ((a) < (b) ? a : b) -#define MAX( a, b) ((a) > (b) ? a : b) +#define MIN( a, b) ((a) < (b) ? a : b) +#define MAX( a, b) ((a) > (b) ? a : b) #endif -#define RED_SHIFT 16 +#define RED_SHIFT 16 #define GREEN_SHIFT 8 #define BLUE_SHIFT 0 -/* -extern list_ptr new_list(); -extern list_ptr dup_list_head(); -extern void * first_in_list(); -extern void * next_in_list(); -extern int add_to_list(); -extern void zero_list(); -extern void delete_list(); -extern void delete_list_destroying(); -extern unsigned int list_length(); -*/ - /* Prototype Declarations for Static Functions */ static int QueryColorMap( Display *, Colormap , Visual *, XColor **, int *, int *, int * - ); + ); static void TransferImage( Display *, XImage *,int, int , image_region_type*, XImage *,int ,int - ); + ); static XImage * ReadRegionsInList( Display *, Visual *, int ,int ,int , int , XRectangle, list_ptr @@ -133,12 +121,12 @@ static XImage * ReadRegionsInList( static list_ptr make_region_list( Display*, Window, XRectangle*, - int*, int, XVisualInfo**, int * + int*, int, XVisualInfo**, int * ); static void destroy_region_list( list_ptr - ) ; + ); static void subtr_rect_from_image_region( image_region_type *, int , int , int , int ); @@ -151,11 +139,11 @@ static int src_in_region_list( ); static void add_window_to_list( list_ptr, Window, int, int , - int , int , int , int, int, + int , int , int , int, int, Visual*, Colormap, Window ); static int src_in_image( - image_win_type *, int , XVisualInfo** + image_win_type *, int , XVisualInfo** ); static int src_in_overlay( image_region_type *, int, OverlayInfo *, int*, int* @@ -170,39 +158,41 @@ static void destroy_image_region( /* End of Prototype Declarations */ -void initFakeVisual(Vis) -Visual *Vis ; +void +initFakeVisual(Visual *Vis) { Vis->ext_data=NULL; - Vis->class = DirectColor ; + Vis->class = DirectColor; Vis->red_mask = 0x00FF0000; - Vis->green_mask = 0x0000FF00 ; - Vis->blue_mask = 0x000000FF ; - Vis->map_entries = 256 ; - Vis->bits_per_rgb = 8 ; + Vis->green_mask = 0x0000FF00; + Vis->blue_mask = 0x000000FF; + Vis->map_entries = 256; + Vis->bits_per_rgb = 8; } static int -QueryColorMap(disp,src_cmap,src_vis,src_colors,rShift,gShift,bShift) -Display *disp ; -Visual *src_vis ; -Colormap src_cmap ; -XColor **src_colors ; -int *rShift, *gShift, *bShift; +QueryColorMap( + Display *disp, + Colormap src_cmap, + Visual *src_vis, + XColor **src_colors, + int *rShift, + int *gShift, + int *bShift) { - int ncolors,i ; + int ncolors,i; unsigned long redMask, greenMask, blueMask; int redShift, greenShift, blueShift; - XColor *colors ; + XColor *colors; - ncolors = src_vis->map_entries ; - *src_colors = colors = (XColor *)malloc(ncolors * sizeof(XColor) ) ; + ncolors = src_vis->map_entries; + *src_colors = colors = (XColor *)malloc(ncolors * sizeof(XColor) ); if(src_vis->class != TrueColor && src_vis->class != DirectColor) { - for(i=0 ; i < ncolors ; i++) + for(i=0; i < ncolors; i++) { - colors[i].pixel = i ; + colors[i].pixel = i; colors[i].pad = 0; colors[i].flags = DoRed|DoGreen|DoBlue; } @@ -225,46 +215,45 @@ int *rShift, *gShift, *bShift; blueShift++; blueMask = blueMask>>1; } - *rShift = redShift ; - *gShift = greenShift ; - *bShift = blueShift ; + *rShift = redShift; + *gShift = greenShift; + *bShift = blueShift; for (i=0; inext && (*vis_regions)->next->next ) || ( *vis_image_regions && (*vis_image_regions)->next && - (*vis_image_regions)->next->next ) ) return 1 ; - else return 0 ; + (*vis_image_regions)->next->next ) ) return 1; + else return 0; } -static void TransferImage(disp,reg_image,srcw,srch,reg, - target_image,dst_x,dst_y) -Display *disp; -XImage *reg_image,*target_image ; -image_region_type *reg; -int srcw,srch,dst_x , dst_y ; +static void +TransferImage( + Display *disp, + XImage *reg_image, + int srcw, + int srch, + image_region_type *reg, + XImage *target_image, + int dst_x, + int dst_y) { - int i,j,old_pixel,new_pixel,red_ind,green_ind,blue_ind ; + int i,j,old_pixel,new_pixel,red_ind,green_ind,blue_ind; XColor *colors; int rShift,gShift,bShift; (void) QueryColorMap(disp,reg->cmap,reg->vis,&colors, - &rShift,&gShift,&bShift) ; + &rShift,&gShift,&bShift); switch (reg->vis->class) { case TrueColor : - for(i=0 ; i < srch ; i++) + for(i=0; i < srch; i++) { - for(j=0 ; j < srcw ; j++) + for(j=0; j < srcw; j++) { - old_pixel = XGetPixel(reg_image,j,i) ; + old_pixel = XGetPixel(reg_image,j,i); if( reg->vis->map_entries == 16) { - - red_ind = (old_pixel & reg->vis->red_mask) >> rShift ; - green_ind = (old_pixel & reg->vis->green_mask) >> gShift ; - blue_ind = (old_pixel & reg->vis->blue_mask) >> bShift ; - - new_pixel = ( - ((colors[red_ind].red >> 8) << RED_SHIFT) - |((colors[green_ind].green >> 8) << GREEN_SHIFT) - |((colors[blue_ind].blue >> 8) << BLUE_SHIFT) + + red_ind = (old_pixel & reg->vis->red_mask) >> rShift; + green_ind = (old_pixel & reg->vis->green_mask) >> gShift; + blue_ind = (old_pixel & reg->vis->blue_mask) >> bShift; + + new_pixel = ( + ((colors[red_ind].red >> 8) << RED_SHIFT) + |((colors[green_ind].green >> 8) << GREEN_SHIFT) + |((colors[blue_ind].blue >> 8) << BLUE_SHIFT) ); } - else - new_pixel = old_pixel; + else + new_pixel = old_pixel; XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel); - + } } break; case DirectColor : - for(i=0 ; i < srch ; i++) + for(i=0; i < srch; i++) { - - for(j=0 ; j < srcw ; j++) + + for(j=0; j < srcw; j++) { - old_pixel = XGetPixel(reg_image,j,i) ; - red_ind = (old_pixel & reg->vis->red_mask) >> rShift ; - green_ind = (old_pixel & reg->vis->green_mask) >> gShift ; - blue_ind = (old_pixel & reg->vis->blue_mask) >> bShift ; - - new_pixel = ( - ((colors[red_ind].red >> 8) << RED_SHIFT) - |((colors[green_ind].green >> 8) << GREEN_SHIFT) - |((colors[blue_ind].blue >> 8) << BLUE_SHIFT) + old_pixel = XGetPixel(reg_image,j,i); + red_ind = (old_pixel & reg->vis->red_mask) >> rShift; + green_ind = (old_pixel & reg->vis->green_mask) >> gShift; + blue_ind = (old_pixel & reg->vis->blue_mask) >> bShift; + + new_pixel = ( + ((colors[red_ind].red >> 8) << RED_SHIFT) + |((colors[green_ind].green >> 8) << GREEN_SHIFT) + |((colors[blue_ind].blue >> 8) << BLUE_SHIFT) ); XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel); - + } } break; default : - for(i=0 ; i < srch ; i++) + for(i=0; i < srch; i++) { - for(j=0 ; j < srcw ; j++) + for(j=0; j < srcw; j++) { - old_pixel = XGetPixel(reg_image,j,i) ; - - new_pixel = ( - ((colors[old_pixel].red >> 8) << RED_SHIFT) - |((colors[old_pixel].green >> 8) << GREEN_SHIFT) - |((colors[old_pixel].blue >> 8) << BLUE_SHIFT) + old_pixel = XGetPixel(reg_image,j,i); + + new_pixel = ( + ((colors[old_pixel].red >> 8) << RED_SHIFT) + |((colors[old_pixel].green >> 8) << GREEN_SHIFT) + |((colors[old_pixel].blue >> 8) << BLUE_SHIFT) ); XPutPixel(target_image,dst_x+j, dst_y+i,new_pixel); - + } } break; @@ -388,21 +381,23 @@ int srcw,srch,dst_x , dst_y ; } static XImage * -ReadRegionsInList(disp,fakeVis,depth,format,width,height,bbox,regions) -Display *disp ; -Visual *fakeVis ; -int depth , width , height ; -int format ; -XRectangle bbox; /* bounding box of grabbed area */ -list_ptr regions;/* list of regions to read from */ +ReadRegionsInList( + Display *disp, + Visual *fakeVis, + int depth, + int format, + int width, + int height, + XRectangle bbox, /* bounding box of grabbed area */ + list_ptr regions) /* list of regions to read from */ { - image_region_type *reg; - int dst_x, dst_y; /* where in pixmap to write (UL) */ - int diff; + image_region_type *reg; + int dst_x, dst_y; /* where in pixmap to write (UL) */ + int diff; - XImage *reg_image,*ximage ; - int srcRect_x,srcRect_y,srcRect_width,srcRect_height ; - int rem ; + XImage *reg_image,*ximage; + int srcRect_x,srcRect_y,srcRect_width,srcRect_height; + int rem; int bytes_per_line; int bitmap_unit; @@ -422,231 +417,230 @@ list_ptr regions;/* list of regions to read from */ } ximage = XCreateImage(disp,fakeVis,depth,format,0,NULL,width,height, - 8,0) ; + 8,0); bytes_per_line = ximage->bytes_per_line; if (format == ZPixmap) - ximage->data = malloc(height*bytes_per_line); + ximage->data = malloc(height*bytes_per_line); else ximage->data = malloc(height*bytes_per_line*depth); ximage->bits_per_pixel = depth; /** Valid only if format is ZPixmap ***/ for (reg = (image_region_type *) first_in_list( regions); reg; - reg = (image_region_type *) next_in_list( regions)) + reg = (image_region_type *) next_in_list( regions)) { - int rect; - struct my_XRegion *vis_reg; - vis_reg = (struct my_XRegion *)(reg->visible_region); - for (rect = 0; - rect < vis_reg->numRects; - rect++) - { - /** ------------------------------------------------------------------------ - Intersect bbox with visible part of region giving src rect & output - location. Width is the min right side minus the max left side. - Similar for height. Offset src rect so x,y are relative to - origin of win, not the root-relative visible rect of win. - ------------------------------------------------------------------------ **/ - srcRect_width = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x) - - MAX( vis_reg->rects[rect].x1, bbox.x); - srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y) - - MAX( vis_reg->rects[rect].y1, bbox.y); - diff = bbox.x - vis_reg->rects[rect].x1; - srcRect_x = MAX( 0, diff) + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border); - dst_x = MAX( 0, -diff) ; - diff = bbox.y - vis_reg->rects[rect].y1; - srcRect_y = MAX( 0, diff) + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border); - dst_y = MAX( 0, -diff) ; + int rect; + struct my_XRegion *vis_reg; + vis_reg = (struct my_XRegion *)(reg->visible_region); + for (rect = 0; + rect < vis_reg->numRects; + rect++) + { + /** ------------------------------------------------------------------------ + Intersect bbox with visible part of region giving src rect & output + location. Width is the min right side minus the max left side. + Similar for height. Offset src rect so x,y are relative to + origin of win, not the root-relative visible rect of win. + ------------------------------------------------------------------------ **/ + srcRect_width = MIN( vis_reg->rects[rect].x2, bbox.width + bbox.x) - + MAX( vis_reg->rects[rect].x1, bbox.x); + srcRect_height = MIN( vis_reg->rects[rect].y2, bbox.height + bbox.y) - + MAX( vis_reg->rects[rect].y1, bbox.y); + diff = bbox.x - vis_reg->rects[rect].x1; + srcRect_x = MAX( 0, diff) + (vis_reg->rects[rect].x1 - reg->x_rootrel - reg->border); + dst_x = MAX( 0, -diff); + diff = bbox.y - vis_reg->rects[rect].y1; + srcRect_y = MAX( 0, diff) + (vis_reg->rects[rect].y1 - reg->y_rootrel - reg->border); + dst_y = MAX( 0, -diff); reg_image = XGetImage(disp,reg->win,srcRect_x,srcRect_y, - srcRect_width,srcRect_height,AllPlanes,format) ; - TransferImage(disp,reg_image,srcRect_width, - srcRect_height,reg,ximage,dst_x,dst_y) ; - } + srcRect_width,srcRect_height,AllPlanes,format); + TransferImage(disp,reg_image,srcRect_width, + srcRect_height,reg,ximage,dst_x,dst_y); + } } - return ximage ; + return ximage; } /** ------------------------------------------------------------------------ ------------------------------------------------------------------------ **/ -XImage *ReadAreaToImage(disp, srcRootWinid, x, y, width, height, - numVisuals,pVisuals,numOverlayVisuals,pOverlayVisuals,numImageVisuals, - pImageVisuals,vis_regions,vis_image_regions,format,allImage) - Display *disp; - Window srcRootWinid; /* root win on which grab was done */ - int x; /* root rel UL corner of bounding box of grab */ - int y; - unsigned int width; /* size of bounding box of grab */ - unsigned int height; - /** int transparentOverlays; ***/ - int numVisuals; - XVisualInfo *pVisuals; - int numOverlayVisuals; - OverlayInfo *pOverlayVisuals; - int numImageVisuals; - XVisualInfo **pImageVisuals; - list_ptr vis_regions; /* list of regions to read from */ - list_ptr vis_image_regions ;/* list of regions to read from */ - int format; - int allImage ; +XImage * +ReadAreaToImage( + Display *disp, + Window srcRootWinid, /* root win on which grab was done */ + int x, /* root rel UL corner of bounding box of grab */ + int y, + unsigned int width, /* size of bounding box of grab */ + unsigned int height, + /** int transparentOverlays; ***/ + int numVisuals, + XVisualInfo *pVisuals, + int numOverlayVisuals, + OverlayInfo *pOverlayVisuals, + int numImageVisuals, + XVisualInfo **pImageVisuals, + list_ptr vis_regions, /* list of regions to read from */ + list_ptr vis_image_regions,/* list of regions to read from */ + int format, + int allImage) { - image_region_type *reg; - XRectangle bbox; /* bounding box of grabbed area */ - int depth ; - XImage *ximage, *ximage_ipm = NULL; - Visual fakeVis ; - int x1, y1; - XImage *image; + image_region_type *reg; + XRectangle bbox; /* bounding box of grabbed area */ + int depth; + XImage *ximage, *ximage_ipm = NULL; + Visual fakeVis; + int x1, y1; + XImage *image; #if 0 - unsigned char *pmData , *ipmData ; + unsigned char *pmData , *ipmData; #endif int transparentColor, transparentType; - int srcRect_x,srcRect_y,srcRect_width,srcRect_height ; - int diff ; - int dst_x, dst_y; /* where in pixmap to write (UL) */ - int pixel; + int srcRect_x,srcRect_y,srcRect_width,srcRect_height; + int diff; + int dst_x, dst_y; /* where in pixmap to write (UL) */ + int pixel; - bbox.x = x; /* init X rect for bounding box */ + bbox.x = x; /* init X rect for bounding box */ bbox.y = y; bbox.width = width; bbox.height = height; - initFakeVisual(&fakeVis) ; + initFakeVisual(&fakeVis); - depth = 24 ; + depth = 24; ximage = ReadRegionsInList(disp,&fakeVis,depth,format,width,height, - bbox,vis_regions) ; + bbox,vis_regions); #if 0 - pmData = (unsigned char *)ximage -> data ; + pmData = (unsigned char *)ximage -> data; #endif /* if transparency possible do it again, but this time for image planes only */ if (vis_image_regions && (vis_image_regions->next) && !allImage) { - ximage_ipm = ReadRegionsInList(disp,&fakeVis,depth,format,width,height, - bbox,vis_image_regions) ; + ximage_ipm = ReadRegionsInList(disp,&fakeVis,depth,format,width,height, + bbox,vis_image_regions); #if 0 - ipmData = (unsigned char *)ximage_ipm -> data ; + ipmData = (unsigned char *)ximage_ipm -> data; #endif } /* Now tranverse the overlay visual windows and test for transparency index. */ /* If you find one, subsitute the value from the matching image plane pixmap. */ for (reg = (image_region_type *) first_in_list( vis_regions); reg; - reg = (image_region_type *) next_in_list( vis_regions)) + reg = (image_region_type *) next_in_list( vis_regions)) { - if (src_in_overlay( reg, numOverlayVisuals, pOverlayVisuals, - &transparentColor, &transparentType)) - { - int test = 0 ; - srcRect_width = MIN( reg->width + reg->x_vis, bbox.width + bbox.x) - - MAX( reg->x_vis, bbox.x); - srcRect_height = MIN( reg->height + reg->y_vis, bbox.height - + bbox.y) - MAX( reg->y_vis, bbox.y); + if (src_in_overlay( reg, numOverlayVisuals, pOverlayVisuals, + &transparentColor, &transparentType)) + { + int test = 0; + srcRect_width = MIN( reg->width + reg->x_vis, bbox.width + bbox.x) + - MAX( reg->x_vis, bbox.x); + srcRect_height = MIN( reg->height + reg->y_vis, bbox.height + + bbox.y) - MAX( reg->y_vis, bbox.y); diff = bbox.x - reg->x_vis; srcRect_x = MAX( 0, diff) + (reg->x_vis - reg->x_rootrel - reg->border); - dst_x = MAX( 0, -diff) ; - diff = bbox.y - reg->y_vis; - srcRect_y = MAX( 0, diff) + (reg->y_vis - reg->y_rootrel - reg->border); - dst_y = MAX( 0, -diff) ; - /* let's test some pixels for transparency */ + dst_x = MAX( 0, -diff); + diff = bbox.y - reg->y_vis; + srcRect_y = MAX( 0, diff) + (reg->y_vis - reg->y_rootrel - reg->border); + dst_y = MAX( 0, -diff); + /* let's test some pixels for transparency */ image = XGetImage(disp, reg->win, srcRect_x, srcRect_y, - srcRect_width, srcRect_height, 0xffffffff, ZPixmap); + srcRect_width, srcRect_height, 0xffffffff, ZPixmap); /* let's assume byte per pixel for overlay image for now */ - if ((image->depth == 8) && (transparentType == TransparentPixel)) - { - unsigned char *pixel_ptr; - unsigned char *start_of_line = (unsigned char *) image->data; - - for (y1 = 0; y1 < srcRect_height; y1++) { - pixel_ptr = start_of_line; - for (x1 = 0; x1 < srcRect_width; x1++) - { - if (*pixel_ptr++ == transparentColor) - { + if ((image->depth == 8) && (transparentType == TransparentPixel)) + { + unsigned char *pixel_ptr; + unsigned char *start_of_line = (unsigned char *) image->data; + + for (y1 = 0; y1 < srcRect_height; y1++) { + pixel_ptr = start_of_line; + for (x1 = 0; x1 < srcRect_width; x1++) + { + if (*pixel_ptr++ == transparentColor) + { #if 0 - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; + *pmData++ = *ipmData++; + *pmData++ = *ipmData++; + *pmData++ = *ipmData++; #endif - pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ; + pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1); XPutPixel(ximage,dst_x+x1, dst_y+y1,pixel); - - if(!test){ - test = 1 ; - } - } + + if(!test){ + test = 1; + } + } #if 0 - else { - pmData +=3; - ipmData +=3; - } + else { + pmData +=3; + ipmData +=3; + } #endif - } - start_of_line += image->bytes_per_line; - } - } else { - if (transparentType == TransparentPixel) { - for (y1 = 0; y1 < srcRect_height; y1++) { - for (x1 = 0; x1 < srcRect_width; x1++) - { - int pixel_value = XGetPixel(image, x1, y1); - if (pixel_value == transparentColor) - { + } + start_of_line += image->bytes_per_line; + } + } else { + if (transparentType == TransparentPixel) { + for (y1 = 0; y1 < srcRect_height; y1++) { + for (x1 = 0; x1 < srcRect_width; x1++) + { + int pixel_value = XGetPixel(image, x1, y1); + if (pixel_value == transparentColor) + { #if 0 - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; + *pmData++ = *ipmData++; + *pmData++ = *ipmData++; + *pmData++ = *ipmData++; #endif - pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ; + pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1); XPutPixel(ximage,dst_x+x1, dst_y+y1,pixel); - if(!test){ - test = 1 ; - } - } + if(!test){ + test = 1; + } + } #if 0 - else { - pmData +=3; - ipmData +=3; - } + else { + pmData +=3; + ipmData +=3; + } #endif - } - } - } else { - for (y1 = 0; y1 < srcRect_height; y1++) { - for (x1 = 0; x1 < srcRect_width; x1++) - { - int pixel_value = XGetPixel(image, x1, y1); - if (pixel_value & transparentColor) - { + } + } + } else { + for (y1 = 0; y1 < srcRect_height; y1++) { + for (x1 = 0; x1 < srcRect_width; x1++) + { + int pixel_value = XGetPixel(image, x1, y1); + if (pixel_value & transparentColor) + { #if 0 - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; - *pmData++ = *ipmData++; + *pmData++ = *ipmData++; + *pmData++ = *ipmData++; + *pmData++ = *ipmData++; #endif - pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1) ; + pixel = XGetPixel(ximage_ipm,dst_x+x1,dst_y+y1); XPutPixel(ximage,dst_x+x1, dst_y+y1,pixel); - if(!test){ - test = 1 ; - } - } + if(!test){ + test = 1; + } + } #if 0 - else { - pmData +=3; - ipmData +=3; - } + else { + pmData +=3; + ipmData +=3; + } #endif - } - } - } - } + } + } + } + } XDestroyImage (image); - } /* end of src_in_overlay */ + } /* end of src_in_overlay */ } /** end transparency **/ destroy_region_list( vis_regions); if (vis_image_regions) destroy_region_list( vis_image_regions ); @@ -657,130 +651,130 @@ XImage *ReadAreaToImage(disp, srcRootWinid, x, y, width, height, } /** ------------------------------------------------------------------------ - Creates a list of the subwindows of a given window which have a - different visual than their parents. The function is recursive. - This list is used in make_region_list(), which coalesces the - windows with the same visual into a region. - image_wins must point to an existing list struct that's already - been zeroed (zero_list()). + Creates a list of the subwindows of a given window which have a + different visual than their parents. The function is recursive. + This list is used in make_region_list(), which coalesces the + windows with the same visual into a region. + image_wins must point to an existing list struct that's already + been zeroed (zero_list()). ------------------------------------------------------------------------ **/ -static void make_src_list( disp, image_wins, bbox, curr, x_rootrel, y_rootrel, - curr_attrs, pclip) - Display *disp; - list_ptr image_wins; - XRectangle *bbox; /* bnding box of area we want */ - Window curr; - int x_rootrel; /* pos of curr WRT root */ - int y_rootrel; - XWindowAttributes *curr_attrs; - XRectangle *pclip; /* visible part of curr, not */ - /* obscurred by ancestors */ +static void +make_src_list( + Display *disp, + list_ptr image_wins, + XRectangle *bbox, /* bnding box of area we want */ + Window curr, + int x_rootrel, /* pos of curr WRT root */ + int y_rootrel, + XWindowAttributes *curr_attrs, + XRectangle *pclip) /* visible part of curr, not */ + /* obscurred by ancestors */ { XWindowAttributes child_attrs; - Window root, parent, *child; /* variables for XQueryTree() */ - Window *save_child_list; /* variables for XQueryTree() */ - unsigned int nchild; /* variables for XQueryTree() */ - XRectangle child_clip; /* vis part of child */ + Window root, parent, *child; /* variables for XQueryTree() */ + Window *save_child_list; /* variables for XQueryTree() */ + unsigned int nchild; /* variables for XQueryTree() */ + XRectangle child_clip; /* vis part of child */ int curr_clipX, curr_clipY, curr_clipRt, curr_clipBt; /* check that win is mapped & not outside bounding box */ if (curr_attrs->map_state == IsViewable && - curr_attrs->class == InputOutput && - !( pclip->x >= (int) (bbox->x + bbox->width) || - pclip->y >= (int) (bbox->y + bbox->height) || - (int) (pclip->x + pclip->width) <= bbox->x || - (int) (pclip->y + pclip->height) <= bbox->y)) { - - XQueryTree( disp, curr, &root, &parent, &child, &nchild ); - save_child_list = child; /* so we can free list when we're done */ - add_window_to_list( image_wins, curr, x_rootrel, y_rootrel, - pclip->x, pclip->y, - pclip->width, pclip->height, - curr_attrs->border_width,curr_attrs->visual, - curr_attrs->colormap, parent); - - + curr_attrs->class == InputOutput && + !( pclip->x >= (int) (bbox->x + bbox->width) || + pclip->y >= (int) (bbox->y + bbox->height) || + (int) (pclip->x + pclip->width) <= bbox->x || + (int) (pclip->y + pclip->height) <= bbox->y)) { + + XQueryTree( disp, curr, &root, &parent, &child, &nchild ); + save_child_list = child; /* so we can free list when we're done */ + add_window_to_list( image_wins, curr, x_rootrel, y_rootrel, + pclip->x, pclip->y, + pclip->width, pclip->height, + curr_attrs->border_width,curr_attrs->visual, + curr_attrs->colormap, parent); + + /** ------------------------------------------------------------------------ - set RR coords of right (Rt), left (X), bottom (Bt) and top (Y) - of rect we clip all children by. This is our own clip rect (pclip) - inflicted on us by our parent plus our own borders. Within the - child loop, we figure the clip rect for each child by adding in - it's rectangle (not taking into account the child's borders). + set RR coords of right (Rt), left (X), bottom (Bt) and top (Y) + of rect we clip all children by. This is our own clip rect (pclip) + inflicted on us by our parent plus our own borders. Within the + child loop, we figure the clip rect for each child by adding in + it's rectangle (not taking into account the child's borders). ------------------------------------------------------------------------ **/ - curr_clipX = MAX( pclip->x, x_rootrel + (int) curr_attrs->border_width); - curr_clipY = MAX( pclip->y, y_rootrel + (int) curr_attrs->border_width); - curr_clipRt = MIN( pclip->x + (int) pclip->width, - x_rootrel + (int) curr_attrs->width + - 2 * (int) curr_attrs->border_width); - curr_clipBt = MIN( pclip->y + (int) pclip->height, - y_rootrel + (int) curr_attrs->height + - 2 * (int) curr_attrs->border_width); - - while (nchild--) { - int new_width, new_height; - int child_xrr, child_yrr; /* root relative x & y of child */ - - XGetWindowAttributes( disp, *child, &child_attrs); - - /* intersect parent & child clip rects */ - child_xrr = x_rootrel + child_attrs.x + curr_attrs->border_width; - child_clip.x = MAX( curr_clipX, child_xrr); - new_width = MIN( curr_clipRt, child_xrr + (int) child_attrs.width - + 2 * child_attrs.border_width) - - child_clip.x; - if (new_width >= 0) { - child_clip.width = new_width; - - child_yrr = y_rootrel + child_attrs.y + - curr_attrs->border_width; - child_clip.y = MAX( curr_clipY, child_yrr); - new_height = MIN( curr_clipBt, - child_yrr + (int) child_attrs.height + - 2 * child_attrs.border_width) - - child_clip.y; - if (new_height >= 0) { - child_clip.height = new_height; - make_src_list( disp, image_wins, bbox, *child, - child_xrr, child_yrr, - &child_attrs, &child_clip); - } - } - child++; - } - XFree( save_child_list); + curr_clipX = MAX( pclip->x, x_rootrel + (int) curr_attrs->border_width); + curr_clipY = MAX( pclip->y, y_rootrel + (int) curr_attrs->border_width); + curr_clipRt = MIN( pclip->x + (int) pclip->width, + x_rootrel + (int) curr_attrs->width + + 2 * (int) curr_attrs->border_width); + curr_clipBt = MIN( pclip->y + (int) pclip->height, + y_rootrel + (int) curr_attrs->height + + 2 * (int) curr_attrs->border_width); + + while (nchild--) { + int new_width, new_height; + int child_xrr, child_yrr; /* root relative x & y of child */ + + XGetWindowAttributes( disp, *child, &child_attrs); + + /* intersect parent & child clip rects */ + child_xrr = x_rootrel + child_attrs.x + curr_attrs->border_width; + child_clip.x = MAX( curr_clipX, child_xrr); + new_width = MIN( curr_clipRt, child_xrr + (int) child_attrs.width + + 2 * child_attrs.border_width) + - child_clip.x; + if (new_width >= 0) { + child_clip.width = new_width; + + child_yrr = y_rootrel + child_attrs.y + + curr_attrs->border_width; + child_clip.y = MAX( curr_clipY, child_yrr); + new_height = MIN( curr_clipBt, + child_yrr + (int) child_attrs.height + + 2 * child_attrs.border_width) + - child_clip.y; + if (new_height >= 0) { + child_clip.height = new_height; + make_src_list( disp, image_wins, bbox, *child, + child_xrr, child_yrr, + &child_attrs, &child_clip); + } + } + child++; + } + XFree( save_child_list); } } /** ------------------------------------------------------------------------ - This function creates a list of regions which tile a specified - window. Each region contains all visible portions of the window - which are drawn with the same visual. For example, if the - window consists of subwindows of two different visual types, - there will be two regions in the list. - Returns a pointer to the list. + This function creates a list of regions which tile a specified + window. Each region contains all visible portions of the window + which are drawn with the same visual. For example, if the + window consists of subwindows of two different visual types, + there will be two regions in the list. + Returns a pointer to the list. ------------------------------------------------------------------------ **/ -static list_ptr make_region_list( disp, win, bbox, hasNonDefault, - numImageVisuals, pImageVisuals, allImage) - Display *disp; - Window win; - XRectangle *bbox; - int *hasNonDefault; - int numImageVisuals; - XVisualInfo **pImageVisuals; - int *allImage; +static list_ptr +make_region_list( + Display *disp, + Window win, + XRectangle *bbox, + int *hasNonDefault, + int numImageVisuals, + XVisualInfo **pImageVisuals, + int *allImage) { - XWindowAttributes win_attrs; - list image_wins; - list_ptr image_regions; - list_ptr srcs_left; - image_region_type *new_reg; - image_win_type *base_src, *src; - Region bbox_region = XCreateRegion(); - XRectangle clip; - int image_only; - - int count=0 ; + XWindowAttributes win_attrs; + list image_wins; + list_ptr image_regions; + list_ptr srcs_left; + image_region_type *new_reg; + image_win_type *base_src, *src; + Region bbox_region = XCreateRegion(); + XRectangle clip; + int image_only; + + int count=0; *hasNonDefault = False; XUnionRectWithRegion( bbox, bbox_region, bbox_region); @@ -792,106 +786,107 @@ static list_ptr make_region_list( disp, win, bbox, hasNonDefault, clip.width = win_attrs.width; clip.height = win_attrs.height; make_src_list( disp, &image_wins, bbox, win, - 0 /* x_rootrel */, 0 /* y_rootrel */, &win_attrs, &clip); + 0 /* x_rootrel */, 0 /* y_rootrel */, &win_attrs, &clip); image_regions = new_list(); image_only = (*allImage) ? True:False; for (base_src = (image_win_type *) first_in_list( &image_wins); base_src; - base_src = (image_win_type *) next_in_list( &image_wins)) + base_src = (image_win_type *) next_in_list( &image_wins)) + { + /* test for image visual */ + if (!image_only || src_in_image(base_src, numImageVisuals, pImageVisuals)) { - /* test for image visual */ - if (!image_only || src_in_image(base_src, numImageVisuals, pImageVisuals)) - { - /* find a window whose visual hasn't been put in list yet */ - if (!src_in_region_list( base_src, image_regions)) - { - if (! (new_reg = (image_region_type *) - malloc( sizeof( image_region_type)))) { - return (list_ptr) NULL; - } - count++; - - new_reg->visible_region = XCreateRegion(); - new_reg->win = base_src->win; - new_reg->vis = base_src->vis; - new_reg->cmap = base_src->cmap; - new_reg->x_rootrel = base_src->x_rootrel; - new_reg->y_rootrel = base_src->y_rootrel; - new_reg->x_vis = base_src->x_vis; - new_reg->y_vis = base_src->y_vis; - new_reg->width = base_src->width; - new_reg->height = base_src->height; - new_reg->border = base_src->border_width; - - srcs_left = (list_ptr) dup_list_head( &image_wins, START_AT_CURR); - for (src = (image_win_type *) first_in_list( srcs_left); src; - src = (image_win_type *) next_in_list( srcs_left)) { - if (SAME_REGIONS( base_src, src)) { - add_rect_to_image_region( new_reg, src->x_vis, src->y_vis, - src->width, src->height); - } - else { - if (!image_only || src_in_image(src, numImageVisuals, pImageVisuals)) - { - subtr_rect_from_image_region( new_reg, src->x_vis, - src->y_vis, src->width, src->height); - } - } - } - XIntersectRegion( bbox_region, new_reg->visible_region, - new_reg->visible_region); - if (! XEmptyRegion( new_reg->visible_region)) { - add_to_list( image_regions, new_reg); - if (new_reg->vis != DefaultVisualOfScreen( win_attrs.screen) || - new_reg->cmap != DefaultColormapOfScreen( - win_attrs.screen)) { - *hasNonDefault = True; - } - } - else { - XDestroyRegion( new_reg->visible_region); - free( (void *) new_reg); - } - } - } else *allImage = 0; + /* find a window whose visual hasn't been put in list yet */ + if (!src_in_region_list( base_src, image_regions)) + { + if (! (new_reg = (image_region_type *) + malloc( sizeof( image_region_type)))) { + return (list_ptr) NULL; + } + count++; + + new_reg->visible_region = XCreateRegion(); + new_reg->win = base_src->win; + new_reg->vis = base_src->vis; + new_reg->cmap = base_src->cmap; + new_reg->x_rootrel = base_src->x_rootrel; + new_reg->y_rootrel = base_src->y_rootrel; + new_reg->x_vis = base_src->x_vis; + new_reg->y_vis = base_src->y_vis; + new_reg->width = base_src->width; + new_reg->height = base_src->height; + new_reg->border = base_src->border_width; + + srcs_left = (list_ptr) dup_list_head( &image_wins, START_AT_CURR); + for (src = (image_win_type *) first_in_list( srcs_left); src; + src = (image_win_type *) next_in_list( srcs_left)) { + if (SAME_REGIONS( base_src, src)) { + add_rect_to_image_region( new_reg, src->x_vis, src->y_vis, + src->width, src->height); + } + else { + if (!image_only || src_in_image(src, numImageVisuals, pImageVisuals)) + { + subtr_rect_from_image_region( new_reg, src->x_vis, + src->y_vis, src->width, src->height); + } + } + } + XIntersectRegion( bbox_region, new_reg->visible_region, + new_reg->visible_region); + if (! XEmptyRegion( new_reg->visible_region)) { + add_to_list( image_regions, new_reg); + if (new_reg->vis != DefaultVisualOfScreen( win_attrs.screen) || + new_reg->cmap != DefaultColormapOfScreen( + win_attrs.screen)) { + *hasNonDefault = True; + } + } + else { + XDestroyRegion( new_reg->visible_region); + free( (void *) new_reg); + } + } + } else *allImage = 0; } delete_list( &image_wins, True); XDestroyRegion( bbox_region); return image_regions; } /** ------------------------------------------------------------------------ - Destructor called from destroy_region_list(). + Destructor called from destroy_region_list(). ------------------------------------------------------------------------ **/ -static void destroy_image_region(image_region) - image_region_type *image_region; +static void +destroy_image_region(image_region_type *image_region) { XDestroyRegion( image_region->visible_region); free( (void *) image_region); } /** ------------------------------------------------------------------------ - Destroys the region list, destroying all the regions contained in it. + Destroys the region list, destroying all the regions contained in it. ------------------------------------------------------------------------ **/ -static void destroy_region_list( rlist) - list_ptr rlist; +static void +destroy_region_list(list_ptr rlist) { delete_list_destroying( rlist, (DESTRUCT_FUNC_PTR)destroy_image_region); } /** ------------------------------------------------------------------------ - Subtracts the specified rectangle from the region in image_region. - First converts the rectangle to a region of its own, since X - only provides a way to subtract one region from another, not a - rectangle from a region. + Subtracts the specified rectangle from the region in image_region. + First converts the rectangle to a region of its own, since X + only provides a way to subtract one region from another, not a + rectangle from a region. ------------------------------------------------------------------------ **/ -static void subtr_rect_from_image_region( image_region, x, y, width, height) - image_region_type *image_region; - int x; - int y; - int width; - int height; +static void +subtr_rect_from_image_region( + image_region_type *image_region, + int x, + int y, + int width, + int height) { XRectangle rect; Region rect_region; @@ -903,20 +898,21 @@ static void subtr_rect_from_image_region( image_region, x, y, width, height) rect.height = height; XUnionRectWithRegion( &rect, rect_region, rect_region); XSubtractRegion( image_region->visible_region, rect_region, - image_region->visible_region); + image_region->visible_region); XDestroyRegion( rect_region); } /** ------------------------------------------------------------------------ - Adds the specified rectangle to the region in image_region. + Adds the specified rectangle to the region in image_region. ------------------------------------------------------------------------ **/ -static void add_rect_to_image_region( image_region, x, y, width, height) - image_region_type *image_region; - int x; - int y; - int width; - int height; +static void +add_rect_to_image_region( + image_region_type *image_region, + int x, + int y, + int width, + int height) { XRectangle rect; @@ -925,26 +921,27 @@ static void add_rect_to_image_region( image_region, x, y, width, height) rect.width = width; rect.height = height; XUnionRectWithRegion( &rect, image_region->visible_region, - image_region->visible_region); + image_region->visible_region); } /** ------------------------------------------------------------------------ - Returns TRUE if the given src's visual is already represented in - the image_regions list, FALSE otherwise. + Returns TRUE if the given src's visual is already represented in + the image_regions list, FALSE otherwise. ------------------------------------------------------------------------ **/ -static int src_in_region_list( src, image_regions) - image_win_type *src; - list_ptr image_regions; +static int +src_in_region_list( + image_win_type *src, + list_ptr image_regions) { - image_region_type *ir; + image_region_type *ir; for (ir = (image_region_type *) first_in_list( image_regions); ir; - ir = (image_region_type *) next_in_list( image_regions)) { - if (SAME_REGIONS( ir, src)) { + ir = (image_region_type *) next_in_list( image_regions)) { + if (SAME_REGIONS( ir, src)) { - return 1; - } + return 1; + } } return 0; @@ -952,28 +949,28 @@ static int src_in_region_list( src, image_regions) /** ------------------------------------------------------------------------ - Makes a new entry in image_wins with the given fields filled in. + Makes a new entry in image_wins with the given fields filled in. ------------------------------------------------------------------------ **/ -static void add_window_to_list( image_wins, w, xrr, yrr, x_vis, y_vis, - width, height, border_width,vis, cmap, parent) - list_ptr image_wins; - Window w; - int xrr; - int yrr; - int x_vis; - int y_vis; - int width; - int height; - int border_width; - Visual *vis; - Colormap cmap; - Window parent; +static void +add_window_to_list( + list_ptr image_wins, + Window w, + int xrr, + int yrr, + int x_vis, + int y_vis, + int width, + int height, + int border_width, + Visual *vis, + Colormap cmap, + Window parent) { - image_win_type *new_src; + image_win_type *new_src; if ((new_src = (image_win_type *) malloc( sizeof( image_win_type))) == NULL) - return; + return; new_src->win = w; new_src->x_rootrel = xrr; @@ -990,52 +987,52 @@ static void add_window_to_list( image_wins, w, xrr, yrr, x_vis, y_vis, } /** ------------------------------------------------------------------------ - Returns TRUE if the given src's visual is in the image planes, - FALSE otherwise. + Returns TRUE if the given src's visual is in the image planes, + FALSE otherwise. ------------------------------------------------------------------------ **/ -static int src_in_image( src, numImageVisuals, pImageVisuals) - image_win_type *src; - int numImageVisuals; - XVisualInfo **pImageVisuals; +static int +src_in_image( + image_win_type *src, + int numImageVisuals, + XVisualInfo **pImageVisuals) { - int i; + int i; - for (i = 0 ; i < numImageVisuals ; i++) + for (i = 0; i < numImageVisuals; i++) { - if (pImageVisuals[i]->visual == src->vis) - return 1; + if (pImageVisuals[i]->visual == src->vis) + return 1; } return 0; } /** ------------------------------------------------------------------------ - Returns TRUE if the given src's visual is in the overlay planes - and transparency is possible, FALSE otherwise. + Returns TRUE if the given src's visual is in the overlay planes + and transparency is possible, FALSE otherwise. ------------------------------------------------------------------------ **/ -static int src_in_overlay( src, numOverlayVisuals, pOverlayVisuals, - transparentColor, transparentType) - image_region_type *src; - int numOverlayVisuals; - OverlayInfo *pOverlayVisuals; - int *transparentColor; - int *transparentType; +static int src_in_overlay( + image_region_type *src, + int numOverlayVisuals, + OverlayInfo *pOverlayVisuals, + int *transparentColor, + int *transparentType) { - int i; + int i; - for (i = 0 ; i < numOverlayVisuals ; i++) + for (i = 0; i < numOverlayVisuals; i++) + { + if (((pOverlayVisuals[i].pOverlayVisualInfo)->visual == src->vis) + && (pOverlayVisuals[i].transparentType != None)) { - if (((pOverlayVisuals[i].pOverlayVisualInfo)->visual == src->vis) - && (pOverlayVisuals[i].transparentType != None)) - { - *transparentColor = pOverlayVisuals[i].value; - *transparentType = pOverlayVisuals[i].transparentType; - return 1; - } - - else { - } - + *transparentColor = pOverlayVisuals[i].value; + *transparentType = pOverlayVisuals[i].transparentType; + return 1; + } + + else { + } + } return 0; } @@ -1055,14 +1052,14 @@ static int src_in_overlay( src, numOverlayVisuals, pOverlayVisuals, -#define STATIC_GRAY 0x01 -#define GRAY_SCALE 0x02 -#define PSEUDO_COLOR 0x04 -#define TRUE_COLOR 0x10 -#define DIRECT_COLOR 0x11 +#define STATIC_GRAY 0x01 +#define GRAY_SCALE 0x02 +#define PSEUDO_COLOR 0x04 +#define TRUE_COLOR 0x10 +#define DIRECT_COLOR 0x11 -static int weCreateServerOverlayVisualsProperty = False; +static int weCreateServerOverlayVisualsProperty = False; /****************************************************************************** @@ -1072,10 +1069,10 @@ static int weCreateServerOverlayVisualsProperty = False; * This routine takes an X11 Display, screen number, and returns whether the * screen supports transparent overlays and three arrays: * - * 1) All of the XVisualInfo struct's for the screen. - * 2) All of the OverlayInfo struct's for the screen. - * 3) An array of pointers to the screen's image plane XVisualInfo - * structs. + * 1) All of the XVisualInfo struct's for the screen. + * 2) All of the OverlayInfo struct's for the screen. + * 3) An array of pointers to the screen's image plane XVisualInfo + * structs. * * The code below obtains the array of all the screen's visuals, and obtains * the array of all the screen's overlay visual information. It then processes @@ -1087,42 +1084,39 @@ static int weCreateServerOverlayVisualsProperty = False; * ******************************************************************************/ -int GetXVisualInfo(display, screen, transparentOverlays, - numVisuals, pVisuals, - numOverlayVisuals, pOverlayVisuals, - numImageVisuals, pImageVisuals) - - Display *display; /* Which X server (aka "display"). */ - int screen; /* Which screen of the "display". */ - int *transparentOverlays; /* Non-zero if there's at least one - * overlay visual and if at least one - * of those supports a transparent - * pixel. */ - int *numVisuals; /* Number of XVisualInfo struct's - * pointed to to by pVisuals. */ - XVisualInfo **pVisuals; /* All of the device's visuals. */ - int *numOverlayVisuals; /* Number of OverlayInfo's pointed - * to by pOverlayVisuals. If this - * number is zero, the device does - * not have overlay planes. */ - OverlayInfo **pOverlayVisuals; /* The device's overlay plane visual - * information. */ - int *numImageVisuals; /* Number of XVisualInfo's pointed - * to by pImageVisuals. */ - XVisualInfo ***pImageVisuals; /* The device's image visuals. */ +int +GetXVisualInfo( + Display *display, /* Which X server (aka "display"). */ + int screen, /* Which screen of the "display". */ + int *transparentOverlays, /* Non-zero if there's at least one + * overlay visual and if at least one + * of those supports a transparent + * pixel. */ + int *numVisuals, /* Number of XVisualInfo struct's + * pointed to to by pVisuals. */ + XVisualInfo **pVisuals, /* All of the device's visuals. */ + int *numOverlayVisuals, /* Number of OverlayInfo's pointed + * to by pOverlayVisuals. If this + * number is zero, the device does + * not have overlay planes. */ + OverlayInfo **pOverlayVisuals, /* The device's overlay plane visual + * information. */ + int *numImageVisuals, /* Number of XVisualInfo's pointed + * to by pImageVisuals. */ + XVisualInfo ***pImageVisuals) /* The device's image visuals. */ { - XVisualInfo getVisInfo; /* Paramters of XGetVisualInfo */ - int mask; - XVisualInfo *pVis, **pIVis; /* Faster, local copies */ - OverlayInfo *pOVis; - OverlayVisualPropertyRec *pOOldVis; - int nVisuals, nOVisuals; - Atom overlayVisualsAtom; /* Parameters for XGetWindowProperty */ - Atom actualType; + XVisualInfo getVisInfo; /* Paramters of XGetVisualInfo */ + int mask; + XVisualInfo *pVis, **pIVis; /* Faster, local copies */ + OverlayInfo *pOVis; + OverlayVisualPropertyRec *pOOldVis; + int nVisuals, nOVisuals; + Atom overlayVisualsAtom; /* Parameters for XGetWindowProperty */ + Atom actualType; unsigned long numLongs, bytesAfter; - int actualFormat; - int nImageVisualsAlloced; /* Values to process the XVisualInfo */ - int imageVisual; /* array */ + int actualFormat; + int nImageVisualsAlloced; /* Values to process the XVisualInfo */ + int imageVisual; /* array */ /* First, get the list of visuals for this screen. */ @@ -1132,8 +1126,8 @@ int GetXVisualInfo(display, screen, transparentOverlays, *pVisuals = XGetVisualInfo(display, mask, &getVisInfo, numVisuals); if ((nVisuals = *numVisuals) <= 0) { - /* Return that the information wasn't sucessfully obtained: */ - return(1); + /* Return that the information wasn't sucessfully obtained: */ + return(1); } pVis = *pVisuals; @@ -1144,30 +1138,30 @@ int GetXVisualInfo(display, screen, transparentOverlays, overlayVisualsAtom = XInternAtom(display, "SERVER_OVERLAY_VISUALS", True); if (overlayVisualsAtom != None) { - /* Since the Atom exists, we can request the property's contents. The - * do-while loop makes sure we get the entire list from the X server. - */ - bytesAfter = 0; - numLongs = sizeof(OverlayVisualPropertyRec) / 4; - do - { - numLongs += bytesAfter * 4; - XGetWindowProperty(display, RootWindow(display, screen), - overlayVisualsAtom, 0, numLongs, False, - overlayVisualsAtom, &actualType, &actualFormat, - &numLongs, &bytesAfter, (unsigned char**) pOverlayVisuals); - } while (bytesAfter > 0); - - - /* Calculate the number of overlay visuals in the list. */ - *numOverlayVisuals = numLongs / (sizeof(OverlayVisualPropertyRec) / 4); + /* Since the Atom exists, we can request the property's contents. The + * do-while loop makes sure we get the entire list from the X server. + */ + bytesAfter = 0; + numLongs = sizeof(OverlayVisualPropertyRec) / 4; + do + { + numLongs += bytesAfter * 4; + XGetWindowProperty(display, RootWindow(display, screen), + overlayVisualsAtom, 0, numLongs, False, + overlayVisualsAtom, &actualType, &actualFormat, + &numLongs, &bytesAfter, (unsigned char**) pOverlayVisuals); + } while (bytesAfter > 0); + + + /* Calculate the number of overlay visuals in the list. */ + *numOverlayVisuals = numLongs / (sizeof(OverlayVisualPropertyRec) / 4); } else { - /* This screen doesn't have overlay planes. */ - *numOverlayVisuals = 0; - *pOverlayVisuals = NULL; - *transparentOverlays = 0; + /* This screen doesn't have overlay planes. */ + *numOverlayVisuals = 0; + *pOverlayVisuals = NULL; + *transparentOverlays = 0; } @@ -1177,33 +1171,33 @@ int GetXVisualInfo(display, screen, transparentOverlays, pIVis = *pImageVisuals = (XVisualInfo **) malloc(sizeof(XVisualInfo *)); while (--nVisuals >= 0) { - nOVisuals = *numOverlayVisuals; - pOVis = *pOverlayVisuals; - imageVisual = True; - while (--nOVisuals >= 0) - { - pOOldVis = (OverlayVisualPropertyRec *) pOVis; - if (pVis->visualid == pOOldVis->visualID) - { - imageVisual = False; - pOVis->pOverlayVisualInfo = pVis; - if (pOVis->transparentType == TransparentPixel) - *transparentOverlays = 1; - } - pOVis++; - } - if (imageVisual) - { - if ((*numImageVisuals += 1) > nImageVisualsAlloced) - { - nImageVisualsAlloced++; - *pImageVisuals = (XVisualInfo **) - realloc(*pImageVisuals, (nImageVisualsAlloced * sizeof(XVisualInfo *))); - pIVis = *pImageVisuals + (*numImageVisuals - 1); - } - *pIVis++ = pVis; - } - pVis++; + nOVisuals = *numOverlayVisuals; + pOVis = *pOverlayVisuals; + imageVisual = True; + while (--nOVisuals >= 0) + { + pOOldVis = (OverlayVisualPropertyRec *) pOVis; + if (pVis->visualid == pOOldVis->visualID) + { + imageVisual = False; + pOVis->pOverlayVisualInfo = pVis; + if (pOVis->transparentType == TransparentPixel) + *transparentOverlays = 1; + } + pOVis++; + } + if (imageVisual) + { + if ((*numImageVisuals += 1) > nImageVisualsAlloced) + { + nImageVisualsAlloced++; + *pImageVisuals = (XVisualInfo **) + realloc(*pImageVisuals, (nImageVisualsAlloced * sizeof(XVisualInfo *))); + pIVis = *pImageVisuals + (*numImageVisuals - 1); + } + *pIVis++ = pVis; + } + pVis++; } @@ -1221,17 +1215,17 @@ int GetXVisualInfo(display, screen, transparentOverlays, * ******************************************************************************/ -void FreeXVisualInfo(pVisuals, pOverlayVisuals, pImageVisuals) - - XVisualInfo *pVisuals; - OverlayInfo *pOverlayVisuals; - XVisualInfo **pImageVisuals; +void +FreeXVisualInfo( + XVisualInfo *pVisuals, + OverlayInfo *pOverlayVisuals, + XVisualInfo **pImageVisuals) { XFree(pVisuals); if (weCreateServerOverlayVisualsProperty) - free(pOverlayVisuals); + free(pOverlayVisuals); else - XFree(pOverlayVisuals); + XFree(pOverlayVisuals); free(pImageVisuals); } /* FreeXVisualInfo() */ diff --git a/xwd.c b/xwd.c index 944faab..ab1764a 100644 --- a/xwd.c +++ b/xwd.c @@ -91,47 +91,44 @@ typedef unsigned long Pixel; /* Setable Options */ -int format = ZPixmap; -Bool nobdrs = False; -Bool on_root = False; -Bool standard_out = True; -Bool debug = False; -Bool silent = False; -Bool use_installed = False; -long add_pixel_value = 0; - - -extern int main(int, char **); -extern void Window_Dump(Window, FILE *); -extern int Image_Size(XImage *); -extern int Get_XColors(XWindowAttributes *, XColor **); -extern void _swapshort(register char *, register unsigned); -extern void _swaplong(register char *, register unsigned); +static int format = ZPixmap; +static Bool nobdrs = False; +static Bool on_root = False; +static Bool standard_out = True; +static Bool debug = False; +static Bool silent = False; +static Bool use_installed = False; +static long add_pixel_value = 0; + + +static void Window_Dump(Window, FILE *); +static int Image_Size(XImage *); +static int Get_XColors(XWindowAttributes *, XColor **); +static void _swapshort(register char *, register unsigned); +static void _swaplong(register char *, register unsigned); static long parse_long(char *); static int Get24bitDirectColors(XColor **); static int ReadColors(Visual *, Colormap, XColor **); -static long parse_long (s) - char *s; +static long +parse_long(char *s) { char *fmt = "%lu"; long retval = 0L; int thesign = 1; if (s && s[0]) { - if (s[0] == '-') s++, thesign = -1; - if (s[0] == '0') s++, fmt = "%lo"; - if (s[0] == 'x' || s[0] == 'X') s++, fmt = "%lx"; - (void) sscanf (s, fmt, &retval); + if (s[0] == '-') s++, thesign = -1; + if (s[0] == '0') s++, fmt = "%lo"; + if (s[0] == 'x' || s[0] == 'X') s++, fmt = "%lx"; + (void) sscanf (s, fmt, &retval); } return (thesign * retval); } int -main(argc, argv) - int argc; - char **argv; +main(int argc, char **argv) { register int i; Window target_win; @@ -146,60 +143,60 @@ main(argc, argv) target_win = Select_Window_Args(&argc, argv); for (i = 1; i < argc; i++) { - if (!strcmp(argv[i], "-nobdrs")) { - nobdrs = True; - continue; - } - if (!strcmp(argv[i], "-debug")) { - debug = True; - continue; - } - if (!strcmp(argv[i], "-help")) - usage(); - if (!strcmp(argv[i], "-out")) { - if (++i >= argc) usage(); - if (!(out_file = fopen(argv[i], "wb"))) - Fatal_Error("Can't open output file as specified."); - standard_out = False; - continue; - } - if (!strcmp(argv[i], "-xy")) { - format = XYPixmap; - continue; - } - if (!strcmp(argv[i], "-screen")) { - on_root = True; - continue; - } - if (!strcmp(argv[i], "-icmap")) { - use_installed = True; - continue; - } - if (!strcmp(argv[i], "-add")) { - if (++i >= argc) usage(); - add_pixel_value = parse_long (argv[i]); - continue; - } - if (!strcmp(argv[i], "-frame")) { - frame_only = True; - continue; - } - if (!strcmp(argv[i], "-silent")) { - silent = True; - continue; - } - usage(); + if (!strcmp(argv[i], "-nobdrs")) { + nobdrs = True; + continue; + } + if (!strcmp(argv[i], "-debug")) { + debug = True; + continue; + } + if (!strcmp(argv[i], "-help")) + usage(); + if (!strcmp(argv[i], "-out")) { + if (++i >= argc) usage(); + if (!(out_file = fopen(argv[i], "wb"))) + Fatal_Error("Can't open output file as specified."); + standard_out = False; + continue; + } + if (!strcmp(argv[i], "-xy")) { + format = XYPixmap; + continue; + } + if (!strcmp(argv[i], "-screen")) { + on_root = True; + continue; + } + if (!strcmp(argv[i], "-icmap")) { + use_installed = True; + continue; + } + if (!strcmp(argv[i], "-add")) { + if (++i >= argc) usage(); + add_pixel_value = parse_long (argv[i]); + continue; + } + if (!strcmp(argv[i], "-frame")) { + frame_only = True; + continue; + } + if (!strcmp(argv[i], "-silent")) { + silent = True; + continue; + } + usage(); } #ifdef WIN32 if (standard_out) - _setmode(fileno(out_file), _O_BINARY); + _setmode(fileno(out_file), _O_BINARY); #endif /* * Let the user select the target window. */ if (target_win == None) - target_win = Select_Window(dpy, !frame_only); + target_win = Select_Window(dpy, !frame_only); /* * Dump it! @@ -208,28 +205,27 @@ main(argc, argv) XCloseDisplay(dpy); if (fclose(out_file)) { - perror("xwd"); - exit(1); + perror("xwd"); + exit(1); } exit(0); } static int -Get24bitDirectColors(colors) -XColor **colors ; +Get24bitDirectColors(XColor **colors) { - int i , ncolors = 256 ; - XColor *tcol ; + int i , ncolors = 256; + XColor *tcol; - *colors = tcol = (XColor *)malloc(sizeof(XColor) * ncolors) ; + *colors = tcol = (XColor *)malloc(sizeof(XColor) * ncolors); - for(i=0 ; i < ncolors ; i++) + for (i=0; i < ncolors; i++) { - tcol[i].pixel = i << 16 | i << 8 | i ; - tcol[i].red = tcol[i].green = tcol[i].blue = i << 8 | i ; + tcol[i].pixel = i << 16 | i << 8 | i; + tcol[i].red = tcol[i].green = tcol[i].blue = i << 8 | i; } - return ncolors ; + return ncolors; } @@ -238,10 +234,8 @@ XColor **colors ; * writting. */ -void -Window_Dump(window, out) - Window window; - FILE *out; +static void +Window_Dump(Window window, FILE *out) { unsigned long swaptest = 1; XColor *colors; @@ -269,20 +263,20 @@ Window_Dump(window, out) int numImageVisuals; XVisualInfo **pImageVisuals; list_ptr vis_regions; /* list of regions to read from */ - list_ptr vis_image_regions ; - Visual vis_h,*vis ; - int allImage = 0 ; + list_ptr vis_image_regions; + Visual vis_h,*vis; + int allImage = 0; /* * Inform the user not to alter the screen. */ if (!silent) { #ifdef XKB - XkbStdBell(dpy,None,50,XkbBI_Wait); + XkbStdBell(dpy,None,50,XkbBI_Wait); #else - XBell(dpy,FEEP_VOLUME); + XBell(dpy,FEEP_VOLUME); #endif - XFlush(dpy); + XFlush(dpy); } /* @@ -295,10 +289,10 @@ Window_Dump(window, out) /* handle any frame window */ if (!XTranslateCoordinates (dpy, window, RootWindow (dpy, screen), 0, 0, &absx, &absy, &dummywin)) { - fprintf (stderr, - "%s: unable to translate window coordinates (%d,%d)\n", - program_name, absx, absy); - exit (1); + fprintf (stderr, + "%s: unable to translate window coordinates (%d,%d)\n", + program_name, absx, absy); + exit (1); } win_info.x = absx; win_info.y = absy; @@ -307,11 +301,11 @@ Window_Dump(window, out) bw = 0; if (!nobdrs) { - absx -= win_info.border_width; - absy -= win_info.border_width; - bw = win_info.border_width; - width += (2 * bw); - height += (2 * bw); + absx -= win_info.border_width; + absy -= win_info.border_width; + bw = win_info.border_width; + width += (2 * bw); + height += (2 * bw); } dwidth = DisplayWidth (dpy, screen); dheight = DisplayHeight (dpy, screen); @@ -325,10 +319,10 @@ Window_Dump(window, out) XFetchName(dpy, window, &win_name); if (!win_name || !win_name[0]) { - win_name = "xwdump"; - got_win_name = False; + win_name = "xwdump"; + got_win_name = False; } else { - got_win_name = True; + got_win_name = True; } /* sizeof(char) is included for the null string terminator. */ @@ -343,61 +337,59 @@ Window_Dump(window, out) multiVis = GetMultiVisualRegions(dpy,RootWindow(dpy, screen), absx, absy, - width, height,&transparentOverlays,&numVisuals, &pVisuals, + width, height,&transparentOverlays,&numVisuals, &pVisuals, &numOverlayVisuals,&pOverlayVisuals,&numImageVisuals, - &pImageVisuals,&vis_regions,&vis_image_regions,&allImage) ; - if (on_root || multiVis) - { - if(!multiVis) - image = XGetImage (dpy, RootWindow(dpy, screen), absx, absy, + &pImageVisuals,&vis_regions,&vis_image_regions,&allImage); + if (on_root || multiVis) { + if(!multiVis) + image = XGetImage (dpy, RootWindow(dpy, screen), absx, absy, width, height, AllPlanes, format); - else - image = ReadAreaToImage(dpy, RootWindow(dpy, screen), absx, absy, - width, height, - numVisuals,pVisuals,numOverlayVisuals,pOverlayVisuals, - numImageVisuals, pImageVisuals,vis_regions, - vis_image_regions,format,allImage); - } - else - image = XGetImage (dpy, window, x, y, width, height, AllPlanes, format); + else + image = ReadAreaToImage(dpy, RootWindow(dpy, screen), absx, absy, + width, height, + numVisuals,pVisuals,numOverlayVisuals,pOverlayVisuals, + numImageVisuals, pImageVisuals,vis_regions, + vis_image_regions,format,allImage); + } else + image = XGetImage (dpy, window, x, y, width, height, AllPlanes, + format); if (!image) { - fprintf (stderr, "%s: unable to get image at %dx%d+%d+%d\n", - program_name, width, height, x, y); - exit (1); + fprintf (stderr, "%s: unable to get image at %dx%d+%d+%d\n", + program_name, width, height, x, y); + exit (1); } - if (add_pixel_value != 0) XAddPixel (image, add_pixel_value); + if (add_pixel_value != 0) + XAddPixel(image, add_pixel_value); /* * Determine the pixmap size. */ buffer_size = Image_Size(image); - if (debug) outl("xwd: Getting Colors.\n"); + if (debug) + outl("xwd: Getting Colors.\n"); - if( !multiVis) - { + if (!multiVis) { ncolors = Get_XColors(&win_info, &colors); - vis = win_info.visual ; - } - else - { - ncolors = Get24bitDirectColors(&colors) ; - initFakeVisual(&vis_h) ; - vis = &vis_h ; + vis = win_info.visual; + } else { + ncolors = Get24bitDirectColors(&colors); + initFakeVisual(&vis_h); + vis = &vis_h; } /* * Inform the user that the image has been retrieved. */ if (!silent) { #ifdef XKB - XkbStdBell(dpy,window,FEEP_VOLUME,XkbBI_Proceed); - XkbStdBell(dpy,window,FEEP_VOLUME,XkbBI_RepeatingLastBell); + XkbStdBell(dpy,window,FEEP_VOLUME,XkbBI_Proceed); + XkbStdBell(dpy,window,FEEP_VOLUME,XkbBI_RepeatingLastBell); #else - XBell(dpy, FEEP_VOLUME); - XBell(dpy, FEEP_VOLUME); + XBell(dpy, FEEP_VOLUME); + XBell(dpy, FEEP_VOLUME); #endif - XFlush(dpy); + XFlush(dpy); } /* @@ -446,17 +438,17 @@ Window_Dump(window, out) header.window_bdrwidth = (CARD32) win_info.border_width; if (*(char *) &swaptest) { - _swaplong((char *) &header, sizeof(header)); - for (i = 0; i < ncolors; i++) { - _swaplong((char *) &colors[i].pixel, sizeof(CARD32)); - _swapshort((char *) &colors[i].red, 3 * sizeof(short)); - } + _swaplong((char *) &header, sizeof(header)); + for (i = 0; i < ncolors; i++) { + _swaplong((char *) &colors[i].pixel, sizeof(CARD32)); + _swapshort((char *) &colors[i].red, 3 * sizeof(short)); + } } if (fwrite((char *)&header, SIZEOF(XWDheader), 1, out) != 1 || - fwrite(win_name, win_name_size, 1, out) != 1) { - perror("xwd"); - exit(1); + fwrite(win_name, win_name_size, 1, out) != 1) { + perror("xwd"); + exit(1); } /* @@ -465,15 +457,15 @@ Window_Dump(window, out) if (debug) outl("xwd: Dumping %d colors.\n", ncolors); for (i = 0; i < ncolors; i++) { - xwdcolor.pixel = colors[i].pixel; - xwdcolor.red = colors[i].red; - xwdcolor.green = colors[i].green; - xwdcolor.blue = colors[i].blue; - xwdcolor.flags = colors[i].flags; - if (fwrite((char *) &xwdcolor, SIZEOF(XWDColor), 1, out) != 1) { - perror("xwd"); - exit(1); - } + xwdcolor.pixel = colors[i].pixel; + xwdcolor.red = colors[i].red; + xwdcolor.green = colors[i].green; + xwdcolor.blue = colors[i].blue; + xwdcolor.flags = colors[i].flags; + if (fwrite((char *) &xwdcolor, SIZEOF(XWDColor), 1, out) != 1) { + perror("xwd"); + exit(1); + } } /* @@ -488,8 +480,8 @@ Window_Dump(window, out) * non-existant X function. */ if (fwrite(image->data, (int) buffer_size, 1, out) != 1) { - perror("xwd"); - exit(1); + perror("xwd"); + exit(1); } /* @@ -515,7 +507,7 @@ Window_Dump(window, out) * Report the syntax for calling xwd. */ void -usage() +usage(void) { fprintf (stderr, "usage: %s [-display host:dpy] [-debug] [-help] %s [-nobdrs] [-out ]", @@ -529,8 +521,8 @@ usage() * Determine the pixmap size. */ -int Image_Size(image) - XImage *image; +static int +Image_Size(XImage *image) { if (image->format != ZPixmap) return(image->bytes_per_line * image->height * image->depth); @@ -541,44 +533,41 @@ int Image_Size(image) #define lowbit(x) ((x) & (~(x) + 1)) static int -ReadColors(vis,cmap,colors) -Visual *vis ; -Colormap cmap ; -XColor **colors ; +ReadColors(Visual *vis, Colormap cmap, XColor **colors) { - int i,ncolors ; + int i,ncolors; ncolors = vis->map_entries; if (!(*colors = (XColor *) malloc (sizeof(XColor) * ncolors))) - Fatal_Error("Out of memory!"); + Fatal_Error("Out of memory!"); if (vis->class == DirectColor || vis->class == TrueColor) { - Pixel red, green, blue, red1, green1, blue1; - - red = green = blue = 0; - red1 = lowbit(vis->red_mask); - green1 = lowbit(vis->green_mask); - blue1 = lowbit(vis->blue_mask); - for (i=0; i vis->red_mask) - red = 0; - green += green1; - if (green > vis->green_mask) - green = 0; - blue += blue1; - if (blue > vis->blue_mask) - blue = 0; - } + Pixel red, green, blue, red1, green1, blue1; + + red = green = blue = 0; + red1 = lowbit(vis->red_mask); + green1 = lowbit(vis->green_mask); + blue1 = lowbit(vis->blue_mask); + for (i=0; i vis->red_mask) + red = 0; + green += green1; + if (green > vis->green_mask) + green = 0; + blue += blue1; + if (blue > vis->blue_mask) + blue = 0; + } } else { - for (i=0; icolormap; if (use_installed) - /* assume the visual will be OK ... */ - cmap = XListInstalledColormaps(dpy, win_info->root, &i)[0]; + /* assume the visual will be OK ... */ + cmap = XListInstalledColormaps(dpy, win_info->root, &i)[0]; if (!cmap) - return(0); - ncolors = ReadColors(win_info->visual,cmap,colors) ; - return ncolors ; + return(0); + ncolors = ReadColors(win_info->visual,cmap,colors); + return ncolors; } -void -_swapshort (bp, n) - register char *bp; - register unsigned n; +static void +_swapshort(register char *bp, register unsigned n) { register char c; register char *ep = bp + n; while (bp < ep) { - c = *bp; - *bp = *(bp + 1); - bp++; - *bp++ = c; + c = *bp; + *bp = *(bp + 1); + bp++; + *bp++ = c; } } -void -_swaplong (bp, n) - register char *bp; - register unsigned n; +static void +_swaplong(register char *bp, register unsigned n) { register char c; register char *ep = bp + n;