Skip to content

Commit

Permalink
feat(manip): even more manipulations
Browse files Browse the repository at this point in the history
  • Loading branch information
nitrogenez committed Sep 7, 2024
1 parent 3fb25eb commit b0d02d1
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/manip.zig
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,19 @@ pub fn desaturate(rgb: [3]f64, amount: f64) [3]f64 {
hsl[1] = std.math.clamp(hsl[1], 0.0, 1.0);
return prism.hslToRgb(hsl);
}

/// Sets saturation `value` for `rgb`. RGB values must be normalized. `value` = 0...1
pub fn setSaturation(rgb: [3]f64, value: f64) [3]f64 {
var hsl = prism.rgbToHsl(rgb);
hsl[1] = value;
hsl[1] = std.math.clamp(hsl[1], 0.0, 1.0);
return prism.hslToRgb(hsl);
}

/// Rotates the hue of `rgb`. `amount` = 0...1
pub fn rotateHue(rgb: [3]f64, amount: f64) [3]f64 {
var hsl = prism.rgbToHsl(rgb);
hsl[0] += amount;
hsl[0] = std.math.clamp(hsl[0], 0.0, 360.0);
return prism.hslToRgb(hsl);
}

0 comments on commit b0d02d1

Please sign in to comment.