errorcorrection.go 639 B

1234567891011121314151617181920212223242526272829
  1. package qr
  2. import (
  3. "github.com/boombuler/barcode/utils"
  4. )
  5. type errorCorrection struct {
  6. rs *utils.ReedSolomonEncoder
  7. }
  8. var ec = newErrorCorrection()
  9. func newErrorCorrection() *errorCorrection {
  10. fld := utils.NewGaloisField(285, 256, 0)
  11. return &errorCorrection{utils.NewReedSolomonEncoder(fld)}
  12. }
  13. func (ec *errorCorrection) calcECC(data []byte, eccCount byte) []byte {
  14. dataInts := make([]int, len(data))
  15. for i := 0; i < len(data); i++ {
  16. dataInts[i] = int(data[i])
  17. }
  18. res := ec.rs.Encode(dataInts, int(eccCount))
  19. result := make([]byte, len(res))
  20. for i := 0; i < len(res); i++ {
  21. result[i] = byte(res[i])
  22. }
  23. return result
  24. }