Browse Source

remove some methods

tags/2.3
clowwindy 9 years ago
parent
commit
25c133070f
3 changed files with 3 additions and 531 deletions
  1. +0
    -210
      shadowsocks-csharp/3rd/zxing/common/BitArray.cs
  2. +0
    -168
      shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs
  3. +3
    -153
      shadowsocks-csharp/3rd/zxing/qrcode/encoder/Encoder.cs

+ 0
- 210
shadowsocks-csharp/3rd/zxing/common/BitArray.cs View File

@@ -89,15 +89,6 @@ namespace ZXing.Common
} }
} }
/// <summary> Flips bit i.
///
/// </summary>
/// <param name="i">bit to set
/// </param>
public void flip(int i)
{
bits[i >> 5] ^= 1 << (i & 0x1F);
}
private static int numberOfTrailingZeros(int num) 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 0, 25, 22, 31, 15, 29, 10, 12, 6, 0, 21, 14, 9, 5, 20, 8, 19, 18
}; };
/// <summary>
/// Gets the next set.
/// </summary>
/// <param name="from">first bit to check</param>
/// <returns>index of first bit that is set, starting from the given index, or size if none are set
/// at or beyond this given index</returns>
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;
}
/// <summary>
/// see getNextSet(int)
/// </summary>
/// <param name="from"></param>
/// <returns></returns>
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;
}
/// <summary> Sets a block of 32 bits, starting at bit i. /// <summary> Sets a block of 32 bits, starting at bit i.
/// ///
@@ -181,44 +118,6 @@ namespace ZXing.Common
bits[i >> 5] = newBits; bits[i >> 5] = newBits;
} }
/// <summary>
/// Sets a range of bits.
/// </summary>
/// <param name="start">start of range, inclusive.</param>
/// <param name="end">end of range, exclusive</param>
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;
}
}
/// <summary> Clears all bits (sets to false).</summary> /// <summary> Clears all bits (sets to false).</summary>
public void clear() public void clear()
@@ -230,59 +129,6 @@ namespace ZXing.Common
} }
} }
/// <summary> Efficient method to check if a range of bits is set, or not set.
///
/// </summary>
/// <param name="start">start of range, inclusive.
/// </param>
/// <param name="end">end of range, exclusive
/// </param>
/// <param name="value">if true, checks that bits in range are set, otherwise checks that they are not set
/// </param>
/// <returns> true iff all bits are set or not set in range, according to value argument
/// </returns>
/// <throws> IllegalArgumentException if end is less than or equal to start </throws>
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;
}
/// <summary> /// <summary>
/// Appends the bit. /// Appends the bit.
/// </summary> /// </summary>
@@ -374,43 +220,6 @@ namespace ZXing.Common
} }
} }
/// <summary> Reverses all bits in the array.</summary>
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) private static int[] makeArray(int size)
{ {
return new int[(size + 31) >> 5]; return new int[(size + 31) >> 5];
@@ -454,25 +263,6 @@ namespace ZXing.Common
return hash; return hash;
} }
/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
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();
}
/// <summary> /// <summary>
/// Erstellt ein neues Objekt, das eine Kopie der aktuellen Instanz darstellt. /// Erstellt ein neues Objekt, das eine Kopie der aktuellen Instanz darstellt.


+ 0
- 168
shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs View File

@@ -56,24 +56,6 @@ namespace ZXing.Common
return height; return height;
} }
}
/// <summary> 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.
///
/// </summary>
/// <returns> row/column dimension of this matrix
/// </returns>
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. // A helper to construct a square matrix.
@@ -141,15 +123,6 @@ namespace ZXing.Common
bits[offset] ^= 1 << (x & 0x1f); bits[offset] ^= 1 << (x & 0x1f);
} }
/// <summary> Clears all bits (sets to false).</summary>
public void clear()
{
int max = bits.Length;
for (int i = 0; i < max; i++)
{
bits[i] = 0;
}
}
/// <summary> <p>Sets a square region of the bit matrix to true.</p> /// <summary> <p>Sets a square region of the bit matrix to true.</p>
/// ///
@@ -226,90 +199,6 @@ namespace ZXing.Common
Array.Copy(row.Array, 0, bits, y * rowSize, rowSize); Array.Copy(row.Array, 0, bits, y * rowSize, rowSize);
} }
/// <summary>
/// Modifies this {@code BitMatrix} to represent the same but rotated 180 degrees
/// </summary>
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);
}
}
/// <summary>
/// This is useful in detecting the enclosing rectangle of a 'pure' barcode.
/// </summary>
/// <returns>{left,top,width,height} enclosing rectangle of all 1 bits, or null if it is all white</returns>
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 };
}
/// <summary> /// <summary>
/// This is useful in detecting a corner of a 'pure' barcode. /// This is useful in detecting a corner of a 'pure' barcode.
@@ -366,62 +255,5 @@ namespace ZXing.Common
return new int[] { x, y }; 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());
}
} }
} }

+ 3
- 153
shadowsocks-csharp/3rd/zxing/qrcode/encoder/Encoder.cs View File

@@ -201,73 +201,9 @@ namespace ZXing.QrCode.Internal
/// <returns></returns> /// <returns></returns>
private static Mode chooseMode(String content, String encoding) 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; 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, private static int chooseMaskPattern(BitArray bits,
ErrorCorrectionLevel ecLevel, ErrorCorrectionLevel ecLevel,
Version version, Version version,
@@ -578,19 +514,10 @@ namespace ZXing.QrCode.Internal
BitArray bits, BitArray bits,
String encoding) 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 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) 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) 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);
}
* */
} }
} }

Loading…
Cancel
Save