From 25c133070fe344ceb3db0a1fc3270bd8e98fb5f7 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 13 Jan 2015 02:16:45 +0800 Subject: [PATCH] remove some methods --- .../3rd/zxing/common/BitArray.cs | 210 ------------------ .../3rd/zxing/common/BitMatrix.cs | 168 -------------- .../3rd/zxing/qrcode/encoder/Encoder.cs | 156 +------------ 3 files changed, 3 insertions(+), 531 deletions(-) diff --git a/shadowsocks-csharp/3rd/zxing/common/BitArray.cs b/shadowsocks-csharp/3rd/zxing/common/BitArray.cs index c3676142..994d5ef5 100755 --- a/shadowsocks-csharp/3rd/zxing/common/BitArray.cs +++ b/shadowsocks-csharp/3rd/zxing/common/BitArray.cs @@ -89,15 +89,6 @@ namespace ZXing.Common } } - /// Flips bit i. - /// - /// - /// bit to set - /// - public void flip(int i) - { - bits[i >> 5] ^= 1 << (i & 0x1F); - } private static int numberOfTrailingZeros(int num) { @@ -113,60 +104,6 @@ namespace ZXing.Common 0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5, 20, 8, 19, 18 }; - /// - /// Gets the next set. - /// - /// first bit to check - /// index of first bit that is set, starting from the given index, or size if none are set - /// at or beyond this given index - public int getNextSet(int from) - { - if (from >= size) - { - return size; - } - int bitsOffset = from >> 5; - int currentBits = bits[bitsOffset]; - // mask off lesser bits first - currentBits &= ~((1 << (from & 0x1F)) - 1); - while (currentBits == 0) - { - if (++bitsOffset == bits.Length) - { - return size; - } - currentBits = bits[bitsOffset]; - } - int result = (bitsOffset << 5) + numberOfTrailingZeros(currentBits); - return result > size ? size : result; - } - - /// - /// see getNextSet(int) - /// - /// - /// - public int getNextUnset(int from) - { - if (from >= size) - { - return size; - } - int bitsOffset = from >> 5; - int currentBits = ~bits[bitsOffset]; - // mask off lesser bits first - currentBits &= ~((1 << (from & 0x1F)) - 1); - while (currentBits == 0) - { - if (++bitsOffset == bits.Length) - { - return size; - } - currentBits = ~bits[bitsOffset]; - } - int result = (bitsOffset << 5) + numberOfTrailingZeros(currentBits); - return result > size ? size : result; - } /// Sets a block of 32 bits, starting at bit i. /// @@ -181,44 +118,6 @@ namespace ZXing.Common bits[i >> 5] = newBits; } - /// - /// Sets a range of bits. - /// - /// start of range, inclusive. - /// end of range, exclusive - public void setRange(int start, int end) - { - if (end < start) - { - throw new ArgumentException(); - } - if (end == start) - { - return; - } - end--; // will be easier to treat this as the last actually set bit -- inclusive - int firstInt = start >> 5; - int lastInt = end >> 5; - for (int i = firstInt; i <= lastInt; i++) - { - int firstBit = i > firstInt ? 0 : start & 0x1F; - int lastBit = i < lastInt ? 31 : end & 0x1F; - int mask; - if (firstBit == 0 && lastBit == 31) - { - mask = -1; - } - else - { - mask = 0; - for (int j = firstBit; j <= lastBit; j++) - { - mask |= 1 << j; - } - } - bits[i] |= mask; - } - } /// Clears all bits (sets to false). public void clear() @@ -230,59 +129,6 @@ namespace ZXing.Common } } - /// Efficient method to check if a range of bits is set, or not set. - /// - /// - /// start of range, inclusive. - /// - /// end of range, exclusive - /// - /// if true, checks that bits in range are set, otherwise checks that they are not set - /// - /// true iff all bits are set or not set in range, according to value argument - /// - /// IllegalArgumentException if end is less than or equal to start - public bool isRange(int start, int end, bool value) - { - if (end < start) - { - throw new System.ArgumentException(); - } - if (end == start) - { - return true; // empty range matches - } - end--; // will be easier to treat this as the last actually set bit -- inclusive - int firstInt = start >> 5; - int lastInt = end >> 5; - for (int i = firstInt; i <= lastInt; i++) - { - int firstBit = i > firstInt ? 0 : start & 0x1F; - int lastBit = i < lastInt ? 31 : end & 0x1F; - int mask; - if (firstBit == 0 && lastBit == 31) - { - mask = -1; - } - else - { - mask = 0; - for (int j = firstBit; j <= lastBit; j++) - { - mask |= 1 << j; - } - } - - // Return false if we're looking for 1s and the masked bits[i] isn't all 1s (that is, - // equals the mask, or we're looking for 0s and the masked portion is not all 0s - if ((bits[i] & mask) != (value ? mask : 0)) - { - return false; - } - } - return true; - } - /// /// Appends the bit. /// @@ -374,43 +220,6 @@ namespace ZXing.Common } } - /// Reverses all bits in the array. - public void reverse() - { - var newBits = new int[bits.Length]; - // reverse all int's first - var len = ((size - 1) >> 5); - var oldBitsLen = len + 1; - for (var i = 0; i < oldBitsLen; i++) - { - var x = (long)bits[i]; - x = ((x >> 1) & 0x55555555u) | ((x & 0x55555555u) << 1); - x = ((x >> 2) & 0x33333333u) | ((x & 0x33333333u) << 2); - x = ((x >> 4) & 0x0f0f0f0fu) | ((x & 0x0f0f0f0fu) << 4); - x = ((x >> 8) & 0x00ff00ffu) | ((x & 0x00ff00ffu) << 8); - x = ((x >> 16) & 0x0000ffffu) | ((x & 0x0000ffffu) << 16); - newBits[len - i] = (int)x; - } - // now correct the int's if the bit size isn't a multiple of 32 - if (size != oldBitsLen * 32) - { - var leftOffset = oldBitsLen * 32 - size; - var mask = 1; - for (var i = 0; i < 31 - leftOffset; i++) - mask = (mask << 1) | 1; - var currentInt = (newBits[0] >> leftOffset) & mask; - for (var i = 1; i < oldBitsLen; i++) - { - var nextInt = newBits[i]; - currentInt |= nextInt << (32 - leftOffset); - newBits[i - 1] = currentInt; - currentInt = (nextInt >> leftOffset) & mask; - } - newBits[oldBitsLen - 1] = currentInt; - } - bits = newBits; - } - private static int[] makeArray(int size) { return new int[(size + 31) >> 5]; @@ -454,25 +263,6 @@ namespace ZXing.Common return hash; } - /// - /// Returns a that represents this instance. - /// - /// - /// A that represents this instance. - /// - public override String ToString() - { - var result = new System.Text.StringBuilder(size); - for (int i = 0; i < size; i++) - { - if ((i & 0x07) == 0) - { - result.Append(' '); - } - result.Append(this[i] ? 'X' : '.'); - } - return result.ToString(); - } /// /// Erstellt ein neues Objekt, das eine Kopie der aktuellen Instanz darstellt. diff --git a/shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs b/shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs index 52dce4bd..9b250548 100755 --- a/shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs +++ b/shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs @@ -56,24 +56,6 @@ namespace ZXing.Common return height; } - } - /// This method is for compatibility with older code. It's only logical to call if the matrix - /// is square, so I'm throwing if that's not the case. - /// - /// - /// row/column dimension of this matrix - /// - public int Dimension - { - get - { - if (width != height) - { - throw new System.ArgumentException("Can't call getDimension() on a non-square matrix"); - } - return width; - } - } // A helper to construct a square matrix. @@ -141,15 +123,6 @@ namespace ZXing.Common bits[offset] ^= 1 << (x & 0x1f); } - /// Clears all bits (sets to false). - public void clear() - { - int max = bits.Length; - for (int i = 0; i < max; i++) - { - bits[i] = 0; - } - } ///

