Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created May 11, 2018 19:57
Show Gist options
  • Save rust-play/40a8fc9422f88c5af8bcd5900fe9230a to your computer and use it in GitHub Desktop.
Save rust-play/40a8fc9422f88c5af8bcd5900fe9230a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
extern crate rgb;
pub mod openktg {
use rgb::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct LinearLight(u16);
impl LinearLight {
pub fn new(x: u16) -> LinearLight {
LinearLight { 0: x }
}
}
impl Add for LinearLight {
type Output = LinearLight;
fn add(self, other: LinearLight) -> LinearLight {
LinearLight(self.0.saturating_add(other.0))
}
}
pub type LinearRGBA = RGBA<LinearLight, u16>;
}
fn main() {
let px = LinearRGBA {
r: LinearLight::new(65535),
g: LinearLight::new(65535),
b: LinearLight::new(65535),
a: 255,
};
let px2 = px.map(|channel| channel + 100);
println!("{:?}", px2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment