add support for depth in barcode generations
- Introduced depth parameter to EncodeWithDepth function to allow generating barcodes with specified color depth. - Updated Encode function to use EncodeWithDepth with a default depth of 16.
This commit is contained in:
1 parent
f3630e1cd4
commit
87ab0677e3
15 files changed
+114
-47
No files matched your search
+6
-5
@@ -13,10 +13,11 @@ type aztecCode struct {
|
||||
*utils.BitList
|
||||
size int
|
||||
content []byte
|
||||
depth int
|
||||
}
|
||||
|
||||
func newAztecCode(size int) *aztecCode {
|
||||
return &aztecCode{utils.NewBitList(size * size), size, nil}
|
||||
func newAztecCode(size int, depth int) *aztecCode {
|
||||
return &aztecCode{utils.NewBitList(size * size), size, nil, 16}
|
||||
}
|
||||
|
||||
func (c *aztecCode) Content() string {
|
||||
@@ -28,7 +29,7 @@ func (c *aztecCode) Metadata() barcode.Metadata {
|
||||
}
|
||||
|
||||
func (c *aztecCode) ColorModel() color.Model {
|
||||
return color.Gray16Model
|
||||
return utils.ColorModel(c.depth)
|
||||
}
|
||||
|
||||
func (c *aztecCode) Bounds() image.Rectangle {
|
||||
@@ -37,9 +38,9 @@ func (c *aztecCode) Bounds() image.Rectangle {
|
||||
|
||||
func (c *aztecCode) At(x, y int) color.Color {
|
||||
if c.GetBit(x*c.size + y) {
|
||||
return color.Black
|
||||
return utils.BlackColor(c.depth)
|
||||
}
|
||||
return color.White
|
||||
return utils.WhiteColor(c.depth)
|
||||
}
|
||||
|
||||
func (c *aztecCode) set(x, y int) {
|
||||
|
||||
+7
-2
@@ -123,7 +123,12 @@ func drawBullsEye(matrix *aztecCode, center, size int) {
|
||||
}
|
||||
|
||||
// Encode returns an aztec barcode with the given content
|
||||
func Encode(data []byte, minECCPercent int, userSpecifiedLayers int) (barcode.Barcode, error) {
|
||||
func Encode(data []byte, minECCPercent int, userSpecifiedLayers int) (barcode.Barcode, error){
|
||||
return EncodeWithDepth(data, minECCPercent, userSpecifiedLayers, 16)
|
||||
}
|
||||
|
||||
// Encode returns an aztec barcode with the given content
|
||||
func EncodeWithDepth(data []byte, minECCPercent int, userSpecifiedLayers int, depth int) (barcode.Barcode, error) {
|
||||
bits := highlevelEncode(data)
|
||||
eccBits := ((bits.Len() * minECCPercent) / 100) + 11
|
||||
totalSizeBits := bits.Len() + eccBits
|
||||
@@ -215,7 +220,7 @@ func Encode(data []byte, minECCPercent int, userSpecifiedLayers int) (barcode.Ba
|
||||
alignmentMap[origCenter+i] = center + newOffset + 1
|
||||
}
|
||||
}
|
||||
code := newAztecCode(matrixSize)
|
||||
code := newAztecCode(matrixSize, depth)
|
||||
code.content = data
|
||||
|
||||
// draw data bits
|
||||
|
||||
Reference in new issue
Block a user