1 /* capture a PPM image using YUV packed format and single capture mode */
2 /* Copyright (c) 1995 Mark Tinguely and Jim Lowe
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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/types.h>
34 #include <sys/fcntl.h>
35 /*#include <machine/ioctl_meteor.h>*/
36 #include "/sys/i386/include/ioctl_meteor.h"
38 typedef unsigned char uint8
;
39 typedef signed char int8
;
41 static int8
*yuv_data
;
45 #define SIZE (ROWS * COLS * 2)
48 struct meteor_geomet geo
;
49 char b
[4],header
[16],*p
;
53 if ((i
= open("/dev/meteor", O_RDONLY
)) < 0) {
54 printf("open failed: %d\n", errno
);
57 /* set up the capture type and size */
63 geo
.oformat
= METEOR_GEO_YUV_PACKED
;
65 if (ioctl(i
, METEORSETGEO
, &geo
) < 0) {
66 printf("ioctl failed: %d\n", errno
);
72 if (ioctl(i
, METEORSFMT
, &c
) < 0) {
73 printf("ioctl failed: %d\n", errno
);
77 c
= METEOR_INPUT_DEV0
;
79 if (ioctl(i
, METEORSINPUT
, &c
) < 0) {
80 printf("ioctl failed: %d\n", errno
);
84 yuv_data
= (uint8
*)mmap((caddr_t
)0,SIZE
,PROT_READ
,MAP_SHARED
, i
, (off_t
)0);
86 if (yuv_data
== (int8
*) MAP_FAILED
) return (0);
88 c
= METEOR_CAP_SINGLE
;
89 ioctl(i
, METEORCAPTUR
, &c
);
91 if ((o
= open("yuvpk.ppm", O_WRONLY
| O_CREAT
, 0644)) < 0) {
92 printf("ppm open failed: %d\n", errno
);
96 /* make PPM header and save to file */
97 strcpy(&header
[0], "P6 640 480 255 ");
98 header
[2] = header
[6] = header
[10] = header
[14] = '\n';
99 write (o
, &header
[0], 15);
101 for (c
= 0 ; c
< ROWS
*COLS
; c
+=2) {
103 if ((y1
= *yuv_data
++) < 0) y1
+= 256;
105 if ((y2
= *yuv_data
++) < 0) y2
+= 256;
107 b
[0]= (double)y1
+ 1.375 * (double)v
; /*r*/
108 b
[1]= (double)y1
- 0.703125 * (double)v
-0.34375 * (double)u
; /* g */
109 b
[2]= (double)y1
+ 1.734375 * (double)u
; /* b */
110 b
[3]= (double)y2
+ 1.375 * (double)v
; /*r*/
111 b
[4]= (double)y2
- 0.703125 * (double)v
-0.34375 * (double)u
; /* g */
112 b
[5]= (double)y2
+ 1.734375 * (double)u
; /* b */