src/video/SDL_video.c
changeset 1076 8d3b95ece376
parent 1052 68f607298ca9
child 1133 609c060fd2a2
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 	}