Skip to content

Commit

Permalink
Added support for all colors.
Browse files Browse the repository at this point in the history
  • Loading branch information
xStrom committed Apr 16, 2017
1 parent 6198494 commit 52e3ff8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
43 changes: 30 additions & 13 deletions art/art.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,31 @@ const (
DarkPurple
)

var colorToRGBA = map[int]color.RGBA64{
White: color.RGBA64{65535, 65535, 65535, 65535},
LightGray: color.RGBA64{58596, 58596, 58596, 65535},
Gray: color.RGBA64{34952, 34952, 34952, 65535},
Black: color.RGBA64{8738, 8738, 8738, 65535},
Pink: color.RGBA64{65535, 42919, 53713, 65535},
Red: color.RGBA64{58853, 0, 2313, 65535},
Orange: color.RGBA64{58853, 38293, 0, 65535},
Brown: color.RGBA64{41120, 27242, 16962, 65535},
Yellow: color.RGBA64{58853, 55769, 0, 65535},
LightGreen: color.RGBA64{38036, 57568, 17476, 65535},
Green: color.RGBA64{514, 48830, 257, 65535},
Cyan: color.RGBA64{0, 54227, 56797, 65535},
MediumBlue: color.RGBA64{0, 33667, 51143, 65535},
DarkBlue: color.RGBA64{0, 0, 60138, 65535},
LightPurple: color.RGBA64{53199, 28270, 58596, 65535},
DarkPurple: color.RGBA64{33410, 0, 32896, 65535},
}

type Pixel struct {
X int
Y int
C int
}

var blue = color.RGBA64{0, 0, 60138, 65535}
var black = color.RGBA64{8738, 8738, 8738, 65535}
var white = color.RGBA64{65535, 65535, 65535, 65535}

type Image struct {
lock sync.RWMutex
version int
Expand Down Expand Up @@ -94,15 +109,17 @@ func (i *Image) ParseKeyframe(version int, data []byte) error {
for y := minY; y < maxY; y++ {
coords := x | (y << 16)
c := img.At(x, y)

if sameColor(c, blue) {
colors[coords] = DarkBlue
} else if sameColor(c, black) {
colors[coords] = Black
} else if sameColor(c, white) {
colors[coords] = White
} else {
colors[coords] = -1 // TODO: Implement all colors
color := -1
for cc, rgba := range colorToRGBA {
if sameColor(c, rgba) {
color = cc
break
}
}
colors[coords] = color
if color == -1 {
r, g, b, a := c.RGBA()
log.Infof("Unknown color in keyframe: %v:%v - %v:%v:%v:%v", x, y, r, g, b, a)
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions painter/painter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ func Work(wg *sync.WaitGroup, image *art.Image) {
go func(p *art.Pixel) {
if err := sp.DrawPixel(p.X, p.Y, p.C); err != nil {
log.Infof("Failed drawing %v:%v to %v, because: %v", p.X, p.Y, p.C, err)
} else {
// TODO: Find out if we need to update the image ourselves in case of a successful situation
}
time.Sleep(5 * time.Second) // Allow another additional 5 seconds for realtime to update after the request is done
inFlightLock.Lock()
Expand Down
8 changes: 6 additions & 2 deletions realtime/realtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ connect:
if len(message) >= 7 {
version := int(binary.LittleEndian.Uint32(message[0:4]))
for i := 4; i < len(message); i += 3 {
x, y, color := decodeEdit(message[i : i+3]) // TODO: Out of bounds check
image.UpdatePixel(x, y, color, version)
if len(message) >= i+3 {
x, y, color := decodeEdit(message[i : i+3])
image.UpdatePixel(x, y, color, version)
} else {
log.Infof("recv unknown suffix on edits: %v", message[i:])
}
}
} else {
log.Infof("recv unknown: %v", message)
Expand Down

0 comments on commit 52e3ff8

Please sign in to comment.