brendanzab / color-rs Goto Github PK
View Code? Open in Web Editor NEWA library that provides types and conversions for working with various color formats.
License: Apache License 2.0
A library that provides types and conversions for working with various color formats.
License: Apache License 2.0
Hey, if you aren't actively working on this I'd like to take over. I've rewritten color utilities at least five times now for separate projects, and I want to dedicate a crate to it once and for all.
If you require more details on what I plan to do with it, I can outline them all for you here.
Rather than having different color formats that are identical except for the presence of an alpha channel (such as RGB and RGBA), we may instead have a type that represents a "color with an alpha channel", such as:
struct AlphaColor<T: Channel, C: Color<T>> {
color: C,
alpha: T
}
Right now the current version on crates.io is 0.0.1. This no longer builds on beta.
matthew@0xB1uE7:/workspace/rust-playground/color-rs$ rustc -V/workspace/rust-playground/color-rs$ cargo -V
rustc 1.0.0-dev (built 2015-03-15)
matthew@0xB1uE7:
cargo 0.0.1-pre (2d2e039 2015-03-14) (built 2015-03-16)
matthew@0xB1uE7:~/workspace/rust-playground/color-rs$ cargo build
Compiling color v0.0.1 (file:///home/matthew/workspace/rust-playground/color-rs)
src/alpha.rs:19:38: 19:42 warning: derive(Show) is deprecated in favor of derive(Debug)
src/alpha.rs:19 #[derive(Clone, Copy, PartialEq, Eq, Show)]
^~~~
src/hsv.rs:26:38: 26:42 warning: derive(Show) is deprecated in favor of derive(Debug)
src/hsv.rs:26 #[derive(Clone, Copy, PartialEq, Eq, Show)]
^~~~
src/rgb.rs:22:38: 22:42 warning: derive(Show) is deprecated in favor of derive(Debug)
src/rgb.rs:22 #[derive(Clone, Copy, PartialEq, Eq, Show)]
^~~~
src/srgb.rs:16:38: 16:42 warning: derive(Show) is deprecated in favor of derive(Debug)
src/srgb.rs:16 #[derive(Clone, Copy, PartialEq, Eq, Show)]
^~~~
src/ycbcr.rs:18:38: 18:42 warning: derive(Show) is deprecated in favor of derive(Debug)
src/ycbcr.rs:18 #[derive(Clone, Copy, PartialEq, Eq, Show)]
^~~~
src/channel.rs:21:12: 21:29 warning: use of unstable library feature 'core': trait is likely to be removed
src/channel.rs:21 fn cast<T: std::num::NumCast, U: std::num::NumCast>(n: T) -> U {
^~~~~~~~~~~~~~~~~
src/channel.rs:21:29: 21:29 help: add #![feature(core)] to the crate attributes to silence this warning
src/channel.rs:21:34: 21:51 warning: use of unstable library feature 'core': trait is likely to be removed
src/channel.rs:21 fn cast<T: std::num::NumCast, U: std::num::NumCast>(n: T) -> U {
^~~~~~~~~~~~~~~~~
src/channel.rs:21:51: 21:51 help: add #![feature(core)] to the crate attributes to silence this warning
src/channel.rs:22:5: 22:19 warning: use of unstable library feature 'core': likely to be removed
src/channel.rs:22 std::num::cast(n).unwrap()
^~~~~~~~~~~~~~
src/channel.rs:22:19: 22:19 help: add #![feature(core)] to the crate attributes to silence this warning
src/hsv.rs:22:12: 22:24 warning: use of unstable library feature 'core': trait is likely to be removed
src/hsv.rs:22 fn cast<T: num::NumCast, U: num::NumCast>(n: T) -> U {
^~~~~~~~~~~~
src/hsv.rs:22:24: 22:24 help: add #![feature(core)] to the crate attributes to silence this warning
src/hsv.rs:22:29: 22:41 warning: use of unstable library feature 'core': trait is likely to be removed
src/hsv.rs:22 fn cast<T: num::NumCast, U: num::NumCast>(n: T) -> U {
^~~~~~~~~~~~
src/hsv.rs:22:41: 22:41 help: add #![feature(core)] to the crate attributes to silence this warning
src/hsv.rs:23:5: 23:14 warning: use of unstable library feature 'core': likely to be removed
src/hsv.rs:23 num::cast(n).unwrap()
^~~~~~~~~
src/hsv.rs:23:14: 23:14 help: add #![feature(core)] to the crate attributes to silence this warning
src/hsv.rs:116:22: 116:32 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:116 let one: T = Float::one();
^~~~~~~~~~
src/hsv.rs:116:32: 116:32 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/hsv.rs:117:49: 117:59 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:117 let x = chr * (one - ((h % cast(2u8)) - Float::one()).abs());
^~~~~~~~~~
src/hsv.rs:117:59: 117:59 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/hsv.rs:120:62: 120:73 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:120 if h < cast(1u8) { Rgb::new(chr.clone(), x, Float::zero()) }
^~~~~~~~~~~
src/hsv.rs:120:73: 120:73 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/hsv.rs:121:62: 121:73 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:121 else if h < cast(2u8) { Rgb::new(x, chr.clone(), Float::zero()) }
^~~~~~~~~~~
src/hsv.rs:121:73: 121:73 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/hsv.rs:122:46: 122:57 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:122 else if h < cast(3u8) { Rgb::new(Float::zero(), chr.clone(), x) }
^~~~~~~~~~~
src/hsv.rs:122:57: 122:57 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/hsv.rs:123:46: 123:57 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:123 else if h < cast(4u8) { Rgb::new(Float::zero(), x, chr.clone()) }
^~~~~~~~~~~
src/hsv.rs:123:57: 123:57 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/hsv.rs:124:49: 124:60 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:124 else if h < cast(5u8) { Rgb::new(x, Float::zero(), chr.clone()) }
^~~~~~~~~~~
src/hsv.rs:124:60: 124:60 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/hsv.rs:125:59: 125:70 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:125 else if h < cast(6u8) { Rgb::new(chr.clone(), Float::zero(), x) }
^~~~~~~~~~~
src/hsv.rs:125:70: 125:70 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/hsv.rs:126:46: 126:57 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:126 else { Rgb::new(Float::zero(), Float::zero(), Float::zero()) };
^~~~~~~~~~~
src/hsv.rs:126:57: 126:57 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/hsv.rs:126:61: 126:72 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:126 else { Rgb::new(Float::zero(), Float::zero(), Float::zero()) };
^~~~~~~~~~~
src/hsv.rs:126:72: 126:72 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/hsv.rs:126:76: 126:87 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/hsv.rs:126 else { Rgb::new(Float::zero(), Float::zero(), Float::zero()) };
^~~~~~~~~~~
src/hsv.rs:126:87: 126:87 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/rgb.rs:25:12: 25:24 warning: use of unstable library feature 'core': trait is likely to be removed
src/rgb.rs:25 fn cast<T: num::NumCast, U: num::NumCast>(n: T) -> U {
^~~~~~~~~~~~
src/rgb.rs:25:24: 25:24 help: add #![feature(core)] to the crate attributes to silence this warning
src/rgb.rs:25:29: 25:41 warning: use of unstable library feature 'core': trait is likely to be removed
src/rgb.rs:25 fn cast<T: num::NumCast, U: num::NumCast>(n: T) -> U {
^~~~~~~~~~~~
src/rgb.rs:25:41: 25:41 help: add #![feature(core)] to the crate attributes to silence this warning
src/rgb.rs:26:5: 26:14 warning: use of unstable library feature 'core': likely to be removed
src/rgb.rs:26 num::cast(n).unwrap()
^~~~~~~~~
src/rgb.rs:26:14: 26:14 help: add #![feature(core)] to the crate attributes to silence this warning
src/rgb.rs:119:19: 119:30 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/rgb.rs:119 if chr != Float::zero() {
^~~~~~~~~~~
src/rgb.rs:119:30: 119:30 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/rgb.rs:131:22: 131:33 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/rgb.rs:131 Hsv::new(Float::zero(), Float::zero(), mx)
^~~~~~~~~~~
src/rgb.rs:131:33: 131:33 help: add #![feature(std_misc)] to the crate attributes to silence this warning
src/rgb.rs:131:37: 131:48 warning: use of unstable library feature 'std_misc': unsure about its place in the world
src/rgb.rs:131 Hsv::new(Float::zero(), Float::zero(), mx)
^~~~~~~~~~~
src/rgb.rs:131:48: 131:48 help: add #![feature(std_misc)] to the crate attributes to silence this warning
We need a way to represent color spaces. It may be desirable to have color spaces defined independantly of color formats, ideally allowing us to have color types defined as a combination of channel type, color format and color space, such as:
// color channels
trait Channel { .. }
// color spaces
enum Linear {}
enum sRGB {}
trait ColorSpace { .. }
impl ColorSpace for Linear { .. }
impl ColorSpace for SRGB { .. }
// color formats
struct RGB<T: Channel, S: ColorSpace> { r: T, g: T, b: T }
// color types
trait Color<T: Channel, S: ColorSpace> { .. }
impl<T: Channel, S: ColorSpace> Color<T, S> for RGB<T, S> { .. }
// possible color types: RGB<u8, sRGB>, RGB<f32, Linear>, etc
However, this may not work well in practice since color spaces are often tied to their own color formats.
Lab* colors are usually represented as one of the following two
L* | a* | b* |
---|---|---|
0 – 100 | -120 – 120 | -120 – 120 |
0 – 100 | -128 – 128 | -128 – 128 |
the last one more “accomodating” to computers (to almost represent them as i8
, i guess).
now adding this is a problem: we’d have to add two more ways to invert this: 100 - L
and the simple -a
/-b
.
i think we should consider a way to handle this, e.g. by tying the kind of channel to the color model:
HSV | Lab* | RGB | |
---|---|---|---|
H/L*/R | circular | unsigned | unsigned |
S/a*/G | unsigned | signed | unsigned |
V/b*/B | unsigned | signed | unsigned |
that would involve either normalizing float channels (always clamp to [-1..1] or [0..1], modulo when circular). also bits would be lost: using 3×i8 for Lab* would mean using all int values from -128 to 127, but only 100 lightness levels!
do you have a different idea how to handle this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.