From 239baf9ce87a834631d6090374a949d75101260f Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Fri, 16 Oct 2026 00:34:31 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9B=BE=E5=83=8F=E5=A4=84=E7=90=86):=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=9B=BE=E5=83=8F=E9=80=8F=E6=98=8E=E5=BA=A6?= =?UTF-8?q?=E6=89=AB=E6=8F=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/base/image/image.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/base/image/image.go b/internal/base/image/image.go index 461ae47..a6de09f 100644 --- a/internal/base/image/image.go +++ b/internal/base/image/image.go @@ -722,6 +722,7 @@ func WithTransparentEdge(ctx context.Context, img image.Image) (image.Image, int hasZero, hasVisible := false, false var pixels []byte var stride, step int + wideAlpha := false switch src := source.(type) { case *image.NRGBA: pixels, stride, step = src.Pix, src.Stride, 4 @@ -729,9 +730,17 @@ func WithTransparentEdge(ctx context.Context, img image.Image) (image.Image, int pixels, stride, step = src.Pix, src.Stride, 4 case *image.Alpha: pixels, stride, step = src.Pix, src.Stride, 1 + case *image.NRGBA64: + pixels, stride, step, wideAlpha = src.Pix, src.Stride, 8, true + case *image.RGBA64: + pixels, stride, step, wideAlpha = src.Pix, src.Stride, 8, true + case *image.Alpha16: + pixels, stride, step, wideAlpha = src.Pix, src.Stride, 2, true + case *colorImage: + pixels, stride, step, wideAlpha = src.Pix, src.Stride, 8, true } if pixels != nil { - hasZero = pixels[step-1] == 0 + hasZero = pixels[step-1] == 0 && (!wideAlpha || pixels[step-2] == 0) hasVisible = !hasZero scan: for y := 0; y < h; y++ { @@ -745,7 +754,7 @@ func WithTransparentEdge(ctx context.Context, img image.Image) (image.Image, int return nil, 0, err } } - if (pixels[offset] == 0) != hasZero { + if (pixels[offset] == 0 && (!wideAlpha || pixels[offset-1] == 0)) != hasZero { hasZero, hasVisible = true, true break scan }