The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
utils.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 /** @file */
16 
17 #ifndef SDL_UTILS_INCLUDED
18 #define SDL_UTILS_INCLUDED
19 
20 #include "scoped_resource.hpp"
21 #include "util.hpp"
22 #include "sdl/compat.hpp"
23 
24 #include <SDL.h>
25 
26 #include <cstdlib>
27 #include <iosfwd>
28 #include <map>
29 #include <string>
30 
31 //older versions of SDL don't define the
32 //mouse wheel macros, so define them ourselves
33 //if necessary.
34 #ifndef SDL_BUTTON_WHEELUP
35 #define SDL_BUTTON_WHEELUP 4
36 #endif
37 
38 #ifndef SDL_BUTTON_WHEELDOWN
39 #define SDL_BUTTON_WHEELDOWN 5
40 #endif
41 
42 #ifndef SDL_BUTTON_WHEELLEFT
43 #define SDL_BUTTON_WHEELLEFT 6
44 #endif
45 
46 #ifndef SDL_BUTTON_WHEELRIGHT
47 #define SDL_BUTTON_WHEELRIGHT 7
48 #endif
49 
51 
52 
53 struct surface
54 {
55 private:
56  static void sdl_add_ref(SDL_Surface *surf)
57  {
58  if (surf != nullptr)
59  ++surf->refcount;
60  }
61 
63  void operator()(SDL_Surface *surf) const
64  {
65  if (surf != nullptr)
66  SDL_FreeSurface(surf);
67  }
68  };
69 
71 public:
72  surface() : surface_(nullptr)
73  {}
74 
75  surface(SDL_Surface *surf) : surface_(surf)
76  {}
77 
78  surface(const surface& o) : surface_(o.surface_.get())
79  {
81  }
82 
83  void assign(const surface& o)
84  {
85  SDL_Surface *surf = o.surface_.get();
86  sdl_add_ref(surf); // need to be done before assign to avoid corruption on "a=a;"
87  surface_.assign(surf);
88  }
89 
91  {
92  assign(o);
93  return *this;
94  }
95 
96  operator SDL_Surface*() const { return surface_.get(); }
97 
98  SDL_Surface* get() const { return surface_.get(); }
99 
100  SDL_Surface* operator->() const { return surface_.get(); }
101 
102  void assign(SDL_Surface* surf) { surface_.assign(surf); }
103 
104  bool null() const { return surface_.get() == nullptr; }
105 
106 private:
107  scoped_sdl_surface surface_;
108 };
109 
110 bool operator<(const surface& a, const surface& b);
111 
112 inline void sdl_blit(const surface& src, SDL_Rect* src_rect, surface& dst, SDL_Rect* dst_rect){
113  SDL_BlitSurface(src, src_rect, dst, dst_rect);
114 }
115 
116 inline void sdl_copy_portion(const surface& screen, SDL_Rect* screen_rect, surface& dst, SDL_Rect* dst_rect){
117  SDL_SetSurfaceBlendMode(screen, SDL_BLENDMODE_NONE);
118  SDL_SetSurfaceBlendMode(dst, SDL_BLENDMODE_NONE);
119  SDL_BlitSurface(screen, screen_rect, dst, dst_rect);
120  SDL_SetSurfaceBlendMode(screen, SDL_BLENDMODE_BLEND);
121 }
122 
123 /**
124  * This method blends a RGBA color. The method takes as input a surface,
125  * the RGB color to blend and a value specifying how much blending to apply.
126  * The blended color is returned.
127  * Caution: if you use a transparent color,
128  * make sure the resulting color is not equal to the transparent color.
129  */
130 Uint32 blend_rgba(const surface& surf, unsigned char r, unsigned char g, unsigned char b,
131  unsigned char a, unsigned char drop);
132 
133 /**
134  * Check that the surface is neutral bpp 32.
135  *
136  * The surface may have an empty alpha channel.
137  *
138  * @param surf The surface to test.
139  *
140  * @returns The status @c true if neutral, @c false if not.
141  */
142 bool is_neutral(const surface& surf);
143 
147 
148 /**
149  * Stretches a surface in the horizontal direction.
150  *
151  * The stretches a surface it uses the first pixel in the horizontal
152  * direction of the original surface and copies that to the destination.
153  * This means only the first column of the original is used for the destination.
154  * @param surf The source surface.
155  * @param w The width of the resulting surface.
156  * @param optimize Should the return surface be RLE optimized.
157  *
158  * @return An optimized surface.
159  * returned.
160  * @retval 0 Returned upon error.
161  * @retval surf Returned if w == surf->w, note this ignores the
162  * optimize flag.
163  */
165  const surface& surf, const unsigned w, const bool optimize = true);
166 
167 /**
168  * Stretches a surface in the vertical direction.
169  *
170  * The stretches a surface it uses the first pixel in the vertical
171  * direction of the original surface and copies that to the destination.
172  * This means only the first row of the original is used for the destination.
173  * @param surf The source surface.
174  * @param h The height of the resulting surface.
175  * @param optimize Should the return surface be RLE optimized.
176  *
177  * @return An optimized surface.
178  * returned.
179  *
180  * @retval surf Returned if h == surf->h, note this ignores the
181  * optimize flag.
182  */
184  const surface& surf, const unsigned h, const bool optimize = true);
185 
186 /** Scale a surface using xBRZ algorithm
187  * @param surf The source surface
188  * @param z The scaling factor. Should be an integer 2-5 (1 is tolerated).
189  * @return The scaled (optimized) surface
190  */
191 surface scale_surface_xbrz(const surface & surf, size_t z);
192 
193 /** Scale a surface using the nearest neighbor algorithm (provided by xBRZ lib)
194  * @param surf The sources surface
195  * @param w The width of the resulting surface.
196  * @param h The height of the resulting surface.
197  * @return The rescaled surface.
198  */
199 surface scale_surface_nn(const surface & surf, int w, int h);
200 
201 /** Scale a surface
202  * @param surf The source surface.
203  * @param w The width of the resulting surface.
204  * @param h The height of the resulting surface.
205  * @param optimize Should the return surface be RLE optimized.
206  * @return A surface containing the scaled version of the source.
207  * @retval 0 Returned upon error.
208  * @retval surf Returned if w == surf->w and h == surf->h
209  * note this ignores the optimize flag.
210  */
211 surface scale_surface(const surface &surf, int w, int h, bool optimize /*=true*/);
212 surface scale_surface(const surface &surf, int w, int h);
213 //commenting out the default parameter so that it is possible to make function pointers to the 3 parameter version
214 
215 /** Scale a surface using modified nearest neighbour algorithm. Use only if
216  * preserving sharp edges is a priority (e.g. minimap).
217  * @param surf The source surface.
218  * @param w The width of the resulting surface.
219  * @param h The height of the resulting surface.
220  * @param optimize Should the return surface be RLE optimized.
221  * @return A surface containing the scaled version of the source.
222  * @retval 0 Returned upon error.
223  * @retval surf Returned if w == surf->w and h == surf->h
224  * note this ignores the optimize flag.
225  */
226 surface scale_surface_sharp(const surface& surf, int w, int h, bool optimize=true);
227 
228 /** Tile a surface
229  * @param surf The source surface.
230  * @param w The width of the resulting surface.
231  * @param h The height of the resulting surface.
232  * @param optimize Should the return surface be RLE optimized
233  * @return A surface containing the tiled version of the source.
234  * @retval 0 Returned upon error
235  * @retval surf Returned if w == surf->w and h == surf->h
236  * note this ignores the optimize flag.
237  */
238 surface tile_surface(const surface &surf, int w, int h, bool optimize=true);
239 
240 surface adjust_surface_color(const surface &surf, int r, int g, int b, bool optimize=true);
241 surface greyscale_image(const surface &surf, bool optimize=true);
242 surface monochrome_image(const surface &surf, const int threshold, bool optimize=true);
243 surface sepia_image(const surface &surf, bool optimize=true);
244 surface negative_image(const surface &surf, const int thresholdR, const int thresholdG, const int thresholdB, bool optimize=true);
245 surface alpha_to_greyscale(const surface & surf, bool optimize=true);
246 surface wipe_alpha(const surface & surf, bool optimize=true);
247 /** create an heavy shadow of the image, by blurring, increasing alpha and darkening */
248 surface shadow_image(const surface &surf, bool optimize=true);
249 
250 enum channel { RED, GREEN, BLUE, ALPHA };
251 surface swap_channels_image(const surface& surf, channel r, channel g, channel b, channel a, bool optimize=true);
252 
253 /**
254  * Recolors a surface using a map with source and converted palette values.
255  * This is most often used for team-coloring.
256  *
257  * @param surf The source surface.
258  * @param map_rgb Map of color values, with the keys corresponding to the
259  * source palette, and the values to the recolored palette.
260  * @param optimize Whether the new surface should be RLE encoded. Only
261  * useful when the source is not the screen and it is
262  * going to be used multiple times.
263  * @return A recolored surface, or a null surface if there are
264  * problems with the source.
265  */
266 surface recolor_image(surface surf, const std::map<Uint32, Uint32>& map_rgb,
267  bool optimize=true);
268 
269 surface brighten_image(const surface &surf, fixed_t amount, bool optimize=true);
270 
271 /** Get a portion of the screen.
272  * Send nullptr if the portion is outside of the screen.
273  * @param surf The source surface.
274  * @param rect The portion of the source surface to copy.
275  * @return A surface containing the portion of the source.
276  * No RLE or Alpha bits are set.
277  * @retval 0 if error or the portion is outside of the surface.
278  */
279 surface get_surface_portion(const surface &surf, SDL_Rect &rect);
280 
281 surface adjust_surface_alpha(const surface &surf, fixed_t amount, bool optimize=true);
282 surface adjust_surface_alpha_add(const surface &surf, int amount, bool optimize=true);
283 
284 /** Applies a mask on a surface. */
285 surface mask_surface(const surface &surf, const surface &mask, bool* empty_result = nullptr, const std::string& filename = std::string());
286 
287 /** Check if a surface fit into a mask */
288 bool in_mask_surface(const surface &surf, const surface &mask);
289 
290 /** Progressively reduce alpha of bottom part of the surface
291  * @param surf The source surface.
292  * @param depth The height of the bottom part in pixels
293  * @param alpha_base The alpha adjustment at the interface
294  * @param alpha_delta The alpha adjustment reduction rate by pixel depth
295  * @param optimize Optimize by converting to result to display
296 */
297 surface submerge_alpha(const surface &surf, int depth, float alpha_base, float alpha_delta, bool optimize=true);
298 
299 /**
300  * Light surf using lightmap
301  * @param surf The source surface.
302  * @param lightmap add/subtract this color to surf
303  * but RGB values are converted to (X-128)*2
304  * to cover the full (-256,256) spectrum.
305  * Should already be neutral
306  * @param optimize Whether the new surface should be RLE encoded.
307 */
308 surface light_surface(const surface &surf, const surface &lightmap, bool optimize=true);
309 
310 /** Cross-fades a surface. */
311 surface blur_surface(const surface &surf, int depth = 1, bool optimize=true);
312 
313 /**
314  * Cross-fades a surface in place.
315  *
316  * @param surf The surface to blur, must be not optimized
317  * and have 32 bits per pixel.
318  * @param rect The part of the surface to blur.
319  * @param depth The depth of the blurring.
320  */
321 void blur_surface(surface& surf, SDL_Rect rect, int depth = 1);
322 
323 /**
324  * Cross-fades a surface with alpha channel.
325  *
326  * @todo FIXME: This is just an adapted copy-paste
327  * of the normal blur but with blur alpha channel too
328  */
329 surface blur_alpha_surface(const surface &surf, int depth = 1, bool optimize=true);
330 
331 /** Cuts a rectangle from a surface. */
332 surface cut_surface(const surface &surf, SDL_Rect const &r);
333 
334 /**
335  * Blends a surface with a color.
336  *
337  * Every pixel in the surface will be blended with the @p color given. The
338  * final color of a pixel is amount * @p color + (1 - amount) * original.
339  *
340  * @param surf The surface to blend.
341  * @param amount The amount of the new color is determined by
342  * @p color. Must be a number in the range
343  * [0, 1].
344  * @param color The color to blend width, note its alpha
345  * channel is ignored.
346  * @param optimize Should the return surface be RLE optimized.
347  *
348  * @return The blended surface.
349  */
351  const surface &surf
352  , const double amount
353  , const Uint32 color
354  , const bool optimize = true);
355 
356 /**
357  * Rotates a surface by any degrees.
358  *
359  * @pre @p zoom >= @p offset Otherwise @return will have empty pixels.
360  * @pre @p offset > 0 Otherwise the procedure will not return.
361  *
362  * @param surf The surface to rotate.
363  * @param angle The angle of rotation.
364  * @param zoom Which zoom level to use for calculating the result.
365  * @param offset Pixel offset when scanning the zoomed source.
366  * @param optimize Should the return surface be RLE optimized.
367  *
368  * @return The rotated surface.
369  */
370 surface rotate_any_surface(const surface& surf, float angle,
371  int zoom, int offset, bool optimize=true);
372 
373 /**
374  * Rotates a surface 180 degrees.
375  *
376  * @param surf The surface to rotate.
377  * @param optimize Should the return surface be RLE optimized.
378  *
379  * @return The rotated surface.
380  */
381 surface rotate_180_surface(const surface &surf, bool optimize=true);
382 
383 /**
384  * Rotates a surface 90 degrees.
385  *
386  * @param surf The surface to rotate.
387  * @param clockwise Whether the rotation should be clockwise (true)
388  * or counter-clockwise (false).
389  * @param optimize Should the return surface be RLE optimized.
390  *
391  * @return The rotated surface.
392  */
393 surface rotate_90_surface(const surface &surf, bool clockwise, bool optimize=true);
394 
395 surface flip_surface(const surface &surf, bool optimize=true);
396 surface flop_surface(const surface &surf, bool optimize=true);
397 surface create_compatible_surface(const surface &surf, int width = -1, int height = -1);
398 
399 /**
400  * Replacement for sdl_blit.
401  *
402  * sdl_blit has problems with blitting partly transparent surfaces so
403  * this is a replacement. It ignores the SDL_SRCALPHA and SDL_SRCCOLORKEY
404  * flags. src and dst will have the SDL_RLEACCEL flag removed.
405  * The return value of SDL_BlistSurface is normally ignored so no return value.
406  * The rectangles are const and will not be modified.
407  *
408  * @pre @p src contains a valid canvas.
409  * @pre @p dst contains a valid neutral canvas.
410  * @pre The caller must make sure the @p src fits on the @p dst.
411  *
412  * @param src The surface to blit.
413  * @param srcrect The region of the surface to blit
414  * @param dst The surface to blit on.
415  * @param dstrect The offset to blit the surface on, only x and y are used.
416  */
417 void blit_surface(const surface& src,
418  const SDL_Rect* srcrect, surface& dst, const SDL_Rect* dstrect);
419 
420 SDL_Rect get_non_transparent_portion(const surface &surf);
421 
422 bool operator==(const SDL_Color& a, const SDL_Color& b);
423 bool operator!=(const SDL_Color& a, const SDL_Color& b);
424 
425 SDL_Color inverse(const SDL_Color& color);
426 SDL_Color int_to_color(const Uint32 rgb);
427 SDL_Color string_to_color(const std::string& color_string);
428 
429 SDL_Color create_color(const unsigned char red
430  , unsigned char green
431  , unsigned char blue
432  , unsigned char alpha = SDL_ALPHA_OPAQUE);
433 
434 /**
435  * Helper class for pinning SDL surfaces into memory.
436  * @note This class should be used only with neutral surfaces, so that
437  * the pointer returned by #pixels is meaningful.
438  */
440 {
441  surface_lock(surface &surf);
442  ~surface_lock();
443 
444  Uint32* pixels() { return reinterpret_cast<Uint32*>(surface_->pixels); }
445 private:
447  bool locked_;
448 };
449 
451 {
452  const_surface_lock(const surface &surf);
454 
455  const Uint32* pixels() const { return reinterpret_cast<const Uint32*>(surface_->pixels); }
456 private:
458  bool locked_;
459 };
460 
461 /**
462  * Helper methods for setting/getting a single pixel in an image.
463  * Lifted from http://sdl.beuc.net/sdl.wiki/Pixel_Access
464  *
465  * @param surf The image to get or receive the pixel from.
466  * @param surf_lock The locked surface to make sure the pointers are valid.
467  * @param x The position in the row of the pixel.
468  * @param y The row of the pixel.
469  */
470 void put_pixel(const surface& surf, surface_lock& surf_lock, int x, int y, Uint32 pixel);
471 Uint32 get_pixel(const surface& surf, const const_surface_lock& surf_lock, int x, int y);
472 
474 {
476  surface_restorer(class CVideo* target, const SDL_Rect& rect);
478 
479  void restore() const;
480  void restore(SDL_Rect const &dst) const;
481  void update();
482  void cancel();
483 
484  const SDL_Rect& area() const { return rect_; }
485 
486 private:
487  class CVideo* target_;
488  SDL_Rect rect_;
490 };
491 
493 {
494  // if r is nullptr, clip to the full size of the surface.
495  clip_rect_setter(const surface &surf, const SDL_Rect* r, bool operate = true) : surface_(surf), rect_(), operate_(operate)
496  {
497  if(operate_){
498  SDL_GetClipRect(surface_, &rect_);
499  SDL_SetClipRect(surface_, r);
500  }
501  }
502 
504  if (operate_)
505  SDL_SetClipRect(surface_, &rect_);
506  }
507 
508 private:
510  SDL_Rect rect_;
511  const bool operate_;
512 };
513 
514 // blit the image on the center of the rectangle
515 // and a add a colored background
516 void draw_centered_on_background(surface surf, const SDL_Rect& rect,
517  const SDL_Color& color, surface target);
518 
519 std::ostream& operator<<(std::ostream& s, const SDL_Rect& rect);
520 
521 #endif
void operator()(SDL_Surface *surf) const
Definition: utils.hpp:63
Definition: utils.hpp:250
GLdouble GLdouble z
Definition: glew.h:1527
bool null() const
Definition: utils.hpp:104
Uint32 get_pixel(const surface &surf, const const_surface_lock &surf_lock, int x, int y)
Definition: utils.cpp:2006
surface scale_surface_nn(const surface &surf, int w, int h)
Scale a surface using the nearest neighbor algorithm (provided by xBRZ lib)
Definition: utils.cpp:404
SDL_Surface * get() const
Definition: utils.hpp:98
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glew.h:1222
surface & surface_
Definition: utils.hpp:446
surface(SDL_Surface *surf)
Definition: utils.hpp:75
void blit_surface(const surface &src, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect)
Replacement for sdl_blit.
Definition: utils.cpp:2185
surface create_neutral_surface(int w, int h)
Definition: utils.cpp:150
surface alpha_to_greyscale(const surface &surf, bool optimize=true)
Definition: utils.cpp:931
surface stretch_surface_horizontal(const surface &surf, const unsigned w, const bool optimize=true)
Stretches a surface in the horizontal direction.
Definition: utils.cpp:178
Sint32 fixed_t
Definition: drawer.hpp:40
surface tile_surface(const surface &surf, int w, int h, bool optimize=true)
Tile a surface.
Definition: utils.cpp:674
surface adjust_surface_alpha(const surface &surf, fixed_t amount, bool optimize=true)
Definition: utils.cpp:1202
surface light_surface(const surface &surf, const surface &lightmap, bool optimize=true)
Light surf using lightmap.
Definition: utils.cpp:1458
surface wipe_alpha(const surface &surf, bool optimize=true)
Definition: utils.cpp:959
Definition: video.hpp:58
bool operator==(const SDL_Color &a, const SDL_Color &b)
Definition: utils.cpp:2450
game_display * screen
Definition: resources.cpp:27
surface scale_surface_xbrz(const surface &surf, size_t z)
Scale a surface using xBRZ algorithm.
Definition: utils.cpp:366
const Uint32 * pixels() const
Definition: utils.hpp:455
const surface & surface_
Definition: utils.hpp:457
scoped_sdl_surface surface_
Definition: utils.hpp:107
std::ostream & operator<<(std::ostream &s, const SDL_Rect &rect)
Definition: utils.cpp:2535
util::scoped_resource< SDL_Surface *, free_sdl_surface > scoped_sdl_surface
Definition: utils.hpp:70
surface()
Definition: utils.hpp:72
surface rotate_90_surface(const surface &surf, bool clockwise, bool optimize=true)
Rotates a surface 90 degrees.
Definition: utils.cpp:2071
GLboolean GLboolean g
Definition: glew.h:7319
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1220
GLenum src
Definition: glew.h:2392
surface negative_image(const surface &surf, const int thresholdR, const int thresholdG, const int thresholdB, bool optimize=true)
Definition: utils.cpp:888
bool locked_
Definition: utils.hpp:447
bool in_mask_surface(const surface &surf, const surface &mask)
Check if a surface fit into a mask.
Definition: utils.cpp:1349
#define SDLKey
Definition: compat.hpp:29
scoped_resource: class template, functions, helper policies etc. for resource management.
const_surface_lock(const surface &surf)
Definition: utils.cpp:51
Uint32 blend_rgba(const surface &surf, unsigned char r, unsigned char g, unsigned char b, unsigned char a, unsigned char drop)
This method blends a RGBA color.
Definition: utils.cpp:356
surface blend_surface(const surface &surf, const double amount, const Uint32 color, const bool optimize=true)
Blends a surface with a color.
Definition: utils.cpp:1840
static void sdl_add_ref(SDL_Surface *surf)
Definition: utils.hpp:56
surface surface_
Definition: utils.hpp:489
surface cut_surface(const surface &surf, SDL_Rect const &r)
Cuts a rectangle from a surface.
Definition: utils.cpp:1782
surface greyscale_image(const surface &surf, bool optimize=true)
Definition: utils.cpp:761
surface scale_surface_sharp(const surface &surf, int w, int h, bool optimize=true)
Scale a surface using modified nearest neighbour algorithm.
Definition: utils.cpp:577
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
GLintptr offset
Definition: glew.h:1650
void restore() const
Definition: utils.cpp:2496
surface blur_alpha_surface(const surface &surf, int depth=1, bool optimize=true)
Cross-fades a surface with alpha channel.
Definition: utils.cpp:1659
GLclampf GLclampf blue
Definition: glew.h:1488
GLclampf green
Definition: glew.h:1488
surface shadow_image(const surface &surf, bool optimize=true)
create an heavy shadow of the image, by blurring, increasing alpha and darkening
Definition: utils.cpp:987
SDL_Rect rect_
Definition: utils.hpp:488
Definition: utils.hpp:250
Compatibility layer for using SDL 1.2 and 2.0.
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1858
GLenum GLenum dst
Definition: glew.h:2392
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:7319
surface swap_channels_image(const surface &surf, channel r, channel g, channel b, channel a, bool optimize=true)
Definition: utils.cpp:1024
surface & operator=(const surface &o)
Definition: utils.hpp:90
surface blur_surface(const surface &surf, int depth=1, bool optimize=true)
Cross-fades a surface.
Definition: utils.cpp:1524
GLclampf GLclampf GLclampf alpha
Definition: glew.h:1488
SDL_Surface * operator->() const
Definition: utils.hpp:100
SDL_Rect rect_
Definition: utils.hpp:510
SDL_Color string_to_color(const std::string &color_string)
Return the color the string represents.
Definition: help_impl.cpp:1206
surface mask_surface(const surface &surf, const surface &mask, bool *empty_result=nullptr, const std::string &filename=std::string())
Applies a mask on a surface.
Definition: utils.cpp:1279
GLenum GLint GLuint mask
Definition: glew.h:1813
Helper class for pinning SDL surfaces into memory.
Definition: utils.hpp:439
const bool operate_
Definition: utils.hpp:511
Templates and utility-routines for strings and numbers.
resource_type get() const
This function provides explicit access to the resource.
surface adjust_surface_alpha_add(const surface &surf, int amount, bool optimize=true)
Definition: utils.cpp:1241
surf
Definition: filter.cpp:143
GLuint color
Definition: glew.h:5801
const std::string &parameters float amount
Definition: filter.cpp:132
SDL_Color inverse(const SDL_Color &color)
Definition: utils.cpp:2458
surface sepia_image(const surface &surf, bool optimize=true)
Definition: utils.cpp:846
surface brighten_image(const surface &surf, fixed_t amount, bool optimize=true)
Definition: utils.cpp:1160
Definition: utils.hpp:250
SDL_Color create_color(const unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=SDL_ALPHA_OPAQUE)
Definition: utils.cpp:89
class CVideo * target_
Definition: utils.hpp:487
SDLKey sdl_keysym_from_name(std::string const &keyname)
Definition: utils.cpp:103
surface flop_surface(const surface &surf, bool optimize=true)
Definition: utils.cpp:2137
void put_pixel(const surface &surf, surface_lock &surf_lock, int x, int y, Uint32 pixel)
Helper methods for setting/getting a single pixel in an image.
Definition: utils.cpp:1975
bool is_neutral(const surface &surf)
Check that the surface is neutral bpp 32.
Definition: utils.cpp:113
surface create_optimized_surface(const surface &surf)
Definition: utils.cpp:168
surface get_surface_portion(const surface &surf, SDL_Rect &rect)
Get a portion of the screen.
Definition: utils.cpp:2335
surface adjust_surface_color(const surface &surf, int r, int g, int b, bool optimize=true)
Definition: utils.cpp:718
void assign(const resource_type &o)
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:5910
GLint GLint GLint GLint GLint x
Definition: glew.h:1220
bool operator<(const surface &a, const surface &b)
Definition: utils.cpp:108
Definition: utils.hpp:250
GLdouble GLdouble GLdouble r
Definition: glew.h:1374
surface monochrome_image(const surface &surf, const int threshold, bool optimize=true)
Definition: utils.cpp:806
surface surface_
Definition: utils.hpp:509
surface make_neutral_surface(const surface &surf)
Definition: utils.cpp:135
GLint GLint GLint GLint GLint GLint GLsizei GLsizei height
Definition: glew.h:1220
void assign(SDL_Surface *surf)
Definition: utils.hpp:102
surface(const surface &o)
Definition: utils.hpp:78
clip_rect_setter(const surface &surf, const SDL_Rect *r, bool operate=true)
Definition: utils.hpp:495
SDL_Color int_to_color(const Uint32 rgb)
Definition: utils.cpp:63
bool operator!=(const SDL_Color &a, const SDL_Color &b)
Definition: utils.cpp:2454
const SDL_Rect & area() const
Definition: utils.hpp:484
GLdouble angle
Definition: glew.h:6979
surface flip_surface(const surface &surf, bool optimize=true)
Definition: utils.cpp:2108
void assign(const surface &o)
Definition: utils.hpp:83
surface stretch_surface_vertical(const surface &surf, const unsigned h, const bool optimize=true)
Stretches a surface in the vertical direction.
Definition: utils.cpp:223
Uint32 * pixels()
Definition: utils.hpp:444
surface submerge_alpha(const surface &surf, int depth, float alpha_base, float alpha_delta, bool optimize=true)
Progressively reduce alpha of bottom part of the surface.
Definition: utils.cpp:1395
GLint GLint GLint GLint GLint GLint GLsizei width
Definition: glew.h:1220
surface_lock(surface &surf)
Definition: utils.cpp:39
void sdl_copy_portion(const surface &screen, SDL_Rect *screen_rect, surface &dst, SDL_Rect *dst_rect)
Definition: utils.hpp:116
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
Definition: utils.hpp:112
surface rotate_any_surface(const surface &surf, float angle, int zoom, int offset, bool optimize=true)
Rotates a surface by any degrees.
Definition: utils.cpp:1920
surface scale_surface(const surface &surf, int w, int h, bool optimize)
Scale a surface.
Definition: utils.cpp:447
surface rotate_180_surface(const surface &surf, bool optimize=true)
Rotates a surface 180 degrees.
Definition: utils.cpp:2029
GLdouble s
Definition: glew.h:1358
void draw_centered_on_background(surface surf, const SDL_Rect &rect, const SDL_Color &color, surface target)
Definition: utils.cpp:2518
GLsizei const GLcharARB ** string
Definition: glew.h:4503
SDL_Rect get_non_transparent_portion(const surface &surf)
Definition: utils.cpp:2381
surface create_compatible_surface(const surface &surf, int width=-1, int height=-1)
Definition: utils.cpp:2166
surface recolor_image(surface surf, const std::map< Uint32, Uint32 > &map_rgb, bool optimize=true)
Recolors a surface using a map with source and converted palette values.
Definition: utils.cpp:1126
GLenum target
Definition: glew.h:5190
~surface_lock()
Definition: utils.cpp:45
channel
Definition: utils.hpp:250