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

Image alpha channel is now an f32 #65

Merged
merged 1 commit into from
Nov 27, 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 .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=pass
waywardmonkeys marked this conversation as resolved.
Show resolved Hide resolved

- 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
}
}