The Battle for Wesnoth  1.19.25+dev
Namespaces | Functions | Variables
utils_simd.hpp File Reference

SIMD-accelerated helper functions for image manipulation. More...

#include "game_config.hpp"
#include "preferences/preferences.hpp"
#include "sdl/surface.hpp"
#include <cstdint>
#include <algorithm>
Include dependency graph for utils_simd.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 simd
 

Functions

bool simd::is_enabled ()
 Checks if SIMD hardware acceleration is allowed/enabeled. More...
 
std::size_t mask_surface_simd (surface &surf, const surface &mask, bool &empty)
 Modifies the alpha channel of the surface pixels based on the mask. More...
 
std::size_t apply_surface_opacity_simd (surface &surf, uint8_t alpha_mod)
 Applies an alpha modification to the whole surface using SIMD. More...
 
std::size_t adjust_surface_color_simd (surface &surf, int r, int g, int b)
 Adjusts the color channels of a surface using saturated SIMD arithmetic. More...
 
std::size_t flip_image_simd (surface &surf)
 Flips each row of pixels (horizontal mirror) using SIMD. More...
 

Variables

constexpr std::size_t simd::SIMD_THRESHOLD = 64
 Minimum number of pixels required to trigger SIMD optimizations. More...
 

Detailed Description

SIMD-accelerated helper functions for image manipulation.

These functions operate on raw pixel buffers to isolate platform-specific intrinsics (SSE2, NEON) from the main codebase.

Definition in file utils_simd.hpp.

Function Documentation

◆ adjust_surface_color_simd()

std::size_t adjust_surface_color_simd ( surface surf,
int  r,
int  g,
int  b 
)

Adjusts the color channels of a surface using saturated SIMD arithmetic.

Parameters
surfThe surface to modify.
r,g,bAmounts to add (positive) or subtract (negative) per channel. Clamped to [-255, 255].
Returns
Number of pixels processed via SIMD, or 0 if SIMD was not used.

Definition at line 337 of file utils_simd.cpp.

References surface::area(), b, g, surface_locker< T >::pixels(), simd::SIMD_THRESHOLD, and surf.

Referenced by adjust_surface_color().

◆ apply_surface_opacity_simd()

std::size_t apply_surface_opacity_simd ( surface surf,
uint8_t  alpha_mod 
)

Applies an alpha modification to the whole surface using SIMD.

Parameters
surfThe surface to modify.
alpha_modThe 0-255 modifier to multiply the existing alpha by.
Returns
Number of pixels processed via SIMD, or 0 if SIMD was not used.

Definition at line 320 of file utils_simd.cpp.

References surface::area(), surface_locker< T >::pixels(), simd::SIMD_THRESHOLD, and surf.

Referenced by apply_surface_opacity().

◆ flip_image_simd()

std::size_t flip_image_simd ( surface surf)

Flips each row of pixels (horizontal mirror) using SIMD.

Parameters
surfThe surface to modify.
Returns
Number of columns (per row) processed via SIMD, or 0 if SIMD was not used.

Definition at line 354 of file utils_simd.cpp.

References surface::area(), surface_locker< T >::pixels(), simd::SIMD_THRESHOLD, and surf.

Referenced by flip_surface().

◆ mask_surface_simd()

std::size_t mask_surface_simd ( surface surf,
const surface mask,
bool &  empty 
)

Modifies the alpha channel of the surface pixels based on the mask.

Parameters
surfThe surface to modify.
maskThe mask surface to read alpha values from.
emptyOutput: set to false if any resulting pixel is non-transparent. Should be initialised to true by the caller.
Returns
Number of pixels processed via SIMD (always a multiple of 4), or 0 if SIMD was unavailable / pixel count was below the threshold.

Definition at line 302 of file utils_simd.cpp.

References surface::area(), surface_locker< T >::pixels(), simd::SIMD_THRESHOLD, and surf.

Referenced by mask_surface().