Browse Source

clean zxing

tags/2.3
clowwindy 9 years ago
parent
commit
42f976cdc6
11 changed files with 7 additions and 1854 deletions
  1. +0
    -328
      shadowsocks-csharp/3rd/zxing/BitArray.cs
  2. +0
    -435
      shadowsocks-csharp/3rd/zxing/BitMatrix.cs
  3. +0
    -131
      shadowsocks-csharp/3rd/zxing/EncodeHintType.cs
  4. +3
    -239
      shadowsocks-csharp/3rd/zxing/Encoder.cs
  5. +0
    -197
      shadowsocks-csharp/3rd/zxing/FormatInformation.cs
  6. +0
    -40
      shadowsocks-csharp/3rd/zxing/GenericGF.cs
  7. +0
    -101
      shadowsocks-csharp/3rd/zxing/GenericGFPoly.cs
  8. +0
    -34
      shadowsocks-csharp/3rd/zxing/QRCode.cs
  9. +1
    -344
      shadowsocks-csharp/3rd/zxing/Version.cs
  10. +2
    -2
      shadowsocks-csharp/View/QRCodeForm.cs
  11. +1
    -3
      shadowsocks-csharp/shadowsocks-csharp.csproj

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

@@ -49,11 +49,6 @@ namespace ZXing.Common
{
return (bits[i >> 5] & (1 << (i & 0x1F))) != 0;
}
set
{
if (value)
bits[i >> 5] |= 1 << (i & 0x1F);
}
}
public BitArray()
@@ -62,22 +57,6 @@ namespace ZXing.Common
this.bits = new int[1];
}
public BitArray(int size)
{
if (size < 1)
{
throw new ArgumentException("size must be at least 1");
}
this.size = size;
this.bits = makeArray(size);
}
// For testing only
private BitArray(int[] bits, int size)
{
this.bits = bits;
this.size = size;
}
private void ensureCapacity(int size)
{
@@ -89,200 +68,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)
{
var index = (-num & num)%37;
if (index < 0)
index *= -1;
return _lookup[index];
}
private static readonly int[] _lookup =
{
32, 0, 1, 26, 2, 23, 27, 0, 3, 16, 24, 30, 28, 11, 0, 13, 4, 7, 17,
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">index to start looking for unset bit</param>
/// <returns>index of next unset bit, or <see cref="Size"/> if none are unset until the end</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>
/// <param name="i">first bit to set
/// </param>
/// <param name="newBits">the new value of the next 32 bits. Note again that the least-significant bit
/// corresponds to bit i, the next-least-significant to i+1, and so on.
/// </param>
public void setBulk(int i, int 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>
public void clear()
{
int max = bits.Length;
for (int i = 0; i < max; i++)
{
bits[i] = 0;
}
}
/// <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>
/// Appends the bit.
/// </summary>
@@ -297,14 +82,6 @@ namespace ZXing.Common
size++;
}
/// <returns> underlying array of ints. The first element holds the first 32 bits, and the least
/// significant bit is bit 0.
/// </returns>
public int[] Array
{
get { return bits; }
}
/// <summary>
/// Appends the least-significant bits, from value, in order from most-significant to
/// least-significant. For example, appending 6 bits from 0x000001E will append the bits
@@ -374,115 +151,10 @@ 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)
{
return new int[(size + 31) >> 5];
}
/// <summary>
/// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
/// </summary>
/// <param name="o">The <see cref="System.Object"/> to compare with this instance.</param>
/// <returns>
/// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(Object o)
{
var other = o as BitArray;
if (other == null)
return false;
if (size != other.size)
return false;
for (var index = 0; index < size; index++)
{
if (bits[index] != other.bits[index])
return false;
}
return true;
}
/// <summary>
/// Returns a hash code for this instance.
/// </summary>
/// <returns>
/// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
/// </returns>
public override int GetHashCode()
{
var hash = size;
foreach (var bit in bits)
{
hash = 31 * hash + bit.GetHashCode();
}
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>
/// Erstellt ein neues Objekt, das eine Kopie der aktuellen Instanz darstellt.
/// </summary>
/// <returns>
/// Ein neues Objekt, das eine Kopie dieser Instanz darstellt.
/// </returns>
public object Clone()
{
return new BitArray((int[])bits.Clone(), size);
}
}
}

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

