/* * Copyright (c) 1997 by * PARALLAX GRAPHICS, INCORPORATED, Santa Clara, California. * All rights reserved * * This software is furnished on an as-is basis, and may be used and copied * only with the inclusion of the above copyright notice. * * The information in this software is subject to change without notice. * No committment is made as to the usability or reliability of this * software. * * Parallax Graphics, Inc. * 2500 Condensa Street * Santa Clara, California 95051 * Author: Scott Schmitz */ /* Revision 0.01 97/08/12 scott * Initial coding of "winout". Grab image from 24-bit window * MUST BE ON 24-BIT FB!, use XPlxPutImage to place onto * Parallax output board, send to output */ /*To invoke winout, just type "./winout" You will be asked to /*select a window to send to Parallax output. A new (video) /*window will be created which will display what is sent out. /*NOTES: /*- the largest area sent out will be 640x480 /*- you may hide the video window under the source window /* without any problems /*- the window selected MUST BE a 24-bit window */ #include #include #include #include #include #include #include #include char ProgName[] = "winout"; char ProgVers[] = "Version 0.01 Rev: 08/12/97 - by Scott Schmitz"; char FileName[80]; #ifdef __STDC__ #define ARGS(alist) alist #else #define ARGS(alist) () #endif #define MAX_ARG 10 #define TIMEOUT 30 #define MIN_WIDTH 8 #define MIN_HEIGHT 8 #define videowidth 640 #define videoheight 480 typedef unsigned char byte; typedef void (*vfp)(); static Display *dsp; static XImage *image; static FILE *out; static int width,height; /* G L O B A L P R E D E F I N I T I O N S */ Window SelectWindow(Display *dpy) { int status; Cursor cursor; XEvent event; Window target_win = None; Window root; int buttons = 0; unsigned int numWin; int windowFound; int subWindowFound; int isRootWindow; XWindowAttributes windowAttributes; int targetWidth; int targetHeight; int windowWidth; int windowHeight; Window parent; Window current; Window *children; int i; root = RootWindow(dpy, XDefaultScreen(dpy)); cursor = XCreateFontCursor(dpy, XC_crosshair); /* Make the target cursor */ status = XGrabPointer(dpy, root, False, /* Grab the pointer using target cursor, letting it... */ ButtonPressMask|ButtonReleaseMask, /* ...roam all over */ GrabModeSync, GrabModeAsync, root, cursor, CurrentTime); if (status != GrabSuccess) return(root); while ((target_win == None) || (buttons != 0)) /* Let the user select a window... */ { XAllowEvents(dpy, SyncPointer, CurrentTime); /* allow one more event */ XWindowEvent(dpy, root, ButtonPressMask|ButtonReleaseMask, &event); switch (event.type) { case ButtonPress: if (target_win == None) { target_win = event.xbutton.subwindow; /* window selected */ if (target_win == None) target_win = root; } buttons++; break; case ButtonRelease: if (buttons > 0) /* There may have been some down before we started */ buttons--; break; } } XUngrabPointer(dpy, CurrentTime); /* Done with pointer */ XGetWindowAttributes(dpy, target_win, &windowAttributes); targetWidth = windowAttributes.width; targetHeight = windowAttributes.height; windowWidth = 0; windowHeight = 0; subWindowFound = False; XQueryTree(dpy, target_win, &root, &parent, &children, &numWin); /* * If the user selected the root window, do not look for a * child window. */ if(target_win != root) { for(i = 0; i < numWin; i++) { XGetWindowAttributes(dpy, children[i], &windowAttributes); if(windowAttributes.width >= windowWidth && windowAttributes.height >= windowHeight) { /* * Found a child window with the same width and height. */ windowWidth = windowAttributes.width; windowHeight = windowAttributes.height; target_win = children[i]; } } } else { } XFree(children); width = windowWidth; height = windowHeight; return(target_win); } /* end function SelectWindow */ static void quit(message) char *message; { fprintf(stderr,"%s: %s\n",ProgName,message); XBell(dsp, 0); XBell(dsp, 0); XBell(dsp, 0); XCloseDisplay(dsp); fclose(out); exit(1); } main(ArgC, ArgV) int ArgC; char *ArgV[]; { int iffile, ifcolor; int i, n, maxcol, argc; int x, y, ncol, R[256], G[256], B[256]; long igray, irep; byte r[256], g[256], b[256], scline[4096]; char *format, mess[80], *argv[MAX_ARG]; Window wid; char newFileName[85]; int number_to_save; char* movie_name; int scr; XVisualInfo* visualInfo; int depth = 32; XSetWindowAttributes attr; int first=1; Window winout; GC gcout; GC gcput; int mask; plx_IO* plxio = NULL; int vmask; XWindowChanges xwc; /* G E T P A R A M E T E R S */ iffile = 0; number_to_save = 10000; /* do "forever" */ /* O P E N D I S P L A Y */ dsp = XOpenDisplay(""); if (dsp == NULL) { fprintf(stderr,"%s: unable to open display '%s'\n", ProgName,XDisplayName("")); fclose(out); exit(1); } scr = (int)XDefaultScreen(dsp); /* G E T W I N D O W */ fprintf(stderr,"*******************************************************\n"); fprintf(stderr,"* *\n"); fprintf(stderr,"* Select a window by moving the mouse to that area, *\n"); fprintf(stderr,"* then clicking on the left mouse button *\n"); fprintf(stderr,"* *\n"); fprintf(stderr,"*******************************************************\n"); XBell(dsp, 0); wid = SelectWindow(dsp); x=0; y=0; /* P I C K I M A G E */ for (n = 0; ndepth; if (TrueColor == visualInfo->class) { attr.colormap = XCreateColormap(dsp, XRootWindow(dsp, scr), visualInfo->visual, AllocNone); } else { attr.colormap = XDefaultColormap(dsp, scr); } mask = CWBackPixel | /* WARNING! !! Must set up the colormap, the... */ CWColormap | /* background_pixel and the border_pixel to make it */ CWBorderPixel; /* work when the win depth is diff from root depth. */ attr.background_pixel = BlackPixel(dsp, DefaultScreen(dsp)); attr.border_pixel = WhitePixel(dsp, DefaultScreen(dsp)); winout = XCreateWindow(dsp, RootWindow(dsp, scr), 0, 0, width, height, 1, depth, InputOutput, visualInfo->visual, mask, &attr); vmask = CWX | CWY; xwc.x = -10; /* place under parent */ xwc.y = -20; /* xwc.sibling = wid; /* associate with selected window */ /* xwc.stack_mode = Below; /* and "lower" it */ XConfigureWindow(dsp,winout,vmask,&xwc); gcput = XCreateGC(dsp, winout, 0, 0); gcout = XCreateGC(dsp, winout, 0, 0); XFlush(dsp); plxio = XPlxQueryConfig(dsp, winout, gcout); XPlxVideoOutputSelect(dsp, winout, gcout, PLX_OUTPUT_0, PLX_NTSC, PLX_COMP, PLX_RGB24); XPlxVideoScaleOutput(dsp, winout, gcout, 0, 0, width, height, 0, 0, videowidth, videoheight); XMapWindow(dsp,winout); first = 0; } image->depth = 32; XPlxPutImage(dsp,winout,gcput,image,0,0,0,0,width,height); XDestroyImage(image); } XBell(dsp, 0); XBell(dsp, 0); XBell(dsp, 0); XCloseDisplay(dsp); exit(0); }