Skip to content

Commit

Permalink
Date: Wed, 5 Nov 2003 21:27:47 +0100
Browse files Browse the repository at this point in the history
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
  • Loading branch information
icculus committed Nov 5, 2003
1 parent 0b3f1a7 commit 060e026
Showing 1 changed file with 54 additions and 13 deletions.
67 changes: 54 additions & 13 deletions src/video/directfb/SDL_DirectFB_video.c
Expand Up @@ -529,6 +529,19 @@ int DirectFB_VideoInit(_THIS, SDL_PixelFormat *vformat)
HIDDEN->c2frame->Clear(HIDDEN->c2frame, 0, 0, 0, 0xff );

HIDDEN->c2layer->SetOpacity(HIDDEN->c2layer, 0xFF );

/* Check if overscan is possibly set */
if (getenv("SDL_DIRECTFB_MGA_OVERSCAN") != NULL)
{
float overscan = 0;
if (sscanf(getenv("SDL_DIRECTFB_MGA_OVERSCAN"), "%f", &overscan) == 1)
if (overscan > 0 && overscan < 2)
HIDDEN->mga_crtc2_stretch_overscan = overscan;
}

#ifdef DIRECTFB_CRTC2_DEBUG
printf("CRTC2 overscan: %f\n", HIDDEN->mga_crtc2_stretch_overscan);
#endif
}

return 0;
Expand Down Expand Up @@ -693,39 +706,66 @@ static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width

if (getenv("SDL_DIRECTFB_MGA_STRETCH") != NULL)
{
/* don't stretch slightly smaller/larger images */
if (width < HIDDEN->c2framesize.w*0.95 && height < HIDDEN->c2framesize.w*0.95)
/* Normally assume a picture aspect ratio of 4:3 */
int zoom_aspect_x = 4, zoom_aspect_y = 3, i, j;

for (i = 1; i < 20; i++)
{
for (j = 1; j < 10; j++)
{
if ((float)width/(float)i*(float)j == height)
{
zoom_aspect_x = i;
zoom_aspect_y = j;

/* break the loop */
i = 21;
break;
}
}
}

#ifdef DIRECTFB_CRTC2_DEBUG
printf("Source resolution: X: %d, Y: %d, Aspect ratio: %d:%d\n", width, height, zoom_aspect_x, zoom_aspect_y);
printf("CRTC2 resolution: X: %d, Y: %d\n", HIDDEN->c2framesize.w, HIDDEN->c2framesize.h);
#endif

/* don't stretch only slightly smaller/larger images */
if ((float)width < (float)HIDDEN->c2framesize.w*0.95 || (float)height < (float)HIDDEN->c2framesize.h*0.95)
{
while (HIDDEN->c2dsize.w < HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan && HIDDEN->c2dsize.h < HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
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)
{
HIDDEN->c2dsize.w+=4;
HIDDEN->c2dsize.h+=3;
HIDDEN->c2dsize.w+=zoom_aspect_x;
HIDDEN->c2dsize.h+=zoom_aspect_y;
}

/* one step down */
HIDDEN->c2dsize.w-=4;
HIDDEN->c2dsize.h-=3;
HIDDEN->c2dsize.w-=zoom_aspect_x;
HIDDEN->c2dsize.h-=zoom_aspect_y;

#ifdef DIRECTFB_CRTC2_DEBUG
printf("Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
#endif

HIDDEN->mga_crtc2_stretch = 1;
}
else if (width > HIDDEN->c2framesize.w*0.95 && height > HIDDEN->c2framesize.w*0.95)
else if ((float)width > (float)HIDDEN->c2framesize.w*0.95 || (float)height > (float)HIDDEN->c2framesize.h*0.95)
{
while (HIDDEN->c2dsize.w > HIDDEN->c2framesize.w*HIDDEN->mga_crtc2_stretch_overscan || HIDDEN->c2dsize.h > HIDDEN->c2framesize.h*HIDDEN->mga_crtc2_stretch_overscan)
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)
{
HIDDEN->c2dsize.w-=4;
HIDDEN->c2dsize.h-=3;
HIDDEN->c2dsize.w-=zoom_aspect_x;
HIDDEN->c2dsize.h-=zoom_aspect_y;
}

#ifdef DIRECTFB_CRTC2_DEBUG
printf("Down-Stretched resolution: X: %d, Y: %d\n", HIDDEN->c2dsize.w, HIDDEN->c2dsize.h);
#endif

HIDDEN->mga_crtc2_stretch = 1;
}
} else {
#ifdef DIRECTFB_CRTC2_DEBUG
printf("Not stretching image\n");
#endif
}

/* Panning */
Expand All @@ -740,9 +780,10 @@ static SDL_Surface *DirectFB_SetVideoMode(_THIS, SDL_Surface *current, int width
HIDDEN->c2dsize.y = (HIDDEN->c2dsize.h - HIDDEN->c2framesize.h) / 2;

#ifdef DIRECTFB_CRTC2_DEBUG
printf("CTRC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
printf("CRTC2 position X: %d, Y: %d\n", HIDDEN->c2dsize.x, HIDDEN->c2dsize.y);
#endif
}
}

return current;
}
Expand Down

0 comments on commit 060e026

Please sign in to comment.