Skip to content

Commit

Permalink
colorspace: replace if statements with if expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
arrufat committed Oct 10, 2024
1 parent d73be3f commit 002bc48
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/colorspace.zig
Original file line number Diff line number Diff line change
Expand Up @@ -298,23 +298,9 @@ pub const Rgb = struct {
var g: f64 = @as(f64, @floatFromInt(self.g)) / 255;
var b: f64 = @as(f64, @floatFromInt(self.b)) / 255;

if (r > 0.04045) {
r = pow(f64, (r + 0.055) / 1.055, 2.4);
} else {
r /= 12.92;
}

if (g > 0.04045) {
g = pow(f64, (g + 0.055) / 1.055, 2.4);
} else {
g /= 12.92;
}

if (b > 0.04045) {
b = pow(f64, (b + 0.055) / 1.055, 2.4);
} else {
b /= 12.92;
}
r = if (r > 0.04045) pow(f64, (r + 0.055) / 1.055, 2.4) else r / 12.92;
g = if (g > 0.04045) pow(f64, (g + 0.055) / 1.055, 2.4) else g / 12.92;
b = if (b > 0.04045) pow(f64, (b + 0.055) / 1.055, 2.4) else b / 12.92;

return .{
.x = (r * 0.4124 + g * 0.3576 + b * 0.1805) * 100,
Expand Down

0 comments on commit 002bc48

Please sign in to comment.