#color-conversion #hex-color #color #conversion #hex-string #hsluv #hpluv

rust-hsluv

Color converstions. Convert to/from various color representations: hex, rgb, hsluv, hpluv, lch and xyz.

4 releases

Uses old Rust 2015

0.1.4 Jun 2, 2020
0.1.3 Nov 28, 2017
0.1.2 Nov 16, 2017
0.1.1 Nov 16, 2017

#261 in Rendering

Download history 413/week @ 2024-07-23 1054/week @ 2024-07-30 731/week @ 2024-08-06 646/week @ 2024-08-13 550/week @ 2024-08-20 972/week @ 2024-08-27 596/week @ 2024-09-03 482/week @ 2024-09-10 645/week @ 2024-09-17 395/week @ 2024-09-24 928/week @ 2024-10-01 536/week @ 2024-10-08 546/week @ 2024-10-15 770/week @ 2024-10-22 1179/week @ 2024-10-29 537/week @ 2024-11-05

3,115 downloads per month
Used in 13 crates (3 directly)

MIT license

1MB
294 lines

A Rust implementation of HSLuv.

Demo

Demo

Demo link: http://www.hsluv.org/syntax/#006925

Installation

Add this line to your application's Cargo.toml:

[dependencies]
hsluv = "0.1.2"

Usage

  • hue is a 64bit float between 0 and 360
  • saturation is a 64bit float between 0 and 100
  • lightness is a 64bit float between 0 and 100
  • hex is the hexadecimal format of the color
  • red is a 64bit float between 0 and 1
  • green is a 64bit float between 0 and 1
  • blue is a 64bit float between 0 and 1
extern crate hsluv;

use hsluv::*;

fn main() {
  let hex = "#ab3912";
  let hsluv = hex_to_hsluv(hex);
  let rgb = hsluv_to_rgb(hsluv);

  println!("Convert HEX {:?} to HSLUV: {:?}", hex, hsluv);
  println!("Convert HSLUV {:?} to RGB: {:?}", hsluv, rgb);
  println!("Convert RGB {:?} to HEX: {:?}", rgb, rgb_to_hex(rgb));
}

All API calls take and return a 3-tuple of 64bit floats, (f64, f64, f64) except the *_to_hex() functions: hsluv_to_hex(), hpluv_to_hex(), rgb_to_hex() which return String.

hsluv::hsluv_to_hex((hue, saturation, lightness)) -> color as a hex string

hsluv::hsluv_to_hex((12.177, 100.0, 53.23)) // => #ff0000

hsluv::hsluv_to_rgb((hue, saturation, lightness)) -> color as rgb

hsluv::hsluv_to_rgb(12.177, 100.0, 53.23) // => (0.9998643703868711, 0.00000000000006849859221502719, 0.000008791283550555612)

hsluv::hex_to_hsluv(hex) -> list of floats as defined above

hsluv::hex_to_hsluv("#ff0000") // => (12.177050630061776, 100.0000000000022, 53.23711559542933)

hsluv::rgb_to_hsluv(rgb) -> list of floats as defined above

hsluv::rgb_to_hsluv((0.99, 6.84e-14, 8.79e-16)) // => (12.17705063006216, 100.00000000000209, 52.711595266911985)

For HPLuv (the pastel variant), use:

  • hpluv_to_hex
  • hpluv_to_rgb
  • hex_to_hpluv
  • rgb_to_hpluv

Testing

Run cargo test.

Contributing

  1. Fork it ( http://github.com/dvdplm/hsluv-rust )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

No runtime deps