From e64575ec162f7fcd85cce2d593d58c54cd9c990b Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Fri, 16 Oct 2026 00:18:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E8=89=B2=E5=BD=A9=E7=AE=A1=E7=90=86):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E5=9B=BE=E5=83=8F=E8=89=B2=E5=BD=A9?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/base/image/tiff_profile.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/internal/base/image/tiff_profile.go b/internal/base/image/tiff_profile.go index 21f150e..47cad48 100644 --- a/internal/base/image/tiff_profile.go +++ b/internal/base/image/tiff_profile.go @@ -78,7 +78,7 @@ func applyTIFFColorProfile(ctx context.Context, source image.Image, profile *pdf return applyImageColorProfile(ctx, source, profile, false) } -// applyImageColorProfile 按源配置转换显示像素,缺省传递函数在浮点域解码 +// applyImageColorProfile 按源配置转换显示像素,精确复用连续同色结果 // 入参: ctx 取消上下文, source 源像素, profile 颜色空间, linearSRGB 是否先解码sRGB传递函数 // 返回: image.Image 十六位显示图像, error 变换或取消错误 func applyImageColorProfile(ctx context.Context, source image.Image, profile *pdfgo.ColorSpace, linearSRGB bool) (image.Image, error) { @@ -100,7 +100,10 @@ func applyImageColorProfile(ctx context.Context, source image.Image, profile *pd premultiplied := model == color.RGBAModel || model == color.RGBA64Model table := newTIFFProfileTable(source) result := image.NewNRGBA64(bounds) + var previous [4]float64 + var previousPixel color.NRGBA64 for y := bounds.Min.Y; y < bounds.Max.Y; y++ { + misses := 0 for x := bounds.Min.X; x < bounds.Max.X; x++ { if (x-bounds.Min.X)&255 == 0 { if err := ctx.Err(); err != nil { @@ -151,6 +154,17 @@ func applyImageColorProfile(ctx context.Context, source image.Image, profile *pd alpha = pixel.A values = [4]float64{float64(pixel.R) / 65535, float64(pixel.G) / 65535, float64(pixel.B) / 65535} } + if misses < 32 { + if previousPixel.A != 0 && values == previous { + pixel := previousPixel + pixel.A = alpha + result.SetNRGBA64(x, y, pixel) + misses = 0 + continue + } + previous = values + misses++ + } if linearSRGB { for i := range 3 { if values[i] <= 0.04045 { @@ -168,6 +182,11 @@ func applyImageColorProfile(ctx context.Context, source image.Image, profile *pd for i, value := range rgb { channels[i] = uint16(math.Round(max(0, min(1, value)) * 65535)) } + if misses < 32 { + previousPixel = color.NRGBA64{R: channels[0], G: channels[1], B: channels[2], A: 65535} + } else { + previousPixel.A = 0 + } if slot >= 0 { table[slot] = color.NRGBA64{R: channels[0], G: channels[1], B: channels[2], A: 65535} }