Adonthell 0.4
|
00001 /* 00002 $Id: image.h,v 1.28 2004/10/25 06:55:01 ksterker Exp $ 00003 00004 Copyright (C) 1999/2000/2001/2004 Alexandre Courbot 00005 Part of the Adonthell Project http://adonthell.linuxgames.com 00006 00007 This program is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License. 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY. 00011 00012 See the COPYING file for more details. 00013 */ 00014 00015 00016 /** 00017 * @file image.h 00018 * @author Alexandre Courbot <alexandrecourbot@linuxgames.com> 00019 * 00020 * @brief Declares the image class. 00021 * 00022 * 00023 */ 00024 00025 00026 #ifndef IMAGE_H_ 00027 #define IMAGE_H_ 00028 00029 #include "fileops.h" 00030 #include "screen.h" 00031 00032 00033 /** 00034 * Image manipulation class. 00035 * Designed to work with single images, without having to care about the bit 00036 * depth. This class is widely used through the %game - in fact it handles 00037 * everything that is displayed on the %screen. 00038 * This class highly relies on surface, so you'll probably want to have a look 00039 * at it before using image. 00040 */ 00041 class image : public surface 00042 { 00043 public: 00044 /** 00045 * Default constructor. 00046 * The image created via this constructor is totally empty. 00047 */ 00048 image (); 00049 00050 #ifndef SWIG 00051 /** Creates an image with a specified size. 00052 * @param l length of the image. 00053 * @param h height of the image. 00054 * @param mode use screen::dblmode or set dbl_mode to false 00055 * 00056 * @attention Not accessible from Python. 00057 */ 00058 image (u_int16 l, u_int16 h, bool mode = true); 00059 00060 /** 00061 * Create image from SDL_Surface. 00062 * @param s surface 00063 */ 00064 image (SDL_Surface *s, const SDL_Color & color); 00065 #endif 00066 00067 /** Destructor. 00068 */ 00069 ~image (); 00070 00071 /** 00072 * Resize this image. 00073 * All the content will be lost. 00074 * If you want to zoom the image you'll want to see the zoom () function 00075 * instead. 00076 * 00077 * @param l new length. 00078 * @param h new height. 00079 * @sa zoom () 00080 */ 00081 void resize (u_int16 l, u_int16 h); 00082 00083 /** 00084 * Resets the image to it's initial state, that is totally 00085 * empty. 00086 * 00087 */ 00088 void clear (); 00089 00090 00091 /** 00092 * @name Loading / Saving Methods. 00093 * These methods allows you to load and save 00094 * an image in different formats. 00095 * 00096 */ 00097 //@{ 00098 00099 00100 /** Loads an image from an opened file, saved in %game internal format, 00101 * with alpha and mask values. 00102 * @param file the opened file from which to read. 00103 * @return 00104 * @li 0 in case of success. 00105 * @li -1 in case of error. 00106 * @sa load () 00107 */ 00108 s_int8 get (igzstream& file); 00109 00110 /** Loads an image from a file name, in game internal format, with alpha 00111 * and mask values. 00112 * @param fname the name of the file to load. 00113 * @return 00114 * @li 0 in case of success. 00115 * @li -1 in case of error. 00116 * @sa get () 00117 */ 00118 s_int8 load (string fname); 00119 00120 /** Loads an image from an opened file, saved in %game internal format, 00121 * without alpha and mask values. 00122 * @param file the opened file from which to read. 00123 * @return 00124 * @li 0 in case of success. 00125 * @li -1 in case of error. 00126 * @sa load_raw () 00127 */ 00128 s_int8 get_raw (igzstream& file); 00129 00130 /** Loads an image from a file name, in game internal format, without alpha 00131 * and mask values. 00132 * @param fname the name of the file to load. 00133 * @return 00134 * @li 0 in case of success. 00135 * @li -1 in case of error. 00136 * @sa get_raw () 00137 */ 00138 s_int8 load_raw (string fname); 00139 00140 /** Loads an image from an opened file, in PNM format, without 00141 * alpha and mask values. 00142 * @param file the opened file from which to read. 00143 * @return 00144 * @li 0 in case of success. 00145 * @li -1 in case of error. 00146 * @sa load_pnm () 00147 */ 00148 s_int8 get_pnm (SDL_RWops * file); 00149 00150 /** Loads an image from a file name, in PNM format, without 00151 * alpha and mask values. 00152 * @param fname the name of the file to load. 00153 * @return 00154 * @li 0 in case of success. 00155 * @li -1 in case of error. 00156 * @sa get_pnm () 00157 */ 00158 s_int8 load_pnm (string fname); 00159 00160 /** Saves an image into an opened file, in %game format, with 00161 * alpha and mask values. 00162 * @warning as the image which is saved comes from a %screen's depth 00163 * surface, it will be slightly altered during the save. 00164 * If you want a class capable of saving images with full 00165 * truecolor quality, use image_edit instead. 00166 * @param file opened file where to save into. 00167 * @return 00168 * @li 0 in case of success. 00169 * @li -1 in case of error. 00170 * @sa save () 00171 */ 00172 s_int8 put (ogzstream& file) const; 00173 00174 /** Saves an image into an file, in %game format, with 00175 * alpha and mask values. 00176 * @warning as the image which is saved comes from a %screen's depth 00177 * surface, it will be slightly altered during the save. 00178 * If you want a class capable of saving images with full 00179 * truecolor quality, use image_edit instead. 00180 * @param fname file name where to save into. 00181 * @return 00182 * @li 0 in case of success. 00183 * @li -1 in case of error. 00184 * @sa put () 00185 */ 00186 s_int8 save (string fname) const; 00187 00188 /** Saves an image into an opened file, in %game format, without 00189 * alpha and mask values. 00190 * @warning as the image which is saved comes from a %screen's depth 00191 * surface, it will be slightly altered during the save. 00192 * If you want a class capable of saving images with full 00193 * truecolor quality, use image_edit instead. 00194 * @param file opened file where to save into. 00195 * @return 00196 * @li 0 in case of success. 00197 * @li -1 in case of error. 00198 * @sa save_raw () 00199 */ 00200 s_int8 put_raw (ogzstream& file) const; 00201 00202 /** Saves an image into an file, in %game format, without 00203 * alpha and mask values. 00204 * @warning as the image which is saved comes from a %screen's depth 00205 * surface, it will be slightly altered during the save. 00206 * If you want a class capable of saving images with full 00207 * truecolor quality, use image_edit instead. 00208 * @param fname file name where to save into. 00209 * @return 00210 * @li 0 in case of success. 00211 * @li -1 in case of error. 00212 * @sa put_raw () 00213 */ 00214 s_int8 save_raw (string fname) const; 00215 00216 /** Saves an image into an opened file, in PNM format, without 00217 * alpha and mask values. 00218 * @warning as the image which is saved comes from a %screen's depth 00219 * surface, it will be slightly altered during the save. 00220 * If you want a class capable of saving images with full 00221 * truecolor quality, use image_edit instead. 00222 * @param file opened file where to save into. 00223 * @return 00224 * @li 0 in case of success. 00225 * @li -1 in case of error. 00226 * @sa save_pnm () 00227 */ 00228 s_int8 put_pnm (SDL_RWops * file) const; 00229 00230 /** Saves an image into an file, in PNM format, without 00231 * alpha and mask values. 00232 * @warning as the image which is saved comes from a %screen's depth 00233 * surface, it will be slightly altered during the save. 00234 * If you want a class capable of saving images with full 00235 * truecolor quality, use image_edit instead. 00236 * @param fname file name where to save into. 00237 * @return 00238 * @li 0 in case of success. 00239 * @li -1 in case of error. 00240 * @sa put_pnm () 00241 */ 00242 s_int8 save_pnm (string fname) const; 00243 00244 00245 //@} 00246 00247 00248 /** 00249 * @name Special FX Methods. 00250 * Allows you to put fantasy in your image manipulations! Can 00251 * eventually even be usefull... 00252 * 00253 */ 00254 //@{ 00255 00256 00257 /** Zooms a surface. 00258 * Zoom the content of the src surface into this image, to it's own size. 00259 * @param src the source image to zoom. 00260 */ 00261 void zoom (const surface& src) 00262 { 00263 zoom (src, length (), height (), 0, 0); 00264 } 00265 00266 #ifndef SWIG 00267 /** 00268 * Zooms a surface. 00269 * Zoom the content of the src surface into this image, to the size 00270 * (l, h), at position (x, y) on this image. 00271 * 00272 * @param src The source surface to zoom. 00273 * @param l length of the zoomed image. 00274 * @param h height of the zoomed image. 00275 * @param x X offset on the destination image. 00276 * @param y Y offset on the destination image. 00277 * 00278 * @attention Not available from Python. Use zoom_to () from Python instead. 00279 * @sa zoom_to () 00280 */ 00281 void zoom (const surface& src, u_int16 l, u_int16 h, u_int16 x = 0, u_int16 y = 0); 00282 #endif 00283 00284 /** 00285 * Synonym of zoom () to guarantee its access from Python. 00286 * 00287 * @sa zoom () 00288 * 00289 */ 00290 void zoom_to (const surface& src, u_int16 l, u_int16 h, u_int16 x = 0, u_int16 y = 0) 00291 { 00292 zoom (src, l, h, x, y); 00293 } 00294 00295 /** Tiles a surface. 00296 * Tiles the src surface so this image is totally filled. 00297 * @param source the source surface to tile. 00298 */ 00299 void tile (const surface& src) 00300 { 00301 tile (src, length (), height ()); 00302 } 00303 00304 #ifndef SWIG 00305 /** 00306 * Tiles a surface. 00307 * Tiles the src surface so the area of this image starting at position 00308 * (x, y) and (l, h) sized is totally filled. 00309 * @param source the source surface to tile. 00310 * @param l length of the area to tile. 00311 * @param h height of the area to tile. 00312 * @param x X offset on the destination image. 00313 * @param y Y offset on the destination image. 00314 * 00315 * @attention Not available from Python. Use tile_to () from Python instead. 00316 * @sa tile_to () 00317 */ 00318 void tile (const surface& src, u_int16 l, u_int16 h, u_int16 x = 0, u_int16 y = 0); 00319 #endif 00320 00321 /** 00322 * Synonym of tile () to guarantee its access from Python. 00323 * 00324 * @sa tile () 00325 * 00326 */ 00327 void tile_to (const surface& src, u_int16 l, u_int16 h, u_int16 x = 0, u_int16 y = 0) 00328 { 00329 tile (src, l, h, x, y); 00330 } 00331 00332 /** 00333 * Applies a "brightness" to a surface. 00334 * Lighten (or darken) the src surface and put the result into this image. 00335 * This image will be resized to the src surface's size. 00336 * @param src the source surface to lighten/darken. 00337 * @param cont the "brightness" value, if < 256 the image will be 00338 * darkened. 00339 * @todo modify it so when < 128 -> darken, > 128 -> brighten. 00340 * @param proceed_mask if set to true, then the translucent pixels will 00341 * be lightened/darkened too. 00342 */ 00343 void brightness (const surface& src, u_int8 cont, bool proceed_mask = false); 00344 //@} 00345 00346 00347 #ifndef SWIG 00348 /** 00349 * Image copy (similar to copy ()). 00350 * 00351 * @attention Not available from Python. Use copy () from Python instead. 00352 * @sa copy () 00353 */ 00354 image& operator = (const image& src); 00355 #endif 00356 00357 /** 00358 * Synonym of operator = to guarantee its access from Python. 00359 * 00360 * @sa operator = 00361 */ 00362 void copy (const image& src) 00363 { 00364 *this = src; 00365 } 00366 00367 private: 00368 /** 00369 * Forbid value passing. 00370 */ 00371 image(const image& src); 00372 00373 /** 00374 * Converts a raw image source recorded in RGB to the current screen depth 00375 * and put it to this image. 00376 * 00377 * @param rawdata raw data to convert. 00378 * @param l length of the raw image. 00379 * @param h height of the raw image. 00380 */ 00381 void raw2display (void * rawdata, u_int16 l, u_int16 h); 00382 }; 00383 00384 00385 #endif