00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ResImagePack.h"
00010
00011 #include "Path.h"
00012 #include "ImgException.h"
00013 #include "SDLException.h"
00014
00015 #include "SDL_image.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 SDL_Surface *
00027 ResImagePack::loadImage(const Path &file)
00028 {
00029 SDL_Surface *raw_image = IMG_Load(file.getNative().c_str());
00030 if (NULL == raw_image) {
00031 throw ImgException(ExInfo("Load")
00032 .addInfo("file", file.getNative()));
00033 }
00034
00035 SDL_Surface *surface = SDL_DisplayFormatAlpha(raw_image);
00036 if (NULL == surface) {
00037 throw SDLException(ExInfo("DisplayFormat")
00038 .addInfo("file", file.getNative()));
00039 }
00040 SDL_FreeSurface(raw_image);
00041
00042 return surface;
00043 }
00044
00045
00046
00047
00048
00049
00050
00051 void
00052 ResImagePack::addImage(const std::string &name, const Path &file)
00053 {
00054 SDL_Surface *surface = loadImage(file);
00055 addRes(name, surface);
00056 }
00057
00058 void
00059 ResImagePack::unloadRes(SDL_Surface *res)
00060 {
00061 SDL_FreeSurface(res);
00062 }
00063