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