Mercurial > mplayer.hg
annotate libvo/mga_common.c @ 5610:fd196de4f1e9
cleanup. cosmetics only, no functional changes
author | arpi |
---|---|
date | Sat, 13 Apr 2002 22:16:15 +0000 |
parents | 1972c3475d93 |
children | 08c552788216 |
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 } |
4970 | 236 static uint32_t control(uint32_t request, void *data, ...) |
237 { | |
238 switch (request) { | |
5014
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
239 case VOCTRL_QUERY_VAA: |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
240 query_vaa((vo_vaa_t*)data); |
4458e43871d3
video_eq support - applied brightness/contrast patch by Brian J. Murrell
arpi
parents:
4981
diff
changeset
|
241 return VO_TRUE; |
4970 | 242 case VOCTRL_QUERY_FORMAT: |
243 return query_format(*((uint32_t*)data)); | |
4971 | 244 case VOCTRL_GET_IMAGE: |
245 return get_image(data); | |
4981 | 246 #ifdef VO_XMGA |
247 case VOCTRL_FULLSCREEN: | |
248 vo_x11_fullscreen(); | |
249 return VO_TRUE; | |
250 #endif | |
4970 | 251 } |
252 return VO_NOTIMPL; | |
253 } | |
254 | |
255 | |
56 | 256 static int mga_init(){ |
257 char *frame_mem; | |
258 | |
5432 | 259 mga_vid_config.num_frames=(vo_directrendering && !vo_doublebuffering)?1:3; |
56 | 260 mga_vid_config.version=MGA_VID_VERSION; |
261 if (ioctl(f,MGA_VID_CONFIG,&mga_vid_config)) | |
262 { | |
275 | 263 perror("Error in mga_vid_config ioctl()"); |
264 printf("Your mga_vid driver version is incompatible with this MPlayer version!\n"); | |
56 | 265 return -1; |
266 } | |
267 ioctl(f,MGA_VID_ON,0); | |
5432 | 268 |
269 printf("[mga] Using %d buffers.\n",mga_vid_config.num_frames); | |
56 | 270 |
271 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,f,0); | |
272 frames[1] = frames[0] + 1*mga_vid_config.frame_size; | |
273 frames[2] = frames[0] + 2*mga_vid_config.frame_size; | |
274 frames[3] = frames[0] + 3*mga_vid_config.frame_size; | |
275 mga_next_frame = 0; | |
276 vid_data = frames[mga_next_frame]; | |
277 | |
278 //clear the buffer | |
279 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
280 | |
281 return 0; | |
282 | |
283 } | |
284 | |
1637 | 285 static int mga_uninit(){ |
286 ioctl( f,MGA_VID_OFF,0 ); | |
287 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
288 close(f); | |
5389
7296c4262457
quick hack to make vo_mga accept multiple calls to config
rfelker
parents:
5335
diff
changeset
|
289 f = -1; |
1637 | 290 } |
4970 | 291 |
292 static uint32_t preinit(const char *arg) | |
293 { | |
5433 | 294 char *devname=vo_subdevice?vo_subdevice:"/dev/mga_vid"; |
295 | |
296 f = open(devname,O_RDWR); | |
297 if(f == -1) | |
298 { | |
299 perror("open"); | |
300 printf("Couldn't open %s\n",devname); | |
301 return(-1); | |
302 } | |
4970 | 303 return 0; |
304 } | |
305 |