2013-12-12 19:36:57 +00:00
|
|
|
package datamatrix
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/color"
|
2017-06-17 21:42:17 +00:00
|
|
|
|
2025-01-03 19:41:46 +00:00
|
|
|
"git.bbr-dev.info/brajkovic/barcode"
|
|
|
|
"git.bbr-dev.info/brajkovic/barcode/utils"
|
2013-12-12 19:36:57 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type datamatrixCode struct {
|
2013-12-13 12:53:27 +00:00
|
|
|
*utils.BitList
|
2013-12-12 19:36:57 +00:00
|
|
|
*dmCodeSize
|
|
|
|
content string
|
2024-07-31 19:11:52 +00:00
|
|
|
color barcode.ColorScheme
|
2024-07-24 13:29:23 +00:00
|
|
|
}
|
|
|
|
|
2024-07-31 19:11:52 +00:00
|
|
|
func newDataMatrixCodeWithColor(size *dmCodeSize, color barcode.ColorScheme) *datamatrixCode {
|
|
|
|
return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, "", color}
|
2013-12-12 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func newDataMatrixCode(size *dmCodeSize) *datamatrixCode {
|
2024-07-31 19:11:52 +00:00
|
|
|
return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, "", barcode.ColorScheme16}
|
2013-12-12 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *datamatrixCode) Content() string {
|
|
|
|
return c.content
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *datamatrixCode) Metadata() barcode.Metadata {
|
2017-06-17 21:42:17 +00:00
|
|
|
return barcode.Metadata{barcode.TypeDataMatrix, 2}
|
2013-12-12 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *datamatrixCode) ColorModel() color.Model {
|
2024-07-31 19:11:52 +00:00
|
|
|
return c.color.Model
|
2013-12-12 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
2024-08-02 15:33:00 +00:00
|
|
|
func (c *datamatrixCode) ColorScheme() barcode.ColorScheme {
|
|
|
|
return c.color
|
|
|
|
}
|
|
|
|
|
2013-12-12 19:36:57 +00:00
|
|
|
func (c *datamatrixCode) Bounds() image.Rectangle {
|
|
|
|
return image.Rect(0, 0, c.Columns, c.Rows)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *datamatrixCode) At(x, y int) color.Color {
|
|
|
|
if c.get(x, y) {
|
2024-07-31 19:11:52 +00:00
|
|
|
return c.color.Foreground
|
2013-12-12 19:36:57 +00:00
|
|
|
}
|
2024-07-31 19:11:52 +00:00
|
|
|
return c.color.Background
|
2013-12-12 19:36:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *datamatrixCode) get(x, y int) bool {
|
|
|
|
return c.GetBit(x*c.Rows + y)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *datamatrixCode) set(x, y int, value bool) {
|
|
|
|
c.SetBit(x*c.Rows+y, value)
|
|
|
|
}
|