Skip to content

Commit 0e6fbe3

Browse files
authored
add gamma_ramp_arrays and calculate_gamma_ramp (#1451)
1 parent 9f97c16 commit 0e6fbe3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ when upgrading from a version of rust-sdl2 to another.
33

44
### Next
55

6+
[PR #1451](https://github.com/Rust-SDL2/rust-sdl2/pull/1451) Add `gamma_ramp_arrays` and `calculate_gamma_ramp`.
7+
68
[PR #1459](https://github.com/Rust-SDL2/rust-sdl2/pull/1459) Fix image and mixer init flag logic
79

810
[PR #1444](https://github.com/Rust-SDL2/rust-sdl2/pull/1444) Add texture scale mode api + fix unsafe

src/sdl2/video.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1984,6 +1984,24 @@ 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 red, mut green, mut blue] = [mem::MaybeUninit::<[u16; 256]>::uninit(); 3];
1990+
let result = unsafe {
1991+
sys::SDL_GetWindowGammaRamp(
1992+
self.context.raw,
1993+
red.as_mut_ptr().cast::<u16>(),
1994+
green.as_mut_ptr().cast::<u16>(),
1995+
blue.as_mut_ptr().cast::<u16>(),
1996+
)
1997+
};
1998+
if result == 0 {
1999+
Ok(unsafe { [red.assume_init(), green.assume_init(), blue.assume_init()] })
2000+
} else {
2001+
Err(get_error())
2002+
}
2003+
}
2004+
19872005
/// Set the transparency of the window. The given value will be clamped internally between
19882006
/// `0.0` (fully transparent), and `1.0` (fully opaque).
19892007
///
@@ -2138,3 +2156,12 @@ pub fn drivers() -> DriverIterator {
21382156
index: 0,
21392157
}
21402158
}
2159+
2160+
#[doc(alias = "SDL_CalculateGammaRamp")]
2161+
pub fn calculate_gamma_ramp(gamma: f32) -> [u16; 256] {
2162+
unsafe {
2163+
let mut ret = mem::MaybeUninit::<[u16; 256]>::uninit();
2164+
sys::SDL_CalculateGammaRamp(gamma as c_float, ret.as_mut_ptr().cast::<u16>());
2165+
ret.assume_init()
2166+
}
2167+
}

0 commit comments

Comments
 (0)