Skip to content

Commit

Permalink
Image alpha channel is now an f32
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
waywardmonkeys committed Nov 27, 2024
1 parent d825bdf commit 9bb04af
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
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](#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.
Expand Down Expand Up @@ -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
Expand Down
12 changes: 3 additions & 9 deletions src/image.rs
Original file line number Diff line number Diff line change
@@ -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).
Expand Down Expand Up @@ -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 {
Expand All @@ -60,7 +56,7 @@ impl Image {
height,
extend: Extend::Pad,
// Opaque
alpha: u8::MAX,
alpha: 1.,
}
}

Expand All @@ -73,16 +69,14 @@ 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 {
debug_assert!(
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
}
}

0 comments on commit 9bb04af

Please sign in to comment.