Skip to content

Commit

Permalink
bug(writer): pre-multiply RGB by A (#111)
Browse files Browse the repository at this point in the history
color.RGBA is pre-multiplied by alpha. When A is 0 the only valid value for R, G and B is 0.

When drawing a logo with an alpha channel the blending operation may overflow when R, G, B have invalid values (i.e larger than A).
  • Loading branch information
gustafsson authored Jun 9, 2024
1 parent 68ae684 commit b5ed638
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions writer/standard/image_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ func (oo *outputImageOptions) translateToRGBA(v qrcode.QRValue) (rgba color.RGBA

if oo.bgTransparent {
(&oo.bgColor).A = 0x00
// color.RGBA is pre-multiplied by alpha, so set RGB to 0 when fully transparent.
(&oo.bgColor).R = 0x00
(&oo.bgColor).G = 0x00
(&oo.bgColor).B = 0x00
}
rgba = oo.bgColor

Expand Down

0 comments on commit b5ed638

Please sign in to comment.