Skip to content

Fix alpha blending formula - #594

Merged
lhecker merged 3 commits into
mainfrom
dev/lhecker/alpha-blending
Aug 12, 2025
Merged

Fix alpha blending formula#594
lhecker merged 3 commits into
mainfrom
dev/lhecker/alpha-blending

Conversation

@lhecker

@lhecker lhecker commented Jul 31, 2025

Copy link
Copy Markdown
Member

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
Comment thread src/framebuffer.rs
0xfff0e100, // BrightCyan
0xffffffff, // BrightWhite
pub const DEFAULT_THEME: [StraightRgba; INDEXED_COLORS_COUNT] = [
StraightRgba::from_be(0x000000ff), // Black

Copy link
Copy Markdown
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
Copy Markdown
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).

Comment thread src/framebuffer.rs
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
Copy Markdown
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
Copy Markdown
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
Lou32Verbose pushed a commit to Lou32Verbose/edit that referenced this pull request Jan 11, 2026
Since `srgb_to_linear` is non-linear we can't use it for premultiplied
colors. Instead of unpremultiplying them, I changed the rest of the app
to straight alpha and introduced types to ensure we don't mess it up.
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