1
|
1
|
|
2 // mga_vid drawing functions
|
|
3
|
56
|
4 static int mga_next_frame=0;
|
|
5
|
|
6 static mga_vid_config_t mga_vid_config;
|
|
7 static uint8_t *vid_data, *frames[4];
|
|
8 static int f;
|
|
9
|
47
|
10
|
1
|
11 static void
|
|
12 write_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb)
|
|
13 {
|
|
14 uint8_t *dest;
|
|
15 uint32_t bespitch,h,w;
|
|
16
|
|
17 dest = vid_data;
|
|
18 bespitch = (mga_vid_config.src_width + 31) & ~31;
|
|
19
|
|
20 for(h=0; h < mga_vid_config.src_height; h++)
|
|
21 {
|
|
22 memcpy(dest, y, mga_vid_config.src_width);
|
|
23 y += mga_vid_config.src_width;
|
|
24 dest += bespitch;
|
|
25 }
|
|
26
|
|
27 for(h=0; h < mga_vid_config.src_height/2; h++)
|
|
28 {
|
|
29 for(w=0; w < mga_vid_config.src_width/2; w++)
|
|
30 {
|
|
31 *dest++ = *cb++;
|
|
32 *dest++ = *cr++;
|
|
33 }
|
|
34 dest += bespitch - mga_vid_config.src_width;
|
|
35 }
|
|
36 }
|
|
37
|
|
38 static void
|
|
39 write_frame_g400(uint8_t *y,uint8_t *cr, uint8_t *cb)
|
|
40 {
|
|
41 uint8_t *dest;
|
|
42 uint32_t bespitch,h;
|
|
43
|
|
44 dest = vid_data;
|
|
45 bespitch = (mga_vid_config.src_width + 31) & ~31;
|
|
46
|
|
47 for(h=0; h < mga_vid_config.src_height; h++)
|
|
48 {
|
|
49 memcpy(dest, y, mga_vid_config.src_width);
|
|
50 y += mga_vid_config.src_width;
|
|
51 dest += bespitch;
|
|
52 }
|
|
53
|
|
54 for(h=0; h < mga_vid_config.src_height/2; h++)
|
|
55 {
|
|
56 memcpy(dest, cb, mga_vid_config.src_width/2);
|
|
57 cb += mga_vid_config.src_width/2;
|
|
58 dest += bespitch/2;
|
|
59 }
|
|
60
|
|
61 for(h=0; h < mga_vid_config.src_height/2; h++)
|
|
62 {
|
|
63 memcpy(dest, cr, mga_vid_config.src_width/2);
|
|
64 cr += mga_vid_config.src_width/2;
|
|
65 dest += bespitch/2;
|
|
66 }
|
|
67 }
|
|
68
|
|
69 //static void
|
|
70 //write_slice_g200(uint8_t *y,uint8_t *cr, uint8_t *cb,uint32_t slice_num)
|
|
71
|
|
72 static void
|
|
73 draw_slice_g200(uint8_t *image[], int stride[], int width,int height,int x,int y)
|
|
74 {
|
|
75 uint8_t *src;
|
|
76 uint8_t *src2;
|
|
77 uint8_t *dest;
|
|
78 uint32_t bespitch,h,w;
|
|
79
|
|
80 bespitch = (mga_vid_config.src_width + 31) & ~31;
|
|
81
|
|
82 dest = vid_data + bespitch * y * x;
|
|
83 src = image[0];
|
|
84 for(h=0; h < height; h++)
|
|
85 {
|
|
86 memcpy(dest, src, width);
|
|
87 src += stride[0];
|
|
88 dest += bespitch;
|
|
89 }
|
|
90
|
|
91 width/=2;height/=2;x/=2;y/=2;
|
|
92
|
|
93 dest = vid_data + bespitch * mga_vid_config.src_height +
|
|
94 bespitch * y + 2*x;
|
|
95 src = image[1];
|
|
96 src2 = image[2];
|
|
97 for(h=0; h < height; h++)
|
|
98 {
|
|
99 for(w=0; w < width; w++)
|
|
100 {
|
|
101 dest[2*w+0] = src[w];
|
|
102 dest[2*w+1] = src2[w];
|
|
103 }
|
|
104 dest += bespitch;
|
|
105 src += stride[1];
|
|
106 src2+= stride[2];
|
|
107 }
|
|
108 }
|
|
109
|
|
110 static void
|
|
111 draw_slice_g400(uint8_t *image[], int stride[], int w,int h,int x,int y)
|
|
112 {
|
|
113 uint8_t *src;
|
|
114 uint8_t *dest;
|
|
115 uint32_t bespitch,bespitch2;
|
|
116 int i;
|
|
117
|
|
118 bespitch = (mga_vid_config.src_width + 31) & ~31;
|
|
119 bespitch2 = bespitch/2;
|
|
120
|
|
121 dest = vid_data + bespitch * y + x;
|
|
122 src = image[0];
|
|
123 for(i=0;i<h;i++){
|
|
124 memcpy(dest,src,w);
|
|
125 src+=stride[0];
|
|
126 dest += bespitch;
|
|
127 }
|
|
128
|
|
129 w/=2;h/=2;x/=2;y/=2;
|
|
130
|
|
131 dest = vid_data + bespitch*mga_vid_config.src_height + bespitch2 * y + x;
|
|
132 src = image[1];
|
|
133 for(i=0;i<h;i++){
|
|
134 memcpy(dest,src,w);
|
|
135 src+=stride[1];
|
|
136 dest += bespitch2;
|
|
137 }
|
|
138
|
|
139 dest = vid_data + bespitch*mga_vid_config.src_height
|
|
140 + bespitch*mga_vid_config.src_height / 4
|
|
141 + bespitch2 * y + x;
|
|
142 src = image[2];
|
|
143 for(i=0;i<h;i++){
|
|
144 memcpy(dest,src,w);
|
|
145 src+=stride[2];
|
|
146 dest += bespitch2;
|
|
147 }
|
|
148
|
|
149 }
|
|
150
|
|
151 static uint32_t
|
|
152 draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y)
|
|
153 {
|
|
154 if (mga_vid_config.card_type == MGA_G200)
|
|
155 draw_slice_g200(src,stride,w,h,x,y);
|
|
156 else
|
|
157 draw_slice_g400(src,stride,w,h,x,y);
|
|
158 return 0;
|
|
159 }
|
|
160
|
|
161 static void
|
31
|
162 vo_mga_flip_page(void)
|
1
|
163 {
|
47
|
164
|
|
165 // printf("-- flip to %d --\n",mga_next_frame);
|
1
|
166
|
47
|
167 #if 1
|
|
168 ioctl(f,MGA_VID_FSEL,&mga_next_frame);
|
56
|
169 mga_next_frame=(mga_next_frame+1)%mga_vid_config.num_frames;
|
47
|
170 vid_data=frames[mga_next_frame];
|
|
171 #endif
|
1
|
172
|
|
173 }
|
|
174
|
|
175
|
|
176 static void
|
|
177 write_frame_yuy2(uint8_t *y)
|
|
178 {
|
|
179 uint8_t *dest;
|
|
180 uint32_t bespitch,h;
|
|
181 int len=2*mga_vid_config.src_width;
|
|
182
|
|
183 dest = vid_data;
|
|
184 bespitch = (mga_vid_config.src_width + 31) & ~31;
|
|
185
|
|
186 // y+=2*mga_vid_config.src_width*mga_vid_config.src_height;
|
|
187
|
|
188 for(h=0; h < mga_vid_config.src_height; h++)
|
|
189 {
|
|
190 // y -= 2*mga_vid_config.src_width;
|
|
191 memcpy(dest, y, len);
|
|
192 y += len;
|
|
193 dest += 2*bespitch;
|
|
194 }
|
|
195 }
|
|
196
|
|
197
|
|
198 static uint32_t
|
|
199 draw_frame(uint8_t *src[])
|
|
200 {
|
|
201 if (mga_vid_config.format==MGA_VID_FORMAT_YUY2)
|
|
202 write_frame_yuy2(src[0]);
|
|
203 else
|
|
204 if (mga_vid_config.card_type == MGA_G200)
|
|
205 write_frame_g200(src[0], src[2], src[1]);
|
|
206 else
|
|
207 write_frame_g400(src[0], src[2], src[1]);
|
|
208
|
|
209 //flip_page();
|
|
210 return 0;
|
|
211 }
|
|
212
|
|
213 static uint32_t
|
|
214 query_format(uint32_t format)
|
|
215 {
|
|
216 switch(format){
|
|
217 case IMGFMT_YV12:
|
|
218 case IMGFMT_YUY2:
|
|
219 // case IMGFMT_RGB|24:
|
|
220 // case IMGFMT_BGR|24:
|
|
221 return 1;
|
|
222 }
|
|
223 return 0;
|
|
224 }
|
|
225
|
56
|
226 static int mga_init(){
|
|
227 char *frame_mem;
|
|
228
|
|
229 mga_vid_config.num_frames=4;
|
|
230 mga_vid_config.version=MGA_VID_VERSION;
|
|
231 if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config))
|
|
232 {
|
|
233 perror("Error in mga_vid_config ioctl");
|
|
234 return -1;
|
|
235 }
|
|
236 ioctl(f,MGA_VID_ON,0);
|
|
237
|
|
238 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,f,0);
|
|
239 frames[1] = frames[0] + 1*mga_vid_config.frame_size;
|
|
240 frames[2] = frames[0] + 2*mga_vid_config.frame_size;
|
|
241 frames[3] = frames[0] + 3*mga_vid_config.frame_size;
|
|
242 mga_next_frame = 0;
|
|
243 vid_data = frames[mga_next_frame];
|
|
244
|
|
245 //clear the buffer
|
|
246 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames);
|
|
247
|
|
248 return 0;
|
|
249
|
|
250 }
|
|
251
|