The Battle for Wesnoth  1.15.0-dev
Classes | Typedefs | Enumerations | Functions | Variables
image Namespace Reference

this module manages the cache of images. More...

Classes

class  adjust_alpha_modification
 Adjust Alpha (ADJUST_ALPHA) modification. More...
 
class  adjust_channels_modification
 Adjust Channels (CHAN) modification. More...
 
struct  background_modification
 Fill background with a color (BG). More...
 
class  bl_modification
 Gaussian-like blur (BL) modification. More...
 
class  blend_modification
 Color blending (BLEND) modification. More...
 
class  blit_modification
 Scale (BLIT) modification. More...
 
class  bw_modification
 Black and white (BW) modification. More...
 
class  cache_type
 
class  crop_modification
 Crop (CROP) modification. More...
 
class  cs_modification
 Color-shift (CS, R, G, B) modification. More...
 
class  fl_modification
 Mirror (FL) modification. More...
 
class  gs_modification
 Grayscale (GS) modification. More...
 
class  light_modification
 LIGHT (L) modification. More...
 
class  locator
 
struct  manager
 the image manager is responsible for setting up images, and destroying all images when the program exits. More...
 
class  mask_modification
 Mask (MASK) modification. More...
 
class  modification
 Base abstract class for an image-path modification. More...
 
class  modification_queue
 A modified priority queue used to order image modifications. More...
 
class  negative_modification
 Make an image negative (NEG) More...
 
class  o_modification
 Opacity (O) modification. More...
 
class  pixel_callable
 
class  plot_alpha_modification
 Plot Alpha (Alpha) modification. More...
 
class  rc_modification
 Recolor (RC/TC/PAL) modification. More...
 
class  rotate_modification
 Rotate (ROTATE) modification. More...
 
class  scale_exact_modification
 Scale exact modification. More...
 
class  scale_into_modification
 Scale into (SCALE_INTO) modification. More...
 
class  scale_modification
 Scaling modifications base class. More...
 
struct  sepia_modification
 Give to the image a sepia tint (SEPIA) More...
 
class  swap_modification
 Channel swap (SWAP). More...
 
class  wipe_alpha_modification
 Wipe Alpha (Wipe_Alpha) modification. More...
 
class  xbrz_modification
 xBRZ scale (xBRZ) modification More...
 

Typedefs

using SCALING_ALGORITHM = preferences::SCALING_ALGORITHM
 
typedef cache_type< surfaceimage_cache
 
typedef cache_type< texturetexture_cache
 
typedef cache_type< bool > bool_cache
 
typedef std::map< t_translation::terrain_code, surfacemini_terrain_cache_map
 
typedef std::basic_string< signed char > light_string
 light_string store colors info of central and adjacent hexes. More...
 
typedef std::map< light_string, surfacelit_variants
 
typedef cache_type< lit_variantslit_cache
 

Enumerations

enum  TYPE {
  UNSCALED, SCALED_TO_ZOOM, HEXED, SCALED_TO_HEX,
  TOD_COLORED, BRIGHTENED
}
 UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM : image will be scaled taking zoom into account HEXED : the hex mask is applied on the image SCALED_TO_HEX : image will be scaled to fit into a hex, taking zoom into account TOD_COLORED : same as SCALED_TO_HEX but ToD coloring is also applied BRIGHTENED : same as TOD_COLORED but also brightened. More...
 
enum  SCALE_QUALITY { NEAREST, LINEAR }
 

Functions

void flush_cache ()
 
static bool localized_file_uptodate (const std::string &loc_file)
 
static std::string get_localized_path (const std::string &file, const std::string &suff="")
 
static void standardize_surface_format (surface &surf)
 
static void add_localized_overlay (const std::string &ovr_file, surface &orig_surf)
 
static surface load_image_file (const image::locator &loc)
 
static surface load_image_sub_file (const image::locator &loc)
 
static surface load_image_data_uri (const image::locator &loc)
 
static signed char col_to_uchar (int i)
 
light_string get_light_string (int op, int r, int g, int b)
 return light_string of one light operation(see above) More...
 
static surface apply_light (surface surf, const light_string &ls)
 
surface load_from_disk (const locator &loc)
 
void set_color_adjustment (int r, int g, int b)
 will make all scaled images have these rgb values added to all their pixels. More...
 
void set_zoom (unsigned int zoom)
 sets the amount scaled images should be scaled. More...
 
template<scaling_function F>
static surface scale_xbrz_helper (const surface &res, int w, int h)
 
static scaling_function select_algorithm (SCALING_ALGORITHM algo)
 
static surface get_hexed (const locator &i_locator)
 
static surface get_scaled_to_hex (const locator &i_locator)
 
static surface get_tod_colored (const locator &i_locator)
 
static surface get_scaled_to_zoom (const locator &i_locator)
 
