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.

110 lines
2.5 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. function BitMatrix( width, height)
  22. {
  23. if(!height)
  24. height=width;
  25. if (width < 1 || height < 1)
  26. {
  27. throw "Both dimensions must be greater than 0";
  28. }
  29. this.width = width;
  30. this.height = height;
  31. var rowSize = width >> 5;
  32. if ((width & 0x1f) != 0)
  33. {
  34. rowSize++;
  35. }
  36. this.rowSize = rowSize;
  37. this.bits = new Array(rowSize * height);
  38. for(var i=0;i<this.bits.length;i++)
  39. this.bits[i]=0;
  40. this.__defineGetter__("Width", function()
  41. {
  42. return this.width;
  43. });
  44. this.__defineGetter__("Height", function()
  45. {
  46. return this.height;
  47. });
  48. this.__defineGetter__("Dimension", function()
  49. {
  50. if (this.width != this.height)
  51. {
  52. throw "Can't call getDimension() on a non-square matrix";
  53. }
  54. return this.width;
  55. });
  56. this.get_Renamed=function( x, y)
  57. {
  58. var offset = y * this.rowSize + (x >> 5);
  59. return ((URShift(this.bits[offset], (x & 0x1f))) & 1) != 0;
  60. }
  61. this.set_Renamed=function( x, y)
  62. {
  63. var offset = y * this.rowSize + (x >> 5);
  64. this.bits[offset] |= 1 << (x & 0x1f);
  65. }
  66. this.flip=function( x, y)
  67. {
  68. var offset = y * this.rowSize + (x >> 5);
  69. this.bits[offset] ^= 1 << (x & 0x1f);
  70. }
  71. this.clear=function()
  72. {
  73. var max = this.bits.length;
  74. for (var i = 0; i < max; i++)
  75. {
  76. this.bits[i] = 0;
  77. }
  78. }
  79. this.setRegion=function( left, top, width, height)
  80. {
  81. if (top < 0 || left < 0)
  82. {
  83. throw "Left and top must be nonnegative";
  84. }
  85. if (height < 1 || width < 1)
  86. {
  87. throw "Height and width must be at least 1";
  88. }
  89. var right = left + width;
  90. var bottom = top + height;
  91. if (bottom > this.height || right > this.width)
  92. {
  93. throw "The region must fit inside the matrix";
  94. }
  95. for (var y = top; y < bottom; y++)
  96. {
  97. var offset = y * this.rowSize;
  98. for (var x = left; x < right; x++)
  99. {
  100. this.bits[offset + (x >> 5)] |= 1 << (x & 0x1f);
  101. }
  102. }
  103. }
  104. }