From d6bf3500ecf0fee6f176ac3264580307c059cb87 Mon Sep 17 00:00:00 2001 From: Florian Sundermann Date: Wed, 11 Dec 2013 15:52:59 +0100 Subject: [PATCH] updated documentation --- barcode.go | 8 +++++++- bitlist.go | 15 +++++++++++---- scaledbarcode.go | 1 + 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/barcode.go b/barcode.go index ebad4cb..13b8d13 100644 --- a/barcode.go +++ b/barcode.go @@ -2,13 +2,19 @@ package barcode import "image" +// Contains some meta information about a barcode type Metadata struct { - CodeKind string + // the name of the barcode kind + CodeKind string + // contains 1 for 1D barcodes or 2 for 2D barcodes Dimensions byte } +// a rendered and encoded barcode type Barcode interface { image.Image + // returns some meta information about the barcode Metadata() Metadata + // the data that was encoded in this barcode Content() string } diff --git a/bitlist.go b/bitlist.go index 4e93384..45b0627 100644 --- a/bitlist.go +++ b/bitlist.go @@ -1,10 +1,13 @@ package barcode +// utility class that contains bits type BitList struct { count int data []int32 } +// returns a new BitList with the given length +// all bits are initialize with false func NewBitList(capacity int) *BitList { bl := new(BitList) bl.count = capacity @@ -16,14 +19,11 @@ func NewBitList(capacity int) *BitList { return bl } +// returns the number of contained bits func (bl *BitList) Len() int { return bl.count } -func (bl *BitList) Cap() int { - return len(bl.data) * 32 -} - func (bl *BitList) grow() { growBy := len(bl.data) if growBy < 128 { @@ -37,6 +37,7 @@ 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) { @@ -46,6 +47,7 @@ func (bl *BitList) AddBit(bit bool) { bl.count++ } +// sets the bit at the given index to the given value func (bl *BitList) SetBit(index int, value bool) { itmIndex := 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 { itmIndex := index / 32 itmBitShift := 31 - (index % 32) 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) { for i := 7; i >= 0; i-- { 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) { for i := int(count - 1); i >= 0; i-- { bl.AddBit(((b >> uint(i)) & 1) == 1) } } +// returns all bits of the BitList as a []byte func (bl *BitList) GetBytes() []byte { len := bl.count >> 3 if (bl.count % 8) != 0 { @@ -87,6 +93,7 @@ func (bl *BitList) GetBytes() []byte { return result } +// itterates through all bytes contained in the BitList func (bl *BitList) ItterateBytes() <-chan byte { res := make(chan byte) diff --git a/scaledbarcode.go b/scaledbarcode.go index afbaa8f..e301da2 100644 --- a/scaledbarcode.go +++ b/scaledbarcode.go @@ -36,6 +36,7 @@ func (bc *scaledBarcode) At(x, y int) color.Color { return bc.wrapperFunc(x, y) } +// returns a resized barcode with the given width and height. func Scale(bc Barcode, width, height int) (Barcode, error) { switch bc.Metadata().Dimensions { case 1: