Skip to content

Commit

Permalink
add gamma_ramp_arrays and calculate_gamma_ramp
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
antonilol committed Jan 5, 2025
1 parent 400e033 commit e28f3d3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/sdl2/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<u16>();
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).
///
Expand Down Expand Up @@ -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::<u16>());
ret.assume_init()
}
}

0 comments on commit e28f3d3

Please sign in to comment.