MCPcopy
hub / github.com/fogleman/primitive / computeColor

Function computeColor

primitive/core.go:8–34  ·  view source on GitHub ↗
(target, current *image.RGBA, lines []Scanline, alpha int)

Source from the content-addressed store, hash-verified

6)
7
8func computeColor(target, current *image.RGBA, lines []Scanline, alpha int) Color {
9 var rsum, gsum, bsum, count int64
10 a := 0x101 * 255 / alpha
11 for _, line := range lines {
12 i := target.PixOffset(line.X1, line.Y)
13 for x := line.X1; x <= line.X2; x++ {
14 tr := int(target.Pix[i])
15 tg := int(target.Pix[i+1])
16 tb := int(target.Pix[i+2])
17 cr := int(current.Pix[i])
18 cg := int(current.Pix[i+1])
19 cb := int(current.Pix[i+2])
20 i += 4
21 rsum += int64((tr-cr)*a + cr*0x101)
22 gsum += int64((tg-cg)*a + cg*0x101)
23 bsum += int64((tb-cb)*a + cb*0x101)
24 count++
25 }
26 }
27 if count == 0 {
28 return Color{}
29 }
30 r := clampInt(int(rsum/count)>>8, 0, 255)
31 g := clampInt(int(gsum/count)>>8, 0, 255)
32 b := clampInt(int(bsum/count)>>8, 0, 255)
33 return Color{r, g, b, alpha}
34}
35
36func copyLines(dst, src *image.RGBA, lines []Scanline) {
37 for _, line := range lines {

Callers 2

AddMethod · 0.85
EnergyMethod · 0.85

Calls 1

clampIntFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…