]> Cypherpunks repositories - gostls13.git/commit
image/draw: have draw.Src preserve NRGBA colors
authorNigel Tao <nigeltao@golang.org>
Thu, 31 Mar 2022 03:16:49 +0000 (14:16 +1100)
committerNigel Tao <nigeltao@golang.org>
Thu, 7 Apr 2022 10:41:34 +0000 (10:41 +0000)
commit3a0cda43a49793429bc38bdcb1d2112179b02fe1
treeeddf2a0ecd79ca176c88540980ce7ab76137b3f7
parentd3362fc1242f20c40f6d3986ddf4398019c8ea26
image/draw: have draw.Src preserve NRGBA colors

This reverts a behavior change introduced in Go 1.18 (commit 9f69a443;
CL 340049). In Go 1.17 and earlier, draw.Draw(etc, draw.Src) with
image.NRGBA dst and src images would pass through a (heap allocated)
color.Color interface value holding a color.NRGBA concrete value.
Threading that color.NRGBA value all the way through preserves
non-premultiplied alpha transparency information (distinguishing e.g.
transparent blue from transparent red).

CL 340049 optimized out that heap allocation (per pixel), calling new
SetRGBA64At and RGBA64At methods instead. However, these methods (like
the existing image/color Color.RGBA method) work in premultiplied alpha,
so any distinction between transparent colors is lost.

This commit re-introduces the preservation of distinct transparencies,
when dst and src are both *image.NRGBA (or both *image.NRGBA64) and the
op is draw.Src.

Fixes #51893

Change-Id: Id9c64bfeeaecc458586f169f50b99d6c8aa52a7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/396795
Trust: Nigel Tao <nigeltao@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
doc/go1.19.html
src/image/draw/draw.go
src/image/draw/draw_test.go