27 #include <SDL_image.h> 55 const std::string& filename = img->
getName();
56 std::unique_ptr<RawData> data(vfs->
open(filename));
57 size_t datalen = data->getDataLength();
58 std::unique_ptr<uint8_t[]> darray(
new uint8_t[datalen]);
59 data->readInto(darray.get(), datalen);
60 SDL_RWops* rwops = SDL_RWFromConstMem(darray.get(),
static_cast<int>(datalen));
62 SDL_Surface* surface = IMG_Load_RW(rwops,
false);
65 throw SDLException(std::string(
"Fatal Error when loading image into a SDL_Surface: ") + SDL_GetError());
75 SDL_PixelFormat src_format = *surface->format;
76 uint8_t dstbits = dst_format.BitsPerPixel;
77 uint8_t srcbits = src_format.BitsPerPixel;
79 if (srcbits != 32 || dst_format.Rmask != src_format.Rmask || dst_format.Gmask != src_format.Gmask ||
80 dst_format.Bmask != src_format.Bmask || dst_format.Amask != src_format.Amask) {
81 dst_format.BitsPerPixel = 32;
82 SDL_Surface* conv = SDL_ConvertSurface(surface, &dst_format, 0);
83 dst_format.BitsPerPixel = dstbits;
86 throw SDLException(std::string(
"Fatal Error when converting surface to the screen format: ") + SDL_GetError());
90 SDL_FreeSurface(surface);
Abstract interface for all the renderbackends.
void setXShift(int32_t xshift)
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
const SDL_PixelFormat & getPixelFormat() const
Gets the current screen rgba format.
virtual void load(IResource *res)
int32_t getXShift() const
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
void setYShift(int32_t yshift)