Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ You can find its changes [documented below](#033-2026-05-05).

This release has an [MSRV][] of 1.86.

### Added

- Add a `const` `DynamicColor::new` constructor for convenience, taking a color space tag and color components, and setting default `Flags`. ([#219][] by [@tomcur][])

### Changed

- `Flags::set_missing`, `Flags::discard_name`, `Flags::set_named_color_space`, and `Missing::insert` are now `const` thanks to the MSRV update. ([#218][] by [@DJMcNab][])
Expand Down Expand Up @@ -231,6 +235,7 @@ This is the initial release.
[#210]: https://github.com/linebender/color/pull/210
[#211]: https://github.com/linebender/color/pull/211
[#218]: https://github.com/linebender/color/pull/218
[#219]: https://github.com/linebender/color/pull/219

[Unreleased]: https://github.com/linebender/color/compare/v0.3.3...HEAD
[0.3.3]: https://github.com/linebender/color/releases/tag/v0.3.3
Expand Down
20 changes: 15 additions & 5 deletions color/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ pub struct UnpremultipliedInterpolator {
}

impl DynamicColor {
/// Construct a `DynamicColor` from a color space tag and its components.
///
/// The the first three components are interpreted according to the color space tag. The
/// fourth component is separate alpha.
#[inline]
#[must_use]
pub const fn new(cs: ColorSpaceTag, components: [f32; 4]) -> Self {
Self {
cs,
flags: Flags::from_missing(Missing::EMPTY),
components,
}
}

/// Convert to `AlphaColor` with a static color space.
///
/// Missing components are interpreted as 0.
Expand All @@ -96,11 +110,7 @@ impl DynamicColor {
#[must_use]
pub fn from_alpha_color<CS: ColorSpace>(color: AlphaColor<CS>) -> Self {
if let Some(cs) = CS::TAG {
Self {
cs,
flags: Flags::default(),
components: color.components,
}
Self::new(cs, color.components)
} else {
Self::from_alpha_color(color.convert::<LinearSrgb>())
}
Expand Down
Loading