tylerreisinger / prisma Goto Github PK
View Code? Open in Web Editor NEWA powerful color representation, manipulation and conversion library that aims to be easy to use.
License: MIT License
A powerful color representation, manipulation and conversion library that aims to be easy to use.
License: MIT License
Angular-units is a dependency of the crate, but since prisma doesn't re-export it, users need to add angular-units to their own dependencies in order to use things like prisma::Hsv.
I think it'd help usability to add a re-export.
@tylerreisinger thanks for the prisma crate! I really prefer it compared to the alternatives.
I created three PRs that should be very clean and easy to merge. They don't touch any of the current features so no need to worry about regressions.
Thanks
While UVW is technically an obsolete color space, it is still used in the computation of correlated color temperature.
It is incorrect to compare XYZ coordinates with different standard observers together. Evaluate if it would be worth extending Xyz<T>
to Xyz<T, S>
where S is a unit struct encoding the color matching functions used.
Right now, from_slice always treats an angular scalar as a Turns
value when loading it. This is asymmetric with as_slice which gives the raw value and somewhat unexpected.
Delta-E allows for quantifying color difference. It's very useful in many applications.
Running with Rust 1.77.2 on Windows 10, I ran this code :
let color = [r, g, b];
let color = prisma::Rgb::new(color[0], color[1], color[2]);
let mut color = prisma::Hsv::<f32,angular_units::Deg<_>>::from_color(&color);
color.set_hue( color.hue() + angular_units::Deg(90.0) );
let color = prisma::Rgb::from_color(&color);
let color = [color.red(), color.green(), color.blue()];
In other words, I created a color from existing r,g,b values and then attempted to rotate its hue 90 degrees.
On the line let color = prisma::Rgb::from_color(&color);
I got:
thread 'main' panicked at C:\Users\Andi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\prisma-0.1.1\src\hsv.rs:29
1:18:
internal error: entered unreachable code
stack backtrace:
0: std::panicking::begin_panic_handler
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\std\src\panicking.rs:647
1: core::panicking::panic_fmt
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\core\src\panicking.rs:72
2: core::panicking::panic
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04/library\core\src\panicking.rs:144
3: prisma::hsv::impl$15::from_color<f32,angular_units::Deg<f32> >
3: prisma::hsv::impl$15::from_color<f32,angular_units::Deg<f32> >
at C:\Users\Andi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\prisma-0.1.1\src\hsv.rs:291 3: prisma::hsv::impl$15::from_color<f32,angular_units::Deg<f32> >
at C:\Users\Andi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\prisma-0.1.1\src\hsv.rs:291 3: prisma::hsv::impl$15::from_color<f32,angular_units::Deg<f32> >
at C:\Users\Andi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\prisma-0.1.1\src\hsv.rs:291 3: prisma::hsv::impl$15::from_color<f32,angular_units::Deg<f32> >
at C:\Users\Andi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\prisma-0.1.1\src\hsv.rs:291 3: prisma::hsv::impl$15::from_color<f32,angular_units::Deg<f32> >
at C:\Users\Andi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\prisma-0.1.1\src\hsv.rs:291 3: prisma::hsv::impl$15::from_color<f32,angular_units::Deg<f32> >
at C:\Users\Andi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\prisma-0.1.1\src\hsv.rs:291 3: prisma::hsv::impl$15::from_color<f32,angular_units::Deg<f32> >
at C:\Users\Andi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\prisma-0.1.1\src\hsv.rs:291 3: prisma::hsv::impl$15::from_color<f32,angular_units::Deg<f32> >
at C:\Users\Andi\.cargo\registry\src\index.crates.io-6f17d22bba15001f\prisma-0.1.1\src\hsv.rs:291
4: video::main
at .\src\main.rs:188
5: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\core\src\ops\function.rs:250
6: core::hint::black_box
at /rustc/25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04\library\core\src\hint.rs:334
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
However, if I change the rotation line to:
color.set_hue( ( color.hue() + angular_units::Deg(90.0) ) % angular_units::Deg(360.0) )
It runs without problems.
Prisma contains many traits. Usability may be improved by re-exporting the most commonly used into a preamble
module that can then be glob imported.
Many functions are trivial and should be inlined. Do an inlining pass over the code.
Palette has a bunch of them, and Prisma should have them too.
Lu'v' or UCS is an analog to the xyY space for XYZ. It is useful in many places Luv is used.
Half-precision floating point has 11 bits of precision, which is more than enough for most display-oriented colors. Implementing an optional feature supporting them in prisma could be beneficial to some applications.
From can even be used to do conversion chains, but not for things tthat require models or other additional information.
Lerp always takes the shortest path on angular channels. Sometimes, it might be desirable to take the other path, and so there should be a method to support that. Non-angular channels will behave identically for both lerp methods.
It would be nice to be able to pack colors into a buffer, and to swizzle the channels if necessary.
Converting spectral data to XYZ is an important process for colorimetry.
Chromatic adaptation allows changing white points and color spaces, which is useful in photography and many other fields
Right now, the documentation says that RGB components can only be in the 0..1 range. I'm currently doing "Ray Tracing In One Weekend" and I wanted to do HDR with a proper color library, but it doesn't look like Prisma allows that. :/
The mean of Rgb is a very simple process, but the mean of polar colors is a bit more involved, as is the mean of xyY. It would be nice to have a trait to allow means to be computed from an iterator of color values.
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.