This commit is contained in:
Florian Sundermann committed 2013-12-16 14:10:24 +01:00
1 parent a4167688a0
commit 9741f0ff8d
12 files changed
+143 -270

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
package utils
import (
"github.com/boombuler/barcode"
"image"
"image/color"
)
type base1DCode struct {
*BitList
kind string
content string
}
func (c *base1DCode) Content() string {
return c.content
}
func (c *base1DCode) Metadata() barcode.Metadata {
return barcode.Metadata{c.kind, 1}
}
func (c *base1DCode) ColorModel() color.Model {
return color.Gray16Model
}
func (c *base1DCode) Bounds() image.Rectangle {
return image.Rect(0, 0, c.Len(), 1)
}
func (c *base1DCode) At(x, y int) color.Color {
if c.GetBit(x) {
return color.Black
}
return color.White
}
func New1DCode(codeKind, content string, bars *BitList) barcode.Barcode {
return &base1DCode{bars, codeKind, content}
}
+9 -14
View File
@@ -37,14 +37,16 @@ func (bl *BitList) grow() {
bl.data = nd
}
// appends the given bit to the end of the list
func (bl *BitList) AddBit(bit bool) {
itmIndex := bl.count / 32
for itmIndex >= len(bl.data) {
bl.grow()
// appends the given bits to the end of the list
func (bl *BitList) AddBit(bits ...bool) {
for _, bit := range bits {
itmIndex := bl.count / 32
for itmIndex >= len(bl.data) {
bl.grow()
}
bl.SetBit(bl.count, bit)
bl.count++
}
bl.SetBit(bl.count, bit)
bl.count++
}
// sets the bit at the given index to the given value
@@ -79,13 +81,6 @@ func (bl *BitList) AddBits(b int, count byte) {
}
}
// appends all bits in the bool-slice to the end of the list
func (bl *BitList) AddRange(bits []bool) {
for _, b := range bits {
bl.AddBit(b)
}
}
// returns all bits of the BitList as a []byte
func (bl *BitList) GetBytes() []byte {
len := bl.count >> 3