aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/video4linux
diff options
context:
space:
mode:
authorRandy Dunlap <rdunlap@xenotime.net>2006-05-26 09:32:13 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2006-06-25 01:05:00 -0400
commita22f1cbc2d3acd99986e96092109f6ced0f0022e (patch)
tree8a01d0bd98db15858499548f5cf5e9c14c50215e /Documentation/video4linux
parentc003d467bd71a7da22554e0d812a646ab58abea5 (diff)
V4L/DVB (4047): Doc. sources: expose video4linux/
Documentation/video4linux/: Expose example and tool source files in the Documentation/ directory in their own files instead of being buried (almost hidden) in readme/txt files. This will make them more visible/usable to users who may need to use them, to developers who may need to test with them, and to janitors who would update them if they were more visible. Also, if any of these possibly should not be in the kernel tree at all, it will be clearer that they are here and we can discuss if they should be removed. Signed-off-by: Randy Dunlap <rdunlap@xenotime.net> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'Documentation/video4linux')
-rw-r--r--Documentation/video4linux/CQcam.txt203
-rw-r--r--Documentation/video4linux/v4lgrab.c192
2 files changed, 195 insertions, 200 deletions
diff --git a/Documentation/video4linux/CQcam.txt b/Documentation/video4linux/CQcam.txt
index 464e4cec94cb..ade8651e2443 100644
--- a/Documentation/video4linux/CQcam.txt
+++ b/Documentation/video4linux/CQcam.txt
@@ -185,207 +185,10 @@ this work is documented at the video4linux2 site listed below.
185 185
1869.0 --- A sample program using v4lgrabber, 1869.0 --- A sample program using v4lgrabber,
187 187
188This program is a simple image grabber that will copy a frame from the 188v4lgrab is a simple image grabber that will copy a frame from the
189first video device, /dev/video0 to standard output in portable pixmap 189first video device, /dev/video0 to standard output in portable pixmap
190format (.ppm) Using this like: 'v4lgrab | convert - c-qcam.jpg' 190format (.ppm) To produce .jpg output, you can use it like this:
191produced this picture of me at 191'v4lgrab | convert - c-qcam.jpg'
192 http://mug.sys.virginia.edu/~drf5n/extras/c-qcam.jpg
193
194-------------------- 8< ---------------- 8< -----------------------------
195
196/* Simple Video4Linux image grabber. */
197/*
198 * Video4Linux Driver Test/Example Framegrabbing Program
199 *
200 * Compile with:
201 * gcc -s -Wall -Wstrict-prototypes v4lgrab.c -o v4lgrab
202 * Use as:
203 * v4lgrab >image.ppm
204 *
205 * Copyright (C) 1998-05-03, Phil Blundell <philb@gnu.org>
206 * Copied from http://www.tazenda.demon.co.uk/phil/vgrabber.c
207 * with minor modifications (Dave Forrest, drf5n@virginia.edu).
208 *
209 */
210
211#include <unistd.h>
212#include <sys/types.h>
213#include <sys/stat.h>
214#include <fcntl.h>
215#include <stdio.h>
216#include <sys/ioctl.h>
217#include <stdlib.h>
218
219#include <linux/types.h>
220#include <linux/videodev.h>
221
222#define FILE "/dev/video0"
223
224/* Stole this from tvset.c */
225
226#define READ_VIDEO_PIXEL(buf, format, depth, r, g, b) \
227{ \
228 switch (format) \
229 { \
230 case VIDEO_PALETTE_GREY: \
231 switch (depth) \
232 { \
233 case 4: \
234 case 6: \
235 case 8: \
236 (r) = (g) = (b) = (*buf++ << 8);\
237 break; \
238 \
239 case 16: \
240 (r) = (g) = (b) = \
241 *((unsigned short *) buf); \
242 buf += 2; \
243 break; \
244 } \
245 break; \
246 \
247 \
248 case VIDEO_PALETTE_RGB565: \
249 { \
250 unsigned short tmp = *(unsigned short *)buf; \
251 (r) = tmp&0xF800; \
252 (g) = (tmp<<5)&0xFC00; \
253 (b) = (tmp<<11)&0xF800; \
254 buf += 2; \
255 } \
256 break; \
257 \
258 case VIDEO_PALETTE_RGB555: \
259 (r) = (buf[0]&0xF8)<<8; \
260 (g) = ((buf[0] << 5 | buf[1] >> 3)&0xF8)<<8; \
261 (b) = ((buf[1] << 2 ) & 0xF8)<<8; \
262 buf += 2; \
263 break; \
264 \
265 case VIDEO_PALETTE_RGB24: \
266 (r) = buf[0] << 8; (g) = buf[1] << 8; \
267 (b) = buf[2] << 8; \
268 buf += 3; \
269 break; \
270 \
271 default: \
272 fprintf(stderr, \
273 "Format %d not yet supported\n", \
274 format); \
275 } \
276}
277
278int get_brightness_adj(unsigned char *image, long size, int *brightness) {
279 long i, tot = 0;
280 for (i=0;i<size*3;i++)
281 tot += image[i];
282 *brightness = (128 - tot/(size*3))/3;
283 return !((tot/(size*3)) >= 126 && (tot/(size*3)) <= 130);
284}
285
286int main(int argc, char ** argv)
287{
288 int fd = open(FILE, O_RDONLY), f;
289 struct video_capability cap;
290 struct video_window win;
291 struct video_picture vpic;
292
293 unsigned char *buffer, *src;
294 int bpp = 24, r, g, b;
295 unsigned int i, src_depth;
296
297 if (fd < 0) {
298 perror(FILE);
299 exit(1);
300 }
301
302 if (ioctl(fd, VIDIOCGCAP, &cap) < 0) {
303 perror("VIDIOGCAP");
304 fprintf(stderr, "(" FILE " not a video4linux device?)\n");
305 close(fd);
306 exit(1);
307 }
308
309 if (ioctl(fd, VIDIOCGWIN, &win) < 0) {
310 perror("VIDIOCGWIN");
311 close(fd);
312 exit(1);
313 }
314
315 if (ioctl(fd, VIDIOCGPICT, &vpic) < 0) {
316 perror("VIDIOCGPICT");
317 close(fd);
318 exit(1);
319 }
320
321 if (cap.type & VID_TYPE_MONOCHROME) {
322 vpic.depth=8;
323 vpic.palette=VIDEO_PALETTE_GREY; /* 8bit grey */
324 if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
325 vpic.depth=6;
326 if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
327 vpic.depth=4;
328 if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
329 fprintf(stderr, "Unable to find a supported capture format.\n");
330 close(fd);
331 exit(1);
332 }
333 }
334 }
335 } else {
336 vpic.depth=24;
337 vpic.palette=VIDEO_PALETTE_RGB24;
338
339 if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
340 vpic.palette=VIDEO_PALETTE_RGB565;
341 vpic.depth=16;
342
343 if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) {
344 vpic.palette=VIDEO_PALETTE_RGB555;
345 vpic.depth=15;
346
347 if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) {
348 fprintf(stderr, "Unable to find a supported capture format.\n");
349 return -1;
350 }
351 }
352 }
353 }
354
355 buffer = malloc(win.width * win.height * bpp);
356 if (!buffer) {
357 fprintf(stderr, "Out of memory.\n");
358 exit(1);
359 }
360
361 do {
362 int newbright;
363 read(fd, buffer, win.width * win.height * bpp);
364 f = get_brightness_adj(buffer, win.width * win.height, &newbright);
365 if (f) {
366 vpic.brightness += (newbright << 8);
367 if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) {
368 perror("VIDIOSPICT");
369 break;
370 }
371 }
372 } while (f);
373
374 fprintf(stdout, "P6\n%d %d 255\n", win.width, win.height);
375
376 src = buffer;
377
378 for (i = 0; i < win.width * win.height; i++) {
379 READ_VIDEO_PIXEL(src, vpic.palette, src_depth, r, g, b);
380 fputc(r>>8, stdout);
381 fputc(g>>8, stdout);
382 fputc(b>>8, stdout);
383 }
384
385 close(fd);
386 return 0;
387}
388-------------------- 8< ---------------- 8< -----------------------------
389 192
390 193
39110.0 --- Other Information 19410.0 --- Other Information
diff --git a/Documentation/video4linux/v4lgrab.c b/Documentation/video4linux/v4lgrab.c
new file mode 100644
index 000000000000..079b628481cf
--- /dev/null
+++ b/Documentation/video4linux/v4lgrab.c
@@ -0,0 +1,192 @@
1/* Simple Video4Linux image grabber. */
2/*
3 * Video4Linux Driver Test/Example Framegrabbing Program
4 *
5 * Compile with:
6 * gcc -s -Wall -Wstrict-prototypes v4lgrab.c -o v4lgrab
7 * Use as:
8 * v4lgrab >image.ppm
9 *
10 * Copyright (C) 1998-05-03, Phil Blundell <philb@gnu.org>
11 * Copied from http://www.tazenda.demon.co.uk/phil/vgrabber.c
12 * with minor modifications (Dave Forrest, drf5n@virginia.edu).
13 *
14 */
15
16#include <unistd.h>
17#include <sys/types.h>
18#include <sys/stat.h>
19#include <fcntl.h>
20#include <stdio.h>
21#include <sys/ioctl.h>
22#include <stdlib.h>
23
24#include <linux/types.h>
25#include <linux/videodev.h>
26
27#define FILE "/dev/video0"
28
29/* Stole this from tvset.c */
30
31#define READ_VIDEO_PIXEL(buf, format, depth, r, g, b) \
32{ \
33 switch (format) \
34 { \
35 case VIDEO_PALETTE_GREY: \
36 switch (depth) \
37 { \
38 case 4: \
39 case 6: \
40 case 8: \
41 (r) = (g) = (b) = (*buf++ << 8);\
42 break; \
43 \
44 case 16: \
45 (r) = (g) = (b) = \
46 *((unsigned short *) buf); \
47 buf += 2; \
48 break; \
49 } \
50 break; \
51 \
52 \
53 case VIDEO_PALETTE_RGB565: \
54 { \
55 unsigned short tmp = *(unsigned short *)buf; \
56 (r) = tmp&0xF800; \
57 (g) = (tmp<<5)&0xFC00; \
58 (b) = (tmp<<11)&0xF800; \
59 buf += 2; \
60 } \
61 break; \
62 \
63 case VIDEO_PALETTE_RGB555: \
64 (r) = (buf[0]&0xF8)<<8; \
65 (g) = ((buf[0] << 5 | buf[1] >> 3)&0xF8)<<8; \
66 (b) = ((buf[1] << 2 ) & 0xF8)<<8; \
67 buf += 2; \
68 break; \
69 \
70 case VIDEO_PALETTE_RGB24: \
71 (r) = buf[0] << 8; (g) = buf[1] << 8; \
72 (b) = buf[2] << 8; \
73 buf += 3; \
74 break; \
75 \
76 default: \
77 fprintf(stderr, \
78 "Format %d not yet supported\n", \
79 format); \
80 } \
81}
82
83int get_brightness_adj(unsigned char *image, long size, int *brightness) {
84 long i, tot = 0;
85 for (i=0;i<size*3;i++)
86 tot += image[i];
87 *brightness = (128 - tot/(size*3))/3;
88 return !((tot/(size*3)) >= 126 && (tot/(size*3)) <= 130);
89}
90
91int main(int argc, char ** argv)
92{
93 int fd = open(FILE, O_RDONLY), f;
94 struct video_capability cap;
95 struct video_window win;
96 struct video_picture vpic;
97
98 unsigned char *buffer, *src;
99 int bpp = 24, r, g, b;
100 unsigned int i, src_depth;
101
102 if (fd < 0) {
103 perror(FILE);
104 exit(1);
105 }
106
107 if (ioctl(fd, VIDIOCGCAP, &cap) < 0) {
108 perror("VIDIOGCAP");
109 fprintf(stderr, "(" FILE " not a video4linux device?)\n");
110 close(fd);
111 exit(1);
112 }
113
114 if (ioctl(fd, VIDIOCGWIN, &win) < 0) {
115 perror("VIDIOCGWIN");
116 close(fd);
117 exit(1);
118 }
119
120 if (ioctl(fd, VIDIOCGPICT, &vpic) < 0) {
121 perror("VIDIOCGPICT");
122 close(fd);
123 exit(1);
124 }
125
126 if (cap.type & VID_TYPE_MONOCHROME) {
127 vpic.depth=8;
128 vpic.palette=VIDEO_PALETTE_GREY; /* 8bit grey */
129 if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
130 vpic.depth=6;
131 if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
132 vpic.depth=4;
133 if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
134 fprintf(stderr, "Unable to find a supported capture format.\n");
135 close(fd);
136 exit(1);
137 }
138 }
139 }
140 } else {
141 vpic.depth=24;
142 vpic.palette=VIDEO_PALETTE_RGB24;
143
144 if(ioctl(fd, VIDIOCSPICT, &vpic) < 0) {
145 vpic.palette=VIDEO_PALETTE_RGB565;
146 vpic.depth=16;
147
148 if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) {
149 vpic.palette=VIDEO_PALETTE_RGB555;
150 vpic.depth=15;
151
152 if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) {
153 fprintf(stderr, "Unable to find a supported capture format.\n");
154 return -1;
155 }
156 }
157 }
158 }
159
160 buffer = malloc(win.width * win.height * bpp);
161 if (!buffer) {
162 fprintf(stderr, "Out of memory.\n");
163 exit(1);
164 }
165
166 do {
167 int newbright;
168 read(fd, buffer, win.width * win.height * bpp);
169 f = get_brightness_adj(buffer, win.width * win.height, &newbright);
170 if (f) {
171 vpic.brightness += (newbright << 8);
172 if(ioctl(fd, VIDIOCSPICT, &vpic)==-1) {
173 perror("VIDIOSPICT");
174 break;
175 }
176 }
177 } while (f);
178
179 fprintf(stdout, "P6\n%d %d 255\n", win.width, win.height);
180
181 src = buffer;
182
183 for (i = 0; i < win.width * win.height; i++) {
184 READ_VIDEO_PIXEL(src, vpic.palette, src_depth, r, g, b);
185 fputc(r>>8, stdout);
186 fputc(g>>8, stdout);
187 fputc(b>>8, stdout);
188 }
189
190 close(fd);
191 return 0;
192}