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