Skip to content

Canvas: tint an image, or composite in a layer of its own #1111

Closed

Description

@houko

Context

Found while building sprites for nsgo-dev/game#4; part of #1047. A Drawing has composite modes (internal/driver/canvas.go:249-274) but no transparency layer or offscreen target, so a multiply tint mixes with everything already drawn under the image: an image cannot be tinted on its own. #565 covers rendering a whole Drawing to pixels, not a layer within one.

Proposal

Either a per-draw tint on DrawImage* (multiply by a color, as Core Graphics' clip-to-mask plus fill, Direct2D's tint effect, Cairo's mask, Android's ColorFilter and the web's offscreen canvas do), or Drawing.BeginLayer(alpha)/EndLayer(), as CanvasKit's saveLayer and Core Graphics' transparency layers. The first is enough for sprites; the second also gives group opacity.

Acceptance

  • A tinted image draws the same on every target, checked by pixel comparison, without changing what was drawn under it.
  • canvas.md and the public docs describe it.

Activity

  1. added
    enhancement
    on Nov 21, 2026
  2. self-assigned this
    on Nov 21, 2026
  3. houko commented on Nov 22, 2026

    @houko
    CollaboratorAuthor

    Landed in #1200: DrawTintedImage, DrawTintedImageIn and DrawTintedImageFrom (drawTintedImage in TSX) multiply an image's sRGB and alpha by a color before compositing, without touching what is under it. Apple, Windows, Linux, Android and the web support it, the capture test TestCanvasImageTint runs in CI on those targets, and canvas.md and the public docs describe it.

    Still open: HarmonyOS draws tinted images untinted. The ArkTS host needs to multiply the pixels and the committed host needs a rebuild (roadmap row "Canvas image tint"). Device verification can follow after that.

  4. houko commented on Nov 23, 2026

    @houko
    CollaboratorAuthor

    HarmonyOS tinting landed in #2016 (the #2003 patch plus the rebuilt committed host), so DrawTintedImage, DrawTintedImageIn and DrawTintedImageFrom now tint on every target: #1200 covered Apple, Windows, Linux, Android and the web, with TestCanvasImageTint in CI.

    Remaining, device-only: run the shared tint pixel test (its encoded case) on a HarmonyOS emulator or device (roadmap row "Canvas image tint").

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreenhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions