#include "color_range.hpp"#include "color.hpp"#include "sdl/surface.hpp"#include "utils/math.hpp"#include "game_version.hpp"#include <string>Go to the source code of this file.
Namespaces | |
| sdl | |
Enumerations | |
| enum | channel { RED , GREEN , BLUE , ALPHA } |
Functions | |
| version_info | sdl::get_version () |
| Returns the runtime SDL version. More... | |
| bool | sdl::runtime_at_least (uint8_t major, uint8_t minor=0, uint8_t patch=0) |
| Returns true if the runtime SDL version is at or greater than the specified version, false otherwise. More... | |
| void | sdl_blit (const surface &src, const SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect) |
| surface | scale_surface_xbrz (const surface &surf, std::size_t z) |
| Scale a surface using xBRZ algorithm. More... | |
| surface | scale_surface (const surface &surf, int w, int h) |
| Scale a surface using alpha-weighted modified bilinear filtering Note: causes artifacts with alpha gradients, for example in some portraits. More... | |
| surface | scale_surface_legacy (const surface &surf, int w, int h) |
| Scale a surface using simple bilinear filtering (discarding rgb from source pixels with 0 alpha) More... | |
| surface | scale_surface_sharp (const surface &surf, int w, int h) |
| Scale a surface using modified nearest neighbour algorithm. More... | |
| void | adjust_surface_color (surface &surf, int r, int g, int b) |
| void | greyscale_image (surface &surf) |
| void | monochrome_image (surface &surf, const int threshold) |
| void | sepia_image (surface &surf) |
| void | negative_image (surface &surf, const int thresholdR, const int thresholdG, const int thresholdB) |
| void | alpha_to_greyscale (surface &surf) |
| void | wipe_alpha (surface &surf) |
| void | shadow_image (surface &surf, int scale=1) |
| create an heavy shadow of the image, by blurring, increasing alpha and darkening More... | |
| void | swap_channels_image (surface &surf, channel r, channel g, channel b, channel a) |
| void | apply_surface_opacity (surface &surf, float opacity) |
| Applies an opacity modification to a surface. More... | |
| void | recolor_image (surface &surf, const color_mapping &map_rgb) |
| Recolors a surface using a map with source and converted palette values. More... | |
| void | brighten_image (surface &surf, int32_t amount) |
| surface | get_surface_portion (const surface &surf, rect &rect) |
| Get a portion of the screen. More... | |
| void | adjust_surface_alpha (surface &surf, uint8_t alpha_mod) |
| void | adjust_surface_alpha_add (surface &surf, int amount) |
| bool | mask_surface (surface &surf, const surface &mask, const std::string &filename=std::string()) |
| Applies a mask to the source surface by calculating the minimum alpha channel value for every corresponding pixel. More... | |
| bool | in_mask_surface (const surface &surf, const surface &mask) |
| Checks if the source surface is entirely covered by the visible area of the mask. More... | |
| void | light_surface (surface &surf, const surface &lightmap) |
| Light surf using lightmap. More... | |
| void | blur_surface (surface &surf, rect rect, int depth=1) |
| Cross-fades a surface in place. More... | |
| void | blur_alpha_surface (surface &surf, int depth=1) |
| Cross-fades a surface with alpha channel. More... | |
| surface | cut_surface (const surface &surf, const rect &r) |
| Cuts a rectangle from a surface. More... | |
| void | blend_surface (surface &surf, const double amount, const color_t color) |
| Blends a surface with a color. More... | |
| surface | rotate_any_surface (const surface &surf, float angle, int zoom, int offset) |
| Rotates a surface by any degrees. More... | |
| surface | rotate_180_surface (const surface &surf) |
| Rotates a surface 180 degrees. More... | |
| surface | rotate_90_surface (const surface &surf, bool clockwise) |
| Rotates a surface 90 degrees. More... | |
| void | flip_surface (surface &surf) |
| void | flop_surface (surface &surf) |
| rect | get_non_transparent_portion (const surface &surf) |
| void adjust_surface_alpha | ( | surface & | surf, |
| uint8_t | alpha_mod | ||
| ) |
| void adjust_surface_alpha_add | ( | surface & | surf, |
| int | amount | ||
| ) |
Definition at line 694 of file utils.cpp.
References b, color_t::from_argb_bytes(), g, and surface_locker< T >::pixel_span().
| void adjust_surface_color | ( | surface & | surf, |
| int | r, | ||
| int | g, | ||
| int | b | ||
| ) |
Definition at line 405 of file utils.cpp.
References adjust_surface_color_simd(), b, color_t::from_argb_bytes(), g, simd::is_enabled(), surface_locker< T >::pixel_span(), and surface_helper::pixel_span().
Referenced by image::apply_light(), image::get_tod_colored(), and image::cs_modification::operator()().
| void alpha_to_greyscale | ( | surface & | surf | ) |
Definition at line 504 of file utils.cpp.
References surface_locker< T >::pixel_span().
Referenced by image::plot_alpha_modification::operator()().
| void apply_surface_opacity | ( | surface & | surf, |
| float | opacity | ||
| ) |
Applies an opacity modification to a surface.
| surf | The surface to modify. |
| opacity | The new opacity (0.0 to 1.0). |
Definition at line 1392 of file utils.cpp.
References apply_surface_opacity_simd(), b, color_multiply(), float_to_color(), color_t::from_argb_bytes(), g, simd::is_enabled(), surface_locker< T >::pixel_span(), surface_helper::pixel_span(), and surf.
Referenced by image::o_modification::operator()().
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. |
Definition at line 1153 of file utils.cpp.
References b, color_t::from_argb_bytes(), g, and surface_locker< T >::pixel_span().
Referenced by image::blend_modification::operator()().
| void blur_alpha_surface | ( | surface & | surf, |
| int | depth = 1 |
||
| ) |
Cross-fades a surface with alpha channel.
| surf | The source surface. |
| depth | The depth of the blurring. |
Definition at line 954 of file utils.cpp.
References p, surface_locker< T >::pixels(), and surface::size().
Referenced by image::bl_modification::operator()(), and shadow_image().
Cross-fades a surface in place.
| surf | The surface to blur, must have 32 bits per pixel. |
| rect | The part of the surface to blur. |
| depth | The depth of the blurring. |
Definition at line 838 of file utils.cpp.
References p, surface_locker< T >::pixels(), and surf.
Referenced by gui2::canvas::update_blur().
| void brighten_image | ( | surface & | surf, |
| int32_t | amount | ||
| ) |
Definition at line 667 of file utils.cpp.
References b, fixed_point_multiply(), color_t::from_argb_bytes(), g, and surface_locker< T >::pixel_span().
Cuts a rectangle from a surface.
Definition at line 1092 of file utils.cpp.
References surface_locker< T >::pixels(), PLAIN_LOG, utf8::size(), src, and surf.
Referenced by image::load_image_sub_file(), and image::crop_modification::operator()().
| void flip_surface | ( | surface & | surf | ) |
Definition at line 1317 of file utils.cpp.
References flip_image_simd(), simd::is_enabled(), surface_locker< T >::pixels(), and swap().
Referenced by image::fl_modification::operator()().
| void flop_surface | ( | surface & | surf | ) |
Definition at line 1340 of file utils.cpp.
References surface_locker< T >::pixels(), and swap().
Referenced by image::fl_modification::operator()().
Definition at line 1440 of file utils.cpp.
References utils::views::stride, boost::span< T, E >::subspan(), and surf.
Referenced by BOOST_AUTO_TEST_CASE(), and image::crop_transparency_modification::operator()().
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 1356 of file utils.cpp.
References dst, PLAIN_LOG, and src.
Referenced by image::crop_transparency_modification::operator()().
| void greyscale_image | ( | surface & | surf | ) |
Definition at line 424 of file utils.cpp.
References b, color_t::from_argb_bytes(), g, and surface_locker< T >::pixel_span().
Referenced by image::gs_modification::operator()().
Checks if the source surface is entirely covered by the visible area of the mask.
If a visible pixel is found outside the mask's visible area, the function immediately returns false. Mostly used to see if an image has all visable pixels within a hex shape.
| surf | The source surface (whose visibility is being checked). |
| mask | The mask surface (whose visible area defines the boundary). |
surf are contained within the non-transparent area of mask (i.e., the surface is fully covered). Returns false otherwise. Definition at line 756 of file utils.cpp.
References i, surface_locker< T >::pixel_span(), SDL_ALPHA_MASK, and boost::span< T, E >::size().
Referenced by image::is_in_hex().
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 |
Definition at line 790 of file utils.cpp.
References surface::area(), b, color_t::from_argb_bytes(), g, surface_locker< T >::pixels(), and PLAIN_LOG.
Referenced by image::apply_light(), and image::light_modification::operator()().
| bool mask_surface | ( | surface & | surf, |
| const surface & | mask, | ||
| const std::string & | filename = std::string() |
||
| ) |
Applies a mask to the source surface by calculating the minimum alpha channel value for every corresponding pixel.
This operation ensures that the resulting surface is only visible where BOTH the original surface AND the mask were visible. Mostly used to remove any pixels outside a hex shape.
| surf | The surface to be modified (the destination). |
| mask | The mask surface (read-only). if the resulting surface contains no visible pixels (i.e., is fully transparent). |
| filename | Optional string for logging purposes. |
Definition at line 708 of file utils.cpp.
References filename, i, simd::is_enabled(), mask_surface_simd(), surface_locker< T >::pixel_span(), PLAIN_LOG, SDL_ALPHA_MASK, boost::span< T, E >::size(), and boost::span< T, E >::subspan().
Referenced by image::get_hexed(), image::is_empty_hex(), image::load_image_sub_file(), and image::mask_modification::operator()().
| void monochrome_image | ( | surface & | surf, |
| const int | threshold | ||
| ) |
Definition at line 446 of file utils.cpp.
References b, color_t::from_argb_bytes(), g, and surface_locker< T >::pixel_span().
Referenced by image::bw_modification::operator()().
| void negative_image | ( | surface & | surf, |
| const int | thresholdR, | ||
| const int | thresholdG, | ||
| const int | thresholdB | ||
| ) |
Definition at line 483 of file utils.cpp.
References b, color_t::from_argb_bytes(), g, and surface_locker< T >::pixel_span().
Referenced by image::negative_modification::operator()().
| void recolor_image | ( | surface & | surf, |
| const color_mapping & | map_rgb | ||
| ) |
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. |
Definition at line 636 of file utils.cpp.
References ALPHA_OPAQUE, color_t::from_argb_bytes(), and surface_locker< T >::pixel_span().
Referenced by image::rc_modification::operator()().
Rotates a surface 180 degrees.
| surf | The surface to rotate. |
Definition at line 1243 of file utils.cpp.
References surface::clone(), is_odd(), surface_locker< T >::pixels(), PLAIN_LOG, surf, 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). |
Definition at line 1283 of file utils.cpp.
References dst, surface_locker< T >::pixels(), PLAIN_LOG, and surf.
Referenced by image::rotate_modification::operator()().
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. |
Definition at line 1181 of file utils.cpp.
References dst, surface_locker< T >::pixels(), xbrz::scale(), scale_surface(), src, and surf.
Referenced by image::rotate_modification::operator()().
Scale a surface using alpha-weighted modified bilinear filtering Note: causes artifacts with alpha gradients, for example in some portraits.
| surf | The source surface. |
| w | The width of the resulting surface. |
| h | The height of the resulting surface. |
| 0 | Returned upon error. |
| surf | Returned if w == surf->w and h == surf->h. |
Definition at line 99 of file utils.cpp.
References b, dst, e, fixed_point_divide(), fixed_point_to_int(), g, h, loc, n, surface_locker< T >::pixels(), PLAIN_LOG, s, surf, and w.
Referenced by image::light_modification::operator()(), video::read_pixels_low_res(), and rotate_any_surface().
Scale a surface using simple bilinear filtering (discarding rgb from source pixels with 0 alpha)
| surf | The source surface. |
| w | The width of the resulting surface. |
| h | The height of the resulting surface. |
| 0 | Returned upon error. |
| surf | Returned if w == surf->w and h == surf->h. |
Definition at line 225 of file utils.cpp.
References b, dst, fixed_point_divide(), fixed_point_to_int(), g, h, loc, surface_locker< T >::pixels(), PLAIN_LOG, surf, and w.
Referenced by image::scale_modification::operator()().
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. |
| 0 | Returned upon error. |
| surf | Returned if w == surf->w and h == surf->h. |
Definition at line 358 of file utils.cpp.
References dst, h, surface_locker< T >::pixels(), PLAIN_LOG, surf, and w.
Referenced by BOOST_AUTO_TEST_CASE(), 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 61 of file utils.cpp.
References xbrz::ARGB, dst, surface_locker< T >::pixels(), PLAIN_LOG, xbrz::scale(), xbrz::SCALE_FACTOR_MAX, and surf.
Referenced by image::xbrz_modification::operator()().
|
inline |
Definition at line 43 of file utils.hpp.
Referenced by image::add_localized_overlay(), image::apply_light(), image::get_hexed(), image::blit_modification::operator()(), image::mask_modification::operator()(), and image::background_modification::operator()().
| void sepia_image | ( | surface & | surf | ) |
Definition at line 464 of file utils.cpp.
References b, color_t::from_argb_bytes(), g, and surface_locker< T >::pixel_span().
Referenced by image::sepia_modification::operator()().
| void shadow_image | ( | surface & | surf, |
| int | scale = 1 |
||
| ) |
create an heavy shadow of the image, by blurring, increasing alpha and darkening
Definition at line 529 of file utils.cpp.
References blur_alpha_surface(), surface_locker< T >::pixel_span(), xbrz::scale(), and surf.
Definition at line 554 of file utils.cpp.
References ALPHA, b, BLUE, color_t::from_argb_bytes(), g, GREEN, surface_locker< T >::pixel_span(), and RED.
Referenced by image::swap_modification::operator()().
| void wipe_alpha | ( | surface & | surf | ) |
Definition at line 517 of file utils.cpp.
References surface_locker< T >::pixel_span().
Referenced by image::wipe_alpha_modification::operator()().