Crates.io | color |
lib.rs | color |
version | 0.1.0 |
source | src |
created_at | 2014-11-21 00:14:09.623627 |
updated_at | 2024-11-20 19:27:07.282156 |
description | A library for representing and manipulating colors |
homepage | |
repository | https://github.com/linebender/color |
max_upload_size | |
id | 194 |
size | 211,216 |
Color is a Rust crate which implements color space conversions, targeting at least CSS Color Level 4.
Color in its entirety is an extremely deep and complex topic. It is completely impractical for a single crate to meet all color needs. The goal of this one is to strike a balance, providing color capabilities while also keeping things simple and efficient.
The main purpose of this crate is to provide a good set of types for representing colors, along with conversions between them and basic manipulations, especially interpolation. A major inspiration is the CSS Color Level 4 draft spec; we implement most of the operations and strive for correctness.
A primary use case is rendering, including color conversions and methods for preparing gradients. The crate should also be suitable for document authoring and editing, as it contains methods for parsing and serializing colors with CSS Color 4 compatible syntax.
Simplifications include:
f32
to represent component values.A number of other tasks are out of scope for this crate:
The Rgba8
type is a partial exception to this last item, as that representation
is ubiquitous and requires special logic for serializing to maximize compatibility.
Some of these capabilities may be added as other crates within the color
repository,
and we will also facilitate interoperability with other color crates in the Rust
ecosystem as needed.
The crate has two approaches to representing color in the Rust type system: a set of
types with static color space as part of the types, and DynamicColor
in which the color space is represented at runtime.
The static color types come in three variants: OpaqueColor
without an
alpha channel, AlphaColor
with a separate alpha channel, and PremulColor
with
premultiplied alpha. The last type is particularly useful for making interpolation and
compositing more efficient. These have a marker type parameter, indicating which
ColorSpace
they are in. Conversion to another color space uses the convert
method
on each of these types. The static types are open-ended, as it's possible to implement
this trait for new color spaces.
std
(enabled by default): Get floating point functions from the standard library
(likely using your target's libc).libm
: Use floating point implementations from libm.bytemuck
: Implement traits from bytemuck
on AlphaColor
, OpaqueColor
,
PremulColor
, and Rgba8
.At least one of std
and libm
is required; std
overrides libm
.
This version of Color has been verified to compile with Rust 1.82 and later.
Future versions of Color might increase the Rust version requirement. It will not be treated as a breaking change and as such can even happen with small patch releases.
As time has passed, some of Color's dependencies could have released versions with a higher Rust requirement. If you encounter a compilation issue due to a dependency and don't want to upgrade your Rust toolchain, then you could downgrade the dependency.
# Use the problematic dependency's name and version
cargo update -p package_name --precise 0.1.1
Discussion of Color development happens in the Linebender Zulip, specifically the #color channel. All public content can be read without logging in.
Licensed under either of
at your option.
Contributions are welcome by pull request. The Rust code of conduct applies. Please feel free to add your name to the AUTHORS file in any substantive pull request.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be licensed as above, without any additional terms or conditions.