Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright 2012 ZXing authors
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. @class ZXBitArray, ZXIntArray;
  17. /**
  18. * Represents a 2D matrix of bits. In function arguments below, and throughout the common
  19. * module, x is the column position, and y is the row position. The ordering is always x, y.
  20. * The origin is at the top-left.
  21. *
  22. * Internally the bits are represented in a 1-D array of 32-bit ints. However, each row begins
  23. * with a new NSInteger. This is done intentionally so that we can copy out a row into a BitArray very
  24. * efficiently.
  25. *
  26. * The ordering of bits is row-major. Within each NSInteger, the least significant bits are used first,
  27. * meaning they represent lower x values. This is compatible with BitArray's implementation.
  28. */
  29. @interface ZXBitMatrix : NSObject <NSCopying>
  30. /**
  31. * @return The width of the matrix
  32. */
  33. @property (nonatomic, assign, readonly) int width;
  34. /**
  35. * @return The height of the matrix
  36. */
  37. @property (nonatomic, assign, readonly) int height;
  38. @property (nonatomic, assign, readonly) int32_t *bits;
  39. /**
  40. * @return The row size of the matrix
  41. */
  42. @property (nonatomic, assign, readonly) int rowSize;
  43. // A helper to construct a square matrix.
  44. - (id)initWithDimension:(int)dimension;
  45. - (id)initWithWidth:(int)width height:(int)height;
  46. + (ZXBitMatrix *)parse:(NSString *)stringRepresentation
  47. setString:(NSString *)setString
  48. unsetString:(NSString *)unsetString;
  49. /**
  50. * Gets the requested bit, where true means black.
  51. *
  52. * @param x The horizontal component (i.e. which column)
  53. * @param y The vertical component (i.e. which row)
  54. * @return value of given bit in matrix
  55. */
  56. - (BOOL)getX:(int)x y:(int)y;
  57. /**
  58. * Sets the given bit to true.
  59. *
  60. * @param x The horizontal component (i.e. which column)
  61. * @param y The vertical component (i.e. which row)
  62. */
  63. - (void)setX:(int)x y:(int)y;
  64. - (void)unsetX:(int)x y:(int)y;
  65. /**
  66. * Flips the given bit.
  67. *
  68. * @param x The horizontal component (i.e. which column)
  69. * @param y The vertical component (i.e. which row)
  70. */
  71. - (void)flipX:(int)x y:(int)y;
  72. /**
  73. * Exclusive-or (XOR): Flip the bit in this ZXBitMatrix if the corresponding
  74. * mask bit is set.
  75. *
  76. * @param mask XOR mask
  77. */
  78. - (void)xor:(ZXBitMatrix *)mask;
  79. /**
  80. * Clears all bits (sets to false).
  81. */
  82. - (void)clear;
  83. /**
  84. * Sets a square region of the bit matrix to true.
  85. *
  86. * @param left The horizontal position to begin at (inclusive)
  87. * @param top The vertical position to begin at (inclusive)
  88. * @param width The width of the region
  89. * @param height The height of the region
  90. */
  91. - (void)setRegionAtLeft:(int)left top:(int)top width:(int)width height:(int)height;
  92. /**
  93. * A fast method to retrieve one row of data from the matrix as a ZXBitArray.
  94. *
  95. * @param y The row to retrieve
  96. * @param row An optional caller-allocated BitArray, will be allocated if null or too small
  97. * @return The resulting BitArray - this reference should always be used even when passing
  98. * your own row
  99. */
  100. - (ZXBitArray *)rowAtY:(int)y row:(ZXBitArray *)row;
  101. /**
  102. * @param y row to set
  103. * @param row ZXBitArray to copy from
  104. */
  105. - (void)setRowAtY:(int)y row:(ZXBitArray *)row;
  106. /**
  107. * Modifies this ZXBitMatrix to represent the same but rotated 180 degrees
  108. */
  109. - (void)rotate180;
  110. /**
  111. * This is useful in detecting the enclosing rectangle of a 'pure' barcode.
  112. *
  113. * @return {left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white
  114. */
  115. - (ZXIntArray *)enclosingRectangle;
  116. /**
  117. * This is useful in detecting a corner of a 'pure' barcode.
  118. *
  119. * @return {x,y} coordinate of top-left-most 1 bit, or null if it is all white
  120. */
  121. - (ZXIntArray *)topLeftOnBit;
  122. - (ZXIntArray *)bottomRightOnBit;
  123. - (NSString *)descriptionWithSetString:(NSString *)setString unsetString:(NSString *)unsetString;
  124. /**
  125. * @deprecated call descriptionWithSetString:unsetString: only, which uses \n line separator always
  126. */
  127. - (NSString *)descriptionWithSetString:(NSString *)setString unsetString:(NSString *)unsetString
  128. lineSeparator:(NSString *)lineSeparator DEPRECATED_ATTRIBUTE;
  129. @end