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