Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

ResImagePack.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
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  * Load unshared image from file
00020  * and convert image to diplayformat.
00021  *
00022  * @return loaded surface
00023  * @throws ImgException when image cannot be loaded
00024  * @throws SDLException when image cannot be converted
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  * Store image from file.
00047  *
00048  * @throws ImgException when image cannot be loaded
00049  * @throws SDLException when image cannot be converted
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 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2