Skip to content

Commit e28f3d3

Browse files
committed
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
1 parent 400e033 commit e28f3d3

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/sdl2/video.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,20 @@ impl Window {
19841984
}
19851985
}
19861986

1987+
#[doc(alias = "SDL_GetWindowGammaRamp")]
1988+
pub fn gamma_ramp_arrays(&self) -> Result<[[u16; 256]; 3], String> {
1989+
let mut ret = mem::MaybeUninit::<[[u16; 256]; 3]>::uninit();
1990+
let ptr = ret.as_mut_ptr().cast::<u16>();
1991+
let result = unsafe {
1992+
sys::SDL_GetWindowGammaRamp(self.context.raw, ptr, ptr.add(256), ptr.add(512))
1993+
};
1994+
if result == 0 {
1995+
Ok(unsafe { ret.assume_init() })
1996+
} else {
1997+
Err(get_error())
1998+
}
1999+
}
2000+
19872001
/// Set the transparency of the window. The given value will be clamped internally between
19882002
/// `0.0` (fully transparent), and `1.0` (fully opaque).
19892003
///
@@ -2138,3 +2152,12 @@ pub fn drivers() -> DriverIterator {
21382152
index: 0,
21392153
}
21402154
}
2155+
2156+
#[doc(alias = "SDL_CalculateGammaRamp")]
2157+
pub fn calculate_gamma_ramp(gamma: f32) -> [u16; 256] {
2158+
unsafe {
2159+
let mut ret = mem::MaybeUninit::<[u16; 256]>::uninit();
2160+
sys::SDL_CalculateGammaRamp(gamma as c_float, ret.as_mut_ptr().cast::<u16>());
2161+
ret.assume_init()
2162+
}
2163+
}

0 commit comments

Comments
 (0)