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