Skip to content

Add premultiplied option for raw pixel exports - #292

Open
ttarczewski wants to merge 1 commit into
samizdatco:mainfrom
ttarczewski:premultiplied-alpha-export
Open

Add premultiplied option for raw pixel exports#292
ttarczewski wants to merge 1 commit into
samizdatco:mainfrom
ttarczewski:premultiplied-alpha-export

Conversation

@ttarczewski

Copy link
Copy Markdown

Currently getImageData, toBuffer('raw'), and toBufferSync('raw') all return RGBA pixel data in unpremultiplied (straight alpha) form, consistent with the HTML Canvas specification. Although the underlying canvas bitmap is typically stored in premultiplied form, every read-back path performs automatic unpremultiplication, and there is no API for retrieving the premultiplied pixel data directly.

Why this matters

  • Premultiplied alpha is commonly preferred for GPU upload paths because it matches the representation used by GPU blending pipelines. Applications therefore typically need to re-premultiply the data during upload. This introduces unnecessary overhead when the original pixel data was already premultiplied before skia-canvas unpremultiplied it during read-back.
  • The premultiplied-unpremultiplied-premultiplied round-trip is lossy at low alpha values, since unpremultiplication quantizes color channels.

Implementation

Add a new boolean option, premultiplied (defaulting to false). When enabled, the ImageInfo is constructed with AlphaType::Premul instead of AlphaType::Unpremul, bypassing unpremultiplication and returning the underlying premultiplied pixel data directly.

@Rush Rush mentioned this pull request Sep 4, 2026
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.

1 participant