2013-12-11 13:31:11 +00:00
|
|
|
package qr
|
|
|
|
|
2013-12-13 12:53:27 +00:00
|
|
|
import (
|
|
|
|
"github.com/boombuler/barcode/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
type errorCorrection struct {
|
2016-12-26 21:16:28 +00:00
|
|
|
rs *utils.ReedSolomonEncoder
|
2013-12-11 13:31:11 +00:00
|
|
|
}
|
|
|
|
|
2016-12-26 21:16:28 +00:00
|
|
|
var ec = newErrorCorrection()
|
2013-12-11 13:31:11 +00:00
|
|
|
|
2016-12-26 21:16:28 +00:00
|
|
|
func newErrorCorrection() *errorCorrection {
|
|
|
|
fld := utils.NewGaloisField(285, 256, 0)
|
|
|
|
return &errorCorrection{utils.NewReedSolomonEncoder(fld)}
|
2013-12-11 13:31:11 +00:00
|
|
|
}
|
|
|
|
|
2013-12-13 12:53:27 +00:00
|
|
|
func (ec *errorCorrection) calcECC(data []byte, eccCount byte) []byte {
|
2016-12-26 21:16:28 +00:00
|
|
|
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])
|
|
|
|
}
|
2015-02-25 13:08:58 +00:00
|
|
|
return result
|
2013-12-11 13:31:11 +00:00
|
|
|
}
|