/* * 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 * * Adapted from SUN makemovie, not saving anything */ /* Program: ximagetime Usage: ximagetime [options] [options]: -wWidth (in pixels) Height is automatic Example: ximagetime -w320 This will record at with a width of 320 pixels (height is automatic) Description: This program will capture uncompressed images (32-bit Ximages) in a tight loop. Statistics related to this capture will be printed to the screen. This program allows the user to "rate" their system to understand the frames per second which can be captured at a specific width/height. */ #include #include #include #include #include #include #include #include #include #include #include /* required for gettimeofday */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* function prototypes */ void print_help(void); void FindRate(int); struct timeval later, now; main(argc,argv) int argc; char **argv; { int depth; Display *disp; Window win; int screen, width=640, height=480, i=1; int winMask; /* Window attribute mask. */ XImage *xImage; GC gc; static unsigned char *qTable; /* Q Table to load to CCube chip */ static int qTableSize; /* Size of Q Table. */ XVisualInfo *vInfo; XSetWindowAttributes attr; static int mask=ExposureMask; /* Window event mask. */ XEvent winEvent; plx_signal *plxSignal=NULL; /* Video signal structure. */ int playbackRate=20; /* Movie playback rate, default to 20 fps, */ /* this is conservative. */ int end = 30; /* Number of frames to capture. */ int seconds = 10; /* Default to 10 seconds of recording */ long int us_per_frame; /* micro seconds per frame */ long int ms_per_frame; int frame = 0; char *window_name="fastgrab"; XTextProperty windowname; int nextFrameTime; int thisFrameTime; int framesizing; if (argc<1) /* Forgot to specify a filename? */ { /* Print help message */ print_help(); exit(1); } i = 1; while(i < argc && argv[i][0] == '-') /* Decode option list (options begin with */ /* a '-' */ { switch(argv[i][1]) { case 'w': /* set the width (height is automatic) */ { width = atoi(argv[i]+2); height = (int)((double)(480.0/640.0) * (double) width); printf("width = %d, height = %d (pixels).\n", width, height); } /* end of case 'w' */ break; break; } /* end of switch statement */ i++; /* increment the argument pointer */ } /* end of while */ us_per_frame = (long int)((1.0 / (float)playbackRate) * 1000000); ms_per_frame = us_per_frame / 1000; disp=XOpenDisplay(getenv("DISPLAY")); screen=(int)XDefaultScreen(disp); vInfo = XPlxGetVideoVisual(screen, disp); /* Try to get a visual appropriate for showing live video */ depth = vInfo->depth; winMask=CWBackPixel|CWColormap|CWBorderPixel; /* Setup window attribute mask. */ attr.colormap=XCreateColormap(disp, /* Create colormap according to visual. */ XRootWindow(disp,screen), vInfo->visual,AllocNone); attr.background_pixel=BlackPixel(disp,screen); /* Set background color to black. */ attr.border_pixel=WhitePixel(disp,screen); /* Set boarder color to white. */ win=XCreateWindow(disp,RootWindow(disp,screen), /* Create window for frame grab. */ 0,0,width,height,0,depth,InputOutput, /* Window size is set to 640 x 480. */ vInfo->visual,winMask,&attr); XStringListToTextProperty(&window_name, 1, &windowname); XSetWMProperties(disp, win, &windowname, &windowname, argv, argc, NULL, NULL, NULL); gc=XCreateGC(disp, win, 0, 0); /* Create window gc. */ XPlxVideoInputSelect(disp,win,gc, PLX_INPUT_0, PLX_NTSC, PLX_COMP, /* NTSC */ /* PLX_INPUT_0, PLX_PAL, PLX_COMP, /* PAL */ PLX_RGB24); /* Select video input type & channel. */ plxSignal=(plx_signal*)XPlxQueryVideo(disp, /* Detect for video signal at input. */ win,gc); while (!plxSignal->sync_ok) { printf("Sync Absent - Hook up an input source\n"); XPlxSleep(500000); plxSignal=(plx_signal*)XPlxQueryVideo(disp, win, gc); } XPlxVideoTag(disp,win,gc,PLX_VIDEO); /* Setup up window tag to display video */ XSelectInput(disp,win,mask); /* Setup up window event mask. */ XMapWindow(disp,win); /* Map window to display. */ XNextEvent(disp,&winEvent); XPlxVideoSqueezeLive(disp,win,gc,0,plxSignal->b, 640, 480, 0,0,width,height); /* Display live video. NTSC */ /* 768, 575, 0,0,width,height); /* Display live video. PAL */ gettimeofday(&now, NULL); while(1) { xImage=(XImage *) XPlxGetImage(disp,win, 0,0, width, height, AllPlanes, ZPixmap); /* Grab an uncompressed image from window. */ frame++; framesizing += width*height*3; /* 4 bytes (32 bits) per frame */ if(frame % 100 == 0) /* calculate rate every 100 frames */ { FindRate(framesizing); framesizing = 0; /* reset size for next calculation */ } /* insert your processing code here */ XDestroyImage(xImage); /* free up storage */ } } void print_help(void) { printf("usage: ximagetime [-options]\n"); printf(" -options:\n"); printf(" -wWidth (Height is automatic)\n"); return; } void FindRate(int sizes) { char buf[32]; float d,e; int i,j; float bps; gettimeofday(&later,NULL); i = later.tv_sec * 1000000 + later.tv_usec; j = now.tv_sec * 1000000 + now.tv_usec; i = i - j; e = ((float) i) / 100.0; d = 1000000.0 / e; printf("Captured %d bytes in %1.1f seconds\n",sizes,(float)i/1000000); bps = ((sizes * 8) / ((float)i)); printf("Current Rate : %1.1f fps bandwidth = %1.4f Mbits/sec\n", d,bps); gettimeofday(&now,NULL); }