summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/resources/imagehelper.cpp15
-rw-r--r--src/resources/imagehelper.h2
-rw-r--r--src/resources/openglimagehelper.cpp3
-rw-r--r--src/resources/resourcemanager.cpp10
-rw-r--r--src/resources/sdlimagehelper.cpp3
5 files changed, 26 insertions, 7 deletions
diff --git a/src/resources/imagehelper.cpp b/src/resources/imagehelper.cpp
index 5b7797cbb..eea15d29c 100644
--- a/src/resources/imagehelper.cpp
+++ b/src/resources/imagehelper.cpp
@@ -43,8 +43,7 @@ bool ImageHelper::mEnableAlpha = true;
Image *ImageHelper::load(SDL_RWops *const rw)
{
- SDL_Surface *const tmpImage = IMG_Load_RW(rw, 1);
-
+ SDL_Surface *const tmpImage = loadPng(rw);
if (!tmpImage)
{
logger->log("Error, image load failed: %s", IMG_GetError());
@@ -115,3 +114,15 @@ void ImageHelper::dumpSurfaceFormat(const SDL_Surface *const image) const
format->Gmask, format->Bmask, format->Amask);
}
}
+
+SDL_Surface *ImageHelper::loadPng(SDL_RWops *const rw)
+{
+ if (!rw || !IMG_isPNG(rw))
+ {
+ logger->log("Error, image missing or not png");
+ return nullptr;
+ }
+ SDL_Surface *const tmpImage = IMG_LoadPNG_RW(rw);
+ SDL_RWclose(rw);
+ return tmpImage;
+}
diff --git a/src/resources/imagehelper.h b/src/resources/imagehelper.h
index 19500f15a..e894bc66b 100644
--- a/src/resources/imagehelper.h
+++ b/src/resources/imagehelper.h
@@ -97,6 +97,8 @@ class ImageHelper
static void setEnableAlpha(const bool n)
{ mEnableAlpha = n; }
+ static SDL_Surface *loadPng(SDL_RWops *const rw);
+
protected:
static bool mEnableAlpha;
};
diff --git a/src/resources/openglimagehelper.cpp b/src/resources/openglimagehelper.cpp
index 6fc800e4e..073835626 100644
--- a/src/resources/openglimagehelper.cpp
+++ b/src/resources/openglimagehelper.cpp
@@ -53,8 +53,7 @@ bool OpenGLImageHelper::mUseTextureSampler = false;
Image *OpenGLImageHelper::load(SDL_RWops *const rw, Dye const &dye)
{
- SDL_Surface *const tmpImage = IMG_Load_RW(rw, 1);
-
+ SDL_Surface *const tmpImage = loadPng(rw);
if (!tmpImage)
{
logger->log("Error, image load failed: %s", IMG_GetError());
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 542a96a9e..bd739644c 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -1012,7 +1012,15 @@ SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename) const
{
SDL_Surface *surface = nullptr;
if (SDL_RWops *const rw = PHYSFSRWOPS_openRead(filename.c_str()))
- surface = IMG_Load_RW(rw, 1);
+ {
+ if (!IMG_isPNG(rw))
+ {
+ logger->log("Error, image is not png: " + filename);
+ return nullptr;
+ }
+ surface = IMG_LoadPNG_RW(rw);
+ SDL_RWclose(rw);
+ }
return surface;
}
diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp
index 40f3a4a53..b21f76b7f 100644
--- a/src/resources/sdlimagehelper.cpp
+++ b/src/resources/sdlimagehelper.cpp
@@ -40,8 +40,7 @@ bool SDLImageHelper::mEnableAlphaCache = false;
Image *SDLImageHelper::load(SDL_RWops *const rw, Dye const &dye)
{
- SDL_Surface *const tmpImage = IMG_Load_RW(rw, 1);
-
+ SDL_Surface *const tmpImage = loadPng(rw);
if (!tmpImage)
{
logger->log("Error, image load failed: %s", IMG_GetError());