Skip to content

Commit

Permalink
Prevent recalculating the same thing over and over again
Browse files Browse the repository at this point in the history
  • Loading branch information
mweibel committed Nov 26, 2017
1 parent 69506c9 commit 61cdb90
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions primitive/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,22 @@ func drawLines(im *image.RGBA, c Color, lines []Scanline) {
sr, sg, sb, sa := c.NRGBA().RGBA()
for _, line := range lines {
ma := line.Alpha
a := (m - sa*ma/m) * 0x101
sra := sr * ma
sga := sg * ma
sba := sb * ma
saa := sa * ma

a := (m - saa/m) * 0x101
i := im.PixOffset(line.X1, line.Y)
for x := line.X1; x <= line.X2; x++ {
dr := uint32(im.Pix[i+0])
dg := uint32(im.Pix[i+1])
db := uint32(im.Pix[i+2])
da := uint32(im.Pix[i+3])
im.Pix[i+0] = uint8((dr*a + sr*ma) / m >> 8)
im.Pix[i+1] = uint8((dg*a + sg*ma) / m >> 8)
im.Pix[i+2] = uint8((db*a + sb*ma) / m >> 8)
im.Pix[i+3] = uint8((da*a + sa*ma) / m >> 8)
im.Pix[i+0] = uint8((dr*a + sra) / m >> 8)
im.Pix[i+1] = uint8((dg*a + sga) / m >> 8)
im.Pix[i+2] = uint8((db*a + sba) / m >> 8)
im.Pix[i+3] = uint8((da*a + saa) / m >> 8)
i += 4
}
}
Expand Down

0 comments on commit 61cdb90

Please sign in to comment.