updated documentation
This commit is contained in:
parent
422121e68f
commit
d6bf3500ec
|
@ -2,13 +2,19 @@ package barcode
|
||||||
|
|
||||||
import "image"
|
import "image"
|
||||||
|
|
||||||
|
// Contains some meta information about a barcode
|
||||||
type Metadata struct {
|
type Metadata struct {
|
||||||
|
// the name of the barcode kind
|
||||||
CodeKind string
|
CodeKind string
|
||||||
|
// contains 1 for 1D barcodes or 2 for 2D barcodes
|
||||||
Dimensions byte
|
Dimensions byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// a rendered and encoded barcode
|
||||||
type Barcode interface {
|
type Barcode interface {
|
||||||
image.Image
|
image.Image
|
||||||
|
// returns some meta information about the barcode
|
||||||
Metadata() Metadata
|
Metadata() Metadata
|
||||||
|
// the data that was encoded in this barcode
|
||||||
Content() string
|
Content() string
|
||||||
}
|
}
|
||||||
|
|
15
bitlist.go
15
bitlist.go
|
@ -1,10 +1,13 @@
|
||||||
package barcode
|
package barcode
|
||||||
|
|
||||||
|
// utility class that contains bits
|
||||||
type BitList struct {
|
type BitList struct {
|
||||||
count int
|
count int
|
||||||
data []int32
|
data []int32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns a new BitList with the given length
|
||||||
|
// all bits are initialize with false
|
||||||
func NewBitList(capacity int) *BitList {
|
func NewBitList(capacity int) *BitList {
|
||||||
bl := new(BitList)
|
bl := new(BitList)
|
||||||
bl.count = capacity
|
bl.count = capacity
|
||||||
|
@ -16,14 +19,11 @@ func NewBitList(capacity int) *BitList {
|
||||||
return bl
|
return bl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns the number of contained bits
|
||||||
func (bl *BitList) Len() int {
|
func (bl *BitList) Len() int {
|
||||||
return bl.count
|
return bl.count
|
||||||
}
|
}
|
||||||
|
|
||||||
func (bl *BitList) Cap() int {
|
|
||||||
return len(bl.data) * 32
|
|
||||||
}
|
|
||||||
|
|
||||||
func (bl *BitList) grow() {
|
func (bl *BitList) grow() {
|
||||||
growBy := len(bl.data)
|
growBy := len(bl.data)
|
||||||
if growBy < 128 {
|
if growBy < 128 {
|
||||||
|
@ -37,6 +37,7 @@ func (bl *BitList) grow() {
|
||||||
bl.data = nd
|
bl.data = nd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// appends the given bit to the end of the list
|
||||||
func (bl *BitList) AddBit(bit bool) {
|
func (bl *BitList) AddBit(bit bool) {
|
||||||
itmIndex := bl.count / 32
|
itmIndex := bl.count / 32
|
||||||
for itmIndex >= len(bl.data) {
|
for itmIndex >= len(bl.data) {
|
||||||
|
@ -46,6 +47,7 @@ func (bl *BitList) AddBit(bit bool) {
|
||||||
bl.count++
|
bl.count++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sets the bit at the given index to the given value
|
||||||
func (bl *BitList) SetBit(index int, value bool) {
|
func (bl *BitList) SetBit(index int, value bool) {
|
||||||
itmIndex := index / 32
|
itmIndex := index / 32
|
||||||
itmBitShift := 31 - (index % 32)
|
itmBitShift := 31 - (index % 32)
|
||||||
|
@ -56,24 +58,28 @@ func (bl *BitList) SetBit(index int, value bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns the bit at the given index
|
||||||
func (bl *BitList) GetBit(index int) bool {
|
func (bl *BitList) GetBit(index int) bool {
|
||||||
itmIndex := index / 32
|
itmIndex := index / 32
|
||||||
itmBitShift := 31 - (index % 32)
|
itmBitShift := 31 - (index % 32)
|
||||||
return ((bl.data[itmIndex] >> uint(itmBitShift)) & 1) == 1
|
return ((bl.data[itmIndex] >> uint(itmBitShift)) & 1) == 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// appends all 8 bits of the given byte to the end of the list
|
||||||
func (bl *BitList) AddByte(b byte) {
|
func (bl *BitList) AddByte(b byte) {
|
||||||
for i := 7; i >= 0; i-- {
|
for i := 7; i >= 0; i-- {
|
||||||
bl.AddBit(((b >> uint(i)) & 1) == 1)
|
bl.AddBit(((b >> uint(i)) & 1) == 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// appends the last (LSB) 'count' bits of 'b' the the end of the list
|
||||||
func (bl *BitList) AddBits(b int, count byte) {
|
func (bl *BitList) AddBits(b int, count byte) {
|
||||||
for i := int(count - 1); i >= 0; i-- {
|
for i := int(count - 1); i >= 0; i-- {
|
||||||
bl.AddBit(((b >> uint(i)) & 1) == 1)
|
bl.AddBit(((b >> uint(i)) & 1) == 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns all bits of the BitList as a []byte
|
||||||
func (bl *BitList) GetBytes() []byte {
|
func (bl *BitList) GetBytes() []byte {
|
||||||
len := bl.count >> 3
|
len := bl.count >> 3
|
||||||
if (bl.count % 8) != 0 {
|
if (bl.count % 8) != 0 {
|
||||||
|
@ -87,6 +93,7 @@ func (bl *BitList) GetBytes() []byte {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// itterates through all bytes contained in the BitList
|
||||||
func (bl *BitList) ItterateBytes() <-chan byte {
|
func (bl *BitList) ItterateBytes() <-chan byte {
|
||||||
res := make(chan byte)
|
res := make(chan byte)
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ func (bc *scaledBarcode) At(x, y int) color.Color {
|
||||||
return bc.wrapperFunc(x, y)
|
return bc.wrapperFunc(x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// returns a resized barcode with the given width and height.
|
||||||
func Scale(bc Barcode, width, height int) (Barcode, error) {
|
func Scale(bc Barcode, width, height int) (Barcode, error) {
|
||||||
switch bc.Metadata().Dimensions {
|
switch bc.Metadata().Dimensions {
|
||||||
case 1:
|
case 1:
|
||||||
|
|
Loading…
Reference in New Issue