diff options
author | Piotr Dziwinski <piotrdz@gmail.com> | 2013-11-15 10:22:11 +0100 |
---|---|---|
committer | Piotr Dziwinski <piotrdz@gmail.com> | 2013-11-15 10:22:49 +0100 |
commit | 81b940cc25e6892ac752005521b3adba4534177b (patch) | |
tree | b4c3426e65accc52fec6ff0dcbbbe1e52f944493 /src/common/image.cpp | |
parent | be3d92ba03d832427f0720106dd72a9852639cb6 (diff) | |
download | colobot-81b940cc25e6892ac752005521b3adba4534177b.tar.gz colobot-81b940cc25e6892ac752005521b3adba4534177b.tar.bz2 colobot-81b940cc25e6892ac752005521b3adba4534177b.zip |
Fix for crash when loading PNG in indexed mode
For example, some icons in SatCom
Diffstat (limited to 'src/common/image.cpp')
-rw-r--r-- | src/common/image.cpp | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/common/image.cpp b/src/common/image.cpp index a9587ef..8a876e3 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -218,15 +218,30 @@ void CImage::PadToNearestPowerOfTwo() int w = Math::NextPowerOfTwo(m_data->surface->w); int h = Math::NextPowerOfTwo(m_data->surface->h); + BlitToNewRGBASurface(w, h); +} + +void CImage::ConvertToRGBA() +{ + assert(m_data != nullptr); + + int w = m_data->surface->w; + int h = m_data->surface->h; + + BlitToNewRGBASurface(w, h); +} + +void CImage::BlitToNewRGBASurface(int width, int height) +{ m_data->surface->flags &= (~SDL_SRCALPHA); - SDL_Surface* resizedSurface = SDL_CreateRGBSurface(0, w, h, 32, 0x00ff0000, 0x0000ff00, - 0x000000ff, 0xff000000); - assert(resizedSurface != NULL); - SDL_BlitSurface(m_data->surface, NULL, resizedSurface, NULL); + SDL_Surface* convertedSurface = SDL_CreateRGBSurface(0, width, height, 32, 0x00FF0000, 0x0000FF00, + 0x000000FF, 0xFF000000); + assert(convertedSurface != nullptr); + SDL_BlitSurface(m_data->surface, nullptr, convertedSurface, nullptr); SDL_FreeSurface(m_data->surface); - m_data->surface = resizedSurface; + m_data->surface = convertedSurface; } /** @@ -376,6 +391,11 @@ bool CImage::Load(const std::string& fileName) return false; } + if (m_data->surface->format->palette != nullptr) + { + ConvertToRGBA(); + } + return true; } |