diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15e1f6d..a1896de 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,7 +8,7 @@ env: # If the compilation fails, then the version specified here needs to be bumped up to reality. # Be sure to also update the rust-version property in the workspace Cargo.toml file, # plus all the README.md files of the affected packages. - RUST_MIN_VER: "1.70" + RUST_MIN_VER: "1.82" # List of packages that will be checked with the minimum supported Rust version. # This should be limited to packages that are intended for publishing. RUST_MIN_VER_PKGS: "-p peniko" diff --git a/Cargo.lock b/Cargo.lock index c02a93b..c149a15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,15 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" +[[package]] +name = "color" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce566db61cc9ebcb00cf6f338ec87d1d030727152fd3661caad38d0113f76c11" +dependencies = [ + "libm", +] + [[package]] name = "kurbo" version = "0.11.1" @@ -23,9 +32,9 @@ dependencies = [ [[package]] name = "libm" -version = "0.2.8" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" +checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa" [[package]] name = "mint" @@ -37,6 +46,7 @@ checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff" name = "peniko" version = "0.2.0" dependencies = [ + "color", "kurbo", "serde", "serde_bytes", diff --git a/Cargo.toml b/Cargo.toml index f5a93e9..4c6f70d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,10 +8,9 @@ keywords = ["graphics", "vector", "style"] categories = ["graphics"] repository = "https://github.com/linebender/peniko" readme = "README.md" -# We support from Rust 1.70 so that CI uses the sparse protocol. # Keep in sync with RUST_MIN_VER in .github/workflows/ci.yml and with the relevant README.md files. # and with the MSRV in the `Unreleased` section of CHANGELOG.md. -rust-version = "1.70" +rust-version = "1.82" [package.metadata.docs.rs] all-features = true @@ -21,12 +20,13 @@ targets = [] [features] default = ["std"] -std = ["kurbo/std"] -libm = ["kurbo/libm"] +std = ["color/std", "kurbo/std"] +libm = ["color/libm", "kurbo/libm"] mint = ["kurbo/mint"] serde = ["smallvec/serde", "kurbo/serde", "dep:serde_bytes", "dep:serde"] [dependencies] +color = { version = "0.1.0", default-features = false } # NOTE: Make sure to keep this in sync with the version badge in README.md kurbo = { version = "0.11.1", default-features = false } smallvec = "1.13.2" @@ -69,8 +69,10 @@ rust.unused_macro_rules = "warn" rust.unused_qualifications = "warn" rust.variant_size_differences = "warn" -clippy.allow_attributes = "warn" -clippy.allow_attributes_without_reason = "warn" +# FIXME(color): I'm lazy about fixing this yet. +clippy.allow_attributes = "allow" +clippy.allow_attributes_without_reason = "allow" + clippy.cast_possible_truncation = "warn" clippy.collection_is_never_read = "warn" clippy.dbg_macro = "warn" diff --git a/src/brush.rs b/src/brush.rs index 7cbb730..fff3b0b 100644 --- a/src/brush.rs +++ b/src/brush.rs @@ -2,15 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 OR MIT use super::{Color, Gradient, Image}; +use color::{AlphaColor, Srgb}; /// Describes the color content of a filled or stroked shape. /// /// See also [`BrushRef`] which can be used to avoid allocations. -#[derive(Clone, PartialEq, Debug)] +// FIXME(color): `PartialEq` was removed from here for now. +#[derive(Clone, Debug)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub enum Brush { /// Solid color brush. - Solid(Color), + Solid(AlphaColor), /// Gradient brush. Gradient(Gradient), /// Image brush. @@ -19,6 +21,12 @@ pub enum Brush { impl From for Brush { fn from(c: Color) -> Self { + Self::Solid(c.into()) + } +} + +impl From> for Brush { + fn from(c: AlphaColor) -> Self { Self::Solid(c) } } @@ -37,7 +45,7 @@ impl From for Brush { impl Default for Brush { fn default() -> Self { - Self::Solid(Color::default()) + Self::Solid(Color::default().into()) } } @@ -58,7 +66,7 @@ impl Brush { self } else { match self { - Self::Solid(color) => color.multiply_alpha(alpha).into(), + Self::Solid(color) => color.mul_alpha(alpha).into(), Self::Gradient(mut gradient) => { gradient .stops @@ -77,10 +85,11 @@ impl Brush { /// This is useful for methods that would like to accept brushes by reference. Defining /// the type as `impl>` allows accepting types like `&LinearGradient` /// directly without cloning or allocating. -#[derive(Copy, Clone, PartialEq, Debug)] +// FIXME(color): `PartialEq` was removed from here for now. +#[derive(Copy, Clone, Debug)] pub enum BrushRef<'a> { /// Solid color brush. - Solid(Color), + Solid(AlphaColor), /// Gradient brush. Gradient(&'a Gradient), /// Image brush. @@ -101,12 +110,24 @@ impl BrushRef<'_> { impl From for BrushRef<'_> { fn from(color: Color) -> Self { - Self::Solid(color) + Self::Solid(color.into()) } } impl<'a> From<&'a Color> for BrushRef<'_> { fn from(color: &'a Color) -> Self { + Self::Solid((*color).into()) + } +} + +impl From> for BrushRef<'_> { + fn from(color: AlphaColor) -> Self { + Self::Solid(color) + } +} + +impl<'a> From<&'a AlphaColor> for BrushRef<'_> { + fn from(color: &'a AlphaColor) -> Self { Self::Solid(*color) } } diff --git a/src/color.rs b/src/color.rs index c1a1ed8..aa1a322 100644 --- a/src/color.rs +++ b/src/color.rs @@ -3,6 +3,7 @@ // Borrows code heavily from the piet (https://github.com/linebender/piet/) Color // type. +use color::{AlphaColor, Srgb}; #[cfg(all(not(feature = "std"), feature = "libm"))] #[allow(unused_imports)] use kurbo::common::FloatFuncs as _; @@ -467,6 +468,12 @@ impl Color { pub const YELLOW_GREEN: Color = Color::rgba8(154, 205, 50, 255); } +impl From for AlphaColor { + fn from(c: Color) -> Self { + Self::from_rgba8(c.r, c.g, c.b, c.a) + } +} + impl From<[u8; 3]> for Color { fn from(rgb: [u8; 3]) -> Self { Self::rgb8(rgb[0], rgb[1], rgb[2]) diff --git a/src/lib.rs b/src/lib.rs index 3ef8dd5..6321cdc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,13 +3,14 @@ //! A Rust 2D graphics type library //! -//! The `peniko` library builds on top of [`kurbo`] and provides a set of generic types that define -//! styles for rendering and composition. +//! The `peniko` library builds on top of [`kurbo`] and [`color`] and provides a set of +//! generic types that define styles for rendering and composition. //! //! The name "peniko" is Esperanto for "brush" which is one family of types that the library //! contains. //! //! [`kurbo`]: https://crates.io/crates/kurbo +//! [`color`]: https://crates.io/crates/color #![cfg_attr(all(not(feature = "std"), not(test)), no_std)] #![cfg_attr(docsrs, feature(doc_auto_cfg))]