Mercurial > fife-parpg
comparison engine/core/loaders/native/video_loaders/image_loader.cpp @ 0:4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
author | mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 29 Jun 2008 18:44:17 +0000 |
parents | |
children | 90005975cdbb |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4a0efb7baf70 |
---|---|
1 /*************************************************************************** | |
2 * Copyright (C) 2005-2008 by the FIFE team * | |
3 * http://www.fifengine.de * | |
4 * This file is part of FIFE. * | |
5 * * | |
6 * FIFE is free software; you can redistribute it and/or modify * | |
7 * it under the terms of the GNU General Public License as published by * | |
8 * the Free Software Foundation; either version 2 of the License, or * | |
9 * (at your option) any later version. * | |
10 * * | |
11 * This program is distributed in the hope that it will be useful, * | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
14 * GNU General Public License for more details. * | |
15 * * | |
16 * You should have received a copy of the GNU General Public License * | |
17 * along with this program; if not, write to the * | |
18 * Free Software Foundation, Inc., * | |
19 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * | |
20 ***************************************************************************/ | |
21 | |
22 // Standard C++ library includes | |
23 | |
24 // 3rd party library includes | |
25 #include <boost/scoped_array.hpp> | |
26 #include <boost/scoped_ptr.hpp> | |
27 #include <SDL.h> | |
28 #include <SDL_image.h> | |
29 | |
30 // FIFE includes | |
31 // These includes are split up in two parts, separated by one empty line | |
32 // First block: files included from the FIFE root src directory | |
33 // Second block: files included from the same folder | |
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" | |
38 #include "vfs/vfs.h" | |
39 #include "video/renderbackend.h" | |
40 #include "video/image_location.h" | |
41 | |
42 #include "image_loader.h" | |
43 | |
44 namespace FIFE { | |
45 IResource* ImageLoader::loadResource(const ResourceLocation& location) { | |
46 const ImageLocation* loc = dynamic_cast<const ImageLocation*>(&location); | |
47 | |
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); | |
55 SDL_FreeRW(rwops); | |
56 if( !surface ) { | |
57 return 0; | |
58 } | |
59 | |
60 Image* res = RenderBackend::instance()->createImage(surface); | |
61 if (loc) { | |
62 res->setXShift(loc->getXShift()); | |
63 res->setYShift(loc->getYShift()); | |
64 } | |
65 res->setAlphaOptimizerEnabled(true); | |
66 return res; | |
67 }; | |
68 } |