Mercurial > mplayer.hg
comparison libvo/vo_vesa.c @ 2293:638cd37032da
Better resolution detection
author | nick |
---|---|
date | Fri, 19 Oct 2001 15:09:40 +0000 |
parents | 98c2bfc87825 |
children | 1d100b2d668c |
comparison
equal
deleted
inserted
replaced
2292:d57280ca1db9 | 2293:638cd37032da |
---|---|
70 static uint32_t image_width, image_height; /* source image dimension */ | 70 static uint32_t image_width, image_height; /* source image dimension */ |
71 static uint32_t x_offset,y_offset; /* to center image on screen */ | 71 static uint32_t x_offset,y_offset; /* to center image on screen */ |
72 static unsigned init_mode; /* mode before run of mplayer */ | 72 static unsigned init_mode; /* mode before run of mplayer */ |
73 static void *init_state = NULL; /* state before run of mplayer */ | 73 static void *init_state = NULL; /* state before run of mplayer */ |
74 static struct win_frame win; /* real-mode window to video memory */ | 74 static struct win_frame win; /* real-mode window to video memory */ |
75 static void *temp_buffer = NULL; /* for yuv2rgb and sw_scaling */ | 75 static void *yuv_buffer = NULL; /* for yuv2rgb and sw_scaling */ |
76 static unsigned video_mode; /* selected video mode for playback */ | 76 static unsigned video_mode; /* selected video mode for playback */ |
77 static struct VesaModeInfoBlock video_mode_info; | 77 static struct VesaModeInfoBlock video_mode_info; |
78 | 78 |
79 #define MOVIE_MODE (MODE_ATTR_COLOR | MODE_ATTR_GRAPHICS) | 79 #define MOVIE_MODE (MODE_ATTR_COLOR | MODE_ATTR_GRAPHICS) |
80 #define FRAME_MODE (MODE_WIN_RELOCATABLE | MODE_WIN_READABLE | MODE_WIN_WRITEABLE) | 80 #define FRAME_MODE (MODE_WIN_RELOCATABLE | MODE_WIN_READABLE | MODE_WIN_WRITEABLE) |
104 static void vesa_term( void ) | 104 static void vesa_term( void ) |
105 { | 105 { |
106 int err; | 106 int err; |
107 if((err=vbeRestoreState(init_state)) != VBE_OK) PRINT_VBE_ERR("vbeRestoreState",err); | 107 if((err=vbeRestoreState(init_state)) != VBE_OK) PRINT_VBE_ERR("vbeRestoreState",err); |
108 if((err=vbeSetMode(init_mode,NULL)) != VBE_OK) PRINT_VBE_ERR("vbeSetMode",err); | 108 if((err=vbeSetMode(init_mode,NULL)) != VBE_OK) PRINT_VBE_ERR("vbeSetMode",err); |
109 free(temp_buffer); | 109 free(yuv_buffer); |
110 vbeDestroy(); | 110 vbeDestroy(); |
111 } | 111 } |
112 | 112 |
113 #define VALID_WIN_FRAME(offset) (offset >= win.low && offset < win.high) | 113 #define VALID_WIN_FRAME(offset) (offset >= win.low && offset < win.high) |
114 #define VIDEO_PTR(offset) (win.ptr + offset - win.low) | 114 #define VIDEO_PTR(offset) (win.ptr + offset - win.low) |
220 } | 220 } |
221 } | 221 } |
222 /* is called for yuv only */ | 222 /* is called for yuv only */ |
223 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | 223 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) |
224 { | 224 { |
225 yuv2rgb(temp_buffer, image[0], image[1], image[2], w, h, image_width * ((video_mode_info.BitsPerPixel+7)/8), | 225 yuv2rgb(yuv_buffer, image[0], image[1], image[2], w, h, |
226 image_width * ((video_mode_info.BitsPerPixel+7)/8), | |
226 stride[0], stride[1]); | 227 stride[0], stride[1]); |
227 __vbeCopyData((uint8_t *)temp_buffer); | 228 __vbeCopyData((uint8_t *)yuv_buffer); |
228 return 0; | 229 return 0; |
229 } | 230 } |
230 | 231 |
231 static void draw_osd(void) | 232 static void draw_osd(void) |
232 { | 233 { |
272 retval = 0; | 273 retval = 0; |
273 } | 274 } |
274 return retval; | 275 return retval; |
275 } | 276 } |
276 | 277 |
278 static char *model2str(unsigned char type) | |
279 { | |
280 char *retval; | |
281 switch(type) | |
282 { | |
283 case memText: retval = "Text"; break; | |
284 case memCGA: retval="CGA"; break; | |
285 case memHercules: retval="Hercules"; break; | |
286 case memPL: retval="Planar"; break; | |
287 case memPK: retval="Packed pixel"; break; | |
288 case mem256: retval="256"; break; | |
289 case memRGB: retval="Direct color RGB"; break; | |
290 case memYUV: retval="Direct color YUV"; break; | |
291 default: retval="Unknown"; break; | |
292 } | |
293 return retval; | |
294 } | |
295 | |
277 /* fullscreen: | 296 /* fullscreen: |
278 * bit 0 (0x01) means fullscreen (-fs) | 297 * bit 0 (0x01) means fullscreen (-fs) |
279 * bit 1 (0x02) means mode switching (-vm) | 298 * bit 1 (0x02) means mode switching (-vm) |
280 * bit 2 (0x04) enables software scaling (-zoom) | 299 * bit 2 (0x04) enables software scaling (-zoom) |
281 * bit 3 (0x08) enables flipping (-flip) | 300 * bit 3 (0x08) enables flipping (-flip) |
292 image_width = width; | 311 image_width = width; |
293 image_height = height; | 312 image_height = height; |
294 if(fullscreen & (0x1|0x4|0x8)) | 313 if(fullscreen & (0x1|0x4|0x8)) |
295 { | 314 { |
296 printf("vo_vesa: switches: -fs, -zoom, -flip are not supported\n"); | 315 printf("vo_vesa: switches: -fs, -zoom, -flip are not supported\n"); |
297 } | |
298 if(!(temp_buffer = malloc(width*height*4))) | |
299 { | |
300 printf("vo_vesa: Can't allocate temporary buffer\n"); | |
301 return -1; | |
302 } | 316 } |
303 if((err=vbeInit()) != VBE_OK) { PRINT_VBE_ERR("vbeInit",err); return -1; } | 317 if((err=vbeInit()) != VBE_OK) { PRINT_VBE_ERR("vbeInit",err); return -1; } |
304 memcpy(vib.VESASignature,"VBE2",4); | 318 memcpy(vib.VESASignature,"VBE2",4); |
305 if((err=vbeGetControllerInfo(&vib)) != VBE_OK) | 319 if((err=vbeGetControllerInfo(&vib)) != VBE_OK) |
306 { | 320 { |
369 if((err=vbeGetModeInfo(mode_ptr[i],&vmib)) != VBE_OK) | 383 if((err=vbeGetModeInfo(mode_ptr[i],&vmib)) != VBE_OK) |
370 { | 384 { |
371 PRINT_VBE_ERR("vbeGetModeInfo",err); | 385 PRINT_VBE_ERR("vbeGetModeInfo",err); |
372 return -1; | 386 return -1; |
373 } | 387 } |
374 if(vmib.XResolution > image_width && | 388 if(vmib.XResolution >= image_width && |
375 vmib.YResolution > image_height && | 389 vmib.YResolution >= image_height && |
376 (vmib.ModeAttributes & MOVIE_MODE) == MOVIE_MODE && | 390 (vmib.ModeAttributes & MOVIE_MODE) == MOVIE_MODE && |
377 vmib.BitsPerPixel == bpp && | 391 vmib.BitsPerPixel == bpp && |
378 vmib.MemoryModel == memRGB) | 392 vmib.MemoryModel == memRGB) |
379 { | 393 { |
380 if(vmib.XResolution < best_x && | 394 if(vmib.XResolution <= best_x && |
381 vmib.YResolution < best_y) | 395 vmib.YResolution <= best_y) |
382 { | 396 { |
383 best_x = vmib.XResolution; | 397 best_x = vmib.XResolution; |
384 best_y = vmib.YResolution; | 398 best_y = vmib.YResolution; |
385 best_mode_idx = i; | 399 best_mode_idx = i; |
386 } | 400 } |
387 } | 401 } |
388 if(verbose) | 402 if(verbose) |
389 { | 403 { |
390 printf("vo_vesa: Mode (%03u): mode=%04X %ux%u@%u attr=%u\n" | 404 printf("vo_vesa: Mode (%03u): mode=%04X %ux%u@%u attr=%x\n" |
391 "vo_vesa: #planes=%u model=%u #pages=%u\n" | 405 "vo_vesa: #planes=%u model=%u(%s) #pages=%u\n" |
392 "vo_vesa: winA=%X(attr=%u) winB=%X(attr=%u) winSize=%u winGran=%u\n" | 406 "vo_vesa: winA=%X(attr=%u) winB=%X(attr=%u) winSize=%u winGran=%u\n" |
393 "vo_vesa: direct_color=%u DGA_phys_addr=%08X\n" | 407 "vo_vesa: direct_color=%u DGA_phys_addr=%08X\n" |
394 ,i,mode_ptr[i],vmib.XResolution,vmib.YResolution,vmib.BitsPerPixel,vmib.ModeAttributes | 408 ,i,mode_ptr[i],vmib.XResolution,vmib.YResolution,vmib.BitsPerPixel,vmib.ModeAttributes |
395 ,vmib.NumberOfPlanes,vmib.MemoryModel,vmib.NumberOfImagePages | 409 ,vmib.NumberOfPlanes,vmib.MemoryModel,model2str(vmib.MemoryModel),vmib.NumberOfImagePages |
396 ,vmib.WinASegment,vmib.WinAAttributes,vmib.WinBSegment,vmib.WinBAttributes,vmib.WinSize,vmib.WinGranularity | 410 ,vmib.WinASegment,vmib.WinAAttributes,vmib.WinBSegment,vmib.WinBAttributes,vmib.WinSize,vmib.WinGranularity |
397 ,vmib.DirectColorModeInfo,vmib.PhysBasePtr); | 411 ,vmib.DirectColorModeInfo,vmib.PhysBasePtr); |
398 if(vmib.MemoryModel == 6 || vmib.MemoryModel == 7) | 412 if(vmib.MemoryModel == 6 || vmib.MemoryModel == 7) |
399 printf("vo_vesa: direct_color_info = %u:%u:%u:%u\n" | 413 printf("vo_vesa: direct_color_info = %u:%u:%u:%u\n" |
400 ,vmib.RedMaskSize,vmib.GreenMaskSize,vmib.BlueMaskSize,vmib.RsvdMaskSize); | 414 ,vmib.RedMaskSize,vmib.GreenMaskSize,vmib.BlueMaskSize,vmib.RsvdMaskSize); |
414 if(verbose) printf("vo_vesa: Initial video mode: %x\n",init_mode); | 428 if(verbose) printf("vo_vesa: Initial video mode: %x\n",init_mode); |
415 if((err=vbeGetModeInfo(video_mode,&video_mode_info)) != VBE_OK) | 429 if((err=vbeGetModeInfo(video_mode,&video_mode_info)) != VBE_OK) |
416 { | 430 { |
417 PRINT_VBE_ERR("vbeGetModeInfo",err); | 431 PRINT_VBE_ERR("vbeGetModeInfo",err); |
418 return -1; | 432 return -1; |
433 } | |
434 if(!(yuv_buffer = malloc(video_mode_info.XResolution*video_mode_info.YResolution*4))) | |
435 { | |
436 printf("vo_vesa: Can't allocate temporary buffer\n"); | |
437 return -1; | |
419 } | 438 } |
420 if((video_mode_info.WinAAttributes & FRAME_MODE) == FRAME_MODE) | 439 if((video_mode_info.WinAAttributes & FRAME_MODE) == FRAME_MODE) |
421 win.idx = 0; /* frame A */ | 440 win.idx = 0; /* frame A */ |
422 else | 441 else |
423 if((video_mode_info.WinBAttributes & FRAME_MODE) == FRAME_MODE) | 442 if((video_mode_info.WinBAttributes & FRAME_MODE) == FRAME_MODE) |