Skip to content

Commit

Permalink
updated to latest weekly and ran gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
uwedeportivo committed Jul 21, 2011
1 parent f96538a commit 5e743b3
Show file tree
Hide file tree
Showing 7 changed files with 394 additions and 393 deletions.
41 changes: 23 additions & 18 deletions goclient/kindi/bitmap.go
Expand Up @@ -49,18 +49,18 @@ func EncodePNG(w io.Writer, payload []byte, m image.Image) os.Error {
}

func DecodePNG(rin io.Reader) ([]byte, os.Error) {
m, err := png.Decode(rin)
m, err := png.Decode(rin)
if err != nil {
return nil, err
}

nrgba := newNRGBAImageLSBReaderWriter(m)

return readLengthEncoded(nrgba)
}

type nrgbaImageLSBReaderWriter struct {
m *image.NRGBA
m *image.NRGBA
x, y, q int
}

Expand All @@ -73,11 +73,11 @@ func newNRGBAImageLSBReaderWriter(im image.Image) *nrgbaImageLSBReaderWriter {

b := im.Bounds()

rv.m = image.NewNRGBA(b.Max.X - b.Min.X, b.Max.Y - b.Min.Y)
rv.m = image.NewNRGBA(b.Max.X-b.Min.X, b.Max.Y-b.Min.Y)

for y := b.Min.Y; y < b.Max.Y; y++ {
for x := b.Min.X; x < b.Max.X; x++ {
rv.m.Set(x - b.Min.X, y - b.Min.Y, im.At(x, y))
rv.m.Set(x-b.Min.X, y-b.Min.Y, im.At(x, y))
}
}
return rv
Expand All @@ -94,7 +94,7 @@ func (it *nrgbaImageLSBReaderWriter) Read(p []byte) (n int, err os.Error) {
for j, _ := range p {
var rv byte = 0
var i uint8
for i = 0; i < 8; i++ {
for i = 0; i < 8; i++ {
it.q++
if it.q == 3 {
it.q = 0
Expand All @@ -107,13 +107,16 @@ func (it *nrgbaImageLSBReaderWriter) Read(p []byte) (n int, err os.Error) {
}
}
}

color := it.m.At(it.x, it.y).(image.NRGBAColor)
var colorByte byte
switch (it.q) {
case 0 : colorByte = color.R
case 1 : colorByte = color.G
case 2 : colorByte = color.B
switch it.q {
case 0:
colorByte = color.R
case 1:
colorByte = color.G
case 2:
colorByte = color.B
}
rv = rv | ((colorByte & 1) << i)
}
Expand Down Expand Up @@ -149,18 +152,20 @@ func (it *nrgbaImageLSBReaderWriter) Write(p []byte) (n int, err os.Error) {
return n, os.EOF
}
}
}
}

color := it.m.At(it.x, it.y).(image.NRGBAColor)
switch (it.q) {
case 0 : color.R = setLSB(color.R, (v >> i) & 1)
case 1 : color.G = setLSB(color.G, (v >> i) & 1)
case 2 : color.B = setLSB(color.B, (v >> i) & 1)
switch it.q {
case 0:
color.R = setLSB(color.R, (v>>i)&1)
case 1:
color.G = setLSB(color.G, (v>>i)&1)
case 2:
color.B = setLSB(color.B, (v>>i)&1)
}
it.m.Set(it.x, it.y, color)
}
n++
}
return n, nil
}

22 changes: 11 additions & 11 deletions goclient/kindi/bitmap_test.go
Expand Up @@ -37,7 +37,7 @@ import (
)

func TestPNG(t *testing.T) {
payload := []byte{0xd9, 0x4a, 0xe0, 0x83, 0x2e, 0x64, 0x45, 0xce,
payload := []byte{0xd9, 0x4a, 0xe0, 0x83, 0x2e, 0x64, 0x45, 0xce,
0x42, 0x33, 0x1c, 0xb0, 0x6d, 0x53, 0x1a, 0x82, 0xb1,
0xdb, 0x4b, 0xaa, 0xd3, 0x0f, 0x74, 0x6d, 0xc9, 0x16,
0xdf, 0x24, 0xd4, 0xe3, 0xc2, 0x45, 0x1f, 0xff, 0x59,
Expand Down Expand Up @@ -77,18 +77,18 @@ func TestPNG(t *testing.T) {
}

err = EncodePNG(buf, payload, m)
if err != nil {
if err != nil {
t.Fatalf("failed to encode as PNG %v", err)
}

outpayload, err := DecodePNG(buf)
if err != nil {
t.Fatalf("failed to decode PNG %v", err)
}
if ! bytes.Equal(outpayload, payload) {
t.Fatalf("decoded payload different from original payload")
}

if !bytes.Equal(outpayload, payload) {
t.Fatalf("decoded payload different from original payload")
}
}

func TestEmbed(t *testing.T) {
Expand Down Expand Up @@ -144,9 +144,9 @@ func TestEmbed(t *testing.T) {
if err != nil {
t.Fatalf("failed %v", err)
}

if ! bytes.Equal(outpayload, payload) {
t.Fatalf("decoded payload different from original payload")
}

}
if !bytes.Equal(outpayload, payload) {
t.Fatalf("decoded payload different from original payload")
}

}

0 comments on commit 5e743b3

Please sign in to comment.