Mercurial > mplayer.hg
annotate libvo/mga_common.c @ 5329:bf30f8d31e6a
reset selection
author | arpi |
---|---|
date | Mon, 25 Mar 2002 03:20:42 +0000 |
parents | 80fbb03b385a |
children | da218aa7f9db |
rev | line source |
---|---|
413 | 1 |
566 | 2 #include "fastmemcpy.h" |
2625 | 3 #include "../mmx_defs.h" |
4971 | 4 #include "../mp_image.h" |
1 | 5 |
6 // mga_vid drawing functions | |
7 | |
56 | 8 static int mga_next_frame=0; |
9 | |
10 static mga_vid_config_t mga_vid_config; | |
11 static uint8_t *vid_data, *frames[4]; | |
12 static int f; | |
13 | |
202 | 14 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ |
15 int x,y; | |
16 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; | |
466 | 17 switch(mga_vid_config.format){ |
18 case MGA_VID_FORMAT_YV12: | |
470 | 19 case MGA_VID_FORMAT_IYUV: |
20 case MGA_VID_FORMAT_I420: | |
326 | 21 vo_draw_alpha_yv12(w,h,src,srca,stride,vid_data+bespitch*y0+x0,bespitch); |
466 | 22 break; |
23 case MGA_VID_FORMAT_YUY2: | |
326 | 24 vo_draw_alpha_yuy2(w,h,src,srca,stride,vid_data+2*(bespitch*y0+x0),2*bespitch); |
466 | 25 break; |
26 case MGA_VID_FORMAT_UYVY: | |
27 vo_draw_alpha_yuy2(w,h,src,srca,stride,vid_data+2*(bespitch*y0+x0)+1,2*bespitch); | |
28 break; | |
29 } | |
1 | 30 } |
31 | |
5014
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
32 static int mga_set_video_eq( const vidix_video_eq_t *info) |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
33 { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
34 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
35 uint32_t luma; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
36 float factor = 256.0 / 2000; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
37 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
38 luma = ((int)(info->brightness * factor) << 16) + |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
39 ((int)(info->contrast * factor) & 0xFFFF); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
40 if (ioctl(f,MGA_VID_SET_LUMA,luma)) { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
41 perror("Error in mga_vid_config ioctl()"); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
42 printf("Could not set luma values in the kernel module!\n"); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
43 return -1; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
44 } |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
45 return 0; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
46 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
47 } |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
48 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
49 static int mga_get_video_eq( vidix_video_eq_t *info) |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
50 { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
51 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
52 uint32_t luma; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
53 float factor = 2000.0 / 256; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
54 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
55 if (ioctl(f,MGA_VID_GET_LUMA,&luma)) { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
56 perror("Error in mga_vid_config ioctl()"); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
57 printf("Could not get luma values from the kernel module!\n"); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
58 return -1; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
59 } |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
60 info->brightness = (luma >> 16) * factor; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
61 info->cap |= VEQ_CAP_BRIGHTNESS; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
62 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
63 info->contrast = (luma & 0xFFFF) * factor; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
64 info->cap |= VEQ_CAP_CONTRAST; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
65 |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
66 return 0; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
67 } |
1 | 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 | |
284 | 80 bespitch = (mga_vid_config.src_width + 31) & ~31; |
1 | 81 |
284 | 82 dest = vid_data + bespitch*y + x; |
4949 | 83 mem2agpcpy_pic(dest, image[0], width, height, bespitch, stride[0]); |
1 | 84 |
85 width/=2;height/=2;x/=2;y/=2; | |
86 | |
284 | 87 dest = vid_data + bespitch*mga_vid_config.src_height + bespitch*y + 2*x; |
5317 | 88 if(mga_vid_config.format==MGA_VID_FORMAT_YV12){ |
89 src = image[1]; | |
90 src2 = image[2]; | |
91 } else { | |
92 src = image[2]; | |
93 src2 = image[1]; | |
94 } | |
95 | |
1 | 96 for(h=0; h < height; h++) |
97 { | |
2625 | 98 #ifdef HAVE_MMX |
99 asm( | |
100 "xorl %%eax, %%eax \n\t" | |
101 "1: \n\t" | |
102 PREFETCH" 64(%1, %%eax) \n\t" | |
103 PREFETCH" 64(%2, %%eax) \n\t" | |
104 "movq (%1, %%eax), %%mm0 \n\t" | |
105 "movq 8(%1, %%eax), %%mm2 \n\t" | |
106 "movq %%mm0, %%mm1 \n\t" | |
107 "movq %%mm2, %%mm3 \n\t" | |
108 "movq (%2, %%eax), %%mm4 \n\t" | |
109 "movq 8(%2, %%eax), %%mm5 \n\t" | |
110 "punpcklbw %%mm4, %%mm0 \n\t" | |
111 "punpckhbw %%mm4, %%mm1 \n\t" | |
112 "punpcklbw %%mm5, %%mm2 \n\t" | |
113 "punpckhbw %%mm5, %%mm3 \n\t" | |
114 MOVNTQ" %%mm0, (%0, %%eax, 2) \n\t" | |
115 MOVNTQ" %%mm1, 8(%0, %%eax, 2) \n\t" | |
116 MOVNTQ" %%mm2, 16(%0, %%eax, 2) \n\t" | |
117 MOVNTQ" %%mm3, 24(%0, %%eax, 2) \n\t" | |
118 "addl $16, %%eax \n\t" | |
119 "cmpl %3, %%eax \n\t" | |
120 " jb 1b \n\t" | |
121 ::"r"(dest), "r"(src), "r"(src2), "r" (width-15) | |
122 : "memory", "%eax" | |
123 ); | |
124 for(w= (width&(~15)); w < width; w++) | |
125 { | |
126 dest[2*w+0] = src[w]; | |
127 dest[2*w+1] = src2[w]; | |
128 } | |
129 #else | |
1 | 130 for(w=0; w < width; w++) |
131 { | |
132 dest[2*w+0] = src[w]; | |
133 dest[2*w+1] = src2[w]; | |
134 } | |
2625 | 135 #endif |
1 | 136 dest += bespitch; |
284 | 137 src += stride[1]; |
138 src2+= stride[2]; | |
1 | 139 } |
2625 | 140 #ifdef HAVE_MMX |
141 asm( | |
142 EMMS" \n\t" | |
143 SFENCE" \n\t" | |
144 ::: "memory" | |
145 ); | |
146 #endif | |
1 | 147 } |
148 | |
149 static void | |
150 draw_slice_g400(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
151 { | |
152 uint8_t *src; | |
153 uint8_t *dest; | |
5317 | 154 uint8_t *dest2; |
1 | 155 uint32_t bespitch,bespitch2; |
156 int i; | |
157 | |
158 bespitch = (mga_vid_config.src_width + 31) & ~31; | |
159 bespitch2 = bespitch/2; | |
160 | |
161 dest = vid_data + bespitch * y + x; | |
4949 | 162 mem2agpcpy_pic(dest, image[0], w, h, bespitch, stride[0]); |
1 | 163 |
164 w/=2;h/=2;x/=2;y/=2; | |
5317 | 165 |
1 | 166 dest = vid_data + bespitch*mga_vid_config.src_height + bespitch2 * y + x; |
5317 | 167 dest2= dest + bespitch2*mga_vid_config.src_height / 2; |
1 | 168 |
5317 | 169 if(mga_vid_config.format==MGA_VID_FORMAT_YV12){ |
170 // mga_vid's YV12 assumes Y,U,V order (insteda of Y,V,U) :( | |
171 mem2agpcpy_pic(dest, image[1], w, h, bespitch2, stride[1]); | |
172 mem2agpcpy_pic(dest2,image[2], w, h, bespitch2, stride[2]); | |
173 } else { | |
4949 | 174 mem2agpcpy_pic(dest, image[2], w, h, bespitch2, stride[2]); |
5317 | 175 mem2agpcpy_pic(dest2,image[1], w, h, bespitch2, stride[1]); |
176 } | |
1 | 177 |
178 } | |
179 | |
180 static uint32_t | |
181 draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
182 { | |
4949 | 183 |
184 #if 0 | |
185 printf("vo: %p/%d %p/%d %p/%d %dx%d/%d;%d \n", | |
186 src[0],stride[0], | |
187 src[1],stride[1], | |
188 src[2],stride[2], | |
189 w,h,x,y); | |
190 #endif | |
191 | |
1 | 192 if (mga_vid_config.card_type == MGA_G200) |
193 draw_slice_g200(src,stride,w,h,x,y); | |
194 else | |
195 draw_slice_g400(src,stride,w,h,x,y); | |
196 return 0; | |
197 } | |
198 | |
199 static void | |
31 | 200 vo_mga_flip_page(void) |
1 | 201 { |
47 | 202 |
203 // printf("-- flip to %d --\n",mga_next_frame); | |
1 | 204 |
47 | 205 #if 1 |
206 ioctl(f,MGA_VID_FSEL,&mga_next_frame); | |
56 | 207 mga_next_frame=(mga_next_frame+1)%mga_vid_config.num_frames; |
47 | 208 vid_data=frames[mga_next_frame]; |
209 #endif | |
1 | 210 |
211 } | |
212 | |
213 | |
214 static void | |
215 write_frame_yuy2(uint8_t *y) | |
216 { | |
217 int len=2*mga_vid_config.src_width; | |
4949 | 218 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; |
1 | 219 |
4949 | 220 mem2agpcpy_pic(vid_data, y, len, mga_vid_config.src_height, 2*bespitch, len); |
1 | 221 } |
222 | |
223 static uint32_t | |
224 draw_frame(uint8_t *src[]) | |
225 { | |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
226 switch(mga_vid_config.format){ |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
227 case MGA_VID_FORMAT_YUY2: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
228 case MGA_VID_FORMAT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
229 write_frame_yuy2(src[0]);break; |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
230 } |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
231 return 0; |
1 | 232 } |
233 | |
234 static uint32_t | |
4971 | 235 get_image(mp_image_t *mpi){ |
236 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; | |
237 uint32_t bespitch2 = bespitch/2; | |
238 // printf("mga: get_image() called\n"); | |
4975 | 239 if(mpi->type==MP_IMGTYPE_STATIC && mga_vid_config.num_frames>1) return VO_FALSE; // it is not static |
4971 | 240 if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram |
241 // printf("width=%d vs. bespitch=%d, flags=0x%X \n",mpi->width,bespitch,mpi->flags); | |
242 if((mpi->width==bespitch) || | |
243 (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))){ | |
244 // we're lucky or codec accepts stride => ok, let's go! | |
245 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
246 mpi->planes[0]=vid_data; | |
5317 | 247 if(mpi->flags&MP_IMGFLAG_SWAPPED){ |
248 mpi->planes[1]=vid_data + bespitch*mga_vid_config.src_height; | |
249 mpi->planes[2]=mpi->planes[1] + bespitch2*mga_vid_config.src_height/2; | |
250 } else { | |
251 mpi->planes[2]=vid_data + bespitch*mga_vid_config.src_height; | |
252 mpi->planes[1]=mpi->planes[2] + bespitch2*mga_vid_config.src_height/2; | |
253 } | |
4971 | 254 mpi->width=mpi->stride[0]=bespitch; |
255 mpi->stride[1]=mpi->stride[2]=bespitch2; | |
256 } else { | |
257 mpi->planes[0]=vid_data; | |
258 mpi->width=bespitch; | |
259 mpi->stride[0]=mpi->width*(mpi->bpp/8); | |
260 } | |
261 mpi->flags|=MP_IMGFLAG_DIRECT; | |
262 // printf("mga: get_image() SUCCESS -> Direct Rendering ENABLED\n"); | |
263 return VO_TRUE; | |
264 } | |
265 return VO_FALSE; | |
266 } | |
267 | |
268 static uint32_t | |
1 | 269 query_format(uint32_t format) |
270 { | |
271 switch(format){ | |
272 case IMGFMT_YV12: | |
470 | 273 case IMGFMT_I420: |
274 case IMGFMT_IYUV: | |
1 | 275 case IMGFMT_YUY2: |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
276 case IMGFMT_UYVY: |
1 | 277 // case IMGFMT_RGB|24: |
278 // case IMGFMT_BGR|24: | |
279 return 1; | |
280 } | |
281 return 0; | |
282 } | |
283 | |
5014
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
284 static void query_vaa(vo_vaa_t *vaa) |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
285 { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
286 memset(vaa,0,sizeof(vo_vaa_t)); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
287 vaa->get_video_eq = mga_get_video_eq; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
288 vaa->set_video_eq = mga_set_video_eq; |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
289 } |
4970 | 290 static uint32_t control(uint32_t request, void *data, ...) |
291 { | |
292 switch (request) { | |
5014
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
293 case VOCTRL_QUERY_VAA: |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
294 query_vaa((vo_vaa_t*)data); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
295 return VO_TRUE; |
4970 | 296 case VOCTRL_QUERY_FORMAT: |
297 return query_format(*((uint32_t*)data)); | |
4971 | 298 case VOCTRL_GET_IMAGE: |
299 return get_image(data); | |
4981 | 300 #ifdef VO_XMGA |
301 case VOCTRL_FULLSCREEN: | |
302 vo_x11_fullscreen(); | |
303 return VO_TRUE; | |
304 #endif | |
4970 | 305 } |
306 return VO_NOTIMPL; | |
307 } | |
308 | |
309 | |
56 | 310 static int mga_init(){ |
311 char *frame_mem; | |
312 | |
313 mga_vid_config.num_frames=4; | |
314 mga_vid_config.version=MGA_VID_VERSION; | |
315 if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config)) | |
316 { | |
275 | 317 perror("Error in mga_vid_config ioctl()"); |
318 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n"); | |
56 | 319 return -1; |
320 } | |
321 ioctl(f,MGA_VID_ON,0); | |
322 | |
323 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,f,0); | |
324 frames[1] = frames[0] + 1*mga_vid_config.frame_size; | |
325 frames[2] = frames[0] + 2*mga_vid_config.frame_size; | |
326 frames[3] = frames[0] + 3*mga_vid_config.frame_size; | |
327 mga_next_frame = 0; | |
328 vid_data = frames[mga_next_frame]; | |
329 | |
330 //clear the buffer | |
331 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
332 | |
333 return 0; | |
334 | |
335 } | |
336 | |
1637 | 337 static int mga_uninit(){ |
338 ioctl( f,MGA_VID_OFF,0 ); | |
339 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
340 close(f); | |
341 } | |
4970 | 342 |
343 static uint32_t preinit(const char *arg) | |
344 { | |
345 return 0; | |
346 } | |
347 |