mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-26 03:52:01 +02:00
Fixes #1378 - do not auto-set key color - image might not have one
This commit is contained in:
parent
4ca22e652d
commit
d83eedb8dd
@ -20,7 +20,7 @@ namespace BitmapHandler
|
|||||||
{
|
{
|
||||||
SDL_Surface * loadH3PCX(ui8 * data, size_t size);
|
SDL_Surface * loadH3PCX(ui8 * data, size_t size);
|
||||||
|
|
||||||
SDL_Surface * loadBitmapFromDir(std::string path, std::string fname, bool setKey=true);
|
SDL_Surface * loadBitmapFromDir(std::string path, std::string fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isPCX(const ui8 *header)//check whether file can be PCX according to header
|
bool isPCX(const ui8 *header)//check whether file can be PCX according to header
|
||||||
@ -102,7 +102,7 @@ SDL_Surface * BitmapHandler::loadH3PCX(ui8 * pcx, size_t size)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fname, bool setKey)
|
SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fname)
|
||||||
{
|
{
|
||||||
if(!fname.size())
|
if(!fname.size())
|
||||||
{
|
{
|
||||||
@ -121,14 +121,7 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
|
|||||||
if (isPCX(readFile.first.get()))
|
if (isPCX(readFile.first.get()))
|
||||||
{//H3-style PCX
|
{//H3-style PCX
|
||||||
ret = loadH3PCX(readFile.first.get(), readFile.second);
|
ret = loadH3PCX(readFile.first.get(), readFile.second);
|
||||||
if (ret)
|
if (!ret)
|
||||||
{
|
|
||||||
if(ret->format->BytesPerPixel == 1 && setKey)
|
|
||||||
{
|
|
||||||
CSDL_Ext::setColorKey(ret,ret->format->palette->colors[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
logGlobal->error("Failed to open %s as H3 PCX!", fname);
|
logGlobal->error("Failed to open %s as H3 PCX!", fname);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -144,7 +137,8 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
|
|||||||
{
|
{
|
||||||
if (ret->format->palette)
|
if (ret->format->palette)
|
||||||
{
|
{
|
||||||
//set correct value for alpha\unused channel
|
// set correct value for alpha\unused channel
|
||||||
|
// NOTE: might be unnecessary with SDL2
|
||||||
for (int i=0; i < ret->format->palette->ncolors; i++)
|
for (int i=0; i < ret->format->palette->ncolors; i++)
|
||||||
ret->format->palette->colors[i].a = SDL_ALPHA_OPAQUE;
|
ret->format->palette->colors[i].a = SDL_ALPHA_OPAQUE;
|
||||||
}
|
}
|
||||||
@ -196,12 +190,12 @@ SDL_Surface * BitmapHandler::loadBitmapFromDir(std::string path, std::string fna
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_Surface * BitmapHandler::loadBitmap(std::string fname, bool setKey)
|
SDL_Surface * BitmapHandler::loadBitmap(std::string fname)
|
||||||
{
|
{
|
||||||
SDL_Surface * bitmap = nullptr;
|
SDL_Surface * bitmap = nullptr;
|
||||||
|
|
||||||
if (!(bitmap = loadBitmapFromDir("DATA/", fname, setKey)) &&
|
if (!(bitmap = loadBitmapFromDir("DATA/", fname)) &&
|
||||||
!(bitmap = loadBitmapFromDir("SPRITES/", fname, setKey)))
|
!(bitmap = loadBitmapFromDir("SPRITES/", fname)))
|
||||||
{
|
{
|
||||||
logGlobal->error("Error: Failed to find file %s", fname);
|
logGlobal->error("Error: Failed to find file %s", fname);
|
||||||
}
|
}
|
||||||
|
@ -14,5 +14,5 @@ struct SDL_Surface;
|
|||||||
namespace BitmapHandler
|
namespace BitmapHandler
|
||||||
{
|
{
|
||||||
//Load file from /DATA or /SPRITES
|
//Load file from /DATA or /SPRITES
|
||||||
SDL_Surface * loadBitmap(std::string fname, bool setKey=true);
|
SDL_Surface * loadBitmap(std::string fname);
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town
|
|||||||
pos.y += str->pos.y;
|
pos.y += str->pos.y;
|
||||||
|
|
||||||
if(!str->borderName.empty())
|
if(!str->borderName.empty())
|
||||||
border = BitmapHandler::loadBitmap(str->borderName, true);
|
border = BitmapHandler::loadBitmap(str->borderName);
|
||||||
else
|
else
|
||||||
border = nullptr;
|
border = nullptr;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user