fixes issue #11

This commit is contained in:
boombuler 2016-07-18 18:56:27 +02:00
parent d1c739eed5
commit 56a31058a9
2 changed files with 13 additions and 2 deletions

View File

@ -29,7 +29,15 @@ func (s *dmCodeSize) DataCodewords() int {
return ((s.MatrixColumns() * s.MatrixRows()) / 8) - s.ECCCount 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 return s.DataCodewords() / s.BlockCount
} }

View File

@ -54,7 +54,7 @@ func (ec *errorCorrection) calcECCBlock(data []byte, poly []int) []byte {
} }
func (ec *errorCorrection) calcECC(data []byte, size *dmCodeSize) []byte { func (ec *errorCorrection) calcECC(data []byte, size *dmCodeSize) []byte {
buff := make([]byte, size.DataCodewordsPerBlock())
poly := ec.getPolynomial(size.ErrorCorrectionCodewordsPerBlock()) poly := ec.getPolynomial(size.ErrorCorrectionCodewordsPerBlock())
dataSize := len(data) dataSize := len(data)
@ -62,6 +62,9 @@ func (ec *errorCorrection) calcECC(data []byte, size *dmCodeSize) []byte {
data = append(data, make([]byte, size.ECCCount)...) data = append(data, make([]byte, size.ECCCount)...)
for block := 0; block < size.BlockCount; block++ { for block := 0; block < size.BlockCount; block++ {
dataCnt := size.DataCodewordsForBlock(block)
buff := make([]byte, dataCnt)
// copy the data for the current block to buff // copy the data for the current block to buff
j := 0 j := 0
for i := block; i < dataSize; i += size.BlockCount { for i := block; i < dataSize; i += size.BlockCount {