barcode/qr/errorcorrection.go

30 lines
645 B
Go
Raw Permalink Normal View History

2013-12-11 13:31:11 +00:00
package qr
import (
2025-01-03 19:41:46 +00:00
"git.bbr-dev.info/brajkovic/barcode/utils"
)
type errorCorrection struct {
rs *utils.ReedSolomonEncoder
2013-12-11 13:31:11 +00:00
}
var ec = newErrorCorrection()
2013-12-11 13:31:11 +00:00
func newErrorCorrection() *errorCorrection {
fld := utils.NewGaloisField(285, 256, 0)
return &errorCorrection{utils.NewReedSolomonEncoder(fld)}
2013-12-11 13:31:11 +00:00
}
func (ec *errorCorrection) calcECC(data []byte, eccCount byte) []byte {
dataInts := make([]int, len(data))
for i := 0; i < len(data); i++ {
dataInts[i] = int(data[i])
}
res := ec.rs.Encode(dataInts, int(eccCount))
result := make([]byte, len(res))
for i := 0; i < len(res); i++ {
result[i] = byte(res[i])
}
return result
2013-12-11 13:31:11 +00:00
}