Skip to content
Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This release has an [MSRV][] of 1.82.
* `AlphaColor`, `OpaqueColor`, and `PremulColor` now impl `PartialEq`. ([#76][], [#86][] by [@waywardmonkeys][])
* `HueDirection` now impls `PartialEq`. ([#79][] by [@waywardmonkeys][])
* `ColorSpaceTag` and `HueDirection` now have bytemuck support. ([#81][] by [@waywardmonkeys][])
* `AlphaColor`, `DynamicColor`, `OpaqueColor`, and `PremulColor` now default to an opaque white. ([#85][] by [@waywardmonkeys][])

### Changed

Expand Down Expand Up @@ -62,6 +63,7 @@ This is the initial release.
[#79]: https://github.com/linebender/color/pull/79
[#80]: https://github.com/linebender/color/pull/80
[#81]: https://github.com/linebender/color/pull/81
[#85]: https://github.com/linebender/color/pull/85
[#86]: https://github.com/linebender/color/pull/86

[Unreleased]: https://github.com/linebender/color/compare/v0.1.0...HEAD
Expand Down
29 changes: 29 additions & 0 deletions color/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ use crate::floatfuncs::FloatFuncs;
/// major motivation for including these is to enable weighted sums, including
/// for spline interpolation. For cylindrical color spaces, hue fixup should
/// be applied before interpolation.
///
/// The default value is an opaque white. We don't recommend relying upon this
/// default.
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[repr(transparent)]
Expand All @@ -37,6 +40,9 @@ pub struct OpaqueColor<CS> {
///
/// A color in a color space known at compile time, with an alpha channel.
///
/// The default value is an opaque white. We don't recommend relying upon this
/// default.
///
/// See [`OpaqueColor`] for a discussion of arithmetic traits and interpolation.
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
Expand All @@ -60,6 +66,9 @@ pub struct AlphaColor<CS> {
/// the hue channel is not premultiplied. If it were, interpolation would
/// give undesirable results.
///
/// The default value is an opaque white. We don't recommend relying upon this
/// default.
///
/// See [`OpaqueColor`] for a discussion of arithmetic traits and interpolation.
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
Expand Down Expand Up @@ -637,6 +646,26 @@ impl<CS: ColorSpace> PremulColor<CS> {
}
}

// Defaults

impl<CS: ColorSpace> Default for AlphaColor<CS> {
fn default() -> Self {
Self::WHITE
}
}

impl<CS: ColorSpace> Default for OpaqueColor<CS> {
fn default() -> Self {
Self::WHITE
}
}

impl<CS: ColorSpace> Default for PremulColor<CS> {
fn default() -> Self {
Self::WHITE
}
}

// Lossless conversion traits.

impl<CS: ColorSpace> From<OpaqueColor<CS>> for AlphaColor<CS> {
Expand Down
10 changes: 10 additions & 0 deletions color/src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use crate::{
color::{add_alpha, fixup_hues_for_interpolate, split_alpha},
AlphaColor, ColorSpace, ColorSpaceLayout, ColorSpaceTag, HueDirection, LinearSrgb, Missing,
Srgb,
};
use core::hash::{Hash, Hasher};

Expand All @@ -25,6 +26,9 @@ use core::hash::{Hash, Hasher};
/// When manipulating components directly, setting them nonzero when the
/// corresponding missing flag is set may yield unexpected results.
///
/// The default value is an opaque white in the [sRGB](Srgb) color space with
/// no missing components. We don't recommend relying upon this default.
///
/// [Oklch]: crate::Oklch
#[derive(Clone, Copy, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
Expand Down Expand Up @@ -365,6 +369,12 @@ impl DynamicColor {
}
}

impl Default for DynamicColor {
fn default() -> Self {
Self::from_alpha_color(AlphaColor::<Srgb>::default())
}
}

impl Hash for DynamicColor {
/// The hash is computed from the bit representation of the component values.
/// That makes it suitable for use as a cache key or memoization, but does not
Expand Down