summaryrefslogtreecommitdiff
path: root/src/resources/sdlimageloader.cpp
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-13 10:20:19 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-13 10:20:19 +0000
commitd3385829ca6f7d52e21706b25b14fe1083cfe984 (patch)
treeaea368b2434a49864b33183f95b6aae36abef3b7 /src/resources/sdlimageloader.cpp
parent7d287027babe615e01ddcf20edc1057f7d778c58 (diff)
downloadmana-d3385829ca6f7d52e21706b25b14fe1083cfe984.tar.gz
mana-d3385829ca6f7d52e21706b25b14fe1083cfe984.tar.bz2
mana-d3385829ca6f7d52e21706b25b14fe1083cfe984.tar.xz
mana-d3385829ca6f7d52e21706b25b14fe1083cfe984.zip
Merged Guichan 0.5.0 support from guichan-0.5.0 branch, plus several updates
from the 0.1.0 branch.
Diffstat (limited to 'src/resources/sdlimageloader.cpp')
-rw-r--r--src/resources/sdlimageloader.cpp53
1 files changed, 2 insertions, 51 deletions
diff --git a/src/resources/sdlimageloader.cpp b/src/resources/sdlimageloader.cpp
index 88c4143e..ae4f4dcb 100644
--- a/src/resources/sdlimageloader.cpp
+++ b/src/resources/sdlimageloader.cpp
@@ -24,60 +24,11 @@
#include "sdlimageloader.h"
#include <string>
-#include <SDL_image.h>
-
-#include <guichan/exception.hpp>
#include "resourcemanager.h"
-void SDLImageLoader::prepare(const std::string &filename)
+SDL_Surface* SDLImageLoader::loadSDLSurface(const std::string& filename)
{
- if (mCurrentImage)
- {
- throw GCN_EXCEPTION("Function called before finalizing or discarding last loaded image.");
- }
-
ResourceManager *resman = ResourceManager::getInstance();
-
- int fileSize;
- void *buffer = resman->loadFile(filename, fileSize);
-
- SDL_Surface *tmp = NULL;
- if (buffer) {
- SDL_RWops *rw = SDL_RWFromMem(buffer, fileSize);
- tmp = IMG_Load_RW(rw, 1);
- ::free(buffer);
- }
-
- if (!tmp)
- {
- throw GCN_EXCEPTION(std::string("Unable to load image file: ")+filename);
- }
-
- Uint32 rmask, gmask, bmask, amask;
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- rmask = 0xff000000;
- gmask = 0x00ff0000;
- bmask = 0x0000ff00;
- amask = 0x000000ff;
-#else
- rmask = 0x000000ff;
- gmask = 0x0000ff00;
- bmask = 0x00ff0000;
- amask = 0xff000000;
-#endif
-
- mCurrentImage = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, 32,
- rmask, gmask, bmask, amask);
-
- if (!mCurrentImage)
- {
- throw GCN_EXCEPTION(std::string("Not enough memory to load: ")+filename);
- }
-
- SDL_Surface* tmp2 = SDL_ConvertSurface(tmp, mCurrentImage->format, SDL_SWSURFACE);
- SDL_FreeSurface(tmp);
- SDL_FreeSurface(mCurrentImage);
-
- mCurrentImage = tmp2;
+ return resman->loadSDLSurface(filename);
}