src/video/directfb/SDL_DirectFB_video.c
changeset 732 d18e2b224d0e
parent 728 5446a009107a
child 759 26ac9609211f
     1.1 --- a/src/video/directfb/SDL_DirectFB_video.c	Mon Oct 06 09:03:02 2003 +0000
     1.2 +++ b/src/video/directfb/SDL_DirectFB_video.c	Wed Nov 05 21:07:29 2003 +0000
     1.3 @@ -529,6 +529,19 @@
     1.4        HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );
     1.5  
     1.6        HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF );
     1.7 +    
     1.8 +      /* Check if overscan is possibly set */
     1.9 +      if (getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL)
    1.10 +        {
    1.11 +	    float overscan = 0;
    1.12 +	    if (sscanf(getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f", &overscan) == 1)
    1.13 +               if (overscan > 0 && overscan < 2)
    1.14 +		  HIDDEN->mga_crtc2_stretch_overscan = overscan;
    1.15 +	}
    1.16 +
    1.17 +      #ifdef DIRECTFB_CRTC2_DEBUG
    1.18 +      printf("CRTC2 overscan: %f\n", HIDDEN->mga_crtc2_stretch_overscan);
    1.19 +      #endif
    1.20      }
    1.21  
    1.22    return 0;
    1.23 @@ -693,18 +706,42 @@
    1.24  
    1.25        if (getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL)
    1.26          {
    1.27 -          /* don't stretch slightly smaller/larger images */
    1.28 -          if (width < HIDDEN->c2framesize.w*0.95 && height < HIDDEN->c2framesize.w*0.95)
    1.29 +	    /* Normally assume a picture aspect ratio of 4:3 */
    1.30 +	    int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j;
    1.31 +
    1.32 +	    for (i = 1; i < 20; i++)
    1.33 +	      {
    1.34 +		for (j = 1; j < 10; j++)
    1.35 +		  {
    1.36 +		    if ((float)width/(float)i*(float)j == height) 
    1.37 +		      {
    1.38 +			zoom_aspect_x = i;
    1.39 +			zoom_aspect_y = j;
    1.40 +			
    1.41 +			/* break the loop */
    1.42 +			i = 21;
    1.43 +			break;
    1.44 +		      }
    1.45 +		  }
    1.46 +	      }
    1.47 +	
    1.48 +            #ifdef DIRECTFB_CRTC2_DEBUG
    1.49 +            printf("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n", width, height, zoom_aspect_x, zoom_aspect_y);
    1.50 +            printf("CRTC2 resolution: X: %d, Y: %d\n", HIDDEN->c2framesize.w, HIDDEN->c2framesize.h);
    1.51 +            #endif
    1.52 +	
    1.53 +          /* don't stretch only slightly smaller/larger images */
    1.54 +          if ((float)width < (float)HIDDEN->c2framesize.w*0.95 || (float)height < (float)HIDDEN->c2framesize.h*0.95)
    1.55              {
    1.56 -              while (HIDDEN->c2dsize.w < HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan && HIDDEN->c2dsize.h < HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
    1.57 +              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)
    1.58                  {
    1.59 -                   HIDDEN->c2dsize.w+=4;
    1.60 -                   HIDDEN->c2dsize.h+=3;
    1.61 +                   HIDDEN->c2dsize.w+=zoom_aspect_x;
    1.62 +                   HIDDEN->c2dsize.h+=zoom_aspect_y;
    1.63                  }
    1.64  
    1.65                /* one step down */
    1.66 -              HIDDEN->c2dsize.w-=4;
    1.67 -              HIDDEN->c2dsize.h-=3;
    1.68 +                HIDDEN->c2dsize.w-=zoom_aspect_x;
    1.69 +                HIDDEN->c2dsize.h-=zoom_aspect_y;
    1.70  
    1.71                #ifdef DIRECTFB_CRTC2_DEBUG
    1.72                printf("Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
    1.73 @@ -712,12 +749,12 @@
    1.74  
    1.75                HIDDEN->mga_crtc2_stretch = 1;
    1.76              } 
    1.77 -          else if (width > HIDDEN->c2framesize.w*0.95 && height > HIDDEN->c2framesize.w*0.95)
    1.78 +          else if ((float)width > (float)HIDDEN->c2framesize.w*0.95 || (float)height > (float)HIDDEN->c2framesize.h*0.95)
    1.79              {
    1.80 -              while (HIDDEN->c2dsize.w > HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan || HIDDEN->c2dsize.h > HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
    1.81 +               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)
    1.82                  {
    1.83 -                  HIDDEN->c2dsize.w-=4;
    1.84 -                  HIDDEN->c2dsize.h-=3;
    1.85 +              HIDDEN->c2dsize.w-=zoom_aspect_x;
    1.86 +              HIDDEN->c2dsize.h-=zoom_aspect_y;
    1.87                  }
    1.88                
    1.89                #ifdef DIRECTFB_CRTC2_DEBUG
    1.90 @@ -725,7 +762,10 @@
    1.91                #endif
    1.92  
    1.93                HIDDEN->mga_crtc2_stretch = 1;
    1.94 -            }
    1.95 +             } else {
    1.96 +          #ifdef DIRECTFB_CRTC2_DEBUG
    1.97 +          printf("Not stretching image\n");
    1.98 +          #endif
    1.99          }
   1.100  
   1.101        /* Panning */
   1.102 @@ -740,9 +780,10 @@
   1.103          HIDDEN->c2dsize.y = (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h)  / 2;
   1.104  
   1.105        #ifdef DIRECTFB_CRTC2_DEBUG
   1.106 -      printf("CTRC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
   1.107 +    printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
   1.108        #endif
   1.109     }
   1.110 +  }
   1.111  
   1.112    return current;
   1.113  }