[Service] Integrate DeviceHome and SignalingServer
[platform/framework/web/wrtjs.git] / device_home / node_modules / qrcode / lib / core / format-info.js
1 var Utils = require('./utils')
2
3 var G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0)
4 var G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1)
5 var G15_BCH = Utils.getBCHDigit(G15)
6
7 /**
8  * Returns format information with relative error correction bits
9  *
10  * The format information is a 15-bit sequence containing 5 data bits,
11  * with 10 error correction bits calculated using the (15, 5) BCH code.
12  *
13  * @param  {Number} errorCorrectionLevel Error correction level
14  * @param  {Number} mask                 Mask pattern
15  * @return {Number}                      Encoded format information bits
16  */
17 exports.getEncodedBits = function getEncodedBits (errorCorrectionLevel, mask) {
18   var data = ((errorCorrectionLevel.bit << 3) | mask)
19   var d = data << 10
20
21   while (Utils.getBCHDigit(d) - G15_BCH >= 0) {
22     d ^= (G15 << (Utils.getBCHDigit(d) - G15_BCH))
23   }
24
25   // xor final data with mask pattern in order to ensure that
26   // no combination of Error Correction Level and data mask pattern
27   // will result in an all-zero data string
28   return ((data << 10) | d) ^ G15_MASK
29 }