feat(图像处理): 优化图像重采样性能

This commit is contained in:
xiaoqidun committed 2026-10-16 00:48:56 +08:00
1 parent 2573053a82
commit 1432562c6f
1 file changed
+7 -9
+7 -9
View File
@@ -189,11 +189,8 @@ func rasterImageHorizontal(row []rasterImagePixel, src image.RGBA64Image, sample
clear(row) clear(row)
first, last := samples[0], samples[len(samples)-1] first, last := samples[0], samples[len(samples)-1]
reversed := first.first > last.first || first.first == last.first && len(first.weights) > len(last.weights) reversed := first.first > last.first || first.first == last.first && len(first.weights) > len(last.weights)
start, end := samples[0].first, samples[0].first+len(samples[0].weights) start := min(first.first, last.first)
for _, sample := range samples[1:] { end := max(first.first+len(first.weights), last.first+len(last.weights))
start = min(start, sample.first)
end = max(end, sample.first+len(sample.weights))
}
active, next := 0, 0 active, next := 0, 0
for x := start; x < end; x++ { for x := start; x < end; x++ {
for next < len(samples) { for next < len(samples) {
@@ -217,6 +214,7 @@ func rasterImageHorizontal(row []rasterImagePixel, src image.RGBA64Image, sample
active++ active++
} }
p := src.RGBA64At(x, y) p := src.RGBA64At(x, y)
r, g, b, a := float64(p.R), float64(p.G), float64(p.B), float64(p.A)
for column := active; column < next; column++ { for column := active; column < next; column++ {
index := column index := column
if reversed { if reversed {
@@ -226,10 +224,10 @@ func rasterImageHorizontal(row []rasterImagePixel, src image.RGBA64Image, sample
weight := sample.weights[x-sample.first] weight := sample.weights[x-sample.first]
if weight != 0 { if weight != 0 {
value := &row[index] value := &row[index]
value.r += float64(p.R) * weight value.r += r * weight
value.g += float64(p.G) * weight value.g += g * weight
value.b += float64(p.B) * weight value.b += b * weight
value.a += float64(p.A) * weight value.a += a * weight
} }
} }
} }