Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc improvements #94

Merged
merged 1 commit into from
Dec 15, 2024
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
2 changes: 1 addition & 1 deletion color/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ this trait for new color spaces.
- `bytemuck`: Implement traits from `bytemuck` on [`AlphaColor`], [`ColorSpaceTag`],
[`HueDirection`], [`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].
- `serde`: Implement `serde::Deserialize` and `serde::Serialize` on [`AlphaColor`],
[`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].
[`DynamicColor`], [`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].

At least one of `std` and `libm` is required; `std` overrides `libm`.

Expand Down
2 changes: 1 addition & 1 deletion color/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
//! - `bytemuck`: Implement traits from `bytemuck` on [`AlphaColor`], [`ColorSpaceTag`],
//! [`HueDirection`], [`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].
//! - `serde`: Implement `serde::Deserialize` and `serde::Serialize` on [`AlphaColor`],
//! [`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].
//! [`DynamicColor`], [`OpaqueColor`], [`PremulColor`], [`PremulRgba8`], and [`Rgba8`].
//!
//! At least one of `std` and `libm` is required; `std` overrides `libm`.
//!
Expand Down
19 changes: 19 additions & 0 deletions color/src/rgba8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ use crate::{AlphaColor, PremulColor, Srgb};
/// Encoding sRGB with 8 bits per component is extremely common, as
/// it is efficient and convenient, even if limited in accuracy and
/// gamut.
///
/// This is not meant to be a general purpose color type and is
/// intended for use with [`AlphaColor::to_rgba8`] and [`OpaqueColor::to_rgba8`].
///
/// For a pre-multiplied packed representation, see [`PremulRgba8`].
///
/// [`AlphaColor::to_rgba8`]: crate::AlphaColor::to_rgba8
/// [`OpaqueColor::to_rgba8`]: crate::OpaqueColor::to_rgba8
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[repr(C)]
Expand All @@ -26,6 +34,8 @@ pub struct Rgba8 {

impl Rgba8 {
/// Returns the color as a `[u8; 4]`.
///
/// The color values will be in the order `[r, g, b, a]`.
#[must_use]
pub const fn to_u8_array(self) -> [u8; 4] {
[self.r, self.g, self.b, self.a]
Expand All @@ -50,6 +60,13 @@ impl From<Rgba8> for AlphaColor<Srgb> {
/// Encoding sRGB with 8 bits per component is extremely common, as
/// it is efficient and convenient, even if limited in accuracy and
/// gamut.
///
/// This is not meant to be a general purpose color type and is
/// intended for use with [`PremulColor::to_rgba8`].
///
/// For a non-pre-multiplied packed representation, see [`Rgba8`].
///
/// [`PremulColor::to_rgba8`]: crate::PremulColor::to_rgba8
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[repr(C)]
Expand All @@ -66,6 +83,8 @@ pub struct PremulRgba8 {

impl PremulRgba8 {
/// Returns the color as a `[u8; 4]`.
///
/// The color values will be in the order `[r, g, b, a]`.
waywardmonkeys marked this conversation as resolved.
Show resolved Hide resolved
#[must_use]
pub const fn to_u8_array(self) -> [u8; 4] {
[self.r, self.g, self.b, self.a]
Expand Down
Loading