cristy@eplrx7.uucp (John Cristy) (10/09/90)
XtoPS is an X Window System window dumping utility. XtoPS reads an image from any visible window on an X server and outputs it to encapsulated Postscript file. You can view this file with any Postscript compatible viewer or printer. The image is displayed in color on viewers or printers that support color Postscript, otherwise it is displayed as grayscale. The target window can be specified by id or name or be selected by clicking the mouse in the desired window. The keyboard bell is rung once at the beginning of the dump and twice when the dump is completed. cristy@dupont.com --- #!/bin/sh # This is a shell archive (produced by shar 3.49) # To extract the files from this archive, save it to a file, remove # everything above the "!/bin/sh" line above, and type "sh file_name". # # made 10/09/1990 16:06 UTC by cristy@sunburst # Source directory /home/cristy/XtoPS # # existing files will NOT be overwritten unless -c is specified # # This shar contains: # length mode name # ------ ---------- ------------------------------------------ # 183 -rwx------ Imakefile # 8954 -rw------- Makefile # 2903 -rwx------ PreR4Icccm.h # 2378 -rwx------ README # 48482 -rwx------ XtoPS.c # 3351 -rwx------ XtoPS.man # 1669 -rwx------ display.h # # ============= Imakefile ============== if test -f 'Imakefile' -a X"$1" != X"-c"; then echo 'x - skipping Imakefile (File already exists)' else echo 'x - extracting Imakefile (Text)' sed 's/^X//' << 'SHAR_EOF' > 'Imakefile' && #DEFINES= -DPRE_R4_ICCCM PROGRAMS= XtoPS SYS_LIBRARIES= $(XLIB) -lm SRCS= XtoPS.c OBJS= XtoPS.o X AllTarget($(PROGRAMS)) X ComplexProgramTarget(XtoPS) InstallManPage(XtoPS,$(MANDIR)) SHAR_EOF chmod 0700 Imakefile || echo 'restore of Imakefile failed' Wc_c="`wc -c < 'Imakefile'`" test 183 -eq "$Wc_c" || echo 'Imakefile: original size 183, current size' "$Wc_c" fi # ============= Makefile ============== if test -f 'Makefile' -a X"$1" != X"-c"; then echo 'x - skipping Makefile (File already exists)' else echo 'x - extracting Makefile (Text)' sed 's/^X//' << 'SHAR_EOF' > 'Makefile' && # Makefile generated by imake - do not edit! # $XConsortium: imake.c,v 1.51 89/12/12 12:37:30 jim Exp $ # # The cpp used on this machine replaces all newlines and multiple tabs and # spaces in a macro expansion with a single space. Imake tries to compensate # for this, but is not always successful. # X ########################################################################### # Makefile generated from "Imake.tmpl" and </tmp/IIf.a01232> # $XConsortium: Imake.tmpl,v 1.77 89/12/18 17:01:37 jim Exp $ # # Platform-specific parameters may be set in the appropriate .cf # configuration files. Site-wide parameters may be set in the file # site.def. Full rebuilds are recommended if any parameters are changed. # # If your C preprocessor doesn't define any unique symbols, you'll need # to set BOOTSTRAPCFLAGS when rebuilding imake (usually when doing # "make Makefile", "make Makefiles", or "make World"). # # If you absolutely can't get imake to work, you'll need to set the # variables at the top of each Makefile as well as the dependencies at the # bottom (makedepend will do this automatically). # X ########################################################################### # platform-specific configuration parameters - edit sun.cf to change X # platform: $XConsortium: sun.cf,v 1.38 89/12/23 16:10:10 jim Exp $ # operating system: SunOS 4.0.3 X ########################################################################### # site-specific configuration parameters - edit site.def to change X # site: $XConsortium: site.def,v 1.21 89/12/06 11:46:50 jim Exp $ X X SHELL = /bin/sh X X TOP = . X CURRENT_DIR = . X X AR = ar cq X BOOTSTRAPCFLAGS = X CC = cc X X COMPRESS = compress X CPP = /lib/cpp $(STD_CPP_DEFINES) X PREPROCESSCMD = cc -E $(STD_CPP_DEFINES) X INSTALL = install X LD = ld X LINT = lint X LINTLIBFLAG = -C X LINTOPTS = -axz X LN = ln -s X MAKE = make X MV = mv X CP = cp X RANLIB = ranlib X RANLIBINSTFLAGS = X RM = rm -f X STD_INCLUDES = X STD_CPP_DEFINES = X STD_DEFINES = X EXTRA_LOAD_FLAGS = X EXTRA_LIBRARIES = X TAGS = ctags X X SHAREDCODEDEF = -DSHAREDCODE X SHLIBDEF = -DSUNSHLIB X X PROTO_DEFINES = X X INSTPGMFLAGS = X X INSTBINFLAGS = -m 0755 X INSTUIDFLAGS = -m 4755 X INSTLIBFLAGS = -m 0664 X INSTINCFLAGS = -m 0444 X INSTMANFLAGS = -m 0444 X INSTDATFLAGS = -m 0444 X INSTKMEMFLAGS = -m 4755 X X DESTDIR = X X TOP_INCLUDES = -I$(INCROOT) X X CDEBUGFLAGS = -O X CCOPTIONS = X COMPATFLAGS = X X ALLINCLUDES = $(STD_INCLUDES) $(TOP_INCLUDES) $(INCLUDES) $(EXTRA_INCLUDES) X ALLDEFINES = $(ALLINCLUDES) $(STD_DEFINES) $(PROTO_DEFINES) $(DEFINES) $(COMPATFLAGS) X CFLAGS = $(CDEBUGFLAGS) $(CCOPTIONS) $(ALLDEFINES) X LINTFLAGS = $(LINTOPTS) -DLINT $(ALLDEFINES) X LDLIBS = $(SYS_LIBRARIES) $(EXTRA_LIBRARIES) X LDOPTIONS = $(CDEBUGFLAGS) $(CCOPTIONS) X LDCOMBINEFLAGS = -X -r X X MACROFILE = sun.cf X RM_CMD = $(RM) *.CKP *.ln *.BAK *.bak *.o core errs ,* *~ *.a .emacs_* tags TAGS make.log MakeOut X X IMAKE_DEFINES = X X IRULESRC = $(CONFIGDIR) X IMAKE_CMD = $(IMAKE) -DUseInstalled -I$(IRULESRC) $(IMAKE_DEFINES) X X ICONFIGFILES = $(IRULESRC)/Imake.tmpl $(IRULESRC)/Imake.rules \ X $(IRULESRC)/Project.tmpl $(IRULESRC)/site.def \ X $(IRULESRC)/$(MACROFILE) $(EXTRA_ICONFIGFILES) X ########################################################################### # X Window System Build Parameters # $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $ X ########################################################################### # X Window System make variables; this need to be coordinated with rules # $XConsortium: Project.tmpl,v 1.63 89/12/18 16:46:44 jim Exp $ X X PATHSEP = / X USRLIBDIR = $(DESTDIR)/usr/lib X BINDIR = $(DESTDIR)/usr/bin/X11 X INCROOT = $(DESTDIR)/usr/include X BUILDINCROOT = $(TOP) X BUILDINCDIR = $(BUILDINCROOT)/X11 X BUILDINCTOP = .. X INCDIR = $(INCROOT)/X11 X ADMDIR = $(DESTDIR)/usr/adm X LIBDIR = $(USRLIBDIR)/X11 X CONFIGDIR = $(LIBDIR)/config X LINTLIBDIR = $(USRLIBDIR)/lint X X FONTDIR = $(LIBDIR)/fonts X XINITDIR = $(LIBDIR)/xinit X XDMDIR = $(LIBDIR)/xdm X AWMDIR = $(LIBDIR)/awm X TWMDIR = $(LIBDIR)/twm X GWMDIR = $(LIBDIR)/gwm X MANPATH = $(DESTDIR)/usr/man X MANSOURCEPATH = $(MANPATH)/man X MANDIR = $(MANSOURCEPATH)n X LIBMANDIR = $(MANSOURCEPATH)3 X XAPPLOADDIR = $(LIBDIR)/app-defaults X X SOXLIBREV = 4.2 X SOXTREV = 4.0 X SOXAWREV = 4.0 X SOOLDXREV = 4.0 X SOXMUREV = 4.0 X SOXEXTREV = 4.0 X X FONTCFLAGS = -t X X INSTAPPFLAGS = $(INSTDATFLAGS) X X IMAKE = imake X DEPEND = makedepend X RGB = rgb X FONTC = bdftosnf X MKFONTDIR = mkfontdir X MKDIRHIER = /bin/sh $(BINDIR)/mkdirhier.sh X X CONFIGSRC = $(TOP)/config X CLIENTSRC = $(TOP)/clients X DEMOSRC = $(TOP)/demos X LIBSRC = $(TOP)/lib X FONTSRC = $(TOP)/fonts X INCLUDESRC = $(TOP)/X11 X SERVERSRC = $(TOP)/server X UTILSRC = $(TOP)/util X SCRIPTSRC = $(UTILSRC)/scripts X EXAMPLESRC = $(TOP)/examples X CONTRIBSRC = $(TOP)/../contrib X DOCSRC = $(TOP)/doc X RGBSRC = $(TOP)/rgb X DEPENDSRC = $(UTILSRC)/makedepend X IMAKESRC = $(CONFIGSRC) X XAUTHSRC = $(LIBSRC)/Xau X XLIBSRC = $(LIBSRC)/X X XMUSRC = $(LIBSRC)/Xmu X TOOLKITSRC = $(LIBSRC)/Xt X AWIDGETSRC = $(LIBSRC)/Xaw X OLDXLIBSRC = $(LIBSRC)/oldX X XDMCPLIBSRC = $(LIBSRC)/Xdmcp X BDFTOSNFSRC = $(FONTSRC)/bdftosnf X MKFONTDIRSRC = $(FONTSRC)/mkfontdir X EXTENSIONSRC = $(TOP)/extensions X X DEPEXTENSIONLIB = $(USRLIBDIR)/libXext.a X EXTENSIONLIB = -lXext X X DEPXLIB = $(DEPEXTENSIONLIB) X XLIB = $(EXTENSIONLIB) -lX11 X X DEPXAUTHLIB = $(USRLIBDIR)/libXau.a X XAUTHLIB = -lXau X X DEPXMULIB = X XMULIB = -lXmu X X DEPOLDXLIB = X OLDXLIB = -loldX X X DEPXTOOLLIB = X XTOOLLIB = -lXt X X DEPXAWLIB = X XAWLIB = -lXaw X X LINTEXTENSIONLIB = $(USRLIBDIR)/llib-lXext.ln X LINTXLIB = $(USRLIBDIR)/llib-lX11.ln X LINTXMU = $(USRLIBDIR)/llib-lXmu.ln X LINTXTOOL = $(USRLIBDIR)/llib-lXt.ln X LINTXAW = $(USRLIBDIR)/llib-lXaw.ln X X DEPLIBS = $(DEPXAWLIB) $(DEPXMULIB) $(DEPXTOOLLIB) $(DEPXLIB) X X DEPLIBS1 = $(DEPLIBS) X DEPLIBS2 = $(DEPLIBS) X DEPLIBS3 = $(DEPLIBS) X ########################################################################### # Imake rules for building libraries, programs, scripts, and data files # rules: $XConsortium: Imake.rules,v 1.67 89/12/18 17:14:15 jim Exp $ X ########################################################################### # start of Imakefile X #DEFINES= -DPRE_R4_ICCCM PROGRAMS= XtoPS SYS_LIBRARIES= $(XLIB) -lm SRCS= XtoPS.c OBJS= XtoPS.o X all:: $(PROGRAMS) X X PROGRAM = XtoPS X all:: XtoPS X XXtoPS: $(OBJS) $(DEPLIBS) X $(RM) $@ X $(CC) -o $@ $(OBJS) $(LDOPTIONS) $(LOCAL_LIBRARIES) $(LDLIBS) $(EXTRA_LOAD_FLAGS) X saber_XtoPS: X #load $(ALLDEFINES) $(SRCS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES) X osaber_XtoPS: X #load $(ALLDEFINES) $(OBJS) $(LOCAL_LIBRARIES) $(SYS_LIBRARIES) $(EXTRA_LIBRARIES) X install:: XtoPS X $(INSTALL) -c $(INSTPGMFLAGS) XtoPS $(BINDIR) X install.man:: XtoPS.man X $(INSTALL) -c $(INSTMANFLAGS) XtoPS.man $(MANDIR)/XtoPS.n X depend:: X $(DEPEND) -s "# DO NOT DELETE" -- $(ALLDEFINES) -- $(SRCS) X lint: X $(LINT) $(LINTFLAGS) $(SRCS) $(LINTLIBS) lint1: X $(LINT) $(LINTFLAGS) $(FILE) $(LINTLIBS) X clean:: X $(RM) $(PROGRAM) X install.man:: XtoPS.man X $(INSTALL) -c $(INSTMANFLAGS) XtoPS.man $(MANDIR)/XtoPS.n X ########################################################################### # common rules for all Makefiles - do not edit X emptyrule:: X clean:: X $(RM_CMD) \#* X Makefile:: X -@if [ -f Makefile ]; then \ X echo " $(RM) Makefile.bak; $(MV) Makefile Makefile.bak"; \ X $(RM) Makefile.bak; $(MV) Makefile Makefile.bak; \ X else exit 0; fi X $(IMAKE_CMD) -DTOPDIR=$(TOP) -DCURDIR=$(CURRENT_DIR) X tags:: X $(TAGS) -w *.[ch] X $(TAGS) -xw *.[ch] > TAGS X saber: X #load $(ALLDEFINES) $(SRCS) X osaber: X #load $(ALLDEFINES) $(OBJS) X ########################################################################### # empty rules for directories that do not have SUBDIRS - do not edit X install:: X @echo "install in $(CURRENT_DIR) done" X install.man:: X @echo "install.man in $(CURRENT_DIR) done" X Makefiles:: X includes:: X ########################################################################### # dependencies generated by makedepend X SHAR_EOF chmod 0600 Makefile || echo 'restore of Makefile failed' Wc_c="`wc -c < 'Makefile'`" test 8954 -eq "$Wc_c" || echo 'Makefile: original size 8954, current size' "$Wc_c" fi # ============= PreR4Icccm.h ============== if test -f 'PreR4Icccm.h' -a X"$1" != X"-c"; then echo 'x - skipping PreR4Icccm.h (File already exists)' else echo 'x - extracting PreR4Icccm.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'PreR4Icccm.h' && /* X These routines are compatibility routines for pre-X11R4 ICCCM. */ X typedef struct _XTextProperty { X unsigned char X *value; X X Atom X encoding; X X int X format; X X unsigned long X nitems; } XTextProperty; X XXClassHint *XAllocClassHint() { X return((XClassHint *) malloc(sizeof(XClassHint))); } X XXIconSize *XAllocIconSize() { X return((XIconSize *) malloc(sizeof(XIconSize))); } X XXSizeHints *XAllocSizeHints() { X return((XSizeHints *) malloc(sizeof(XSizeHints))); } X XXStandardColormap *XAllocStandardColormap() { X return((XStandardColormap *) malloc(sizeof(XStandardColormap))); } X XXWMHints *XAllocWMHints() { X return((XWMHints *) malloc(sizeof(XWMHints))); } X Status XGetRGBColormaps(display,window,colormap,count,property) Display X *display; X Window X window; X XXStandardColormap X **colormap; X int X *count; X Atom X property; { X *count=1; X return(XGetStandardColormap(display,window,colormap,property)); } X Status XGetWMName(display,window,text_property) Display X *display; X Window X window; X XXTextProperty X *text_property; { X char X *window_name; X X if (XFetchName(display,window,&window_name) == 0) X return(False); X text_property->value=(unsigned char *) window_name; X text_property->encoding=XA_STRING; X text_property->format=8; X text_property->nitems=strlen(window_name); X return(True); } X void XSetWMProperties(display,window,window_name,icon_name,argv,argc, X size_hints,manager_hints,class_hint) Display X *display; X Window X window; X XXTextProperty X *window_name, X *icon_name; X char X **argv; X int X argc; X XXSizeHints X *size_hints; X XXWMHints *manager_hints; X XXClassHint X *class_hint; { X XSetStandardProperties(display,window,window_name->value,icon_name,None, X argv,argc,size_hints); X XSetWMHints(display,window,manager_hints); X XSetClassHint(display,window,class_hint); } X Status XSetWMProtocols(display,window,protocols,count) Display X *display; X Window X window; X Atom X *protocols; X int X count; { X Atom X protocols_property; X X protocols_property=XInternAtom(display,"WM_PROTOCOLS",False); X XChangeProperty(display,window,protocols_property,XA_ATOM,32,PropModeReplace, X (unsigned char *) protocols, count); X return(True); } X VisualID XVisualIDFromVisual(visual) Visual X *visual; { X return(visual->visualid); } X Status XWithdrawWindow(display,window,screen) Display X *display; X Window X window; X int X screen; { X return(XUnmapWindow(display,window)); } X int XWMGeometry(display,screen,user_geometry,default_geometry,border_width, X size_hints,x,y,width,height,gravity) Display X *display; X int X screen; X char X *user_geometry, X *default_geometry; X unsigned int X border_width; X XXSizeHints X *size_hints; X int X *x, X *y, X *width, X *height, X *gravity; { X int X status; X X status=XGeometry(display,screen,user_geometry,default_geometry,border_width, X 0,0,0,0,x,y,width,height); X *gravity=NorthWestGravity; X return(status); } SHAR_EOF chmod 0700 PreR4Icccm.h || echo 'restore of PreR4Icccm.h failed' Wc_c="`wc -c < 'PreR4Icccm.h'`" test 2903 -eq "$Wc_c" || echo 'PreR4Icccm.h: original size 2903, current size' "$Wc_c" fi # ============= README ============== if test -f 'README' -a X"$1" != X"-c"; then echo 'x - skipping README (File already exists)' else echo 'x - extracting README (Text)' sed 's/^X//' << 'SHAR_EOF' > 'README' && X XtoPS is an X Window System window dumping utility. XtoPS reads an X image from any visible window on an X server and outputs it to X encapsulated Postscript file. You can view this file with any X Postscript compatible viewer or printer. The image is displayed in X color on viewers or printers that support color Postscript, X otherwise it is displayed as grayscale. The target window can be X specified by id or name or be selected by clicking the mouse in the X desired window. The keyboard bell is rung once at the beginning of X the dump and twice when the dump is completed. X X If you have an X11R3 library, change X X #DEFINES= -DPRE_R4_ICCCM X X to X X DEFINES= -DPRE_R4_ICCCM X X in Imakefile X X Next, type X X xmkmf X make X cristy@dupont.com X --- X X In addition to XtoPS, ImageMagick, an X11 image processing and display utility is available on expo.lcs.mit.edu as contrib/ImageMagick.tar.Z. Included are these programs: X Display X X Display is a machine architecture independent image processing and X display program. It can display any image in the MIFF format on X any workstation display running an X server. Display first X determines the hardware capabilities of the workstation. If the X number of unique colors in the image is less than or equal to the X number the workstation can support, the image is displayed in an X X window. Otherwise the number of colors in the image is first X reduced to match the color resolution of the workstation before it X is displayed. X X This means that a continuous-tone 24 bits/pixel image can display X on a 8 bit pseudo-color device or monochrome device. In most X instances the reduced color image closely resembles the original. X Alternatively, a monochrome or pseudo-color image can display on a X continuous-tone 24 bits/pixels device. X Import X X Import is an X Window System window dumping utility. Import allows X X users to store window images in a specially formatted dump file. X This file can then be read by the Display utility for redisplay, X printing, editing, formatting, archiving, image processing, etc. X The target window can be specified by id or name or be selected by X clicking the mouse in the desired window. The keyboard bell is X rung once at the beginning of the dump and twice when the dump is X completed. X SHAR_EOF chmod 0700 README || echo 'restore of README failed' Wc_c="`wc -c < 'README'`" test 2378 -eq "$Wc_c" || echo 'README: original size 2378, current size' "$Wc_c" fi # ============= XtoPS.c ============== if test -f 'XtoPS.c' -a X"$1" != X"-c"; then echo 'x - skipping XtoPS.c (File already exists)' else echo 'x - extracting XtoPS.c (Text)' sed 's/^X//' << 'SHAR_EOF' > 'XtoPS.c' && /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % X X TTTTT OOO PPPP SSSSS % % X X T O O P P S % % X T O O PPPP SSS % % X X T O O P S % % X X T OOO P SSSSS % % % % % % Import X11 image to a Postscript format. % % % % % % Software Design % % John Cristy % % October 1990 % % % % % % Copyright 1990 E. I. Dupont de Nemours & Company % % % % Permission to use, copy, modify, distribute, and sell this software and % % its documentation for any purpose is hereby granted without fee, % % provided that the above Copyright notice appear in all copies and that % % both that Copyright notice and this permission notice appear in % % supporting documentation, and that the name of E. I. Dupont de Nemours % % & Company not be used in advertising or publicity pertaining to % % distribution of the software without specific, written prior % % permission. E. I. Dupont de Nemours & Company makes no representations % % about the suitability of this software for any purpose. It is provided % % "as is" without express or implied warranty. % % % % E. I. Dupont de Nemours & Company disclaims all warranties with regard % % to this software, including all implied warranties of merchantability % % and fitness, in no event shall E. I. Dupont de Nemours & Company be % % liable for any special, indirect or consequential damages or any % % damages whatsoever resulting from loss of use, data or profits, whether % % in an action of contract, negligence or other tortious action, arising % % out of or in connection with the use or performance of this software. % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % The XtoPS program reads an image from any visible window on an X server % and outputs it to encapsulated Postscript file. You can view this file % with any Postscript compatible viewer or printer. The image is displayed in % color on viewers or printers that support color Postscript, otherwise it is % displayed as grayscale. % % The XtoPS program command syntax is: % % Usage: XtoPS [options ...] file % % Where options include: % -border include image borders in the output image % -display name X server to contact % -frame include window manager frame % -id number select window with this id % -name name select window with this name % -root select root window % % Change '-' to '+' in any option above to reverse its effect. % For example, +frame means do not include window manager frame. % % Specify 'file' as '-' for standard input or output. % % */ X #include <X11/Xos.h> #include <X11/Xlib.h> #include <X11/Xutil.h> #include <X11/Xatom.h> #include <X11/cursorfont.h> #include "display.h" #ifdef PRE_R4_ICCCM #include "PreR4Icccm.h" #endif X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % C l i e n t W i n d o w % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Function ClientWindow finds a window, at or below the specified window, % which has a WM_STATE property. If such a window is found, it is returned, % otherwise the argument window is returned. % % The format of the ClientWindow function is: % % client_window=ClientWindow(display,target_window) % % A description of each parameter follows: % % o client_window: ClientWindow returns a window, at or below the specified % window, which has a WM_STATE property otherwise the argument % target_window is returned. % % o display: Specifies a pointer to the Display structure; returned from % XOpenDisplay. % % o target_window: Specifies the window to find a WM_STATE property. % % */ static Window ClientWindow(display,target_window) Display X *display; X Window X target_window; { X Atom X state, X type; X X int X format; X X static Window X WindowByProperty(); X X unsigned char X *data; X X unsigned long X after, X number_items; X X Window X client_window; X X state=XInternAtom(display,"WM_STATE",True); X if (state == (Atom) NULL) X return(target_window); X type=(Atom) NULL; X (void) XGetWindowProperty(display,target_window,state,0L,0L,False, X AnyPropertyType,&type,&format,&number_items,&after,&data); X if (type != (Atom) NULL) X return(target_window); X client_window=WindowByProperty(display,target_window,state); X if (client_window == (Window) NULL) X return(target_window); X return(client_window); } X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % E r r o r % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Function Error displays an error message and then terminates the program. % % The format of the Error routine is: % % Error(message,qualifier) % % A description of each parameter follows: % % o message: Specifies the message to display before terminating the % program. % % o qualifier: Specifies any qualifier to the message. % % */ void Error(message,qualifier) char X *message, X *qualifier; { X (void) fprintf(stderr,"%s: %s",application_name,message); X if (qualifier != (char *) NULL) X (void) fprintf(stderr," %s",qualifier); X (void) fprintf(stderr,".\n"); X exit(1); } X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % I s T r u e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Function IsTrue returns True if the boolean is "true", "on", "yes" or "1". % % The format of the IsTrue routine is: % % option=IsTrue(boolean) % % A description of each parameter follows: % % o option: either True or False depending on the boolean parameter. % % o boolean: Specifies a pointer to a character array. % % */ static int IsTrue(boolean) char X *boolean; { X char X c, X *p; X X if (boolean == (char *) NULL) X return(False); X for (p=boolean; *p != (char) NULL; p++) X { X /* X Convert to lower case. X */ X c=(*p); X if (isascii(c) && isupper(c)) X *p=tolower(c); X } X if (strcmp(boolean,"true") == 0) X return(True); X if (strcmp(boolean,"on") == 0) X return(True); X if (strcmp(boolean,"yes") == 0) X return(True); X if (strcmp(boolean,"1") == 0) X return(True); X return(False); } X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % P r i n t I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Function PrintImage translates a MIFF image to encapsulated Postscript for % printing. % % The format of the PrintImage routine is: % % status=PrintImage(image) % % A description of each parameter follows: % % o status: Function PrintImage return True if the image is printed. % False is returned if the image file cannot be opened for printing. % % o image: The address of a structure of type Image; returned from % ReadImage. % % */ unsigned int PrintImage(image) Image X *image; { #define PointsPerInch 72.0 #define PageBottomMargin 1.27 #define PageLeftMargin 0.21 #define PageWidth 8.5 #define PageHeight 11.0 X X static char X *commands[]= X { X "%", X "% Display a runlength-encoded color image. The image is displayed", X "% in color on viewers and printers that support color Postscript,", X "% otherwise it is displayed as grayscale.", X "%", X "/buffer 512 string def", X "/byte 1 string def", X "/color_packet 3 string def", X "/gray_packet 1 string def", X "/pixels 768 string def", X "", X "/DirectClassPacket", X "{", X " %", X " % Get a runlength-encoded DirectClass packet.", X " %", X " % Parameters:", X " % length: number of pixels minus one of this color.", X " % red.", X " % green.", X " % blue.", X " %", X " currentfile byte readhexstring pop 0 get", X " /number_pixels exch 1 add 3 mul def", X " currentfile color_packet readhexstring pop pop", X " 0 3 number_pixels 1 sub", X " {", X " pixels exch color_packet putinterval", X " } for", X " pixels 0 number_pixels getinterval", X "} bind def", X "", X "/DirectClassImage", X "{", X " %", X " % Display a runlength-encoded DirectClass image.", X " %", X " systemdict /colorimage known", X " {", X " columns rows 8", X " [", X " columns 0 0", X " rows neg 0 rows", X " ]", X " { DirectClassPacket } false 3 colorimage", X " }", X " {", X " %", X " % No colorimage operator; convert to grayscale.", X " %", X " columns rows 8", X " [", X " columns 0 0", X " rows neg 0 rows", X " ]", X " { GrayDirectClassPacket } image", X " } ifelse", X "} bind def", X "", X "/GrayDirectClassPacket", X "{", X " %", X " % Get a runlength-encoded DirectClass packet; convert to grayscale.", X " %", X " % Parameters:", X " % length: number of pixels minus one of this color", X " % red", X " % green", X " % blue", X " %", X " currentfile byte readhexstring pop 0 get", X " /number_pixels exch 1 add def", X " currentfile color_packet readhexstring pop pop", X " color_packet 0 get 0.299 mul", X " color_packet 1 get 0.587 mul add", X " color_packet 2 get 0.114 mul add", X " cvi", X " /gray_packet exch def", X " 0 1 number_pixels 1 sub", X " {", X " pixels exch gray_packet put", X " } for", X " pixels 0 number_pixels getinterval", X "} bind def", X "", X "/GrayPseudoClassPacket", X "{", X " %", X " % Get a runlength-encoded PseudoClass packet; convert to grayscale.", X " %", X " % Parameters:", X " %", X " % length: number of pixels minus one of this color.", X " % index: index into the colormap.", X " %", X " currentfile byte readhexstring pop 0 get", X " /number_pixels exch 1 add def", X " currentfile byte readhexstring pop 0 get", X " /offset exch 3 mul def", X " /color_packet colormap offset 3 getinterval def", X " color_packet 0 get 0.299 mul", X " color_packet 1 get 0.587 mul add", X " color_packet 2 get 0.114 mul add", X " cvi", X " /gray_packet exch def", X " 0 1 number_pixels 1 sub", X " {", X " pixels exch gray_packet put", X " } for", X " pixels 0 number_pixels getinterval", X "} bind def", X "", X "/PseudoClassPacket", X "{", X " %", X " % Get a runlength-encoded PseudoClass packet.", X " %", X " % Parameters:", X " % length: number of pixels minus one of this color.", X " % index: index into the colormap.", X " %", X " %", X " currentfile byte readhexstring pop 0 get", X " /number_pixels exch 1 add 3 mul def", X " currentfile byte readhexstring pop 0 get", X " /offset exch 3 mul def", X " /color_packet colormap offset 3 getinterval def", X " 0 3 number_pixels 1 sub", X " {", X " pixels exch color_packet putinterval", X " } for", X " pixels 0 number_pixels getinterval", X "} bind def", X "", X "/PseudoClassImage", X "{", X " %", X " % Display a runlength-encoded PseudoClass image.", X " %", X " % Parameters:", X " %", X " % colors: number of colors in the colormap.", X " % colormap: red, green, blue color packets.", X " %", X " currentfile buffer readline pop", X " token { /colors exch def } { } ifelse", X " /colors colors 3 mul def", X " /colormap colors string def", X " currentfile colormap readhexstring pop pop", X " systemdict /colorimage known", X " {", X " columns rows 8", X " [", X " columns 0 0", X " rows neg 0 rows", X " ]", X " { PseudoClassPacket } false 3 colorimage", X " }", X " {", X " %", X " % No colorimage operator; convert to grayscale.", X " %", X " columns rows 8", X " [", X " columns 0 0", X " rows neg 0 rows", X " ]", X " { GrayPseudoClassPacket } image", X " } ifelse", X "} bind def", X "", X "/DisplayImage", X "{", X " %", X " % Display a runlength-encoded DirectClass or PseudoClass image.", X " %", X " % Parameters:", X " % degrees rotation.", X " % x & y translation.", X " % x & y scale.", X " % image columns & rows.", X " % class: DirectClass or PseudoClass.", X " % hex color runlength-encoded packets.", X " %", X " gsave", X " currentfile buffer readline pop", X " token { /degrees exch def } { } ifelse", X " degrees rotate", X " currentfile buffer readline pop", X " token { /x exch def } { } ifelse", X " token { /y exch def } { } ifelse", X " x y translate", X " currentfile buffer readline pop", X " token { /x exch def } { } ifelse", X " token { /y exch def } { } ifelse", X " x y scale", X " currentfile buffer readline pop", X " token { /columns exch def } { } ifelse", X " token { /rows exch def } { } ifelse", X " currentfile buffer readline pop", X " token { /class exch def } { } ifelse", X " class 0 gt { PseudoClassImage } { DirectClassImage } ifelse", X " grestore", X " showpage", X "} bind def", X "", X "DisplayImage", X NULL X }; X X char X **q; X X double X delta_x, X delta_y, X image_height, X image_width, X max, X min, X rotate, X scale, X scale_x, X scale_y, X translate_x, X translate_y; X X register RunlengthPacket X *p; X X register int X i, X j; X X /* X Open output image file. X */ X if (*image->filename == '-') X image->file=stdout; X else X image->file=fopen(image->filename,"w"); X if (image->file == (FILE *) NULL) X { X (void) fprintf(stderr,"%s: unable to print image, cannot open %s.\n", X application_name,image->filename); X return(False); X } X /* X Compute image rotation. X */ X if (((double) image->columns/(double) image->rows) > 1.0) X rotate=(-90.0); X else X rotate=0.0; X /* X Compute image scaling. X */ X image_width=(double) image->columns/PointsPerInch; X image_height=(double) image->rows/PointsPerInch; X /* X Check max page sizes X */ X max=image_width > image_height ? image_width : image_height; X if (max > (PageHeight-(2.0*PageBottomMargin))) X { X scale=(PageHeight-(2.0*PageBottomMargin))/max; X image_height*=scale; X image_width*=scale; X } X min=image_width > image_height ? image_height : image_width; X if (min > (PageWidth-(2.0*PageLeftMargin))) X { X scale=(PageWidth-(2.0*PageLeftMargin))/min; X image_width*=scale; X image_height*=scale; X } X scale_x=image_width*PointsPerInch; X scale_y=image_height*PointsPerInch; X translate_x=0.0; X translate_y=0.0; X if (rotate == 0.0) X { X delta_x=PageWidth-(image_width+(2.0*PageLeftMargin)); X delta_y=PageHeight-(image_height+(2.0*PageBottomMargin)); X if (delta_x >= 0.0) X translate_x=((delta_x/2.0+PageLeftMargin)*PointsPerInch); X else X translate_x=PageLeftMargin*PointsPerInch; X if (delta_y >= 0.0) X translate_y=((delta_y/2.0+PageBottomMargin)*PointsPerInch); X else X translate_y=PageBottomMargin*PointsPerInch; X } X else X { X delta_x=PageHeight-(image_width+(2.0*PageBottomMargin)); X delta_y=PageWidth-(image_height+(2.0*PageLeftMargin)); X if (delta_x >= 0.0) X translate_x=((delta_x/2.0+PageBottomMargin-PageHeight)*PointsPerInch); X else X translate_x=(PageBottomMargin-PageHeight)*PointsPerInch; X if (delta_y >= 0.0) X translate_y=((delta_y/2.0+PageLeftMargin)*PointsPerInch); X else X translate_y=PageLeftMargin*PointsPerInch; X } X /* X Output encapsulated Postscript header. X */ X (void) fprintf(image->file,"%%!PS-Adobe-2.0 EPSF-2.0\n"); X if (rotate == 0.0) X (void) fprintf(image->file,"%%%%BoundingBox: %d %d %d %d\n", X (unsigned int) translate_x,(unsigned int) translate_y, X (unsigned int) (translate_x+scale_x), X (unsigned int) (translate_y+scale_y)); X else X (void) fprintf(image->file,"%%%%BoundingBox: %d %d %d %d\n", X (unsigned int) translate_y,(unsigned int) -(translate_x+scale_x), X (unsigned int) (translate_y+scale_y),(unsigned int) -translate_x); X (void) fprintf(image->file,"%%%%Creator: ImageMagick\n"); X (void) fprintf(image->file,"%%%%Title: %s\n",image->filename); X (void) fprintf(image->file,"%%%%EndComments\n"); X /* X Output encapsulated Postscript commands. X */ X for (q=commands; *q; q++) X (void) fprintf(image->file,"%s\n",*q); X /* X Output image data. X */ X (void) fprintf(image->file,"%f\n%f %f\n%f %f\n%d %d\n%d\n",rotate, X translate_x,translate_y,scale_x,scale_y,image->columns,image->rows, X (image->class == PseudoClass)); X p=image->pixels; X j=0; X switch (image->class) X { X case DirectClass: X { X /* X Dump DirectColor packets. X */ X for (i=0; i < image->packets; i++) X { X j++; X (void) fprintf(image->file,"%02x%02x%02x%02x",p->length,p->red, X p->green,p->blue); X if (j == 9) X { X j=0; X (void) fprintf(image->file,"\n"); X } X p++; X } X break; X } X case PseudoClass: X { X /* X Dump number of colors, colormap, PseudoColor packets. X */ X (void) fprintf(image->file,"%d\n",image->colors); X for (i=0; i < image->colors; i++) X (void) fprintf(image->file,"%02x%02x%02x\n",image->colormap[i].red, X image->colormap[i].green,image->colormap[i].blue); X for (i=0; i < image->packets; i++) X { X j++; X (void) fprintf(image->file,"%02x%02x",p->length,p->index); X if (j == 18) X { X j=0; X (void) fprintf(image->file,"\n"); X } X p++; X } X break; X } X } X (void) fprintf(image->file,"\n\n"); X (void) fprintf(image->file,"%%%%Trailer\n"); X if (image->file != stdin) X (void) fclose(image->file); X return(True); } X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d C o l o r m a p % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Function ReadColormap returns the red, green, and blue colormap of a window. % Additionally, the number of colors in the colormap is returned. % % The format of the ReadColormap function is: % % number_colors=ReadColormap(display,window_attributes,colors) % % A description of each parameter follows: % % o number_colors: ReadColormap returns the number of colors in the % colormap. % % o display: Specifies a pointer to the Display structure; returned from % XOpenDisplay. % % o window_attributes: Specifies a pointer to the window attributes % structure; returned from XGetWindowAttributes. % % o colors: Specifies a an array of XColor structures. The colormap % red, green, and blue are returned. % % */ static int ReadColormap(display,window_attributes,colors) Display X *display; X XXWindowAttributes X *window_attributes; X XXColor X **colors; { X int X number_colors; X X register int X i; X X if (window_attributes->colormap == (Colormap) NULL) X return(0); X if (window_attributes->visual->class == TrueColor) X return(0); X number_colors=window_attributes->visual->map_entries; X *colors=(XColor *) malloc((unsigned) (number_colors*sizeof(XColor))); X if (*colors == (XColor *) NULL) X Error("unable to allocate memory",(char *) NULL); X for (i=0; i < number_colors; i++) X if (window_attributes->visual->class != DirectColor) X for (i=0; i < number_colors; i++) X { X (*colors)[i].pixel=i; X (*colors)[i].pad=0; X } X else X { X unsigned long X blue, X blue_bit, X green, X green_bit, X red, X red_bit; X X /* X DirectColor visual. X */ X red=0; X green=0; X blue=0; X red_bit=window_attributes->visual->red_mask & X (~(window_attributes->visual->red_mask)+1); X green_bit=window_attributes->visual->green_mask & X (~(window_attributes->visual->green_mask)+1); X blue_bit=window_attributes->visual->blue_mask & X (~(window_attributes->visual->blue_mask)+1); X for (i=0; i < number_colors; i++) X { X (*colors)[i].pixel=red | green | blue; X (*colors)[i].pad=0; X red+=red_bit; X if (red > window_attributes->visual->red_mask) X red=0; X green+=green_bit; X if (green > window_attributes->visual->green_mask) X green=0; X blue+=blue_bit; X if (blue > window_attributes->visual->blue_mask) X blue=0; X } X } X XQueryColors(display,window_attributes->colormap,*colors,number_colors); X return(number_colors); } X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Procedure ReadImage reads an image from an X window. % % The format of the ReadImage routine is: % % ReadImage(display,root_window,target_window,client_window,borders, % image) % % A description of each parameter follows: % % o display: Specifies a pointer to the Display structure; returned from % XOpenDisplay. % % o root_window: Specifies the id of the root window. % % o target_window: Specifies the id of the target window. % % o client_window: Specifies the id of the client of the target window. % % o borders: Specifies whether borders pixels are to be saved with % the image. % % o image: specifies a pointer to the Image structure. % % */ static void ReadImage(display,root_window,target_window,client_window,borders, X image) Display X *display; X Window X root_window, X target_window, X client_window; X unsigned int X borders; X Image X *image; { X int X display_width, X display_height, X x, X y; X X register int X i; X X register RunlengthPacket X *p; X X register unsigned long X pixel; X X unsigned char X blue, X green, X red; X X Window X child; X X XColor X *colors; X X XImage X *ximage; X X XTextProperty X window_name; X X XWindowAttributes X client_attributes, X target_attributes; X X /* X Inform the user not to alter the screen. X */ X XBell(display,0); X /* X Get the attributes of the window being dumped. X */ X if (!XGetWindowAttributes(display,target_window,&target_attributes) || X !XGetWindowAttributes(display,client_window,&client_attributes)) X Error("unable to get target window attributes",(char *) NULL); X XTranslateCoordinates(display,target_window,root_window,0,0,&x,&y,&child); X target_attributes.x=x; X target_attributes.y=y; X image->columns=target_attributes.width; X image->rows=target_attributes.height; X if (borders) X { X /* X Do not include border in image. X */ X x-=target_attributes.border_width; X y-=target_attributes.border_width; X image->columns+=2*target_attributes.border_width; X image->rows+=2*target_attributes.border_width; X } X /* X clip to window X */ X if (x < 0) X { X image->columns+=x; X x=0; X } X if (y < 0) X { X image->rows+=y; X y=0; X } X display_width=DisplayWidth(display,XDefaultScreen(display)); X display_height=DisplayHeight(display,XDefaultScreen(display)); X if ((x+image->columns) > display_width) X image->columns=display_width-x; X if ((y+image->rows) > display_height) X image->rows=display_height-y; X /* X Get image from window with XGetImage. X */ X x-=target_attributes.x; X y-=target_attributes.y; X ximage=XGetImage(display,target_window,x,y,image->columns,image->rows, X AllPlanes,ZPixmap); X if (ximage == (XImage *) NULL) X Error("unable to get image",(char *) NULL); X /* X Obtain the window colormap from the client of the target window. X */ X image->colors=ReadColormap(display,&client_attributes,&colors); X XBell(display,0); X XBell(display,0); X XFlush(display); X /* X Convert image to MIFF format. X */ X image->comments=(char *) NULL; X if (XGetWMName(display,target_window,&window_name)) X { X /* X Initial image comment. X */ X image->comments=(char *) X malloc((unsigned int) (strlen((char *) window_name.value)+256)); X if (image->comments == (char *) NULL) X Error("unable to allocate memory",(char *) NULL); X (void) sprintf(image->comments,"\n Imported from X11 window: %s\n\0", X window_name.value); X } X if ((target_attributes.visual->class == TrueColor) || X (target_attributes.visual->class == DirectColor)) X image->class=DirectClass; X else X image->class=PseudoClass; X image->compression=RunlengthEncodedCompression; X image->scene=0; X image->pixels=(RunlengthPacket *) X malloc(image->columns*image->rows*sizeof(RunlengthPacket)); X if (image->pixels == (RunlengthPacket *) NULL) X Error("unable to allocate memory",(char *) NULL); X image->packets=0; X p=image->pixels; X p->length=MaxRunlength; X switch (image->class) X { X case DirectClass: X { X register unsigned long X color, X index; X X unsigned long X blue_mask, X blue_shift, X green_mask, X green_shift, X red_mask, X red_shift; X X /* X Determine shift and mask for red, green, and blue. X */ X red_mask=target_attributes.visual->red_mask; X red_shift=0; X while ((red_mask & 0x01) == 0) X { X red_mask>>=1; X red_shift++; X } X green_mask=target_attributes.visual->green_mask; X green_shift=0; X while ((green_mask & 0x01) == 0) X { X green_mask>>=1; X green_shift++; X } X blue_mask=target_attributes.visual->blue_mask; X blue_shift=0; X while ((blue_mask & 0x01) == 0) X { X blue_mask>>=1; X blue_shift++; X } X /* X Convert X image to DirectClass packets. X */ X if ((image->colors > 0) && X (target_attributes.visual->class == DirectColor)) X for (y=0; y < image->rows; y++) X { X for (x=0; x < image->columns; x++) X { X pixel=XGetPixel(ximage,x,y); X index=(pixel >> red_shift) & red_mask; X red=(unsigned char) (colors[index].red >> 8); X index=(pixel >> green_shift) & green_mask; X green=(unsigned char) (colors[index].green >> 8); X index=(pixel >> blue_shift) & blue_mask; X blue=(unsigned char) (colors[index].blue >> 8); X if ((red == p->red) && (green == p->green) && (blue == p->blue) && X (p->length < MaxRunlength)) X p->length++; X else X { X if (image->packets > 0) X p++; X image->packets++; X p->red=red; X p->green=green; X p->blue=blue; X p->index=0; X p->length=0; X } X } X } X else X for (y=0; y < image->rows; y++) X for (x=0; x < image->columns; x++) X { X pixel=XGetPixel(ximage,x,y); X color=(pixel >> red_shift) & red_mask; X red=(unsigned char) X ((((unsigned long) color*65535)/red_mask) >> 8); X color=(pixel >> green_shift) & green_mask; X green=(unsigned char) X ((((unsigned long) color*65535)/green_mask) >> 8); X color=(pixel >> blue_shift) & blue_mask; X blue=(unsigned char) X ((((unsigned long) color*65535)/blue_mask) >> 8); X if ((red == p->red) && (green == p->green) && (blue == p->blue) && X (p->length < MaxRunlength)) X p->length++; X else X { X if (image->packets > 0) X p++; X image->packets++; X p->red=red; X p->green=green; X p->blue=blue; X p->index=0; X p->length=0; X } X } X break; X } X case PseudoClass: X { X /* X Convert X image to PseudoClass packets. X */ X image->colormap=(ColorPacket *) X malloc((unsigned) (image->colors*sizeof(ColorPacket))); X if (image->colormap == (ColorPacket *) NULL) X Error("unable to allocate memory",(char *) NULL); X for (i=0; i < image->colors; i++) X { X image->colormap[i].red=colors[i].red >> 8; X image->colormap[i].green=colors[i].green >> 8; X image->colormap[i].blue=colors[i].blue >> 8; X } X for (y=0; y < image->rows; y++) X for (x=0; x < image->columns; x++) X { X pixel=XGetPixel(ximage,x,y); X red=(unsigned char) (colors[pixel].red >> 8); X green=(unsigned char) (colors[pixel].green >> 8); X blue=(unsigned char) (colors[pixel].blue >> 8); X if ((red == p->red) && (green == p->green) && (blue == p->blue) && X (p->length < MaxRunlength)) X p->length++; X else X { X if (image->packets > 0) X p++; X image->packets++; X p->red=red; X p->green=green; X p->blue=blue; X p->index=(unsigned short) pixel; X p->length=0; X } X } X break; X } X } X /* X Free image and colormap. X */ X if (image->colors > 0) X (void) free((char *) colors); X XDestroyImage(ximage); X if (image->packets > ((image->columns*image->rows*3) >> 2)) X image->compression=NoCompression; X image->pixels=(RunlengthPacket *) X realloc((char *) image->pixels,image->packets*sizeof(RunlengthPacket)); } X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % S e l e c t W i n d o w % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Function SelectWindow allows a user to select a window using the mouse. % % The format of the SelectWindow function is: % % target_window=SelectWindow(display,root_window) % % A description of each parameter follows: % % o window: SelectWindow returns the window id. % % o display: Specifies a pointer to the Display structure; returned from % XOpenDisplay. % % o root_window: Specifies the window id of the root window. % % */ static Window SelectWindow(display,root_window) Display X *display; X Window X root_window; { X Cursor X crosshair_cursor; X X int X status; X X unsigned int X presses; X X Window X target_window; X X XEvent X event; X X /* X Make the target cursor. X */ X crosshair_cursor=XCreateFontCursor(display,XC_crosshair); X /* X Grab the pointer using target cursor. X */ X status=XGrabPointer(display,root_window,False,ButtonPressMask | X ButtonReleaseMask,GrabModeSync,GrabModeAsync,root_window,crosshair_cursor, X CurrentTime); X if (status != GrabSuccess) X Error("cannot grab the mouse",(char *) NULL); X /* X Select a window. X */ X target_window=(Window) NULL; X presses=0; X do X { X /* X Allow another event. X */ X XAllowEvents(display,SyncPointer,CurrentTime); X XWindowEvent(display,root_window,ButtonPressMask | ButtonReleaseMask, X &event); X switch (event.type) X { X case ButtonPress: X { X if (target_window == (Window) NULL) X { X target_window=event.xbutton.subwindow; X if (target_window == (Window) NULL) X target_window=root_window; X } X presses++; X break; X } X case ButtonRelease: X { X if (presses > 0) X presses--; X break; X } X default: X break; X } X } X while ((target_window == (Window) NULL) || (presses != 0)); X XUngrabPointer(display,CurrentTime); X XFreeCursor(display,crosshair_cursor); X return(target_window); } X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % U s a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Procedure Usage displays the program usage; % % The format of the Usage routine is: % % Usage(message) % % A description of each parameter follows: % % message: Specifies a specific message to display to the user. % */ static void Usage(message) char X *message; { X char X **p; X X static char X *options[]= X { X "-border include image borders in the output image", X "-display server X server to contact", X "-frame include window manager frame", X "-id number select window with this id", X "-name name select window with this name", X "-root select root window", X (char *) NULL X }; X if (message != (char *) NULL) X (void) fprintf(stderr,"Can't continue, %s.\n\n",message); X (void) fprintf(stderr,"Usage: %s [options ...] file\n",application_name); X (void) fprintf(stderr,"\nWhere options include:\n"); X for (p=options; *p != (char *) NULL; p++) X (void) fprintf(stderr," %s\n",*p); X (void) fprintf(stderr, X "\nChange '-' to '+' in any option above to reverse its effect.\n"); X (void) fprintf(stderr, X "For example, +frame means do not include window manager frame.\n"); X (void) fprintf(stderr,"\nSpecify 'file' as '-' for standard output.\n"); X exit(1); } X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % W i n d o w B y N a m e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Function WindowByName locates a window with a given name on a display. % If no window with the given name is found, 0 is returned. If more than % one window has the given name, the first one is returned. Only root and % its children are searched. % % The format of the WindowByName function is: % % window=WindowByName(display,root_window,name) % % A description of each parameter follows: % % o window: WindowByName returns the window id. % % o display: Specifies a pointer to the Display structure; returned from % XOpenDisplay. % % o root_window: Specifies the id of the root window. % % o name: Specifies the name of the window to locate. % % */ static Window WindowByName(display,root_window,name) Display X *display; X Window X root_window; X char X *name; { X register int X i; X X unsigned int X number_children; X X Window X *children, X child, X window; X X XTextProperty X window_name; X X if (XGetWMName(display,root_window,&window_name)) X if (strcmp((char *) window_name.value,name) == 0) X return(root_window); X if (!XQueryTree(display,root_window,&child,&child,&children,&number_children)) X return(0); X window=0; X for (i=0; i < number_children; i++) X { X /* X Search each child and their children. X */ X window=WindowByName(display,children[i],name); X if (window != (Window) NULL) X break; X } X if (children != (Window *) NULL) X XFree((char *) children); X return(window); } X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % W i n d o w B y P r o p e r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Function WindowByProperty locates a child window with a given property. % If no window with the given name is found, 0 is returned. If more than % one window has the given property, the first one is returned. Only the % window specified and its subwindows are searched. % % The format of the WindowByProperty function is: % % child=WindowByProperty(display,window,property) % % A description of each parameter follows: % % o child: WindowByProperty returns the window id with the specified % property. If no windows are found, WindowByProperty returns 0. % % o display: Specifies a pointer to the Display structure; returned from % XOpenDisplay. % % o property: Specifies the property of the window to locate. % % */ static Window WindowByProperty(display,window,property) Display X *display; X Window X window; X Atom X property; { X Atom X type; X X int X format; X X unsigned char X *data; X X unsigned int X i, X number_children; X X unsigned long X after, X number_items; X X Window X *children, X child, X parent, X root; X X if (!XQueryTree(display,window,&root,&parent,&children,&number_children)) X return((Window) NULL); X type=(Atom) NULL; X child=(Window) NULL; X for (i=0; (i < number_children) && (child == (Window) NULL); i++) X { X (void) XGetWindowProperty(display,children[i],property,0L,0L,False, X AnyPropertyType,&type,&format,&number_items,&after,&data); X if (type != (Atom) NULL) X child=children[i]; X } X for (i = 0; (i < number_children) && (child == (Window) NULL); i++) X child=WindowByProperty(display,children[i],property); X if (children != (Window *) NULL) X XFree((char *) children); X return(child); } X /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % M a i n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % */ int main(argc,argv) int X argc; X char X *argv[]; { X char X *filename, X *option, X *server_name; X X Display X *display; X X extern unsigned int X WriteImage(); X X Image X image; X X int X i; X X unsigned int X borders, X frame, X j; X X Window X client_window, X root_window, X target_window; X X /* X Display usage profile if there are no command line arguments. X */ X application_name=(*argv); X if (argc < 2) X Usage((char *) NULL); X /* X Connect to X server. X */ X server_name=(char *) NULL; X for (i=1; i < argc; i++) X { X /* X Check command line for server name. X */ X option=argv[i]; X if ((strlen(option) > 1) && ((*option == '-') || (*option == '+'))) X if (strncmp("dis",option+1,3) == 0) X { X /* X User specified server name. X */ X i++; X if (i == argc) X Usage("missing server name on -display"); X server_name=argv[i]; X break; X } X } X display=XOpenDisplay(server_name); X if (display == (Display *) NULL) X Error("unable to connect to",XDisplayName(server_name)); X root_window=XRootWindow(display,XDefaultScreen(display)); X /* X Get X defaults. X */ X option=XGetDefault(display,application_name,"borders"); X borders=IsTrue(option); X option=XGetDefault(display,application_name,"frame"); X frame=IsTrue(option); X /* X Check command syntax. X */ X filename=(char *) NULL; X target_window=(Window) NULL; X for (i=1; i < argc; i++) X { X option=argv[i]; X if ((strlen(option) < 2) || ((*option != '-') && (*option != '+'))) X filename=argv[i]; X else X switch(*(option+1)) X { X case 'b': X { X borders=(*option == '-'); X break; X } X case 'h': X { X Usage((char *) NULL); X break; X } X case 'f': X { X frame=(*option == '-'); X break; X } X case 'i': X { X i++; X if (i == argc) X Usage("missing id on -id"); X option=argv[i]; X target_window=(Window) strtol(option,(char **) NULL,0); X break; X } X case 'n': X { X i++; X if (i == argc) X Usage("missing name on -name"); X option=argv[i]; X target_window=WindowByName(display,root_window,option); X if (target_window == (Window) NULL) X (void) fprintf(stderr,"No window with name %s exists!\n",option); X break; X } X case 'r': X { X target_window=root_window; X break; X } X default: X Usage((char *) NULL); X } X } X if (filename == (char *) NULL) X Usage("missing an image file name"); X /* X If the window is not specified, let the user choose one with the mouse. X */ X if (target_window == (Window) NULL) X target_window=SelectWindow(display,root_window); X client_window=target_window; X if (target_window != root_window) X if (XGetGeometry(display,target_window,&root_window,&i,&i,&j,&j,&j,&j)) X { X /* X Get client window. X */ X client_window=ClientWindow(display,target_window); X if (!frame) X target_window=client_window; X } X (void) strcpy(image.filename,filename); X ReadImage(display,root_window,target_window,client_window,borders,&image); X (void) fprintf(stderr,"%s %dx%d\n",image.filename,image.columns,image.rows); X (void) PrintImage(&image); X return(False); } SHAR_EOF chmod 0700 XtoPS.c || echo 'restore of XtoPS.c failed' Wc_c="`wc -c < 'XtoPS.c'`" test 48482 -eq "$Wc_c" || echo 'XtoPS.c: original size 48482, current size' "$Wc_c" fi # ============= XtoPS.man ============== if test -f 'XtoPS.man' -a X"$1" != X"-c"; then echo 'x - skipping XtoPS.man (File already exists)' else echo 'x - extracting XtoPS.man (Text)' sed 's/^X//' << 'SHAR_EOF' > 'XtoPS.man' && .ad l .nh .TH XtoPS 1 "4 July 1990" "X Version 11" .SH NAME XXtoPS - dump an image of an X window as encapsulated Postscript .SH SYNOPSIS .B "XtoPS" [ \fIoptions\fP ... ] \fIfile\fP .SH DESCRIPTION .PP .I XtoPS is an X Window System window dumping utility. .I XtoPS reads an image from any visible window on an X server and outputs it to an encapsulated Postscript file. You can view this file with any Postscript compatible viewer or printer. The image is displayed in color on viewers or printers that support color Postscript, otherwise it is displayed as grayscale. .pp The target window can be specified by id or name or be selected by clicking the mouse in the desired window. The keyboard bell is rung once at the beginning of the dump and twice when the dump is completed. .SH EXAMPLE .PP To save the entire X server screen as encapsulated Postscript in a file on disk titled root.ps, use: .PP X XtoPS -root root.ps .SH OPTIONS \fIXtoPS\fP options can appear on the command line or in your X resources file (see X(1)). Options on the command line supercede values specified in your X resources file. .TP 4 .B "-border" include image borders in the output image. .TP 4 .B "-display \fIhost:display[.screen]\fP" specifies the X server to contact; see \fBX(1)\fP. .TP 4 .B "-frame" include window manager frame. .TP 4 .B "-id \fIvalue\fP" select window with this id. .TP 4 .B "-name \fIname\fP" select window with this name. .TP 4 .B "-root" select root window. .PP Change \fI-\fP to \fI+\fP in any option above to reverse its effect. For example \fB+frame\fP means do not include window manager frame. .PP Specify \fIfile\fP as \fI-\fP for standard input or output. .PP .SH ENVIRONMENT .PP .TP 4 .B DISPLAY To get the default host, display number, and screen. .SH SEE ALSO XX(1), display(1), import(1) .SH COPYRIGHT Copyright 1990 E. I. Dupont de Nemours & Company .PP Permission to use, copy, modify, distribute, and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of E. I. Dupont de Nemours & Company not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. E. I. Dupont de Nemours & Company makes no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty. .PP E. I. Dupont de Nemours & Company disclaims all warranties with regard to this software, including all implied warranties of merchantability and fitness, in no event shall E. I. Dupont de Nemours & Company be liable for any special, indirect or consequential damages or any damages whatsoever resulting from loss of use, data or profits, whether in an action of contract, negligence or other tortious action, arising out of or in connection with the use or performance of this software. .SH AUTHORS John Cristy, E.I. DuPont De Nemours & Company Incorporated X SHAR_EOF chmod 0700 XtoPS.man || echo 'restore of XtoPS.man failed' Wc_c="`wc -c < 'XtoPS.man'`" test 3351 -eq "$Wc_c" || echo 'XtoPS.man: original size 3351, current size' "$Wc_c" fi # ============= display.h ============== if test -f 'display.h' -a X"$1" != X"-c"; then echo 'x - skipping display.h (File already exists)' else echo 'x - extracting display.h (Text)' sed 's/^X//' << 'SHAR_EOF' > 'display.h' && X #include <stdio.h> #include <ctype.h> #include <math.h> #ifdef vms #define pclose(file) (FILE *) exit(1) #define popen(command,mode) (FILE *) exit(1) #else #include <malloc.h> #include <memory.h> X extern long X strtol(), X time(); #endif /* X Define declarations for the Display program. */ #ifndef False #define False 0 #endif #define Intensity(color) \ X (((color).red*77+(color).green*150+(color).blue*29) >> 8) #define Max(x,y) (((x) > (y)) ? (x) : (y)) #define MaxColormapSize 4096 #define MaxImageSize (4096*4096) #define MaxRgb 255 #define MaxRunlength 255 #define Min(x,y) (((x) < (y)) ? (x) : (y)) #ifndef True #define True 1 #endif /* X Image Id's */ #define UnknownId 0 #define ImageMagickId 1 /* X Image classes: */ #define UnknownClass 0 #define DirectClass 1 #define PseudoClass 2 /* X Image compression algorithms: */ #define UnknownCompression 0 #define NoCompression 1 #define RunlengthEncodedCompression 2 #define QEncodedCompression 3 X /* X Typedef declarations for the Display program. */ typedef struct _ColorPacket { X unsigned char X red, X green, X blue; X X unsigned short X index; } ColorPacket; X typedef struct _RunlengthPacket { X unsigned char X red, X green, X blue, X length; X X unsigned short X index; } RunlengthPacket; X typedef struct _Image { X FILE X *file; X X char X filename[256]; X X unsigned int X id, X class, X colors, X packets, X compression, X columns, X rows, X scene, X channel; X X char X *comments; X X ColorPacket X *colormap; X X RunlengthPacket X *pixels; X X unsigned int X runlength; } Image; /* X Variable declarations. */ char X *application_name; SHAR_EOF chmod 0700 display.h || echo 'restore of display.h failed' Wc_c="`wc -c < 'display.h'`" test 1669 -eq "$Wc_c" || echo 'display.h: original size 1669, current size' "$Wc_c" fi exit 0 -- The UUCP Mailer