refactor(重构提升): 优化图像裁剪性能,保持渲染结果一致
build.yaml / build (push) Successful in 1m34s

This commit is contained in:
xiaoqidun committed 2026-09-12 02:52:21 +08:00
1 parent 6f23085742
commit d4ae3cbcae
1 file changed
+12
+12
View File
@@ -194,6 +194,18 @@ func imageWithClip(img image.Image, clipPath *canvas.Path, m canvas.Matrix) imag
}
source := imagePixelSource(img)
out := image.NewNRGBA(bounds)
if src, ok := source.(*image.NRGBA); ok {
for y := 0; y < h; y++ {
offset := src.PixOffset(bounds.Min.X, bounds.Min.Y+y)
row := out.Pix[y*out.Stride : y*out.Stride+w*4]
alpha := mask.Pix[y*mask.Stride : y*mask.Stride+w*4]
copy(row, src.Pix[offset:offset+w*4])
for x := 3; x < len(row); x += 4 {
row[x] = uint8(int(row[x]) * int(alpha[x]) / 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)