Skip to content

Conversation

@7coil
Copy link

@7coil 7coil commented Dec 10, 2025

Hello world!
When running edit on my Apple iMac G3, the colours are all weird due to it being a big-endian system

WindowsTerminal_8f83ifCiJY

This pull request ensures that colours are parsed correctly on any system by storing the RGBA components as separate u8s

WindowsTerminal_ifFVcOKWfZ

The unit test should also work in miri - the existing oklab::tests::test_blending should fail without this PR.

# on an x86_64 host
cargo miri test --target s390x-unknown-linux-gnu oklab

Yes this does mean one of you will may need to install Linux on a real PowerPC machine to test this PR 😸

@7coil
Copy link
Author

7coil commented Dec 10, 2025

@microsoft-github-policy-service agree

#[derive(Default, Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub struct StraightRgba(u32);
pub struct StraightRgba([u8; 4]);
Copy link
Member

Choose a reason for hiding this comment

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

I'm a bit sceptic of the performance implications here. The previous structure was essentially a u32 (including u32 alignment), which meant that "memsets" of these got nicely optimized. Compilers often have a hard time to intelligently translate equivalent lower-aligned types like this back into higher aligned ones.

I'd either like to see this investigated/benchmarked, or we could consider changing the existing methods to be endian-specific. E.g. to special-case the red/green/blue/to_bytes methods. I don't mind the change to returning u8 btw. That usually gets optimized away quite nicely anyway.

Thanks for testing this btw!

Copy link
Author

@7coil 7coil Dec 10, 2025

Choose a reason for hiding this comment

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

I'm not a rust developer (mainly typescript and other interpreted languages), so I'll defer any suggestions to anyone else that can help.

If anyone does have a better solution, I'm more than happy to try and run it on a real PowerPC machine (albeit slowly at 600MHz)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants