Skip to content

Commit

Permalink
image: rename toBytes → asBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
arrufat committed Nov 2, 2024
1 parent 84fa108 commit c76ed83
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/image.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}

Expand All @@ -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,
Expand Down

0 comments on commit c76ed83

Please sign in to comment.