aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/video4linux/CQcam.txt
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/CQcam.txt
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/CQcam.txt')
-rw-r--r--Documentation/video4linux/CQcam.txt203
1 files changed, 3 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