Skip to content

Commit

Permalink
image: minor tweaks
Browse files Browse the repository at this point in the history
- make init methods return Image(T) instead of Self to help ZLS
- remove unneeded pointers
  • Loading branch information
arrufat committed Aug 10, 2024
1 parent 25b8ce6 commit 1ba82d2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/src/face_alignment.zig
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub fn extractAlignedFace(
// Resize it to the desired size.
var resized = try Image(Rgba).initAlloc(allocator, out.rows, out.cols);
defer resized.deinit(allocator);
chip.resize(&resized);
chip.resize(resized);
for (out.data, resized.data) |*c, b| {
c.* = b;
}
Expand Down
6 changes: 3 additions & 3 deletions src/image.zig
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ pub fn Image(comptime T: type) type {
const Self = @This();
/// Constructs an image of rows and cols size. If the slice is owned by this image,
/// deinit should also be called.
pub fn init(rows: usize, cols: usize, data: []T) Self {
pub fn init(rows: usize, cols: usize, data: []T) Image(T) {
return .{ .rows = rows, .cols = cols, .data = data };
}

pub fn initAlloc(allocator: std.mem.Allocator, rows: usize, cols: usize) !Self {
pub fn initAlloc(allocator: std.mem.Allocator, rows: usize, cols: usize) !Image(T) {
var array = std.ArrayList(T).init(allocator);
try array.resize(rows * cols);
return .{ .rows = rows, .cols = cols, .data = try array.toOwnedSlice() };
Expand Down Expand Up @@ -117,7 +117,7 @@ pub fn Image(comptime T: type) type {
}

/// Resizes an image to fit in out, using bilinear interpolation.
pub fn resize(self: Self, out: *Self) void {
pub fn resize(self: Self, out: Self) void {
const x_scale: f32 = as(f32, self.cols - 1) / as(f32, @max(out.cols - 1, 1));
const y_scale: f32 = as(f32, self.rows - 1) / as(f32, @max(out.rows - 1, 1));
var sy: f32 = -y_scale;
Expand Down

0 comments on commit 1ba82d2

Please sign in to comment.