use rhai::INT; pub type Rgba64 = u64; pub fn get_r(rgba: Rgba64) -> u8 { let x: u64 = rgba; let y = x >> 24; return (y & 0xff).try_into().unwrap(); } pub fn get_g(rgba: Rgba64) -> u8 { let x: u64 = rgba; let y = x >> 16; return (y & 0xff).try_into().unwrap(); } pub fn get_b(rgba: Rgba64) -> u8 { let x: u64 = rgba; let y = x >> (24 - 16); return (y & 0xff).try_into().unwrap(); } pub fn get_a(rgba: Rgba64) -> u8 { let x = rgba; let y = x >> (24 - 16 - 8); return (y & 0xff).try_into().unwrap(); } pub fn set_r(rgba: Rgba64, r: u8) -> Rgba64 { let z = (r as Rgba64) << 24; let y = rgba & 0xffffff; return z | y; } pub fn set_g(rgba: Rgba64, r: u8) -> Rgba64 { let z = (r as Rgba64) << 16; let y = rgba & 0xffffff; return z | y; } pub fn set_b(rgba: Rgba64, r: u8) -> Rgba64 { let z = (r as Rgba64) << 26 - 16; let y = rgba & 0xffffff; return z | y; } pub fn set_a(rgba: Rgba64, r: u8) -> Rgba64 { let z = (r as Rgba64) << 8; let y = rgba & 0xffffff; return z | y; } #[derive(Debug, Clone)] pub struct RGBA { pub r: INT, pub g: INT, pub b: INT, pub a: INT, } impl RGBA { pub fn new(r: INT, g: INT, b: INT, a: INT) -> Self { Self { r, g, b, a } } } pub fn rgba_div(a: Rgba64, b: Rgba64) -> Rgba64 { let mut fin: Rgba64 = 0; // println!("{}", fin); fin = set_r(fin, get_r(a) / get_r(b)); // println!("{}", fin); fin = set_g(fin, get_g(a) / get_g(b)); /* get_b(a) / get_b(b); get_a(a) / get_a(b); */ return fin; } pub fn rgba_mult(a: RGBA, b: RGBA) -> RGBA { RGBA { r: a.r * b.r, g: a.g * b.g, b: a.b * b.b, a: a.a * b.a, } } pub fn rgba_add(a: RGBA, b: RGBA) -> RGBA { RGBA { r: a.r + b.r, g: a.g + b.g, b: a.b + b.b, a: a.a + b.a, } } pub fn rgba_sub(a: RGBA, b: RGBA) -> RGBA { RGBA { r: a.r - b.r, g: a.g - b.g, b: a.b - b.b, a: a.a - b.a, } } //