25 #include <boost/scoped_array.hpp>
26 #include <boost/scoped_ptr.hpp>
28 #include <SDL_image.h>
34 #include "util/base/exception.h"
35 #include "util/resource/resource_location.h"
36 #include "util/resource/resource.h"
37 #include "vfs/raw/rawdata.h"
39 #include "video/renderbackend.h"
40 #include "video/image_location.h"
42 #include "image_loader.h"
45 IResource* ImageLoader::loadResource(
const ResourceLocation& location) {
46 const ImageLocation* loc =
dynamic_cast<const ImageLocation*
>(&location);
48 const std::string& filename = location.getFilename();
49 boost::scoped_ptr<RawData> data (m_vfs->
open(filename));
50 size_t datalen = data->getDataLength();
51 boost::scoped_array<uint8_t> darray(
new uint8_t[datalen]);
52 data->readInto(darray.get(), datalen);
53 SDL_RWops* rwops = SDL_RWFromConstMem(darray.get(), datalen);
54 SDL_Surface* surface = IMG_Load_RW(rwops,
false);
60 Image* res = RenderBackend::instance()->createImage(surface);
61 res->setResourceLocation(location);
63 res->setXShift(loc->getXShift());
64 res->setYShift(loc->getYShift());
66 res->setAlphaOptimizerEnabled(
true);