comparison ext/guichan-0.8.1/include/guichan/image.hpp @ 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
comparison
equal deleted inserted replaced
-1:000000000000 0:4a0efb7baf70
1 /* _______ __ __ __ ______ __ __ _______ __ __
2 * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\
3 * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
4 * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / /
5 * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / /
6 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
7 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
8 *
9 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
10 *
11 *
12 * Per Larsson a.k.a finalman
13 * Olof Naessén a.k.a jansem/yakslem
14 *
15 * Visit: http://guichan.sourceforge.net
16 *
17 * License: (BSD)
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in
25 * the documentation and/or other materials provided with the
26 * distribution.
27 * 3. Neither the name of Guichan nor the names of its contributors may
28 * be used to endorse or promote products derived from this software
29 * without specific prior written permission.
30 *
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
37 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
38 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
39 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
40 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
41 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 #ifndef GCN_IMAGE_HPP
45 #define GCN_IMAGE_HPP
46
47 #include <string>
48
49 #include "guichan/platform.hpp"
50
51 namespace gcn
52 {
53 class Color;
54 class ImageLoader;
55
56 /**
57 * Holds an image. To be able to use this class you must first set an
58 * ImageLoader in Image by calling
59 * @code Image::setImageLoader(myImageLoader) @endcode
60 * The function is static. If this is not done, the constructor taking a
61 * filename will throw an exception. The ImageLoader you use must be
62 * compatible with the Graphics object you use.
63 *
64 * EXAMPLE: If you use SDLGraphics you should use SDLImageLoader.
65 * Otherwise your program might crash in a most bizarre way.
66 * @see AllegroImageLoader, HGEImageLoader, OpenLayerImageLoader,
67 * OpenGLAllegroImageLoader, OpenGLSDLImageLoader, SDLImageLoader
68 * @since 0.1.0
69 */
70 class GCN_CORE_DECLSPEC Image
71 {
72 public:
73
74 /**
75 * Constructor.
76 */
77 Image();
78
79 /**
80 * Destructor.
81 */
82 virtual ~Image();
83
84 /**
85 * Loads an image by using the class' image laoder. All image loaders implemented
86 * in Guichan return a newly instantiated image which must be deleted in
87 * order to avoid a memory leak.
88 *
89 * NOTE: The functions getPixel and putPixel are only guaranteed to work
90 * before an image has been converted to display format.
91 *
92 * @param filename The file to load.
93 * @param convertToDisplayFormat True if the image should be converted
94 * to display, false otherwise.
95 * @since 0.5.0
96 */
97 static Image* load(const std::string& filename, bool convertToDisplayFormat = true);
98
99 /**
100 * Gets the image loader used for loading images.
101 *
102 * @return The image loader used for loading images.
103 * @see setImageLoader, AllegroImageLoader, HGEImageLoader,
104 * OpenLayerImageLoader, OpenGLAllegroImageLoader,
105 * OpenGLSDLImageLoader, SDLImageLoader
106 * @since 0.1.0
107 */
108 static ImageLoader* getImageLoader();
109
110 /**
111 * Sets the ImageLoader to be used for loading images.
112 *
113 * IMPORTANT: The image loader is static and MUST be set before
114 * loading images!
115 *
116 * @param imageLoader The image loader to be used for loading images.
117 * @see getImageLoader, AllegroImageLoader, HGEImageLoader,
118 * OpenLayerImageLoader, OpenGLAllegroImageLoader,
119 * OpenGLSDLImageLoader, SDLImageLoader
120 * @since 0.1.0
121 */
122 static void setImageLoader(ImageLoader* imageLoader);
123
124 /**
125 * Frees an image.
126 *
127 * @since 0.5.0
128 */
129 virtual void free() = 0;
130
131 /**
132 * Gets the width of the image.
133 *
134 * @return The width of the image.
135 *
136 * @since 0.1.0
137 */
138 virtual int getWidth() const = 0;
139
140 /**
141 * Gets the height of the image.
142 *
143 * @return The height of the image.
144 *
145 * @since 0.1.0
146 */
147 virtual int getHeight() const = 0;
148
149 /**
150 * Gets the color of a pixel at coordinate (x, y) in the image.
151 *
152 * IMPORTANT: Only guaranteed to work before the image has been
153 * converted to display format.
154 *
155 * @param x The x coordinate.
156 * @param y The y coordinate.
157 * @return The color of the pixel.
158 *
159 * @since 0.5.0
160 */
161 virtual Color getPixel(int x, int y) = 0;
162
163 /**
164 * Puts a pixel with a certain color at coordinate (x, y).
165 *
166 * @param x The x coordinate.
167 * @param y The y coordinate.
168 * @param color The color of the pixel to put.
169 * @since 0.5.0
170 */
171 virtual void putPixel(int x, int y, const Color& color) = 0;
172
173 /**
174 * Converts the image, if possible, to display format.
175 *
176 * IMPORTANT: Only guaranteed to work before the image has been
177 * converted to display format.
178 * @since 0.5.0
179 */
180 virtual void convertToDisplayFormat() = 0;
181
182 protected:
183 /**
184 * Holds the image loader to be used when loading images.
185 */
186 static ImageLoader* mImageLoader;
187 };
188 }
189
190 #endif // end GCN_IMAGE_HPP