Add a wlan_ratectl(4) manual page and reference it from drivers that support
[dragonfly/vkernel-mp.git] / share / examples / meteor / rgb24.c
blobf2969022bb8741d7728e92ad93268817fcf143ac
1 /* capture a PPM file using 24 bit RGB image and read() */
2 /* Copyright (c) 1995 Mark Tinguely and Jim Lowe
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Mark Tinguely and Jim Lowe
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/fcntl.h>
33 /*#include <machine/ioctl_meteor.h>*/
34 #include "/sys/i386/include/ioctl_meteor.h"
36 extern int errno;
37 #define ROWS 300
38 #define COLS 400
39 #define SIZE (ROWS * COLS * 4)
40 main()
42 struct meteor_geomet geo;
43 char buf[SIZE],b[4],header[16],*p;
44 int i,o,c;
46 if ((i = open("/dev/meteor", O_RDONLY)) < 0) {
47 printf("open failed: %d\n", errno);
48 exit(1);
50 /* set up the capture type and size */
51 geo.rows = ROWS;
52 geo.columns = COLS;
53 geo.frames = 1;
54 geo.oformat = METEOR_GEO_RGB24 ;
56 if (ioctl(i, METEORSETGEO, &geo) < 0) {
57 printf("ioctl failed: %d\n", errno);
58 exit(1);
61 c = METEOR_FMT_NTSC;
63 if (ioctl(i, METEORSFMT, &c) < 0) {
64 printf("ioctl failed: %d\n", errno);
65 exit(1);
68 c = METEOR_INPUT_DEV0;
70 if (ioctl(i, METEORSINPUT, &c) < 0) {
71 printf("ioctl failed: %d\n", errno);
72 exit(1);
75 if ((c=read(i, &buf[0], SIZE)) < SIZE) {
76 printf("read failed %d %d %d\n", c, i, errno);
77 close(i);
78 exit(1);
80 close(i);
82 if ((o = open("rgb24.ppm", O_WRONLY | O_CREAT, 0644)) < 0) {
83 printf("ppm open failed: %d\n", errno);
84 exit(1);
87 /* make PPM header and save to file */
88 strcpy(&header[0], "P6 400 300 255 ");
89 header[2] = header[6] = header[10] = header[14] = '\n';
90 write (o, &header[0], 15);
91 /* save the RGB data to PPM file */
92 for (p = &buf[0]; p < &buf[SIZE]; ) {
93 b[2] = *p++; /* blue */
94 b[1] = *p++; /* green */
95 b[0] = *p++; /* red */
96 *p++; /* NULL byte */
97 write(o,&b[0], 3); /* not very efficient */
99 close(o);
100 exit(0);