Mercurial > mplayer.hg
annotate libvo/vo_vesa.c @ 2533:36a9317a2afc
added stss (not completed)
author | alex |
---|---|
date | Mon, 29 Oct 2001 16:56:36 +0000 |
parents | 6f3fa9bc3b27 |
children | 28d30f50d89c |
rev | line source |
---|---|
2519 | 1 /* |
2244 | 2 * video_out_vesa.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 * GNU General Public licence v2. | |
8 * This file is partly based on vbetest.c from lrmi distributive. | |
9 */ | |
10 | |
11 /* | |
12 TODO: | |
13 - DGA support (need volunteers who have corresponding hardware) | |
14 - hw YUV support (need volunteers who have corresponding hardware) | |
15 - double (triple) buffering (if it will really speedup playback). | |
16 - refresh rate support (need additional info from mplayer) | |
17 */ | |
18 #include <stdio.h> | |
2446 | 19 #include <stdlib.h> |
2244 | 20 #include <string.h> |
21 #include <stddef.h> | |
22 #include <limits.h> | |
23 | |
24 #include "config.h" | |
25 #include "video_out.h" | |
26 #include "video_out_internal.h" | |
27 | |
28 #include "fastmemcpy.h" | |
29 #include "yuv2rgb.h" | |
2337 | 30 #include "sub.h" |
2244 | 31 #include "linux/vbelib.h" |
32 #include "bswap.h" | |
33 | |
2298 | 34 #include "../postproc/swscale.h" |
2504 | 35 #include "../postproc/rgb2rgb.h" |
2298 | 36 |
2244 | 37 LIBVO_EXTERN(vesa) |
38 extern int verbose; | |
39 | |
40 #ifndef max | |
41 #define max(a,b) ((a)>(b)?(a):(b)) | |
42 #endif | |
43 #ifndef min | |
44 #define min(a,b) ((a)<(b)?(a):(b)) | |
45 #endif | |
46 | |
47 | |
48 static vo_info_t vo_info = | |
49 { | |
50 "VESA VBE 2.0 video output", | |
51 "vesa", | |
52 "Nick Kurshev <nickols_k@mail.ru>", | |
53 "Requires ROOT privileges" | |
54 }; | |
55 | |
56 /* driver data */ | |
57 | |
58 /* | |
59 TODO: for linear framebuffer mode: | |
60 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
61 win.ptr = linear address of frame buffer; | |
62 win.low = 0; | |
63 win.high = vide_memory_size; | |
64 */ | |
65 struct win_frame | |
66 { | |
67 uint8_t *ptr; /* pointer to window's frame memory */ | |
68 uint32_t low; /* lowest boundary of frame */ | |
69 uint32_t high; /* highest boundary of frame */ | |
70 uint8_t idx; /* indicates index of relocatable frame (A or B) */ | |
71 }; | |
72 | |
2298 | 73 static int vesa_zoom=0; /* software scaling */ |
74 static unsigned int scale_xinc=0; | |
75 static unsigned int scale_yinc=0; | |
76 | |
2504 | 77 static uint32_t image_bpp,image_width, image_height; /* source image dimension */ |
2329 | 78 static int32_t x_offset,y_offset; /* to center image on screen */ |
2244 | 79 static unsigned init_mode; /* mode before run of mplayer */ |
80 static void *init_state = NULL; /* state before run of mplayer */ | |
81 static struct win_frame win; /* real-mode window to video memory */ | |
2308 | 82 static uint8_t *yuv_buffer = NULL; /* for yuv2rgb and sw_scaling */ |
2244 | 83 static unsigned video_mode; /* selected video mode for playback */ |
84 static struct VesaModeInfoBlock video_mode_info; | |
2331 | 85 static int flip_trigger = 0; |
2337 | 86 static void (*draw_alpha_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride); |
2504 | 87 static void (*rgb2rgb_fnc)(uint8_t *src,uint8_t *dst,uint32_t src_size); |
2244 | 88 |
89 #define MOVIE_MODE (MODE_ATTR_COLOR | MODE_ATTR_GRAPHICS) | |
90 #define FRAME_MODE (MODE_WIN_RELOCATABLE | MODE_WIN_READABLE | MODE_WIN_WRITEABLE) | |
91 static char * vbeErrToStr(int err) | |
92 { | |
93 char *retval; | |
94 static char sbuff[80]; | |
95 if((err & VBE_VESA_ERROR_MASK) == VBE_VESA_ERROR_MASK) | |
96 { | |
2255 | 97 sprintf(sbuff,"VESA failed = 0x4f%x",(err & VBE_VESA_ERRCODE_MASK)>>8); |
2244 | 98 retval = sbuff; |
99 } | |
100 else | |
101 switch(err) | |
102 { | |
103 case VBE_OK: retval = "No error"; break; | |
104 case VBE_VM86_FAIL: retval = "vm86() syscall failed"; break; | |
105 case VBE_OUT_OF_DOS_MEM: retval = "Out of DOS memory"; break; | |
106 case VBE_OUT_OF_MEM: retval = "Out of memory"; break; | |
2360 | 107 case VBE_BROKEN_BIOS: retval = "Broken BIOS or DOS TSR"; break; |
2244 | 108 default: sprintf(sbuff,"Uknown error: %i",err); retval=sbuff; break; |
109 } | |
110 return retval; | |
111 } | |
112 | |
113 #define PRINT_VBE_ERR(name,err) { printf("vo_vesa: %s returns: %s\n",name,vbeErrToStr(err)); fflush(stdout); } | |
114 | |
115 static void vesa_term( void ) | |
116 { | |
117 int err; | |
118 if((err=vbeRestoreState(init_state)) != VBE_OK) PRINT_VBE_ERR("vbeRestoreState",err); | |
119 if((err=vbeSetMode(init_mode,NULL)) != VBE_OK) PRINT_VBE_ERR("vbeSetMode",err); | |
2337 | 120 if(yuv_buffer) free(yuv_buffer); |
2244 | 121 vbeDestroy(); |
122 } | |
123 | |
124 #define VALID_WIN_FRAME(offset) (offset >= win.low && offset < win.high) | |
125 #define VIDEO_PTR(offset) (win.ptr + offset - win.low) | |
126 | |
127 static inline void __vbeSwitchBank(unsigned long offset) | |
128 { | |
129 unsigned long gran; | |
130 unsigned new_offset; | |
131 int err; | |
132 gran = video_mode_info.WinGranularity*1024; | |
133 new_offset = offset / gran; | |
134 if((err=vbeSetWindow(win.idx,new_offset)) != VBE_OK) | |
135 { | |
136 PRINT_VBE_ERR("vbeSetWindow",err); | |
137 printf("vo_vesa: Fatal error occured! Can't continue\n"); | |
138 vesa_term(); | |
139 exit(-1); | |
140 } | |
141 win.low = new_offset * gran; | |
142 win.high = win.low + video_mode_info.WinSize*1024; | |
143 } | |
144 | |
145 static void __vbeSetPixel(int x, int y, int r, int g, int b) | |
146 { | |
147 int x_res = video_mode_info.XResolution; | |
148 int y_res = video_mode_info.YResolution; | |
149 int shift_r = video_mode_info.RedFieldPosition; | |
150 int shift_g = video_mode_info.GreenFieldPosition; | |
151 int shift_b = video_mode_info.BlueFieldPosition; | |
152 int pixel_size = (video_mode_info.BitsPerPixel+7)/8; | |
153 int bpl = video_mode_info.BytesPerScanLine; | |
154 int color, offset; | |
155 | |
156 if (x < 0 || x >= x_res || y < 0 || y >= y_res) return; | |
157 r >>= 8 - video_mode_info.RedMaskSize; | |
158 g >>= 8 - video_mode_info.GreenMaskSize; | |
159 b >>= 8 - video_mode_info.BlueMaskSize; | |
160 color = (r << shift_r) | (g << shift_g) | (b << shift_b); | |
161 offset = y * bpl + (x * pixel_size); | |
162 if(!VALID_WIN_FRAME(offset)) __vbeSwitchBank(offset); | |
163 memcpy(VIDEO_PTR(offset), &color, pixel_size); | |
164 } | |
165 | |
166 /* | |
167 Copies line of frame to video memory. Data should be in the same format as video | |
168 memory. | |
169 */ | |
170 static void __vbeCopyBlock(unsigned long offset,uint8_t *image,unsigned long size) | |
171 { | |
172 unsigned long delta,src_idx = 0; | |
173 while(size) | |
174 { | |
175 if(!VALID_WIN_FRAME(offset)) __vbeSwitchBank(offset); | |
176 delta = min(size,win.high - offset); | |
177 memcpy(VIDEO_PTR(offset),&image[src_idx],delta); | |
178 src_idx += delta; | |
179 offset += delta; | |
180 size -= delta; | |
181 } | |
182 } | |
183 | |
184 static void __vbeCopyBlockSwap(unsigned long offset,uint8_t *image,unsigned long size) | |
185 { | |
186 unsigned byte_len; | |
187 uint8_t ch; | |
188 while(size) | |
189 { | |
190 switch(video_mode_info.BitsPerPixel) | |
191 { | |
192 case 8: byte_len = 1; break; | |
193 default: | |
194 case 15: | |
195 printf("vo_vesa: Can't swap non byte aligned data\n"); | |
196 vesa_term(); | |
197 exit(-1); | |
198 case 16: *(image + offset) = ByteSwap16(*(image + offset)); | |
199 byte_len = 2; break; | |
200 case 24: ch = *(image+offset); | |
201 *(image+offset) = *(image+offset+3); | |
202 *(image+offset+3) = ch; | |
203 byte_len = 3; break; | |
204 case 32: *(image + offset) = ByteSwap32(*(image + offset)); | |
205 byte_len = 4; break; | |
206 } | |
207 __vbeCopyBlock(offset,image,byte_len); | |
208 size -= byte_len; | |
209 image += byte_len; | |
210 offset += byte_len; | |
211 } | |
212 } | |
213 | |
214 /* | |
215 Copies frame to video memory. Data should be in the same format as video | |
216 memory. | |
217 */ | |
218 static void __vbeCopyData(uint8_t *image) | |
219 { | |
2308 | 220 unsigned long i,j,image_offset,offset; |
2244 | 221 unsigned pixel_size,image_line_size,screen_line_size,x_shift; |
222 pixel_size = (video_mode_info.BitsPerPixel+7)/8; | |
223 screen_line_size = video_mode_info.XResolution*pixel_size; | |
224 image_line_size = image_width*pixel_size; | |
2306 | 225 if(image_width == video_mode_info.XResolution) |
226 { | |
227 /* Special case for zooming */ | |
228 __vbeCopyBlock(y_offset*screen_line_size,image,image_line_size*image_height); | |
229 } | |
230 else | |
2244 | 231 { |
2306 | 232 x_shift = x_offset*pixel_size; |
2308 | 233 for(j=0,i=y_offset;j<image_height;i++,j++) |
2306 | 234 { |
235 offset = i*screen_line_size+x_shift; | |
236 image_offset = j*image_line_size; | |
237 __vbeCopyBlock(offset,&image[image_offset],image_line_size); | |
238 } | |
2244 | 239 } |
240 } | |
2328 | 241 |
2244 | 242 /* is called for yuv only */ |
243 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
244 { | |
2504 | 245 if(verbose > 2) |
246 printf("vo_vesa: draw_slice was called: w=%u h=%u x=%u y=%u\n",w,h,x,y); | |
2298 | 247 if(vesa_zoom) |
248 { | |
2519 | 249 uint8_t *dst[3]= {yuv_buffer, NULL, NULL}; |
250 SwScale_YV12slice(image,stride,y,h, | |
251 dst, | |
2298 | 252 image_width*((video_mode_info.BitsPerPixel+7)/8), |
253 image_width, video_mode_info.BitsPerPixel, | |
254 scale_xinc, scale_yinc); | |
255 } | |
256 else | |
257 { | |
2331 | 258 uint8_t *yuv_slice; |
259 yuv_slice=yuv_buffer+(image_width*y+x)*((video_mode_info.BitsPerPixel+7)/8); | |
260 yuv2rgb(yuv_slice, image[0], image[1], image[2], w, h, | |
2293 | 261 image_width * ((video_mode_info.BitsPerPixel+7)/8), |
2244 | 262 stride[0], stride[1]); |
2298 | 263 } |
2331 | 264 flip_trigger = 1; |
2298 | 265 return 0; |
2244 | 266 } |
267 | |
2337 | 268 static void draw_alpha_32(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ |
269 vo_draw_alpha_rgb32(w,h,src,srca,stride,yuv_buffer+4*(y0*image_width+x0),4*image_width); | |
270 } | |
271 | |
272 static void draw_alpha_24(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
273 vo_draw_alpha_rgb24(w,h,src,srca,stride,yuv_buffer+3*(y0*image_width+x0),3*image_width); | |
274 } | |
275 | |
276 static void draw_alpha_16(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
277 vo_draw_alpha_rgb16(w,h,src,srca,stride,yuv_buffer+2*(y0*image_width+x0),2*image_width); | |
278 } | |
279 | |
280 static void draw_alpha_15(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
281 vo_draw_alpha_rgb15(w,h,src,srca,stride,yuv_buffer+2*(y0*image_width+x0),2*image_width); | |
282 } | |
283 | |
284 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
285 } | |
286 | |
287 | |
2244 | 288 static void draw_osd(void) |
289 { | |
2504 | 290 if(verbose > 2) |
291 printf("vo_vesa: draw_osd was called\n"); | |
2337 | 292 if(yuv_buffer) vo_draw_text(image_width,image_height,draw_alpha_fnc); |
2244 | 293 } |
294 | |
295 static void flip_page(void) | |
296 { | |
2504 | 297 if(verbose > 2) |
298 printf("vo_vesa: flip_page was called\n"); | |
2331 | 299 if(flip_trigger) { __vbeCopyData(yuv_buffer); flip_trigger = 0; } |
2244 | 300 } |
301 | |
302 /* is called for rgb only */ | |
303 static uint32_t draw_frame(uint8_t *src[]) | |
304 { | |
2504 | 305 uint8_t *data; |
306 if(verbose > 2) | |
307 printf("vo_vesa: draw_frame was called\n"); | |
308 if(rgb2rgb_fnc) | |
309 { | |
310 (*rgb2rgb_fnc)(src[0],yuv_buffer,image_width*image_height*image_bpp); | |
311 data = yuv_buffer; | |
312 if(verbose > 2) | |
313 printf("vo_vesa: rgb2rgb_fnc was called\n"); | |
314 } | |
315 else data = src[0]; | |
316 __vbeCopyData(data); | |
317 return 0; | |
2244 | 318 } |
319 | |
320 static uint32_t query_format(uint32_t format) | |
321 { | |
322 uint32_t retval; | |
2504 | 323 if(verbose > 2) |
324 printf("vo_vesa: query_format was called: %x (%s)\n",format,vo_format_name(format)); | |
2244 | 325 switch(format) |
326 { | |
327 case IMGFMT_YV12: | |
2296 | 328 #if 0 /* Should be tested better */ |
2244 | 329 case IMGFMT_I420: |
330 case IMGFMT_IYUV: | |
331 #endif | |
332 case IMGFMT_RGB8: | |
333 case IMGFMT_RGB15: | |
334 case IMGFMT_RGB16: | |
335 case IMGFMT_RGB24: | |
336 case IMGFMT_RGB32: | |
337 case IMGFMT_BGR8: | |
338 case IMGFMT_BGR15: | |
339 case IMGFMT_BGR16: | |
340 case IMGFMT_BGR24: | |
341 case IMGFMT_BGR32: | |
342 retval = 1; break; | |
343 default: | |
344 if(verbose) | |
345 printf("vo_vesa: unknown format: %x = %s\n",format,vo_format_name(format)); | |
346 retval = 0; | |
347 } | |
348 return retval; | |
349 } | |
350 | |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
351 static void vesa_aspect(uint32_t width,uint32_t height, |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
352 uint32_t xres,uint32_t yres, |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
353 uint32_t *image_width,uint32_t *image_height) |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
354 { |
2331 | 355 float aspect_factor; |
2328 | 356 aspect_factor = (float)width / height; |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
357 *image_width = xres; |
2328 | 358 *image_height = xres /aspect_factor; |
359 if(verbose) printf("vo_vesa: aspect factor = %f(%ux%u) *image=%ux%u screen=%ux%u\n",aspect_factor,width,height,*image_width,*image_height,xres,yres); | |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
360 if((*image_height) > yres) |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
361 { |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
362 *image_height = yres; |
2328 | 363 *image_width = yres * aspect_factor; |
2329 | 364 if(verbose) printf("vo_vesa: Y > X therefore *image=%ux%u\n",*image_width,*image_height); |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
365 } |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
366 } |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
367 |
2293 | 368 static char *model2str(unsigned char type) |
369 { | |
370 char *retval; | |
371 switch(type) | |
372 { | |
373 case memText: retval = "Text"; break; | |
374 case memCGA: retval="CGA"; break; | |
375 case memHercules: retval="Hercules"; break; | |
376 case memPL: retval="Planar"; break; | |
377 case memPK: retval="Packed pixel"; break; | |
378 case mem256: retval="256"; break; | |
379 case memRGB: retval="Direct color RGB"; break; | |
380 case memYUV: retval="Direct color YUV"; break; | |
381 default: retval="Unknown"; break; | |
382 } | |
383 return retval; | |
384 } | |
385 | |
2244 | 386 /* fullscreen: |
387 * bit 0 (0x01) means fullscreen (-fs) | |
388 * bit 1 (0x02) means mode switching (-vm) | |
389 * bit 2 (0x04) enables software scaling (-zoom) | |
2335 | 390 * bit 3 (0x08) enables flipping (-flip) (NK: and for what?) |
2244 | 391 */ |
392 static uint32_t | |
2329 | 393 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
2244 | 394 { |
395 struct VbeInfoBlock vib; | |
396 struct VesaModeInfoBlock vmib; | |
397 size_t i,num_modes; | |
2329 | 398 uint32_t w,h; |
2244 | 399 unsigned short *mode_ptr,win_seg; |
400 unsigned bpp,best_x = UINT_MAX,best_y=UINT_MAX,best_mode_idx = UINT_MAX; | |
2337 | 401 int err,fs_mode,yuv_fmt; |
2244 | 402 image_width = width; |
403 image_height = height; | |
2336 | 404 fs_mode = 0; |
2504 | 405 rgb2rgb_fnc = NULL; |
2329 | 406 if(flags & 0x8) |
2244 | 407 { |
2329 | 408 printf("vo_vesa: switch -flip is not supported\n"); |
2244 | 409 } |
2329 | 410 if(flags & 0x04) vesa_zoom = 1; |
2336 | 411 if(flags & 0x01) |
412 { | |
413 if(vesa_zoom) vesa_zoom = 2; | |
414 else fs_mode = 1; | |
415 } | |
2244 | 416 if((err=vbeInit()) != VBE_OK) { PRINT_VBE_ERR("vbeInit",err); return -1; } |
417 memcpy(vib.VESASignature,"VBE2",4); | |
418 if((err=vbeGetControllerInfo(&vib)) != VBE_OK) | |
419 { | |
420 PRINT_VBE_ERR("vbeGetControllerInfo",err); | |
421 printf("vo_vesa: possible reason: No VBE2 BIOS found\n"); | |
422 return -1; | |
423 } | |
424 /* Print general info here */ | |
425 printf("vo_vesa: Found VESA VBE BIOS Version %x.%x Revision: %x\n", | |
426 (int)(vib.VESAVersion >> 8) & 0xff, | |
427 (int)(vib.VESAVersion & 0xff), | |
428 (int)(vib.OemSoftwareRev & 0xffff)); | |
2255 | 429 printf("vo_vesa: Video memory: %u Kb\n",vib.TotalMemory*64); |
430 printf("vo_vesa: VESA Capabilities: %s %s %s %s %s\n" | |
431 ,vib.Capabilities & VBE_DAC_8BIT ? "8-bit DAC," : "6-bit DAC," | |
432 ,vib.Capabilities & VBE_NONVGA_CRTC ? "non-VGA CRTC,":"VGA CRTC," | |
433 ,vib.Capabilities & VBE_SNOWED_RAMDAC ? "snowed RAMDAC,":"normal RAMDAC," | |
434 ,vib.Capabilities & VBE_STEREOSCOPIC ? "stereoscopic,":"no stereoscopic," | |
435 ,vib.Capabilities & VBE_STEREO_EVC ? "Stereo EVC":"no stereo"); | |
436 printf("vo_vesa: !!! Below will be printed OEM info. !!!\n"); | |
437 printf("vo_vesa: You should watch 5 OEM related lines below else you've broken vm86\n"); | |
2244 | 438 printf("vo_vesa: OEM info: %s\n",vib.OemStringPtr); |
2255 | 439 printf("vo_vesa: OEM Revision: %x\n",vib.OemSoftwareRev); |
440 printf("vo_vesa: OEM vendor: %s\n",vib.OemVendorNamePtr); | |
441 printf("vo_vesa: OEM Product Name: %s\n",vib.OemProductNamePtr); | |
442 printf("vo_vesa: OEM Product Rev: %s\n",vib.OemProductRevPtr); | |
443 printf("vo_vesa: Hint: To get workable TV-Out you should have plugged tv-connector in\n" | |
444 "vo_vesa: before booting PC since VESA BIOS initializes itself only during POST\n"); | |
2244 | 445 /* Find best mode here */ |
446 num_modes = 0; | |
447 mode_ptr = vib.VideoModePtr; | |
448 while(*mode_ptr++ != 0xffff) num_modes++; | |
2337 | 449 yuv_fmt = format == IMGFMT_YV12 || format == IMGFMT_I420 || format == IMGFMT_IYUV; |
2244 | 450 switch(format) |
451 { | |
452 case IMGFMT_BGR8: | |
453 case IMGFMT_RGB8: bpp = 8; break; | |
454 case IMGFMT_BGR15: | |
455 case IMGFMT_RGB15: bpp = 15; break; | |
2504 | 456 default: |
2244 | 457 case IMGFMT_YV12: |
458 case IMGFMT_I420: | |
2504 | 459 case IMGFMT_IYUV: |
2244 | 460 case IMGFMT_BGR16: |
461 case IMGFMT_RGB16: bpp = 16; break; | |
462 case IMGFMT_BGR24: | |
463 case IMGFMT_RGB24: bpp = 24; break; | |
464 case IMGFMT_BGR32: | |
465 case IMGFMT_RGB32: bpp = 32; break; | |
466 } | |
2504 | 467 image_bpp = bpp; |
468 if(vo_dbpp) bpp = vo_dbpp; | |
469 if(yuv_fmt) yuv2rgb_init(bpp, MODE_RGB); | |
2337 | 470 switch(bpp) |
471 { | |
472 case 15: draw_alpha_fnc = draw_alpha_15; break; | |
473 case 16: draw_alpha_fnc = draw_alpha_16; break; | |
474 case 24: draw_alpha_fnc = draw_alpha_24; break; | |
475 case 32: draw_alpha_fnc = draw_alpha_32; break; | |
476 default: draw_alpha_fnc = draw_alpha_null; break; | |
477 } | |
2244 | 478 if(verbose) |
479 { | |
2304 | 480 printf("vo_vesa: Requested mode: %ux%u@%u (%s)\n",width,height,bpp,vo_format_name(format)); |
2244 | 481 printf("vo_vesa: Total modes found: %u\n",num_modes); |
482 mode_ptr = vib.VideoModePtr; | |
483 printf("vo_vesa: Mode list:"); | |
484 for(i = 0;i < num_modes;i++) | |
485 { | |
486 printf(" %04X",mode_ptr[i]); | |
487 } | |
488 printf("\nvo_vesa: Modes in detail:\n"); | |
489 } | |
490 mode_ptr = vib.VideoModePtr; | |
2335 | 491 if(vesa_zoom) |
492 { | |
493 image_width = d_width; | |
494 image_height= d_height; | |
495 } | |
496 if(vo_screenwidth) w = vo_screenwidth; | |
497 else w = max(image_width,width); | |
498 if(vo_screenheight) h = vo_screenheight; | |
499 else h = max(image_height,height); | |
2244 | 500 for(i=0;i < num_modes;i++) |
501 { | |
502 if((err=vbeGetModeInfo(mode_ptr[i],&vmib)) != VBE_OK) | |
503 { | |
504 PRINT_VBE_ERR("vbeGetModeInfo",err); | |
505 return -1; | |
506 } | |
2329 | 507 if(vmib.XResolution >= w && |
508 vmib.YResolution >= h && | |
2244 | 509 (vmib.ModeAttributes & MOVIE_MODE) == MOVIE_MODE && |
510 vmib.BitsPerPixel == bpp && | |
511 vmib.MemoryModel == memRGB) | |
512 { | |
2293 | 513 if(vmib.XResolution <= best_x && |
514 vmib.YResolution <= best_y) | |
2244 | 515 { |
516 best_x = vmib.XResolution; | |
517 best_y = vmib.YResolution; | |
518 best_mode_idx = i; | |
519 } | |
520 } | |
521 if(verbose) | |
522 { | |
2298 | 523 printf("vo_vesa: Mode (%03u): mode=%04X %ux%u@%u attr=%04X\n" |
2293 | 524 "vo_vesa: #planes=%u model=%u(%s) #pages=%u\n" |
525 "vo_vesa: winA=%X(attr=%u) winB=%X(attr=%u) winSize=%u winGran=%u\n" | |
2446 | 526 "vo_vesa: direct_color=%u DGA_phys_addr=%08lX\n" |
2244 | 527 ,i,mode_ptr[i],vmib.XResolution,vmib.YResolution,vmib.BitsPerPixel,vmib.ModeAttributes |
2293 | 528 ,vmib.NumberOfPlanes,vmib.MemoryModel,model2str(vmib.MemoryModel),vmib.NumberOfImagePages |
2244 | 529 ,vmib.WinASegment,vmib.WinAAttributes,vmib.WinBSegment,vmib.WinBAttributes,vmib.WinSize,vmib.WinGranularity |
530 ,vmib.DirectColorModeInfo,vmib.PhysBasePtr); | |
531 if(vmib.MemoryModel == 6 || vmib.MemoryModel == 7) | |
532 printf("vo_vesa: direct_color_info = %u:%u:%u:%u\n" | |
533 ,vmib.RedMaskSize,vmib.GreenMaskSize,vmib.BlueMaskSize,vmib.RsvdMaskSize); | |
534 fflush(stdout); | |
535 } | |
536 } | |
537 if(best_mode_idx != UINT_MAX) | |
538 { | |
539 video_mode = vib.VideoModePtr[best_mode_idx]; | |
540 fflush(stdout); | |
541 if((err=vbeGetMode(&init_mode)) != VBE_OK) | |
542 { | |
543 PRINT_VBE_ERR("vbeGetMode",err); | |
544 return -1; | |
545 } | |
546 if(verbose) printf("vo_vesa: Initial video mode: %x\n",init_mode); | |
547 if((err=vbeGetModeInfo(video_mode,&video_mode_info)) != VBE_OK) | |
548 { | |
549 PRINT_VBE_ERR("vbeGetModeInfo",err); | |
550 return -1; | |
551 } | |
2329 | 552 printf("vo_vesa: Using VESA mode (%u) = %x [%ux%u@%u]\n" |
553 ,best_mode_idx,video_mode,video_mode_info.XResolution | |
554 ,video_mode_info.YResolution,video_mode_info.BitsPerPixel); | |
2336 | 555 if( vesa_zoom || fs_mode ) |
2298 | 556 { |
2304 | 557 if( format==IMGFMT_YV12 ) |
558 { | |
559 /* software scale */ | |
2329 | 560 if(vesa_zoom > 1) |
2335 | 561 vesa_aspect(image_width,image_height, |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
562 video_mode_info.XResolution,video_mode_info.YResolution, |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
563 &image_width,&image_height); |
2336 | 564 else |
565 if(fs_mode) | |
566 { | |
567 image_width = video_mode_info.XResolution; | |
568 image_height = video_mode_info.YResolution; | |
569 vesa_zoom = 1; | |
570 } | |
2304 | 571 scale_xinc=(width << 16) / image_width - 2; /* needed for proper rounding */ |
572 scale_yinc=(height << 16) / image_height + 2; | |
573 SwScale_Init(); | |
574 if(verbose) printf("vo_vesa: Using SCALE\n"); | |
575 } | |
576 else | |
577 { | |
578 printf("vo_vesa: Can't apply zooming to non YV12 formats\n"); | |
579 return -1; | |
580 } | |
2298 | 581 } |
2504 | 582 if(format != IMGFMT_YV12 && image_bpp != video_mode_info.BitsPerPixel) |
583 { | |
584 if(image_bpp == 24 && video_mode_info.BitsPerPixel == 32) rgb2rgb_fnc = rgb24to32; | |
585 else | |
2505 | 586 if(image_bpp == 32 && video_mode_info.BitsPerPixel == 24) rgb2rgb_fnc = rgb32to24; |
587 else | |
2506 | 588 if(image_bpp == 15 && video_mode_info.BitsPerPixel == 16) rgb2rgb_fnc = rgb15to16; |
589 else | |
2504 | 590 { |
591 printf("vo_vesa: Can't convert %u to %u\n",image_bpp,video_mode_info.BitsPerPixel); | |
592 return -1; | |
593 } | |
594 if(verbose) printf("vo_vesa: using %u to %u sw convertor\n",image_bpp,video_mode_info.BitsPerPixel); | |
595 } | |
2244 | 596 if((video_mode_info.WinAAttributes & FRAME_MODE) == FRAME_MODE) |
597 win.idx = 0; /* frame A */ | |
598 else | |
599 if((video_mode_info.WinBAttributes & FRAME_MODE) == FRAME_MODE) | |
600 win.idx = 1; /* frame B */ | |
601 else { printf("vo_vesa: Can't find usable frame of window\n"); return -1; } | |
602 if(!(win_seg = win.idx == 0 ? video_mode_info.WinASegment:video_mode_info.WinBSegment)) | |
603 { | |
604 printf("vo_vesa: Can't find valid window address\n"); | |
605 if(video_mode_info.ModeAttributes & MODE_ATTR_LINEAR) | |
606 printf("vo_vesa: Your BIOS supports DGA access which is not implemented for now\n"); | |
607 return -1; | |
608 } | |
609 win.ptr = PhysToVirtSO(win_seg,0); | |
610 win.low = 0L; | |
611 win.high= video_mode_info.WinSize*1024; | |
2329 | 612 if(video_mode_info.XResolution > image_width) |
613 x_offset = (video_mode_info.XResolution - image_width) / 2; | |
614 else x_offset = 0; | |
615 if(video_mode_info.YResolution > image_height) | |
616 y_offset = (video_mode_info.YResolution - image_height) / 2; | |
617 else y_offset = 0; | |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
618 if(verbose) |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
619 printf("vo_vesa: image: %ux%u screen = %ux%u x_offset = %u y_offset = %u\n" |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
620 ,image_width,image_height |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
621 ,video_mode_info.XResolution,video_mode_info.YResolution |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
622 ,x_offset,y_offset); |
2504 | 623 if(yuv_fmt || rgb2rgb_fnc) |
624 { | |
625 if(!(yuv_buffer = malloc(video_mode_info.XResolution*video_mode_info.YResolution*video_mode_info.BitsPerPixel))) | |
2337 | 626 { |
627 printf("vo_vesa: Can't allocate temporary buffer\n"); | |
628 return -1; | |
629 } | |
2504 | 630 if(verbose) printf("vo_vesa: yuv_buffer was allocated = %p\n",yuv_buffer); |
631 } | |
2244 | 632 if((err=vbeSaveState(&init_state)) != VBE_OK) |
633 { | |
634 PRINT_VBE_ERR("vbeSaveState",err); | |
635 return -1; | |
636 } | |
637 if((err=vbeSetMode(video_mode,NULL)) != VBE_OK) | |
638 { | |
639 PRINT_VBE_ERR("vbeSetMode",err); | |
640 return -1; | |
641 } | |
642 /* Now we are in video mode!!!*/ | |
2337 | 643 /* Below 'return -1' is impossible */ |
2244 | 644 if(verbose) |
645 { | |
646 printf("vo_vesa: Graphics mode was activated\n"); | |
647 fflush(stdout); | |
648 } | |
649 } | |
650 else | |
651 { | |
2255 | 652 printf("vo_vesa: Can't find mode for: %ux%u@%u\n",width,height,bpp); |
2244 | 653 return -1; |
654 } | |
655 if(verbose) | |
656 { | |
657 printf("vo_vesa: VESA initialization complete\n"); | |
658 fflush(stdout); | |
659 } | |
660 if(verbose) | |
661 { | |
662 int x_res = video_mode_info.XResolution; | |
663 int y_res = video_mode_info.YResolution; | |
664 int x, y; | |
665 | |
666 for (y = 0; y < y_res; ++y) | |
667 { | |
668 for (x = 0; x < x_res; ++x) | |
669 { | |
670 int r, g, b; | |
671 if ((x & 16) ^ (y & 16)) | |
672 { | |
673 r = x * 255 / x_res; | |
674 g = y * 255 / y_res; | |
675 b = 255 - x * 255 / x_res; | |
676 } | |
677 else | |
678 { | |
679 r = 255 - x * 255 / x_res; | |
680 g = y * 255 / y_res; | |
681 b = 255 - y * 255 / y_res; | |
682 } | |
683 | |
684 __vbeSetPixel(x, y, r, g, b); | |
685 } | |
686 } | |
687 } | |
2410 | 688 vbeWriteString(0,0,7,title); |
2244 | 689 return 0; |
690 } | |
691 | |
692 static const vo_info_t* | |
693 get_info(void) | |
694 { | |
2504 | 695 if(verbose > 2) |
696 printf("vo_vesa: get_info was called\n"); | |
2244 | 697 return &vo_info; |
698 } | |
699 | |
700 static void | |
701 uninit(void) | |
702 { | |
2504 | 703 if(verbose > 2) |
704 printf("vo_vesa: uninit was called\n"); | |
2244 | 705 vesa_term(); |
706 } | |
707 | |
708 | |
709 static void check_events(void) | |
710 { | |
2504 | 711 if(verbose > 2) |
712 printf("vo_vesa: check_events was called\n"); | |
2244 | 713 /* Nothing to do */ |
714 } |