Support-routines for the SDL-graphics-library. More...
#include "global.hpp"
#include "color_range.hpp"
#include "sdl/utils.hpp"
#include "sdl/alpha.hpp"
#include "sdl/rect.hpp"
#include "floating_point_emulation.hpp"
#include "neon.hpp"
#include "video.hpp"
#include "xBRZ/xbrz.hpp"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <boost/math/constants/constants.hpp>
Go to the source code of this file.
Functions | |
SDL_Color | int_to_color (const Uint32 rgb) |
SDL_Color | string_to_color (const std::string &color_string) |
Return the color the string represents. More... | |
SDL_Color | create_color (const unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha) |
SDLKey | sdl_keysym_from_name (std::string const &keyname) |
bool | operator< (const surface &a, const surface &b) |
bool | is_neutral (const surface &surf) |
Check that the surface is neutral bpp 32. More... | |
static SDL_PixelFormat & | get_neutral_pixel_format () |
surface | make_neutral_surface (const surface &surf) |
surface | create_neutral_surface (int w, int h) |
surface | create_optimized_surface (const surface &surf) |
surface | stretch_surface_horizontal (const surface &surf, const unsigned w, const bool optimize) |
Stretches a surface in the horizontal direction. More... | |
surface | stretch_surface_vertical (const surface &surf, const unsigned h, const bool optimize) |
Stretches a surface in the vertical direction. More... | |
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. More... | |
surface | scale_surface_xbrz (const surface &surf, size_t z) |
Scale a surface using xBRZ algorithm. More... | |
surface | scale_surface_nn (const surface &surf, int w, int h) |
Scale a surface using the nearest neighbor algorithm (provided by xBRZ lib) More... | |
surface | scale_surface (const surface &surf, int w, int h) |
surface | scale_surface (const surface &surf, int w, int h, bool optimize) |
Scale a surface. More... | |
surface | scale_surface_sharp (const surface &surf, int w, int h, bool optimize) |
Scale a surface using modified nearest neighbour algorithm. More... | |
surface | tile_surface (const surface &surf, int w, int h, bool optimize) |
Tile a surface. More... | |
surface | adjust_surface_color (const surface &surf, int red, int green, int blue, bool optimize) |
surface | greyscale_image (const surface &surf, bool optimize) |
surface | monochrome_image (const surface &surf, const int threshold, bool optimize) |
surface | sepia_image (const surface &surf, bool optimize) |
surface | negative_image (const surface &surf, const int thresholdR, const int thresholdG, const int thresholdB, bool optimize) |
surface | alpha_to_greyscale (const surface &surf, bool optimize) |
surface | wipe_alpha (const surface &surf, bool optimize) |
surface | shadow_image (const surface &surf, bool optimize) |
create an heavy shadow of the image, by blurring, increasing alpha and darkening More... | |
surface | swap_channels_image (const surface &surf, channel r, channel g, channel b, channel a, bool optimize) |
surface | recolor_image (surface surf, const std::map< Uint32, Uint32 > &map_rgb, bool optimize) |
Recolors a surface using a map with source and converted palette values. More... | |
surface | brighten_image (const surface &surf, fixed_t amount, bool optimize) |
surface | adjust_surface_alpha (const surface &surf, fixed_t amount, bool optimize) |
surface | adjust_surface_alpha_add (const surface &surf, int amount, bool optimize) |
surface | mask_surface (const surface &surf, const surface &mask, bool *empty_result, const std::string &filename) |
Applies a mask on a surface. More... | |
bool | in_mask_surface (const surface &surf, const surface &mask) |
Check if a surface fit into a mask. More... | |
surface | submerge_alpha (const surface &surf, int depth, float alpha_base, float alpha_delta, bool optimize) |
Progressively reduce alpha of bottom part of the surface. More... | |
surface | light_surface (const surface &surf, const surface &lightmap, bool optimize) |
Light surf using lightmap. More... | |
surface | blur_surface (const surface &surf, int depth, bool optimize) |
Cross-fades a surface. More... | |
void | blur_surface (surface &surf, SDL_Rect rect, int depth) |
Cross-fades a surface in place. More... | |
surface | blur_alpha_surface (const surface &surf, int depth, bool optimize) |
Cross-fades a surface with alpha channel. More... | |
surface | cut_surface (const surface &surf, SDL_Rect const &r) |
Cuts a rectangle from a surface. More... | |
surface | blend_surface (const surface &surf, const double amount, const Uint32 color, const bool optimize) |
Blends a surface with a color. More... | |
surface | rotate_any_surface (const surface &surf, float angle, int zoom, int offset, bool optimize) |
Rotates a surface by any degrees. More... | |
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. More... | |
Uint32 | get_pixel (const surface &surf, const const_surface_lock &surf_lock, int x, int y) |
surface | rotate_180_surface (const surface &surf, bool optimize) |
Rotates a surface 180 degrees. More... | |
surface | rotate_90_surface (const surface &surf, bool clockwise, bool optimize) |
Rotates a surface 90 degrees. More... | |
surface | flip_surface (const surface &surf, bool optimize) |
surface | flop_surface (const surface &surf, bool optimize) |
surface | create_compatible_surface (const surface &surf, int width, int height) |
void | blit_surface (const surface &surf, const SDL_Rect *srcrect, surface &dst, const SDL_Rect *dstrect) |
Replacement for sdl_blit. More... | |
surface | get_surface_portion (const surface &src, SDL_Rect &area) |
Get a portion of the screen. More... | |
SDL_Rect | get_non_transparent_portion (const surface &surf) |
bool | operator== (const SDL_Color &a, const SDL_Color &b) |
bool | operator!= (const SDL_Color &a, const SDL_Color &b) |
SDL_Color | inverse (const SDL_Color &color) |
void | draw_centered_on_background (surface surf, const SDL_Rect &rect, const SDL_Color &color, surface target) |
std::ostream & | operator<< (std::ostream &s, const SDL_Rect &rect) |
Support-routines for the SDL-graphics-library.
Definition in file utils.cpp.
Definition at line 1202 of file utils.cpp.
References create_optimized_surface(), fxpmult, g, make_neutral_surface(), and surface_lock::pixels().
Referenced by font::floating_label::create_surface(), gui::textbox::draw_contents(), game_display::new_turn(), image::adjust_alpha_modification::operator()(), image::o_modification::operator()(), display::render_image(), editor::mouse_action_item::set_item_mouse_overlay(), editor::mouse_action_map_label::set_mouse_overlay(), editor::mouse_action_village::set_mouse_overlay(), editor::mouse_action_select::set_mouse_overlay(), editor::mouse_action_paste::set_mouse_overlay(), editor::mouse_action_starting_position::set_mouse_overlay(), editor::mouse_action::set_terrain_mouse_overlay(), and editor::mouse_action_unit::set_unit_mouse_overlay().
Definition at line 1241 of file utils.cpp.
References create_optimized_surface(), g, make_neutral_surface(), and surface_lock::pixels().
Referenced by font::floating_label::undraw().
Definition at line 718 of file utils.cpp.
References create_optimized_surface(), g, int(), make_neutral_surface(), surface_lock::pixels(), and surf.
Referenced by image::apply_light(), image::get_tod_colored(), image::getMinimap(), and image::cs_modification::operator()().
Definition at line 931 of file utils.cpp.
References create_optimized_surface(), make_neutral_surface(), and surface_lock::pixels().
Referenced by image::plot_alpha_modification::operator()().
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.
The method takes as input a surface, the RGB color to blend and a value specifying how much blending to apply. The blended color is returned. Caution: if you use a transparent color, make sure the resulting color is not equal to the transparent color.
Definition at line 356 of file utils.cpp.
Referenced by battle_prediction_pane::get_hp_distrib_surface().
surface blend_surface | ( | const surface & | surf, |
const double | amount, | ||
const Uint32 | color, | ||
const bool | optimize = true |
||
) |
Blends a surface with a color.
Every pixel in the surface will be blended with the color
given. The final color of a pixel is amount * color
+ (1 - amount) * original.
surf | The surface to blend. |
amount | The amount of the new color is determined by color . Must be a number in the range [0, 1]. |
color | The color to blend width, note its alpha channel is ignored. |
optimize | Should the return surface be RLE optimized. |
Definition at line 1840 of file utils.cpp.
References create_optimized_surface(), i, make_neutral_surface(), surface_lock::pixels(), vaddq_u16(), tmatrix< T, S, D >::val, vdup_n_u8(), vdupq_n_u16(), vld4_u8(), vmull_u8(), vshrn_n_u16(), and vst4_u8().
Referenced by blend_image(), image::blend_modification::operator()(), and display::render_image().
void blit_surface | ( | const surface & | src, |
const SDL_Rect * | srcrect, | ||
surface & | dst, | ||
const SDL_Rect * | dstrect | ||
) |
Replacement for sdl_blit.
sdl_blit has problems with blitting partly transparent surfaces so this is a replacement. It ignores the SDL_SRCALPHA and SDL_SRCCOLORKEY flags. src and dst will have the SDL_RLEACCEL flag removed. The return value of SDL_BlistSurface is normally ignored so no return value. The rectangles are const and will not be modified.
src
contains a valid canvas. dst
contains a valid neutral canvas. src
fits on the dst
.src | The surface to blit. |
srcrect | The region of the surface to blit |
dst | The surface to blit on. |
dstrect | The offset to blit the surface on, only x and y are used. |
Definition at line 2185 of file utils.cpp.
References sdl::create_rect(), is_neutral(), make_neutral_surface(), surface_lock::pixels(), and const_surface_lock::pixels().
Referenced by image::apply_light(), font::floating_label::create_surface(), gui::button::draw_contents(), gui::tristate_button::draw_contents(), draw_panel(), gui::multimenu::draw_row(), image::getMinimap(), image::blit_modification::operator()(), image::mask_modification::operator()(), image::brighten_modification::operator()(), image::darken_modification::operator()(), image::background_modification::operator()(), storyscreen::part_ui::prepare_background(), editor::mouse_action_map_label::set_mouse_overlay(), editor::mouse_action_village::set_mouse_overlay(), editor::mouse_action_paste::set_mouse_overlay(), editor::mouse_action_starting_position::set_mouse_overlay(), and editor::mouse_action::set_terrain_mouse_overlay().
Cross-fades a surface with alpha channel.
Definition at line 1659 of file utils.cpp.
References create_optimized_surface(), make_neutral_surface(), and surface_lock::pixels().
Referenced by image::bl_modification::operator()(), and shadow_image().
Cross-fades a surface.
Definition at line 1524 of file utils.cpp.
References blur_surface(), create_optimized_surface(), sdl::create_rect(), and make_neutral_surface().
Referenced by gui2::tcanvas::blit(), blur_surface(), and gui::dialog_frame::draw_background().
Cross-fades a surface in place.
surf | The surface to blur, must be not optimized and have 32 bits per pixel. |
rect | The part of the surface to blur. |
depth | The depth of the blurring. |
Definition at line 1543 of file utils.cpp.
References surface_lock::pixels().
Definition at line 1160 of file utils.cpp.
References create_optimized_surface(), fxpmult, g, make_neutral_surface(), and surface_lock::pixels().
Referenced by image::get_brightened(), and display::render_image().
SDL_Color create_color | ( | const unsigned char | red, |
unsigned char | green, | ||
unsigned char | blue, | ||
unsigned char | alpha | ||
) |
Definition at line 89 of file utils.cpp.
Referenced by image::getMinimap(), game_lua_kernel::intf_print(), the_end(), and unit_moves().
Definition at line 2166 of file utils.cpp.
Referenced by gui::textbox::append_text(), cut_surface(), font::floating_label::draw(), unit_drawer::draw_bar(), sdl::fill_rect_alpha(), get_surface_portion(), main(), font::render_text(), display::screenshot(), and about::show_about().
Definition at line 150 of file utils.cpp.
References get_neutral_pixel_format().
Referenced by font::floating_label::create_surface(), gui2::tcanvas::draw(), display::draw_hex(), battle_prediction_pane::get_hp_distrib_surface(), image::getMinimap(), image::mask_modification::operator()(), storyscreen::part_ui::prepare_background(), rotate_90_surface(), rotate_any_surface(), scale_surface(), scale_surface_nn(), scale_surface_sharp(), scale_surface_xbrz(), editor::mouse_action_map_label::set_mouse_overlay(), editor::mouse_action_village::set_mouse_overlay(), editor::mouse_action_paste::set_mouse_overlay(), editor::mouse_action_starting_position::set_mouse_overlay(), editor::mouse_action::set_terrain_mouse_overlay(), stretch_surface_horizontal(), stretch_surface_vertical(), and tile_surface().
Definition at line 168 of file utils.cpp.
References SDL_SetAlpha(), SDL_SRCALPHA, and surf.
Referenced by adjust_surface_alpha(), adjust_surface_alpha_add(), adjust_surface_color(), alpha_to_greyscale(), blend_surface(), blur_alpha_surface(), blur_surface(), brighten_image(), font::floating_label::create_surface(), flip_surface(), flop_surface(), image::get_image(), image::get_lighted_image(), greyscale_image(), light_surface(), monochrome_image(), negative_image(), image::crop_modification::operator()(), recolor_image(), rotate_180_surface(), rotate_90_surface(), rotate_any_surface(), scale_surface(), scale_surface_nn(), scale_surface_sharp(), scale_surface_xbrz(), sepia_image(), shadow_image(), stretch_surface_horizontal(), stretch_surface_vertical(), submerge_alpha(), swap_channels_image(), tile_surface(), and wipe_alpha().
Cuts a rectangle from a surface.
Definition at line 1782 of file utils.cpp.
References create_compatible_surface(), surface_lock::pixels(), and const_surface_lock::pixels().
Referenced by image::load_image_sub_file(), and image::crop_modification::operator()().
void draw_centered_on_background | ( | surface | surf, |
const SDL_Rect & | rect, | ||
const SDL_Color & | color, | ||
surface | target | ||
) |
Definition at line 2518 of file utils.cpp.
References sdl::fill_rect(), sdl_blit(), and update_rect().
Referenced by mp::create::draw_level_image(), and display::draw_minimap().
Definition at line 2108 of file utils.cpp.
References create_optimized_surface(), make_neutral_surface(), surface_lock::pixels(), and swap().
Referenced by image::fl_modification::operator()(), and image::reverse_image().
Definition at line 2137 of file utils.cpp.
References create_optimized_surface(), make_neutral_surface(), surface_lock::pixels(), and swap().
Referenced by image::fl_modification::operator()(), halo::halo_impl::effect::render(), and display::render_image().
|
static |
Definition at line 120 of file utils.cpp.
References surf.
Referenced by create_neutral_surface(), and make_neutral_surface().
SDL_Rect get_non_transparent_portion | ( | const surface & | surf | ) |
Definition at line 2381 of file utils.cpp.
References make_neutral_surface(), and surface_lock::pixels().
Referenced by display::draw_image_for_report().
Uint32 get_pixel | ( | const surface & | surf, |
const const_surface_lock & | surf_lock, | ||
int | x, | ||
int | y | ||
) |
Definition at line 2006 of file utils.cpp.
References const_surface_lock::pixels().
Referenced by rotate_any_surface().
Get a portion of the screen.
Send nullptr if the portion is outside of the screen.
surf | The source surface. |
rect | The portion of the source surface to copy. |
0 | if error or the portion is outside of the surface. |
Definition at line 2335 of file utils.cpp.
References create_compatible_surface(), and sdl_copy_portion().
Referenced by gui2::tcanvas::blit(), gui2::twindow::draw(), gui::dialog_frame::draw_background(), display::draw_image_for_report(), display::refresh_report(), halo::halo_impl::effect::render(), and surface_restorer::update().
Definition at line 761 of file utils.cpp.
References create_optimized_surface(), g, make_neutral_surface(), and surface_lock::pixels().
Referenced by image::gs_modification::operator()(), and display::render_image().
Check if a surface fit into a mask.
Definition at line 1349 of file utils.cpp.
References make_neutral_surface(), surface_lock::pixels(), and const_surface_lock::pixels().
Referenced by image::is_in_hex().
SDL_Color int_to_color | ( | const Uint32 | rgb | ) |
Definition at line 63 of file utils.cpp.
Referenced by display_chat_manager::add_chat_message(), display::draw_minimap_units(), game_display::draw_movement_info(), team::get_minimap_color(), team::get_side_color(), image::getMinimap(), events::menu_handler::label_terrain(), unit_frame::redraw(), gui2::set_weapon_info(), string_to_color(), unit_defense(), and unit_weapons().
SDL_Color inverse | ( | const SDL_Color & | color | ) |
bool is_neutral | ( | const surface & | surf | ) |
Check that the surface is neutral bpp 32.
The surface may have an empty alpha channel.
surf | The surface to test. |
true
if neutral, false
if not. Definition at line 113 of file utils.cpp.
Referenced by gui2::tcanvas::blit(), and blit_surface().
Light surf using lightmap.
surf | The source surface. |
lightmap | add/subtract this color to surf but RGB values are converted to (X-128)*2 to cover the full (-256,256) spectrum. Should already be neutral |
optimize | Whether the new surface should be RLE encoded. |
Definition at line 1458 of file utils.cpp.
References create_optimized_surface(), g, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.
Referenced by image::apply_light(), and image::light_modification::operator()().
Definition at line 135 of file utils.cpp.
References get_neutral_pixel_format(), SDL_SetAlpha(), and SDL_SRCALPHA.
Referenced by adjust_surface_alpha(), adjust_surface_alpha_add(), adjust_surface_color(), alpha_to_greyscale(), image::apply_light(), blend_surface(), blit_surface(), blur_alpha_surface(), blur_surface(), brighten_image(), unit_drawer::calculate_energy_bar(), composer::compose(), create_cursor(), gui::button::draw_contents(), gui::tristate_button::draw_contents(), flip_surface(), flop_surface(), get_non_transparent_portion(), image::getMinimap(), greyscale_image(), in_mask_surface(), light_surface(), cutter::load_masks(), main(), mask_surface(), monochrome_image(), negative_image(), image::crop_modification::operator()(), image::blit_modification::operator()(), image::light_modification::operator()(), image::brighten_modification::operator()(), image::darken_modification::operator()(), image::background_modification::operator()(), storyscreen::part_ui::prepare_background(), recolor_image(), rotate_180_surface(), rotate_90_surface(), scale_surface(), scale_surface_nn(), scale_surface_sharp(), scale_surface_xbrz(), display::scroll(), sepia_image(), stretch_surface_horizontal(), stretch_surface_vertical(), submerge_alpha(), swap_channels_image(), tile_surface(), and wipe_alpha().
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 at line 1279 of file utils.cpp.
References g, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.
Referenced by image::get_hexed(), image::is_empty_hex(), image::load_image_sub_file(), image::mask_modification::operator()(), and editor::mouse_action::set_terrain_mouse_overlay().
Definition at line 806 of file utils.cpp.
References create_optimized_surface(), g, make_neutral_surface(), and surface_lock::pixels().
Referenced by image::bw_modification::operator()().
surface negative_image | ( | const surface & | surf, |
const int | thresholdR, | ||
const int | thresholdG, | ||
const int | thresholdB, | ||
bool | optimize | ||
) |
Definition at line 888 of file utils.cpp.
References create_optimized_surface(), g, make_neutral_surface(), and surface_lock::pixels().
Referenced by image::negative_modification::operator()().
bool operator!= | ( | const SDL_Color & | a, |
const SDL_Color & | b | ||
) |
Definition at line 2454 of file utils.cpp.
References operator==().
Definition at line 108 of file utils.cpp.
References surface::get().
std::ostream& operator<< | ( | std::ostream & | s, |
const SDL_Rect & | rect | ||
) |
bool operator== | ( | const SDL_Color & | a, |
const SDL_Color & | b | ||
) |
Definition at line 2450 of file utils.cpp.
Referenced by operator!=().
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.
Lifted from http://sdl.beuc.net/sdl.wiki/Pixel_Access
surf | The image to get or receive the pixel from. |
surf_lock | The locked surface to make sure the pointers are valid. |
x | The position in the row of the pixel. |
y | The row of the pixel. |
Definition at line 1975 of file utils.cpp.
References surface_lock::pixels().
Referenced by rotate_any_surface().
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.
This is most often used for team-coloring.
surf | The source surface. |
map_rgb | Map of color values, with the keys corresponding to the source palette, and the values to the recolored palette. |
optimize | Whether the new surface should be RLE encoded. Only useful when the source is not the screen and it is going to be used multiple times. |
Definition at line 1126 of file utils.cpp.
References create_optimized_surface(), i, make_neutral_surface(), surface_lock::pixels(), and surf.
Referenced by image::rc_modification::operator()().
Rotates a surface 180 degrees.
surf | The surface to rotate. |
optimize | Should the return surface be RLE optimized. |
Definition at line 2029 of file utils.cpp.
References create_optimized_surface(), is_odd(), make_neutral_surface(), surface_lock::pixels(), and swap().
Referenced by image::fl_modification::operator()(), and image::rotate_modification::operator()().
Rotates a surface 90 degrees.
surf | The surface to rotate. |
clockwise | Whether the rotation should be clockwise (true) or counter-clockwise (false). |
optimize | Should the return surface be RLE optimized. |
Definition at line 2071 of file utils.cpp.
References create_neutral_surface(), create_optimized_surface(), make_neutral_surface(), surface_lock::pixels(), and const_surface_lock::pixels().
Referenced by image::rotate_modification::operator()().
surface rotate_any_surface | ( | const surface & | surf, |
float | angle, | ||
int | zoom, | ||
int | offset, | ||
bool | optimize = true |
||
) |
Rotates a surface by any degrees.
zoom
>= offset
Otherwise offset
> 0 Otherwise the procedure will not return.surf | The surface to rotate. |
angle | The angle of rotation. |
zoom | Which zoom level to use for calculating the result. |
offset | Pixel offset when scanning the zoomed source. |
optimize | Should the return surface be RLE optimized. |
Definition at line 1920 of file utils.cpp.
References create_neutral_surface(), create_optimized_surface(), get_pixel(), put_pixel(), and scale_surface().
Referenced by image::rotate_modification::operator()().
Definition at line 443 of file utils.cpp.
References scale_surface().
Referenced by ng::campaign::create_image_surface(), gui::dialog_frame::draw_border(), gui::tristate_button::draw_contents(), gui::scrollbar::draw_contents(), dialogs::unit_preview_pane::draw_contents(), mp::ui::draw_contents(), display::draw_image_for_report(), editor::item_palette::draw_item(), editor::unit_palette::draw_item(), editor::terrain_palette::draw_item(), draw_label(), gui::menu::imgsel_style::draw_row_bg(), gui::menu::style::get_item_image(), image::get_lighted_image(), storyscreen::floating_image::get_render_input(), gui::button::load_images(), image::light_modification::operator()(), image::scale_modification::operator()(), storyscreen::part_ui::prepare_background(), storyscreen::part_ui::render_story_box_borders(), rotate_any_surface(), scale(), scale_surface(), image::select_algorithm(), editor::mouse_action_item::set_item_mouse_overlay(), editor::mouse_action_map_label::set_mouse_overlay(), editor::mouse_action_village::set_mouse_overlay(), editor::mouse_action_select::set_mouse_overlay(), editor::mouse_action_paste::set_mouse_overlay(), editor::mouse_action_starting_position::set_mouse_overlay(), editor::mouse_action::set_terrain_mouse_overlay(), editor::mouse_action_unit::set_unit_mouse_overlay(), and about::show_about().
Scale a surface.
surf | The source surface. |
w | The width of the resulting surface. |
h | The height of the resulting surface. |
optimize | Should the return surface be RLE optimized. |
0 | Returned upon error. |
surf | Returned if w == surf->w and h == surf->h note this ignores the optimize flag. |
Definition at line 447 of file utils.cpp.
References create_neutral_surface(), create_optimized_surface(), e, ftofxp, fxpdiv, fxptoi, h, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.
Scale a surface using the nearest neighbor algorithm (provided by xBRZ lib)
surf | The sources surface |
w | The width of the resulting surface. |
h | The height of the resulting surface. |
Definition at line 404 of file utils.cpp.
References create_neutral_surface(), create_optimized_surface(), h, make_neutral_surface(), xbrz::nearestNeighborScale(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.
Referenced by image::select_algorithm().
Scale a surface using modified nearest neighbour algorithm.
Use only if preserving sharp edges is a priority (e.g. minimap).
surf | The source surface. |
w | The width of the resulting surface. |
h | The height of the resulting surface. |
optimize | Should the return surface be RLE optimized. |
0 | Returned upon error. |
surf | Returned if w == surf->w and h == surf->h note this ignores the optimize flag. |
Definition at line 577 of file utils.cpp.
References create_neutral_surface(), create_optimized_surface(), floating_point_emulation::floor(), g, h, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), surf, and floating_point_emulation::tfloat< T, S >::to_int().
Referenced by image::getMinimap(), and image::scale_modification::operator()().
Scale a surface using xBRZ algorithm.
surf | The source surface |
z | The scaling factor. Should be an integer 2-5 (1 is tolerated). |
Definition at line 366 of file utils.cpp.
References create_neutral_surface(), create_optimized_surface(), make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and xbrz::scale().
Referenced by image::xbrz_modification::operator()(), and image::scale_xbrz_helper().
SDLKey sdl_keysym_from_name | ( | std::string const & | keyname | ) |
Definition at line 846 of file utils.cpp.
References create_optimized_surface(), g, make_neutral_surface(), and surface_lock::pixels().
Referenced by image::sepia_modification::operator()().
create an heavy shadow of the image, by blurring, increasing alpha and darkening
Definition at line 987 of file utils.cpp.
References blur_alpha_surface(), create_optimized_surface(), and surface_lock::pixels().
Referenced by font::floating_label::create_surface().
surface stretch_surface_horizontal | ( | const surface & | surf, |
const unsigned | w, | ||
const bool | optimize = true |
||
) |
Stretches a surface in the horizontal direction.
The stretches a surface it uses the first pixel in the horizontal direction of the original surface and copies that to the destination. This means only the first column of the original is used for the destination.
surf | The source surface. |
w | The width of the resulting surface. |
optimize | Should the return surface be RLE optimized. |
0 | Returned upon error. |
surf | Returned if w == surf->w, note this ignores the optimize flag. |
Definition at line 178 of file utils.cpp.
References create_neutral_surface(), create_optimized_surface(), make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.
surface stretch_surface_vertical | ( | const surface & | surf, |
const unsigned | h, | ||
const bool | optimize = true |
||
) |
Stretches a surface in the vertical direction.
The stretches a surface it uses the first pixel in the vertical direction of the original surface and copies that to the destination. This means only the first row of the original is used for the destination.
surf | The source surface. |
h | The height of the resulting surface. |
optimize | Should the return surface be RLE optimized. |
surf | Returned if h == surf->h, note this ignores the optimize flag. |
Definition at line 223 of file utils.cpp.
References create_neutral_surface(), create_optimized_surface(), h, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), and surf.
SDL_Color string_to_color | ( | const std::string & | color_string | ) |
Return the color the string represents.
Return font::NORMAL_COLOR if the string is empty or can't be matched against any other color.
Definition at line 77 of file utils.cpp.
References font::BAD_COLOR, font::BIGMAP_COLOR, font::BLACK_COLOR, font::GOOD_COLOR, int_to_color(), font::NORMAL_COLOR, string2rgb(), and font::YELLOW_COLOR.
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.
surf | The source surface. |
depth | The height of the bottom part in pixels |
alpha_base | The alpha adjustment at the interface |
alpha_delta | The alpha adjustment reduction rate by pixel depth |
optimize | Optimize by converting to result to display |
Definition at line 1395 of file utils.cpp.
References amount, create_optimized_surface(), d, ftofxp, fxpmult, g, make_neutral_surface(), and surface_lock::pixels().
Referenced by display::render_image().
surface swap_channels_image | ( | const surface & | surf, |
channel | r, | ||
channel | g, | ||
channel | b, | ||
channel | a, | ||
bool | optimize | ||
) |
Definition at line 1024 of file utils.cpp.
References ALPHA, BLUE, create_optimized_surface(), GREEN, make_neutral_surface(), surface_lock::pixels(), and RED.
Referenced by image::swap_modification::operator()().
Tile a surface.
surf | The source surface. |
w | The width of the resulting surface. |
h | The height of the resulting surface. |
optimize | Should the return surface be RLE optimized |
0 | Returned upon error |
surf | Returned if w == surf->w and h == surf->h note this ignores the optimize flag. |
Definition at line 674 of file utils.cpp.
References create_neutral_surface(), create_optimized_surface(), h, i, make_neutral_surface(), surface_lock::pixels(), const_surface_lock::pixels(), surf, and sw.
Referenced by draw_panel(), and storyscreen::part_ui::prepare_background().
Definition at line 959 of file utils.cpp.
References create_optimized_surface(), make_neutral_surface(), and surface_lock::pixels().
Referenced by image::wipe_alpha_modification::operator()().