speed up parsePixels()
This commit is contained in:
parent
d86e769e9a
commit
15b9cf19da
|
@ -9,7 +9,6 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/textproto"
|
"net/textproto"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Flut asynchronously sends the given image to pixelflut server at `address`
|
// Flut asynchronously sends the given image to pixelflut server at `address`
|
||||||
|
@ -59,13 +58,19 @@ func parsePixels(target *image.NRGBA, conn net.Conn) {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// @speed: Split is ridiculously slow due to mallocs!
|
// parse response ("PX <x> <y> <col>")
|
||||||
// chunk last 6 chars off -> color, remove first 3 chars, find space in
|
// @incomplete errorhandling
|
||||||
// remainder, then Atoi() xy?
|
colorStart := len(res) - 6
|
||||||
res2 := strings.Split(res, " ")
|
xy := res[3:colorStart - 1]
|
||||||
x, _ := strconv.Atoi(res2[1])
|
yStart := 0
|
||||||
y, _ := strconv.Atoi(res2[2])
|
for yStart = len(xy) - 1; yStart >= 0; yStart-- {
|
||||||
col, _ := hex.DecodeString(res2[3])
|
if xy[yStart] == ' ' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
x, _ := strconv.Atoi(xy[:yStart])
|
||||||
|
y, _ := strconv.Atoi(xy[yStart+1:])
|
||||||
|
col, _ := hex.DecodeString(res[colorStart:])
|
||||||
|
|
||||||
target.Set(x, y, color.NRGBA{
|
target.Set(x, y, color.NRGBA{
|
||||||
uint8(col[0]),
|
uint8(col[0]),
|
||||||
|
|
Loading…
Reference in New Issue