@@ -1,435 +0,0 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
namespace ZXing.Common
{
/// <summary>
/// <p>Represents a 2D matrix of bits. In function arguments below, and throughout the common
/// module, x is the column position, and y is the row position. The ordering is always x, y.
/// The origin is at the top-left.</p>
/// <p>Internally the bits are represented in a 1-D array of 32-bit ints. However, each row begins
/// with a new int. This is done intentionally so that we can copy out a row into a BitArray very
/// efficiently.</p>
/// <p>The ordering of bits is row-major. Within each int, the least significant bits are used first,
/// meaning they represent lower x values. This is compatible with BitArray's implementation.</p>
/// </summary>
/// <author>Sean Owen</author>
/// <author>dswitkin@google.com (Daniel Switkin)</author>
public sealed partial class BitMatrix
{
private readonly int width;
private readonly int height;
private readonly int rowSize;
private readonly int[] bits;
/// <returns> The width of the matrix
/// </returns>
public int Width
{
get
{
return width;
}
}
/// <returns> The height of the matrix
/// </returns>
public int Height
{
get
{
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.
public BitMatrix(int dimension)
: this(dimension, dimension)
{
}
public BitMatrix(int width, int height)
{
if (width < 1 || height < 1)
{
throw new System.ArgumentException("Both dimensions must be greater than 0");
}
this.width = width;
this.height = height;
this.rowSize = (width + 31) >> 5;
bits = new int[rowSize * height];
}
internal BitMatrix(int width, int height, int rowSize, int[] bits)
{
this.width = width;
this.height = height;
this.rowSize = rowSize;
this.bits = bits;
}
internal BitMatrix(int width, int height, int[] bits)
{
this.width = width;
this.height = height;
this.rowSize = (width + 31) >> 5;
this.bits = bits;
}
/// <summary> <p>Gets the requested bit, where true means black.</p>
///
/// </summary>
/// <param name="x">The horizontal component (i.e. which column)
/// </param>
/// <param name="y">The vertical component (i.e. which row)
/// </param>
/// <returns> value of given bit in matrix
/// </returns>
public bool this[int x, int y]
{
get
{
int offset = y * rowSize + (x >> 5);
return (((int)((uint)(bits[offset]) >> (x & 0x1f))) & 1) != 0;
}
set
{
if (value)
{
int offset = y * rowSize + (x >> 5);
bits[offset] |= 1 << (x & 0x1f);
}
}
}
/// <summary> <p>Flips the given bit.</p>
///
/// </summary>
/// <param name="x">The horizontal component (i.e. which column)
/// </param>
/// <param name="y">The vertical component (i.e. which row)
/// </param>
public void flip(int x, int y)
{
int offset = y * rowSize + (x >> 5);
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>
/// <param name="left">The horizontal position to begin at (inclusive)
/// </param>
/// <param name="top">The vertical position to begin at (inclusive)
/// </param>
/// <param name="width">The width of the region
/// </param>
/// <param name="height">The height of the region
/// </param>
public void setRegion(int left, int top, int width, int height)
{
if (top < 0 || left < 0)
{
throw new System.ArgumentException("Left and top must be nonnegative");
}
if (height < 1 || width < 1)
{
throw new System.ArgumentException("Height and width must be at least 1");
}
int right = left + width;
int bottom = top + height;
if (bottom > this.height || right > this.width)
{
throw new System.ArgumentException("The region must fit inside the matrix");
}
for (int y = top; y < bottom; y++)
{
int offset = y * rowSize;
for (int x = left; x < right; x++)
{
bits[offset + (x >> 5)] |= 1 << (x & 0x1f);
}
}
}
/// <summary> A fast method to retrieve one row of data from the matrix as a BitArray.
///
/// </summary>
/// <param name="y">The row to retrieve
/// </param>
/// <param name="row">An optional caller-allocated BitArray, will be allocated if null or too small
/// </param>
/// <returns> The resulting BitArray - this reference should always be used even when passing
/// your own row
/// </returns>
public BitArray getRow(int y, BitArray row)
{
if (row == null || row.Size < width)
{
row = new BitArray(width);
}
else
{
row.clear();
}
int offset = y * rowSize;
for (int x = 0; x < rowSize; x++)
{
row.setBulk(x << 5, bits[offset + x]);
}
return row;
}
/// <summary>
/// Sets the row.
/// </summary>
/// <param name="y">row to set</param>
/// <param name="row">{@link BitArray} to copy from</param>
public void setRow(int y, BitArray row)
{
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>
/// This is useful in detecting a corner of a 'pure' barcode.
/// </summary>
/// <returns>{x,y} coordinate of top-left-most 1 bit, or null if it is all white</returns>
public int[] getTopLeftOnBit()
{
int bitsOffset = 0;
while (bitsOffset < bits.Length && bits[bitsOffset] == 0)
{
bitsOffset++;
}
if (bitsOffset == bits.Length)
{
return null;
}
int y = bitsOffset / rowSize;
int x = (bitsOffset % rowSize) << 5;
int theBits = bits[bitsOffset];
int bit = 0;
while ((theBits << (31 - bit)) == 0)
{
bit++;
}
x += bit;
return new[] { x, y };
}
public int[] getBottomRightOnBit()
{
int bitsOffset = bits.Length - 1;
while (bitsOffset >= 0 && bits[bitsOffset] == 0)
{
bitsOffset--;
}
if (bitsOffset < 0)
{
return null;
}
int y = bitsOffset / rowSize;
int x = (bitsOffset % rowSize) << 5;
int theBits = bits[bitsOffset];
int bit = 31;
while (((int)((uint)theBits >> bit)) == 0) // (theBits >>> bit)
{
bit--;
}
x += bit;
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());
}
}
}

+ 0
- 131
shadowsocks-csharp/3rd/zxing/EncodeHintType.cs View File

@@ -1,131 +0,0 @@
/*
* Copyright 2008 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace ZXing
{
/// <summary>
/// These are a set of hints that you may pass to Writers to specify their behavior.
/// </summary>
/// <author>dswitkin@google.com (Daniel Switkin)</author>
public enum EncodeHintType
{
/// <summary>
/// Specifies the width of the barcode image
/// type: <see cref="System.Int32" />
/// </summary>
WIDTH,
/// <summary>
/// Specifies the height of the barcode image
/// type: <see cref="System.Int32" />
/// </summary>
HEIGHT,
/// <summary>
/// Don't put the content string into the output image.
/// type: <see cref="System.Boolean" />
/// </summary>
PURE_BARCODE,
/// <summary>
/// Specifies what degree of error correction to use, for example in QR Codes.
/// Type depends on the encoder. For example for QR codes it's type
/// <see cref="ZXing.QrCode.Internal.ErrorCorrectionLevel" />
/// For Aztec it is of type <see cref="System.Int32" />, representing the minimal percentage of error correction words.
/// Note: an Aztec symbol should have a minimum of 25% EC words.
/// For PDF417 it is of type <see cref="ZXing.PDF417.Internal.PDF417ErrorCorrectionLevel"/> or <see cref="System.Int32" /> (between 0 and 8),
/// </summary>
ERROR_CORRECTION,
/// <summary>
/// Specifies what character encoding to use where applicable.
/// type: <see cref="System.String" />
/// </summary>
CHARACTER_SET,
/// <summary>
/// Specifies margin, in pixels, to use when generating the barcode. The meaning can vary
/// by format; for example it controls margin before and after the barcode horizontally for
/// most 1D formats.
/// type: <see cref="System.Int32" />
/// </summary>
MARGIN,
/// <summary>
/// Specifies whether to use compact mode for PDF417.
/// type: <see cref="System.Boolean" />
/// </summary>
PDF417_COMPACT,
/// <summary>
/// Specifies what compaction mode to use for PDF417.
/// type: <see cref="ZXing.PDF417.Internal.Compaction" />
/// </summary>
PDF417_COMPACTION,
/// <summary>
/// Specifies the minimum and maximum number of rows and columns for PDF417.
/// type: <see cref="ZXing.PDF417.Internal.Dimensions" />
/// </summary>
PDF417_DIMENSIONS,
/// <summary>
/// Don't append ECI segment.
/// That is against the specification of QR Code but some
/// readers have problems if the charset is switched from
/// ISO-8859-1 (default) to UTF-8 with the necessary ECI segment.
/// If you set the property to true you can use UTF-8 encoding
/// and the ECI segment is omitted.
/// type: <see cref="System.Boolean" />
/// </summary>
DISABLE_ECI,
/// <summary>
/// Specifies the matrix shape for Data Matrix (type <see cref="ZXing.Datamatrix.Encoder.SymbolShapeHint"/>)
/// </summary>
DATA_MATRIX_SHAPE,
/// <summary>
/// Specifies a minimum barcode size (type <see cref="ZXing.Dimension"/>). Only applicable to Data Matrix now.
/// </summary>
MIN_SIZE,
/// <summary>
/// Specifies a maximum barcode size (type <see cref="ZXing.Dimension"/>). Only applicable to Data Matrix now.
/// </summary>
MAX_SIZE,
/// <summary>
/// if true, don't switch to codeset C for numbers
/// </summary>
CODE128_FORCE_CODESET_B,
/// <summary>
/// Specifies the default encodation for Data Matrix (type <see cref="ZXing.Datamatrix.Encoder.Encodation"/>)
/// Make sure that the content fits into the encodation value, otherwise there will be an exception thrown.
/// standard value: Encodation.ASCII
/// </summary>
DATA_MATRIX_DEFAULT_ENCODATION,
/// <summary>
/// Specifies the required number of layers for an Aztec code:
/// a negative number (-1, -2, -3, -4) specifies a compact Aztec code
/// 0 indicates to use the minimum number of layers (the default)
/// a positive number (1, 2, .. 32) specifies a normal (non-compact) Aztec code
/// </summary>
AZTEC_LAYERS,
}
}

+ 3
- 239
shadowsocks-csharp/3rd/zxing/Encoder.cs View File

@@ -30,15 +30,6 @@ namespace ZXing.QrCode.Internal
public static class Encoder
{
// The original table is defined in the table 5 of JISX0510:2004 (p.19).
private static readonly int[] ALPHANUMERIC_TABLE = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x00-0x0f
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // 0x10-0x1f
36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, // 0x20-0x2f
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, // 0x30-0x3f
-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, // 0x40-0x4f
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, // 0x50-0x5f
};
internal static String DEFAULT_BYTE_MODE_ENCODING = "ISO-8859-1";
@@ -65,29 +56,11 @@ namespace ZXing.QrCode.Internal
/// <param name="ecLevel">error correction level to use</param>
/// <returns><see cref="QRCode"/> representing the encoded QR code</returns>
public static QRCode encode(String content, ErrorCorrectionLevel ecLevel)
{
return encode(content, ecLevel, null);
}
/// <summary>
/// Encodes the specified content.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="ecLevel">The ec level.</param>
/// <param name="hints">The hints.</param>
/// <returns></returns>
public static QRCode encode(String content,
ErrorCorrectionLevel ecLevel,
IDictionary<EncodeHintType, object> hints)
{
// Determine what character encoding has been specified by the caller, if any
#if !SILVERLIGHT || WINDOWS_PHONE
String encoding = hints == null || !hints.ContainsKey(EncodeHintType.CHARACTER_SET) ? null : (String)hints[EncodeHintType.CHARACTER_SET];
if (encoding == null)
{
encoding = DEFAULT_BYTE_MODE_ENCODING;
}
bool generateECI = !DEFAULT_BYTE_MODE_ENCODING.Equals(encoding);
String encoding = DEFAULT_BYTE_MODE_ENCODING;
//bool generateECI = !DEFAULT_BYTE_MODE_ENCODING.Equals(encoding);
#else
// Silverlight supports only UTF-8 and UTF-16 out-of-the-box
const string encoding = "UTF-8";
@@ -98,7 +71,7 @@ namespace ZXing.QrCode.Internal
// Pick an encoding mode appropriate for the content. Note that this will not attempt to use
// multiple modes / segments even if that were more efficient. Twould be nice.
Mode mode = chooseMode(content, encoding);
Mode mode = Mode.BYTE;
// This will store the header information, like mode and
// length, as well as "header" segments like an ECI segment.
@@ -183,106 +156,6 @@ namespace ZXing.QrCode.Internal
return qrCode;
}
/// <summary>
/// Gets the alphanumeric code.
/// </summary>
/// <param name="code">The code.</param>
/// <returns>the code point of the table used in alphanumeric mode or
/// -1 if there is no corresponding code in the table.</returns>
internal static int getAlphanumericCode(int code)
{
if (code < ALPHANUMERIC_TABLE.Length)
{
return ALPHANUMERIC_TABLE[code];
}
return -1;
}
/// <summary>
/// Chooses the mode.
/// </summary>
/// <param name="content">The content.</param>
/// <returns></returns>
public static Mode chooseMode(String content)
{
return chooseMode(content, null);
}
/// <summary>
/// Choose the best mode by examining the content. Note that 'encoding' is used as a hint;
/// if it is Shift_JIS, and the input is only double-byte Kanji, then we return {@link Mode#KANJI}.
/// </summary>
/// <param name="content">The content.</param>
/// <param name="encoding">The encoding.</param>
/// <returns></returns>
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,
@@ -594,85 +467,12 @@ 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);
else
if (mode.Equals(Mode.BYTE))
append8BitBytes(content, bits, encoding);
else
if (mode.Equals(Mode.KANJI))
appendKanjiBytes(content, bits);
else
throw new Exception("Invalid mode: " + mode);
}
internal static void appendNumericBytes(String content, BitArray bits)
{
int length = content.Length;
int i = 0;
while (i < length)
{
int num1 = content[i] - '0';
if (i + 2 < length)
{
// Encode three numeric letters in ten bits.
int num2 = content[i + 1] - '0';
int num3 = content[i + 2] - '0';
bits.appendBits(num1 * 100 + num2 * 10 + num3, 10);
i += 3;
}
else if (i + 1 < length)
{
// Encode two numeric letters in seven bits.
int num2 = content[i + 1] - '0';
bits.appendBits(num1 * 10 + num2, 7);
i += 2;
}
else
{
// Encode one numeric letter in four bits.
bits.appendBits(num1, 4);
i++;
}
}
}
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 Exception();
}
if (i + 1 < length)
{
int code2 = getAlphanumericCode(content[i + 1]);
if (code2 == -1)
{
throw new Exception();
}
// 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)
{
byte[] bytes;
@@ -712,42 +512,6 @@ 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 Exception(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 Exception("Invalid byte sequence");
}
int encoded = ((subtracted >> 8) * 0xc0) + (subtracted & 0xff);
bits.appendBits(encoded, 13);
}
}
/*
private static void appendECI(CharacterSetECI eci, BitArray bits)


+ 0
- 197
shadowsocks-csharp/3rd/zxing/FormatInformation.cs View File

@@ -1,197 +0,0 @@
/*
* Copyright 2007 ZXing authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
namespace ZXing.QrCode.Internal
{
/// <summary> <p>Encapsulates a QR Code's format information, including the data mask used and
/// error correction level.</p>
///
/// </summary>
/// <author> Sean Owen
/// </author>
/// <author>www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source
/// </author>
/// <seealso cref="DataMask">
/// </seealso>
/// <seealso cref="ErrorCorrectionLevel">
/// </seealso>
sealed class FormatInformation
{
private const int FORMAT_INFO_MASK_QR = 0x5412;
/// <summary> See ISO 18004:2006, Annex C, Table C.1</summary>
private static readonly int[][] FORMAT_INFO_DECODE_LOOKUP = new int[][]
{
new [] { 0x5412, 0x00 },
new [] { 0x5125, 0x01 },
new [] { 0x5E7C, 0x02 },
new [] { 0x5B4B, 0x03 },
new [] { 0x45F9, 0x04 },
new [] { 0x40CE, 0x05 },
new [] { 0x4F97, 0x06 },
new [] { 0x4AA0, 0x07 },
new [] { 0x77C4, 0x08 },
new [] { 0x72F3, 0x09 },
new [] { 0x7DAA, 0x0A },
new [] { 0x789D, 0x0B },
new [] { 0x662F, 0x0C },
new [] { 0x6318, 0x0D },
new [] { 0x6C41, 0x0E },
new [] { 0x6976, 0x0F },
new [] { 0x1689, 0x10 },
new [] { 0x13BE, 0x11 },
new [] { 0x1CE7, 0x12 },
new [] { 0x19D0, 0x13 },
new [] { 0x0762, 0x14 },
new [] { 0x0255, 0x15 },
new [] { 0x0D0C, 0x16 },
new [] { 0x083B, 0x17 },
new [] { 0x355F, 0x18 },
new [] { 0x3068, 0x19 },
new [] { 0x3F31, 0x1A },
new [] { 0x3A06, 0x1B },
new [] { 0x24B4, 0x1C },
new [] { 0x2183, 0x1D },
new [] { 0x2EDA, 0x1E },
new [] { 0x2BED, 0x1F }
};
/// <summary> Offset i holds the number of 1 bits in the binary representation of i</summary>
private static readonly int[] BITS_SET_IN_HALF_BYTE = new []
{ 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
private readonly ErrorCorrectionLevel errorCorrectionLevel;
private readonly byte dataMask;
private FormatInformation(int formatInfo)
{
// Bits 3,4
errorCorrectionLevel = ErrorCorrectionLevel.forBits((formatInfo >> 3) & 0x03);
// Bottom 3 bits
dataMask = (byte)(formatInfo & 0x07);
}
internal static int numBitsDiffering(int a, int b)
{
a ^= b; // a now has a 1 bit exactly where its bit differs with b's
// Count bits set quickly with a series of lookups:
return BITS_SET_IN_HALF_BYTE[a & 0x0F] +
BITS_SET_IN_HALF_BYTE[(((int)((uint)a >> 4)) & 0x0F)] +
BITS_SET_IN_HALF_BYTE[(((int)((uint)a >> 8)) & 0x0F)] +
BITS_SET_IN_HALF_BYTE[(((int)((uint)a >> 12)) & 0x0F)] +
BITS_SET_IN_HALF_BYTE[(((int)((uint)a >> 16)) & 0x0F)] +
BITS_SET_IN_HALF_BYTE[(((int)((uint)a >> 20)) & 0x0F)] +
BITS_SET_IN_HALF_BYTE[(((int)((uint)a >> 24)) & 0x0F)] +
BITS_SET_IN_HALF_BYTE[(((int)((uint)a >> 28)) & 0x0F)];
}
/// <summary>
/// Decodes the format information.
/// </summary>
/// <param name="maskedFormatInfo1">format info indicator, with mask still applied</param>
/// <param name="maskedFormatInfo2">The masked format info2.</param>
/// <returns>
/// information about the format it specifies, or <code>null</code>
/// if doesn't seem to match any known pattern
/// </returns>
internal static FormatInformation decodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2)
{
FormatInformation formatInfo = doDecodeFormatInformation(maskedFormatInfo1, maskedFormatInfo2);
if (formatInfo != null)
{
return formatInfo;
}
// Should return null, but, some QR codes apparently
// do not mask this info. Try again by actually masking the pattern
// first
return doDecodeFormatInformation(maskedFormatInfo1 ^ FORMAT_INFO_MASK_QR,
maskedFormatInfo2 ^ FORMAT_INFO_MASK_QR);
}
private static FormatInformation doDecodeFormatInformation(int maskedFormatInfo1, int maskedFormatInfo2)
{
// Find the int in FORMAT_INFO_DECODE_LOOKUP with fewest bits differing
int bestDifference = Int32.MaxValue;
int bestFormatInfo = 0;
foreach (var decodeInfo in FORMAT_INFO_DECODE_LOOKUP)
{
int targetInfo = decodeInfo[0];
if (targetInfo == maskedFormatInfo1 || targetInfo == maskedFormatInfo2)
{
// Found an exact match
return new FormatInformation(decodeInfo[1]);
}
int bitsDifference = numBitsDiffering(maskedFormatInfo1, targetInfo);
if (bitsDifference < bestDifference)
{
bestFormatInfo = decodeInfo[1];
bestDifference = bitsDifference;
}
if (maskedFormatInfo1 != maskedFormatInfo2)
{
// also try the other option
bitsDifference = numBitsDiffering(maskedFormatInfo2, targetInfo);
if (bitsDifference < bestDifference)
{
bestFormatInfo = decodeInfo[1];
bestDifference = bitsDifference;
}
}
}
// Hamming distance of the 32 masked codes is 7, by construction, so <= 3 bits
// differing means we found a match
if (bestDifference <= 3)
{
return new FormatInformation(bestFormatInfo);
}
return null;
}
internal ErrorCorrectionLevel ErrorCorrectionLevel
{
get
{
return errorCorrectionLevel;
}
}
internal byte DataMask
{
get
{
return dataMask;
}
}
public override int GetHashCode()
{
return (errorCorrectionLevel.ordinal() << 3) | dataMask;
}
public override bool Equals(Object o)
{
if (!(o is FormatInformation))
{
return false;
}
var other = (FormatInformation)o;
return errorCorrectionLevel == other.errorCorrectionLevel && dataMask == other.dataMask;
}
}
}

+ 0
- 40
shadowsocks-csharp/3rd/zxing/GenericGF.cs View File

@@ -91,14 +91,6 @@ namespace ZXing.Common.ReedSolomon
}
}
internal GenericGFPoly One
{
get
{
return one;
}
}
/// <summary>
/// Builds the monomial.
/// </summary>
@@ -138,19 +130,6 @@ namespace ZXing.Common.ReedSolomon
return expTable[a];
}
/// <summary>
/// Logs the specified a.
/// </summary>
/// <param name="a">A.</param>
/// <returns>base 2 log of a in GF(size)</returns>
internal int log(int a)
{
if (a == 0)
{
throw new ArgumentException();
}
return logTable[a];
}
/// <summary>
/// Inverses the specified a.
@@ -180,14 +159,6 @@ namespace ZXing.Common.ReedSolomon
return expTable[(logTable[a] + logTable[b]) % (size - 1)];
}
/// <summary>
/// Gets the size.
/// </summary>
public int Size
{
get { return size; }
}
/// <summary>
/// Gets the generator base.
/// </summary>
@@ -195,16 +166,5 @@ namespace ZXing.Common.ReedSolomon
{
get { return generatorBase; }
}
/// <summary>
/// Returns a <see cref="System.String"/> that represents this instance.
/// </summary>
/// <returns>
/// A <see cref="System.String"/> that represents this instance.
/// </returns>
override public String ToString()
{
return "GF(0x" + primitive.ToString("X") + ',' + size + ')';
}
}
}

+ 0
- 101
shadowsocks-csharp/3rd/zxing/GenericGFPoly.cs View File

@@ -112,36 +112,6 @@ namespace ZXing.Common.ReedSolomon
return coefficients[coefficients.Length - 1 - degree];
}
/// <summary>
/// evaluation of this polynomial at a given point
/// </summary>
/// <param name="a">A.</param>
/// <returns>evaluation of this polynomial at a given point</returns>
internal int evaluateAt(int a)
{
int result = 0;
if (a == 0)
{
// Just return the x^0 coefficient
return getCoefficient(0);
}
int size = coefficients.Length;
if (a == 1)
{
// Just the sum of the coefficients
foreach (var coefficient in coefficients)
{
result = GenericGF.addOrSubtract(result, coefficient);
}
return result;
}
result = coefficients[0];
for (int i = 1; i < size; i++)
{
result = GenericGF.addOrSubtract(field.multiply(a, result), coefficients[i]);
}
return result;
}
internal GenericGFPoly addOrSubtract(GenericGFPoly other)
{
@@ -206,24 +176,6 @@ namespace ZXing.Common.ReedSolomon
return new GenericGFPoly(field, product);
}
internal GenericGFPoly multiply(int scalar)
{
if (scalar == 0)
{
return field.Zero;
}
if (scalar == 1)
{
return this;
}
int size = coefficients.Length;
int[] product = new int[size];
for (int i = 0; i < size; i++)
{
product[i] = field.multiply(coefficients[i], scalar);
}
return new GenericGFPoly(field, product);
}
internal GenericGFPoly multiplyByMonomial(int degree, int coefficient)
{
@@ -274,58 +226,5 @@ namespace ZXing.Common.ReedSolomon
return new GenericGFPoly[] { quotient, remainder };
}
public override String ToString()
{
StringBuilder result = new StringBuilder(8 * Degree);
for (int degree = Degree; degree >= 0; degree--)
{
int coefficient = getCoefficient(degree);
if (coefficient != 0)
{
if (coefficient < 0)
{
result.Append(" - ");
coefficient = -coefficient;
}
else
{
if (result.Length > 0)
{
result.Append(" + ");
}
}
if (degree == 0 || coefficient != 1)
{
int alphaPower = field.log(coefficient);
if (alphaPower == 0)
{
result.Append('1');
}
else if (alphaPower == 1)
{
result.Append('a');
}
else
{
result.Append("a^");
result.Append(alphaPower);
}
}
if (degree != 0)
{
if (degree == 1)
{
result.Append('x');
}
else
{
result.Append("x^");
result.Append(degree);
}
}
}
}
return result.ToString();
}
}
}

+ 0
- 34
shadowsocks-csharp/3rd/zxing/QRCode.cs View File

@@ -76,40 +76,6 @@ namespace ZXing.QrCode.Internal
/// </value>
public ByteMatrix Matrix { get; set; }
/// <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 StringBuilder(200);
result.Append("<<\n");
result.Append(" mode: ");
result.Append(Mode);
result.Append("\n ecLevel: ");
result.Append(ECLevel);
result.Append("\n version: ");
if (Version == null)
result.Append("null");
else
result.Append(Version);
result.Append("\n maskPattern: ");
result.Append(MaskPattern);
if (Matrix == null)
{
result.Append("\n matrix: null\n");
}
else
{
result.Append("\n matrix:\n");
result.Append(Matrix.ToString());
}
result.Append(">>\n");
return result.ToString();
}
/// <summary>
/// Check if "mask_pattern" is valid.
/// </summary>


+ 1
- 344
shadowsocks-csharp/3rd/zxing/Version.cs View File

@@ -26,19 +26,6 @@ namespace ZXing.QrCode.Internal
/// <author>Sean Owen</author>
public sealed class Version
{
/// <summary> See ISO 18004:2006 Annex D.
/// Element i represents the raw version bits that specify version i + 7
/// </summary>
private static readonly int[] VERSION_DECODE_INFO = new[]
{
0x07C94, 0x085BC, 0x09A99, 0x0A4D3, 0x0BBF6,
0x0C762, 0x0D847, 0x0E60D, 0x0F928, 0x10B78,
0x1145D, 0x12A17, 0x13532, 0x149A6, 0x15683,
0x168C9, 0x177EC, 0x18EC4, 0x191E1, 0x1AFAB,
0x1B08E, 0x1CC1A, 0x1D33F, 0x1ED75, 0x1F250,
0x209D5, 0x216F0, 0x228BA, 0x2379F, 0x24B0B,
0x2542E, 0x26A64, 0x27541, 0x28C69
};
private static readonly Version[] VERSIONS = buildVersions();
@@ -74,18 +61,6 @@ namespace ZXing.QrCode.Internal
}
/// <summary>
/// Gets the alignment pattern centers.
/// </summary>
public int[] AlignmentPatternCenters
{
get
{
return alignmentPatternCenters;
}
}
/// <summary>
/// Gets the total codewords.
/// </summary>
@@ -120,28 +95,6 @@ namespace ZXing.QrCode.Internal
return ecBlocks[ecLevel.ordinal()];
}
/// <summary> <p>Deduces version information purely from QR Code dimensions.</p>
///
/// </summary>
/// <param name="dimension">dimension in modules
/// </param>
/// <returns><see cref="Version" /> for a QR Code of that dimension or null</returns>
public static Version getProvisionalVersionForDimension(int dimension)
{
if (dimension % 4 != 1)
{
return null;
}
try
{
return getVersionForNumber((dimension - 17) >> 2);
}
catch (ArgumentException)
{
return null;
}
}
/// <summary>
/// Gets the version for number.
/// </summary>
@@ -156,81 +109,6 @@ namespace ZXing.QrCode.Internal
return VERSIONS[versionNumber - 1];
}
internal static Version decodeVersionInformation(int versionBits)
{
int bestDifference = Int32.MaxValue;
int bestVersion = 0;
for (int i = 0; i < VERSION_DECODE_INFO.Length; i++)
{
int targetVersion = VERSION_DECODE_INFO[i];
// Do the version info bits match exactly? done.
if (targetVersion == versionBits)
{
return getVersionForNumber(i + 7);
}
// Otherwise see if this is the closest to a real version info bit string
// we have seen so far
int bitsDifference = FormatInformation.numBitsDiffering(versionBits, targetVersion);
if (bitsDifference < bestDifference)
{
bestVersion = i + 7;
bestDifference = bitsDifference;
}
}
// We can tolerate up to 3 bits of error since no two version info codewords will
// differ in less than 8 bits.
if (bestDifference <= 3)
{
return getVersionForNumber(bestVersion);
}
// If we didn't find a close enough match, fail
return null;
}
/// <summary> See ISO 18004:2006 Annex E</summary>
internal BitMatrix buildFunctionPattern()
{
int dimension = DimensionForVersion;
BitMatrix bitMatrix = new BitMatrix(dimension);
// Top left finder pattern + separator + format
bitMatrix.setRegion(0, 0, 9, 9);
// Top right finder pattern + separator + format
bitMatrix.setRegion(dimension - 8, 0, 8, 9);
// Bottom left finder pattern + separator + format
bitMatrix.setRegion(0, dimension - 8, 9, 8);
// Alignment patterns
int max = alignmentPatternCenters.Length;
for (int x = 0; x < max; x++)
{
int i = alignmentPatternCenters[x] - 2;
for (int y = 0; y < max; y++)
{
if ((x == 0 && (y == 0 || y == max - 1)) || (x == max - 1 && y == 0))
{
// No alignment patterns near the three finder paterns
continue;
}
bitMatrix.setRegion(alignmentPatternCenters[y] - 2, i, 5, 5);
}
}
// Vertical timing pattern
bitMatrix.setRegion(6, 9, 1, dimension - 17);
// Horizontal timing pattern
bitMatrix.setRegion(9, 6, dimension - 17, 1);
if (versionNumber > 6)
{
// Version info, top right
bitMatrix.setRegion(dimension - 11, 0, 3, 6);
// Version info, bottom left
bitMatrix.setRegion(0, dimension - 11, 6, 3);
}
return bitMatrix;
}
/// <summary> <p>Encapsulates a set of error-correction blocks in one symbol version. Most versions will
/// use blocks of differing sizes within one version, so, this encapsulates the parameters for
@@ -457,228 +335,7 @@ namespace ZXing.QrCode.Internal
new ECBlocks(30, new ECB(5, 24),
new ECB(7, 25)),
new ECBlocks(24, new ECB(11, 12),
new ECB(7, 13))),
new Version(16, new int[] {6, 26, 50, 74},
new ECBlocks(24, new ECB(5, 98),
new ECB(1, 99)),
new ECBlocks(28, new ECB(7, 45),
new ECB(3, 46)),
new ECBlocks(24, new ECB(15, 19),
new ECB(2, 20)),
new ECBlocks(30, new ECB(3, 15),
new ECB(13, 16))),
new Version(17, new int[] {6, 30, 54, 78},
new ECBlocks(28, new ECB(1, 107),
new ECB(5, 108)),
new ECBlocks(28, new ECB(10, 46),
new ECB(1, 47)),
new ECBlocks(28, new ECB(1, 22),
new ECB(15, 23)),
new ECBlocks(28, new ECB(2, 14),
new ECB(17, 15))),
new Version(18, new int[] {6, 30, 56, 82},
new ECBlocks(30, new ECB(5, 120),
new ECB(1, 121)),
new ECBlocks(26, new ECB(9, 43),
new ECB(4, 44)),
new ECBlocks(28, new ECB(17, 22),
new ECB(1, 23)),
new ECBlocks(28, new ECB(2, 14),
new ECB(19, 15))),
new Version(19, new int[] {6, 30, 58, 86},
new ECBlocks(28, new ECB(3, 113),
new ECB(4, 114)),
new ECBlocks(26, new ECB(3, 44),
new ECB(11, 45)),
new ECBlocks(26, new ECB(17, 21),
new ECB(4, 22)),
new ECBlocks(26, new ECB(9, 13),
new ECB(16, 14))),
new Version(20, new int[] {6, 34, 62, 90},
new ECBlocks(28, new ECB(3, 107),
new ECB(5, 108)),
new ECBlocks(26, new ECB(3, 41),
new ECB(13, 42)),
new ECBlocks(30, new ECB(15, 24),
new ECB(5, 25)),
new ECBlocks(28, new ECB(15, 15),
new ECB(10, 16))),
new Version(21, new int[] {6, 28, 50, 72, 94},
new ECBlocks(28, new ECB(4, 116),
new ECB(4, 117)),
new ECBlocks(26, new ECB(17, 42)),
new ECBlocks(28, new ECB(17, 22),
new ECB(6, 23)),
new ECBlocks(30, new ECB(19, 16),
new ECB(6, 17))),
new Version(22, new int[] {6, 26, 50, 74, 98},
new ECBlocks(28, new ECB(2, 111),
new ECB(7, 112)),
new ECBlocks(28, new ECB(17, 46)),
new ECBlocks(30, new ECB(7, 24),
new ECB(16, 25)),
new ECBlocks(24, new ECB(34, 13))),
new Version(23, new int[] {6, 30, 54, 78, 102},
new ECBlocks(30, new ECB(4, 121),
new ECB(5, 122)),
new ECBlocks(28, new ECB(4, 47),
new ECB(14, 48)),
new ECBlocks(30, new ECB(11, 24),
new ECB(14, 25)),
new ECBlocks(30, new ECB(16, 15),
new ECB(14, 16))),
new Version(24, new int[] {6, 28, 54, 80, 106},
new ECBlocks(30, new ECB(6, 117),
new ECB(4, 118)),
new ECBlocks(28, new ECB(6, 45),
new ECB(14, 46)),
new ECBlocks(30, new ECB(11, 24),
new ECB(16, 25)),
new ECBlocks(30, new ECB(30, 16),
new ECB(2, 17))),
new Version(25, new int[] {6, 32, 58, 84, 110},
new ECBlocks(26, new ECB(8, 106),
new ECB(4, 107)),
new ECBlocks(28, new ECB(8, 47),
new ECB(13, 48)),
new ECBlocks(30, new ECB(7, 24),
new ECB(22, 25)),
new ECBlocks(30, new ECB(22, 15),
new ECB(13, 16))),
new Version(26, new int[] {6, 30, 58, 86, 114},
new ECBlocks(28, new ECB(10, 114),
new ECB(2, 115)),
new ECBlocks(28, new ECB(19, 46),
new ECB(4, 47)),
new ECBlocks(28, new ECB(28, 22),
new ECB(6, 23)),
new ECBlocks(30, new ECB(33, 16),
new ECB(4, 17))),
new Version(27, new int[] {6, 34, 62, 90, 118},
new ECBlocks(30, new ECB(8, 122),
new ECB(4, 123)),
new ECBlocks(28, new ECB(22, 45),
new ECB(3, 46)),
new ECBlocks(30, new ECB(8, 23),
new ECB(26, 24)),
new ECBlocks(30, new ECB(12, 15),
new ECB(28, 16))),
new Version(28, new int[] {6, 26, 50, 74, 98, 122},
new ECBlocks(30, new ECB(3, 117),
new ECB(10, 118)),
new ECBlocks(28, new ECB(3, 45),
new ECB(23, 46)),
new ECBlocks(30, new ECB(4, 24),
new ECB(31, 25)),
new ECBlocks(30, new ECB(11, 15),
new ECB(31, 16))),
new Version(29, new int[] {6, 30, 54, 78, 102, 126},
new ECBlocks(30, new ECB(7, 116),
new ECB(7, 117)),
new ECBlocks(28, new ECB(21, 45),
new ECB(7, 46)),
new ECBlocks(30, new ECB(1, 23),
new ECB(37, 24)),
new ECBlocks(30, new ECB(19, 15),
new ECB(26, 16))),
new Version(30, new int[] {6, 26, 52, 78, 104, 130},
new ECBlocks(30, new ECB(5, 115),
new ECB(10, 116)),
new ECBlocks(28, new ECB(19, 47),
new ECB(10, 48)),
new ECBlocks(30, new ECB(15, 24),
new ECB(25, 25)),
new ECBlocks(30, new ECB(23, 15),
new ECB(25, 16))),
new Version(31, new int[] {6, 30, 56, 82, 108, 134},
new ECBlocks(30, new ECB(13, 115),
new ECB(3, 116)),
new ECBlocks(28, new ECB(2, 46),
new ECB(29, 47)),
new ECBlocks(30, new ECB(42, 24),
new ECB(1, 25)),
new ECBlocks(30, new ECB(23, 15),
new ECB(28, 16))),
new Version(32, new int[] {6, 34, 60, 86, 112, 138},
new ECBlocks(30, new ECB(17, 115)),
new ECBlocks(28, new ECB(10, 46),
new ECB(23, 47)),
new ECBlocks(30, new ECB(10, 24),
new ECB(35, 25)),
new ECBlocks(30, new ECB(19, 15),
new ECB(35, 16))),
new Version(33, new int[] {6, 30, 58, 86, 114, 142},
new ECBlocks(30, new ECB(17, 115),
new ECB(1, 116)),
new ECBlocks(28, new ECB(14, 46),
new ECB(21, 47)),
new ECBlocks(30, new ECB(29, 24),
new ECB(19, 25)),
new ECBlocks(30, new ECB(11, 15),
new ECB(46, 16))),
new Version(34, new int[] {6, 34, 62, 90, 118, 146},
new ECBlocks(30, new ECB(13, 115),
new ECB(6, 116)),
new ECBlocks(28, new ECB(14, 46),
new ECB(23, 47)),
new ECBlocks(30, new ECB(44, 24),
new ECB(7, 25)),
new ECBlocks(30, new ECB(59, 16),
new ECB(1, 17))),
new Version(35, new int[] {6, 30, 54, 78, 102, 126, 150},
new ECBlocks(30, new ECB(12, 121),
new ECB(7, 122)),
new ECBlocks(28, new ECB(12, 47),
new ECB(26, 48)),
new ECBlocks(30, new ECB(39, 24),
new ECB(14, 25)),
new ECBlocks(30, new ECB(22, 15),
new ECB(41, 16))),
new Version(36, new int[] {6, 24, 50, 76, 102, 128, 154},
new ECBlocks(30, new ECB(6, 121),
new ECB(14, 122)),
new ECBlocks(28, new ECB(6, 47),
new ECB(34, 48)),
new ECBlocks(30, new ECB(46, 24),
new ECB(10, 25)),
new ECBlocks(30, new ECB(2, 15),
new ECB(64, 16))),
new Version(37, new int[] {6, 28, 54, 80, 106, 132, 158},
new ECBlocks(30, new ECB(17, 122),
new ECB(4, 123)),
new ECBlocks(28, new ECB(29, 46),
new ECB(14, 47)),
new ECBlocks(30, new ECB(49, 24),
new ECB(10, 25)),
new ECBlocks(30, new ECB(24, 15),
new ECB(46, 16))),
new Version(38, new int[] {6, 32, 58, 84, 110, 136, 162},
new ECBlocks(30, new ECB(4, 122),
new ECB(18, 123)),
new ECBlocks(28, new ECB(13, 46),
new ECB(32, 47)),
new ECBlocks(30, new ECB(48, 24),
new ECB(14, 25)),
new ECBlocks(30, new ECB(42, 15),
new ECB(32, 16))),
new Version(39, new int[] {6, 26, 54, 82, 110, 138, 166},
new ECBlocks(30, new ECB(20, 117),
new ECB(4, 118)),
new ECBlocks(28, new ECB(40, 47),
new ECB(7, 48)),
new ECBlocks(30, new ECB(43, 24),
new ECB(22, 25)),
new ECBlocks(30, new ECB(10, 15),
new ECB(67, 16))),
new Version(40, new int[] {6, 30, 58, 86, 114, 142, 170},
new ECBlocks(30, new ECB(19, 118),
new ECB(6, 119)),
new ECBlocks(28, new ECB(18, 47),
new ECB(31, 48)),
new ECBlocks(30, new ECB(34, 24),
new ECB(34, 25)),
new ECBlocks(30, new ECB(20, 15),
new ECB(61, 16)))
new ECB(7, 13)))
};
}
}

+ 2
- 2
shadowsocks-csharp/View/QRCodeForm.cs View File

@@ -31,13 +31,13 @@ namespace Shadowsocks.View
QRCode code = ZXing.QrCode.Internal.Encoder.encode(qrText, ErrorCorrectionLevel.M);
ByteMatrix m = code.Matrix;
int blockSize = Math.Max(200 / m.Height, 1);
Bitmap drawArea = new Bitmap((m.Height * blockSize), (m.Height * blockSize));
Bitmap drawArea = new Bitmap((m.Width * blockSize), (m.Height * blockSize));
using (Graphics g = Graphics.FromImage(drawArea))
{
g.Clear(Color.White);
using (Brush b = new SolidBrush(Color.Black))
{
for (int row = 0; row < m.Height; row++)
for (int row = 0; row < m.Width; row++)
{
for (int col = 0; col < m.Height; col++)
{


+ 1
- 3
shadowsocks-csharp/shadowsocks-csharp.csproj View File

@@ -57,6 +57,7 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
@@ -71,13 +72,10 @@
<ItemGroup>
<Compile Include="3rd\SimpleJson.cs" />
<Compile Include="3rd\zxing\BitArray.cs" />
<Compile Include="3rd\zxing\BitMatrix.cs" />
<Compile Include="3rd\zxing\BlockPair.cs" />
<Compile Include="3rd\zxing\ByteMatrix.cs" />
<Compile Include="3rd\zxing\EncodeHintType.cs" />
<Compile Include="3rd\zxing\Encoder.cs" />
<Compile Include="3rd\zxing\ErrorCorrectionLevel.cs" />
<Compile Include="3rd\zxing\FormatInformation.cs" />
<Compile Include="3rd\zxing\GenericGF.cs" />
<Compile Include="3rd\zxing\GenericGFPoly.cs" />
<Compile Include="3rd\zxing\MaskUtil.cs" />


Loading…
Cancel
Save