From e28f3d33ba9f0717cc7b7660a1abdae5ed1fb9f5 Mon Sep 17 00:00:00 2001 From: Antoni Spaanderman <56turtle56@gmail.com> Date: Sun, 5 Jan 2025 01:27:18 +0100 Subject: [PATCH] add gamma_ramp_arrays and calculate_gamma_ramp - gamma_ramp_arrays is similar to gamma_ramp, but returns the gamma ramps as an array of 3 arrays, this way no heap allocations are made and users get a compile time guarantee that each ramp contains 256 values - calculate_gamma_ramp wraps SDL_CalculateGammaRamp, which calculates the gamma ramp for a gives gamma value, see https://wiki.libsdl.org/SDL2/SDL_CalculateGammaRamp --- src/sdl2/video.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/sdl2/video.rs b/src/sdl2/video.rs index c758a61425..66402052ca 100644 --- a/src/sdl2/video.rs +++ b/src/sdl2/video.rs @@ -1984,6 +1984,20 @@ impl Window { } } + #[doc(alias = "SDL_GetWindowGammaRamp")] + pub fn gamma_ramp_arrays(&self) -> Result<[[u16; 256]; 3], String> { + let mut ret = mem::MaybeUninit::<[[u16; 256]; 3]>::uninit(); + let ptr = ret.as_mut_ptr().cast::(); + let result = unsafe { + sys::SDL_GetWindowGammaRamp(self.context.raw, ptr, ptr.add(256), ptr.add(512)) + }; + if result == 0 { + Ok(unsafe { ret.assume_init() }) + } else { + Err(get_error()) + } + } + /// Set the transparency of the window. The given value will be clamped internally between /// `0.0` (fully transparent), and `1.0` (fully opaque). /// @@ -2138,3 +2152,12 @@ pub fn drivers() -> DriverIterator { index: 0, } } + +#[doc(alias = "SDL_CalculateGammaRamp")] +pub fn calculate_gamma_ramp(gamma: f32) -> [u16; 256] { + unsafe { + let mut ret = mem::MaybeUninit::<[u16; 256]>::uninit(); + sys::SDL_CalculateGammaRamp(gamma as c_float, ret.as_mut_ptr().cast::()); + ret.assume_init() + } +}