-/*\r
-* Copyright 2008 ZXing authors\r
+/*\r
+* Copyright 2007 ZXing authors\r
*\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* See the License for the specific language governing permissions and\r
* limitations under the License.\r
*/\r
+using System;\r
namespace com.google.zxing.common\r
{\r
- using System;\r
- using System.Text;\r
-\r
- /// <summary> A class which wraps a 2D array of bytes. The default usage is signed. If you want to use it as a\r
- /// unsigned container, it's up to you to do byteValue & 0xff at each location.\r
- /// *\r
- /// JAVAPORT: I'm not happy about the argument ordering throughout the file, as I always like to have\r
- /// the horizontal component first, but this is for compatibility with the C++ code. The original\r
- /// code was a 2D array of ints, but since it only ever gets assigned -1, 0, and 1, I'm going to use\r
- /// less memory and go with bytes.\r
- /// *\r
- /// </summary>\r
- /// <author> dswitkin@google.com (Daniel Switkin)\r
- /// \r
- /// </author>\r
- public sealed class BitArray\r
- {\r
- // TODO: I have changed these members to be public so ProGuard can inline get() and set(). Ideally\r
- // they'd be private and we'd use the -allowaccessmodification flag, but Dalvik rejects the\r
- // resulting binary at runtime on Android. If we find a solution to this, these should be changed\r
- // back to private.\r
- public int[] bits;\r
- public int Size;\r
-\r
- public BitArray(int size) {\r
- if (size < 1) {\r
- throw new Exception("size must be at least 1");\r
- }\r
- this.Size = size;\r
- this.bits = makeArray(size);\r
- }\r
-\r
- public int getSize() {\r
- return Size;\r
- }\r
-\r
- /**\r
- * @param i bit to get\r
- * @return true iff bit i is set\r
- */\r
- public bool get(int i) {\r
- return (bits[i >> 5] & (1 << (i & 0x1F))) != 0;\r
- }\r
-\r
- /**\r
- * Sets bit i.\r
- *\r
- * @param i bit to set\r
- */\r
- public void set(int i) {\r
- bits[i >> 5] |= 1 << (i & 0x1F);\r
- }\r
-\r
- /**\r
- * Sets a block of 32 bits, starting at bit i.\r
- *\r
- * @param i first bit to set\r
- * @param newBits the new value of the next 32 bits. Note again that the least-significant bit\r
- * corresponds to bit i, the next-least-significant to i+1, and so on.\r
- */\r
- public void setBulk(int i, int newBits) {\r
- bits[i >> 5] = newBits;\r
- }\r
-\r
- /**\r
- * Clears all bits (sets to false).\r
- */\r
- public void clear() {\r
- int max = bits.Length;\r
- for (int i = 0; i < max; i++) {\r
- bits[i] = 0;\r
- }\r
- }\r
-\r
- /**\r
- * Efficient method to check if a range of bits is set, or not set.\r
- *\r
- * @param start start of range, inclusive.\r
- * @param end end of range, exclusive\r
- * @param value if true, checks that bits in range are set, otherwise checks that they are not set\r
- * @return true iff all bits are set or not set in range, according to value argument\r
- * @throws IllegalArgumentException if end is less than or equal to start\r
- */\r
- public bool isRange(int start, int end, bool value) {\r
- if (end < start) {\r
- throw new Exception();\r
- }\r
- if (end == start) {\r
- return true; // empty range matches\r
- }\r
- end--; // will be easier to treat this as the last actually set bit -- inclusive \r
- int firstInt = start >> 5;\r
- int lastInt = end >> 5;\r
- for (int i = firstInt; i <= lastInt; i++) {\r
- int firstBit = i > firstInt ? 0 : start & 0x1F;\r
- int lastBit = i < lastInt ? 31 : end & 0x1F;\r
- int mask;\r
- if (firstBit == 0 && lastBit == 31) {\r
- mask = -1;\r
- } else {\r
- mask = 0;\r
- for (int j = firstBit; j <= lastBit; j++) {\r
- mask |= 1 << j;\r
- }\r
- }\r
-\r
- // Return false if we're looking for 1s and the masked bits[i] isn't all 1s (that is,\r
- // equals the mask, or we're looking for 0s and the masked portion is not all 0s\r
- if ((bits[i] & mask) != (value ? mask : 0)) {\r
- return false;\r
- }\r
- }\r
- return true;\r
- }\r
-\r
- /**\r
- * @return underlying array of ints. The first element holds the first 32 bits, and the least\r
- * significant bit is bit 0.\r
- */\r
- public int[] getBitArray() {\r
- return bits;\r
- }\r
-\r
- /**\r
- * Reverses all bits in the array.\r
- */\r
- public void reverse() {\r
- int[] newBits = makeArray(Size);\r
- int max = newBits.Length;\r
- for (int i = 0; i < max; i++) {\r
- newBits[i] = 0;\r
- }\r
- int size = this.Size;\r
- for (int i = 0; i < size; i++) {\r
- if (get(size - i - 1)) {\r
- newBits[i >> 5] |= 1 << (i & 0x1F);\r
- }\r
- }\r
- bits = newBits;\r
- }\r
-\r
- private static int[] makeArray(int size) {\r
- int arraySize = size >> 5;\r
- if ((size & 0x1F) != 0) {\r
- arraySize++;\r
- }\r
- return new int[arraySize];\r
- }\r
- \r
- public String toString() {\r
- StringBuilder result = new StringBuilder(Size);\r
- for (int i = 0; i < Size; i++) {\r
- if (i % 8 == 0) {\r
- result.Append(' ');\r
- }\r
- result.Append(get(i) ? 'X' : '.');\r
- }\r
- return result.ToString();\r
- }\r
- }\r
+ \r
+ /// <summary> <p>A simple, fast array of bits, represented compactly by an array of ints internally.</p>\r
+ /// \r
+ /// </summary>\r
+ /// <author> Sean Owen\r
+ /// </author>\r
+ /// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source \r
+ /// </author>\r
+ public sealed class BitArray\r
+ {\r
+ public int Size\r
+ {\r
+ get\r
+ {\r
+ return size;\r
+ }\r
+ \r
+ }\r
+ \r
+ // TODO: I have changed these members to be public so ProGuard can inline get() and set(). Ideally\r
+ // they'd be private and we'd use the -allowaccessmodification flag, but Dalvik rejects the\r
+ // resulting binary at runtime on Android. If we find a solution to this, these should be changed\r
+ // back to private.\r
+ public int[] bits;\r
+ //UPGRADE_NOTE: Final was removed from the declaration of 'size '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"\r
+ public int size;\r
+ \r
+ public BitArray(int size)\r
+ {\r
+ if (size < 1)\r
+ {\r
+ throw new System.ArgumentException("size must be at least 1");\r
+ }\r
+ this.size = size;\r
+ this.bits = makeArray(size);\r
+ }\r
+ \r
+ /// <param name="i">bit to get\r
+ /// </param>\r
+ /// <returns> true iff bit i is set\r
+ /// </returns>\r
+ public bool get_Renamed(int i)\r
+ {\r
+ return (bits[i >> 5] & (1 << (i & 0x1F))) != 0;\r
+ }\r
+ \r
+ /// <summary> Sets bit i.\r
+ /// \r
+ /// </summary>\r
+ /// <param name="i">bit to set\r
+ /// </param>\r
+ public void set_Renamed(int i)\r
+ {\r
+ bits[i >> 5] |= 1 << (i & 0x1F);\r
+ }\r
+ \r
+ /// <summary> Flips bit i.\r
+ /// \r
+ /// </summary>\r
+ /// <param name="i">bit to set\r
+ /// </param>\r
+ public void flip(int i)\r
+ {\r
+ bits[i >> 5] ^= 1 << (i & 0x1F);\r
+ }\r
+ \r
+ /// <summary> Sets a block of 32 bits, starting at bit i.\r
+ /// \r
+ /// </summary>\r
+ /// <param name="i">first bit to set\r
+ /// </param>\r
+ /// <param name="newBits">the new value of the next 32 bits. Note again that the least-significant bit\r
+ /// corresponds to bit i, the next-least-significant to i+1, and so on.\r
+ /// </param>\r
+ public void setBulk(int i, int newBits)\r
+ {\r
+ bits[i >> 5] = newBits;\r
+ }\r
+ \r
+ /// <summary> Clears all bits (sets to false).</summary>\r
+ public void clear()\r
+ {\r
+ int max = bits.Length;\r
+ for (int i = 0; i < max; i++)\r
+ {\r
+ bits[i] = 0;\r
+ }\r
+ }\r
+ \r
+ /// <summary> Efficient method to check if a range of bits is set, or not set.\r
+ /// \r
+ /// </summary>\r
+ /// <param name="start">start of range, inclusive.\r
+ /// </param>\r
+ /// <param name="end">end of range, exclusive\r
+ /// </param>\r
+ /// <param name="value">if true, checks that bits in range are set, otherwise checks that they are not set\r
+ /// </param>\r
+ /// <returns> true iff all bits are set or not set in range, according to value argument\r
+ /// </returns>\r
+ /// <throws> IllegalArgumentException if end is less than or equal to start </throws>\r
+ public bool isRange(int start, int end, bool value_Renamed)\r
+ {\r
+ if (end < start)\r
+ {\r
+ throw new System.ArgumentException();\r
+ }\r
+ if (end == start)\r
+ {\r
+ return true; // empty range matches\r
+ }\r
+ end--; // will be easier to treat this as the last actually set bit -- inclusive \r
+ int firstInt = start >> 5;\r
+ int lastInt = end >> 5;\r
+ for (int i = firstInt; i <= lastInt; i++)\r
+ {\r
+ int firstBit = i > firstInt?0:start & 0x1F;\r
+ int lastBit = i < lastInt?31:end & 0x1F;\r
+ int mask;\r
+ if (firstBit == 0 && lastBit == 31)\r
+ {\r
+ mask = - 1;\r
+ }\r
+ else\r
+ {\r
+ mask = 0;\r
+ for (int j = firstBit; j <= lastBit; j++)\r
+ {\r
+ mask |= 1 << j;\r
+ }\r
+ }\r
+ \r
+ // Return false if we're looking for 1s and the masked bits[i] isn't all 1s (that is,\r
+ // equals the mask, or we're looking for 0s and the masked portion is not all 0s\r
+ if ((bits[i] & mask) != (value_Renamed?mask:0))\r
+ {\r
+ return false;\r
+ }\r
+ }\r
+ return true;\r
+ }\r
+ \r
+ /// <returns> underlying array of ints. The first element holds the first 32 bits, and the least\r
+ /// significant bit is bit 0.\r
+ /// </returns>\r
+ public int[] getBitArray()\r
+ {\r
+ return bits;\r
+ }\r
+ \r
+ /// <summary> Reverses all bits in the array.</summary>\r
+ public void reverse()\r
+ {\r
+ int[] newBits = new int[bits.Length];\r
+ int size = this.size;\r
+ for (int i = 0; i < size; i++)\r
+ {\r
+ if (get_Renamed(size - i - 1))\r
+ {\r
+ newBits[i >> 5] |= 1 << (i & 0x1F);\r
+ }\r
+ }\r
+ bits = newBits;\r
+ }\r
+ \r
+ private static int[] makeArray(int size)\r
+ {\r
+ int arraySize = size >> 5;\r
+ if ((size & 0x1F) != 0)\r
+ {\r
+ arraySize++;\r
+ }\r
+ return new int[arraySize];\r
+ }\r
+ \r
+ public override System.String ToString()\r
+ {\r
+ System.Text.StringBuilder result = new System.Text.StringBuilder(size);\r
+ for (int i = 0; i < size; i++)\r
+ {\r
+ if ((i & 0x07) == 0)\r
+ {\r
+ result.Append(' ');\r
+ }\r
+ result.Append(get_Renamed(i)?'X':'.');\r
+ }\r
+ return result.ToString();\r
+ }\r
+ }\r
}
\ No newline at end of file