comparison src/video/directfb/SDL_DirectFB_video.c @ 732:d18e2b224d0e

Date: Wed, 5 Nov 2003 21:27:47 +0100 From: Thomas Jarosch <xxx> To: Ryan C. Gordon <xxx> Subject: MGA CRTC2 update Hi Ryan, attached is a small update for the DirectFB MGA CRTC2 support: - Video aspect ratio correct scaling (important for MAME) - Small bugfix in previous scaling code - Ability to control the TV picture overscan via the environment variable SDL_DIRECTFB_OVERSCAN. Sounds worth enough for applying it to SDL CVS ;-) Cheers, Thomas
author Ryan C. Gordon <icculus@icculus.org>
date Wed, 05 Nov 2003 21:07:29 +0000
parents 5446a009107a
children 26ac9609211f
comparison
equal deleted inserted replaced
731:faaa676b20ef 732:d18e2b224d0e
527 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff ); 527 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
528 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0 ); 528 HIDDEN->c2frame->Flip(HIDDEN->c2frame, NULL, 0 );
529 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff ); 529 HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
530 530
531 HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF ); 531 HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF );
532
533 /* Check if overscan is possibly set */
534 if (getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL)
535 {
536 float overscan = 0;
537 if (sscanf(getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f", &overscan) == 1)
538 if (overscan > 0 && overscan < 2)
539 HIDDEN->mga_crtc2_stretch_overscan = overscan;
540 }
541
542 #ifdef DIRECTFB_CRTC2_DEBUG
543 printf("CRTC2 overscan: %f\n", HIDDEN->mga_crtc2_stretch_overscan);
544 #endif
532 } 545 }
533 546
534 return 0; 547 return 0;
535 548
536 error: 549 error:
691 704
692 HIDDEN->mga_crtc2_stretch = 0; 705 HIDDEN->mga_crtc2_stretch = 0;
693 706
694 if (getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL) 707 if (getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL)
695 { 708 {
696 /* don't stretch slightly smaller/larger images */ 709 /* Normally assume a picture aspect ratio of 4:3 */
697 if (width < HIDDEN->c2framesize.w*0.95 && height < HIDDEN->c2framesize.w*0.95) 710 int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j;
711
712 for (i = 1; i < 20; i++)
713 {
714 for (j = 1; j < 10; j++)
715 {
716 if ((float)width/(float)i*(float)j == height)
717 {
718 zoom_aspect_x = i;
719 zoom_aspect_y = j;
720
721 /* break the loop */
722 i = 21;
723 break;
724 }
725 }
726 }
727
728 #ifdef DIRECTFB_CRTC2_DEBUG
729 printf("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n", width, height, zoom_aspect_x, zoom_aspect_y);
730 printf("CRTC2 resolution: X: %d, Y: %d\n", HIDDEN->c2framesize.w, HIDDEN->c2framesize.h);
731 #endif
732
733 /* don't stretch only slightly smaller/larger images */
734 if ((float)width < (float)HIDDEN->c2framesize.w*0.95 || (float)height < (float)HIDDEN->c2framesize.h*0.95)
698 { 735 {
699 while (HIDDEN->c2dsize.w < HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan && HIDDEN->c2dsize.h < HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan) 736 while ((float)HIDDEN->c2dsize.w < (float)HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan && (float)HIDDEN->c2dsize.h < (float)HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
700 { 737 {
701 HIDDEN->c2dsize.w+=4; 738 HIDDEN->c2dsize.w+=zoom_aspect_x;
702 HIDDEN->c2dsize.h+=3; 739 HIDDEN->c2dsize.h+=zoom_aspect_y;
703 } 740 }
704 741
705 /* one step down */ 742 /* one step down */
706 HIDDEN->c2dsize.w-=4; 743 HIDDEN->c2dsize.w-=zoom_aspect_x;
707 HIDDEN->c2dsize.h-=3; 744 HIDDEN->c2dsize.h-=zoom_aspect_y;
708 745
709 #ifdef DIRECTFB_CRTC2_DEBUG 746 #ifdef DIRECTFB_CRTC2_DEBUG
710 printf("Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h); 747 printf("Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
711 #endif 748 #endif
712 749
713 HIDDEN->mga_crtc2_stretch = 1; 750 HIDDEN->mga_crtc2_stretch = 1;
714 } 751 }
715 else if (width > HIDDEN->c2framesize.w*0.95 && height > HIDDEN->c2framesize.w*0.95) 752 else if ((float)width > (float)HIDDEN->c2framesize.w*0.95 || (float)height > (float)HIDDEN->c2framesize.h*0.95)
716 { 753 {
717 while (HIDDEN->c2dsize.w > HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan || HIDDEN->c2dsize.h > HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan) 754 while ((float)HIDDEN->c2dsize.w > (float)HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan || (float)HIDDEN->c2dsize.h > (float)HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
718 { 755 {
719 HIDDEN->c2dsize.w-=4; 756 HIDDEN->c2dsize.w-=zoom_aspect_x;
720 HIDDEN->c2dsize.h-=3; 757 HIDDEN->c2dsize.h-=zoom_aspect_y;
721 } 758 }
722 759
723 #ifdef DIRECTFB_CRTC2_DEBUG 760 #ifdef DIRECTFB_CRTC2_DEBUG
724 printf("Down-Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h); 761 printf("Down-Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
725 #endif 762 #endif
726 763
727 HIDDEN->mga_crtc2_stretch = 1; 764 HIDDEN->mga_crtc2_stretch = 1;
728 } 765 } else {
766 #ifdef DIRECTFB_CRTC2_DEBUG
767 printf("Not stretching image\n");
768 #endif
729 } 769 }
730 770
731 /* Panning */ 771 /* Panning */
732 if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w) 772 if (HIDDEN->c2framesize.w > HIDDEN->c2dsize.w)
733 HIDDEN->c2dsize.x = (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w) / 2; 773 HIDDEN->c2dsize.x = (HIDDEN->c2framesize.w - HIDDEN->c2dsize.w) / 2;
738 HIDDEN->c2dsize.y = (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h) / 2; 778 HIDDEN->c2dsize.y = (HIDDEN->c2framesize.h - HIDDEN->c2dsize.h) / 2;
739 else 779 else
740 HIDDEN->c2dsize.y = (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2; 780 HIDDEN->c2dsize.y = (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2;
741 781
742 #ifdef DIRECTFB_CRTC2_DEBUG 782 #ifdef DIRECTFB_CRTC2_DEBUG
743 printf("CTRC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y); 783 printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
744 #endif 784 #endif
745 } 785 }
786 }
746 787
747 return current; 788 return current;
748 } 789 }
749 790
750 static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface) 791 static int DirectFB_AllocHWSurface(_THIS, SDL_Surface *surface)