MCPcopy Create free account
hub / github.com/LazarSoft/jsqrcode / BitMatrixParser

Function BitMatrixParser

src/bmparser.js:26–203  ·  view source on GitHub ↗
(bitMatrix)

Source from the content-addressed store, hash-verified

24
25
26function BitMatrixParser(bitMatrix)
27{
28 var dimension = bitMatrix.Dimension;
29 if (dimension < 21 || (dimension & 0x03) != 1)
30 {
31 throw "Error BitMatrixParser";
32 }
33 this.bitMatrix = bitMatrix;
34 this.parsedVersion = null;
35 this.parsedFormatInfo = null;
36
37 this.copyBit=function( i, j, versionBits)
38 {
39 return this.bitMatrix.get_Renamed(i, j)?(versionBits << 1) | 0x1:versionBits << 1;
40 }
41
42 this.readFormatInformation=function()
43 {
44 if (this.parsedFormatInfo != null)
45 {
46 return this.parsedFormatInfo;
47 }
48
49 // Read top-left format info bits
50 var formatInfoBits = 0;
51 for (var i = 0; i < 6; i++)
52 {
53 formatInfoBits = this.copyBit(i, 8, formatInfoBits);
54 }
55 // .. and skip a bit in the timing pattern ...
56 formatInfoBits = this.copyBit(7, 8, formatInfoBits);
57 formatInfoBits = this.copyBit(8, 8, formatInfoBits);
58 formatInfoBits = this.copyBit(8, 7, formatInfoBits);
59 // .. and skip a bit in the timing pattern ...
60 for (var j = 5; j >= 0; j--)
61 {
62 formatInfoBits = this.copyBit(8, j, formatInfoBits);
63 }
64
65 this.parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits);
66 if (this.parsedFormatInfo != null)
67 {
68 return this.parsedFormatInfo;
69 }
70
71 // Hmm, failed. Try the top-right/bottom-left pattern
72 var dimension = this.bitMatrix.Dimension;
73 formatInfoBits = 0;
74 var iMin = dimension - 8;
75 for (var i = dimension - 1; i >= iMin; i--)
76 {
77 formatInfoBits = this.copyBit(i, 8, formatInfoBits);
78 }
79 for (var j = dimension - 7; j < dimension; j++)
80 {
81 formatInfoBits = this.copyBit(8, j, formatInfoBits);
82 }
83

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected