2 * svgrab24 - Grab the current video input image into an rgb file.
4 * Jack Jansen, CWI, May 93.
6 * Adapted from grabone.c
15 #include <gl/device.h>
19 main(int argc
, char *argv
[])
30 char *ProgName
= argv
[0];
33 ci
.format
= SV_RGB32_FRAMES
;
39 if ( argc
> 2 && strcmp(argv
[0], "-w") == 0) {
40 ci
.width
= atoi(argv
[1]);
45 fprintf(stderr
, "Usage: %s [-w width] rgbfilename\n", ProgName
);
49 /* Open video device */
50 if ((V
= svOpenVideo()) == NULL
) {
55 if (svQueryCaptureBufferSize(V
, &ci
, &bufferSize
) < 0) {
56 svPerror("svQueryCaptureBufferSize");
59 buffer
= malloc(bufferSize
);
61 if (svCaptureOneFrame(V
, ci
.format
, &ci
.width
, &ci
.height
, buffer
) < 0) {
62 svPerror("svCaptureOneFrame");
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) {
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
);
80 for(y
=0; y
<ci
.height
; y
++) {
81 for(x
=0; x
<ci
.width
; x
++) {
82 unsigned long data
= *buffer
++;
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
);