not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
3.6 KiB

  1. /*
  2. Ported to JavaScript by Lazar Laszlo 2011
  3. lazarsoft@gmail.com, www.lazarsoft.info
  4. */
  5. /*
  6. *
  7. * Copyright 2007 ZXing authors
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License");
  10. * you may not use this file except in compliance with the License.
  11. * You may obtain a copy of the License at
  12. *
  13. * http://www.apache.org/licenses/LICENSE-2.0
  14. *
  15. * Unless required by applicable law or agreed to in writing, software
  16. * distributed under the License is distributed on an "AS IS" BASIS,
  17. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. */
  21. var DataMask = {};
  22. DataMask.forReference = function(reference)
  23. {
  24. if (reference < 0 || reference > 7)
  25. {
  26. throw "System.ArgumentException";
  27. }
  28. return DataMask.DATA_MASKS[reference];
  29. }
  30. function DataMask000()
  31. {
  32. this.unmaskBitMatrix=function(bits, dimension)
  33. {
  34. for (var i = 0; i < dimension; i++)
  35. {
  36. for (var j = 0; j < dimension; j++)
  37. {
  38. if (this.isMasked(i, j))
  39. {
  40. bits.flip(j, i);
  41. }
  42. }
  43. }
  44. }
  45. this.isMasked=function( i, j)
  46. {
  47. return ((i + j) & 0x01) == 0;
  48. }
  49. }
  50. function DataMask001()
  51. {
  52. this.unmaskBitMatrix=function(bits, dimension)
  53. {
  54. for (var i = 0; i < dimension; i++)
  55. {
  56. for (var j = 0; j < dimension; j++)
  57. {
  58. if (this.isMasked(i, j))
  59. {
  60. bits.flip(j, i);
  61. }
  62. }
  63. }
  64. }
  65. this.isMasked=function( i, j)
  66. {
  67. return (i & 0x01) == 0;
  68. }
  69. }
  70. function DataMask010()
  71. {
  72. this.unmaskBitMatrix=function(bits, dimension)
  73. {
  74. for (var i = 0; i < dimension; i++)
  75. {
  76. for (var j = 0; j < dimension; j++)
  77. {
  78. if (this.isMasked(i, j))
  79. {
  80. bits.flip(j, i);
  81. }
  82. }
  83. }
  84. }
  85. this.isMasked=function( i, j)
  86. {
  87. return j % 3 == 0;
  88. }
  89. }
  90. function DataMask011()
  91. {
  92. this.unmaskBitMatrix=function(bits, dimension)
  93. {
  94. for (var i = 0; i < dimension; i++)
  95. {
  96. for (var j = 0; j < dimension; j++)
  97. {
  98. if (this.isMasked(i, j))
  99. {
  100. bits.flip(j, i);
  101. }
  102. }
  103. }
  104. }
  105. this.isMasked=function( i, j)
  106. {
  107. return (i + j) % 3 == 0;
  108. }
  109. }
  110. function DataMask100()
  111. {
  112. this.unmaskBitMatrix=function(bits, dimension)
  113. {
  114. for (var i = 0; i < dimension; i++)
  115. {
  116. for (var j = 0; j < dimension; j++)
  117. {
  118. if (this.isMasked(i, j))
  119. {
  120. bits.flip(j, i);
  121. }
  122. }
  123. }
  124. }
  125. this.isMasked=function( i, j)
  126. {
  127. return (((URShift(i, 1)) + (j / 3)) & 0x01) == 0;
  128. }
  129. }
  130. function DataMask101()
  131. {
  132. this.unmaskBitMatrix=function(bits, dimension)
  133. {
  134. for (var i = 0; i < dimension; i++)
  135. {
  136. for (var j = 0; j < dimension; j++)
  137. {
  138. if (this.isMasked(i, j))
  139. {
  140. bits.flip(j, i);
  141. }
  142. }
  143. }
  144. }
  145. this.isMasked=function( i, j)
  146. {
  147. var temp = i * j;
  148. return (temp & 0x01) + (temp % 3) == 0;
  149. }
  150. }
  151. function DataMask110()
  152. {
  153. this.unmaskBitMatrix=function(bits, dimension)
  154. {
  155. for (var i = 0; i < dimension; i++)
  156. {
  157. for (var j = 0; j < dimension; j++)
  158. {
  159. if (this.isMasked(i, j))
  160. {
  161. bits.flip(j, i);
  162. }
  163. }
  164. }
  165. }
  166. this.isMasked=function( i, j)
  167. {
  168. var temp = i * j;
  169. return (((temp & 0x01) + (temp % 3)) & 0x01) == 0;
  170. }
  171. }
  172. function DataMask111()
  173. {
  174. this.unmaskBitMatrix=function(bits, dimension)
  175. {
  176. for (var i = 0; i < dimension; i++)
  177. {
  178. for (var j = 0; j < dimension; j++)
  179. {
  180. if (this.isMasked(i, j))
  181. {
  182. bits.flip(j, i);
  183. }
  184. }
  185. }
  186. }
  187. this.isMasked=function( i, j)
  188. {
  189. return ((((i + j) & 0x01) + ((i * j) % 3)) & 0x01) == 0;
  190. }
  191. }
  192. DataMask.DATA_MASKS = new Array(new DataMask000(), new DataMask001(), new DataMask010(), new DataMask011(), new DataMask100(), new DataMask101(), new DataMask110(), new DataMask111());