codesize.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package datamatrix
  2. type dmCodeSize struct {
  3. Rows int
  4. Columns int
  5. RegionCountHorizontal int
  6. RegionCountVertical int
  7. ECCCount int
  8. BlockCount int
  9. }
  10. func (s *dmCodeSize) RegionRows() int {
  11. return (s.Rows - (s.RegionCountHorizontal * 2)) / s.RegionCountHorizontal
  12. }
  13. func (s *dmCodeSize) RegionColumns() int {
  14. return (s.Columns - (s.RegionCountVertical * 2)) / s.RegionCountVertical
  15. }
  16. func (s *dmCodeSize) MatrixRows() int {
  17. return s.RegionRows() * s.RegionCountHorizontal
  18. }
  19. func (s *dmCodeSize) MatrixColumns() int {
  20. return s.RegionColumns() * s.RegionCountVertical
  21. }
  22. func (s *dmCodeSize) DataCodewords() int {
  23. return ((s.MatrixColumns() * s.MatrixRows()) / 8) - s.ECCCount
  24. }
  25. func (s *dmCodeSize) DataCodewordsForBlock(idx int) int {
  26. if s.Rows == 144 && s.Columns == 144 {
  27. // Special Case...
  28. if idx < 8 {
  29. return 156
  30. } else {
  31. return 155
  32. }
  33. }
  34. return s.DataCodewords() / s.BlockCount
  35. }
  36. func (s *dmCodeSize) ErrorCorrectionCodewordsPerBlock() int {
  37. return s.ECCCount / s.BlockCount
  38. }
  39. var codeSizes []*dmCodeSize = []*dmCodeSize{
  40. &dmCodeSize{10, 10, 1, 1, 5, 1},
  41. &dmCodeSize{12, 12, 1, 1, 7, 1},
  42. &dmCodeSize{14, 14, 1, 1, 10, 1},
  43. &dmCodeSize{16, 16, 1, 1, 12, 1},
  44. &dmCodeSize{18, 18, 1, 1, 14, 1},
  45. &dmCodeSize{20, 20, 1, 1, 18, 1},
  46. &dmCodeSize{22, 22, 1, 1, 20, 1},
  47. &dmCodeSize{24, 24, 1, 1, 24, 1},
  48. &dmCodeSize{26, 26, 1, 1, 28, 1},
  49. &dmCodeSize{32, 32, 2, 2, 36, 1},
  50. &dmCodeSize{36, 36, 2, 2, 42, 1},
  51. &dmCodeSize{40, 40, 2, 2, 48, 1},
  52. &dmCodeSize{44, 44, 2, 2, 56, 1},
  53. &dmCodeSize{48, 48, 2, 2, 68, 1},
  54. &dmCodeSize{52, 52, 2, 2, 84, 2},
  55. &dmCodeSize{64, 64, 4, 4, 112, 2},
  56. &dmCodeSize{72, 72, 4, 4, 144, 4},
  57. &dmCodeSize{80, 80, 4, 4, 192, 4},
  58. &dmCodeSize{88, 88, 4, 4, 224, 4},
  59. &dmCodeSize{96, 96, 4, 4, 272, 4},
  60. &dmCodeSize{104, 104, 4, 4, 336, 6},
  61. &dmCodeSize{120, 120, 6, 6, 408, 6},
  62. &dmCodeSize{132, 132, 6, 6, 496, 8},
  63. &dmCodeSize{144, 144, 6, 6, 620, 10},
  64. }