Last change
on this file since 956 was
956,
checked in by sam, 11 years ago
|
core: remove calls to exit() in image loaders since they can now report
on errors.
|
-
Property svn:keywords set to
Id
|
File size:
1.4 KB
|
Line | |
---|
1 | // |
---|
2 | // Lol Engine |
---|
3 | // |
---|
4 | // Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net> |
---|
5 | // This program is free software; you can redistribute it and/or |
---|
6 | // modify it under the terms of the Do What The Fuck You Want To |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
9 | // |
---|
10 | |
---|
11 | #if defined HAVE_CONFIG_H |
---|
12 | # include "config.h" |
---|
13 | #endif |
---|
14 | |
---|
15 | #if defined USE_SDL_IMAGE |
---|
16 | |
---|
17 | #include <cmath> |
---|
18 | |
---|
19 | #include <SDL.h> |
---|
20 | #include <SDL_image.h> |
---|
21 | |
---|
22 | #include "core.h" |
---|
23 | #include "image/image-private.h" |
---|
24 | |
---|
25 | using namespace std; |
---|
26 | |
---|
27 | namespace lol |
---|
28 | { |
---|
29 | |
---|
30 | /* |
---|
31 | * Image implementation class |
---|
32 | */ |
---|
33 | |
---|
34 | DECLARE_IMAGE_LOADER(SdlImageData, 50) |
---|
35 | { |
---|
36 | public: |
---|
37 | virtual bool Open(char const *); |
---|
38 | virtual bool Close(); |
---|
39 | |
---|
40 | virtual void *GetData() const; |
---|
41 | |
---|
42 | private: |
---|
43 | SDL_Surface *img; |
---|
44 | }; |
---|
45 | |
---|
46 | /* |
---|
47 | * Public Image class |
---|
48 | */ |
---|
49 | |
---|
50 | bool SdlImageData::Open(char const *path) |
---|
51 | { |
---|
52 | for (char const *name = path; *name; name++) |
---|
53 | if ((img = IMG_Load(name))) |
---|
54 | break; |
---|
55 | |
---|
56 | if (!img) |
---|
57 | { |
---|
58 | #if !LOL_RELEASE |
---|
59 | Log::Error("could not load %s\n", path); |
---|
60 | #endif |
---|
61 | return false; |
---|
62 | } |
---|
63 | |
---|
64 | size = ivec2(img->w, img->h); |
---|
65 | format = img->format->Amask ? Image::FORMAT_RGBA : Image::FORMAT_RGB; |
---|
66 | |
---|
67 | return true; |
---|
68 | } |
---|
69 | |
---|
70 | bool SdlImageData::Close() |
---|
71 | { |
---|
72 | SDL_FreeSurface(img); |
---|
73 | |
---|
74 | return true; |
---|
75 | } |
---|
76 | |
---|
77 | void * SdlImageData::GetData() const |
---|
78 | { |
---|
79 | return img->pixels; |
---|
80 | } |
---|
81 | |
---|
82 | } /* namespace lol */ |
---|
83 | |
---|
84 | #endif /* defined USE_SDL_IMAGE */ |
---|
85 | |
---|
Note: See
TracBrowser
for help on using the repository browser.