git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/barcode/datamatrix/codesize.go (about) 1 package datamatrix 2 3 type dmCodeSize struct { 4 Rows int 5 Columns int 6 RegionCountHorizontal int 7 RegionCountVertical int 8 ECCCount int 9 BlockCount int 10 } 11 12 func (s *dmCodeSize) RegionRows() int { 13 return (s.Rows - (s.RegionCountVertical * 2)) / s.RegionCountVertical 14 } 15 16 func (s *dmCodeSize) RegionColumns() int { 17 return (s.Columns - (s.RegionCountHorizontal * 2)) / s.RegionCountHorizontal 18 } 19 20 func (s *dmCodeSize) MatrixRows() int { 21 return s.RegionRows() * s.RegionCountVertical 22 } 23 24 func (s *dmCodeSize) MatrixColumns() int { 25 return s.RegionColumns() * s.RegionCountHorizontal 26 } 27 28 func (s *dmCodeSize) DataCodewords() int { 29 return ((s.MatrixColumns() * s.MatrixRows()) / 8) - s.ECCCount 30 } 31 32 func (s *dmCodeSize) DataCodewordsForBlock(idx int) int { 33 if s.Rows == 144 && s.Columns == 144 { 34 // Special Case... 35 if idx < 8 { 36 return 156 37 } else { 38 return 155 39 } 40 } 41 return s.DataCodewords() / s.BlockCount 42 } 43 44 func (s *dmCodeSize) ErrorCorrectionCodewordsPerBlock() int { 45 return s.ECCCount / s.BlockCount 46 } 47 48 var codeSizes []*dmCodeSize = []*dmCodeSize{ 49 &dmCodeSize{10, 10, 1, 1, 5, 1}, 50 &dmCodeSize{12, 12, 1, 1, 7, 1}, 51 &dmCodeSize{14, 14, 1, 1, 10, 1}, 52 &dmCodeSize{16, 16, 1, 1, 12, 1}, 53 &dmCodeSize{18, 18, 1, 1, 14, 1}, 54 &dmCodeSize{20, 20, 1, 1, 18, 1}, 55 &dmCodeSize{22, 22, 1, 1, 20, 1}, 56 &dmCodeSize{24, 24, 1, 1, 24, 1}, 57 &dmCodeSize{26, 26, 1, 1, 28, 1}, 58 &dmCodeSize{32, 32, 2, 2, 36, 1}, 59 &dmCodeSize{36, 36, 2, 2, 42, 1}, 60 &dmCodeSize{40, 40, 2, 2, 48, 1}, 61 &dmCodeSize{44, 44, 2, 2, 56, 1}, 62 &dmCodeSize{48, 48, 2, 2, 68, 1}, 63 &dmCodeSize{52, 52, 2, 2, 84, 2}, 64 &dmCodeSize{64, 64, 4, 4, 112, 2}, 65 &dmCodeSize{72, 72, 4, 4, 144, 4}, 66 &dmCodeSize{80, 80, 4, 4, 192, 4}, 67 &dmCodeSize{88, 88, 4, 4, 224, 4}, 68 &dmCodeSize{96, 96, 4, 4, 272, 4}, 69 &dmCodeSize{104, 104, 4, 4, 336, 6}, 70 &dmCodeSize{120, 120, 6, 6, 408, 6}, 71 &dmCodeSize{132, 132, 6, 6, 496, 8}, 72 &dmCodeSize{144, 144, 6, 6, 620, 10}, 73 }