color: generate color from a u24
This commit is contained in:
parent
18609912d3
commit
7ff5251ea3
1 changed files with 12 additions and 0 deletions
12
src/Cell.zig
12
src/Cell.zig
|
@ -65,4 +65,16 @@ pub const Color = union(enum) {
|
||||||
default,
|
default,
|
||||||
index: u8,
|
index: u8,
|
||||||
rgb: [3]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 };
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue