Rev 1170 | Rev 1174 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1173 | giacomo | 1 | /* |
2 | * Project: S.Ha.R.K. |
||
3 | * |
||
4 | * Coordinators: |
||
5 | * Giorgio Buttazzo <giorgio@sssup.it> |
||
6 | * Paolo Gai <pj@gandalf.sssup.it> |
||
7 | * |
||
8 | * Authors : |
||
9 | * Giacomo Guidi <giacomo@gandalf.sssup.it> |
||
10 | * |
||
11 | * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy) |
||
12 | * |
||
13 | * http://www.sssup.it |
||
14 | * http://retis.sssup.it |
||
15 | * http://shark.sssup.it |
||
16 | */ |
||
17 | |||
18 | /* |
||
19 | * Copyright (C) 2003 Giacomo Guidi |
||
20 | * |
||
21 | * This program is free software; you can redistribute it and/or modify |
||
22 | * it under the terms of the GNU General Public License as published by |
||
23 | * the Free Software Foundation; either version 2 of the License, or |
||
24 | * (at your option) any later version. |
||
25 | * |
||
26 | * This program is distributed in the hope that it will be useful, |
||
27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
29 | * GNU General Public License for more details. |
||
30 | * |
||
31 | * You should have received a copy of the GNU General Public License |
||
32 | * along with this program; if not, write to the Free Software |
||
33 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
34 | */ |
||
35 | |||
36 | #include "kernel/kern.h" |
||
37 | #include <drivers/fg.h> |
||
38 | #include <drivers/vga.h> |
||
39 | #include <drivers/keyb.h> |
||
40 | #include <unistd.h> |
||
41 | #include <stdlib.h> |
||
42 | |||
43 | #define WIDTH 640 |
||
44 | #define HEIGHT 480 |
||
45 | #define BYTES_PP 2 |
||
46 | #define INITSTR G640x480x64K //SVGAlib standard mode definitions |
||
47 | #define CARD VESA //Video driver |
||
48 | |||
49 | unsigned char *video_buf = NULL; //Video Buffer |
||
50 | unsigned long int VMEMLONG = WIDTH * HEIGHT * BYTES_PP / 4; // Used by copy_videomem_16to16 |
||
51 | unsigned long int RGB565MEM = WIDTH * HEIGHT * BYTES_PP; // Total video mem |
||
52 | |||
53 | #define FG_PERIOD 40000 |
||
54 | #define FG_WCET 30000 |
||
55 | #define FG_W 320 |
||
56 | #define FG_H 200 |
||
57 | |||
58 | unsigned int color = FG_MONO; |
||
59 | |||
60 | static int screen(int mode) |
||
61 | { |
||
62 | |||
63 | vga_modeinfo *minf; |
||
64 | |||
65 | vga_setmode(mode,CARD); |
||
66 | minf = vga_getmodeinfo(mode); |
||
67 | if(! (minf->flags & CAPABLE_LINEAR)){ |
||
68 | vga_setmode(TEXT,CARD); |
||
69 | printk(KERN_INFO "The mode %d is not capable of linear\n",mode); |
||
70 | return 1; |
||
71 | } |
||
72 | vga_setpage(0); |
||
73 | if(vga_setlinearaddressing() == -1) { |
||
74 | vga_setmode(TEXT,CARD); |
||
75 | printk(KERN_INFO "Could not set linear addressing for mode %d\n",mode); |
||
76 | return 1; |
||
77 | } |
||
78 | |||
79 | video_buf = vga_getgraphmem(); |
||
80 | |||
81 | memset(video_buf, 0, RGB565MEM); |
||
82 | |||
83 | grx_setbuffer(video_buf, WIDTH, HEIGHT); //Init of RGBA version of grx functions |
||
84 | //created to work with Mesa buffer |
||
85 | return 0; |
||
86 | |||
87 | } |
||
88 | |||
89 | void program_end(void *arg) |
||
90 | { |
||
91 | |||
92 | FG_close(); |
||
93 | |||
94 | vga_setmode(TEXT,CARD); |
||
95 | |||
96 | sys_end(); |
||
97 | |||
98 | } |
||
99 | |||
100 | void program_key_end(KEY_EVT *k) |
||
101 | { |
||
102 | |||
103 | sys_end(); |
||
104 | |||
105 | } |
||
106 | |||
107 | void elaborate_image(void *imageptr) |
||
108 | { |
||
109 | |||
110 | WORD x,y; |
||
111 | BYTE *col; |
||
112 | |||
113 | if (color == FG_MONO) { |
||
114 | |||
115 | for(y = 0; y < FG_H; y++) |
||
116 | for(x = 0; x < FG_W; x++) { |
||
117 | |||
118 | col = (BYTE *)(imageptr + y*FG_W + x); |
||
119 | *(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col),*(BYTE *)(col)); |
||
120 | |||
121 | } |
||
122 | |||
123 | } |
||
124 | |||
125 | if (color == FG_RGB24) { |
||
126 | |||
127 | for(y = 0; y < FG_H; y++) |
||
128 | for(x = 0; x < FG_W; x++) { |
||
129 | |||
130 | col = (BYTE *)(imageptr + y*(FG_W*3) + (x*3)); |
||
131 | *(WORD *)(video_buf + y*(WIDTH*2) + (x*2)) = (WORD)rgb16(*(BYTE *)(col),*(BYTE *)(col+1),*(BYTE *)(col+2)); |
||
132 | |||
133 | } |
||
134 | |||
135 | } |
||
136 | |||
137 | printf_xy(0,0,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 50*FG_W + 50)); |
||
138 | printf_xy(0,1,WHITE,"Grabbed = %08lx",*(DWORD *)(imageptr + 51*FG_W + 50)); |
||
139 | |||
140 | } |
||
141 | |||
142 | int main(int argc, char **argv) |
||
143 | { |
||
144 | |||
145 | int channel = 0; |
||
146 | |||
147 | if (argc < 2) { |
||
148 | channel = 0; |
||
149 | } else { |
||
150 | channel = atoi(argv[1]); |
||
151 | } |
||
152 | |||
153 | sys_atrunlevel(program_end,NULL, RUNLEVEL_BEFORE_EXIT); |
||
154 | |||
155 | { |
||
156 | KEY_EVT k; |
||
157 | k.flag = ALTL_BIT; |
||
158 | k.scan = KEY_C; |
||
159 | k.ascii = 'c'; |
||
160 | keyb_hook(k,program_key_end); |
||
161 | } |
||
162 | |||
163 | //screen(INITSTR); |
||
164 | video_buf = malloc(RGB565MEM); |
||
165 | |||
166 | sleep(1); |
||
167 | |||
168 | FG_init(FG_PERIOD, FG_WCET, FG_W, FG_H, color, channel); |
||
169 | |||
170 | FG_set_hook(elaborate_image); |
||
171 | |||
172 | FG_start_grabbing(); |
||
173 | |||
174 | return 0; |
||
175 | |||
176 | } |