From 7ff5251ea32ad44821e395300c1349710580b182 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 15 Apr 2024 07:15:00 -0500 Subject: [PATCH] color: generate color from a u24 --- src/Cell.zig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Cell.zig b/src/Cell.zig index 18bd3dd..e733223 100644 --- a/src/Cell.zig +++ b/src/Cell.zig @@ -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 }; + } };