src/video/SDL_bmp.c
changeset 12644 7c643f1c1887
parent 12612 07c39cbbeacf
child 12665 4743da9c3eea
equal deleted inserted replaced
12643:76caa6065d50 12644:7c643f1c1887
   244     case 1:
   244     case 1:
   245     case 4:
   245     case 4:
   246         ExpandBMP = biBitCount;
   246         ExpandBMP = biBitCount;
   247         biBitCount = 8;
   247         biBitCount = 8;
   248         break;
   248         break;
       
   249     case 2:
       
   250     case 3:
       
   251     case 5:
       
   252     case 6:
       
   253     case 7:
       
   254 		SDL_SetError("%d-bpp BMP images are not supported", biBitCount);
       
   255         was_error = SDL_TRUE;
       
   256         goto done;
   249     default:
   257     default:
   250         ExpandBMP = 0;
   258         ExpandBMP = 0;
   251         break;
   259         break;
   252     }
   260     }
   253 
   261 
   396                             SDL_SetError("Error reading from BMP");
   404                             SDL_SetError("Error reading from BMP");
   397                             was_error = SDL_TRUE;
   405                             was_error = SDL_TRUE;
   398                             goto done;
   406                             goto done;
   399                         }
   407                         }
   400                     }
   408                     }
   401                     *(bits + i) = (pixel >> shift);
   409                     bits[i] = (pixel >> shift);
       
   410 					if (bits[i] >= biClrUsed) {
       
   411 						SDL_SetError("A BMP image contains a pixel with a color out of the palette");
       
   412 						was_error = SDL_TRUE;
       
   413 						goto done;
       
   414 					}
   402                     pixel <<= ExpandBMP;
   415                     pixel <<= ExpandBMP;
   403                 }
   416                 }
   404             }
   417             }
   405             break;
   418             break;
   406 
   419 
   407         default:
   420         default:
   408             if (SDL_RWread(src, bits, 1, surface->pitch)
   421             if (SDL_RWread(src, bits, 1, surface->pitch) != surface->pitch) {
   409                 != surface->pitch) {
       
   410                 SDL_Error(SDL_EFREAD);
   422                 SDL_Error(SDL_EFREAD);
   411                 was_error = SDL_TRUE;
   423                 was_error = SDL_TRUE;
   412                 goto done;
   424                 goto done;
   413             }
   425             }
       
   426 			if (biBitCount == 8 && palette && biClrUsed < (1 << biBitCount)) {
       
   427 				for (i = 0; i < surface->w; ++i) {
       
   428 					if (bits[i] >= biClrUsed) {
       
   429 						SDL_SetError("A BMP image contains a pixel with a color out of the palette");
       
   430 						was_error = SDL_TRUE;
       
   431 						goto done;
       
   432 					}
       
   433 				}
       
   434 			}
   414 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
   435 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
   415             /* Byte-swap the pixels if needed. Note that the 24bpp
   436             /* Byte-swap the pixels if needed. Note that the 24bpp
   416                case has already been taken care of above. */
   437                case has already been taken care of above. */
   417             switch (biBitCount) {
   438             switch (biBitCount) {
   418             case 15:
   439             case 15: