Add error for loading non 24-bit bitmaps

This commit is contained in:
Broxzier 2017-04-23 22:37:29 +02:00 committed by Michał Janiszewski
parent b456fe2a4d
commit d8253ef849
3 changed files with 9 additions and 0 deletions

View File

@ -4362,6 +4362,7 @@ STR_6050 :Error reading bitmap
STR_6051 :The width and height need to match
STR_6052 :The heightmap is too big, and will be cut off
STR_6053 :The heightmap cannot be normalized
STR_6054 :Only 24-bit bitmaps are supported
#############
# Scenarios #

View File

@ -3712,6 +3712,7 @@ enum {
STR_ERROR_WIDTH_AND_HEIGHT_DO_NOT_MATCH = 6051,
STR_ERROR_HEIHGT_MAP_TOO_BIG = 6052,
STR_ERROR_CANNOT_NORMALIZE = 6053,
STR_ERROR_24_BIT_BITMAP = 6054,
// Have to include resource strings (from scenarios and objects) for the time being now that language is partially working
STR_COUNT = 32768

View File

@ -816,6 +816,13 @@ bool mapgen_load_heightmap(const utf8 *path)
numChannels = bitmap->format->BytesPerPixel;
pitch = bitmap->pitch;
if (numChannels < 3 || bitmap->format->BitsPerPixel < 24)
{
window_error_open(STR_HEIGHT_MAP_ERROR, STR_ERROR_24_BIT_BITMAP);
SDL_FreeSurface(bitmap);
return false;
}
// Copy pixels over, then discard the surface
SDL_LockSurface(bitmap);
pixels = malloc(height * bitmap->pitch);