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