From 664678f9026159274eb5cb9a88e7e5c7656309d4 Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Mon, 6 May 2019 22:49:40 +0200 Subject: [PATCH] Reimplement gamma functions --- src/control/mod.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/control/mod.rs b/src/control/mod.rs index 96455358..eb638618 100644 --- a/src/control/mod.rs +++ b/src/control/mod.rs @@ -392,6 +392,50 @@ pub trait Device: super::Device { Ok(prop_val_set) } + + /// Receive the currently set gamma ramp of a crtc + fn get_gamma(&self, crtc: crtc::Handle, red: &mut [u16], green: &mut [u16], blue: &mut [u16]) -> Result<(), SystemError> { + let crtc_info = self.get_crtc(crtc)?; + if crtc_info.gamma_length as usize > red.len() || + crtc_info.gamma_length as usize > green.len() || + crtc_info.gamma_length as usize > blue.len() + { + return Err(SystemError::InvalidArgument); + } + + ffi::mode::get_gamma( + self.as_raw_fd(), + crtc.as_ref().get(), + crtc_info.gamma_length as usize, + red, + green, + blue + )?; + + Ok(()) + } + + /// Set a gamma ramp for the given crtc + fn set_gamma(&self, crtc: crtc::Handle, red: &[u16], green: &[u16], blue: &[u16]) -> Result<(), SystemError> { + let crtc_info = self.get_crtc(crtc)?; + if crtc_info.gamma_length as usize > red.len() || + crtc_info.gamma_length as usize > green.len() || + crtc_info.gamma_length as usize > blue.len() + { + return Err(SystemError::InvalidArgument); + } + + ffi::mode::set_gamma( + self.as_raw_fd(), + crtc.as_ref().get(), + crtc_info.gamma_length as usize, + red, + green, + blue + )?; + + Ok(()) + } } /// The set of [ResourceHandles](ResourceHandle.t.html) that a