Refactor to use ColorScheme instead of 'depth' approach

This commit is contained in:
zhaori96 committed 2024-07-31 16:11:52 -03:00
1 parent e966fa7106
commit 30509e0dd7
16 files changed
+83 -81

No files matched your search

+6 -6
View File
@@ -13,11 +13,11 @@ type aztecCode struct {
*utils.BitList
size int
content []byte
depth int
color barcode.ColorScheme
}
func newAztecCode(size int, depth int) *aztecCode {
return &aztecCode{utils.NewBitList(size * size), size, nil, 16}
func newAztecCode(size int, color barcode.ColorScheme) *aztecCode {
return &aztecCode{utils.NewBitList(size * size), size, nil, barcode.ColorScheme16}
}
func (c *aztecCode) Content() string {
@@ -29,7 +29,7 @@ func (c *aztecCode) Metadata() barcode.Metadata {
}
func (c *aztecCode) ColorModel() color.Model {
return utils.ColorModel(c.depth)
return c.color.Model
}
func (c *aztecCode) Bounds() image.Rectangle {
@@ -38,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 utils.BlackColor(c.depth)
return c.color.Foreground
}
return utils.WhiteColor(c.depth)
return c.color.Background
}
func (c *aztecCode) set(x, y int) {
+4 -4
View File
@@ -123,12 +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){
return EncodeWithDepth(data, minECCPercent, userSpecifiedLayers, 16)
func Encode(data []byte, minECCPercent int, userSpecifiedLayers int) (barcode.Barcode, error) {
return EncodeWithColor(data, minECCPercent, userSpecifiedLayers, barcode.ColorScheme16)
}
// Encode returns an aztec barcode with the given content
func EncodeWithDepth(data []byte, minECCPercent int, userSpecifiedLayers int, depth int) (barcode.Barcode, error) {
func EncodeWithColor(data []byte, minECCPercent int, userSpecifiedLayers int, color barcode.ColorScheme) (barcode.Barcode, error) {
bits := highlevelEncode(data)
eccBits := ((bits.Len() * minECCPercent) / 100) + 11
totalSizeBits := bits.Len() + eccBits
@@ -220,7 +220,7 @@ func EncodeWithDepth(data []byte, minECCPercent int, userSpecifiedLayers int, de
alignmentMap[origCenter+i] = center + newOffset + 1
}
}
code := newAztecCode(matrixSize, depth)
code := newAztecCode(matrixSize, color)
code.content = data
// draw data bits