comparison 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
comparison
equal deleted inserted replaced
1075:1f5ef94e8bef 1076:8d3b95ece376
460 supported = 0; 460 supported = 0;
461 table = ((*BitsPerPixel+7)/8)-1; 461 table = ((*BitsPerPixel+7)/8)-1;
462 SDL_closest_depths[table][0] = *BitsPerPixel; 462 SDL_closest_depths[table][0] = *BitsPerPixel;
463 SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel; 463 SDL_closest_depths[table][7] = SDL_VideoSurface->format->BitsPerPixel;
464 for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) { 464 for ( b = 0; !supported && SDL_closest_depths[table][b]; ++b ) {
465 int best;
466
465 format.BitsPerPixel = SDL_closest_depths[table][b]; 467 format.BitsPerPixel = SDL_closest_depths[table][b];
466 sizes = SDL_ListModes(&format, flags); 468 sizes = SDL_ListModes(&format, flags);
467 if ( sizes == (SDL_Rect **)0 ) { 469 if ( sizes == (SDL_Rect **)0 ) {
468 /* No sizes supported at this bit-depth */ 470 /* No sizes supported at this bit-depth */
469 continue; 471 continue;
470 } 472 }
473 best=0;
471 for ( i=0; sizes[i]; ++i ) { 474 for ( i=0; sizes[i]; ++i ) {
472 if ((sizes[i]->w < *w) || (sizes[i]->h < *h)) { 475 /* Mode with both dimensions bigger or equal than asked ? */
473 if ( i > 0 ) { 476 if ((sizes[i]->w >= *w) && (sizes[i]->h >= *h)) {
474 --i; 477 /* Mode with any dimension smaller or equal than current best ? */
475 *w = sizes[i]->w; 478 if ((sizes[i]->w <= sizes[best]->w) || (sizes[i]->h <= sizes[best]->h)) {
476 *h = sizes[i]->h; 479 best=i;
477 *BitsPerPixel = SDL_closest_depths[table][b];
478 supported = 1; 480 supported = 1;
479 } else {
480 /* Largest mode too small... */;
481 } 481 }
482 break; 482 }
483 } 483 }
484 } 484 if (supported) {
485 if ( (i > 0) && ! sizes[i] ) { 485 *w=sizes[best]->w;
486 /* The smallest mode was larger than requested, OK */ 486 *h=sizes[best]->h;
487 --i;
488 *w = sizes[i]->w;
489 *h = sizes[i]->h;
490 *BitsPerPixel = SDL_closest_depths[table][b]; 487 *BitsPerPixel = SDL_closest_depths[table][b];
491 supported = 1;
492 } 488 }
493 } 489 }
494 if ( ! supported ) { 490 if ( ! supported ) {
495 SDL_SetError("No video mode large enough for %dx%d", *w, *h); 491 SDL_SetError("No video mode large enough for %dx%d", *w, *h);
496 } 492 }