static surface get_brightened (const locator &i_locator)
 
static TYPE simplify_type (const image::locator &i_locator, TYPE type)
 translate type to a simpler one when possible More...
 
surface get_image (const locator &i_locator, TYPE type=UNSCALED)
 function to get the surface corresponding to an image. More...
 
surface get_lighted_image (const image::locator &i_locator, const light_string &ls, TYPE type)
 function to get the surface corresponding to an image. More...
 
surface get_hexmask ()
 function to get the standard hex mask More...
 
bool is_in_hex (const locator &i_locator)
 function to check if an image fit into an hex return false if the image has not the standard size. More...
 
bool is_empty_hex (const locator &i_locator)
 function to check if an image is empty after hex cut should be only used on terrain image (cache the hex cut version) More...
 
surface reverse_image (const surface &surf)
 function to reverse an image. More...
 
bool exists (const locator &i_locator)
 returns true if the given image actually exists, without loading it. More...
 
static void precache_file_existence_internal (const std::string &dir, const std::string &subdir)
 
void precache_file_existence (const std::string &subdir="")
 precache the existence of files in the subdir (ex: "terrain/") More...
 
bool precached_file_exists (const std::string &file)
 
bool save_image (const locator &i_locator, const std::string &filename)
 
bool save_image (const surface &surf, const std::string &filename)
 
bool update_from_preferences ()
 initialize any private data, e.g. algorithm choices from preferences More...
 
static void set_scale_quality_pre_texture_creation (SCALE_QUALITY quality)
 Sets the texture scale quality hint. More...
 
static texture create_texture_from_file (const image::locator &loc)
 Loads a new texture directly from disk. More...
 
static texture create_texture_from_sub_file (const image::locator &loc)
 Handle IPF manipulation. More...
 
texture create_texture_from_disk (const locator &loc)
 
static texture create_texture_post_surface_op (const image::locator &i_locator, TYPE type)
 Small wrapper for creating a texture after applying a specific type of surface op. More...
 
texture get_texture (const image::locator &i_locator, TYPE type)
 
texture get_texture (const image::locator &i_locator, SCALE_QUALITY quality, TYPE type)
 Returns a texture for the corresponding image. More...
 
void render_minimap (texture &tex, const gamemap &map, const team *vw=nullptr, const unit_map *units=nullptr, const std::map< map_location, unsigned int > *reach_map=nullptr, bool ignore_terrain_disabled=false)
 Renders the minimap to the given texture. More...
 
void build_spritesheet_from (const std::string &subdir)
 

Variables

mini_terrain_cache_map mini_terrain_cache
 
mini_terrain_cache_map mini_fogged_terrain_cache
 
mini_terrain_cache_map mini_highlighted_terrain_cache
 
static int last_index_ = 0
 
static std::set< std::string > fuzzy_localized_files
 

Detailed Description

this module manages the cache of images.

With an image name, you can get the surface corresponding to that image.

Typedef Documentation

◆ bool_cache

Definition at line 131 of file image.hpp.

◆ image_cache

Definition at line 129 of file image.hpp.

◆ light_string

typedef std::basic_string<signed char> image::light_string

light_string store colors info of central and adjacent hexes.

The structure is one or several 4 chars blocks (L,R,G,B) where RGB is the color and L is the lightmap to use: -1: none 0: full hex 1-6: concave corners 7-12: convex half-corners 1 13-19: convex half-corners 2

Definition at line 146 of file image.hpp.

◆ lit_cache

Definition at line 153 of file image.hpp.

◆ lit_variants

Definition at line 151 of file image.hpp.

◆ mini_terrain_cache_map

Definition at line 133 of file image.hpp.

◆ SCALING_ALGORITHM

using image::SCALING_ALGORITHM = typedef preferences::SCALING_ALGORITHM

Definition at line 869 of file image.cpp.

◆ texture_cache

Definition at line 130 of file image.hpp.

Enumeration Type Documentation

◆ SCALE_QUALITY

Enumerator
NEAREST 
LINEAR 

Definition at line 183 of file image.hpp.

◆ TYPE

UNSCALED : image will be drawn "as is" without changing size, even in case of redraw SCALED_TO_ZOOM : image will be scaled taking zoom into account HEXED : the hex mask is applied on the image SCALED_TO_HEX : image will be scaled to fit into a hex, taking zoom into account TOD_COLORED : same as SCALED_TO_HEX but ToD coloring is also applied BRIGHTENED : same as TOD_COLORED but also brightened.

Enumerator
UNSCALED 
SCALED_TO_ZOOM 
HEXED 
SCALED_TO_HEX 
TOD_COLORED 
BRIGHTENED 

Definition at line 181 of file image.hpp.

Function Documentation

◆ add_localized_overlay()

static void image::add_localized_overlay ( const std::string &  ovr_file,
surface orig_surf 
)
static