Sets a square region of the bit matrix to true.

/// @@ -226,90 +199,6 @@ namespace ZXing.Common Array.Copy(row.Array, 0, bits, y * rowSize, rowSize); } - /// - /// Modifies this {@code BitMatrix} to represent the same but rotated 180 degrees - /// - public void rotate180() - { - var width = Width; - var height = Height; - var topRow = new BitArray(width); - var bottomRow = new BitArray(width); - for (int i = 0; i < (height + 1)/2; i++) - { - topRow = getRow(i, topRow); - bottomRow = getRow(height - 1 - i, bottomRow); - topRow.reverse(); - bottomRow.reverse(); - setRow(i, bottomRow); - setRow(height - 1 - i, topRow); - } - } - - /// - /// This is useful in detecting the enclosing rectangle of a 'pure' barcode. - /// - /// {left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white - public int[] getEnclosingRectangle() - { - int left = width; - int top = height; - int right = -1; - int bottom = -1; - - for (int y = 0; y < height; y++) - { - for (int x32 = 0; x32 < rowSize; x32++) - { - int theBits = bits[y * rowSize + x32]; - if (theBits != 0) - { - if (y < top) - { - top = y; - } - if (y > bottom) - { - bottom = y; - } - if (x32 * 32 < left) - { - int bit = 0; - while ((theBits << (31 - bit)) == 0) - { - bit++; - } - if ((x32 * 32 + bit) < left) - { - left = x32 * 32 + bit; - } - } - if (x32 * 32 + 31 > right) - { - int bit = 31; - while (((int)((uint)theBits >> bit)) == 0) // (theBits >>> bit) - { - bit--; - } - if ((x32 * 32 + bit) > right) - { - right = x32 * 32 + bit; - } - } - } - } - } - - int widthTmp = right - left; - int heightTmp = bottom - top; - - if (widthTmp < 0 || heightTmp < 0) - { - return null; - } - - return new [] { left, top, widthTmp, heightTmp }; - } /// /// This is useful in detecting a corner of a 'pure' barcode. @@ -366,62 +255,5 @@ namespace ZXing.Common return new int[] { x, y }; } - public override bool Equals(object obj) - { - if (!(obj is BitMatrix)) - { - return false; - } - BitMatrix other = (BitMatrix)obj; - if (width != other.width || height != other.height || - rowSize != other.rowSize || bits.Length != other.bits.Length) - { - return false; - } - for (int i = 0; i < bits.Length; i++) - { - if (bits[i] != other.bits[i]) - { - return false; - } - } - return true; - } - - public override int GetHashCode() - { - int hash = width; - hash = 31 * hash + width; - hash = 31 * hash + height; - hash = 31 * hash + rowSize; - foreach (var bit in bits) - { - hash = 31 * hash + bit.GetHashCode(); - } - return hash; - } - - public override String ToString() - { - var result = new System.Text.StringBuilder(height * (width + 1)); - for (int y = 0; y < height; y++) - { - for (int x = 0; x < width; x++) - { - result.Append(this[x, y] ? "X " : " "); - } -#if WindowsCE - result.Append("\r\n"); -#else - result.AppendLine(""); -#endif - } - return result.ToString(); - } - - public object Clone() - { - return new BitMatrix(width, height, rowSize, (int[])bits.Clone()); - } } } \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/encoder/Encoder.cs b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/Encoder.cs index 32826a00..56c9a9a8 100755 --- a/shadowsocks-csharp/3rd/zxing/qrcode/encoder/Encoder.cs +++ b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/Encoder.cs @@ -201,73 +201,9 @@ namespace ZXing.QrCode.Internal /// private static Mode chooseMode(String content, String encoding) { - if ("Shift_JIS".Equals(encoding)) - { - - // Choose Kanji mode if all input are double-byte characters - return isOnlyDoubleByteKanji(content) ? Mode.KANJI : Mode.BYTE; - } - bool hasNumeric = false; - bool hasAlphanumeric = false; - for (int i = 0; i < content.Length; ++i) - { - char c = content[i]; - if (c >= '0' && c <= '9') - { - hasNumeric = true; - } - else if (getAlphanumericCode(c) != -1) - { - hasAlphanumeric = true; - } - else - { - return Mode.BYTE; - } - } - if (hasAlphanumeric) - { - - return Mode.ALPHANUMERIC; - } - if (hasNumeric) - { - - return Mode.NUMERIC; - } return Mode.BYTE; } - private static bool isOnlyDoubleByteKanji(String content) - { - byte[] bytes; - try - { - bytes = Encoding.GetEncoding("Shift_JIS").GetBytes(content); - } - catch (Exception ) - { - return false; - } - int length = bytes.Length; - if (length % 2 != 0) - { - return false; - } - for (int i = 0; i < length; i += 2) - { - - - int byte1 = bytes[i] & 0xFF; - if ((byte1 < 0x81 || byte1 > 0x9F) && (byte1 < 0xE0 || byte1 > 0xEB)) - { - - return false; - } - } - return true; - } - private static int chooseMaskPattern(BitArray bits, ErrorCorrectionLevel ecLevel, Version version, @@ -578,19 +514,10 @@ namespace ZXing.QrCode.Internal BitArray bits, String encoding) { - if (mode.Equals(Mode.NUMERIC)) - appendNumericBytes(content, bits); - else - if (mode.Equals(Mode.ALPHANUMERIC)) - appendAlphanumericBytes(content, bits); + if (mode.Equals(Mode.BYTE)) + append8BitBytes(content, bits, encoding); else - if (mode.Equals(Mode.BYTE)) - append8BitBytes(content, bits, encoding); - else - if (mode.Equals(Mode.KANJI)) - appendKanjiBytes(content, bits); - else - throw new WriterException("Invalid mode: " + mode); + throw new WriterException("Invalid mode: " + mode); } internal static void appendNumericBytes(String content, BitArray bits) @@ -625,37 +552,6 @@ namespace ZXing.QrCode.Internal } } - internal static void appendAlphanumericBytes(String content, BitArray bits) - { - int length = content.Length; - - int i = 0; - while (i < length) - { - int code1 = getAlphanumericCode(content[i]); - if (code1 == -1) - { - throw new WriterException(); - } - if (i + 1 < length) - { - int code2 = getAlphanumericCode(content[i + 1]); - if (code2 == -1) - { - throw new WriterException(); - } - // Encode two alphanumeric letters in 11 bits. - bits.appendBits(code1 * 45 + code2, 11); - i += 2; - } - else - { - // Encode one alphanumeric letter in six bits. - bits.appendBits(code1, 6); - i++; - } - } - } internal static void append8BitBytes(String content, BitArray bits, String encoding) { @@ -696,51 +592,5 @@ namespace ZXing.QrCode.Internal } } - internal static void appendKanjiBytes(String content, BitArray bits) - { - byte[] bytes; - try - { - bytes = Encoding.GetEncoding("Shift_JIS").GetBytes(content); - } - catch (Exception uee) - { - throw new WriterException(uee.Message, uee); - } - int length = bytes.Length; - for (int i = 0; i < length; i += 2) - { - int byte1 = bytes[i] & 0xFF; - int byte2 = bytes[i + 1] & 0xFF; - int code = (byte1 << 8) | byte2; - int subtracted = -1; - if (code >= 0x8140 && code <= 0x9ffc) - { - - subtracted = code - 0x8140; - } - else if (code >= 0xe040 && code <= 0xebbf) - { - subtracted = code - 0xc140; - } - if (subtracted == -1) - { - - throw new WriterException("Invalid byte sequence"); - } - int encoded = ((subtracted >> 8) * 0xc0) + (subtracted & 0xff); - bits.appendBits(encoded, 13); - } - } - - /* - private static void appendECI(CharacterSetECI eci, BitArray bits) - { - bits.appendBits(Mode.ECI.Bits, 4); - - // This is correct for values up to 127, which is all we need now. - bits.appendBits(eci.Value, 8); - } - * */ } } \ No newline at end of file