Skip to content

Commit

Permalink
[PATCH] SDL_GetVideoMode() do not find the best video mode
Browse files Browse the repository at this point in the history
The current GetVideoMode() function stops at the first mode which has any
dimensions smaller than the one asked, and gives the previous in the list.

If I ask 336x224 with this list:
768x480 768x240 640x400 640x200 384x480 384x240 320x400 320x200
SDL will give me 640x400, because 640x200 as height smaller than what I
asked.

However the best mode is the smaller which has both dimensions bigger
than the one asked (384x240 in my example).

This patch fixes this, plus it does not rely on a sorted video mode list.
  • Loading branch information
pmandin committed Jun 12, 2005
1 parent 714dceb commit 67057e7
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/video/SDL_video.c
Expand Up @@ -462,33 +462,29 @@ static int SDL_GetVideoMode (int *w, int *h, int *BitsPerPixel, Uint32 flags)
SDL_closest_depths[table][0] = *BitsPerPixel;
SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel;
for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) {
int best;

format.BitsPerPixel = SDL_closest_depths[table][b];
sizes = SDL_ListModes(&format, flags);
if ( sizes == (SDL_Rect **)0 ) {
/* No sizes supported at this bit-depth */
continue;
}
best=0;
for ( i=0; sizes[i]; ++i ) {
if ((sizes[i]->w < *w) || (sizes[i]->h < *h)) {
if ( i > 0 ) {
--i;
*w = sizes[i]->w;
*h = sizes[i]->h;
*BitsPerPixel = SDL_closest_depths[table][b];
/* Mode with both dimensions bigger or equal than asked ? */
if ((sizes[i]->w >= *w) && (sizes[i]->h >= *h)) {
/* Mode with any dimension smaller or equal than current best ? */
if ((sizes[i]->w <= sizes[best]->w) || (sizes[i]->h <= sizes[best]->h)) {
best=i;
supported = 1;
} else {
/* Largest mode too small... */;
}
break;
}
}
if ( (i > 0) && ! sizes[i] ) {
/* The smallest mode was larger than requested, OK */
--i;
*w = sizes[i]->w;
*h = sizes[i]->h;
if (supported) {
*w=sizes[best]->w;
*h=sizes[best]->h;
*BitsPerPixel = SDL_closest_depths[table][b];
supported = 1;
}
}
if ( ! supported ) {
Expand Down

0 comments on commit 67057e7

Please sign in to comment.