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

Fix test failures on big endian targets #69

Merged
merged 2 commits into from
Jan 29, 2023
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
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,6 @@ jobs:

- name: Run tests with Neon
run: cross test --target aarch64-unknown-linux-gnu

- name: Rust tests on PowerPC (big endian)
run: cross test --target powerpc-unknown-linux-gnu
18 changes: 9 additions & 9 deletions src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ impl ColorU8 {

/// Returns color's red component.
pub const fn red(self) -> u8 {
((self.0 >> 0) & 0xFF) as u8
self.0.to_ne_bytes()[0]
}

/// Returns color's green component.
pub const fn green(self) -> u8 {
((self.0 >> 8) & 0xFF) as u8
self.0.to_ne_bytes()[1]
}

/// Returns color's blue component.
pub const fn blue(self) -> u8 {
((self.0 >> 16) & 0xFF) as u8
self.0.to_ne_bytes()[2]
}

/// Returns color's alpha component.
pub const fn alpha(self) -> u8 {
((self.0 >> 24) & 0xFF) as u8
self.0.to_ne_bytes()[3]
}

/// Check that color is opaque.
Expand Down Expand Up @@ -128,26 +128,26 @@ impl PremultipliedColorU8 {
///
/// The value is <= alpha.
pub const fn red(self) -> u8 {
((self.0 >> 0) & 0xFF) as u8
self.0.to_ne_bytes()[0]
}

/// Returns color's green component.
///
/// The value is <= alpha.
pub const fn green(self) -> u8 {
((self.0 >> 8) & 0xFF) as u8
self.0.to_ne_bytes()[1]
}

/// Returns color's blue component.
///
/// The value is <= alpha.
pub const fn blue(self) -> u8 {
((self.0 >> 16) & 0xFF) as u8
self.0.to_ne_bytes()[2]
}

/// Returns color's alpha component.
pub const fn alpha(self) -> u8 {
((self.0 >> 24) & 0xFF) as u8
self.0.to_ne_bytes()[3]
}

/// Check that color is opaque.
Expand Down Expand Up @@ -427,7 +427,7 @@ pub fn premultiply_u8(c: u8, a: u8) -> u8 {
}

const fn pack_rgba(r: u8, g: u8, b: u8, a: u8) -> u32 {
((a as u32) << 24) | ((b as u32) << 16) | ((g as u32) << 8) | ((r as u32) << 0)
u32::from_ne_bytes([r, g, b, a])
}

fn color_f32_to_u8(
Expand Down