Git Product home page Git Product logo

color_space's Introduction

A Rust library for converting between color spaces and comparing colors, ported from https://github.com/berendeanicolae/ColorSpace.

Color Conversion

You can convert between any supported color spaces using the from trait method:

use color_space::{Rgb, Hsv};

let rgb = Rgb::new(0.0, 255.0, 0.0);
let hsv = Hsv::from(rgb);
assert_eq!(hsv, Hsv::new(120.0, 1.0, 1.0));

You can also do this generically with the from_color method:

use color_space::{Rgb, Hsv, FromColor};

let rgb = Rgb::new(0.0, 0.0, 255.0);
let hsv = Hsv::from_color(&rgb);
assert_eq!(hsv, Hsv::new(240.0, 1.0, 1.0));

Comparing Colors

You can compare colors by using the compare_* methods:

use color_space::{Rgb, Hsv, CompareCie2000};

let rgb = Rgb::new(255.0, 0.0, 0.0);
let hsv = Hsv::new(0.0, 1.0, 1.0);
let diff = rgb.compare_cie2000(&hsv);
assert_eq!(diff, 0.0);
// these two colors are the same, so the difference is zero

Currently Supported Color Spaces

  • CMY
  • CMYK
  • HSL
  • HSB
  • HSV
  • CIE L*AB
  • Hunter LAB
  • LCH
  • LUV
  • RGB
  • XYZ
  • YXY

Currently Supported Comparisons

  • Euclidean
  • CIE1976
  • CIE2000
  • CMC

Contibutions

I'm happy to take feedback and improvements on the API if there's ways it can be improved. I need to write more tests to check the quality of the conversion outputs as well, but they are tedious to write so I'm currently procrastinating on that.

color_space's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.