comparison 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
comparison
equal deleted inserted replaced
2328:00f64d5858b8 2329:fc52a0a1626f
74 static unsigned int scale_yinc=0; 74 static unsigned int scale_yinc=0;
75 static float aspect_factor; 75 static float aspect_factor;
76 76
77 77
78 static uint32_t image_width, image_height; /* source image dimension */ 78 static uint32_t image_width, image_height; /* source image dimension */
79 static uint32_t x_offset,y_offset; /* to center image on screen */ 79 static int32_t x_offset,y_offset; /* to center image on screen */
80 static unsigned init_mode; /* mode before run of mplayer */ 80 static unsigned init_mode; /* mode before run of mplayer */
81 static void *init_state = NULL; /* state 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 */ 82 static struct win_frame win; /* real-mode window to video memory */
83 static uint8_t *yuv_buffer = NULL; /* for yuv2rgb and sw_scaling */ 83 static uint8_t *yuv_buffer = NULL; /* for yuv2rgb and sw_scaling */
84 static unsigned video_mode; /* selected video mode for playback */ 84 static unsigned video_mode; /* selected video mode for playback */
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); 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);
349 if((*image_height) > yres) 349 if((*image_height) > yres)
350 { 350 {
351 *image_height = yres; 351 *image_height = yres;
352 *image_width = yres * aspect_factor; 352 *image_width = yres * aspect_factor;
353 if(verbose) printf("vo_vesa: Y > X tehrefore *image=%ux%u\n",*image_width,*image_height); 353 if(verbose) printf("vo_vesa: Y > X therefore *image=%ux%u\n",*image_width,*image_height);
354 } 354 }
355 } 355 }
356 356
357 static char *model2str(unsigned char type) 357 static char *model2str(unsigned char type)
358 { 358 {
377 * bit 1 (0x02) means mode switching (-vm) 377 * bit 1 (0x02) means mode switching (-vm)
378 * bit 2 (0x04) enables software scaling (-zoom) 378 * bit 2 (0x04) enables software scaling (-zoom)
379 * bit 3 (0x08) enables flipping (-flip) 379 * bit 3 (0x08) enables flipping (-flip)
380 */ 380 */
381 static uint32_t 381 static uint32_t
382 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format) 382 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format)
383 { 383 {
384 struct VbeInfoBlock vib; 384 struct VbeInfoBlock vib;
385 struct VesaModeInfoBlock vmib; 385 struct VesaModeInfoBlock vmib;
386 size_t i,num_modes; 386 size_t i,num_modes;
387 uint32_t w,h;
387 unsigned short *mode_ptr,win_seg; 388 unsigned short *mode_ptr,win_seg;
388 unsigned bpp,best_x = UINT_MAX,best_y=UINT_MAX,best_mode_idx = UINT_MAX; 389 unsigned bpp,best_x = UINT_MAX,best_y=UINT_MAX,best_mode_idx = UINT_MAX;
389 int err; 390 int err;
390 image_width = width; 391 image_width = width;
391 image_height = height; 392 image_height = height;
392 if(fullscreen & (0x1|0x8)) 393 if(flags & 0x8)
393 { 394 {
394 printf("vo_vesa: switches: -fs, -flip are not supported\n"); 395 printf("vo_vesa: switch -flip is not supported\n");
395 } 396 }
396 if(fullscreen & 0x04) vesa_zoom = 1; 397 if(flags & 0x04) vesa_zoom = 1;
398 if(flags & 0x01) vesa_zoom = 2;
397 if((err=vbeInit()) != VBE_OK) { PRINT_VBE_ERR("vbeInit",err); return -1; } 399 if((err=vbeInit()) != VBE_OK) { PRINT_VBE_ERR("vbeInit",err); return -1; }
398 memcpy(vib.VESASignature,"VBE2",4); 400 memcpy(vib.VESASignature,"VBE2",4);
399 if((err=vbeGetControllerInfo(&vib)) != VBE_OK) 401 if((err=vbeGetControllerInfo(&vib)) != VBE_OK)
400 { 402 {
401 PRINT_VBE_ERR("vbeGetControllerInfo",err); 403 PRINT_VBE_ERR("vbeGetControllerInfo",err);
425 "vo_vesa: before booting PC since VESA BIOS initializes itself only during POST\n"); 427 "vo_vesa: before booting PC since VESA BIOS initializes itself only during POST\n");
426 /* Find best mode here */ 428 /* Find best mode here */
427 num_modes = 0; 429 num_modes = 0;
428 mode_ptr = vib.VideoModePtr; 430 mode_ptr = vib.VideoModePtr;
429 while(*mode_ptr++ != 0xffff) num_modes++; 431 while(*mode_ptr++ != 0xffff) num_modes++;
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
430 switch(format) 439 switch(format)
431 { 440 {
432 case IMGFMT_BGR8: 441 case IMGFMT_BGR8:
433 case IMGFMT_RGB8: bpp = 8; break; 442 case IMGFMT_RGB8: bpp = 8; break;
434 case IMGFMT_BGR15: 443 case IMGFMT_BGR15:
456 printf(" %04X",mode_ptr[i]); 465 printf(" %04X",mode_ptr[i]);
457 } 466 }
458 printf("\nvo_vesa: Modes in detail:\n"); 467 printf("\nvo_vesa: Modes in detail:\n");
459 } 468 }
460 mode_ptr = vib.VideoModePtr; 469 mode_ptr = vib.VideoModePtr;
470 w = d_width ? d_width : width;
471 h = d_height ? d_height : height;
461 for(i=0;i < num_modes;i++) 472 for(i=0;i < num_modes;i++)
462 { 473 {
463 if((err=vbeGetModeInfo(mode_ptr[i],&vmib)) != VBE_OK) 474 if((err=vbeGetModeInfo(mode_ptr[i],&vmib)) != VBE_OK)
464 { 475 {
465 PRINT_VBE_ERR("vbeGetModeInfo",err); 476 PRINT_VBE_ERR("vbeGetModeInfo",err);
466 return -1; 477 return -1;
467 } 478 }
468 if(vmib.XResolution >= image_width && 479 if(vmib.XResolution >= w &&
469 vmib.YResolution >= image_height && 480 vmib.YResolution >= h &&
470 (vmib.ModeAttributes & MOVIE_MODE) == MOVIE_MODE && 481 (vmib.ModeAttributes & MOVIE_MODE) == MOVIE_MODE &&
471 vmib.BitsPerPixel == bpp && 482 vmib.BitsPerPixel == bpp &&
472 vmib.MemoryModel == memRGB) 483 vmib.MemoryModel == memRGB)
473 { 484 {
474 if(vmib.XResolution <= best_x && 485 if(vmib.XResolution <= best_x &&
496 } 507 }
497 } 508 }
498 if(best_mode_idx != UINT_MAX) 509 if(best_mode_idx != UINT_MAX)
499 { 510 {
500 video_mode = vib.VideoModePtr[best_mode_idx]; 511 video_mode = vib.VideoModePtr[best_mode_idx];
501 printf("vo_vesa: Using VESA mode (%u) = %x\n",best_mode_idx,video_mode);
502 fflush(stdout); 512 fflush(stdout);
503 if((err=vbeGetMode(&init_mode)) != VBE_OK) 513 if((err=vbeGetMode(&init_mode)) != VBE_OK)
504 { 514 {
505 PRINT_VBE_ERR("vbeGetMode",err); 515 PRINT_VBE_ERR("vbeGetMode",err);
506 return -1; 516 return -1;
509 if((err=vbeGetModeInfo(video_mode,&video_mode_info)) != VBE_OK) 519 if((err=vbeGetModeInfo(video_mode,&video_mode_info)) != VBE_OK)
510 { 520 {
511 PRINT_VBE_ERR("vbeGetModeInfo",err); 521 PRINT_VBE_ERR("vbeGetModeInfo",err);
512 return -1; 522 return -1;
513 } 523 }
514 if(!(yuv_buffer = malloc(video_mode_info.XResolution*video_mode_info.YResolution*4))) 524 printf("vo_vesa: Using VESA mode (%u) = %x [%ux%u@%u]\n"
515 { 525 ,best_mode_idx,video_mode,video_mode_info.XResolution
516 printf("vo_vesa: Can't allocate temporary buffer\n"); 526 ,video_mode_info.YResolution,video_mode_info.BitsPerPixel);
517 return -1;
518 }
519 if( vesa_zoom ) 527 if( vesa_zoom )
520 { 528 {
521 if( format==IMGFMT_YV12 ) 529 if( format==IMGFMT_YV12 )
522 { 530 {
523 /* software scale */ 531 /* software scale */
532 if(vesa_zoom > 1)
533 {
534 image_width = video_mode_info.XResolution;
535 image_height = video_mode_info.YResolution;
536 }
537 else
524 vesa_aspect(width,height, 538 vesa_aspect(width,height,
525 video_mode_info.XResolution,video_mode_info.YResolution, 539 video_mode_info.XResolution,video_mode_info.YResolution,
526 &image_width,&image_height); 540 &image_width,&image_height);
527 /* image_width = video_mode_info.XResolution;
528 image_height = video_mode_info.YResolution; */
529 scale_xinc=(width << 16) / image_width - 2; /* needed for proper rounding */ 541 scale_xinc=(width << 16) / image_width - 2; /* needed for proper rounding */
530 scale_yinc=(height << 16) / image_height + 2; 542 scale_yinc=(height << 16) / image_height + 2;
531 SwScale_Init(); 543 SwScale_Init();
532 if(verbose) printf("vo_vesa: Using SCALE\n"); 544 if(verbose) printf("vo_vesa: Using SCALE\n");
533 } 545 }
551 return -1; 563 return -1;
552 } 564 }
553 win.ptr = PhysToVirtSO(win_seg,0); 565 win.ptr = PhysToVirtSO(win_seg,0);
554 win.low = 0L; 566 win.low = 0L;
555 win.high= video_mode_info.WinSize*1024; 567 win.high= video_mode_info.WinSize*1024;
556 x_offset = (video_mode_info.XResolution - image_width) / 2; 568 if(video_mode_info.XResolution > image_width)
557 y_offset = (video_mode_info.YResolution - image_height) / 2; 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;
558 if(verbose) 574 if(verbose)
559 printf("vo_vesa: image: %ux%u screen = %ux%u x_offset = %u y_offset = %u\n" 575 printf("vo_vesa: image: %ux%u screen = %ux%u x_offset = %u y_offset = %u\n"
560 ,image_width,image_height 576 ,image_width,image_height
561 ,video_mode_info.XResolution,video_mode_info.YResolution 577 ,video_mode_info.XResolution,video_mode_info.YResolution
562 ,x_offset,y_offset); 578 ,x_offset,y_offset);
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 }
563 if((err=vbeSaveState(&init_state)) != VBE_OK) 584 if((err=vbeSaveState(&init_state)) != VBE_OK)
564 { 585 {
565 PRINT_VBE_ERR("vbeSaveState",err); 586 PRINT_VBE_ERR("vbeSaveState",err);
566 return -1; 587 return -1;
567 } 588 }