diff src/video/SDL_video.c @ 1076:8d3b95ece376

[PATCH] SDL_GetVideoMode() do not find the best video mode 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.
author Patrice Mandin <patmandin@gmail.com>
date Sun, 12 Jun 2005 16:12:55 +0000
parents 68f607298ca9
children 609c060fd2a2
line wrap: on
line diff
--- a/src/video/SDL_video.c	Tue Jun 07 13:30:06 2005 +0000
+++ b/src/video/SDL_video.c	Sun Jun 12 16:12:55 2005 +0000
@@ -462,33 +462,29 @@
 	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 ) {