Macro retro_pixel::rgba16 [−][src]
macro_rules! rgba16 { ($r:expr, $g:expr, $b:expr, $a:expr) => { ... }; }
Builds a u16
value from the given RGBA values.
Each color channel is cast into u16
, and then they're combined into a
single u16
value (A1_B5_G5_R5
). If color channel aren't within the range
0..=31
you'll get some unintentional output. The alpha value is given as a
boolean expression, and flips the highest bit on or off.
#[macro_use] extern crate retro_pixel; fn main() { const TRANSPARENT_BLACK: u16 = rgba16!(0, 0, 0, false); const SOLID_WHITE: u16 = rgba16!(31, 0x1F, 31.0, true); assert_eq!(TRANSPARENT_BLACK, 0u16); assert_eq!(SOLID_WHITE, ::std::u16::MAX); // all other outputs depend on what endian the machine is, // currently only little endian is supported. assert_eq!(rgba16!(31, 0, 0, false), 0b0000000000011111u16); assert_eq!(rgba16!(0, 31, 0, false), 0b0000001111100000u16); assert_eq!(rgba16!(0, 0, 31, false), 0b0111110000000000u16); assert_eq!(rgba16!(0, 0, 0, true), 0b1000000000000000u16); }