◆ apply_light()

static surface image::apply_light ( surface  surf,
const light_string ls 
)
static

◆ build_spritesheet_from()

void image::build_spritesheet_from ( const std::string &  subdir)

Definition at line 225 of file spritesheet_generator.cpp.

References filesystem::get_binary_paths(), p, and editor::start().

◆ col_to_uchar()

static signed char image::col_to_uchar ( int  i)
static

Definition at line 723 of file image.cpp.

Referenced by get_light_string().

◆ create_texture_from_disk()

texture image::create_texture_from_disk ( const locator loc)

◆ create_texture_from_file()

static texture image::create_texture_from_file ( const image::locator loc)
static

◆ create_texture_from_sub_file()

static texture image::create_texture_from_sub_file ( const image::locator loc)
static

◆ create_texture_post_surface_op()

static texture image::create_texture_post_surface_op ( const image::locator i_locator,
TYPE  type 
)
static

Small wrapper for creating a texture after applying a specific type of surface op.

Won't be necessary once we get shader support.

Definition at line 1466 of file image.cpp.

References get_image(), and surf.

Referenced by get_texture().

◆ exists()

bool image::exists ( const image::locator i_locator)

◆ flush_cache()

void image::flush_cache ( )

◆ get_brightened()

static surface image::get_brightened ( const locator i_locator)
static

Definition at line 939 of file image.cpp.

References brighten_image(), ftofxp, get_image(), game_config::hex_brightening, and TOD_COLORED.

Referenced by get_image().

◆ get_hexed()

static surface image::get_hexed ( const locator i_locator)
static

◆ get_hexmask()

surface image::get_hexmask ( )

◆ get_image()

surface image::get_image ( const image::locator i_locator,
TYPE  type 
)

◆ get_light_string()

light_string image::get_light_string ( int  op,
int  r,
int  g,
int  b 
)

return light_string of one light operation(see above)

Definition at line 728 of file image.cpp.

References col_to_uchar().

◆ get_lighted_image()

surface image::get_lighted_image ( const image::locator i_locator,
const light_string ls,
TYPE  type 
)

function to get the surface corresponding to an image.

after applying the lightmap encoded in ls type should be HEXED or SCALED_TO_HEX

Definition at line 1060 of file image.cpp.

References image::locator::access_in_cache(), image::locator::add_to_cache(), apply_light(), get_image(), HEXED, image::locator::in_cache(), image::locator::is_void(), image::locator::locate_in_cache(), scale_surface(), SCALED_TO_HEX, and game_config::tile_size.

Referenced by apply_light().

◆ get_localized_path()

static std::string image::get_localized_path ( const std::string &  file,
const std::string &  suff = "" 
)
static

◆ get_scaled_to_hex()

static surface image::get_scaled_to_hex ( const locator i_locator)
static

Definition at line 906 of file image.cpp.

References get_image(), HEXED, and surface::null().

Referenced by get_image().

◆ get_scaled_to_zoom()

static surface image::get_scaled_to_zoom ( const locator i_locator)
static

Definition at line 925 of file image.cpp.

References get_image(), surface::null(), game_config::tile_size, and UNSCALED.

Referenced by get_image().

◆ get_texture() [1/2]

texture image::get_texture ( const image::locator i_locator,
TYPE  type 
)

◆ get_texture() [2/2]

texture image::get_texture ( const image::locator i_locator,
SCALE_QUALITY  quality,
TYPE  type 
)

◆ get_tod_colored()

static surface image::get_tod_colored ( const locator i_locator)
static

Definition at line 919 of file image.cpp.

References adjust_surface_color(), get_image(), and SCALED_TO_HEX.

Referenced by get_image().

◆ is_empty_hex()

bool image::is_empty_hex ( const locator i_locator)

function to check if an image is empty after hex cut should be only used on terrain image (cache the hex cut version)

Definition at line 1141 of file image.cpp.

References image::locator::add_to_cache(), get_hexmask(), get_image(), HEXED, image::locator::in_cache(), image::locator::locate_in_cache(), mask_surface(), and surf.

Referenced by terrain_builder::tile::rebuild_cache().

◆ is_in_hex()

bool image::is_in_hex ( const locator i_locator)

function to check if an image fit into an hex return false if the image has not the standard size.

Definition at line 1118 of file image.cpp.

References image::locator::add_to_cache(), get_hexmask(), get_image(), image::locator::in_cache(), in_mask_surface(), image::locator::locate_in_cache(), and UNSCALED.

Referenced by unit_frame::get_overlaped_hex().

◆ load_from_disk()

surface image::load_from_disk ( const locator loc)

◆ load_image_data_uri()

static surface image::load_image_data_uri ( const image::locator loc)
static

◆ load_image_file()

static surface image::load_image_file ( const image::locator loc)
static

