diff --git a/ofdgo_renderer_image.go b/ofdgo_renderer_image.go index 8a89827..aaf4763 100644 --- a/ofdgo_renderer_image.go +++ b/ofdgo_renderer_image.go @@ -289,6 +289,17 @@ func imageWithAlpha(img image.Image, alpha *int) image.Image { bounds := img.Bounds() out := image.NewNRGBA(bounds) source := imagePixelSource(img) + if src, ok := source.(*image.NRGBA); ok { + for y := 0; y < bounds.Dy(); y++ { + offset := src.PixOffset(bounds.Min.X, bounds.Min.Y+y) + row := out.Pix[y*out.Stride : (y+1)*out.Stride] + copy(row, src.Pix[offset:offset+len(row)]) + for x := 3; x < len(row); x += 4 { + row[x] = uint8(int(row[x]) * a / 255) + } + } + return out + } for y := bounds.Min.Y; y < bounds.Max.Y; y++ { for x := bounds.Min.X; x < bounds.Max.X; x++ { c := imageNRGBAAt(source, x, y)