|
| 1 | +/* |
| 2 | + * svgrab24 - Grab the current video input image into an rgb file. |
| 3 | + * |
| 4 | + * Jack Jansen, CWI, May 93. |
| 5 | + * |
| 6 | + * Adapted from grabone.c |
| 7 | + */ |
| 8 | + |
| 9 | +#ident "$Revision$" |
| 10 | + |
| 11 | +#include <stdio.h> |
| 12 | +#include <stdlib.h> |
| 13 | +#include <svideo.h> |
| 14 | +#include <gl/gl.h> |
| 15 | +#include <gl/device.h> |
| 16 | +#include <getopt.h> |
| 17 | +#include <image.h> |
| 18 | + |
| 19 | +main(int argc, char *argv[]) |
| 20 | +{ |
| 21 | + SVhandle V; |
| 22 | + svCaptureInfo ci; |
| 23 | + boolean debug; |
| 24 | + int ch, errflg; |
| 25 | + int bufferSize; |
| 26 | + long *buffer; |
| 27 | + IMAGE *imgfile; |
| 28 | + short *r, *g, *b; |
| 29 | + int x, y; |
| 30 | + char *ProgName = argv[0]; |
| 31 | + |
| 32 | + debug = FALSE; |
| 33 | + ci.format = SV_RGB32_FRAMES; |
| 34 | + ci.width = 0; |
| 35 | + ci.height = 0; |
| 36 | + ci.size = 1; |
| 37 | + |
| 38 | + argv++; argc--; |
| 39 | + if ( argc > 2 && strcmp(argv[0], "-w") == 0) { |
| 40 | + ci.width = atoi(argv[1]); |
| 41 | + argc -= 2; |
| 42 | + argv += 2; |
| 43 | + } |
| 44 | + if ( argc != 1 ) { |
| 45 | + fprintf(stderr, "Usage: %s [-w width] rgbfilename\n", ProgName); |
| 46 | + exit(1); |
| 47 | + } |
| 48 | + |
| 49 | + /* Open video device */ |
| 50 | + if ((V = svOpenVideo()) == NULL) { |
| 51 | + svPerror("open"); |
| 52 | + exit(1); |
| 53 | + } |
| 54 | + |
| 55 | + if (svQueryCaptureBufferSize(V, &ci, &bufferSize) < 0) { |
| 56 | + svPerror("svQueryCaptureBufferSize"); |
| 57 | + exit(1); |
| 58 | + } |
| 59 | + buffer = malloc(bufferSize); |
| 60 | + |
| 61 | + if (svCaptureOneFrame(V, ci.format, &ci.width, &ci.height, buffer) < 0) { |
| 62 | + svPerror("svCaptureOneFrame"); |
| 63 | + exit(1); |
| 64 | + } |
| 65 | + if (debug) { |
| 66 | + printf("captured size: %d by %d\n", ci.width, ci.height); |
| 67 | + } |
| 68 | + |
| 69 | + if ( (imgfile=iopen(argv[0], "w", RLE(1), 3, ci.width, ci.height, 3)) == 0) { |
| 70 | + perror(argv[1]); |
| 71 | + exit(1); |
| 72 | + } |
| 73 | + r = (short *)malloc(ci.width*sizeof(short)); |
| 74 | + g = (short *)malloc(ci.width*sizeof(short)); |
| 75 | + b = (short *)malloc(ci.width*sizeof(short)); |
| 76 | + if ( !r || !g || !b ) { |
| 77 | + fprintf(stderr, "%s: malloc failed\n", ProgName); |
| 78 | + exit(1); |
| 79 | + } |
| 80 | + for(y=0; y<ci.height; y++) { |
| 81 | + for(x=0; x<ci.width; x++) { |
| 82 | + unsigned long data = *buffer++; |
| 83 | + |
| 84 | + r[x] = data & 0xff; |
| 85 | + g[x] = (data>>8) & 0xff; |
| 86 | + b[x] = (data>>16) & 0xff; |
| 87 | + } |
| 88 | + if ( putrow(imgfile, r, y, 0) == 0 || |
| 89 | + putrow(imgfile, g, y, 1) == 0 || |
| 90 | + putrow(imgfile, b, y, 2) == 0) { |
| 91 | + fprintf(stderr, "%s: putrow failed\n", ProgName); |
| 92 | + exit(1); |
| 93 | + } |
| 94 | + } |
| 95 | + iclose(imgfile); |
| 96 | + exit(0); |
| 97 | +} |
0 commit comments