From 9bb04af37630201c1a168dd0019da1d65beb0b2a Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Wed, 27 Nov 2024 12:42:51 +0700 Subject: [PATCH] `Image` alpha channel is now an `f32` In the next release of Peniko, our alpha channels will all be `f32` as we move to the new color code. Also, new version of `cargo-nextest` fails when there are no tests and this crate has no tests, so just warn for now. --- .github/workflows/ci.yml | 2 +- CHANGELOG.md | 5 +++++ src/image.rs | 12 +++--------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15e1f6d..ca79340 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -174,7 +174,7 @@ jobs: save-if: ${{ github.event_name != 'merge_group' }} - name: cargo nextest - run: cargo nextest run --workspace --locked --all-features --no-fail-fast + run: cargo nextest run --workspace --locked --all-features --no-fail-fast --no-tests=warn - name: cargo test --doc run: cargo test --doc --workspace --locked --all-features --no-fail-fast diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b01c92..a155570 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,10 @@ You can find its changes [documented below](#020-2024-09-19). This release has an [MSRV] of 1.70. +### Changed + +- `Image` now stores the alpha as an `f32` ([#65][] by [@waywardmonkeys][]) + ## [0.2.0][] (2024-09-19) This release has an [MSRV] of 1.70. @@ -50,6 +54,7 @@ This release has an [MSRV] of 1.70. [#46]: https://github.com/linebender/peniko/pull/46 [#47]: https://github.com/linebender/peniko/pull/47 [#52]: https://github.com/linebender/peniko/pull/52 +[#65]: https://github.com/linebender/peniko/pull/65 [@DJMcNab]: https://github.com/DJMcNab [@ratmice]: https://github.com/ratmice diff --git a/src/image.rs b/src/image.rs index 735f97d..724cb22 100644 --- a/src/image.rs +++ b/src/image.rs @@ -1,10 +1,6 @@ // Copyright 2022 the Peniko Authors // SPDX-License-Identifier: Apache-2.0 OR MIT -#[cfg(all(not(feature = "std"), feature = "libm"))] -#[allow(unused_imports)] -use kurbo::common::FloatFuncs as _; - use super::{Blob, Extend}; /// Defines the pixel format of an [image](Image). @@ -46,7 +42,7 @@ pub struct Image { /// Extend mode. pub extend: Extend, /// An additional alpha multiplier to use with the image. - pub alpha: u8, + pub alpha: f32, } impl Image { @@ -60,7 +56,7 @@ impl Image { height, extend: Extend::Pad, // Opaque - alpha: u8::MAX, + alpha: 1., } } @@ -73,8 +69,6 @@ impl Image { /// Returns the image with the alpha multiplier multiplied again by `alpha`. /// The behaviour of this transformation is undefined if `alpha` is negative. - /// - /// If any resulting alphas would overflow, these currently saturate (to opaque). #[must_use] #[track_caller] pub fn multiply_alpha(mut self, alpha: f32) -> Self { @@ -82,7 +76,7 @@ impl Image { alpha.is_finite() && alpha >= 0.0, "A non-finite or negative alpha ({alpha}) is meaningless." ); - self.alpha = ((self.alpha as f32) * alpha).round() as u8; + self.alpha *= alpha; self } }