RSBlock.js 5.4 KB

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