◆ load_image_sub_file()

static surface image::load_image_sub_file ( const image::locator loc)
static

◆ localized_file_uptodate()

static bool image::localized_file_uptodate ( const std::string &  loc_file)
static

◆ precache_file_existence()

void image::precache_file_existence ( const std::string &  subdir)

precache the existence of files in the subdir (ex: "terrain/")

Definition at line 1236 of file image.cpp.

References filesystem::get_binary_paths(), p, and precache_file_existence_internal().

Referenced by terrain_builder::terrain_builder().

◆ precache_file_existence_internal()

static void image::precache_file_existence_internal ( const std::string &  dir,
const std::string &  subdir 
)
static

◆ precached_file_exists()

bool image::precached_file_exists ( const std::string &  file)

Definition at line 1245 of file image.cpp.

References b.

Referenced by image_exists().

◆ render_minimap()

void image::render_minimap ( texture tex,
const gamemap map,
const team vw,
const unit_map units,
const std::map< map_location, unsigned int > *  reach_map,
bool  ignore_terrain_disabled 
)

◆ reverse_image()

surface image::reverse_image ( const surface surf)

function to reverse an image.

The image MUST have originally been returned from an image:: function. Returned images have the same semantics as for get_image()

Definition at line 1160 of file image.cpp.

References flip_surface().

◆ save_image() [1/2]

bool image::save_image ( const locator i_locator,
const std::string &  filename 
)

◆ save_image() [2/2]

bool image::save_image ( const surface surf,
const std::string &  filename 
)

◆ scale_xbrz_helper()

template<scaling_function F>
static surface image::scale_xbrz_helper ( const surface res,
int  w,
int  h 
)
static

Definition at line 862 of file image.cpp.

References utils::clamp(), and scale_surface_xbrz().

◆ select_algorithm()

static scaling_function image::select_algorithm ( SCALING_ALGORITHM  algo)
static

Definition at line 871 of file image.cpp.

References LINEAR, scale_surface(), and scale_surface_nn().

Referenced by update_from_preferences().

◆ set_color_adjustment()

void image::set_color_adjustment ( int  r,
int  g,
int  b 
)

will make all scaled images have these rgb values added to all their pixels.

i.e. add a certain color hint to images. useful for representing day/night. Invalidates all scaled images.

Definition at line 826 of file image.cpp.

References b, and g.

Referenced by display::update_tod().

◆ set_scale_quality_pre_texture_creation()

static void image::set_scale_quality_pre_texture_creation ( SCALE_QUALITY  quality)
static

Sets the texture scale quality hint.

Must be called before creating textures!

Definition at line 1317 of file image.cpp.

References NEAREST, and set_texture_scale_quality().

Referenced by get_texture().

◆ set_zoom()

void image::set_zoom ( unsigned int  zoom)

sets the amount scaled images should be scaled.

Invalidates all scaled images.

Definition at line 840 of file image.cpp.

References game_config::tile_size.

Referenced by display::bounds_check_position(), display::display(), display::idle_anim_rate(), and display::set_zoom().

◆ simplify_type()

static TYPE image::simplify_type ( const image::locator i_locator,
TYPE  type 
)
static

translate type to a simpler one when possible

Definition at line 946 of file image.cpp.

References BRIGHTENED, ftofxp, image::locator::get_loc(), game_config::hex_brightening, HEXED, SCALED_TO_HEX, SCALED_TO_ZOOM, game_config::tile_size, TOD_COLORED, UNSCALED, and map_location::valid().

Referenced by get_image().

◆ standardize_surface_format()

static void image::standardize_surface_format ( surface surf)
static

Definition at line 568 of file image.cpp.

References is_neutral(), make_neutral_surface(), and surface::null().

Referenced by add_localized_overlay(), and load_image_file().

◆ update_from_preferences()

bool image::update_from_preferences ( )

initialize any private data, e.g. algorithm choices from preferences

Definition at line 1288 of file image.cpp.

References preferences::default_scaling_algorithm, preferences::get(), and select_algorithm().

Referenced by do_gameloop(), and gui2::dialogs::advanced_graphics_options::post_show().

Variable Documentation

◆ fuzzy_localized_files

std::set<std::string> image::fuzzy_localized_files
static

Definition at line 485 of file image.cpp.

◆ last_index_

int image::last_index_ = 0
static

Definition at line 248 of file image.cpp.

◆ mini_fogged_terrain_cache

mini_terrain_cache_map image::mini_fogged_terrain_cache

Definition at line 245 of file image.cpp.

◆ mini_highlighted_terrain_cache

mini_terrain_cache_map image::mini_highlighted_terrain_cache

Definition at line 246 of file image.cpp.

◆ mini_terrain_cache

mini_terrain_cache_map image::mini_terrain_cache

Definition at line 244 of file image.cpp.