Skip to content

Commit

Permalink
image: do not round floats
Browse files Browse the repository at this point in the history
  • Loading branch information
arrufat committed Dec 7, 2024
1 parent a117b8c commit e6d4334
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/image.zig
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub fn Image(comptime T: type) type {
const int22s: @Vector(simd_len, f32) = integral.data[r2_offset + c2 ..][0..simd_len].*;
const areas: @Vector(simd_len, f32) = @splat(@as(f32, @floatFromInt(r2_r1 * 2 * radius)));
const sums = int22s - int21s - int12s + int11s;
const vals: [simd_len]f32 = @round(sums / areas);
const vals: [simd_len]f32 = if (@typeInfo(T) == .int) @round(sums / areas) else sums / areas;
for (vals, 0..) |val, i| {
if (@typeInfo(T) == .int) {
blurred.data[pos + i] = @intFromFloat(@max(std.math.minInt(T), @min(std.math.maxInt(T), val)));
Expand All @@ -319,7 +319,6 @@ pub fn Image(comptime T: type) type {
blurred.data[pos] = switch (@typeInfo(T)) {
.int => @intFromFloat(@max(std.math.minInt(T), @min(std.math.maxInt(T), (@round(sum / area))))),
.float => as(T, sum / area),
else => @compileError("Can't compute the boxBlur image with struct fields of type " ++ @typeName(T) ++ "."),
};
pos += 1;
rem -= 1;
Expand Down

0 comments on commit e6d4334

Please sign in to comment.