Skip to content

Fix alpha blending formula #594

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

Merged
merged 3 commits into from
Aug 12, 2025
Merged

Fix alpha blending formula #594

merged 3 commits into from
Aug 12, 2025

Conversation

lhecker
Copy link
Member

@lhecker lhecker commented Jul 31, 2025

Since srgb_to_linear is non-linear we can't use it for premultiplied colors.
Instead of unpremultiplying them, I simply changed the rest of the app to use
straight alpha and introduced types to ensure we don't mess it up.

@lhecker lhecker requested a review from DHowett August 4, 2025 21:25
0xfff0e100, // BrightCyan
0xffffffff, // BrightWhite
pub const DEFAULT_THEME: [StraightRgba; INDEXED_COLORS_COUNT] = [
StraightRgba::from_be(0x000000ff), // Black
Copy link
Member

Choose a reason for hiding this comment

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

why from_be sometimes and from_le other times?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just whatever I felt like in any given situation. from_be is helpful because it allows you to copy/paste the literal as a CSS color code (which is also in big endian).

@@ -118,7 +118,8 @@ impl Framebuffer {
DEFAULT_THEME[IndexedColor::Black as usize],
DEFAULT_THEME[IndexedColor::BrightWhite as usize],
],
contrast_colors: [const { Cell::new((0, 0)) }; CACHE_TABLE_SIZE],
contrast_colors: [const { Cell::new((StraightRgba::zero(), StraightRgba::zero())) };
Copy link
Member

Choose a reason for hiding this comment

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

would this be helped by deriving default or implementing it to return zero

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately no, because traits cannot be const and the Rust maintainers have been bickering working on an implementation for const traits since at least 2020. 🥲

@lhecker lhecker merged commit 695d88e into main Aug 12, 2025
3 checks passed
@lhecker lhecker deleted the dev/lhecker/alpha-blending branch August 12, 2025 21:27
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