feat(合成处理): 加速蒙版与图像合成
build.yaml / build (push) Successful in 50s

This commit is contained in:
xiaoqidun committed 2026-10-15 14:51:28 +08:00
1 parent 75b6943e10
commit 3d54b15b11
2 files changed
+26 -4

No files matched your search

+19
View File
@@ -658,12 +658,27 @@ func (c *pdfCompositor) mask(mask *pdfgo.SoftMask, inherited *pdfgo.ColorSpace)
c.scratch.masks.release(result)
}
}()
values := make(map[[4]float64]float64)
var previous [4]float64
var opacity float64
for i, pixel := range pixels {
if i%pdfCompositeTileSize == 0 {
if err := c.importer.ctx.Err(); err != nil {
return nil, err
}
}
key := [4]float64{pixel.Alpha}
if mask.Subtype == "Luminosity" {
key = pixel.Values
}
if i != 0 && key == previous {
result[i] = opacity
continue
}
if cached, ok := values[key]; ok {
previous, opacity, result[i] = key, cached, cached
continue
}
v := pixel.Alpha
if mask.Subtype == "Luminosity" {
v, err = space.Luminosity(pixel.Values[:space.Components()], "RelativeColorimetric")
@@ -675,6 +690,10 @@ func (c *pdfCompositor) mask(mask *pdfgo.SoftMask, inherited *pdfgo.ColorSpace)
if err != nil {
return nil, err
}
previous, opacity = key, result[i]
if len(values) < 2*pdfCompositeTileSize {
values[key] = opacity
}
}
complete = true
c.masks[mask] = result