feat(内存占用): 优化图片透明度处理性能,保持渲染结果一致
build.yaml / build (push) Successful in 39s

This commit is contained in:
xiaoqidun committed 2026-09-12 03:57:59 +08:00
1 parent 9a618d6eae
commit c5abb3667a
1 file changed
+11
+11
View File
@@ -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)