QRRSBlock.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. import QRErrorCorrectLevel from "./QRErrorCorrectLevel.js";
  2. export default class QRRSBlock {
  3. static RS_BLOCK_TABLE = [
  4. [1, 26, 19],
  5. [1, 26, 16],
  6. [1, 26, 13],
  7. [1, 26, 9],
  8. [1, 44, 34],
  9. [1, 44, 28],
  10. [1, 44, 22],
  11. [1, 44, 16],
  12. [1, 70, 55],
  13. [1, 70, 44],
  14. [2, 35, 17],
  15. [2, 35, 13],
  16. [1, 100, 80],
  17. [2, 50, 32],
  18. [2, 50, 24],
  19. [4, 25, 9],
  20. [1, 134, 108],
  21. [2, 67, 43],
  22. [2, 33, 15, 2, 34, 16],
  23. [2, 33, 11, 2, 34, 12],
  24. [2, 86, 68],
  25. [4, 43, 27],
  26. [4, 43, 19],
  27. [4, 43, 15],
  28. [2, 98, 78],
  29. [4, 49, 31],
  30. [2, 32, 14, 4, 33, 15],
  31. [4, 39, 13, 1, 40, 14],
  32. [2, 121, 97],
  33. [2, 60, 38, 2, 61, 39],
  34. [4, 40, 18, 2, 41, 19],
  35. [4, 40, 14, 2, 41, 15],
  36. [2, 146, 116],
  37. [3, 58, 36, 2, 59, 37],
  38. [4, 36, 16, 4, 37, 17],
  39. [4, 36, 12, 4, 37, 13],
  40. [2, 86, 68, 2, 87, 69],
  41. [4, 69, 43, 1, 70, 44],
  42. [6, 43, 19, 2, 44, 20],
  43. [6, 43, 15, 2, 44, 16],
  44. [4, 101, 81],
  45. [1, 80, 50, 4, 81, 51],
  46. [4, 50, 22, 4, 51, 23],
  47. [3, 36, 12, 8, 37, 13],
  48. [2, 116, 92, 2, 117, 93],
  49. [6, 58, 36, 2, 59, 37],
  50. [4, 46, 20, 6, 47, 21],
  51. [7, 42, 14, 4, 43, 15],
  52. [4, 133, 107],
  53. [8, 59, 37, 1, 60, 38],
  54. [8, 44, 20, 4, 45, 21],
  55. [12, 33, 11, 4, 34, 12],
  56. [3, 145, 115, 1, 146, 116],
  57. [4, 64, 40, 5, 65, 41],
  58. [11, 36, 16, 5, 37, 17],
  59. [11, 36, 12, 5, 37, 13],
  60. [5, 109, 87, 1, 110, 88],
  61. [5, 65, 41, 5, 66, 42],
  62. [5, 54, 24, 7, 55, 25],
  63. [11, 36, 12],
  64. [5, 122, 98, 1, 123, 99],
  65. [7, 73, 45, 3, 74, 46],
  66. [15, 43, 19, 2, 44, 20],
  67. [3, 45, 15, 13, 46, 16],
  68. [1, 135, 107, 5, 136, 108],
  69. [10, 74, 46, 1, 75, 47],
  70. [1, 50, 22, 15, 51, 23],
  71. [2, 42, 14, 17, 43, 15],
  72. [5, 150, 120, 1, 151, 121],
  73. [9, 69, 43, 4, 70, 44],
  74. [17, 50, 22, 1, 51, 23],
  75. [2, 42, 14, 19, 43, 15],
  76. [3, 141, 113, 4, 142, 114],
  77. [3, 70, 44, 11, 71, 45],
  78. [17, 47, 21, 4, 48, 22],
  79. [9, 39, 13, 16, 40, 14],
  80. [3, 135, 107, 5, 136, 108],
  81. [3, 67, 41, 13, 68, 42],
  82. [15, 54, 24, 5, 55, 25],
  83. [15, 43, 15, 10, 44, 16],
  84. [4, 144, 116, 4, 145, 117],
  85. [17, 68, 42],
  86. [17, 50, 22, 6, 51, 23],
  87. [19, 46, 16, 6, 47, 17],
  88. [2, 139, 111, 7, 140, 112],
  89. [17, 74, 46],
  90. [7, 54, 24, 16, 55, 25],
  91. [34, 37, 13],
  92. [4, 151, 121, 5, 152, 122],
  93. [4, 75, 47, 14, 76, 48],
  94. [11, 54, 24, 14, 55, 25],
  95. [16, 45, 15, 14, 46, 16],
  96. [6, 147, 117, 4, 148, 118],
  97. [6, 73, 45, 14, 74, 46],
  98. [11, 54, 24, 16, 55, 25],
  99. [30, 46, 16, 2, 47, 17],
  100. [8, 132, 106, 4, 133, 107],
  101. [8, 75, 47, 13, 76, 48],
  102. [7, 54, 24, 22, 55, 25],
  103. [22, 45, 15, 13, 46, 16],
  104. [10, 142, 114, 2, 143, 115],
  105. [19, 74, 46, 4, 75, 47],
  106. [28, 50, 22, 6, 51, 23],
  107. [33, 46, 16, 4, 47, 17],
  108. [8, 152, 122, 4, 153, 123],
  109. [22, 73, 45, 3, 74, 46],
  110. [8, 53, 23, 26, 54, 24],
  111. [12, 45, 15, 28, 46, 16],
  112. [3, 147, 117, 10, 148, 118],
  113. [3, 73, 45, 23, 74, 46],
  114. [4, 54, 24, 31, 55, 25],
  115. [11, 45, 15, 31, 46, 16],
  116. [7, 146, 116, 7, 147, 117],
  117. [21, 73, 45, 7, 74, 46],
  118. [1, 53, 23, 37, 54, 24],
  119. [19, 45, 15, 26, 46, 16],
  120. [5, 145, 115, 10, 146, 116],
  121. [19, 75, 47, 10, 76, 48],
  122. [15, 54, 24, 25, 55, 25],
  123. [23, 45, 15, 25, 46, 16],
  124. [13, 145, 115, 3, 146, 116],
  125. [2, 74, 46, 29, 75, 47],
  126. [42, 54, 24, 1, 55, 25],
  127. [23, 45, 15, 28, 46, 16],
  128. [17, 145, 115],
  129. [10, 74, 46, 23, 75, 47],
  130. [10, 54, 24, 35, 55, 25],
  131. [19, 45, 15, 35, 46, 16],
  132. [17, 145, 115, 1, 146, 116],
  133. [14, 74, 46, 21, 75, 47],
  134. [29, 54, 24, 19, 55, 25],
  135. [11, 45, 15, 46, 46, 16],
  136. [13, 145, 115, 6, 146, 116],
  137. [14, 74, 46, 23, 75, 47],
  138. [44, 54, 24, 7, 55, 25],
  139. [59, 46, 16, 1, 47, 17],
  140. [12, 151, 121, 7, 152, 122],
  141. [12, 75, 47, 26, 76, 48],
  142. [39, 54, 24, 14, 55, 25],
  143. [22, 45, 15, 41, 46, 16],
  144. [6, 151, 121, 14, 152, 122],
  145. [6, 75, 47, 34, 76, 48],
  146. [46, 54, 24, 10, 55, 25],
  147. [2, 45, 15, 64, 46, 16],
  148. [17, 152, 122, 4, 153, 123],
  149. [29, 74, 46, 14, 75, 47],
  150. [49, 54, 24, 10, 55, 25],
  151. [24, 45, 15, 46, 46, 16],
  152. [4, 152, 122, 18, 153, 123],
  153. [13, 74, 46, 32, 75, 47],
  154. [48, 54, 24, 14, 55, 25],
  155. [42, 45, 15, 32, 46, 16],
  156. [20, 147, 117, 4, 148, 118],
  157. [40, 75, 47, 7, 76, 48],
  158. [43, 54, 24, 22, 55, 25],
  159. [10, 45, 15, 67, 46, 16],
  160. [19, 148, 118, 6, 149, 119],
  161. [18, 75, 47, 31, 76, 48],
  162. [34, 54, 24, 34, 55, 25],
  163. [20, 45, 15, 61, 46, 16]
  164. ];
  165. constructor(totalCount, dataCount) {
  166. this.totalCount = totalCount;
  167. this.dataCount = dataCount;
  168. }
  169. static getRSBlocks(typeNumber, errorCorrectLevel) {
  170. var rsBlock = QRRSBlock.getRsBlockTable(typeNumber, errorCorrectLevel);
  171. if (rsBlock == undefined) {
  172. throw new Error("bad rs block @ typeNumber:" + typeNumber + "/errorCorrectLevel:" +
  173. errorCorrectLevel);
  174. }
  175. var length = rsBlock.length / 3;
  176. var list = [];
  177. for (var i = 0; i < length; i++) {
  178. var count = rsBlock[i * 3 + 0];
  179. var totalCount = rsBlock[i * 3 + 1];
  180. var dataCount = rsBlock[i * 3 + 2];
  181. for (var j = 0; j < count; j++) {
  182. list.push(new QRRSBlock(totalCount, dataCount));
  183. }
  184. }
  185. return list;
  186. }
  187. static getRsBlockTable(typeNumber, errorCorrectLevel) {
  188. switch (errorCorrectLevel) {
  189. case QRErrorCorrectLevel.L:
  190. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 0];
  191. case QRErrorCorrectLevel.M:
  192. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 1];
  193. case QRErrorCorrectLevel.Q:
  194. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 2];
  195. case QRErrorCorrectLevel.H:
  196. return QRRSBlock.RS_BLOCK_TABLE[(typeNumber - 1) * 4 + 3];
  197. default:
  198. return undefined;
  199. }
  200. }
  201. }