Skip to content

Commit

Permalink
colorspace: try bitCast
Browse files Browse the repository at this point in the history
  • Loading branch information
arrufat committed Jan 9, 2025
1 parent 90ed65e commit c5b976e
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/colorspace.zig
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,7 @@ pub const Rgb = struct {

/// Converts the RGB color into a hex value.
pub fn toHex(self: Rgb) u24 {
return
// zig fmt: off
(@as(u24, @intCast(self.r)) << @as(u5, @truncate(8 * 2))) +
(@as(u24, @intCast(self.g)) << @as(u5, @truncate(8 * 1))) +
(@as(u24, @intCast(self.g)) << @as(u5, @truncate(8 * 0)));
// zig fmt: on
return std.mem.bigToNative(u24, @bitCast(self));
}

/// Converts the RGB color into a RGBA color with the specified alpha.
Expand Down Expand Up @@ -400,13 +395,7 @@ pub const Rgba = packed struct {

/// Converts the RGBA color into a hex value.
pub fn toHex(self: Rgba) u32 {
return
// zig fmt: off
(@as(u32, @intCast(self.r)) << @as(u5, @truncate(8 * 3))) +
(@as(u32, @intCast(self.g)) << @as(u5, @truncate(8 * 2))) +
(@as(u32, @intCast(self.g)) << @as(u5, @truncate(8 * 1))) +
(@as(u32, @intCast(self.a)) << @as(u5, @truncate(8 * 0)));
// zig fmt: on
return std.mem.bigToNative(u32, @bitCast(self));
}

/// Converts the RGBA color into a RGB color by removing the alpha channel.
Expand Down

0 comments on commit c5b976e

Please sign in to comment.