-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix translucent image colors by correcting alpha premultiplication in image decoding and GPU texture transfers #4517
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -148,8 +148,8 @@ impl Image<Color> { | |
| .chunks_exact(4) | ||
| .map(|v| { | ||
| // `Image<Color>` pixels are stored linear-light with premultiplied alpha | ||
| let srgba = SRGBA8::new(v[0], v[1], v[2], v[3]); | ||
| Color::from(srgba).apply_opacity(v[3] as f32 / 255.) | ||
| let color = Color::from(SRGBA8::new(v[0], v[1], v[2], v[3])); | ||
| color.map_rgb(|channel| channel * color.a()) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: This premultiplication fix changes stored alpha semantics (no longer alpha-squared) and is the kind of subtle color-space regression that can silently reappear. Add a round-trip test that runs from_image_data on a known semi-transparent RGBA pixel and asserts the stored Color has alpha == v[3]/255 with premultiplied linear RGB (e.g. white at alpha 128 → rgb ≈ 0.502, alpha ≈ 0.502), and that to_png()/to_flat_u8 recovers the original u8 values. Prompt for AI agents |
||
| }) | ||
| .collect(); | ||
| Image { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: This change duplicates the SRGBA8-to-premultiplied-
Colorconversion already used by image-data decoding and GPU readback. Extract the conversion into a shared helper and call it from all paths so future color or alpha fixes cannot leave these implementations inconsistent.Prompt for AI agents