Mercurial > mplayer.hg
annotate libvo/vesa_lvo.c @ 25317:7f3cb5408f28
Fixed VIDIX color bug that was introduced when Radeon VIDIX driver
was synchronized with vidix.sf.net.
The red color was saturating.
Corrected value fixes the issue and restore the color to the level
it used to have before synchronization.
Meaning of the value remains unknow but was retrieved from
register's value of a Radeon 9000 card, so it may need further testing.
Patch by Guillaume Lecerf (foxcore at gmail dot com)
author | ben |
---|---|
date | Mon, 10 Dec 2007 19:27:46 +0000 |
parents | a124f3abc1ec |
children | e2fb1ad9b2b4 |
rev | line source |
---|---|
2869 | 1 /* |
2 * vesa_lvo.c | |
3 * | |
4 * Copyright (C) Nick Kurshev <nickols_k@mail.ru> - Oct 2001 | |
5 * | |
6 * You can redistribute this file under terms and conditions | |
7 * of GNU General Public licence v2. | |
8 * | |
9 * This file contains vo_vesa interface to Linux Video Overlay. | |
10 * (Partly based on vo_mga.c from mplayer's package) | |
11 */ | |
12 | |
13 #include <inttypes.h> | |
14 #include <sys/ioctl.h> | |
15 #include <unistd.h> | |
16 #include <fcntl.h> | |
17 #include <sys/mman.h> | |
18 #include <stdio.h> | |
19 #include <stdlib.h> | |
20 #include <string.h> | |
21 | |
3205 | 22 #include "config.h" |
17932 | 23 #include "mp_msg.h" |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
24 #include "help_mp.h" |
3205 | 25 |
2869 | 26 #include "vesa_lvo.h" |
19431
ac69ba536915
Explicitly include libmpcodecs/img_format.h and libvo/fastmemcpy.h.
diego
parents:
18234
diff
changeset
|
27 #include "libmpcodecs/img_format.h" |
13787
e047e70a9767
Handle "xxx.h" vs "../xxx.h" include paths in a consistent way.
diego
parents:
6817
diff
changeset
|
28 #include "drivers/mga_vid.h" /* <- should be changed to "linux/'something'.h" */ |
2869 | 29 #include "fastmemcpy.h" |
3205 | 30 #include "osd.h" |
3202 | 31 #include "video_out.h" |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
13787
diff
changeset
|
32 #include "libmpcodecs/vfcap.h" |
3202 | 33 |
3165 | 34 #define WIDTH_ALIGN 32 /* should be 16 for rage:422 and 32 for rage:420 */ |
3266
ff90589b635f
Fixed single buffering problems and -vo mga compatibility by number of buffers
nick
parents:
3205
diff
changeset
|
35 #define NUM_FRAMES 10 |
3205 | 36 #define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */ |
37 | |
2869 | 38 static uint8_t *frames[NUM_FRAMES]; |
39 | |
40 static int lvo_handler = -1; | |
41 static uint8_t *lvo_mem = NULL; | |
42 static uint8_t next_frame; | |
43 static mga_vid_config_t mga_vid_config; | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
44 static unsigned image_bpp,image_height,image_width,src_format; |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
45 uint32_t vlvo_control(uint32_t request, void *data, ...); |
2869 | 46 |
47 #define PIXEL_SIZE() ((video_mode_info.BitsPerPixel+7)/8) | |
48 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) ) | |
49 #define IMAGE_LINE_SIZE(pixel_size) (image_width*(pixel_size)) | |
50 | |
3202 | 51 extern vo_functions_t video_out_vesa; |
52 | |
2971 | 53 int vlvo_preinit(const char *drvname) |
54 { | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
55 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_VESA_ThisBranchIsNoLongerSupported); |
4493 | 56 return -1; |
17932 | 57 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
58 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_preinit(%s) was called\n",drvname);} |
2971 | 59 lvo_handler = open(drvname,O_RDWR); |
60 if(lvo_handler == -1) | |
61 { | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
62 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_VESA_CouldntOpen,drvname); |
2971 | 63 return -1; |
64 } | |
3202 | 65 /* we are able to tune up this stuff depend on fourcc format */ |
66 video_out_vesa.draw_slice=vlvo_draw_slice; | |
67 video_out_vesa.draw_frame=vlvo_draw_frame; | |
68 video_out_vesa.flip_page=vlvo_flip_page; | |
69 video_out_vesa.draw_osd=vlvo_draw_osd; | |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
70 video_out_vesa.control=vlvo_control; |
2971 | 71 return 0; |
72 } | |
73 | |
74 int vlvo_init(unsigned src_width,unsigned src_height, | |
2869 | 75 unsigned x_org,unsigned y_org,unsigned dst_width, |
76 unsigned dst_height,unsigned format,unsigned dest_bpp) | |
77 { | |
78 size_t i,awidth; | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
79 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_VESA_ThisBranchIsNoLongerSupported); |
4493 | 80 return -1; |
17932 | 81 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
82 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_init() was called\n");} |
2869 | 83 image_width = src_width; |
84 image_height = src_height; | |
85 mga_vid_config.version=MGA_VID_VERSION; | |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
86 src_format = mga_vid_config.format=format; |
2869 | 87 awidth = (src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); |
88 switch(format){ | |
89 case IMGFMT_YV12: | |
90 case IMGFMT_I420: | |
91 case IMGFMT_IYUV: | |
92 image_bpp=16; | |
93 mga_vid_config.frame_size = awidth*src_height+(awidth*src_height)/2; | |
94 break; | |
95 case IMGFMT_YUY2: | |
96 case IMGFMT_UYVY: | |
97 image_bpp=16; | |
98 mga_vid_config.frame_size = awidth*src_height*2; | |
99 break; | |
100 case IMGFMT_RGB15: | |
101 case IMGFMT_BGR15: | |
102 case IMGFMT_RGB16: | |
103 case IMGFMT_BGR16: | |
104 image_bpp=16; | |
105 mga_vid_config.frame_size = awidth*src_height*2; | |
106 break; | |
107 case IMGFMT_RGB24: | |
108 case IMGFMT_BGR24: | |
109 image_bpp=24; | |
110 mga_vid_config.frame_size = awidth*src_height*3; | |
111 break; | |
112 case IMGFMT_RGB32: | |
113 case IMGFMT_BGR32: | |
114 image_bpp=32; | |
115 mga_vid_config.frame_size = awidth*src_height*4; | |
116 break; | |
117 default: | |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
118 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_VESA_InvalidOutputFormat,vo_format_name(format),format); |
2869 | 119 return -1; |
120 } | |
121 mga_vid_config.colkey_on=0; | |
122 mga_vid_config.src_width = src_width; | |
123 mga_vid_config.src_height= src_height; | |
124 mga_vid_config.dest_width = dst_width; | |
125 mga_vid_config.dest_height= dst_height; | |
126 mga_vid_config.x_org=x_org; | |
127 mga_vid_config.y_org=y_org; | |
128 mga_vid_config.num_frames=NUM_FRAMES; | |
129 if (ioctl(lvo_handler,MGA_VID_CONFIG,&mga_vid_config)) | |
130 { | |
2971 | 131 perror("vesa_lvo: Error in mga_vid_config ioctl()"); |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
132 mp_msg(MSGT_VO,MSGL_WARN, MSGTR_LIBVO_VESA_IncompatibleDriverVersion); |
2869 | 133 return -1; |
134 } | |
135 ioctl(lvo_handler,MGA_VID_ON,0); | |
136 | |
137 frames[0] = (char*)mmap(0,mga_vid_config.frame_size*mga_vid_config.num_frames,PROT_WRITE,MAP_SHARED,lvo_handler,0); | |
138 for(i=1;i<NUM_FRAMES;i++) | |
139 frames[i] = frames[i-1] + mga_vid_config.frame_size; | |
140 next_frame = 0; | |
141 lvo_mem = frames[next_frame]; | |
142 | |
143 /*clear the buffer*/ | |
144 memset(frames[0],0x80,mga_vid_config.frame_size*mga_vid_config.num_frames); | |
145 return 0; | |
146 } | |
147 | |
148 void vlvo_term( void ) | |
149 { | |
17932 | 150 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
151 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_term() was called\n");} |
2869 | 152 ioctl( lvo_handler,MGA_VID_OFF,0 ); |
153 munmap(frames[0],mga_vid_config.frame_size*mga_vid_config.num_frames); | |
154 if(lvo_handler != -1) close(lvo_handler); | |
155 } | |
156 | |
3165 | 157 uint32_t vlvo_draw_slice_420(uint8_t *image[], int stride[], int w,int h,int x,int y) |
2869 | 158 { |
159 uint8_t *src; | |
160 uint8_t *dest; | |
3020 | 161 uint32_t bespitch,bespitch2; |
2869 | 162 int i; |
163 | |
164 bespitch = (mga_vid_config.src_width + (WIDTH_ALIGN-1)) & ~(WIDTH_ALIGN-1); | |
165 bespitch2 = bespitch/2; | |
166 | |
167 dest = lvo_mem + bespitch * y + x; | |
168 src = image[0]; | |
169 for(i=0;i<h;i++){ | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
19431
diff
changeset
|
170 fast_memcpy(dest,src,w); |
2869 | 171 src+=stride[0]; |
172 dest += bespitch; | |
173 } | |
174 | |
175 w/=2;h/=2;x/=2;y/=2; | |
176 | |
177 dest = lvo_mem + bespitch*mga_vid_config.src_height + bespitch2 * y + x; | |
178 src = image[1]; | |
179 for(i=0;i<h;i++){ | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
19431
diff
changeset
|
180 fast_memcpy(dest,src,w); |
2869 | 181 src+=stride[1]; |
182 dest += bespitch2; | |
183 } | |
184 | |
185 dest = lvo_mem + bespitch*mga_vid_config.src_height | |
186 + bespitch*mga_vid_config.src_height / 4 | |
187 + bespitch2 * y + x; | |
188 src = image[2]; | |
189 for(i=0;i<h;i++){ | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
19431
diff
changeset
|
190 fast_memcpy(dest,src,w); |
2869 | 191 src+=stride[2]; |
192 dest += bespitch2; | |
193 } | |
3020 | 194 return 0; |
195 } | |
196 | |
197 uint32_t vlvo_draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
198 { | |
17932 | 199 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
200 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_draw_slice() was called\n");} |
3165 | 201 if(src_format == IMGFMT_YV12 || src_format == IMGFMT_I420 || src_format == IMGFMT_IYUV) |
3202 | 202 vlvo_draw_slice_420(image,stride,w,h,x,y); |
2974
49199909c939
Ugly YV12 support on Radeon BES. (Only radeon_vid currently work with this stuff :( Sorry!)
nick
parents:
2971
diff
changeset
|
203 else |
3202 | 204 { |
205 uint8_t *dst; | |
206 uint8_t bytpp; | |
207 bytpp = (image_bpp+7)/8; | |
208 dst = lvo_mem + (image_width * y + x)*bytpp; | |
209 /* vlvo_draw_slice_422(image,stride,w,h,x,y); just for speed */ | |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
19431
diff
changeset
|
210 fast_memcpy(dst,image[0],mga_vid_config.frame_size); |
3202 | 211 } |
2924 | 212 return 0; |
2869 | 213 } |
214 | |
3017 | 215 uint32_t vlvo_draw_frame(uint8_t *image[]) |
2869 | 216 { |
3017 | 217 /* Note it's very strange but sometime for YUY2 draw_frame is called */ |
23457
a124f3abc1ec
Replace implicit use of fast_memcpy via macro by explicit use to allow
reimar
parents:
19431
diff
changeset
|
218 fast_memcpy(lvo_mem,image[0],mga_vid_config.frame_size); |
17932 | 219 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
220 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_flip_page() was called\n");} |
3017 | 221 return 0; |
2869 | 222 } |
223 | |
224 void vlvo_flip_page(void) | |
225 { | |
17932 | 226 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
227 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: vlvo_draw_osd() was called\n");} |
3266
ff90589b635f
Fixed single buffering problems and -vo mga compatibility by number of buffers
nick
parents:
3205
diff
changeset
|
228 if(vo_doublebuffering) |
ff90589b635f
Fixed single buffering problems and -vo mga compatibility by number of buffers
nick
parents:
3205
diff
changeset
|
229 { |
2869 | 230 ioctl(lvo_handler,MGA_VID_FSEL,&next_frame); |
231 next_frame=(next_frame+1)%mga_vid_config.num_frames; | |
232 lvo_mem=frames[next_frame]; | |
3266
ff90589b635f
Fixed single buffering problems and -vo mga compatibility by number of buffers
nick
parents:
3205
diff
changeset
|
233 } |
2869 | 234 } |
235 | |
3205 | 236 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) |
237 { | |
238 UNUSED(x0); | |
239 UNUSED(y0); | |
240 UNUSED(w); | |
241 UNUSED(h); | |
242 UNUSED(src); | |
243 UNUSED(srca); | |
244 UNUSED(stride); | |
245 } | |
246 | |
247 static void draw_alpha(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) | |
248 { | |
249 uint32_t bespitch = /*(*/mga_vid_config.src_width;// + 15) & ~15; | |
250 switch(mga_vid_config.format){ | |
251 case IMGFMT_BGR15: | |
252 case IMGFMT_RGB15: | |
253 vo_draw_alpha_rgb15(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch); | |
254 break; | |
255 case IMGFMT_BGR16: | |
256 case IMGFMT_RGB16: | |
257 vo_draw_alpha_rgb16(w,h,src,srca,stride,lvo_mem+2*(y0*bespitch+x0),2*bespitch); | |
258 break; | |
259 case IMGFMT_BGR24: | |
260 case IMGFMT_RGB24: | |
261 vo_draw_alpha_rgb24(w,h,src,srca,stride,lvo_mem+3*(y0*bespitch+x0),3*bespitch); | |
262 break; | |
263 case IMGFMT_BGR32: | |
264 case IMGFMT_RGB32: | |
265 vo_draw_alpha_rgb32(w,h,src,srca,stride,lvo_mem+4*(y0*bespitch+x0),4*bespitch); | |
266 break; | |
267 case IMGFMT_YV12: | |
268 case IMGFMT_IYUV: | |
269 case IMGFMT_I420: | |
270 vo_draw_alpha_yv12(w,h,src,srca,stride,lvo_mem+bespitch*y0+x0,bespitch); | |
271 break; | |
272 case IMGFMT_YUY2: | |
273 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0),bespitch); | |
274 break; | |
275 case IMGFMT_UYVY: | |
276 vo_draw_alpha_yuy2(w,h,src,srca,stride,lvo_mem+2*(bespitch*y0+x0)+1,bespitch); | |
277 break; | |
278 default: | |
279 draw_alpha_null(x0,y0,w,h,src,srca,stride); | |
280 } | |
281 } | |
282 | |
2869 | 283 void vlvo_draw_osd(void) |
284 { | |
17932 | 285 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
286 mp_msg(MSGT_VO,MSGL_DBG2,"vesa_lvo: vlvo_draw_osd() was called\n"); } |
2869 | 287 /* TODO: hw support */ |
3205 | 288 #if 0 |
289 /* disable this stuff until new fbvid.h interface will be implemented | |
290 because in different fourcc radeon_vid and rage128_vid have different | |
291 width alignment */ | |
292 vo_draw_text(mga_vid_config.src_width,mga_vid_config.src_height,draw_alpha); | |
293 #endif | |
2869 | 294 } |
295 | |
296 uint32_t vlvo_query_info(uint32_t format) | |
297 { | |
17932 | 298 if( mp_msg_test(MSGT_VO,MSGL_DBG2) ) { |
18234
a107276371a8
Part 5 and final of otvos attila's oattila AT chello-hu mp_msg changes, with lots of corrections
reynaldo
parents:
17932
diff
changeset
|
299 mp_msg(MSGT_VO,MSGL_DBG2, "vesa_lvo: query_format was called: %x (%s)\n",format,vo_format_name(format)); } |
15212
05aa13cdf92f
replace VO and VF numeric flags with #defined identifiers
henry
parents:
13787
diff
changeset
|
300 return VFCAP_CSP_SUPPORTED; |
2869 | 301 } |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
302 |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
303 uint32_t vlvo_control(uint32_t request, void *data, ...) |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
304 { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
305 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
306 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
307 return vlvo_query_info(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
308 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
309 return VO_NOTIMPL; |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4493
diff
changeset
|
310 } |