diff --git a/src/imageio.cpp b/src/imageio.cpp index 822b0b2..f731429 100644 --- a/src/imageio.cpp +++ b/src/imageio.cpp @@ -24,7 +24,7 @@ static void __readFromOpk(png_structp png_ptr, png_bytep ptr, png_size_t length) } #endif -SDL_Surface *loadPNG(const std::string &path) { +SDL_Surface *loadPNG(const std::string &path, bool loadAlpha) { // Declare these with function scope and initialize them to NULL, // so we can use a single cleanup block at the end of the function. SDL_Surface *surface = NULL; @@ -134,10 +134,10 @@ SDL_Surface *loadPNG(const std::string &path) { goto cleanup; } - // Allocate ARGB surface to hold the image. + // Allocate [A]RGB surface to hold the image. surface = SDL_CreateRGBSurface( SDL_SWSURFACE | SDL_SRCALPHA, width, height, 32, - 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000 + 0x00FF0000, 0x0000FF00, 0x000000FF, loadAlpha ? 0xFF000000 : 0x00000000 ); if (!surface) { // Failed to create surface, probably out of memory. diff --git a/src/imageio.h b/src/imageio.h index 54d4640..ced4006 100644 --- a/src/imageio.h +++ b/src/imageio.h @@ -7,6 +7,6 @@ struct SDL_Surface; /** Loads an image from a PNG file into a newly allocated 32bpp RGBA surface. */ -SDL_Surface *loadPNG(const std::string &path); +SDL_Surface *loadPNG(const std::string &path, bool loadAlpha = true); #endif diff --git a/src/surface.cpp b/src/surface.cpp index 3e94047..1f81ed1 100644 --- a/src/surface.cpp +++ b/src/surface.cpp @@ -55,14 +55,14 @@ Surface *Surface::emptySurface(int width, int height) { return new Surface(raw, true); } -Surface *Surface::loadImage(const string &img, const string &skin) { +Surface *Surface::loadImage(const string &img, const string &skin, bool loadAlpha) { string skinpath; if (!skin.empty() && !img.empty() && img[0]!='/') skinpath = SurfaceCollection::getSkinFilePath(skin, img); else skinpath = img; - SDL_Surface *raw = loadPNG(skinpath); + SDL_Surface *raw = loadPNG(skinpath, loadAlpha); if (!raw) { ERROR("Couldn't load surface '%s'\n", img.c_str()); return NULL; diff --git a/src/surface.h b/src/surface.h index 43cd6bc..efd8a64 100644 --- a/src/surface.h +++ b/src/surface.h @@ -41,7 +41,7 @@ public: static Surface *openOutputSurface(int width, int height, int bitsperpixel); static Surface *emptySurface(int width, int height); static Surface *loadImage(const std::string &img, - const std::string &skin=""); + const std::string &skin="", bool loadAlpha=true); Surface(Surface *s); ~Surface(); diff --git a/src/surfacecollection.cpp b/src/surfacecollection.cpp index d2f267e..ef120c4 100644 --- a/src/surfacecollection.cpp +++ b/src/surfacecollection.cpp @@ -119,7 +119,7 @@ Surface *SurfaceCollection::add(const string &path) { } DEBUG("Adding surface: '%s'\n", path.c_str()); - Surface *s = Surface::loadImage(filePath); + Surface *s = Surface::loadImage(filePath, "", defaultAlpha); if (s != NULL) { surfaces[path] = s; } diff --git a/src/surfacecollection.h b/src/surfacecollection.h index 1209dd6..631125f 100644 --- a/src/surfacecollection.h +++ b/src/surfacecollection.h @@ -42,7 +42,7 @@ public: static std::string getSkinFilePath(const std::string &skin, const std::string &file, bool useDefault = true); static std::string getSkinPath(const std::string &skin); - bool defaultAlpha; + bool defaultAlpha = true; void debug(); Surface *add(Surface *s, const std::string &path);