From c76ed83b3836f00c4db10aab9f114187fac84c52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Arrufat?= Date: Sat, 2 Nov 2024 21:57:43 +0900 Subject: [PATCH] =?UTF-8?q?image:=20rename=20toBytes=20=E2=86=92=20asBytes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/image.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/image.zig b/src/image.zig index 441309d..8ab7cbc 100644 --- a/src/image.zig +++ b/src/image.zig @@ -42,7 +42,8 @@ pub fn Image(comptime T: type) type { } /// Returns the image data reinterpreted as a slice of bytes - pub fn toBytes(self: Self) []u8 { + pub fn asBytes(self: Self) []u8 { + assert(self.rows * self.cols == self.data.len); return @as([*]u8, @ptrCast(@alignCast(self.data.ptr)))[0 .. self.data.len * @sizeOf(T)]; } @@ -56,7 +57,7 @@ pub fn Image(comptime T: type) type { /// Returns the number of channels or depth of this image type. pub fn channels() usize { - return switch (@typeInfo(T)) { + return comptime switch (@typeInfo(T)) { .int, .float => 1, .@"struct" => std.meta.fields(T).len, .array => |info| info.len,