Mercurial > mplayer.hg
annotate libvo/vo_vesa.c @ 2504:13e1c5ab417a
vo_vesa: rgb2rgb support
author | nick |
---|---|
date | Sun, 28 Oct 2001 10:17:57 +0000 |
parents | 6fb598bd7ede |
children | 2aaa11d22f91 |
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> | |
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 { | |
249 SwScale_YV12slice_brg24(image,stride,y,h, | |
250 yuv_buffer, | |
251 image_width*((video_mode_info.BitsPerPixel+7)/8), | |
252 image_width, video_mode_info.BitsPerPixel, | |
253 scale_xinc, scale_yinc); | |
254 } | |
255 else | |
256 { | |
2331 | 257 uint8_t *yuv_slice; |
258 yuv_slice=yuv_buffer+(image_width*y+x)*((video_mode_info.BitsPerPixel+7)/8); | |
259 yuv2rgb(yuv_slice, image[0], image[1], image[2], w, h, | |
2293 | 260 image_width * ((video_mode_info.BitsPerPixel+7)/8), |
2244 | 261 stride[0], stride[1]); |
2298 | 262 } |
2331 | 263 flip_trigger = 1; |
2298 | 264 return 0; |
2244 | 265 } |
266 | |
2337 | 267 static void draw_alpha_32(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ |
268 vo_draw_alpha_rgb32(w,h,src,srca,stride,yuv_buffer+4*(y0*image_width+x0),4*image_width); | |
269 } | |
270 | |
271 static void draw_alpha_24(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
272 vo_draw_alpha_rgb24(w,h,src,srca,stride,yuv_buffer+3*(y0*image_width+x0),3*image_width); | |
273 } | |
274 | |
275 static void draw_alpha_16(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
276 vo_draw_alpha_rgb16(w,h,src,srca,stride,yuv_buffer+2*(y0*image_width+x0),2*image_width); | |
277 } | |
278 | |
279 static void draw_alpha_15(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
280 vo_draw_alpha_rgb15(w,h,src,srca,stride,yuv_buffer+2*(y0*image_width+x0),2*image_width); | |
281 } | |
282 | |
283 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
284 } | |
285 | |
286 | |
2244 | 287 static void draw_osd(void) |
288 { | |
2504 | 289 if(verbose > 2) |
290 printf("vo_vesa: draw_osd was called\n"); | |
2337 | 291 if(yuv_buffer) vo_draw_text(image_width,image_height,draw_alpha_fnc); |
2244 | 292 } |
293 | |
294 static void flip_page(void) | |
295 { | |
2504 | 296 if(verbose > 2) |
297 printf("vo_vesa: flip_page was called\n"); | |
2331 | 298 if(flip_trigger) { __vbeCopyData(yuv_buffer); flip_trigger = 0; } |
2244 | 299 } |
300 | |
301 /* is called for rgb only */ | |
302 static uint32_t draw_frame(uint8_t *src[]) | |
303 { | |
2504 | 304 uint8_t *data; |
305 if(verbose > 2) | |
306 printf("vo_vesa: draw_frame was called\n"); | |
307 if(rgb2rgb_fnc) | |
308 { | |
309 (*rgb2rgb_fnc)(src[0],yuv_buffer,image_width*image_height*image_bpp); | |
310 data = yuv_buffer; | |
311 if(verbose > 2) | |
312 printf("vo_vesa: rgb2rgb_fnc was called\n"); | |
313 } | |
314 else data = src[0]; | |
315 __vbeCopyData(data); | |
316 return 0; | |
2244 | 317 } |
318 | |
319 static uint32_t query_format(uint32_t format) | |
320 { | |
321 uint32_t retval; | |
2504 | 322 if(verbose > 2) |
323 printf("vo_vesa: query_format was called: %x (%s)\n",format,vo_format_name(format)); | |
2244 | 324 switch(format) |
325 { | |
326 case IMGFMT_YV12: | |
2296 | 327 #if 0 /* Should be tested better */ |
2244 | 328 case IMGFMT_I420: |
329 case IMGFMT_IYUV: | |
330 #endif | |
331 case IMGFMT_RGB8: | |
332 case IMGFMT_RGB15: | |
333 case IMGFMT_RGB16: | |
334 case IMGFMT_RGB24: | |
335 case IMGFMT_RGB32: | |
336 case IMGFMT_BGR8: | |
337 case IMGFMT_BGR15: | |
338 case IMGFMT_BGR16: | |
339 case IMGFMT_BGR24: | |
340 case IMGFMT_BGR32: | |
341 retval = 1; break; | |
342 default: | |
343 if(verbose) | |
344 printf("vo_vesa: unknown format: %x = %s\n",format,vo_format_name(format)); | |
345 retval = 0; | |
346 } | |
347 return retval; | |
348 } | |
349 | |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
350 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
|
351 uint32_t xres,uint32_t yres, |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
352 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
|
353 { |
2331 | 354 float aspect_factor; |
2328 | 355 aspect_factor = (float)width / height; |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
356 *image_width = xres; |
2328 | 357 *image_height = xres /aspect_factor; |
358 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
|
359 if((*image_height) > yres) |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
360 { |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
361 *image_height = yres; |
2328 | 362 *image_width = yres * aspect_factor; |
2329 | 363 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
|
364 } |
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 |
2293 | 367 static char *model2str(unsigned char type) |
368 { | |
369 char *retval; | |
370 switch(type) | |
371 { | |
372 case memText: retval = "Text"; break; | |
373 case memCGA: retval="CGA"; break; | |
374 case memHercules: retval="Hercules"; break; | |
375 case memPL: retval="Planar"; break; | |
376 case memPK: retval="Packed pixel"; break; | |
377 case mem256: retval="256"; break; | |
378 case memRGB: retval="Direct color RGB"; break; | |
379 case memYUV: retval="Direct color YUV"; break; | |
380 default: retval="Unknown"; break; | |
381 } | |
382 return retval; | |
383 } | |
384 | |
2244 | 385 /* fullscreen: |
386 * bit 0 (0x01) means fullscreen (-fs) | |
387 * bit 1 (0x02) means mode switching (-vm) | |
388 * bit 2 (0x04) enables software scaling (-zoom) | |
2335 | 389 * bit 3 (0x08) enables flipping (-flip) (NK: and for what?) |
2244 | 390 */ |
391 static uint32_t | |
2329 | 392 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
2244 | 393 { |
394 struct VbeInfoBlock vib; | |
395 struct VesaModeInfoBlock vmib; | |
396 size_t i,num_modes; | |
2329 | 397 uint32_t w,h; |
2244 | 398 unsigned short *mode_ptr,win_seg; |
399 unsigned bpp,best_x = UINT_MAX,best_y=UINT_MAX,best_mode_idx = UINT_MAX; | |
2337 | 400 int err,fs_mode,yuv_fmt; |
2244 | 401 image_width = width; |
402 image_height = height; | |
2336 | 403 fs_mode = 0; |
2504 | 404 rgb2rgb_fnc = NULL; |
2329 | 405 if(flags & 0x8) |
2244 | 406 { |
2329 | 407 printf("vo_vesa: switch -flip is not supported\n"); |
2244 | 408 } |
2329 | 409 if(flags & 0x04) vesa_zoom = 1; |
2336 | 410 if(flags & 0x01) |
411 { | |
412 if(vesa_zoom) vesa_zoom = 2; | |
413 else fs_mode = 1; | |
414 } | |
2244 | 415 if((err=vbeInit()) != VBE_OK) { PRINT_VBE_ERR("vbeInit",err); return -1; } |
416 memcpy(vib.VESASignature,"VBE2",4); | |
417 if((err=vbeGetControllerInfo(&vib)) != VBE_OK) | |
418 { | |
419 PRINT_VBE_ERR("vbeGetControllerInfo",err); | |
420 printf("vo_vesa: possible reason: No VBE2 BIOS found\n"); | |
421 return -1; | |
422 } | |
423 /* Print general info here */ | |
424 printf("vo_vesa: Found VESA VBE BIOS Version %x.%x Revision: %x\n", | |
425 (int)(vib.VESAVersion >> 8) & 0xff, | |
426 (int)(vib.VESAVersion & 0xff), | |
427 (int)(vib.OemSoftwareRev & 0xffff)); | |
2255 | 428 printf("vo_vesa: Video memory: %u Kb\n",vib.TotalMemory*64); |
429 printf("vo_vesa: VESA Capabilities: %s %s %s %s %s\n" | |
430 ,vib.Capabilities & VBE_DAC_8BIT ? "8-bit DAC," : "6-bit DAC," | |
431 ,vib.Capabilities & VBE_NONVGA_CRTC ? "non-VGA CRTC,":"VGA CRTC," | |
432 ,vib.Capabilities & VBE_SNOWED_RAMDAC ? "snowed RAMDAC,":"normal RAMDAC," | |
433 ,vib.Capabilities & VBE_STEREOSCOPIC ? "stereoscopic,":"no stereoscopic," | |
434 ,vib.Capabilities & VBE_STEREO_EVC ? "Stereo EVC":"no stereo"); | |
435 printf("vo_vesa: !!! Below will be printed OEM info. !!!\n"); | |
436 printf("vo_vesa: You should watch 5 OEM related lines below else you've broken vm86\n"); | |
2244 | 437 printf("vo_vesa: OEM info: %s\n",vib.OemStringPtr); |
2255 | 438 printf("vo_vesa: OEM Revision: %x\n",vib.OemSoftwareRev); |
439 printf("vo_vesa: OEM vendor: %s\n",vib.OemVendorNamePtr); | |
440 printf("vo_vesa: OEM Product Name: %s\n",vib.OemProductNamePtr); | |
441 printf("vo_vesa: OEM Product Rev: %s\n",vib.OemProductRevPtr); | |
442 printf("vo_vesa: Hint: To get workable TV-Out you should have plugged tv-connector in\n" | |
443 "vo_vesa: before booting PC since VESA BIOS initializes itself only during POST\n"); | |
2244 | 444 /* Find best mode here */ |
445 num_modes = 0; | |
446 mode_ptr = vib.VideoModePtr; | |
447 while(*mode_ptr++ != 0xffff) num_modes++; | |
2337 | 448 yuv_fmt = format == IMGFMT_YV12 || format == IMGFMT_I420 || format == IMGFMT_IYUV; |
2244 | 449 switch(format) |
450 { | |
451 case IMGFMT_BGR8: | |
452 case IMGFMT_RGB8: bpp = 8; break; | |
453 case IMGFMT_BGR15: | |
454 case IMGFMT_RGB15: bpp = 15; break; | |
2504 | 455 default: |
2244 | 456 case IMGFMT_YV12: |
457 case IMGFMT_I420: | |
2504 | 458 case IMGFMT_IYUV: |
2244 | 459 case IMGFMT_BGR16: |
460 case IMGFMT_RGB16: bpp = 16; break; | |
461 case IMGFMT_BGR24: | |
462 case IMGFMT_RGB24: bpp = 24; break; | |
463 case IMGFMT_BGR32: | |
464 case IMGFMT_RGB32: bpp = 32; break; | |
465 } | |
2504 | 466 image_bpp = bpp; |
467 if(vo_dbpp) bpp = vo_dbpp; | |
468 if(yuv_fmt) yuv2rgb_init(bpp, MODE_RGB); | |
2337 | 469 switch(bpp) |
470 { | |
471 case 15: draw_alpha_fnc = draw_alpha_15; break; | |
472 case 16: draw_alpha_fnc = draw_alpha_16; break; | |
473 case 24: draw_alpha_fnc = draw_alpha_24; break; | |
474 case 32: draw_alpha_fnc = draw_alpha_32; break; | |
475 default: draw_alpha_fnc = draw_alpha_null; break; | |
476 } | |
2244 | 477 if(verbose) |
478 { | |
2304 | 479 printf("vo_vesa: Requested mode: %ux%u@%u (%s)\n",width,height,bpp,vo_format_name(format)); |
2244 | 480 printf("vo_vesa: Total modes found: %u\n",num_modes); |
481 mode_ptr = vib.VideoModePtr; | |
482 printf("vo_vesa: Mode list:"); | |
483 for(i = 0;i < num_modes;i++) | |
484 { | |
485 printf(" %04X",mode_ptr[i]); | |
486 } | |
487 printf("\nvo_vesa: Modes in detail:\n"); | |
488 } | |
489 mode_ptr = vib.VideoModePtr; | |
2335 | 490 if(vesa_zoom) |
491 { | |
492 image_width = d_width; | |
493 image_height= d_height; | |
494 } | |
495 if(vo_screenwidth) w = vo_screenwidth; | |
496 else w = max(image_width,width); | |
497 if(vo_screenheight) h = vo_screenheight; | |
498 else h = max(image_height,height); | |
2244 | 499 for(i=0;i < num_modes;i++) |
500 { | |
501 if((err=vbeGetModeInfo(mode_ptr[i],&vmib)) != VBE_OK) | |
502 { | |
503 PRINT_VBE_ERR("vbeGetModeInfo",err); | |
504 return -1; | |
505 } | |
2329 | 506 if(vmib.XResolution >= w && |
507 vmib.YResolution >= h && | |
2244 | 508 (vmib.ModeAttributes & MOVIE_MODE) == MOVIE_MODE && |
509 vmib.BitsPerPixel == bpp && | |
510 vmib.MemoryModel == memRGB) | |
511 { | |
2293 | 512 if(vmib.XResolution <= best_x && |
513 vmib.YResolution <= best_y) | |
2244 | 514 { |
515 best_x = vmib.XResolution; | |
516 best_y = vmib.YResolution; | |
517 best_mode_idx = i; | |
518 } | |
519 } | |
520 if(verbose) | |
521 { | |
2298 | 522 printf("vo_vesa: Mode (%03u): mode=%04X %ux%u@%u attr=%04X\n" |
2293 | 523 "vo_vesa: #planes=%u model=%u(%s) #pages=%u\n" |
524 "vo_vesa: winA=%X(attr=%u) winB=%X(attr=%u) winSize=%u winGran=%u\n" | |
2446 | 525 "vo_vesa: direct_color=%u DGA_phys_addr=%08lX\n" |
2244 | 526 ,i,mode_ptr[i],vmib.XResolution,vmib.YResolution,vmib.BitsPerPixel,vmib.ModeAttributes |
2293 | 527 ,vmib.NumberOfPlanes,vmib.MemoryModel,model2str(vmib.MemoryModel),vmib.NumberOfImagePages |
2244 | 528 ,vmib.WinASegment,vmib.WinAAttributes,vmib.WinBSegment,vmib.WinBAttributes,vmib.WinSize,vmib.WinGranularity |
529 ,vmib.DirectColorModeInfo,vmib.PhysBasePtr); | |
530 if(vmib.MemoryModel == 6 || vmib.MemoryModel == 7) | |
531 printf("vo_vesa: direct_color_info = %u:%u:%u:%u\n" | |
532 ,vmib.RedMaskSize,vmib.GreenMaskSize,vmib.BlueMaskSize,vmib.RsvdMaskSize); | |
533 fflush(stdout); | |
534 } | |
535 } | |
536 if(best_mode_idx != UINT_MAX) | |
537 { | |
538 video_mode = vib.VideoModePtr[best_mode_idx]; | |
539 fflush(stdout); | |
540 if((err=vbeGetMode(&init_mode)) != VBE_OK) | |
541 { | |
542 PRINT_VBE_ERR("vbeGetMode",err); | |
543 return -1; | |
544 } | |
545 if(verbose) printf("vo_vesa: Initial video mode: %x\n",init_mode); | |
546 if((err=vbeGetModeInfo(video_mode,&video_mode_info)) != VBE_OK) | |
547 { | |
548 PRINT_VBE_ERR("vbeGetModeInfo",err); | |
549 return -1; | |
550 } | |
2329 | 551 printf("vo_vesa: Using VESA mode (%u) = %x [%ux%u@%u]\n" |
552 ,best_mode_idx,video_mode,video_mode_info.XResolution | |
553 ,video_mode_info.YResolution,video_mode_info.BitsPerPixel); | |
2336 | 554 if( vesa_zoom || fs_mode ) |
2298 | 555 { |
2304 | 556 if( format==IMGFMT_YV12 ) |
557 { | |
558 /* software scale */ | |
2329 | 559 if(vesa_zoom > 1) |
2335 | 560 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
|
561 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
|
562 &image_width,&image_height); |
2336 | 563 else |
564 if(fs_mode) | |
565 { | |
566 image_width = video_mode_info.XResolution; | |
567 image_height = video_mode_info.YResolution; | |
568 vesa_zoom = 1; | |
569 } | |
2304 | 570 scale_xinc=(width << 16) / image_width - 2; /* needed for proper rounding */ |
571 scale_yinc=(height << 16) / image_height + 2; | |
572 SwScale_Init(); | |
573 if(verbose) printf("vo_vesa: Using SCALE\n"); | |
574 } | |
575 else | |
576 { | |
577 printf("vo_vesa: Can't apply zooming to non YV12 formats\n"); | |
578 return -1; | |
579 } | |
2298 | 580 } |
2504 | 581 if(format != IMGFMT_YV12 && image_bpp != video_mode_info.BitsPerPixel) |
582 { | |
583 if(image_bpp == 24 && video_mode_info.BitsPerPixel == 32) rgb2rgb_fnc = rgb24to32; | |
584 else | |
585 { | |
586 printf("vo_vesa: Can't convert %u to %u\n",image_bpp,video_mode_info.BitsPerPixel); | |
587 return -1; | |
588 } | |
589 if(verbose) printf("vo_vesa: using %u to %u sw convertor\n",image_bpp,video_mode_info.BitsPerPixel); | |
590 } | |
2244 | 591 if((video_mode_info.WinAAttributes & FRAME_MODE) == FRAME_MODE) |
592 win.idx = 0; /* frame A */ | |
593 else | |
594 if((video_mode_info.WinBAttributes & FRAME_MODE) == FRAME_MODE) | |
595 win.idx = 1; /* frame B */ | |
596 else { printf("vo_vesa: Can't find usable frame of window\n"); return -1; } | |
597 if(!(win_seg = win.idx == 0 ? video_mode_info.WinASegment:video_mode_info.WinBSegment)) | |
598 { | |
599 printf("vo_vesa: Can't find valid window address\n"); | |
600 if(video_mode_info.ModeAttributes & MODE_ATTR_LINEAR) | |
601 printf("vo_vesa: Your BIOS supports DGA access which is not implemented for now\n"); | |
602 return -1; | |
603 } | |
604 win.ptr = PhysToVirtSO(win_seg,0); | |
605 win.low = 0L; | |
606 win.high= video_mode_info.WinSize*1024; | |
2329 | 607 if(video_mode_info.XResolution > image_width) |
608 x_offset = (video_mode_info.XResolution - image_width) / 2; | |
609 else x_offset = 0; | |
610 if(video_mode_info.YResolution > image_height) | |
611 y_offset = (video_mode_info.YResolution - image_height) / 2; | |
612 else y_offset = 0; | |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
613 if(verbose) |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
614 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
|
615 ,image_width,image_height |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
616 ,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
|
617 ,x_offset,y_offset); |
2504 | 618 if(yuv_fmt || rgb2rgb_fnc) |
619 { | |
620 if(!(yuv_buffer = malloc(video_mode_info.XResolution*video_mode_info.YResolution*video_mode_info.BitsPerPixel))) | |
2337 | 621 { |
622 printf("vo_vesa: Can't allocate temporary buffer\n"); | |
623 return -1; | |
624 } | |
2504 | 625 if(verbose) printf("vo_vesa: yuv_buffer was allocated = %p\n",yuv_buffer); |
626 } | |
2244 | 627 if((err=vbeSaveState(&init_state)) != VBE_OK) |
628 { | |
629 PRINT_VBE_ERR("vbeSaveState",err); | |
630 return -1; | |
631 } | |
632 if((err=vbeSetMode(video_mode,NULL)) != VBE_OK) | |
633 { | |
634 PRINT_VBE_ERR("vbeSetMode",err); | |
635 return -1; | |
636 } | |
637 /* Now we are in video mode!!!*/ | |
2337 | 638 /* Below 'return -1' is impossible */ |
2244 | 639 if(verbose) |
640 { | |
641 printf("vo_vesa: Graphics mode was activated\n"); | |
642 fflush(stdout); | |
643 } | |
644 } | |
645 else | |
646 { | |
2255 | 647 printf("vo_vesa: Can't find mode for: %ux%u@%u\n",width,height,bpp); |
2244 | 648 return -1; |
649 } | |
650 if(verbose) | |
651 { | |
652 printf("vo_vesa: VESA initialization complete\n"); | |
653 fflush(stdout); | |
654 } | |
655 if(verbose) | |
656 { | |
657 int x_res = video_mode_info.XResolution; | |
658 int y_res = video_mode_info.YResolution; | |
659 int x, y; | |
660 | |
661 for (y = 0; y < y_res; ++y) | |
662 { | |
663 for (x = 0; x < x_res; ++x) | |
664 { | |
665 int r, g, b; | |
666 if ((x & 16) ^ (y & 16)) | |
667 { | |
668 r = x * 255 / x_res; | |
669 g = y * 255 / y_res; | |
670 b = 255 - x * 255 / x_res; | |
671 } | |
672 else | |
673 { | |
674 r = 255 - x * 255 / x_res; | |
675 g = y * 255 / y_res; | |
676 b = 255 - y * 255 / y_res; | |
677 } | |
678 | |
679 __vbeSetPixel(x, y, r, g, b); | |
680 } | |
681 } | |
682 } | |
2410 | 683 vbeWriteString(0,0,7,title); |
2244 | 684 return 0; |
685 } | |
686 | |
687 static const vo_info_t* | |
688 get_info(void) | |
689 { | |
2504 | 690 if(verbose > 2) |
691 printf("vo_vesa: get_info was called\n"); | |
2244 | 692 return &vo_info; |
693 } | |
694 | |
695 static void | |
696 uninit(void) | |
697 { | |
2504 | 698 if(verbose > 2) |
699 printf("vo_vesa: uninit was called\n"); | |
2244 | 700 vesa_term(); |
701 } | |
702 | |
703 | |
704 static void check_events(void) | |
705 { | |
2504 | 706 if(verbose > 2) |
707 printf("vo_vesa: check_events was called\n"); | |
2244 | 708 /* Nothing to do */ |
709 } |