Merge branch 'master' of /home/www-data/gitweb/dragonfly
[dragonfly.git] / share / examples / meteor / rgb16.c
blob4c7ee0703c699fb1aeef60d1f57a159131825743
1 /* capture a PPM image using RGB16 and single capture mode */
3 /* Copyright (c) 1995 Mark Tinguely and Jim Lowe
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Mark Tinguely and Jim Lowe
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
24 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/types.h>
33 #include <sys/mman.h>
34 #include <sys/fcntl.h>
35 /*#include <machine/ioctl_meteor.h>*/
36 #include "/sys/i386/include/ioctl_meteor.h"
38 extern int errno;
39 #define ROWS 480
40 #define COLS 640
41 #define SIZE (ROWS * COLS * 2)
42 main()
44 struct meteor_geomet geo;
45 short *rgb16;
46 char b[4];
47 char header[16];
48 int i,o,c;
50 if ((i = open("/dev/meteor", O_RDONLY)) < 0) {
51 printf("open failed: %d\n", errno);
52 exit(1);
54 /* set up the capture type and size */
55 geo.rows = ROWS;
56 geo.columns = COLS;
57 geo.frames = 1;
59 geo.oformat = METEOR_GEO_RGB16;
61 if (ioctl(i, METEORSETGEO, &geo) < 0) {
62 printf("ioctl failed: %d\n", errno);
63 exit(1);
66 c = METEOR_FMT_NTSC;
68 if (ioctl(i, METEORSFMT, &c) < 0) {
69 printf("ioctl failed: %d\n", errno);
70 exit(1);
73 c = METEOR_INPUT_DEV0;
75 if (ioctl(i, METEORSINPUT, &c) < 0) {
76 printf("ioctl failed: %d\n", errno);
77 exit(1);
80 rgb16 = (short *)mmap((caddr_t)0,SIZE,PROT_READ,MAP_SHARED, i, (off_t)0);
82 if (rgb16 == (short *) MAP_FAILED) return (0);
84 c = METEOR_CAP_SINGLE ;
85 ioctl(i, METEORCAPTUR, &c);
87 if ((o = open("rgb16.ppm", O_WRONLY | O_CREAT, 0644)) < 0) {
88 printf("ppm open failed: %d\n", errno);
89 exit(1);
92 /* make PPM header and save to file */
93 strcpy(&header[0], "P6 640 480 255 ");
94 header[2] = header[6] = header[10] = header[14] = '\n';
95 write (o, &header[0], 15);
97 for (c = 0 ; c < ROWS*COLS; c++) {
98 b[0]= ((*rgb16 >> 7) & 0xf8); /* r */
99 b[1]= ((*rgb16 >> 2) & 0xf8); /* g */
100 b[2]= ((*rgb16++ << 3) & 0xf8); /* b */
101 write(o, &b[0], 3);
103 close(o);
104 close(i);
105 exit(0);