return p.Pix
}
+
+func (self *BitSmash) toImage() image.PalettedImage {
+ self.unpackRepeat()
+ size := self.Size()
+ img := image.NewPaletted(image.Rectangle{image.Pt(0, 0), size}, palette.Palettes[self.palette])
+ c := 0
+
+ for _, p := range(self.packetList) {
+ pixels := p.Pixels()
+ copy(img.Pix[c:], pixels)
+ c += len(pixels)
+ }
+
+ return img
+}
package bs
+// I! O! Let's go!
+// I! O! Let's go!
+// I! O! Let's go!
+// I! O! Let's go!
+// - with apologies to The Ramones
+
import (
"io"
"log"
"fmt"
"errors"
+ "image/png"
"bytex64.net/code/bitsmash/packet"
"bytex64.net/code/bitsmash/ac"
return nil
}
+func (self *BitSmash) WriteImage(file io.Writer) error {
+ image := self.toImage()
+ return png.Encode(file, image)
+}
if args.dump {
smash.Dump()
} else {
- var buf bytes.Buffer
- smash.WriteTo(&buf)
- if args.base64 {
- fmt.Println(":_", base64.RawStdEncoding.EncodeToString(buf.Bytes()))
+ if (args.decode) {
+ smash.WriteImage(os.Stdout)
} else {
- buf.WriteTo(os.Stdout)
+ var buf bytes.Buffer
+ smash.WriteTo(&buf)
+ if args.base64 {
+ fmt.Println(":_", base64.RawStdEncoding.EncodeToString(buf.Bytes()))
+ } else {
+ buf.WriteTo(os.Stdout)
+ }
}
}
}
for _, p := range(self.packetSlice) {
c += p.Length()
}
- return 0
+ return c
}
func (*RepeatPacket) ByteLength() int {