git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/barcode/datamatrix/datamatrixcode.go (about) 1 package datamatrix 2 3 import ( 4 "image" 5 "image/color" 6 7 "git.sr.ht/~pingoo/stdx/barcode" 8 "git.sr.ht/~pingoo/stdx/barcode/utils" 9 ) 10 11 type datamatrixCode struct { 12 *utils.BitList 13 *dmCodeSize 14 content string 15 } 16 17 func newDataMatrixCode(size *dmCodeSize) *datamatrixCode { 18 return &datamatrixCode{utils.NewBitList(size.Rows * size.Columns), size, ""} 19 } 20 21 func (c *datamatrixCode) Content() string { 22 return c.content 23 } 24 25 func (c *datamatrixCode) Metadata() barcode.Metadata { 26 return barcode.Metadata{barcode.TypeDataMatrix, 2} 27 } 28 29 func (c *datamatrixCode) ColorModel() color.Model { 30 return color.Gray16Model 31 } 32 33 func (c *datamatrixCode) Bounds() image.Rectangle { 34 return image.Rect(0, 0, c.Columns, c.Rows) 35 } 36 37 func (c *datamatrixCode) At(x, y int) color.Color { 38 if c.get(x, y) { 39 return color.Black 40 } 41 return color.White 42 } 43 44 func (c *datamatrixCode) get(x, y int) bool { 45 return c.GetBit(x*c.Rows + y) 46 } 47 48 func (c *datamatrixCode) set(x, y int, value bool) { 49 c.SetBit(x*c.Rows+y, value) 50 }