Skip to content

Commit

Permalink
Speedup ip parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mjrider committed Oct 31, 2019
1 parent d0c4c1b commit d9f040c
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,32 @@ func shuffle(a []*net.IPAddr) {
// addresses to ping to draw the image to the board.
func makeAddrs(img image.Image, dstNet string, xOff, yOff int) []*net.IPAddr {
var addrs []*net.IPAddr

tip := net.ParseIP(fmt.Sprintf("%s::", dstNet))
bounds := img.Bounds()
for y := 0; y < bounds.Dy(); y++ {
for x := 0; x < bounds.Dx(); x++ {
r, g, b, a := img.At(bounds.Min.X+x, bounds.Min.Y+y).RGBA()
a = a >> 8
if a > 0 {
// Each channel is 16-bit, just shift down for 8-bit needed
// for the display
ip := fmt.Sprintf("%s:%x:%x:%02x%02x:%02x%02x", dstNet, x+xOff, y+yOff, b>>8, g>>8, r>>8, a)
//fmt.Println(ip)

ip := make(net.IP, len(tip))
copy(ip, tip)

// x
ip[8] = byte((x + xOff) >> 8)
ip[9] = byte(x + xOff)
// y
ip[10] = byte((y + yOff) >> 8)
ip[11] = byte(y + yOff)
// rgba
ip[12] = byte(b >> 8)
ip[13] = byte(g >> 8)
ip[14] = byte(r >> 8)
ip[15] = uint8(a)

addrs = append(addrs, &net.IPAddr{
IP: net.ParseIP(ip),
IP: ip,
})
}
}
Expand Down

0 comments on commit d9f040c

Please sign in to comment.