25 #include <boost/scoped_array.hpp>
26 #include <boost/scoped_ptr.hpp>
28 #include <SDL_image.h>
56 const std::string& filename = img->
getName();
57 boost::scoped_ptr<RawData> data (vfs->
open(filename));
58 size_t datalen = data->getDataLength();
59 boost::scoped_array<uint8_t> darray(
new uint8_t[datalen]);
60 data->readInto(darray.get(), datalen);
61 SDL_RWops* rwops = SDL_RWFromConstMem(darray.get(),
static_cast<int>(datalen));
63 SDL_Surface* surface = IMG_Load_RW(rwops,
false);
66 throw SDLException(std::string(
"Fatal Error when loading image into a SDL_Surface: ") + SDL_GetError());
76 SDL_PixelFormat src_format = *surface->format;
77 uint8_t dstbits = dst_format.BitsPerPixel;
78 uint8_t srcbits = src_format.BitsPerPixel;
80 if (srcbits != 32 || dst_format.Rmask != src_format.Rmask || dst_format.Gmask != src_format.Gmask ||
81 dst_format.Bmask != src_format.Bmask || dst_format.Amask != src_format.Amask) {
82 dst_format.BitsPerPixel = 32;
83 SDL_Surface* conv = SDL_ConvertSurface(surface, &dst_format, SDL_SWSURFACE | SDL_SRCALPHA);
84 dst_format.BitsPerPixel = dstbits;
87 throw SDLException(std::string(
"Fatal Error when converting surface to the screen format: ") + SDL_GetError());
91 SDL_FreeSurface(surface);
Abstract interface for all the renderbackends.
void setXShift(int32_t xshift)
int32_t getXShift() const
virtual const std::string & getName() const =0
The name of the renderbackend.
RawData * open(const std::string &path)
Open a file.
int32_t getYShift() const
virtual void load(IResource *res)
virtual void setSurface(SDL_Surface *surface)=0
This frees the current suface and replaces it with the surface passed in the parameter (which can be ...
virtual const std::string & getName()
bool isSharedImage() const
Returns true if this image shares data with another one.
the main VFS (virtual file system) class
const SDL_PixelFormat & getPixelFormat() const
Gets the current screen rgba format.
void setYShift(int32_t yshift)