Class around PixMap objects that allows more python-like access. By Joe Strout.
[python/dscho.git] / Demo / sgi / video / svgrab24.c
blob3418b145da512df6bf42f8996192175b313c022e
1 /*
2 * svgrab24 - Grab the current video input image into an rgb file.
4 * Jack Jansen, CWI, May 93.
6 * Adapted from grabone.c
7 */
9 #ident "$Revision$"
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>
19 main(int argc, char *argv[])
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];
32 debug = FALSE;
33 ci.format = SV_RGB32_FRAMES;
34 ci.width = 0;
35 ci.height = 0;
36 ci.size = 1;
38 argv++; argc--;
39 if ( argc > 2 && strcmp(argv[0], "-w") == 0) {
40 ci.width = atoi(argv[1]);
41 argc -= 2;
42 argv += 2;
44 if ( argc != 1 ) {
45 fprintf(stderr, "Usage: %s [-w width] rgbfilename\n", ProgName);
46 exit(1);
49 /* Open video device */
50 if ((V = svOpenVideo()) == NULL) {
51 svPerror("open");
52 exit(1);
55 if (svQueryCaptureBufferSize(V, &ci, &bufferSize) < 0) {
56 svPerror("svQueryCaptureBufferSize");
57 exit(1);
59 buffer = malloc(bufferSize);
61 if (svCaptureOneFrame(V, ci.format, &ci.width, &ci.height, buffer) < 0) {
62 svPerror("svCaptureOneFrame");
63 exit(1);
65 if (debug) {
66 printf("captured size: %d by %d\n", ci.width, ci.height);
69 if ( (imgfile=iopen(argv[0], "w", RLE(1), 3, ci.width, ci.height, 3)) == 0) {
70 perror(argv[1]);
71 exit(1);
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);
80 for(y=0; y<ci.height; y++) {
81 for(x=0; x<ci.width; x++) {
82 unsigned long data = *buffer++;
84 r[x] = data & 0xff;
85 g[x] = (data>>8) & 0xff;
86 b[x] = (data>>16) & 0xff;
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);
95 iclose(imgfile);
96 exit(0);