diff --git a/datamatrix/codesize.go b/datamatrix/codesize.go index a949e59..c63eb8c 100644 --- a/datamatrix/codesize.go +++ b/datamatrix/codesize.go @@ -29,7 +29,15 @@ func (s *dmCodeSize) DataCodewords() int { return ((s.MatrixColumns() * s.MatrixRows()) / 8) - s.ECCCount } -func (s *dmCodeSize) DataCodewordsPerBlock() int { +func (s *dmCodeSize) DataCodewordsForBlock(idx int) int { + if s.Rows == 144 && s.Columns == 144 { + // Special Case... + if idx < 8 { + return 156 + } else { + return 155 + } + } return s.DataCodewords() / s.BlockCount } diff --git a/datamatrix/errorcorrection.go b/datamatrix/errorcorrection.go index 4c0bae6..ef5876b 100644 --- a/datamatrix/errorcorrection.go +++ b/datamatrix/errorcorrection.go @@ -54,7 +54,7 @@ func (ec *errorCorrection) calcECCBlock(data []byte, poly []int) []byte { } func (ec *errorCorrection) calcECC(data []byte, size *dmCodeSize) []byte { - buff := make([]byte, size.DataCodewordsPerBlock()) + poly := ec.getPolynomial(size.ErrorCorrectionCodewordsPerBlock()) dataSize := len(data) @@ -62,6 +62,9 @@ func (ec *errorCorrection) calcECC(data []byte, size *dmCodeSize) []byte { data = append(data, make([]byte, size.ECCCount)...) for block := 0; block < size.BlockCount; block++ { + dataCnt := size.DataCodewordsForBlock(block) + + buff := make([]byte, dataCnt) // copy the data for the current block to buff j := 0 for i := block; i < dataSize; i += size.BlockCount {