From 647f742d9c46dd96c78272564a44f51f963d8099 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Thu, 10 Sep 2026 16:41:30 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=80=A7=E8=83=BD=E6=8F=90=E5=8D=87):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87=E5=A4=84=E7=90=86?= =?UTF-8?q?=E6=80=A7=E8=83=BD=EF=BC=8C=E4=BF=9D=E6=8C=81=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ofdgo_renderer_image.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/ofdgo_renderer_image.go b/ofdgo_renderer_image.go index 93ded87..e0f6ad6 100644 --- a/ofdgo_renderer_image.go +++ b/ofdgo_renderer_image.go @@ -189,16 +189,7 @@ func imageWithClip(img image.Image, clipPath *canvas.Path, m canvas.Matrix) imag ctx.SetStrokeColor(canvas.Transparent) ctx.DrawPath(0, 0, clip) mask := rasterizer.Draw(clipCanvas, canvas.DPMM(1), canvas.DefaultColorSpace) - opaque := true - for y := 0; y < h && opaque; y++ { - for x := 0; x < w; x++ { - if mask.RGBAAt(x, y).A != 255 { - opaque = false - break - } - } - } - if opaque { + if mask.Opaque() { return img } source := imagePixelSource(img) @@ -349,16 +340,17 @@ func imageWithTransparentEdge(img image.Image) (image.Image, int) { } srcBounds := src.Bounds() out := image.NewNRGBA(image.Rect(0, 0, w+2, h+2)) + draw.Draw(out, out.Bounds().Inset(1), src, srcBounds.Min, draw.Src) for y := 0; y < h; y++ { + sy := srcBounds.Min.Y + y + offset := src.PixOffset(srcBounds.Min.X, sy) + 3 for x := 0; x < w; x++ { - sx, sy := srcBounds.Min.X+x, srcBounds.Min.Y+y - c := src.NRGBAAt(sx, sy) - if c.A == 0 { - if edge, ok := transparentEdgeColor(src, sx, sy); ok { - c = edge + if src.Pix[offset] == 0 { + if edge, ok := transparentEdgeColor(src, srcBounds.Min.X+x, sy); ok { + out.SetNRGBA(x+1, y+1, edge) } } - out.SetNRGBA(x+1, y+1, c) + offset += 4 } } for x := 0; x < w; x++ {