color: generate color from a u24

This commit is contained in:
Tim Culverhouse 2024-04-15 07:15:00 -05:00
parent 18609912d3
commit 7ff5251ea3

View file

@ -65,4 +65,16 @@ pub const Color = union(enum) {
default,
index: u8,
rgb: [3]u8,
pub fn rgbFromUint(val: u24) Color {
const r_bits = val & 0b11111111_00000000_00000000;
const g_bits = val & 0b00000000_11111111_00000000;
const b_bits = val & 0b00000000_00000000_11111111;
const rgb = [_]u8{
@truncate(r_bits >> 16),
@truncate(g_bits >> 8),
@truncate(b_bits),
};
return .{ .rgb = rgb };
}
};