Skip to content

fix(render): respect color alpha channel in render_to_png#104

Open
mikhaelmartin wants to merge 2 commits into
erweixin:mainfrom
mikhaelmartin:fix/render-alpha-channel
Open

fix(render): respect color alpha channel in render_to_png#104
mikhaelmartin wants to merge 2 commits into
erweixin:mainfrom
mikhaelmartin:fix/render-alpha-channel

Conversation

@mikhaelmartin

@mikhaelmartin mikhaelmartin commented Jun 4, 2026

Copy link
Copy Markdown

Closes #103

render_to_png discards the alpha channel from Color values in all four paint paths. The pipeline correctly flows Color::a through LayoutOptionsDisplayList → renderer, but each paint operation hardcodes alpha to 255:

Function Line
render_glyph_with_font 569
render_line 705
render_rect 741
render_path_segment 861

This replaces the hardcoded 255 with (color.a * 255.0) as u8, matching how the RGB components already use (color.r * 255.0) as u8 etc.

@techwizrd

Copy link
Copy Markdown
Contributor

This fixes the hardcoded alpha in the paint paths, but I think PNG encoding still needs attention. tiny-skia::Pixmap stores premultiplied RGBA, and our custom encode_png() writes pixmap.data() directly. With non-opaque foregrounds, that can produce premultiplied RGB in the PNG. Could we use pixmap.encode_png() or demultiply before writing, plus add a foreground alpha regression test?

I'm happy to add a fix if you'd like.

@mikhaelmartin

Copy link
Copy Markdown
Author

@techwizrd Yes, please! I'm pretty new to this, so feel free to push the fix directly to this branch. Thank you so much for the help!

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.

render_to_png ignores alpha channel

2 participants