From c897d449a49c54e4f6b173c866f71d428ca36a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Tue, 7 Jan 2025 11:25:42 +0100 Subject: [PATCH] colorspace: store @TypeOf result --- src/colorspace.zig | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/colorspace.zig b/src/colorspace.zig index 8713b0d..dd2b50d 100644 --- a/src/colorspace.zig +++ b/src/colorspace.zig @@ -41,54 +41,55 @@ fn isRgbCompatible(comptime T: type) bool { /// Converts color into the T colorspace. pub fn convert(comptime T: type, color: anytype) T { + const ColorType = @TypeOf(color); comptime assert(isColor(T)); - comptime assert(isColor(@TypeOf(color))); + comptime assert(isColor(ColorType)); return switch (T) { - u8 => switch (@TypeOf(color)) { + u8 => switch (ColorType) { u8 => color, inline else => color.toGray(), }, - Rgb => switch (@TypeOf(color)) { + Rgb => switch (ColorType) { Rgb => color, u8 => .{ .r = color, .g = color, .b = color }, inline else => color.toRgb(), }, - Rgba => switch (@TypeOf(color)) { + Rgba => switch (ColorType) { Rgba => color, u8 => .{ .r = color, .g = color, .b = color, .a = 255 }, inline else => color.toRgba(255), }, - Hsl => switch (@TypeOf(color)) { + Hsl => switch (ColorType) { Hsl => color, u8 => .{ .h = 0, .s = 0, .l = @as(f64, @floatFromInt(color)) / 255 * 100 }, inline else => color.toHsl(), }, - Hsv => switch (@TypeOf(color)) { + Hsv => switch (ColorType) { Hsv => color, u8 => .{ .h = 0, .s = 0, .v = @as(f64, @floatFromInt(color)) / 255 * 100 }, inline else => color.toHsv(), }, - Xyz => switch (@TypeOf(color)) { + Xyz => switch (ColorType) { Xyz => color, u8 => Rgb.fromGray(color).toXyz(), inline else => color.toXyz(), }, - Lab => switch (@TypeOf(color)) { + Lab => switch (ColorType) { Lab => color, u8 => .{ .l = @as(f64, @floatFromInt(color)) / 255 * 100, .a = 0, .b = 0 }, inline else => color.toLab(), }, - Lms => switch (@TypeOf(color)) { + Lms => switch (ColorType) { Lms => color, u8 => .{}, inline else => color.toLms(), }, - Oklab => switch (@TypeOf(color)) { + Oklab => switch (ColorType) { Oklab => color, u8 => .{}, inline else => color.toOklab(), }, - Xyb => switch (@TypeOf(color)) { + Xyb => switch (ColorType) { Xyb => color, u8 => .{}, inline else => color.toXyb(),