Skip to content
New issue

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

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

Already on GitHub? # to your account

Add PremulRgba8, Rgba8::to_u32 #66

Merged
merged 1 commit into from
Nov 24, 2024

Conversation

waywardmonkeys
Copy link
Collaborator

Packing a PremulColor to 8 bit channels is a common operation and is done in Vello, so we now have support for a PremulRgb8a and some to_u32 operations as well.

@waywardmonkeys waywardmonkeys added this to the 0.2.0 milestone Nov 24, 2024
@waywardmonkeys waywardmonkeys force-pushed the premulrgb8 branch 2 times, most recently from e2b36a3 to 1b9230b Compare November 24, 2024 04:47
@waywardmonkeys waywardmonkeys changed the title Add PremulRgb8a, Rgba8::to_u32 Add PremulRgba8, Rgba8::to_u32 Nov 24, 2024
Copy link
Contributor

@raphlinus raphlinus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, some suggestions inline.

@waywardmonkeys waywardmonkeys force-pushed the premulrgb8 branch 2 times, most recently from 69c004d to 6a51843 Compare November 24, 2024 05:03
Packing a `PremulColor` to 8 bit channels is a common operation
and is done in Vello, so we now have support for a `PremulRgb8a`
and some `to_u32` operations as well.
@waywardmonkeys waywardmonkeys merged commit 1c9b06f into linebender:main Nov 24, 2024
15 checks passed
@waywardmonkeys waywardmonkeys deleted the premulrgb8 branch November 24, 2024 05:14
/// Returns the color as a packed value, with `r` as the most significant byte and
/// `a` the least.
#[must_use]
pub const fn to_u32(self) -> u32 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IWBN to have the mirroring from_u32.

/// `a` the least.
#[must_use]
pub const fn to_u32(self) -> u32 {
((self.r as u32) << 24) | ((self.g as u32) << 16) | ((self.b as u32) << 8) | self.a as u32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this use from_be_bytes instead? That is also const.

waywardmonkeys added a commit to waywardmonkeys/color that referenced this pull request Nov 26, 2024
Also, add a short sanity check test.

Based on feedback from @DJMcNab in PR linebender#66.
github-merge-queue bot pushed a commit that referenced this pull request Nov 26, 2024
Also, add a short sanity check test.

Based on feedback from @DJMcNab in PR #66.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants