添加项目文件。

This commit is contained in:
akwkevin
2021-07-23 09:42:22 +08:00
commit f25a958797
2798 changed files with 352360 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
/*
* Copyright 2011 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 ZXing.Common;
namespace ZXing.Maxicode.Internal
{
/// <summary>
/// <author>mike32767</author>
/// <author>Manuel Kasten</author>
/// </summary>
sealed class BitMatrixParser
{
private static readonly int[][] BITNR = new int[][] {
new[] {121,120,127,126,133,132,139,138,145,144,151,150,157,156,163,162,169,168,175,174,181,180,187,186,193,192,199,198, -2, -2},
new[] {123,122,129,128,135,134,141,140,147,146,153,152,159,158,165,164,171,170,177,176,183,182,189,188,195,194,201,200,816, -3},
new[] {125,124,131,130,137,136,143,142,149,148,155,154,161,160,167,166,173,172,179,178,185,184,191,190,197,196,203,202,818,817},
new[] {283,282,277,276,271,270,265,264,259,258,253,252,247,246,241,240,235,234,229,228,223,222,217,216,211,210,205,204,819, -3},
new[] {285,284,279,278,273,272,267,266,261,260,255,254,249,248,243,242,237,236,231,230,225,224,219,218,213,212,207,206,821,820},
new[] {287,286,281,280,275,274,269,268,263,262,257,256,251,250,245,244,239,238,233,232,227,226,221,220,215,214,209,208,822, -3},
new[] {289,288,295,294,301,300,307,306,313,312,319,318,325,324,331,330,337,336,343,342,349,348,355,354,361,360,367,366,824,823},
new[] {291,290,297,296,303,302,309,308,315,314,321,320,327,326,333,332,339,338,345,344,351,350,357,356,363,362,369,368,825, -3},
new[] {293,292,299,298,305,304,311,310,317,316,323,322,329,328,335,334,341,340,347,346,353,352,359,358,365,364,371,370,827,826},
new[] {409,408,403,402,397,396,391,390, 79, 78, -2, -2, 13, 12, 37, 36, 2, -1, 44, 43,109,108,385,384,379,378,373,372,828, -3},
new[] {411,410,405,404,399,398,393,392, 81, 80, 40, -2, 15, 14, 39, 38, 3, -1, -1, 45,111,110,387,386,381,380,375,374,830,829},
new[] {413,412,407,406,401,400,395,394, 83, 82, 41, -3, -3, -3, -3, -3, 5, 4, 47, 46,113,112,389,388,383,382,377,376,831, -3},
new[] {415,414,421,420,427,426,103,102, 55, 54, 16, -3, -3, -3, -3, -3, -3, -3, 20, 19, 85, 84,433,432,439,438,445,444,833,832},
new[] {417,416,423,422,429,428,105,104, 57, 56, -3, -3, -3, -3, -3, -3, -3, -3, 22, 21, 87, 86,435,434,441,440,447,446,834, -3},
new[] {419,418,425,424,431,430,107,106, 59, 58, -3, -3, -3, -3, -3, -3, -3, -3, -3, 23, 89, 88,437,436,443,442,449,448,836,835},
new[] {481,480,475,474,469,468, 48, -2, 30, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 0, 53, 52,463,462,457,456,451,450,837, -3},
new[] {483,482,477,476,471,470, 49, -1, -2, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, -2, -1,465,464,459,458,453,452,839,838},
new[] {485,484,479,478,473,472, 51, 50, 31, -3, -3, -3, -3, -3, -3, -3, -3, -3, -3, 1, -2, 42,467,466,461,460,455,454,840, -3},
new[] {487,486,493,492,499,498, 97, 96, 61, 60, -3, -3, -3, -3, -3, -3, -3, -3, -3, 26, 91, 90,505,504,511,510,517,516,842,841},
new[] {489,488,495,494,501,500, 99, 98, 63, 62, -3, -3, -3, -3, -3, -3, -3, -3, 28, 27, 93, 92,507,506,513,512,519,518,843, -3},
new[] {491,490,497,496,503,502,101,100, 65, 64, 17, -3, -3, -3, -3, -3, -3, -3, 18, 29, 95, 94,509,508,515,514,521,520,845,844},
new[] {559,558,553,552,547,546,541,540, 73, 72, 32, -3, -3, -3, -3, -3, -3, 10, 67, 66,115,114,535,534,529,528,523,522,846, -3},
new[] {561,560,555,554,549,548,543,542, 75, 74, -2, -1, 7, 6, 35, 34, 11, -2, 69, 68,117,116,537,536,531,530,525,524,848,847},
new[] {563,562,557,556,551,550,545,544, 77, 76, -2, 33, 9, 8, 25, 24, -1, -2, 71, 70,119,118,539,538,533,532,527,526,849, -3},
new[] {565,564,571,570,577,576,583,582,589,588,595,594,601,600,607,606,613,612,619,618,625,624,631,630,637,636,643,642,851,850},
new[] {567,566,573,572,579,578,585,584,591,590,597,596,603,602,609,608,615,614,621,620,627,626,633,632,639,638,645,644,852, -3},
new[] {569,568,575,574,581,580,587,586,593,592,599,598,605,604,611,610,617,616,623,622,629,628,635,634,641,640,647,646,854,853},
new[] {727,726,721,720,715,714,709,708,703,702,697,696,691,690,685,684,679,678,673,672,667,666,661,660,655,654,649,648,855, -3},
new[] {729,728,723,722,717,716,711,710,705,704,699,698,693,692,687,686,681,680,675,674,669,668,663,662,657,656,651,650,857,856},
new[] {731,730,725,724,719,718,713,712,707,706,701,700,695,694,689,688,683,682,677,676,671,670,665,664,659,658,653,652,858, -3},
new[] {733,732,739,738,745,744,751,750,757,756,763,762,769,768,775,774,781,780,787,786,793,792,799,798,805,804,811,810,860,859},
new[] {735,734,741,740,747,746,753,752,759,758,765,764,771,770,777,776,783,782,789,788,795,794,801,800,807,806,813,812,861, -3},
new[] {737,736,743,742,749,748,755,754,761,760,767,766,773,772,779,778,785,784,791,790,797,796,803,802,809,808,815,814,863,862}
};
private readonly BitMatrix bitMatrix;
/// <summary>
/// <param name="bitMatrix"><see cref="BitMatrix" />to parse</param>
/// </summary>
internal BitMatrixParser(BitMatrix bitMatrix)
{
this.bitMatrix = bitMatrix;
}
internal byte[] readCodewords()
{
byte[] result = new byte[144];
int height = bitMatrix.Height;
int width = bitMatrix.Width;
for (int y = 0; y < height; y++)
{
int[] bitnrRow = BITNR[y];
for (int x = 0; x < width; x++)
{
int bit = bitnrRow[x];
if (bit >= 0 && bitMatrix[x, y])
{
result[bit / 6] |= (byte)(1 << (5 - (bit % 6)));
}
}
}
return result;
}
}
}

View File

@@ -0,0 +1,218 @@
/*
* Copyright 2011 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;
using System.Text;
using ZXing.QrCode.Internal;
using ZXing.Common;
namespace ZXing.Maxicode.Internal
{
/// <summary>
/// <p>MaxiCodes can encode text or structured information as bits in one of several modes,
/// with multiple character sets in one code. This class decodes the bits back into text.</p>
///
/// <author>mike32767</author>
/// <author>Manuel Kasten</author>
/// </summary>
internal static class DecodedBitStreamParser
{
private const char SHIFTA = '\uFFF0';
private const char SHIFTB = '\uFFF1';
private const char SHIFTC = '\uFFF2';
private const char SHIFTD = '\uFFF3';
private const char SHIFTE = '\uFFF4';
private const char TWOSHIFTA = '\uFFF5';
private const char THREESHIFTA = '\uFFF6';
private const char LATCHA = '\uFFF7';
private const char LATCHB = '\uFFF8';
private const char LOCK = '\uFFF9';
private const char ECI = '\uFFFA';
private const char NS = '\uFFFB';
private const char PAD = '\uFFFC';
private const char FS = '\u001C';
private const char GS = '\u001D';
private const char RS = '\u001E';
private const string NINE_DIGITS = "000000000";
private const string THREE_DIGITS = "000";
private static String[] SETS = {
"\nABCDEFGHIJKLMNOPQRSTUVWXYZ"+ECI+FS+GS+RS+NS+' '+PAD+"\"#$%&'()*+,-./0123456789:"+SHIFTB+SHIFTC+SHIFTD+SHIFTE+LATCHB,
"`abcdefghijklmnopqrstuvwxyz"+ECI+FS+GS+RS+NS+'{'+PAD+"}~\u007F;<=>?[\\]^_ ,./:@!|"+PAD+TWOSHIFTA+THREESHIFTA+PAD+SHIFTA+SHIFTC+SHIFTD+SHIFTE+LATCHA,
"\u00C0\u00C1\u00C2\u00C3\u00C4\u00C5\u00C6\u00C7\u00C8\u00C9\u00CA\u00CB\u00CC\u00CD\u00CE\u00CF\u00D0\u00D1\u00D2\u00D3\u00D4\u00D5\u00D6\u00D7\u00D8\u00D9\u00DA"+ECI+FS+GS+RS+"\u00DB\u00DC\u00DD\u00DE\u00DF\u00AA\u00AC\u00B1\u00B2\u00B3\u00B5\u00B9\u00BA\u00BC\u00BD\u00BE\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089"+LATCHA+' '+LOCK+SHIFTD+SHIFTE+LATCHB,
"\u00E0\u00E1\u00E2\u00E3\u00E4\u00E5\u00E6\u00E7\u00E8\u00E9\u00EA\u00EB\u00EC\u00ED\u00EE\u00EF\u00F0\u00F1\u00F2\u00F3\u00F4\u00F5\u00F6\u00F7\u00F8\u00F9\u00FA"+ECI+FS+GS+RS+NS+"\u00FB\u00FC\u00FD\u00FE\u00FF\u00A1\u00A8\u00AB\u00AF\u00B0\u00B4\u00B7\u00B8\u00BB\u00BF\u008A\u008B\u008C\u008D\u008E\u008F\u0090\u0091\u0092\u0093\u0094"+LATCHA+' '+SHIFTC+LOCK+SHIFTE+LATCHB,
"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\n\u000B\u000C\r\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A"+ECI+PAD+PAD+'\u001B'+NS+FS+GS+RS+"\u001F\u009F\u00A0\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7\u00A9\u00AD\u00AE\u00B6\u0095\u0096\u0097\u0098\u0099\u009A\u009B\u009C\u009D\u009E"+LATCHA+' '+SHIFTC+SHIFTD+LOCK+LATCHB,
"\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\n\u000B\u000C\r\u000E\u000F\u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F\u0020\u0021\"\u0023\u0024\u0025\u0026\u0027\u0028\u0029\u002A\u002B\u002C\u002D\u002E\u002F\u0030\u0031\u0032\u0033\u0034\u0035\u0036\u0037\u0038\u0039\u003A\u003B\u003C\u003D\u003E\u003F"
};
internal static DecoderResult decode(byte[] bytes, int mode)
{
StringBuilder result = new StringBuilder(144);
switch (mode)
{
case 2:
case 3:
String postcode;
if (mode == 2)
{
int pc = getPostCode2(bytes);
var df = "0000000000".Substring(0, getPostCode2Length(bytes));
postcode = pc.ToString(df);
}
else
{
postcode = getPostCode3(bytes);
}
String country = getCountry(bytes).ToString(THREE_DIGITS);
String service = getServiceClass(bytes).ToString(THREE_DIGITS);
result.Append(getMessage(bytes, 10, 84));
if (result.ToString().StartsWith("[)>" + RS + "01" + GS))
{
result.Insert(9, postcode + GS + country + GS + service + GS);
}
else
{
result.Insert(0, postcode + GS + country + GS + service + GS);
}
break;
case 4:
result.Append(getMessage(bytes, 1, 93));
break;
case 5:
result.Append(getMessage(bytes, 1, 77));
break;
}
return new DecoderResult(bytes, result.ToString(), null, mode.ToString());
}
private static int getBit(int bit, byte[] bytes)
{
bit--;
return (bytes[bit / 6] & (1 << (5 - (bit % 6)))) == 0 ? 0 : 1;
}
private static int getInt(byte[] bytes, byte[] x)
{
if (x.Length == 0)
throw new ArgumentException("x");
int val = 0;
for (int i = 0; i < x.Length; i++)
{
val += getBit(x[i], bytes) << (x.Length - i - 1);
}
return val;
}
private static int getCountry(byte[] bytes)
{
return getInt(bytes, new byte[] { 53, 54, 43, 44, 45, 46, 47, 48, 37, 38 });
}
private static int getServiceClass(byte[] bytes)
{
return getInt(bytes, new byte[] { 55, 56, 57, 58, 59, 60, 49, 50, 51, 52 });
}
private static int getPostCode2Length(byte[] bytes)
{
return getInt(bytes, new byte[] { 39, 40, 41, 42, 31, 32 });
}
private static int getPostCode2(byte[] bytes)
{
return getInt(bytes, new byte[] {33, 34, 35, 36, 25, 26, 27, 28, 29, 30, 19,
20, 21, 22, 23, 24, 13, 14, 15, 16, 17, 18, 7, 8, 9, 10, 11, 12, 1, 2});
}
private static String getPostCode3(byte[] bytes)
{
return new String(
new char[]
{
SETS[0][getInt(bytes, new byte[] {39, 40, 41, 42, 31, 32})],
SETS[0][getInt(bytes, new byte[] {33, 34, 35, 36, 25, 26})],
SETS[0][getInt(bytes, new byte[] {27, 28, 29, 30, 19, 20})],
SETS[0][getInt(bytes, new byte[] {21, 22, 23, 24, 13, 14})],
SETS[0][getInt(bytes, new byte[] {15, 16, 17, 18, 7, 8})],
SETS[0][getInt(bytes, new byte[] {9, 10, 11, 12, 1, 2})],
}
);
}
private static String getMessage(byte[] bytes, int start, int len)
{
StringBuilder sb = new StringBuilder();
int shift = -1;
int set = 0;
int lastset = 0;
for (int i = start; i < start + len; i++)
{
char c = SETS[set][bytes[i]];
switch (c)
{
case LATCHA:
set = 0;
shift = -1;
break;
case LATCHB:
set = 1;
shift = -1;
break;
case SHIFTA:
case SHIFTB:
case SHIFTC:
case SHIFTD:
case SHIFTE:
lastset = set;
set = c - SHIFTA;
shift = 1;
break;
case TWOSHIFTA:
lastset = set;
set = 0;
shift = 2;
break;
case THREESHIFTA:
lastset = set;
set = 0;
shift = 3;
break;
case NS:
int nsval = (bytes[++i] << 24) + (bytes[++i] << 18) + (bytes[++i] << 12) + (bytes[++i] << 6) + bytes[++i];
sb.Append(nsval.ToString(NINE_DIGITS));
break;
case LOCK:
shift = -1;
break;
default:
sb.Append(c);
break;
}
if (shift-- == 0)
{
set = lastset;
}
}
while (sb.Length > 0 && sb[sb.Length - 1] == PAD)
{
sb.Length = sb.Length - 1;
}
return sb.ToString();
}
}
}

View File

@@ -0,0 +1,124 @@
/*
* Copyright 2011 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;
using System.Collections.Generic;
using ZXing.Common;
using ZXing.Common.ReedSolomon;
namespace ZXing.Maxicode.Internal
{
/// <summary>
/// <p>The main class which implements MaxiCode decoding -- as opposed to locating and extracting
/// the MaxiCode from an image.</p>
///
/// <author>Manuel Kasten</author>
/// </summary>
public sealed class Decoder
{
private const int ALL = 0;
private const int EVEN = 1;
private const int ODD = 2;
private readonly ReedSolomonDecoder rsDecoder;
public Decoder()
{
rsDecoder = new ReedSolomonDecoder(GenericGF.MAXICODE_FIELD_64);
}
public DecoderResult decode(BitMatrix bits)
{
return decode(bits, null);
}
public DecoderResult decode(BitMatrix bits,
IDictionary<DecodeHintType, object> hints)
{
BitMatrixParser parser = new BitMatrixParser(bits);
byte[] codewords = parser.readCodewords();
if (!correctErrors(codewords, 0, 10, 10, ALL))
return null;
int mode = codewords[0] & 0x0F;
byte[] datawords;
switch (mode)
{
case 2:
case 3:
case 4:
if (!correctErrors(codewords, 20, 84, 40, EVEN))
return null;
if (!correctErrors(codewords, 20, 84, 40, ODD))
return null;
datawords = new byte[94];
break;
case 5:
if (!correctErrors(codewords, 20, 68, 56, EVEN))
return null;
if (!correctErrors(codewords, 20, 68, 56, ODD))
return null;
datawords = new byte[78];
break;
default:
return null;
}
Array.Copy(codewords, 0, datawords, 0, 10);
Array.Copy(codewords, 20, datawords, 10, datawords.Length - 10);
return DecodedBitStreamParser.decode(datawords, mode);
}
private bool correctErrors(byte[] codewordBytes,
int start,
int dataCodewords,
int ecCodewords,
int mode)
{
int codewords = dataCodewords + ecCodewords;
// in EVEN or ODD mode only half the codewords
int divisor = mode == ALL ? 1 : 2;
// First read into an array of ints
int[] codewordsInts = new int[codewords / divisor];
for (int i = 0; i < codewords; i++)
{
if ((mode == ALL) || (i % 2 == (mode - 1)))
{
codewordsInts[i / divisor] = codewordBytes[i + start] & 0xFF;
}
}
if (!rsDecoder.decode(codewordsInts, ecCodewords / divisor))
return false;
// Copy back into array of bytes -- only need to worry about the bytes that were data
// We don't care about errors in the error-correction codewords
for (int i = 0; i < dataCodewords; i++)
{
if ((mode == ALL) || (i % 2 == (mode - 1)))
{
codewordBytes[i + start] = (byte)codewordsInts[i / divisor];
}
}
return true;
}
}
}