Mercurial > mplayer.hg
annotate libvo/mga_common.c @ 5281:88df6d5f6ce7
Aspect code reenabled, apparently users didn't like running movies
hi-res ;)
author | mswitch |
---|---|
date | Sat, 23 Mar 2002 18:16:22 +0000 |
parents | 4458e43871d3 |
children | 80fbb03b385a |
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; |
1 | 88 src = image[1]; |
89 src2 = image[2]; | |
90 for(h=0; h < height; h++) | |
91 { | |
2625 | 92 #ifdef HAVE_MMX |
93 asm( | |
94 "xorl %%eax, %%eax \n\t" | |
95 "1: \n\t" | |
96 PREFETCH" 64(%1, %%eax) \n\t" | |
97 PREFETCH" 64(%2, %%eax) \n\t" | |
98 "movq (%1, %%eax), %%mm0 \n\t" | |
99 "movq 8(%1, %%eax), %%mm2 \n\t" | |
100 "movq %%mm0, %%mm1 \n\t" | |
101 "movq %%mm2, %%mm3 \n\t" | |
102 "movq (%2, %%eax), %%mm4 \n\t" | |
103 "movq 8(%2, %%eax), %%mm5 \n\t" | |
104 "punpcklbw %%mm4, %%mm0 \n\t" | |
105 "punpckhbw %%mm4, %%mm1 \n\t" | |
106 "punpcklbw %%mm5, %%mm2 \n\t" | |
107 "punpckhbw %%mm5, %%mm3 \n\t" | |
108 MOVNTQ" %%mm0, (%0, %%eax, 2) \n\t" | |
109 MOVNTQ" %%mm1, 8(%0, %%eax, 2) \n\t" | |
110 MOVNTQ" %%mm2, 16(%0, %%eax, 2) \n\t" | |
111 MOVNTQ" %%mm3, 24(%0, %%eax, 2) \n\t" | |
112 "addl $16, %%eax \n\t" | |
113 "cmpl %3, %%eax \n\t" | |
114 " jb 1b \n\t" | |
115 ::"r"(dest), "r"(src), "r"(src2), "r" (width-15) | |
116 : "memory", "%eax" | |
117 ); | |
118 for(w= (width&(~15)); w < width; w++) | |
119 { | |
120 dest[2*w+0] = src[w]; | |
121 dest[2*w+1] = src2[w]; | |
122 } | |
123 #else | |
1 | 124 for(w=0; w < width; w++) |
125 { | |
126 dest[2*w+0] = src[w]; | |
127 dest[2*w+1] = src2[w]; | |
128 } | |
2625 | 129 #endif |
1 | 130 dest += bespitch; |
284 | 131 src += stride[1]; |
132 src2+= stride[2]; | |
1 | 133 } |
2625 | 134 #ifdef HAVE_MMX |
135 asm( | |
136 EMMS" \n\t" | |
137 SFENCE" \n\t" | |
138 ::: "memory" | |
139 ); | |
140 #endif | |
1 | 141 } |
142 | |
143 static void | |
144 draw_slice_g400(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
145 { | |
146 uint8_t *src; | |
147 uint8_t *dest; | |
148 uint32_t bespitch,bespitch2; | |
149 int i; | |
150 | |
151 bespitch = (mga_vid_config.src_width + 31) & ~31; | |
152 bespitch2 = bespitch/2; | |
153 | |
154 dest = vid_data + bespitch * y + x; | |
4949 | 155 mem2agpcpy_pic(dest, image[0], w, h, bespitch, stride[0]); |
1 | 156 |
157 w/=2;h/=2;x/=2;y/=2; | |
158 | |
159 dest = vid_data + bespitch*mga_vid_config.src_height + bespitch2 * y + x; | |
4949 | 160 mem2agpcpy_pic(dest, image[1], w, h, bespitch2, stride[1]); |
1 | 161 |
162 dest = vid_data + bespitch*mga_vid_config.src_height | |
163 + bespitch*mga_vid_config.src_height / 4 | |
164 + bespitch2 * y + x; | |
4949 | 165 mem2agpcpy_pic(dest, image[2], w, h, bespitch2, stride[2]); |
1 | 166 |
167 } | |
168 | |
169 static uint32_t | |
170 draw_slice(uint8_t *src[], int stride[], int w,int h,int x,int y) | |
171 { | |
4949 | 172 |
173 #if 0 | |
174 printf("vo: %p/%d %p/%d %p/%d %dx%d/%d;%d \n", | |
175 src[0],stride[0], | |
176 src[1],stride[1], | |
177 src[2],stride[2], | |
178 w,h,x,y); | |
179 #endif | |
180 | |
1 | 181 if (mga_vid_config.card_type == MGA_G200) |
182 draw_slice_g200(src,stride,w,h,x,y); | |
183 else | |
184 draw_slice_g400(src,stride,w,h,x,y); | |
185 return 0; | |
186 } | |
187 | |
188 static void | |
31 | 189 vo_mga_flip_page(void) |
1 | 190 { |
47 | 191 |
192 // printf("-- flip to %d --\n",mga_next_frame); | |
1 | 193 |
47 | 194 #if 1 |
195 ioctl(f,MGA_VID_FSEL,&mga_next_frame); | |
56 | 196 mga_next_frame=(mga_next_frame+1)%mga_vid_config.num_frames; |
47 | 197 vid_data=frames[mga_next_frame]; |
198 #endif | |
1 | 199 |
200 } | |
201 | |
202 | |
203 static void | |
204 write_frame_yuy2(uint8_t *y) | |
205 { | |
206 int len=2*mga_vid_config.src_width; | |
4949 | 207 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; |
1 | 208 |
4949 | 209 mem2agpcpy_pic(vid_data, y, len, mga_vid_config.src_height, 2*bespitch, len); |
1 | 210 } |
211 | |
212 static uint32_t | |
213 draw_frame(uint8_t *src[]) | |
214 { | |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
215 switch(mga_vid_config.format){ |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
216 case MGA_VID_FORMAT_YUY2: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
217 case MGA_VID_FORMAT_UYVY: |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
218 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
|
219 } |
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
220 return 0; |
1 | 221 } |
222 | |
223 static uint32_t | |
4971 | 224 get_image(mp_image_t *mpi){ |
225 uint32_t bespitch = (mga_vid_config.src_width + 31) & ~31; | |
226 uint32_t bespitch2 = bespitch/2; | |
227 // printf("mga: get_image() called\n"); | |
4975 | 228 if(mpi->type==MP_IMGTYPE_STATIC && mga_vid_config.num_frames>1) return VO_FALSE; // it is not static |
4971 | 229 if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram |
230 // printf("width=%d vs. bespitch=%d, flags=0x%X \n",mpi->width,bespitch,mpi->flags); | |
231 if((mpi->width==bespitch) || | |
232 (mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH))){ | |
233 // we're lucky or codec accepts stride => ok, let's go! | |
234 if(mpi->flags&MP_IMGFLAG_PLANAR){ | |
235 mpi->planes[0]=vid_data; | |
236 mpi->planes[1]=vid_data + bespitch*mga_vid_config.src_height; | |
237 mpi->planes[2]=vid_data + bespitch*mga_vid_config.src_height | |
238 + bespitch*mga_vid_config.src_height / 4; | |
239 mpi->width=mpi->stride[0]=bespitch; | |
240 mpi->stride[1]=mpi->stride[2]=bespitch2; | |
241 } else { | |
242 mpi->planes[0]=vid_data; | |
243 mpi->width=bespitch; | |
244 mpi->stride[0]=mpi->width*(mpi->bpp/8); | |
245 } | |
246 mpi->flags|=MP_IMGFLAG_DIRECT; | |
247 // printf("mga: get_image() SUCCESS -> Direct Rendering ENABLED\n"); | |
248 return VO_TRUE; | |
249 } | |
250 return VO_FALSE; | |
251 } | |
252 | |
253 static uint32_t | |
1 | 254 query_format(uint32_t format) |
255 { | |
256 switch(format){ | |
257 case IMGFMT_YV12: | |
470 | 258 case IMGFMT_I420: |
259 case IMGFMT_IYUV: | |
1 | 260 case IMGFMT_YUY2: |
448
198b46b739d8
qrva eletbe nem kene cvs-t elbaszni inkabb ne nyuljatok hozza baz+
arpi_esp
parents:
413
diff
changeset
|
261 case IMGFMT_UYVY: |
1 | 262 // case IMGFMT_RGB|24: |
263 // case IMGFMT_BGR|24: | |
264 return 1; | |
265 } | |
266 return 0; | |
267 } | |
268 | |
5014
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
269 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
|
270 { |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
271 memset(vaa,0,sizeof(vo_vaa_t)); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
272 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
|
273 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
|
274 } |
4970 | 275 static uint32_t control(uint32_t request, void *data, ...) |
276 { | |
277 switch (request) { | |
5014
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
278 case VOCTRL_QUERY_VAA: |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
279 query_vaa((vo_vaa_t*)data); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
280 return VO_TRUE; |
4970 | 281 case VOCTRL_QUERY_FORMAT: |
282 return query_format(*((uint32_t*)data)); | |
4971 | 283 case VOCTRL_GET_IMAGE: |
284 return get_image(data); | |
4981 | 285 #ifdef VO_XMGA |
286 case VOCTRL_FULLSCREEN: | |
287 vo_x11_fullscreen(); | |
288 return VO_TRUE; | |
289 #endif | |
4970 | 290 } |
291 return VO_NOTIMPL; | |
292 } | |
293 | |
294 | |
56 | 295 static int mga_init(){ |
296 char *frame_mem; | |
297 | |
298 mga_vid_config.num_frames=4; | |
299 mga_vid_config.version=MGA_VID_VERSION; | |
300 if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config)) | |
301 { | |
275 | 302 perror("Error in mga_vid_config ioctl()"); |
303 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n"); | |
56 | 304 return -1; |
305 } | |
306 ioctl(f,MGA_VID_ON,0); | |
307 | |
308 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,f,0); | |
309 frames[1] = frames[0] + 1*mga_vid_config.frame_size; | |
310 frames[2] = frames[0] + 2*mga_vid_config.frame_size; | |
311 frames[3] = frames[0] + 3*mga_vid_config.frame_size; | |
312 mga_next_frame = 0; | |
313 vid_data = frames[mga_next_frame]; | |
314 | |
315 //clear the buffer | |
316 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
317 | |
318 return 0; | |
319 | |
320 } | |
321 | |
1637 | 322 static int mga_uninit(){ |
323 ioctl( f,MGA_VID_OFF,0 ); | |
324 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
325 close(f); | |
326 } | |
4970 | 327 |
328 static uint32_t preinit(const char *arg) | |
329 { | |
330 return 0; | |
331 } | |
332 |