From f1c821a9cdbe800dab0514c409a1d2808c990ffe Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Wed, 7 Jan 2015 23:08:25 +0800 Subject: [PATCH 01/45] call controller.Stop() when application exit --- shadowsocks-csharp/Program.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index 716e0df7..c3c0537a 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -45,6 +45,8 @@ namespace Shadowsocks controller.Start(); Application.Run(); + + controller.Stop(); } } } From a984e907272ad3834f415430c79c7ecc9458690c Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Wed, 7 Jan 2015 23:10:12 +0800 Subject: [PATCH 02/45] Stop the PACServer when controller stop --- shadowsocks-csharp/Controller/ShadowsocksController.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 080390be..3d9d5119 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -128,6 +128,11 @@ namespace Shadowsocks.Controller { polipoRunner.Stop(); } + if (pacServer != null) + { + pacServer.Stop(); + pacServer = null; + } if (_config.enabled) { SystemProxy.Disable(); From a2f3116ca805828e89258f22a67c478536c4965d Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 00:54:12 +0800 Subject: [PATCH 03/45] auto update gfwlist, see https://github.com/shadowsocks/shadowsocks-csharp/issues/115 --- shadowsocks-csharp/Controller/GfwListUpdater.cs | 283 +++++++++++++++++++++ shadowsocks-csharp/Controller/PACServer.cs | 77 ++++++ shadowsocks-csharp/Data/tld.txt.gz | Bin 0 -> 26402 bytes .../Properties/Resources.Designer.cs | 58 +++-- shadowsocks-csharp/Properties/Resources.resx | 3 + shadowsocks-csharp/shadowsocks-csharp.csproj | 2 + 6 files changed, 399 insertions(+), 24 deletions(-) create mode 100644 shadowsocks-csharp/Controller/GfwListUpdater.cs create mode 100644 shadowsocks-csharp/Data/tld.txt.gz diff --git a/shadowsocks-csharp/Controller/GfwListUpdater.cs b/shadowsocks-csharp/Controller/GfwListUpdater.cs new file mode 100644 index 00000000..294422d4 --- /dev/null +++ b/shadowsocks-csharp/Controller/GfwListUpdater.cs @@ -0,0 +1,283 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; +using System.Net; +using System.IO; +using System.IO.Compression; +using System.Security.Cryptography; +using Shadowsocks.Model; +using Shadowsocks.Properties; + +namespace Shadowsocks.Controller +{ + public class GfwListUpdater + { + private const string GFWLIST_URL = "https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt"; + + private const int EXPIRE_HOURS = 6; + + public IWebProxy proxy = null; + + public bool useSystemProxy = true; + + public class GfwListChangedArgs : EventArgs + { + public string[] GfwList { get; set; } + } + + public event EventHandler GfwListChanged; + + private bool running = false; + private bool closed = false; + private int jobId = 0; + DateTime lastUpdateTimeUtc; + string lastUpdateMd5; + + private object locker = new object(); + + public GfwListUpdater() + { + } + + ~GfwListUpdater() + { + Stop(); + } + + public void Start() + { + lock (locker) + { + if (running) + return; + running = true; + closed = false; + jobId++; + new Thread(new ParameterizedThreadStart(UpdateJob)).Start(jobId); + } + } + + public void Stop() + { + lock(locker) + { + closed = true; + running = false; + jobId++; + } + } + + public void ScheduleUpdateTime(int delaySeconds) + { + lock(locker) + { + lastUpdateTimeUtc = DateTime.UtcNow.AddHours(-1 * EXPIRE_HOURS).AddSeconds(delaySeconds); + } + } + + private string DownloadGfwListFile() + { + try + { + WebClient http = new WebClient(); + http.Proxy = useSystemProxy ? WebRequest.GetSystemWebProxy() : proxy; + return http.DownloadString(new Uri(GFWLIST_URL)); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + return null; + } + + private bool IsExpire() + { + lock (locker) + { + TimeSpan ts = DateTime.UtcNow - lastUpdateTimeUtc; + bool expire = ((int)ts.TotalHours) >= EXPIRE_HOURS; + if (expire) + lastUpdateTimeUtc = DateTime.UtcNow; + return expire; + } + } + + private bool IsJobStop(int currentJobId) + { + lock (locker) + { + if (!running || closed || currentJobId != this.jobId) + return true; + } + return false; + } + + private bool IsGfwListChanged(string content) + { + byte[] inputBytes = Encoding.UTF8.GetBytes(content); + byte[] md5Bytes = MD5.Create().ComputeHash(inputBytes); + string md5 = ""; + for (int i = 0; i < md5Bytes.Length; i++) + md5 += md5Bytes[i].ToString("x").PadLeft(2, '0'); + if (md5 == lastUpdateMd5) + return false; + lastUpdateMd5 = md5; + return true; + } + + private void ParseGfwList(string response) + { + if (!IsGfwListChanged(response)) + return; + if (GfwListChanged != null) + { + Parser parser = new Parser(response); + GfwListChangedArgs args = new GfwListChangedArgs { + GfwList = parser.GetReducedDomains() + }; + GfwListChanged(this, args); + } + } + + private void UpdateJob(object state) + { + int currentJobId = (int)state; + int retryTimes = 3; + while (!IsJobStop(currentJobId)) + { + if (IsExpire()) + { + string response = DownloadGfwListFile(); + if (response != null) + { + ParseGfwList(response); + } + else if (retryTimes > 0) + { + ScheduleUpdateTime(30); /*Delay 30 seconds to retry*/ + retryTimes--; + } + else + { + retryTimes = 3; /* reset retry times, and wait next update time. */ + } + } + + Thread.Sleep(1000); + } + } + + class Parser + { + public string Content { get; private set; } + + public Parser(string response) + { + byte[] bytes = Convert.FromBase64String(response); + this.Content = Encoding.ASCII.GetString(bytes); + } + + public string[] GetLines() + { + return Content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + } + + /* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ + public string[] GetDomains() + { + string[] lines = GetLines(); + List domains = new List(lines.Length); + for(int i =0;i < lines.Length;i++) + { + string line = lines[i]; + if (line.IndexOf(".*") >= 0) + continue; + else if (line.IndexOf("*") >= 0) + line = line.Replace("*", "/"); + if (line.StartsWith("||")) + line = line.Substring(2); + else if (line.StartsWith("|")) + line = line.Substring(1); + else if (line.StartsWith(".")) + line = line.Substring(1); + if (line.StartsWith("!")) + continue; + else if (line.StartsWith("[")) + continue; + else if (line.StartsWith("@")) + continue; /*ignore white list*/ + domains.Add(line); + } + return domains.ToArray(); + } + + /* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ + public string[] GetReducedDomains() + { + string[] domains = GetDomains(); + List new_domains = new List(domains.Length); + IDictionary tld_dic = GetTldDictionary(); + + foreach(string domain in domains) + { + string last_root_domain = null; + int pos; + pos = domain.LastIndexOf('.'); + last_root_domain = domain.Substring(pos + 1); + if (!tld_dic.ContainsKey(last_root_domain)) + continue; + while(pos > 0) + { + pos = domain.LastIndexOf('.', pos - 1); + last_root_domain = domain.Substring(pos + 1); + if (tld_dic.ContainsKey(last_root_domain)) + continue; + else + break; + } + if (last_root_domain != null) + new_domains.Add(last_root_domain); + } + + return new_domains.ToArray(); + } + + private string[] GetTlds() + { + string[] tlds = null; + byte[] pacGZ = Resources.tld_txt; + byte[] buffer = new byte[1024]; + int n; + using(MemoryStream sb = new MemoryStream()) + { + using (GZipStream input = new GZipStream(new MemoryStream(pacGZ), + CompressionMode.Decompress, false)) + { + while ((n = input.Read(buffer, 0, buffer.Length)) > 0) + { + sb.Write(buffer, 0, n); + } + } + tlds = System.Text.Encoding.UTF8.GetString(sb.ToArray()) + .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + } + return tlds; + } + + private IDictionary GetTldDictionary() + { + string[] tlds = GetTlds(); + IDictionary dic = new Dictionary(tlds.Length); + foreach (string tld in tlds) + { + if (!dic.ContainsKey(tld)) + dic.Add(tld, tld); + } + return dic; + } + + } + + } +} diff --git a/shadowsocks-csharp/Controller/PACServer.cs b/shadowsocks-csharp/Controller/PACServer.cs index f02476ae..17351b19 100755 --- a/shadowsocks-csharp/Controller/PACServer.cs +++ b/shadowsocks-csharp/Controller/PACServer.cs @@ -8,6 +8,7 @@ using System.IO.Compression; using System.Net; using System.Net.Sockets; using System.Text; +using System.Text.RegularExpressions; namespace Shadowsocks.Controller { @@ -20,6 +21,8 @@ namespace Shadowsocks.Controller Socket _listener; FileSystemWatcher watcher; + GfwListUpdater gfwlistUpdater; + public event EventHandler PACFileChanged; public void Start(Configuration configuration) @@ -48,6 +51,7 @@ namespace Shadowsocks.Controller _listener); WatchPacFile(); + StartGfwListUpdater(); } catch (SocketException) { @@ -58,6 +62,11 @@ namespace Shadowsocks.Controller public void Stop() { + if (gfwlistUpdater != null) + { + gfwlistUpdater.Stop(); + gfwlistUpdater = null; + } if (_listener != null) { _listener.Close(); @@ -242,5 +251,73 @@ Connection: Close //} return proxy; } + + private void StartGfwListUpdater() + { + if (gfwlistUpdater != null) + { + gfwlistUpdater.Stop(); + gfwlistUpdater = null; + } + + gfwlistUpdater = new GfwListUpdater(); + gfwlistUpdater.GfwListChanged += gfwlistUpdater_GfwListChanged; + IPEndPoint localEndPoint = (IPEndPoint)_listener.LocalEndPoint; + gfwlistUpdater.proxy = new WebProxy(localEndPoint.Address.ToString(), 8123); + gfwlistUpdater.useSystemProxy = false; + /* Delay 30 seconds, wait proxy start up. */ + gfwlistUpdater.ScheduleUpdateTime(30); + gfwlistUpdater.Start(); + + } + + private void gfwlistUpdater_GfwListChanged(object sender, GfwListUpdater.GfwListChangedArgs e) + { + if (e.GfwList == null || e.GfwList.Length == 0) return; + string pacfile = TouchPACFile(); + string pacContent = File.ReadAllText(pacfile); + string oldDomains; + if (ClearPacContent(ref pacContent, out oldDomains)) + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine("{"); + for (int i = 0; i < e.GfwList.Length; i++) + { + if (i == e.GfwList.Length - 1) + sb.AppendFormat("\t\"{0}\": {1}\r\n", e.GfwList[i], 1); + else + sb.AppendFormat("\t\"{0}\": {1},\r\n", e.GfwList[i], 1); + } + sb.Append("}"); + string newDomains = sb.ToString(); + if (!string.Equals(oldDomains, newDomains)) + { + pacContent = pacContent.Replace("__LAST_MODIFIED__", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + pacContent = pacContent.Replace("__DOMAINS__", newDomains); + File.WriteAllText(pacfile, pacContent); + Console.WriteLine("gfwlist updated - " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + } + } + else + { + Console.WriteLine("Broken pac file."); + } + } + + private bool ClearPacContent(ref string pacContent, out string oldDomains) + { + Regex regex = new Regex("(/\\*.*?\\*/\\s*)?var\\s+domains\\s*=\\s*(\\{(\\s*\"[^\"]*\"\\s*:\\s*\\d+\\s*,)*\\s*(\\s*\"[^\"]*\"\\s*:\\s*\\d+\\s*)\\})", RegexOptions.Singleline); + Match m = regex.Match(pacContent); + if (m.Success) + { + oldDomains = m.Result("$2"); + pacContent = regex.Replace(pacContent, "/* Last Modified: __LAST_MODIFIED__ */\r\nvar domains = __DOMAINS__"); + return true; + } + oldDomains = null; + return false; + } + + } } diff --git a/shadowsocks-csharp/Data/tld.txt.gz b/shadowsocks-csharp/Data/tld.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..a502a241c14500b08eb05346fcaa8625cdfdd405 GIT binary patch literal 26402 zcmV+-XWf_|iwFo;7_C$Q19WU;E_8Tw0CZc+t~5DP-q%yiY=5bax|^Ya$8lylovyq% zkDXa{s#XXABLM;-4GW~%uo{8TNQ~5I=oVtZOZ15CG|gl1#l@ME&29M|%bC1t1kF*1K2_Yqd*F45L-ip=DCu$2yvJ*`&cw zb`$0h_mXp3sE?tPi zS7sPOnEd2aj-j_&RvVL<=t5=}8@JlEjf=;0iq7lKj5DOv`FYdCW$V*l{a~);baqQ( zQLT-3TL|Q|4vWbvQF$M}G(sKLsrFfj_9k3olXp5&<7!{@+SadO)> z37=;Vn_|VrPrG&P>+0u1e8X}lms`K#Bqcozt!->9*4+-?b=s_rwh&gU%W#8lw$X&l;jIHJ|+2W{?Q%eWt!OIYJ%hJ)af)*Y-#TR%f^DDbr| zYc$S0HhYaQ&SIy%-_gY0F7seEg>AgX`O9s1c1L5C^!WX9E9>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jAU*b}v>IVmDiO2=ao0DfBoBoU&d!qd%1b9y<=D~|z@4AQA~ z9hTPe1z!y>*yGLvlwu^g=pv0*B8j+gqS@wg>2=2Kr?8pw7~i}Kp?`HWVd=$I-ERR* zvQyWyLHRUk^Mbzzn40Lif8~6n&^=);BNfjqra4JT!1-IyJTwNgw~9U&`d}1&RP;&F z{*_rO*7X%T-Ya(PG&@wxD>HBSwdVJm=a|>d{6*0!&PHXfQIQ{=qE)!9qEE{INu|Z9 zFx{wVRTAf^(47i%(Dds -// This code was generated by a tool. -// Runtime Version:4.0.30319.18444 +// 此代码由工具生成。 +// 运行时版本:4.0.30319.34014 // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. +// 对此文件的更改可能会导致不正确的行为,并且如果 +// 重新生成代码,这些更改将会丢失。 // //------------------------------------------------------------------------------ @@ -13,12 +13,12 @@ namespace Shadowsocks.Properties { ///

- /// A strongly-typed resource class, for looking up localized strings, etc. + /// 一个强类型的资源类,用于查找本地化的字符串等。 /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. + // 此类是由 StronglyTypedResourceBuilder + // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 + // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen + // (以 /str 作为命令选项),或重新生成 VS 项目。 [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] @@ -33,7 +33,7 @@ namespace Shadowsocks.Properties { } /// - /// Returns the cached ResourceManager instance used by this class. + /// 返回此类使用的缓存的 ResourceManager 实例。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ namespace Shadowsocks.Properties { } /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. + /// 使用此强类型资源类,为所有资源查找 + /// 重写当前线程的 CurrentUICulture 属性。 /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { @@ -61,14 +61,14 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized string similar to Shadowsocks=Shadowsocks + /// 查找类似 Shadowsocks=Shadowsocks ///Enable=启用代理 ///Mode=代理模式 ///PAC=PAC 模式 ///Global=全局模式 ///Servers=服务器选择 ///Edit Servers...=编辑服务器... - ///Start on Boot=自动启动 + ///Start on Boot=开机启动 ///Share over LAN=在局域网共享代理 ///Edit PAC File...=编辑 PAC 文件... ///Show QRCode...=显示二维码... @@ -91,7 +91,7 @@ namespace Shadowsocks.Properties { ///QRCode=二维码 ///Shadowsocks Error: {0}=Shadowsocks 错误: {0} ///Port already in use=端口已被占用 - ///Il [rest of string was truncated]";. + ///Il [字符串的其余部分被截断]"; 的本地化字符串。 /// internal static string cn { get { @@ -100,7 +100,7 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized resource of type System.Byte[]. + /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] libsscrypto_dll { get { @@ -110,7 +110,7 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized string similar to proxyAddress = "__POLIPO_BIND_IP__" + /// 查找类似 proxyAddress = "__POLIPO_BIND_IP__" /// ///socksParentProxy = "127.0.0.1:__SOCKS_PORT__" ///socksProxyType = socks5 @@ -118,7 +118,7 @@ namespace Shadowsocks.Properties { ///localDocumentRoot = "" /// ///allowedPorts = 1-65535 - ///tunnelAllowedPorts = 1-65535. + ///tunnelAllowedPorts = 1-65535 的本地化字符串。 /// internal static string polipo_config { get { @@ -127,7 +127,7 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized resource of type System.Byte[]. + /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] polipo_exe { get { @@ -137,7 +137,7 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized resource of type System.Byte[]. + /// 查找 System.Byte[] 类型的本地化资源。 /// internal static byte[] proxy_pac_txt { get { @@ -147,7 +147,7 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized resource of type System.Drawing.Bitmap. + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// internal static System.Drawing.Bitmap ss16 { get { @@ -157,7 +157,7 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized resource of type System.Drawing.Bitmap. + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// internal static System.Drawing.Bitmap ss20 { get { @@ -167,7 +167,7 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized resource of type System.Drawing.Bitmap. + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// internal static System.Drawing.Bitmap ss24 { get { @@ -177,7 +177,7 @@ namespace Shadowsocks.Properties { } /// - /// Looks up a localized resource of type System.Drawing.Bitmap. + /// 查找 System.Drawing.Bitmap 类型的本地化资源。 /// internal static System.Drawing.Bitmap ssw128 { get { @@ -185,5 +185,15 @@ namespace Shadowsocks.Properties { return ((System.Drawing.Bitmap)(obj)); } } + + /// + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] tld_txt { + get { + object obj = ResourceManager.GetObject("tld_txt", resourceCulture); + return ((byte[])(obj)); + } + } } } diff --git a/shadowsocks-csharp/Properties/Resources.resx b/shadowsocks-csharp/Properties/Resources.resx index d8fb470d..b5e75b3f 100755 --- a/shadowsocks-csharp/Properties/Resources.resx +++ b/shadowsocks-csharp/Properties/Resources.resx @@ -145,4 +145,7 @@ ..\Resources\ssw128.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\Data\tld.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index e044d4fb..b192d0fd 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -86,6 +86,7 @@ + @@ -147,6 +148,7 @@ + From b7a8360449e99f7921505066aeb83d02ff75bad2 Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 01:40:08 +0800 Subject: [PATCH 04/45] Log more error information --- shadowsocks-csharp/Controller/GfwListUpdater.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/shadowsocks-csharp/Controller/GfwListUpdater.cs b/shadowsocks-csharp/Controller/GfwListUpdater.cs index 294422d4..ef200930 100644 --- a/shadowsocks-csharp/Controller/GfwListUpdater.cs +++ b/shadowsocks-csharp/Controller/GfwListUpdater.cs @@ -86,7 +86,7 @@ namespace Shadowsocks.Controller } catch (Exception ex) { - Console.WriteLine(ex.Message); + Console.WriteLine(ex.ToString()); } return null; } @@ -132,11 +132,19 @@ namespace Shadowsocks.Controller return; if (GfwListChanged != null) { - Parser parser = new Parser(response); - GfwListChangedArgs args = new GfwListChangedArgs { - GfwList = parser.GetReducedDomains() - }; - GfwListChanged(this, args); + try + { + Parser parser = new Parser(response); + GfwListChangedArgs args = new GfwListChangedArgs + { + GfwList = parser.GetReducedDomains() + }; + GfwListChanged(this, args); + } + catch(Exception ex) + { + Console.WriteLine(ex.ToString()); + } } } From 78c58b3a232044f2abe9be4045e088a1aa967436 Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 03:06:15 +0800 Subject: [PATCH 05/45] add co.hk --- shadowsocks-csharp/Data/tld.txt.gz | Bin 26402 -> 26403 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/shadowsocks-csharp/Data/tld.txt.gz b/shadowsocks-csharp/Data/tld.txt.gz index a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@ap`|m@<5P-> zPI{c^(Jznb!KW;9dIHs9ZbmELPhEn-ht5fRWzWpp3t0pjXuYp}j2JvJ!F5@v7Xno<}BDjLck+3+`?8Z~aL;kT$~!^|(SAUnz^RbCK_ zv~UO;Lj&ql@J%J|bkM$^{^b+Clg5k8cE7kG^_IPL%R08W77U#0EXGGths;3-OUH{Z zj9VP%8CU-1r?`Ps=#iSdl-h8^$sicOMDd~sdfm~|P-mS*eaLw1$#ZwY$rqA`STuH- ze1oZWev)VeO+(6NxbfH!EGj<8dnf*K4#Ezkktb3H(x)N>L2&f~r6bt>NS!6D+DP(C zLULI}n%@+X;M!VmqcOxTyBa^+QZay>l3Gdrw z?qm)f4=nf?(nQ@;DqjAU*b}v>IVmDiO2=ao0DfBoBoU&d!qd%1b9y<=D~|z@4AQA~ z9hTPe1z!y>*yGLvlwu^g=pv0*B8j+gqS@wg>2=2Kr?8pw7~i}Kp?`HWVd=$I-ERR* zvQyWyLHRUk^Mbzzn40Lif8~6n&^=);BNfjqra4JT!1-IyJTwNgw~9U&`d}1&RP;&F z{*_rO*7X%T-Ya(PG&@wxD>HBSwdVJm=a|>d{6*0!&PHXfQIQ{=qE)!9qEE{INu|Z9 zFx{wVRTAf^(47i%(Dds Date: Thu, 8 Jan 2015 03:07:26 +0800 Subject: [PATCH 06/45] support build in gfwlist --- shadowsocks-csharp/Controller/GfwListUpdater.cs | 77 ++++++++++++++++++--- shadowsocks-csharp/Data/builtin.txt.gz | Bin 0 -> 104 bytes .../Properties/Resources.Designer.cs | 10 +++ shadowsocks-csharp/Properties/Resources.resx | 3 + shadowsocks-csharp/shadowsocks-csharp.csproj | 1 + 5 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 shadowsocks-csharp/Data/builtin.txt.gz diff --git a/shadowsocks-csharp/Controller/GfwListUpdater.cs b/shadowsocks-csharp/Controller/GfwListUpdater.cs index ef200930..97f0cb2e 100644 --- a/shadowsocks-csharp/Controller/GfwListUpdater.cs +++ b/shadowsocks-csharp/Controller/GfwListUpdater.cs @@ -6,6 +6,7 @@ using System.Net; using System.IO; using System.IO.Compression; using System.Security.Cryptography; +using System.Text.RegularExpressions; using Shadowsocks.Model; using Shadowsocks.Properties; @@ -194,9 +195,10 @@ namespace Shadowsocks.Controller /* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ public string[] GetDomains() { - string[] lines = GetLines(); - List domains = new List(lines.Length); - for(int i =0;i < lines.Length;i++) + List lines = new List(GetLines()); + lines.AddRange(GetBuildIn()); + List domains = new List(lines.Count); + for (int i = 0; i < lines.Count; i++) { string line = lines[i]; if (line.IndexOf(".*") >= 0) @@ -225,7 +227,7 @@ namespace Shadowsocks.Controller { string[] domains = GetDomains(); List new_domains = new List(domains.Length); - IDictionary tld_dic = GetTldDictionary(); + TldIndex tldIndex = GetTldIndex(); foreach(string domain in domains) { @@ -233,13 +235,13 @@ namespace Shadowsocks.Controller int pos; pos = domain.LastIndexOf('.'); last_root_domain = domain.Substring(pos + 1); - if (!tld_dic.ContainsKey(last_root_domain)) + if (!tldIndex.Contains(last_root_domain)) continue; while(pos > 0) { pos = domain.LastIndexOf('.', pos - 1); last_root_domain = domain.Substring(pos + 1); - if (tld_dic.ContainsKey(last_root_domain)) + if (tldIndex.Contains(last_root_domain)) continue; else break; @@ -273,18 +275,73 @@ namespace Shadowsocks.Controller return tlds; } - private IDictionary GetTldDictionary() + private TldIndex GetTldIndex() { string[] tlds = GetTlds(); - IDictionary dic = new Dictionary(tlds.Length); + TldIndex index = new TldIndex(); foreach (string tld in tlds) { - if (!dic.ContainsKey(tld)) + index.Add(tld); + } + return index; + } + + private string[] GetBuildIn() + { + string[] buildin = null; + byte[] builtinGZ = Resources.builtin_txt; + byte[] buffer = new byte[1024]; + int n; + using (MemoryStream sb = new MemoryStream()) + { + using (GZipStream input = new GZipStream(new MemoryStream(builtinGZ), + CompressionMode.Decompress, false)) + { + while ((n = input.Read(buffer, 0, buffer.Length)) > 0) + { + sb.Write(buffer, 0, n); + } + } + buildin = System.Text.Encoding.UTF8.GetString(sb.ToArray()) + .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + } + return buildin; + } + + class TldIndex + { + List patterns = new List(); + IDictionary dic = new Dictionary(); + + public void Add(string tld) + { + if (string.IsNullOrEmpty(tld)) + return; + if (tld.IndexOfAny(new char[] { '*', '?' }) >= 0) + { + patterns.Add("^" + Regex.Escape(tld).Replace("\\*", ".*").Replace("\\?", ".") + "$"); + } + else if (!dic.ContainsKey(tld)) + { dic.Add(tld, tld); + } } - return dic; + + public bool Contains(string tld) + { + if (dic.ContainsKey(tld)) + return true; + foreach(string pattern in patterns) + { + if (Regex.IsMatch(tld, pattern)) + return true; + } + return false; + } + } + } } diff --git a/shadowsocks-csharp/Data/builtin.txt.gz b/shadowsocks-csharp/Data/builtin.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..c846e6448a7ec005ee03576b0d40e751c51f85f7 GIT binary patch literal 104 zcmV-u0GIzCiwFp_d973c17dY)Y; + /// 查找 System.Byte[] 类型的本地化资源。 + /// + internal static byte[] builtin_txt { + get { + object obj = ResourceManager.GetObject("builtin_txt", resourceCulture); + return ((byte[])(obj)); + } + } + + ///

/// 查找类似 Shadowsocks=Shadowsocks ///Enable=启用代理 ///Mode=代理模式 diff --git a/shadowsocks-csharp/Properties/Resources.resx b/shadowsocks-csharp/Properties/Resources.resx index b5e75b3f..2b53c8e1 100755 --- a/shadowsocks-csharp/Properties/Resources.resx +++ b/shadowsocks-csharp/Properties/Resources.resx @@ -118,6 +118,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Data\builtin.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + ..\data\cn.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index b192d0fd..6ed7cf4f 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -143,6 +143,7 @@ Designer + From dd0051658766c6c0206b1562701ee72803d4d8fb Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 03:30:55 +0800 Subject: [PATCH 07/45] refine, remove duplicate domains --- shadowsocks-csharp/Controller/GfwListUpdater.cs | 38 ++++++++++++++++++++----- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/shadowsocks-csharp/Controller/GfwListUpdater.cs b/shadowsocks-csharp/Controller/GfwListUpdater.cs index 97f0cb2e..ef4fe4eb 100644 --- a/shadowsocks-csharp/Controller/GfwListUpdater.cs +++ b/shadowsocks-csharp/Controller/GfwListUpdater.cs @@ -203,23 +203,32 @@ namespace Shadowsocks.Controller string line = lines[i]; if (line.IndexOf(".*") >= 0) continue; - else if (line.IndexOf("*") >= 0) + if (line.StartsWith("http://")) + line = line.Substring(7); + else if (line.StartsWith("https://")) + line = line.Substring(8); + if (line.IndexOf("*") >= 0) line = line.Replace("*", "/"); if (line.StartsWith("||")) - line = line.Substring(2); + while (line.StartsWith("||")) + line = line.Substring(2); else if (line.StartsWith("|")) - line = line.Substring(1); + line = line.TrimStart('|'); else if (line.StartsWith(".")) - line = line.Substring(1); + line = line.TrimStart('.'); if (line.StartsWith("!")) continue; else if (line.StartsWith("[")) continue; else if (line.StartsWith("@")) continue; /*ignore white list*/ - domains.Add(line); + int pos = line.IndexOfAny(new char[] { '/'}); + if (pos >= 0) + line = line.Substring(0, pos); + if (line.Length > 0) + domains.Add(line); } - return domains.ToArray(); + return RemoveDuplicate(domains.ToArray()); } /* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ @@ -250,7 +259,22 @@ namespace Shadowsocks.Controller new_domains.Add(last_root_domain); } - return new_domains.ToArray(); + return RemoveDuplicate(new_domains.ToArray()); + } + + private string[] RemoveDuplicate(string[] src) + { + List list = new List(src.Length); + Dictionary dic = new Dictionary(src.Length); + foreach(string s in src) + { + if (!dic.ContainsKey(s)) + { + dic.Add(s, s); + list.Add(s); + } + } + return list.ToArray(); } private string[] GetTlds() From c24c1d44b702285f487ef82aea2f045dc7ff1951 Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Wed, 7 Jan 2015 23:41:45 -0500 Subject: [PATCH 08/45] add new menu to update pac file via gfwlist --- shadowsocks-csharp/Controller/GfwListUpdater.cs | 196 +++++---------------- shadowsocks-csharp/Controller/PACServer.cs | 140 +++++++++------ .../Controller/ShadowsocksController.cs | 26 +++ shadowsocks-csharp/Data/abp.js.gz | Bin 0 -> 4594 bytes shadowsocks-csharp/Data/cn.txt | 3 + .../Properties/Resources.Designer.cs | 60 ++++--- shadowsocks-csharp/Properties/Resources.resx | 3 + shadowsocks-csharp/View/MenuViewController.cs | 29 +++ shadowsocks-csharp/shadowsocks-csharp.csproj | 1 + 9 files changed, 228 insertions(+), 230 deletions(-) create mode 100644 shadowsocks-csharp/Data/abp.js.gz diff --git a/shadowsocks-csharp/Controller/GfwListUpdater.cs b/shadowsocks-csharp/Controller/GfwListUpdater.cs index ef4fe4eb..c377efd2 100644 --- a/shadowsocks-csharp/Controller/GfwListUpdater.cs +++ b/shadowsocks-csharp/Controller/GfwListUpdater.cs @@ -16,186 +16,84 @@ namespace Shadowsocks.Controller { private const string GFWLIST_URL = "https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt"; - private const int EXPIRE_HOURS = 6; - public IWebProxy proxy = null; - public bool useSystemProxy = true; - - public class GfwListChangedArgs : EventArgs + public class GfwListDownloadCompletedArgs : EventArgs { - public string[] GfwList { get; set; } + public string Content; } - public event EventHandler GfwListChanged; - - private bool running = false; - private bool closed = false; - private int jobId = 0; - DateTime lastUpdateTimeUtc; - string lastUpdateMd5; - - private object locker = new object(); + public event EventHandler DownloadCompleted; - public GfwListUpdater() - { - } + public event ErrorEventHandler Error; - ~GfwListUpdater() + public void Download() { - Stop(); + WebClient http = new WebClient(); + http.Proxy = proxy; + http.DownloadStringCompleted += http_DownloadStringCompleted; + http.DownloadStringAsync(new Uri(GFWLIST_URL)); } - public void Start() + protected void ReportError(Exception e) { - lock (locker) + if (Error != null) { - if (running) - return; - running = true; - closed = false; - jobId++; - new Thread(new ParameterizedThreadStart(UpdateJob)).Start(jobId); + Error(this, new ErrorEventArgs(e)); } } - public void Stop() - { - lock(locker) - { - closed = true; - running = false; - jobId++; - } - } - - public void ScheduleUpdateTime(int delaySeconds) - { - lock(locker) - { - lastUpdateTimeUtc = DateTime.UtcNow.AddHours(-1 * EXPIRE_HOURS).AddSeconds(delaySeconds); - } - } - - private string DownloadGfwListFile() + private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { try { - WebClient http = new WebClient(); - http.Proxy = useSystemProxy ? WebRequest.GetSystemWebProxy() : proxy; - return http.DownloadString(new Uri(GFWLIST_URL)); + string response = e.Result; + if (DownloadCompleted != null) + { + DownloadCompleted(this, new GfwListDownloadCompletedArgs + { + Content = response + }); + } } catch (Exception ex) { - Console.WriteLine(ex.ToString()); + ReportError(ex); } - return null; } - private bool IsExpire() + public class Parser { - lock (locker) - { - TimeSpan ts = DateTime.UtcNow - lastUpdateTimeUtc; - bool expire = ((int)ts.TotalHours) >= EXPIRE_HOURS; - if (expire) - lastUpdateTimeUtc = DateTime.UtcNow; - return expire; - } - } + private string _Content; - private bool IsJobStop(int currentJobId) - { - lock (locker) + public string Content { - if (!running || closed || currentJobId != this.jobId) - return true; + get { return _Content; } } - return false; - } - private bool IsGfwListChanged(string content) - { - byte[] inputBytes = Encoding.UTF8.GetBytes(content); - byte[] md5Bytes = MD5.Create().ComputeHash(inputBytes); - string md5 = ""; - for (int i = 0; i < md5Bytes.Length; i++) - md5 += md5Bytes[i].ToString("x").PadLeft(2, '0'); - if (md5 == lastUpdateMd5) - return false; - lastUpdateMd5 = md5; - return true; - } - - private void ParseGfwList(string response) - { - if (!IsGfwListChanged(response)) - return; - if (GfwListChanged != null) + public Parser(string response) { - try - { - Parser parser = new Parser(response); - GfwListChangedArgs args = new GfwListChangedArgs - { - GfwList = parser.GetReducedDomains() - }; - GfwListChanged(this, args); - } - catch(Exception ex) - { - Console.WriteLine(ex.ToString()); - } + byte[] bytes = Convert.FromBase64String(response); + this._Content = Encoding.ASCII.GetString(bytes); } - } - private void UpdateJob(object state) - { - int currentJobId = (int)state; - int retryTimes = 3; - while (!IsJobStop(currentJobId)) + public string[] GetValidLines() { - if (IsExpire()) + string[] lines = Content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + List valid_lines = new List(lines.Length); + foreach (string line in lines) { - string response = DownloadGfwListFile(); - if (response != null) - { - ParseGfwList(response); - } - else if (retryTimes > 0) - { - ScheduleUpdateTime(30); /*Delay 30 seconds to retry*/ - retryTimes--; - } - else - { - retryTimes = 3; /* reset retry times, and wait next update time. */ - } + if (line.StartsWith("!") || line.StartsWith("[")) + continue; + valid_lines.Add(line); } - - Thread.Sleep(1000); - } - } - - class Parser - { - public string Content { get; private set; } - - public Parser(string response) - { - byte[] bytes = Convert.FromBase64String(response); - this.Content = Encoding.ASCII.GetString(bytes); + return valid_lines.ToArray(); } - public string[] GetLines() - { - return Content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); - } - /* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ public string[] GetDomains() { - List lines = new List(GetLines()); + List lines = new List(GetValidLines()); lines.AddRange(GetBuildIn()); List domains = new List(lines.Count); for (int i = 0; i < lines.Count; i++) @@ -222,7 +120,7 @@ namespace Shadowsocks.Controller continue; else if (line.StartsWith("@")) continue; /*ignore white list*/ - int pos = line.IndexOfAny(new char[] { '/'}); + int pos = line.IndexOfAny(new char[] { '/' }); if (pos >= 0) line = line.Substring(0, pos); if (line.Length > 0) @@ -238,7 +136,7 @@ namespace Shadowsocks.Controller List new_domains = new List(domains.Length); TldIndex tldIndex = GetTldIndex(); - foreach(string domain in domains) + foreach (string domain in domains) { string last_root_domain = null; int pos; @@ -246,7 +144,7 @@ namespace Shadowsocks.Controller last_root_domain = domain.Substring(pos + 1); if (!tldIndex.Contains(last_root_domain)) continue; - while(pos > 0) + while (pos > 0) { pos = domain.LastIndexOf('.', pos - 1); last_root_domain = domain.Substring(pos + 1); @@ -266,7 +164,7 @@ namespace Shadowsocks.Controller { List list = new List(src.Length); Dictionary dic = new Dictionary(src.Length); - foreach(string s in src) + foreach (string s in src) { if (!dic.ContainsKey(s)) { @@ -281,9 +179,9 @@ namespace Shadowsocks.Controller { string[] tlds = null; byte[] pacGZ = Resources.tld_txt; - byte[] buffer = new byte[1024]; + byte[] buffer = new byte[1024]; int n; - using(MemoryStream sb = new MemoryStream()) + using (MemoryStream sb = new MemoryStream()) { using (GZipStream input = new GZipStream(new MemoryStream(pacGZ), CompressionMode.Decompress, false)) @@ -332,7 +230,7 @@ namespace Shadowsocks.Controller return buildin; } - class TldIndex + public class TldIndex { List patterns = new List(); IDictionary dic = new Dictionary(); @@ -355,7 +253,7 @@ namespace Shadowsocks.Controller { if (dic.ContainsKey(tld)) return true; - foreach(string pattern in patterns) + foreach (string pattern in patterns) { if (Regex.IsMatch(tld, pattern)) return true; @@ -365,7 +263,7 @@ namespace Shadowsocks.Controller } - + } } diff --git a/shadowsocks-csharp/Controller/PACServer.cs b/shadowsocks-csharp/Controller/PACServer.cs index 17351b19..52b838ba 100755 --- a/shadowsocks-csharp/Controller/PACServer.cs +++ b/shadowsocks-csharp/Controller/PACServer.cs @@ -1,6 +1,7 @@ using Shadowsocks.Model; using Shadowsocks.Properties; using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -21,10 +22,12 @@ namespace Shadowsocks.Controller Socket _listener; FileSystemWatcher watcher; - GfwListUpdater gfwlistUpdater; - public event EventHandler PACFileChanged; + public event EventHandler UpdatePACFromGFWListCompleted; + + public event ErrorEventHandler UpdatePACFromGFWListError; + public void Start(Configuration configuration) { try @@ -51,7 +54,6 @@ namespace Shadowsocks.Controller _listener); WatchPacFile(); - StartGfwListUpdater(); } catch (SocketException) { @@ -62,11 +64,6 @@ namespace Shadowsocks.Controller public void Stop() { - if (gfwlistUpdater != null) - { - gfwlistUpdater.Stop(); - gfwlistUpdater = null; - } if (_listener != null) { _listener.Close(); @@ -146,7 +143,7 @@ namespace Shadowsocks.Controller using (GZipStream input = new GZipStream(new MemoryStream(pacGZ), CompressionMode.Decompress, false)) { - while((n = input.Read(buffer, 0, buffer.Length)) > 0) + while ((n = input.Read(buffer, 0, buffer.Length)) > 0) { sb.Write(buffer, 0, n); } @@ -252,72 +249,103 @@ Connection: Close return proxy; } - private void StartGfwListUpdater() + public void UpdatePACFromGFWList() + { + GfwListUpdater gfwlist = new GfwListUpdater(); + gfwlist.DownloadCompleted += gfwlist_DownloadCompleted; + gfwlist.Error += gfwlist_Error; + gfwlist.proxy = new WebProxy(IPAddress.Loopback.ToString(), 8123); /* use polipo proxy*/ + gfwlist.Download(); + } + + private void gfwlist_DownloadCompleted(object sender, GfwListUpdater.GfwListDownloadCompletedArgs e) { - if (gfwlistUpdater != null) + GfwListUpdater.Parser parser = new GfwListUpdater.Parser(e.Content); + string[] lines = parser.GetValidLines(); + StringBuilder rules = new StringBuilder(lines.Length * 16); + SerializeRules(lines, rules); + string abpContent = GetAbpContent(); + abpContent = abpContent.Replace("__RULES__", rules.ToString()); + File.WriteAllText(PAC_FILE, abpContent); + if (UpdatePACFromGFWListCompleted != null) { - gfwlistUpdater.Stop(); - gfwlistUpdater = null; + UpdatePACFromGFWListCompleted(this, new EventArgs()); } + } - gfwlistUpdater = new GfwListUpdater(); - gfwlistUpdater.GfwListChanged += gfwlistUpdater_GfwListChanged; - IPEndPoint localEndPoint = (IPEndPoint)_listener.LocalEndPoint; - gfwlistUpdater.proxy = new WebProxy(localEndPoint.Address.ToString(), 8123); - gfwlistUpdater.useSystemProxy = false; - /* Delay 30 seconds, wait proxy start up. */ - gfwlistUpdater.ScheduleUpdateTime(30); - gfwlistUpdater.Start(); - + private void gfwlist_Error(object sender, ErrorEventArgs e) + { + if (UpdatePACFromGFWListError != null) + { + UpdatePACFromGFWListError(this, e); + } } - private void gfwlistUpdater_GfwListChanged(object sender, GfwListUpdater.GfwListChangedArgs e) + private string GetAbpContent() { - if (e.GfwList == null || e.GfwList.Length == 0) return; - string pacfile = TouchPACFile(); - string pacContent = File.ReadAllText(pacfile); - string oldDomains; - if (ClearPacContent(ref pacContent, out oldDomains)) + byte[] abpGZ = Resources.abp_js; + byte[] buffer = new byte[1024]; // builtin pac gzip size: maximum 100K + int n; + using (MemoryStream sb = new MemoryStream()) { - StringBuilder sb = new StringBuilder(); - sb.AppendLine("{"); - for (int i = 0; i < e.GfwList.Length; i++) - { - if (i == e.GfwList.Length - 1) - sb.AppendFormat("\t\"{0}\": {1}\r\n", e.GfwList[i], 1); - else - sb.AppendFormat("\t\"{0}\": {1},\r\n", e.GfwList[i], 1); - } - sb.Append("}"); - string newDomains = sb.ToString(); - if (!string.Equals(oldDomains, newDomains)) + using (GZipStream input = new GZipStream(new MemoryStream(abpGZ), + CompressionMode.Decompress, false)) { - pacContent = pacContent.Replace("__LAST_MODIFIED__", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); - pacContent = pacContent.Replace("__DOMAINS__", newDomains); - File.WriteAllText(pacfile, pacContent); - Console.WriteLine("gfwlist updated - " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); + while ((n = input.Read(buffer, 0, buffer.Length)) > 0) + { + sb.Write(buffer, 0, n); + } } + return System.Text.Encoding.UTF8.GetString(sb.ToArray()); } - else + } + + private static void SerializeRules(string[] rules, StringBuilder builder) + { + builder.Append("[\n"); + + bool first = true; + foreach (string rule in rules) { - Console.WriteLine("Broken pac file."); + if (!first) + builder.Append(",\n"); + + SerializeString(rule, builder); + + first = false; } + + builder.Append("\n]"); } - private bool ClearPacContent(ref string pacContent, out string oldDomains) + private static void SerializeString(string aString, StringBuilder builder) { - Regex regex = new Regex("(/\\*.*?\\*/\\s*)?var\\s+domains\\s*=\\s*(\\{(\\s*\"[^\"]*\"\\s*:\\s*\\d+\\s*,)*\\s*(\\s*\"[^\"]*\"\\s*:\\s*\\d+\\s*)\\})", RegexOptions.Singleline); - Match m = regex.Match(pacContent); - if (m.Success) + builder.Append("\t\""); + + char[] charArray = aString.ToCharArray(); + for (int i = 0; i < charArray.Length; i++) { - oldDomains = m.Result("$2"); - pacContent = regex.Replace(pacContent, "/* Last Modified: __LAST_MODIFIED__ */\r\nvar domains = __DOMAINS__"); - return true; + char c = charArray[i]; + if (c == '"') + builder.Append("\\\""); + else if (c == '\\') + builder.Append("\\\\"); + else if (c == '\b') + builder.Append("\\b"); + else if (c == '\f') + builder.Append("\\f"); + else if (c == '\n') + builder.Append("\\n"); + else if (c == '\r') + builder.Append("\\r"); + else if (c == '\t') + builder.Append("\\t"); + else + builder.Append(c); } - oldDomains = null; - return false; - } + builder.Append("\""); + } } } diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 3d9d5119..427fe9bf 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -38,6 +38,10 @@ namespace Shadowsocks.Controller // when user clicked Edit PAC, and PAC file has already created public event EventHandler PACFileReadyToOpen; + public event EventHandler UpdatePACFromGFWListCompleted; + + public event ErrorEventHandler UpdatePACFromGFWListError; + public event ErrorEventHandler Errored; public ShadowsocksController() @@ -156,6 +160,14 @@ namespace Shadowsocks.Controller return "ss://" + base64; } + public void UpdatePACFromGFWList() + { + if (pacServer != null) + { + pacServer.UpdatePACFromGFWList(); + } + } + protected void Reload() { // some logic in configuration updated the config when saving, we need to read it again @@ -169,6 +181,8 @@ namespace Shadowsocks.Controller { pacServer = new PACServer(); pacServer.PACFileChanged += pacServer_PACFileChanged; + pacServer.UpdatePACFromGFWListCompleted += pacServer_UpdatePACFromGFWListCompleted; + pacServer.UpdatePACFromGFWListError += pacServer_UpdatePACFromGFWListError; } pacServer.Stop(); @@ -247,6 +261,18 @@ namespace Shadowsocks.Controller UpdateSystemProxy(); } + private void pacServer_UpdatePACFromGFWListCompleted(object sender, EventArgs e) + { + if (UpdatePACFromGFWListCompleted != null) + UpdatePACFromGFWListCompleted(this, e); + } + + private void pacServer_UpdatePACFromGFWListError(object sender, ErrorEventArgs e) + { + if (UpdatePACFromGFWListError != null) + UpdatePACFromGFWListError(this, e); + } + private void StartReleasingMemory() { _ramThread = new Thread(new ThreadStart(ReleaseMemory)); diff --git a/shadowsocks-csharp/Data/abp.js.gz b/shadowsocks-csharp/Data/abp.js.gz new file mode 100644 index 0000000000000000000000000000000000000000..4742149658d7de5482c3dad933840410cd7358bb GIT binary patch literal 4594 zcmV@U2t;17TutE^2cC?Hp@U8cX)OzoO-4vy2izV>GKV1`#8BHM)p( zZwibx4ui~QoS|k0k&WKpzNeql-SYy&Zr$2is+6I-&!bPDSD$XE)zD|#vja1-2k3T& z?uJv>38T%iX(7i$3}y!i&RU)32|zRs+o$dB zR|FC{Zg;=5E-%sXc?UJnMWfSgH?K|`9dvQkxj4UURS~+hF;h0c=g4MAqzls?*pcbD zA)WJASdI`la|dW-KG?7dLS#X!DNmcD=Hf+KUNUDh-Ta2#En3;e?0GzM%qxl zxdB^<{F@u-@+Pj!JEKY9u`zoq&l3JSJ360w7Xd715Y3M4&-JWr( z&Jf|Y>c|WwfHEFokO6d$~qe{lp>ZGag{Viv$4G=fH(tjAArP|RW|YlgA?_@j3*YXu0ksY!j@6Sb8xVk%Tnhf;;Hgg zkff}shGQ7YXcab{$)0nq$QwTIDPYel>eI8LMaPZ{9jK<^UOt*kKaV{o}6@-M+%dUv~$0;HRWV2GoF3{bU&W2*A3%UO;8Q&JNt1g z)BFS!`nBp>zlQO?`r{zR3^*(O5HMgCD(O8y=|IBo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|=JR)v)asVbB5<(0(d zB`G%Tn{&xY%eCo(612*XRDVvAeL+cCyS^h8{sCl@oF9;bgnWu=2L{OrTc$T~1`ygp z4x(&n>0xBK*866@`B(kT-~O_8-D6MJKi*cJ%lMl{qRXh=X`)$;@&DAijLdM9;aB!j zl&a}ZJS>Ba?VX*S&5d_yV@{dH$;DRnx^@M*IP!}b#Fw`5EpF}ZcG9&7Km|$9xz4)u zOOH_~=P@vNb~5_|^41d_*W739>g8g(UB`GnDDogh1%iHGX@C7XCMRy4C{ilE&BRPu z;7NKNb!7-6S%bvV=xpT|SSW&oHZk`E(&MRPfpg-AipAkoA#i6$OeK%~U`|p?$qW|> z(hC(GQck7WTyG$Ox4x5Hh-CB9L>V7oJj*y|UOcH->?;>ZvmNr3KlLjX@q!UIOb?Qa z%tJw$SFe=Rft}mG@U(v3>xWwYt#XvGs#qb^%LNT@w(R=_iP*%kX2d5sC?%qhjHsw~ zDbwtw8jchY$TmQ^;j`2TLgR!UK2pwS={W8@G#e>Cs+DpvfA2#f^b0OB`twAj z4760y)PJHX1C|p;rf1;_hgR##Ej7e*0eX4mfSg#X39SH;xOSz?{-eAfO+i18Obg^1 zv$1%kVp&3_B$p%SVqAY7Q7^Kw{waCO>0~VS+=}8N`J}c4bKqS#b^i}cUl3pFWVkaf0GcrOeE -// 此代码由工具生成。 -// 运行时版本:4.0.30319.34014 +// This code was generated by a tool. +// Runtime Version:4.0.30319.18444 // -// 对此文件的更改可能会导致不正确的行为,并且如果 -// 重新生成代码,这些更改将会丢失。 +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. // //------------------------------------------------------------------------------ @@ -13,12 +13,12 @@ namespace Shadowsocks.Properties { /// - /// 一个强类型的资源类,用于查找本地化的字符串等。 + /// A strongly-typed resource class, for looking up localized strings, etc. /// - // 此类是由 StronglyTypedResourceBuilder - // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 - // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen - // (以 /str 作为命令选项),或重新生成 VS 项目。 + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] @@ -33,7 +33,7 @@ namespace Shadowsocks.Properties { } /// - /// 返回此类使用的缓存的 ResourceManager 实例。 + /// Returns the cached ResourceManager instance used by this class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Resources.ResourceManager ResourceManager { @@ -47,8 +47,8 @@ namespace Shadowsocks.Properties { } /// - /// 使用此强类型资源类,为所有资源查找 - /// 重写当前线程的 CurrentUICulture 属性。 + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. /// [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] internal static global::System.Globalization.CultureInfo Culture { @@ -61,7 +61,17 @@ namespace Shadowsocks.Properties { } /// - /// 查找 System.Byte[] 类型的本地化资源。 + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] abp_js { + get { + object obj = ResourceManager.GetObject("abp_js", resourceCulture); + return ((byte[])(obj)); + } + } + + /// + /// Looks up a localized resource of type System.Byte[]. /// internal static byte[] builtin_txt { get { @@ -71,7 +81,7 @@ namespace Shadowsocks.Properties { } /// - /// 查找类似 Shadowsocks=Shadowsocks + /// Looks up a localized string similar to Shadowsocks=Shadowsocks ///Enable=启用代理 ///Mode=代理模式 ///PAC=PAC 模式 @@ -101,7 +111,7 @@ namespace Shadowsocks.Properties { ///QRCode=二维码 ///Shadowsocks Error: {0}=Shadowsocks 错误: {0} ///Port already in use=端口已被占用 - ///Il [字符串的其余部分被截断]"; 的本地化字符串。 + ///Il [rest of string was truncated]";. /// internal static string cn { get { @@ -110,7 +120,7 @@ namespace Shadowsocks.Properties { } /// - /// 查找 System.Byte[] 类型的本地化资源。 + /// Looks up a localized resource of type System.Byte[]. /// internal static byte[] libsscrypto_dll { get { @@ -120,7 +130,7 @@ namespace Shadowsocks.Properties { } /// - /// 查找类似 proxyAddress = "__POLIPO_BIND_IP__" + /// Looks up a localized string similar to proxyAddress = "__POLIPO_BIND_IP__" /// ///socksParentProxy = "127.0.0.1:__SOCKS_PORT__" ///socksProxyType = socks5 @@ -128,7 +138,7 @@ namespace Shadowsocks.Properties { ///localDocumentRoot = "" /// ///allowedPorts = 1-65535 - ///tunnelAllowedPorts = 1-65535 的本地化字符串。 + ///tunnelAllowedPorts = 1-65535. /// internal static string polipo_config { get { @@ -137,7 +147,7 @@ namespace Shadowsocks.Properties { } /// - /// 查找 System.Byte[] 类型的本地化资源。 + /// Looks up a localized resource of type System.Byte[]. /// internal static byte[] polipo_exe { get { @@ -147,7 +157,7 @@ namespace Shadowsocks.Properties { } /// - /// 查找 System.Byte[] 类型的本地化资源。 + /// Looks up a localized resource of type System.Byte[]. /// internal static byte[] proxy_pac_txt { get { @@ -157,7 +167,7 @@ namespace Shadowsocks.Properties { } /// - /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// Looks up a localized resource of type System.Drawing.Bitmap. /// internal static System.Drawing.Bitmap ss16 { get { @@ -167,7 +177,7 @@ namespace Shadowsocks.Properties { } /// - /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// Looks up a localized resource of type System.Drawing.Bitmap. /// internal static System.Drawing.Bitmap ss20 { get { @@ -177,7 +187,7 @@ namespace Shadowsocks.Properties { } /// - /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// Looks up a localized resource of type System.Drawing.Bitmap. /// internal static System.Drawing.Bitmap ss24 { get { @@ -187,7 +197,7 @@ namespace Shadowsocks.Properties { } /// - /// 查找 System.Drawing.Bitmap 类型的本地化资源。 + /// Looks up a localized resource of type System.Drawing.Bitmap. /// internal static System.Drawing.Bitmap ssw128 { get { @@ -197,7 +207,7 @@ namespace Shadowsocks.Properties { } /// - /// 查找 System.Byte[] 类型的本地化资源。 + /// Looks up a localized resource of type System.Byte[]. /// internal static byte[] tld_txt { get { diff --git a/shadowsocks-csharp/Properties/Resources.resx b/shadowsocks-csharp/Properties/Resources.resx index 2b53c8e1..24d1b168 100755 --- a/shadowsocks-csharp/Properties/Resources.resx +++ b/shadowsocks-csharp/Properties/Resources.resx @@ -118,6 +118,9 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + ..\Data\abp.js.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + ..\Data\builtin.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index a22a8b05..649ac44c 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -45,6 +45,8 @@ namespace Shadowsocks.View controller.ShareOverLANStatusChanged += controller_ShareOverLANStatusChanged; controller.EnableGlobalChanged += controller_EnableGlobalChanged; controller.Errored += controller_Errored; + controller.UpdatePACFromGFWListCompleted += controller_UpdatePACFromGFWListCompleted; + controller.UpdatePACFromGFWListError += controller_UpdatePACFromGFWListError; _notifyIcon = new NotifyIcon(); UpdateTrayIcon(); @@ -138,6 +140,7 @@ namespace Shadowsocks.View this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)), this.ShareOverLANItem = CreateMenuItem("Share over LAN", new EventHandler(this.ShareOverLANItem_Click)), CreateMenuItem("Edit PAC File...", new EventHandler(this.EditPACFileItem_Click)), + CreateMenuItem("Update PAC File via gfwlist...", new EventHandler(this.UpdatePACFromGFWListItem_Click)), new MenuItem("-"), CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)), CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)), @@ -176,6 +179,23 @@ namespace Shadowsocks.View System.Diagnostics.Process.Start("explorer.exe", argument); } + void controller_UpdatePACFromGFWListError(object sender, System.IO.ErrorEventArgs e) + { + _notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist..."); + _notifyIcon.BalloonTipText = I18N.GetString("Update PAC file failed"); + _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; + _notifyIcon.ShowBalloonTip(5000); + Logging.LogUsefulException(e.GetException()); + } + + void controller_UpdatePACFromGFWListCompleted(object sender, EventArgs e) + { + _notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist..."); + _notifyIcon.BalloonTipText = I18N.GetString("Update PAC file succeed"); + _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; + _notifyIcon.ShowBalloonTip(5000); + } + void updateChecker_NewVersionFound(object sender, EventArgs e) { _notifyIcon.BalloonTipTitle = String.Format(I18N.GetString("Shadowsocks {0} Update Found"), updateChecker.LatestVersionNumber); @@ -311,6 +331,15 @@ namespace Shadowsocks.View controller.TouchPACFile(); } + private void UpdatePACFromGFWListItem_Click(object sender, EventArgs e) + { + _notifyIcon.BalloonTipTitle = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version; + _notifyIcon.BalloonTipText = I18N.GetString("Update PAC File via gfwlist..."); + _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; + _notifyIcon.ShowBalloonTip(5000); + controller.UpdatePACFromGFWList(); + } + private void AServerItem_Click(object sender, EventArgs e) { MenuItem item = (MenuItem)sender; diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 6ed7cf4f..314ea6a3 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -143,6 +143,7 @@ Designer + From d4f2ea676578eedc74178de465609b417af3e029 Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 00:10:26 -0500 Subject: [PATCH 09/45] fix abp.js error --- shadowsocks-csharp/Data/abp.js.gz | Bin 4594 -> 4597 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/shadowsocks-csharp/Data/abp.js.gz b/shadowsocks-csharp/Data/abp.js.gz index 4742149658d7de5482c3dad933840410cd7358bb..d265cfd68a7aaa331fbd0be03ca58ece548b2099 100644 GIT binary patch delta 4541 zcmV;u5kl_rBlRN(ABzYGQxL9^2OkO*BYQQvh;?rY43RJze^i+6^XSv(-Ho*x`fPi4 zU`F-;-OkY6aOyf?v^h2{P_WPwhIucA=JA{#bzkPkyyz2Mid2MZF4RuCN zh=z`9BltTue}f45L(~}Dy1w-tUAmJHeZV{b3nqOyhG$hjxT}4v0QiwVo(0a`C_?2U z18vsp+iy1O8(XM3vwigW{`PbQ6H)MCdVy`D&>u!qGq88j%%333^iW_AU^#(vJBfgu z2$|lX<_B07&Ts~3;L*ez*a3=0Hj3=vKE%x851+qWe>1VV=yG!FIu<%}EZYM~KG;F% z_#S$T%n)#l@n|@r!pEQ|n3pTY3p(+Ef*AooHI?(2!2#Ybj9}!Cft!&TVg9C$>!Mp5 zO+tG(aj}G8F8Zz2IlZ{U?QlU7?eUHfo^DM!VBGx;|^P(dBjf^5UvlMd-@L zOxXaRBbyh9iWlgu{nDy&l3JSJGz*9mjP^N5Y3M5 z&-JWr(&Jf{e)sY!W0A)PGAQR{`i5$%C!tf2{;aTQ{vL^FkKSs7U ze<+8OTgx@W5F|AL0_^?39y*?b=gHh$-2T(Hq$TTY#88S@V#HPQFq)0+JpsfSh{pgV z#w4%Bc45<1l6Y&P`!T@)aC~)Tq59+P8A|Td&qzf9pN< zK9yE))((tc%DqpW_mMGvKWBLcoAosHBeor2`4S zPbC@?=)Eex0HuU+82I-cssdt1e`FoOdQ4Qr;VPtvK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$nc0tZ4xGTY z@Cy9(sNHEbyL*4dJMEOZ9QjpGr7*|8qo%T11{e5OL?M)3 zbxzBZ02X!RhY`oke(FxfA1jGGTuKns3mYMZw5IX*jUJWnhO%}l3e4fZ0c_foM>kaf E09pgf_W%F@ From 45d4667aa931a2d48f04cfe9654154cb1ac66c77 Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 00:21:02 -0500 Subject: [PATCH 10/45] prompt user when the job which update pac via gfwlist have been ran on background --- shadowsocks-csharp/Data/cn.txt | 1 + shadowsocks-csharp/View/MenuViewController.cs | 25 ++++++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index f8ceb92b..b97a05b9 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -42,3 +42,4 @@ Disabled=已禁用代理 Update PAC File via gfwlist...=基于 gfwlist 更新 PAC 文件... Update PAC file failed=更新 PAC 文件失败 Update PAC file succeed=更新 PAC 文件成功 +Job running...=任务正在执行中... diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 649ac44c..561ce092 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -33,6 +33,8 @@ namespace Shadowsocks.View private MenuItem PACModeItem; private ConfigForm configForm; + private bool isUpdatePACFromGFWListRunning = false; + public MenuViewController(ShadowsocksController controller) { this.controller = controller; @@ -181,6 +183,7 @@ namespace Shadowsocks.View void controller_UpdatePACFromGFWListError(object sender, System.IO.ErrorEventArgs e) { + isUpdatePACFromGFWListRunning = false; _notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist..."); _notifyIcon.BalloonTipText = I18N.GetString("Update PAC file failed"); _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; @@ -190,6 +193,7 @@ namespace Shadowsocks.View void controller_UpdatePACFromGFWListCompleted(object sender, EventArgs e) { + isUpdatePACFromGFWListRunning = false; _notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist..."); _notifyIcon.BalloonTipText = I18N.GetString("Update PAC file succeed"); _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; @@ -333,11 +337,22 @@ namespace Shadowsocks.View private void UpdatePACFromGFWListItem_Click(object sender, EventArgs e) { - _notifyIcon.BalloonTipTitle = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version; - _notifyIcon.BalloonTipText = I18N.GetString("Update PAC File via gfwlist..."); - _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; - _notifyIcon.ShowBalloonTip(5000); - controller.UpdatePACFromGFWList(); + if (isUpdatePACFromGFWListRunning) + { + _notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist..."); + _notifyIcon.BalloonTipText = I18N.GetString("Job running..."); + _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; + _notifyIcon.ShowBalloonTip(5000); + } + else + { + isUpdatePACFromGFWListRunning = true; + _notifyIcon.BalloonTipTitle = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version; + _notifyIcon.BalloonTipText = I18N.GetString("Update PAC File via gfwlist..."); + _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; + _notifyIcon.ShowBalloonTip(5000); + controller.UpdatePACFromGFWList(); + } } private void AServerItem_Click(object sender, EventArgs e) From 74c61ca76a3c032760c0b08190a6599b68ed4127 Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 00:24:34 -0500 Subject: [PATCH 11/45] remove unuse code and resources --- shadowsocks-csharp/Controller/GfwListUpdater.cs | 174 --------------------- shadowsocks-csharp/Data/builtin.txt.gz | Bin 104 -> 0 bytes shadowsocks-csharp/Data/tld.txt.gz | Bin 26403 -> 0 bytes .../Properties/Resources.Designer.cs | 20 --- shadowsocks-csharp/Properties/Resources.resx | 6 - shadowsocks-csharp/shadowsocks-csharp.csproj | 14 +- 6 files changed, 6 insertions(+), 208 deletions(-) delete mode 100644 shadowsocks-csharp/Data/builtin.txt.gz delete mode 100644 shadowsocks-csharp/Data/tld.txt.gz diff --git a/shadowsocks-csharp/Controller/GfwListUpdater.cs b/shadowsocks-csharp/Controller/GfwListUpdater.cs index c377efd2..2bebdcbf 100644 --- a/shadowsocks-csharp/Controller/GfwListUpdater.cs +++ b/shadowsocks-csharp/Controller/GfwListUpdater.cs @@ -90,180 +90,6 @@ namespace Shadowsocks.Controller return valid_lines.ToArray(); } - /* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ - public string[] GetDomains() - { - List lines = new List(GetValidLines()); - lines.AddRange(GetBuildIn()); - List domains = new List(lines.Count); - for (int i = 0; i < lines.Count; i++) - { - string line = lines[i]; - if (line.IndexOf(".*") >= 0) - continue; - if (line.StartsWith("http://")) - line = line.Substring(7); - else if (line.StartsWith("https://")) - line = line.Substring(8); - if (line.IndexOf("*") >= 0) - line = line.Replace("*", "/"); - if (line.StartsWith("||")) - while (line.StartsWith("||")) - line = line.Substring(2); - else if (line.StartsWith("|")) - line = line.TrimStart('|'); - else if (line.StartsWith(".")) - line = line.TrimStart('.'); - if (line.StartsWith("!")) - continue; - else if (line.StartsWith("[")) - continue; - else if (line.StartsWith("@")) - continue; /*ignore white list*/ - int pos = line.IndexOfAny(new char[] { '/' }); - if (pos >= 0) - line = line.Substring(0, pos); - if (line.Length > 0) - domains.Add(line); - } - return RemoveDuplicate(domains.ToArray()); - } - - /* refer https://github.com/clowwindy/gfwlist2pac/blob/master/gfwlist2pac/main.py */ - public string[] GetReducedDomains() - { - string[] domains = GetDomains(); - List new_domains = new List(domains.Length); - TldIndex tldIndex = GetTldIndex(); - - foreach (string domain in domains) - { - string last_root_domain = null; - int pos; - pos = domain.LastIndexOf('.'); - last_root_domain = domain.Substring(pos + 1); - if (!tldIndex.Contains(last_root_domain)) - continue; - while (pos > 0) - { - pos = domain.LastIndexOf('.', pos - 1); - last_root_domain = domain.Substring(pos + 1); - if (tldIndex.Contains(last_root_domain)) - continue; - else - break; - } - if (last_root_domain != null) - new_domains.Add(last_root_domain); - } - - return RemoveDuplicate(new_domains.ToArray()); - } - - private string[] RemoveDuplicate(string[] src) - { - List list = new List(src.Length); - Dictionary dic = new Dictionary(src.Length); - foreach (string s in src) - { - if (!dic.ContainsKey(s)) - { - dic.Add(s, s); - list.Add(s); - } - } - return list.ToArray(); - } - - private string[] GetTlds() - { - string[] tlds = null; - byte[] pacGZ = Resources.tld_txt; - byte[] buffer = new byte[1024]; - int n; - using (MemoryStream sb = new MemoryStream()) - { - using (GZipStream input = new GZipStream(new MemoryStream(pacGZ), - CompressionMode.Decompress, false)) - { - while ((n = input.Read(buffer, 0, buffer.Length)) > 0) - { - sb.Write(buffer, 0, n); - } - } - tlds = System.Text.Encoding.UTF8.GetString(sb.ToArray()) - .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); - } - return tlds; - } - - private TldIndex GetTldIndex() - { - string[] tlds = GetTlds(); - TldIndex index = new TldIndex(); - foreach (string tld in tlds) - { - index.Add(tld); - } - return index; - } - - private string[] GetBuildIn() - { - string[] buildin = null; - byte[] builtinGZ = Resources.builtin_txt; - byte[] buffer = new byte[1024]; - int n; - using (MemoryStream sb = new MemoryStream()) - { - using (GZipStream input = new GZipStream(new MemoryStream(builtinGZ), - CompressionMode.Decompress, false)) - { - while ((n = input.Read(buffer, 0, buffer.Length)) > 0) - { - sb.Write(buffer, 0, n); - } - } - buildin = System.Text.Encoding.UTF8.GetString(sb.ToArray()) - .Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); - } - return buildin; - } - - public class TldIndex - { - List patterns = new List(); - IDictionary dic = new Dictionary(); - - public void Add(string tld) - { - if (string.IsNullOrEmpty(tld)) - return; - if (tld.IndexOfAny(new char[] { '*', '?' }) >= 0) - { - patterns.Add("^" + Regex.Escape(tld).Replace("\\*", ".*").Replace("\\?", ".") + "$"); - } - else if (!dic.ContainsKey(tld)) - { - dic.Add(tld, tld); - } - } - - public bool Contains(string tld) - { - if (dic.ContainsKey(tld)) - return true; - foreach (string pattern in patterns) - { - if (Regex.IsMatch(tld, pattern)) - return true; - } - return false; - } - - } - - } } diff --git a/shadowsocks-csharp/Data/builtin.txt.gz b/shadowsocks-csharp/Data/builtin.txt.gz deleted file mode 100644 index c846e6448a7ec005ee03576b0d40e751c51f85f7..0000000000000000000000000000000000000000 GIT binary patch literal 0 KcmV+b0RR6000031 literal 104 zcmV-u0GIzCiwFp_d973c17dY)Y;2Z^2uw|s`?Jy! zbT$SQ)V{IPa`w~Jro}t6_%OX3%jRgWz`X#ZLdAL)>tU^Ssfl5|*0qyS8!hm`>4o-I;NQlsZ3enz(Fz`l}zzwVcjw zNi3?h(QXTYoYrA6c_k|E!|s-^*!XF;u6@1J{x9g-Smc2iOZ%AynHs3T>mGi7gEId!TF zp!Uk5y>irES!%EBZ7Vl7vCZvd-cIHr!b1%8kbQiJg&tzIhnVf5mU*1!nJ8~H+8K)3 z4{`zom47f8ZVRA(0n`P6`UOy1z&c^tjFl(EMlu}y=fbv>&DYD7}v|yk1*saOYLKddT|*W4NCCJ-koG}N0NgBBtl%6PbU<)raFIcD@l{}9SOP)C#0!sL z$~ZOzwdZE_a#r~hYbdi7Va`M zygasi#I+TOtejIV!0UQV+%rW$E=33@NCP)Xk!R0glhAUVMdqYQ+4C>eiPO0RNbZOUF>z2 zZtjSuL@V)lm3X{Ld|V|yt`f&bRS;gP7tpFEIx;^AZJ7>C6Vrw1N)&kl=xm9;a@*7s zy)$*JsVQdR)zTNV4}bBmKm6TqiTm+C|Nh7Ce#zXw|K`VU{)sr#5v?xV=PS{cdDk#aOdm|&h<1i) z#ndwOOnIzsB6?x|!fh|yYGD1uQ=VA!%Ht+pOX9JTXt-wLIt$O_O(@Ud&ZQ65bUiOJ zaLt?8ggh076{lE>Qv|d=vdCr%61i&ejqaheBi9Hej@1M!vW-d0pvKX zd`YqL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|)&NO_D5>yt^U<7MPV>rRKqP~7 zs$GYrwS2)>!wdGf^8lq7NiMob8-A_%{pLC5wKIQFw2HG)nQK(!N2h2NZmZ~%@_$lk zaVktVDq5Aqc`9_L!W=aHy3nI4w$T@QQen<2-dXtx3J xc?OPez_g2ePj - /// Looks up a localized resource of type System.Byte[]. - ///

- internal static byte[] builtin_txt { - get { - object obj = ResourceManager.GetObject("builtin_txt", resourceCulture); - return ((byte[])(obj)); - } - } - - /// /// Looks up a localized string similar to Shadowsocks=Shadowsocks ///Enable=启用代理 ///Mode=代理模式 @@ -205,15 +195,5 @@ namespace Shadowsocks.Properties { return ((System.Drawing.Bitmap)(obj)); } } - - /// - /// Looks up a localized resource of type System.Byte[]. - /// - internal static byte[] tld_txt { - get { - object obj = ResourceManager.GetObject("tld_txt", resourceCulture); - return ((byte[])(obj)); - } - } } } diff --git a/shadowsocks-csharp/Properties/Resources.resx b/shadowsocks-csharp/Properties/Resources.resx index 24d1b168..ee5f98ea 100755 --- a/shadowsocks-csharp/Properties/Resources.resx +++ b/shadowsocks-csharp/Properties/Resources.resx @@ -121,9 +121,6 @@ ..\Data\abp.js.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\Data\builtin.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - ..\data\cn.txt;System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 @@ -151,7 +148,4 @@ ..\Resources\ssw128.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a - - ..\Data\tld.txt.gz;System.Byte[], mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - \ No newline at end of file diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 314ea6a3..1848edd9 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -102,6 +102,11 @@ + + True + True + Resources.resx + Form @@ -128,14 +133,9 @@ ResXFileCodeGenerator - Resources.Designer.cs Designer + Resources.Designer.cs - - True - Resources.resx - True - QRCodeForm.cs @@ -144,13 +144,11 @@ Designer - - From 77aa5e82801ec1188852a5c86f6eebe5b4f781b9 Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 00:45:47 -0500 Subject: [PATCH 12/45] change prompt message --- shadowsocks-csharp/Data/cn.txt | 2 +- shadowsocks-csharp/View/MenuViewController.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index b97a05b9..5dd129c0 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -42,4 +42,4 @@ Disabled=已禁用代理 Update PAC File via gfwlist...=基于 gfwlist 更新 PAC 文件... Update PAC file failed=更新 PAC 文件失败 Update PAC file succeed=更新 PAC 文件成功 -Job running...=任务正在执行中... +Job already running...=任务已经运行... diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 561ce092..b7ce3f2d 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -340,7 +340,7 @@ namespace Shadowsocks.View if (isUpdatePACFromGFWListRunning) { _notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist..."); - _notifyIcon.BalloonTipText = I18N.GetString("Job running..."); + _notifyIcon.BalloonTipText = I18N.GetString("Job already running..."); _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; _notifyIcon.ShowBalloonTip(5000); } From 4860d5b32a530c9e34feda3a7d995815e63212b6 Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 01:29:22 -0500 Subject: [PATCH 13/45] fire error event when the pac server is not run --- shadowsocks-csharp/Controller/ShadowsocksController.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 427fe9bf..9b2b9ba3 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -166,6 +166,10 @@ namespace Shadowsocks.Controller { pacServer.UpdatePACFromGFWList(); } + else if (UpdatePACFromGFWListError != null) + { + UpdatePACFromGFWListError(this, new ErrorEventArgs(new Exception("The PACServer is not run."))); + } } protected void Reload() From a984014267636d267d38a3cb416bf7f8103de8a9 Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 01:54:21 -0500 Subject: [PATCH 14/45] remove unuse import packages --- shadowsocks-csharp/Controller/GfwListUpdater.cs | 6 ------ shadowsocks-csharp/Controller/PACServer.cs | 2 -- 2 files changed, 8 deletions(-) diff --git a/shadowsocks-csharp/Controller/GfwListUpdater.cs b/shadowsocks-csharp/Controller/GfwListUpdater.cs index 2bebdcbf..2b3db383 100644 --- a/shadowsocks-csharp/Controller/GfwListUpdater.cs +++ b/shadowsocks-csharp/Controller/GfwListUpdater.cs @@ -1,14 +1,8 @@ using System; using System.Collections.Generic; using System.Text; -using System.Threading; using System.Net; using System.IO; -using System.IO.Compression; -using System.Security.Cryptography; -using System.Text.RegularExpressions; -using Shadowsocks.Model; -using Shadowsocks.Properties; namespace Shadowsocks.Controller { diff --git a/shadowsocks-csharp/Controller/PACServer.cs b/shadowsocks-csharp/Controller/PACServer.cs index 52b838ba..867c81ac 100755 --- a/shadowsocks-csharp/Controller/PACServer.cs +++ b/shadowsocks-csharp/Controller/PACServer.cs @@ -1,7 +1,6 @@ using Shadowsocks.Model; using Shadowsocks.Properties; using System; -using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -9,7 +8,6 @@ using System.IO.Compression; using System.Net; using System.Net.Sockets; using System.Text; -using System.Text.RegularExpressions; namespace Shadowsocks.Controller { From 075069ef167c3b4d9308d92ea47dc6543fabeec2 Mon Sep 17 00:00:00 2001 From: Gang Zhuo Date: Thu, 8 Jan 2015 05:28:43 -0500 Subject: [PATCH 15/45] not update all pac.txt, but only update the rules --- shadowsocks-csharp/Controller/PACServer.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/Controller/PACServer.cs b/shadowsocks-csharp/Controller/PACServer.cs index 867c81ac..fbd1989b 100755 --- a/shadowsocks-csharp/Controller/PACServer.cs +++ b/shadowsocks-csharp/Controller/PACServer.cs @@ -8,6 +8,7 @@ using System.IO.Compression; using System.Net; using System.Net.Sockets; using System.Text; +using System.Text.RegularExpressions; namespace Shadowsocks.Controller { @@ -264,7 +265,7 @@ Connection: Close SerializeRules(lines, rules); string abpContent = GetAbpContent(); abpContent = abpContent.Replace("__RULES__", rules.ToString()); - File.WriteAllText(PAC_FILE, abpContent); + File.WriteAllText(PAC_FILE, abpContent, Encoding.UTF8); if (UpdatePACFromGFWListCompleted != null) { UpdatePACFromGFWListCompleted(this, new EventArgs()); @@ -281,6 +282,18 @@ Connection: Close private string GetAbpContent() { + string content; + if (File.Exists(PAC_FILE)) + { + content = File.ReadAllText(PAC_FILE, Encoding.UTF8); + Regex regex = new Regex("var\\s+rules\\s*=\\s*(\\[(\\s*\"[^\"]*\"\\s*,)*(\\s*\"[^\"]*\")\\s*\\])", RegexOptions.Singleline); + Match m = regex.Match(content); + if (m.Success) + { + content = regex.Replace(content, "var rules = __RULES__"); + return content; + } + } byte[] abpGZ = Resources.abp_js; byte[] buffer = new byte[1024]; // builtin pac gzip size: maximum 100K int n; @@ -294,8 +307,9 @@ Connection: Close sb.Write(buffer, 0, n); } } - return System.Text.Encoding.UTF8.GetString(sb.ToArray()); + content = System.Text.Encoding.UTF8.GetString(sb.ToArray()); } + return content; } private static void SerializeRules(string[] rules, StringBuilder builder) From 082494d587cec92bc697bd45cf2a59e98d6e9b58 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 8 Jan 2015 20:14:43 +0800 Subject: [PATCH 16/45] combine duplicated code --- shadowsocks-csharp/Data/cn.txt | 7 ++-- shadowsocks-csharp/View/MenuViewController.cs | 48 +++++++++------------------ 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index 5dd129c0..f67af0d2 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -39,7 +39,6 @@ Shadowsocks is here=Shadowsocks 在这里 You can turn on/off Shadowsocks in the context menu=可以在右键菜单中开关 Shadowsocks Enabled=已启用代理 Disabled=已禁用代理 -Update PAC File via gfwlist...=基于 gfwlist 更新 PAC 文件... -Update PAC file failed=更新 PAC 文件失败 -Update PAC file succeed=更新 PAC 文件成功 -Job already running...=任务已经运行... +Update PAC File via GFWList...=从 GFWList 更新 PAC 文件... +Failed to update PAC file =更新 PAC 文件失败 +PAC updated=更新 PAC 成功 diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index b7ce3f2d..1ab517f9 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; +using System.IO; using System.Text; using System.Windows.Forms; @@ -33,8 +34,6 @@ namespace Shadowsocks.View private MenuItem PACModeItem; private ConfigForm configForm; - private bool isUpdatePACFromGFWListRunning = false; - public MenuViewController(ShadowsocksController controller) { this.controller = controller; @@ -181,38 +180,36 @@ namespace Shadowsocks.View System.Diagnostics.Process.Start("explorer.exe", argument); } - void controller_UpdatePACFromGFWListError(object sender, System.IO.ErrorEventArgs e) + void ShowBalloonTip(string title, string content, ToolTipIcon icon, int timeout) + { + _notifyIcon.BalloonTipTitle = title; + _notifyIcon.BalloonTipText = content; + _notifyIcon.BalloonTipIcon = icon; + _notifyIcon.ShowBalloonTip(timeout); + } + + void controller_UpdatePACFromGFWListError(object sender, ErrorEventArgs e) { - isUpdatePACFromGFWListRunning = false; - _notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist..."); - _notifyIcon.BalloonTipText = I18N.GetString("Update PAC file failed"); - _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; - _notifyIcon.ShowBalloonTip(5000); + ShowBalloonTip(I18N.GetString("Failed to update PAC file"), e.GetException().Message, ToolTipIcon.Error, 5000); Logging.LogUsefulException(e.GetException()); } void controller_UpdatePACFromGFWListCompleted(object sender, EventArgs e) { - isUpdatePACFromGFWListRunning = false; - _notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist..."); - _notifyIcon.BalloonTipText = I18N.GetString("Update PAC file succeed"); - _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; - _notifyIcon.ShowBalloonTip(5000); + ShowBalloonTip(I18N.GetString("Shadowsocks"), I18N.GetString("PAC updated"), ToolTipIcon.Info, 1000); } void updateChecker_NewVersionFound(object sender, EventArgs e) { - _notifyIcon.BalloonTipTitle = String.Format(I18N.GetString("Shadowsocks {0} Update Found"), updateChecker.LatestVersionNumber); - _notifyIcon.BalloonTipText = I18N.GetString("Click here to download"); - _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; + ShowBalloonTip(String.Format(I18N.GetString("Shadowsocks {0} Update Found"), updateChecker.LatestVersionNumber), I18N.GetString("Click here to download"), ToolTipIcon.Info, 5000); _notifyIcon.BalloonTipClicked += notifyIcon1_BalloonTipClicked; - _notifyIcon.ShowBalloonTip(5000); _isFirstRun = false; } void notifyIcon1_BalloonTipClicked(object sender, EventArgs e) { System.Diagnostics.Process.Start(updateChecker.LatestVersionURL); + _notifyIcon.BalloonTipClicked -= notifyIcon1_BalloonTipClicked; } @@ -337,22 +334,7 @@ namespace Shadowsocks.View private void UpdatePACFromGFWListItem_Click(object sender, EventArgs e) { - if (isUpdatePACFromGFWListRunning) - { - _notifyIcon.BalloonTipTitle = I18N.GetString("Update PAC File via gfwlist..."); - _notifyIcon.BalloonTipText = I18N.GetString("Job already running..."); - _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; - _notifyIcon.ShowBalloonTip(5000); - } - else - { - isUpdatePACFromGFWListRunning = true; - _notifyIcon.BalloonTipTitle = I18N.GetString("Shadowsocks") + " " + UpdateChecker.Version; - _notifyIcon.BalloonTipText = I18N.GetString("Update PAC File via gfwlist..."); - _notifyIcon.BalloonTipIcon = ToolTipIcon.Info; - _notifyIcon.ShowBalloonTip(5000); - controller.UpdatePACFromGFWList(); - } + controller.UpdatePACFromGFWList(); } private void AServerItem_Click(object sender, EventArgs e) From 6192e099704ce47296422c9cbd43ef674cec3d1e Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 8 Jan 2015 21:16:45 +0800 Subject: [PATCH 17/45] revert stop call --- shadowsocks-csharp/Controller/ShadowsocksController.cs | 5 ----- shadowsocks-csharp/Program.cs | 2 -- 2 files changed, 7 deletions(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 9b2b9ba3..2610bbab 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -132,11 +132,6 @@ namespace Shadowsocks.Controller { polipoRunner.Stop(); } - if (pacServer != null) - { - pacServer.Stop(); - pacServer = null; - } if (_config.enabled) { SystemProxy.Disable(); diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index c3c0537a..716e0df7 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -45,8 +45,6 @@ namespace Shadowsocks controller.Start(); Application.Run(); - - controller.Stop(); } } } From a0a5cafe3d1654ba75da7e8ef8f262cdada751f7 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 8 Jan 2015 21:57:51 +0800 Subject: [PATCH 18/45] lint code --- shadowsocks-csharp/3rd/SimpleJson.cs | 6 +- shadowsocks-csharp/Controller/GfwListUpdater.cs | 94 ++++++-------- shadowsocks-csharp/Controller/PACServer.cs | 136 +-------------------- .../Controller/ShadowsocksController.cs | 25 ++-- shadowsocks-csharp/Data/abp.js.gz | Bin 4597 -> 4461 bytes shadowsocks-csharp/Data/cn.txt | 2 +- shadowsocks-csharp/Program.cs | 2 +- shadowsocks-csharp/Util/Util.cs | 22 +++- shadowsocks-csharp/View/MenuViewController.cs | 4 +- shadowsocks-csharp/shadowsocks-csharp.csproj | 2 +- 10 files changed, 84 insertions(+), 209 deletions(-) mode change 100644 => 100755 shadowsocks-csharp/Data/abp.js.gz diff --git a/shadowsocks-csharp/3rd/SimpleJson.cs b/shadowsocks-csharp/3rd/SimpleJson.cs index 2850137d..6581e84b 100644 --- a/shadowsocks-csharp/3rd/SimpleJson.cs +++ b/shadowsocks-csharp/3rd/SimpleJson.cs @@ -1035,13 +1035,13 @@ namespace SimpleJson protected static bool SerializeArray(IJsonSerializerStrategy jsonSerializerStrategy, IEnumerable anArray, StringBuilder builder) { - builder.Append("["); + builder.Append("[\r\n "); bool first = true; foreach (object value in anArray) { if (!first) - builder.Append(","); + builder.Append(",\r\n "); if (!SerializeValue(jsonSerializerStrategy, value, builder)) return false; @@ -1049,7 +1049,7 @@ namespace SimpleJson first = false; } - builder.Append("]"); + builder.Append("\r\n]"); return true; } diff --git a/shadowsocks-csharp/Controller/GfwListUpdater.cs b/shadowsocks-csharp/Controller/GfwListUpdater.cs index 2b3db383..fded3a59 100644 --- a/shadowsocks-csharp/Controller/GfwListUpdater.cs +++ b/shadowsocks-csharp/Controller/GfwListUpdater.cs @@ -3,88 +3,70 @@ using System.Collections.Generic; using System.Text; using System.Net; using System.IO; +using Shadowsocks.Properties; +using System.IO.Compression; +using System.Text.RegularExpressions; +using SimpleJson; +using Shadowsocks.Util; namespace Shadowsocks.Controller { - public class GfwListUpdater + public class GFWListUpdater { private const string GFWLIST_URL = "https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt"; - public IWebProxy proxy = null; + private static string PAC_FILE = PACServer.PAC_FILE; - public class GfwListDownloadCompletedArgs : EventArgs - { - public string Content; - } - - public event EventHandler DownloadCompleted; + public event EventHandler UpdateCompleted; public event ErrorEventHandler Error; - public void Download() - { - WebClient http = new WebClient(); - http.Proxy = proxy; - http.DownloadStringCompleted += http_DownloadStringCompleted; - http.DownloadStringAsync(new Uri(GFWLIST_URL)); - } - - protected void ReportError(Exception e) - { - if (Error != null) - { - Error(this, new ErrorEventArgs(e)); - } - } - private void http_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { try { - string response = e.Result; - if (DownloadCompleted != null) + string[] lines = ParseResult(e.Result); + + JsonArray rules = new JsonArray(); + rules.AddRange(lines); + string abpContent = Utils.UnGzip(Resources.abp_js); + abpContent = abpContent.Replace("__RULES__", rules.ToString()); + File.WriteAllText(PAC_FILE, abpContent, Encoding.UTF8); + if (UpdateCompleted != null) { - DownloadCompleted(this, new GfwListDownloadCompletedArgs - { - Content = response - }); + UpdateCompleted(this, new EventArgs()); } } catch (Exception ex) { - ReportError(ex); + if (Error != null) + { + Error(this, new ErrorEventArgs(ex)); + } } } - public class Parser - { - private string _Content; - - public string Content - { - get { return _Content; } - } - public Parser(string response) - { - byte[] bytes = Convert.FromBase64String(response); - this._Content = Encoding.ASCII.GetString(bytes); - } + public void UpdatePACFromGFWList() + { + WebClient http = new WebClient(); + http.DownloadStringCompleted += http_DownloadStringCompleted; + http.DownloadStringAsync(new Uri(GFWLIST_URL)); + } - public string[] GetValidLines() + public string[] ParseResult(string response) + { + byte[] bytes = Convert.FromBase64String(response); + string content = Encoding.ASCII.GetString(bytes); + string[] lines = content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); + List valid_lines = new List(lines.Length); + foreach (string line in lines) { - string[] lines = Content.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); - List valid_lines = new List(lines.Length); - foreach (string line in lines) - { - if (line.StartsWith("!") || line.StartsWith("[")) - continue; - valid_lines.Add(line); - } - return valid_lines.ToArray(); + if (line.StartsWith("!") || line.StartsWith("[")) + continue; + valid_lines.Add(line); } - + return valid_lines.ToArray(); } - } } diff --git a/shadowsocks-csharp/Controller/PACServer.cs b/shadowsocks-csharp/Controller/PACServer.cs index fbd1989b..b2456e18 100755 --- a/shadowsocks-csharp/Controller/PACServer.cs +++ b/shadowsocks-csharp/Controller/PACServer.cs @@ -1,5 +1,6 @@ using Shadowsocks.Model; using Shadowsocks.Properties; +using Shadowsocks.Util; using System; using System.Collections.Generic; using System.Diagnostics; @@ -8,14 +9,13 @@ using System.IO.Compression; using System.Net; using System.Net.Sockets; using System.Text; -using System.Text.RegularExpressions; namespace Shadowsocks.Controller { class PACServer { private static int PORT = 8093; - private static string PAC_FILE = "pac.txt"; + public static string PAC_FILE = "pac.txt"; private static Configuration config; Socket _listener; @@ -23,10 +23,6 @@ namespace Shadowsocks.Controller public event EventHandler PACFileChanged; - public event EventHandler UpdatePACFromGFWListCompleted; - - public event ErrorEventHandler UpdatePACFromGFWListError; - public void Start(Configuration configuration) { try @@ -135,19 +131,7 @@ namespace Shadowsocks.Controller } else { - byte[] pacGZ = Resources.proxy_pac_txt; - byte[] buffer = new byte[1024]; // builtin pac gzip size: maximum 100K - MemoryStream sb = new MemoryStream(); - int n; - using (GZipStream input = new GZipStream(new MemoryStream(pacGZ), - CompressionMode.Decompress, false)) - { - while ((n = input.Read(buffer, 0, buffer.Length)) > 0) - { - sb.Write(buffer, 0, n); - } - return System.Text.Encoding.UTF8.GetString(sb.ToArray()); - } + return Utils.UnGzip(Resources.proxy_pac_txt); } } @@ -180,7 +164,7 @@ Connection: Close ", System.Text.Encoding.UTF8.GetBytes(pac).Length) + pac; byte[] response = System.Text.Encoding.UTF8.GetBytes(text); conn.BeginSend(response, 0, response.Length, 0, new AsyncCallback(SendCallback), conn); - Util.Util.ReleaseMemory(); + Util.Utils.ReleaseMemory(); } else { @@ -247,117 +231,5 @@ Connection: Close //} return proxy; } - - public void UpdatePACFromGFWList() - { - GfwListUpdater gfwlist = new GfwListUpdater(); - gfwlist.DownloadCompleted += gfwlist_DownloadCompleted; - gfwlist.Error += gfwlist_Error; - gfwlist.proxy = new WebProxy(IPAddress.Loopback.ToString(), 8123); /* use polipo proxy*/ - gfwlist.Download(); - } - - private void gfwlist_DownloadCompleted(object sender, GfwListUpdater.GfwListDownloadCompletedArgs e) - { - GfwListUpdater.Parser parser = new GfwListUpdater.Parser(e.Content); - string[] lines = parser.GetValidLines(); - StringBuilder rules = new StringBuilder(lines.Length * 16); - SerializeRules(lines, rules); - string abpContent = GetAbpContent(); - abpContent = abpContent.Replace("__RULES__", rules.ToString()); - File.WriteAllText(PAC_FILE, abpContent, Encoding.UTF8); - if (UpdatePACFromGFWListCompleted != null) - { - UpdatePACFromGFWListCompleted(this, new EventArgs()); - } - } - - private void gfwlist_Error(object sender, ErrorEventArgs e) - { - if (UpdatePACFromGFWListError != null) - { - UpdatePACFromGFWListError(this, e); - } - } - - private string GetAbpContent() - { - string content; - if (File.Exists(PAC_FILE)) - { - content = File.ReadAllText(PAC_FILE, Encoding.UTF8); - Regex regex = new Regex("var\\s+rules\\s*=\\s*(\\[(\\s*\"[^\"]*\"\\s*,)*(\\s*\"[^\"]*\")\\s*\\])", RegexOptions.Singleline); - Match m = regex.Match(content); - if (m.Success) - { - content = regex.Replace(content, "var rules = __RULES__"); - return content; - } - } - byte[] abpGZ = Resources.abp_js; - byte[] buffer = new byte[1024]; // builtin pac gzip size: maximum 100K - int n; - using (MemoryStream sb = new MemoryStream()) - { - using (GZipStream input = new GZipStream(new MemoryStream(abpGZ), - CompressionMode.Decompress, false)) - { - while ((n = input.Read(buffer, 0, buffer.Length)) > 0) - { - sb.Write(buffer, 0, n); - } - } - content = System.Text.Encoding.UTF8.GetString(sb.ToArray()); - } - return content; - } - - private static void SerializeRules(string[] rules, StringBuilder builder) - { - builder.Append("[\n"); - - bool first = true; - foreach (string rule in rules) - { - if (!first) - builder.Append(",\n"); - - SerializeString(rule, builder); - - first = false; - } - - builder.Append("\n]"); - } - - private static void SerializeString(string aString, StringBuilder builder) - { - builder.Append("\t\""); - - char[] charArray = aString.ToCharArray(); - for (int i = 0; i < charArray.Length; i++) - { - char c = charArray[i]; - if (c == '"') - builder.Append("\\\""); - else if (c == '\\') - builder.Append("\\\\"); - else if (c == '\b') - builder.Append("\\b"); - else if (c == '\f') - builder.Append("\\f"); - else if (c == '\n') - builder.Append("\\n"); - else if (c == '\r') - builder.Append("\\r"); - else if (c == '\t') - builder.Append("\\t"); - else - builder.Append(c); - } - - builder.Append("\""); - } - } } diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 2610bbab..1e193158 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -21,6 +21,7 @@ namespace Shadowsocks.Controller private PACServer pacServer; private Configuration _config; private PolipoRunner polipoRunner; + private GFWListUpdater gfwListUpdater; private bool stopped = false; private bool _systemProxyIsDirty = false; @@ -157,13 +158,9 @@ namespace Shadowsocks.Controller public void UpdatePACFromGFWList() { - if (pacServer != null) + if (gfwListUpdater != null) { - pacServer.UpdatePACFromGFWList(); - } - else if (UpdatePACFromGFWListError != null) - { - UpdatePACFromGFWListError(this, new ErrorEventArgs(new Exception("The PACServer is not run."))); + gfwListUpdater.UpdatePACFromGFWList(); } } @@ -180,8 +177,12 @@ namespace Shadowsocks.Controller { pacServer = new PACServer(); pacServer.PACFileChanged += pacServer_PACFileChanged; - pacServer.UpdatePACFromGFWListCompleted += pacServer_UpdatePACFromGFWListCompleted; - pacServer.UpdatePACFromGFWListError += pacServer_UpdatePACFromGFWListError; + } + if (gfwListUpdater == null) + { + gfwListUpdater = new GFWListUpdater(); + gfwListUpdater.UpdateCompleted += pacServer_PACUpdateCompleted; + gfwListUpdater.Error += pacServer_PACUpdateError; } pacServer.Stop(); @@ -226,7 +227,7 @@ namespace Shadowsocks.Controller } UpdateSystemProxy(); - Util.Util.ReleaseMemory(); + Util.Utils.ReleaseMemory(); } @@ -260,13 +261,13 @@ namespace Shadowsocks.Controller UpdateSystemProxy(); } - private void pacServer_UpdatePACFromGFWListCompleted(object sender, EventArgs e) + private void pacServer_PACUpdateCompleted(object sender, EventArgs e) { if (UpdatePACFromGFWListCompleted != null) UpdatePACFromGFWListCompleted(this, e); } - private void pacServer_UpdatePACFromGFWListError(object sender, ErrorEventArgs e) + private void pacServer_PACUpdateError(object sender, ErrorEventArgs e) { if (UpdatePACFromGFWListError != null) UpdatePACFromGFWListError(this, e); @@ -283,7 +284,7 @@ namespace Shadowsocks.Controller { while (true) { - Util.Util.ReleaseMemory(); + Util.Utils.ReleaseMemory(); Thread.Sleep(30 * 1000); } } diff --git a/shadowsocks-csharp/Data/abp.js.gz b/shadowsocks-csharp/Data/abp.js.gz old mode 100644 new mode 100755 index d265cfd68a7aaa331fbd0be03ca58ece548b2099..e049c0a42c42adc3f42601e8535f3c48f93daf99 GIT binary patch literal 4461 zcmV-z5t8m7iwFo$h^|xu0AXTqE^2cC?Hv76A~*E+&h&qX^xA@QfS%P>YAq^v(&}ju zr@aA=Ss}>w)?H?IIgVEQxA!I4@Dj2Rp!RcmGsj2rzVg2E@-|p3l2_EHp%c>{xt)-^ z{@8P)cxUKziR+VLNV{%C$$ikHAAbbEgE$^W2gTx@8xKaeg>Gjm9+ zY47VIz9<$4;B`>x1$&&iizX* zib2TK;`S#%hmDQ=9t}x6pd_Z@eFOsYFRxzTBr5jE)#%o9yX4&MQXjPXo`#Vd_~Zp~ zB1UA$rlSG31jl{Jq`4N-z_$QcI5A)p=17l1_P~0a#2^?__~67$#Ifsn&BZh0LOy>X6bt>NV)ez&jrdLOz8OW1Xjo>TvY2P zXMj>UuASE!ZwTn+Wv%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*% zd?D7Q6ctMoLJAv86~_Yj#n-T|Tz@*JL_}+cWZ{Lffm&M&>AM=kDGeY9#EDHU5b`Pq zT)KD#=J|~*&gEN>+6A8J{y(RW`4&5W>O_g#m4Ak$U-s8Onf}M9{&xz245`V{NIf5X z{aV}e)GLcg9yLYLsQgC-np5`3TrE<;XMUTNof1h#jMh;JDc_c)PgJwTFkJXjt~5_H zlBP@lj80u{Qkj!(Oe`kt;U zO79dG$>gg7_Rxf<=OT!*e{7}J%EA5oN9Qm)FN@I?H zM^7O~sv_-M8f5|tp3yM&w0|7u4KDHj5rt5C-99T%0@&1%A4VKE`&V}|{#Z%m=~9BA fUI;OyJ&nI_^r(C{ls%`Sz#RS?MbQItIaL4vaBTjm diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index f67af0d2..9f8c6da1 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -39,6 +39,6 @@ Shadowsocks is here=Shadowsocks 在这里 You can turn on/off Shadowsocks in the context menu=可以在右键菜单中开关 Shadowsocks Enabled=已启用代理 Disabled=已禁用代理 -Update PAC File via GFWList...=从 GFWList 更新 PAC 文件... +Update PAC from GFWList=从 GFWList 更新 PAC Failed to update PAC file =更新 PAC 文件失败 PAC updated=更新 PAC 成功 diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index 716e0df7..8ca485d7 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -18,7 +18,7 @@ namespace Shadowsocks [STAThread] static void Main() { - Util.Util.ReleaseMemory(); + Util.Utils.ReleaseMemory(); using (Mutex mutex = new Mutex(false, "Global\\" + "71981632-A427-497F-AB91-241CD227EC1F")) { Application.EnableVisualStyles(); diff --git a/shadowsocks-csharp/Util/Util.cs b/shadowsocks-csharp/Util/Util.cs index afb5539a..15463a3a 100755 --- a/shadowsocks-csharp/Util/Util.cs +++ b/shadowsocks-csharp/Util/Util.cs @@ -1,12 +1,14 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; +using System.IO.Compression; using System.Runtime.InteropServices; using System.Text; namespace Shadowsocks.Util { - public class Util + public class Utils { public static void ReleaseMemory() { @@ -22,6 +24,24 @@ namespace Shadowsocks.Util (UIntPtr)0xFFFFFFFF, (UIntPtr)0xFFFFFFFF); } + public static string UnGzip(byte[] buf) + { + byte[] buffer = new byte[1024]; + int n; + using (MemoryStream sb = new MemoryStream()) + { + using (GZipStream input = new GZipStream(new MemoryStream(buf), + CompressionMode.Decompress, false)) + { + while ((n = input.Read(buffer, 0, buffer.Length)) > 0) + { + sb.Write(buffer, 0, n); + } + } + return System.Text.Encoding.UTF8.GetString(sb.ToArray()); + } + } + [DllImport("kernel32.dll")] [return: MarshalAs(UnmanagedType.Bool)] private static extern bool SetProcessWorkingSetSize(IntPtr process, diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 1ab517f9..76da6036 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -141,7 +141,7 @@ namespace Shadowsocks.View this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)), this.ShareOverLANItem = CreateMenuItem("Share over LAN", new EventHandler(this.ShareOverLANItem_Click)), CreateMenuItem("Edit PAC File...", new EventHandler(this.EditPACFileItem_Click)), - CreateMenuItem("Update PAC File via gfwlist...", new EventHandler(this.UpdatePACFromGFWListItem_Click)), + CreateMenuItem("Update PAC from GFWList", new EventHandler(this.UpdatePACFromGFWListItem_Click)), new MenuItem("-"), CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)), CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)), @@ -265,7 +265,7 @@ namespace Shadowsocks.View void configForm_FormClosed(object sender, FormClosedEventArgs e) { configForm = null; - Util.Util.ReleaseMemory(); + Util.Utils.ReleaseMemory(); ShowFirstTimeBalloon(); } diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 1848edd9..d14d7287 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -86,7 +86,7 @@ - + From b9b9202cdef616ed964884ee3afff78d4c02046a Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 8 Jan 2015 22:06:12 +0800 Subject: [PATCH 19/45] lint code --- shadowsocks-csharp/Controller/GfwListUpdater.cs | 16 ++++++---------- shadowsocks-csharp/Controller/UpdateChecker.cs | 1 + shadowsocks-csharp/View/MenuViewController.cs | 3 +-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/shadowsocks-csharp/Controller/GfwListUpdater.cs b/shadowsocks-csharp/Controller/GfwListUpdater.cs index fded3a59..7abe9445 100644 --- a/shadowsocks-csharp/Controller/GfwListUpdater.cs +++ b/shadowsocks-csharp/Controller/GfwListUpdater.cs @@ -4,8 +4,6 @@ using System.Text; using System.Net; using System.IO; using Shadowsocks.Properties; -using System.IO.Compression; -using System.Text.RegularExpressions; using SimpleJson; using Shadowsocks.Util; @@ -25,12 +23,10 @@ namespace Shadowsocks.Controller { try { - string[] lines = ParseResult(e.Result); + List lines = ParseResult(e.Result); - JsonArray rules = new JsonArray(); - rules.AddRange(lines); string abpContent = Utils.UnGzip(Resources.abp_js); - abpContent = abpContent.Replace("__RULES__", rules.ToString()); + abpContent = abpContent.Replace("__RULES__", SimpleJson.SimpleJson.SerializeObject(lines)); File.WriteAllText(PAC_FILE, abpContent, Encoding.UTF8); if (UpdateCompleted != null) { @@ -46,15 +42,15 @@ namespace Shadowsocks.Controller } } - public void UpdatePACFromGFWList() { WebClient http = new WebClient(); + http.Proxy = new WebProxy(IPAddress.Loopback.ToString(), 8123); http.DownloadStringCompleted += http_DownloadStringCompleted; http.DownloadStringAsync(new Uri(GFWLIST_URL)); } - public string[] ParseResult(string response) + public List ParseResult(string response) { byte[] bytes = Convert.FromBase64String(response); string content = Encoding.ASCII.GetString(bytes); @@ -66,7 +62,7 @@ namespace Shadowsocks.Controller continue; valid_lines.Add(line); } - return valid_lines.ToArray(); + return valid_lines; } } -} +} \ No newline at end of file diff --git a/shadowsocks-csharp/Controller/UpdateChecker.cs b/shadowsocks-csharp/Controller/UpdateChecker.cs index d6653468..7996a687 100755 --- a/shadowsocks-csharp/Controller/UpdateChecker.cs +++ b/shadowsocks-csharp/Controller/UpdateChecker.cs @@ -23,6 +23,7 @@ namespace Shadowsocks.Controller { // TODO test failures WebClient http = new WebClient(); + http.Proxy = new WebProxy(IPAddress.Loopback.ToString(), 8123); http.DownloadStringCompleted += http_DownloadStringCompleted; http.DownloadStringAsync(new Uri(UpdateURL)); } diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 76da6036..3d875f3e 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; -using System.IO; using System.Text; using System.Windows.Forms; @@ -188,7 +187,7 @@ namespace Shadowsocks.View _notifyIcon.ShowBalloonTip(timeout); } - void controller_UpdatePACFromGFWListError(object sender, ErrorEventArgs e) + void controller_UpdatePACFromGFWListError(object sender, System.IO.ErrorEventArgs e) { ShowBalloonTip(I18N.GetString("Failed to update PAC file"), e.GetException().Message, ToolTipIcon.Error, 5000); Logging.LogUsefulException(e.GetException()); From 797bd863aa4033f9d093a404991bd860a9f4abae Mon Sep 17 00:00:00 2001 From: clowwindy Date: Fri, 9 Jan 2015 07:59:45 +0800 Subject: [PATCH 20/45] add develop section --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3304cffc..05c1dfd0 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,10 @@ about the change automatically 6. Please disable other proxy addons in your browser, or set them to use system proxy +### Develop + +Visual Studio Express 2012 is recommended. + #### License GPLv3 From 70d7e813a43a0f5d7f5fcff6341fb2792b3a59bc Mon Sep 17 00:00:00 2001 From: clowwindy Date: Sun, 11 Jan 2015 22:22:55 +0800 Subject: [PATCH 21/45] try fix #105 --- shadowsocks-csharp/Controller/SystemProxy.cs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/shadowsocks-csharp/Controller/SystemProxy.cs b/shadowsocks-csharp/Controller/SystemProxy.cs index c16aa235..fa3c5a8e 100755 --- a/shadowsocks-csharp/Controller/SystemProxy.cs +++ b/shadowsocks-csharp/Controller/SystemProxy.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; using System.Text; +using System.IO; namespace Shadowsocks.Controller { @@ -79,18 +80,24 @@ namespace Shadowsocks.Controller RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections", true); - var defulatValue = registry.GetValue("DefaultConnectionSettings"); - var connections = registry.GetValueNames(); - foreach (String each in connections){ - if (!(each.Equals("DefaultConnectionSettings") - || each.Equals("LAN Connection") - || each.Equals("SavedLegacySettings"))) + var defaultValue = registry.GetValue("DefaultConnectionSettings"); + try + { + var connections = registry.GetValueNames(); + foreach (String each in connections) { - //set all the connections's proxy as the lan - registry.SetValue(each, defulatValue); + if (!(each.Equals("DefaultConnectionSettings") + || each.Equals("LAN Connection") + || each.Equals("SavedLegacySettings"))) + { + //set all the connections's proxy as the lan + registry.SetValue(each, defaultValue); + } } + SystemProxy.NotifyIE(); + } catch (IOException e) { + Logging.LogUsefulException(e); } - NotifyIE(); } private static String GetTimestamp(DateTime value) From 418941cb758a12f6ce18ac18c27c177516617937 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Mon, 12 Jan 2015 00:20:09 +0800 Subject: [PATCH 22/45] add qrcode detector --- shadowsocks-csharp/3rd/zxing/BitArray.cs | 160 ---- shadowsocks-csharp/3rd/zxing/DecodeHintType.cs | 125 ++++ shadowsocks-csharp/3rd/zxing/EncodeHintType.cs | 131 ++++ shadowsocks-csharp/3rd/zxing/ResultPoint.cs | 191 +++++ .../3rd/zxing/ResultPointCallback.cs | 26 + shadowsocks-csharp/3rd/zxing/Version.cs | 342 --------- shadowsocks-csharp/3rd/zxing/WriterException.cs | 55 ++ shadowsocks-csharp/3rd/zxing/common/BitArray.cs | 488 +++++++++++++ shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs | 427 +++++++++++ shadowsocks-csharp/3rd/zxing/common/BitSource.cs | 124 ++++ .../3rd/zxing/common/DecoderResult.cs | 76 ++ .../3rd/zxing/common/DefaultGridSampler.cs | 82 +++ .../3rd/zxing/common/DetectorResult.cs | 39 + .../3rd/zxing/common/EncodingOptions.cs | 121 +++ shadowsocks-csharp/3rd/zxing/common/GridSampler.cs | 192 +++++ .../3rd/zxing/common/PerspectiveTransform.cs | 159 ++++ .../3rd/zxing/common/detector/MathUtils.cs | 48 ++ .../common/detector/MonochromeRectangleDetector.cs | 252 +++++++ .../common/detector/WhiteRectangleDetector.cs | 433 +++++++++++ .../zxing/{ => common/reedsolomon}/GenericGF.cs | 79 ++ .../{ => common/reedsolomon}/GenericGFPoly.cs | 103 ++- .../zxing/common/reedsolomon/ReedSolomonDecoder.cs | 227 ++++++ .../{ => common/reedsolomon}/ReedSolomonEncoder.cs | 0 .../3rd/zxing/qrcode/decoder/BitMatrixParser.cs | 281 +++++++ .../3rd/zxing/qrcode/decoder/DataBlock.cs | 146 ++++ .../3rd/zxing/qrcode/decoder/DataMask.cs | 165 +++++ .../zxing/qrcode/decoder/DecodedBitStreamParser.cs | 293 ++++++++ .../3rd/zxing/qrcode/decoder/Decoder.cs | 195 +++++ .../{ => qrcode/decoder}/ErrorCorrectionLevel.cs | 0 .../3rd/zxing/qrcode/decoder/FormatInformation.cs | 197 +++++ .../3rd/zxing/{ => qrcode/decoder}/Mode.cs | 64 ++ .../zxing/qrcode/decoder/QRCodeDecoderMetaData.cs | 60 ++ .../3rd/zxing/qrcode/decoder/Version.cs | 424 +++++++++++ .../3rd/zxing/qrcode/detector/AlignmentPattern.cs | 68 ++ .../qrcode/detector/AlignmentPatternFinder.cs | 324 +++++++++ .../3rd/zxing/qrcode/detector/Detector.cs | 429 +++++++++++ .../3rd/zxing/qrcode/detector/FinderPattern.cs | 107 +++ .../zxing/qrcode/detector/FinderPatternFinder.cs | 808 +++++++++++++++++++++ .../3rd/zxing/qrcode/detector/FinderPatternInfo.cs | 74 ++ .../3rd/zxing/{ => qrcode/encoder}/BlockPair.cs | 0 .../3rd/zxing/{ => qrcode/encoder}/ByteMatrix.cs | 0 .../3rd/zxing/{ => qrcode/encoder}/Encoder.cs | 288 +++++++- .../3rd/zxing/{ => qrcode/encoder}/MaskUtil.cs | 0 .../3rd/zxing/{ => qrcode/encoder}/MatrixUtil.cs | 18 +- .../3rd/zxing/{ => qrcode/encoder}/QRCode.cs | 36 +- .../zxing/qrcode/encoder/QrCodeEncodingOptions.cs | 110 +++ shadowsocks-csharp/shadowsocks-csharp.csproj | 57 +- 47 files changed, 7462 insertions(+), 562 deletions(-) delete mode 100755 shadowsocks-csharp/3rd/zxing/BitArray.cs create mode 100755 shadowsocks-csharp/3rd/zxing/DecodeHintType.cs create mode 100755 shadowsocks-csharp/3rd/zxing/EncodeHintType.cs create mode 100755 shadowsocks-csharp/3rd/zxing/ResultPoint.cs create mode 100755 shadowsocks-csharp/3rd/zxing/ResultPointCallback.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/Version.cs create mode 100755 shadowsocks-csharp/3rd/zxing/WriterException.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/BitArray.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/BitSource.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/DecoderResult.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/DefaultGridSampler.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/DetectorResult.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/EncodingOptions.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/GridSampler.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/PerspectiveTransform.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/detector/MathUtils.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/detector/MonochromeRectangleDetector.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/detector/WhiteRectangleDetector.cs rename shadowsocks-csharp/3rd/zxing/{ => common/reedsolomon}/GenericGF.cs (68%) rename shadowsocks-csharp/3rd/zxing/{ => common/reedsolomon}/GenericGFPoly.cs (69%) create mode 100755 shadowsocks-csharp/3rd/zxing/common/reedsolomon/ReedSolomonDecoder.cs rename shadowsocks-csharp/3rd/zxing/{ => common/reedsolomon}/ReedSolomonEncoder.cs (100%) create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/decoder/BitMatrixParser.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/decoder/DataBlock.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/decoder/DataMask.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/decoder/Decoder.cs rename shadowsocks-csharp/3rd/zxing/{ => qrcode/decoder}/ErrorCorrectionLevel.cs (100%) create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/decoder/FormatInformation.cs rename shadowsocks-csharp/3rd/zxing/{ => qrcode/decoder}/Mode.cs (55%) create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/decoder/QRCodeDecoderMetaData.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/decoder/Version.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/detector/AlignmentPattern.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/detector/AlignmentPatternFinder.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/detector/Detector.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPattern.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPatternFinder.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPatternInfo.cs rename shadowsocks-csharp/3rd/zxing/{ => qrcode/encoder}/BlockPair.cs (100%) rename shadowsocks-csharp/3rd/zxing/{ => qrcode/encoder}/ByteMatrix.cs (100%) rename shadowsocks-csharp/3rd/zxing/{ => qrcode/encoder}/Encoder.cs (67%) rename shadowsocks-csharp/3rd/zxing/{ => qrcode/encoder}/MaskUtil.cs (100%) rename shadowsocks-csharp/3rd/zxing/{ => qrcode/encoder}/MatrixUtil.cs (96%) rename shadowsocks-csharp/3rd/zxing/{ => qrcode/encoder}/QRCode.cs (67%) create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/encoder/QrCodeEncodingOptions.cs diff --git a/shadowsocks-csharp/3rd/zxing/BitArray.cs b/shadowsocks-csharp/3rd/zxing/BitArray.cs deleted file mode 100755 index b41484ca..00000000 --- a/shadowsocks-csharp/3rd/zxing/BitArray.cs +++ /dev/null @@ -1,160 +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 -{ - /// - /// A simple, fast array of bits, represented compactly by an array of ints internally. - /// - /// Sean Owen - public sealed class BitArray - { - private int[] bits; - private int size; - - public int Size - { - get - { - return size; - } - } - - public int SizeInBytes - { - get - { - return (size + 7) >> 3; - } - } - - public bool this[int i] - { - get - { - return (bits[i >> 5] & (1 << (i & 0x1F))) != 0; - } - } - - public BitArray() - { - this.size = 0; - this.bits = new int[1]; - } - - - private void ensureCapacity(int size) - { - if (size > bits.Length << 5) - { - int[] newBits = makeArray(size); - System.Array.Copy(bits, 0, newBits, 0, bits.Length); - bits = newBits; - } - } - - /// - /// Appends the bit. - /// - /// The bit. - public void appendBit(bool bit) - { - ensureCapacity(size + 1); - if (bit) - { - bits[size >> 5] |= 1 << (size & 0x1F); - } - size++; - } - - /// - /// 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 - /// 0, 1, 1, 1, 1, 0 in that order. - /// - /// containing bits to append - /// bits from value to append - public void appendBits(int value, int numBits) - { - if (numBits < 0 || numBits > 32) - { - throw new ArgumentException("Num bits must be between 0 and 32"); - } - ensureCapacity(size + numBits); - for (int numBitsLeft = numBits; numBitsLeft > 0; numBitsLeft--) - { - appendBit(((value >> (numBitsLeft - 1)) & 0x01) == 1); - } - } - - public void appendBitArray(BitArray other) - { - int otherSize = other.size; - ensureCapacity(size + otherSize); - for (int i = 0; i < otherSize; i++) - { - appendBit(other[i]); - } - } - - public void xor(BitArray other) - { - if (bits.Length != other.bits.Length) - { - throw new ArgumentException("Sizes don't match"); - } - for (int i = 0; i < bits.Length; i++) - { - // The last byte could be incomplete (i.e. not have 8 bits in - // it) but there is no problem since 0 XOR 0 == 0. - bits[i] ^= other.bits[i]; - } - } - - /// - /// Toes the bytes. - /// - /// first bit to start writing - /// array to write into. Bytes are written most-significant byte first. This is the opposite - /// of the internal representation, which is exposed by BitArray - /// position in array to start writing - /// how many bytes to write - public void toBytes(int bitOffset, byte[] array, int offset, int numBytes) - { - for (int i = 0; i < numBytes; i++) - { - int theByte = 0; - for (int j = 0; j < 8; j++) - { - if (this[bitOffset]) - { - theByte |= 1 << (7 - j); - } - bitOffset++; - } - array[offset + i] = (byte)theByte; - } - } - - private static int[] makeArray(int size) - { - return new int[(size + 31) >> 5]; - } - - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/DecodeHintType.cs b/shadowsocks-csharp/3rd/zxing/DecodeHintType.cs new file mode 100755 index 00000000..8ba21bbb --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/DecodeHintType.cs @@ -0,0 +1,125 @@ +/* +* 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; +using System.Collections.Generic; + +namespace ZXing +{ + /// + /// Encapsulates a type of hint that a caller may pass to a barcode reader to help it + /// more quickly or accurately decode it. It is up to implementations to decide what, + /// if anything, to do with the information that is supplied. + /// + /// + /// Sean Owen + /// dswitkin@google.com (Daniel Switkin) + public enum DecodeHintType + { + /// + /// Unspecified, application-specific hint. Maps to an unspecified . + /// + OTHER, + + /// + /// Image is a pure monochrome image of a barcode. Doesn't matter what it maps to; + /// use = true. + /// + PURE_BARCODE, + + /// + /// Image is known to be of one of a few possible formats. + /// Maps to a of s. + /// + POSSIBLE_FORMATS, + + /// + /// Spend more time to try to find a barcode; optimize for accuracy, not speed. + /// Doesn't matter what it maps to; use = true. + /// + TRY_HARDER, + + /// + /// Specifies what character encoding to use when decoding, where applicable (type String) + /// + CHARACTER_SET, + + /// + /// Allowed lengths of encoded data -- reject anything else. Maps to an int[]. + /// + ALLOWED_LENGTHS, + + /// + /// Assume Code 39 codes employ a check digit. Maps to . + /// + ASSUME_CODE_39_CHECK_DIGIT, + + /// + /// The caller needs to be notified via callback when a possible + /// is found. Maps to a . + /// + NEED_RESULT_POINT_CALLBACK, + + /// + /// Assume MSI codes employ a check digit. Maps to . + /// + ASSUME_MSI_CHECK_DIGIT, + + /// + /// if Code39 could be detected try to use extended mode for full ASCII character set + /// Maps to . + /// + USE_CODE_39_EXTENDED_MODE, + + /// + /// Don't fail if a Code39 is detected but can't be decoded in extended mode. + /// Return the raw Code39 result instead. Maps to . + /// + RELAXED_CODE_39_EXTENDED_MODE, + + /// + /// 1D readers supporting rotation with TRY_HARDER enabled. + /// But BarcodeReader class can do auto-rotating for 1D and 2D codes. + /// Enabling that option prevents 1D readers doing double rotation. + /// BarcodeReader enables that option automatically if "global" auto-rotation is enabled. + /// Maps to . + /// + TRY_HARDER_WITHOUT_ROTATION, + + /// + /// Assume the barcode is being processed as a GS1 barcode, and modify behavior as needed. + /// For example this affects FNC1 handling for Code 128 (aka GS1-128). Doesn't matter what it maps to; + /// use . + /// + ASSUME_GS1, + + /// + /// If true, return the start and end digits in a Codabar barcode instead of stripping them. They + /// are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them + /// to not be. Doesn't matter what it maps to; use . + /// + RETURN_CODABAR_START_END, + + /// + /// Allowed extension lengths for EAN or UPC barcodes. Other formats will ignore this. + /// Maps to an of the allowed extension lengths, for example [2], [5], or [2, 5]. + /// If it is optional to have an extension, do not set this hint. If this is set, + /// and a UPC or EAN barcode is found but an extension is not, then no result will be returned + /// at all. + /// + ALLOWED_EAN_EXTENSIONS + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/EncodeHintType.cs b/shadowsocks-csharp/3rd/zxing/EncodeHintType.cs new file mode 100755 index 00000000..01b17f8c --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/EncodeHintType.cs @@ -0,0 +1,131 @@ +/* +* 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 +{ + /// + /// These are a set of hints that you may pass to Writers to specify their behavior. + /// + /// dswitkin@google.com (Daniel Switkin) + public enum EncodeHintType + { + /// + /// Specifies the width of the barcode image + /// type: + /// + WIDTH, + + /// + /// Specifies the height of the barcode image + /// type: + /// + HEIGHT, + + /// + /// Don't put the content string into the output image. + /// type: + /// + PURE_BARCODE, + + /// + /// 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 + /// + /// For Aztec it is of type , 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 or (between 0 and 8), + /// + ERROR_CORRECTION, + + /// + /// Specifies what character encoding to use where applicable. + /// type: + /// + CHARACTER_SET, + + /// + /// 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: + /// + MARGIN, + + /// + /// Specifies whether to use compact mode for PDF417. + /// type: + /// + PDF417_COMPACT, + + /// + /// Specifies what compaction mode to use for PDF417. + /// type: + /// + PDF417_COMPACTION, + + /// + /// Specifies the minimum and maximum number of rows and columns for PDF417. + /// type: + /// + PDF417_DIMENSIONS, + + /// + /// 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: + /// + DISABLE_ECI, + + /// + /// Specifies the matrix shape for Data Matrix (type ) + /// + DATA_MATRIX_SHAPE, + + /// + /// Specifies a minimum barcode size (type ). Only applicable to Data Matrix now. + /// + MIN_SIZE, + + /// + /// Specifies a maximum barcode size (type ). Only applicable to Data Matrix now. + /// + MAX_SIZE, + + /// + /// if true, don't switch to codeset C for numbers + /// + CODE128_FORCE_CODESET_B, + + /// + /// Specifies the default encodation for Data Matrix (type ) + /// Make sure that the content fits into the encodation value, otherwise there will be an exception thrown. + /// standard value: Encodation.ASCII + /// + DATA_MATRIX_DEFAULT_ENCODATION, + + /// + /// 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 + /// + AZTEC_LAYERS, + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/ResultPoint.cs b/shadowsocks-csharp/3rd/zxing/ResultPoint.cs new file mode 100755 index 00000000..d3f39f2d --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/ResultPoint.cs @@ -0,0 +1,191 @@ +/* +* 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; + +using ZXing.Common.Detector; + +namespace ZXing +{ + /// + /// Encapsulates a point of interest in an image containing a barcode. Typically, this + /// would be the location of a finder pattern or the corner of the barcode, for example. + /// + /// Sean Owen + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + public class ResultPoint + { + private readonly float x; + private readonly float y; + private readonly byte[] bytesX; + private readonly byte[] bytesY; + private String toString; + + /// + /// Initializes a new instance of the class. + /// + public ResultPoint() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The x. + /// The y. + public ResultPoint(float x, float y) + { + this.x = x; + this.y = y; + // calculate only once for GetHashCode + bytesX = BitConverter.GetBytes(x); + bytesY = BitConverter.GetBytes(y); + } + + /// + /// Gets the X. + /// + virtual public float X + { + get + { + return x; + } + } + + /// + /// Gets the Y. + /// + virtual public float Y + { + get + { + return y; + } + } + + /// + /// Determines whether the specified is equal to this instance. + /// + /// The to compare with this instance. + /// + /// true if the specified is equal to this instance; otherwise, false. + /// + public override bool Equals(Object other) + { + var otherPoint = other as ResultPoint; + if (otherPoint == null) + return false; + return x == otherPoint.x && y == otherPoint.y; + } + + /// + /// Returns a hash code for this instance. + /// + /// + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// + public override int GetHashCode() + { + return 31 * ((bytesX[0] << 24) + (bytesX[1] << 16) + (bytesX[2] << 8) + bytesX[3]) + + (bytesY[0] << 24) + (bytesY[1] << 16) + (bytesY[2] << 8) + bytesY[3]; + } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override String ToString() + { + if (toString == null) + { + var result = new System.Text.StringBuilder(25); + result.AppendFormat(System.Globalization.CultureInfo.CurrentUICulture, "({0}, {1})", x, y); + toString = result.ToString(); + } + return toString; + } + + /// + /// Orders an array of three ResultPoints in an order [A,B,C] such that AB < AC and + /// BC < AC and the angle between BC and BA is less than 180 degrees. + /// + public static void orderBestPatterns(ResultPoint[] patterns) + { + // Find distances between pattern centers + float zeroOneDistance = distance(patterns[0], patterns[1]); + float oneTwoDistance = distance(patterns[1], patterns[2]); + float zeroTwoDistance = distance(patterns[0], patterns[2]); + + ResultPoint pointA, pointB, pointC; + // Assume one closest to other two is B; A and C will just be guesses at first + if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance) + { + pointB = patterns[0]; + pointA = patterns[1]; + pointC = patterns[2]; + } + else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance) + { + pointB = patterns[1]; + pointA = patterns[0]; + pointC = patterns[2]; + } + else + { + pointB = patterns[2]; + pointA = patterns[0]; + pointC = patterns[1]; + } + + // Use cross product to figure out whether A and C are correct or flipped. + // This asks whether BC x BA has a positive z component, which is the arrangement + // we want for A, B, C. If it's negative, then we've got it flipped around and + // should swap A and C. + if (crossProductZ(pointA, pointB, pointC) < 0.0f) + { + ResultPoint temp = pointA; + pointA = pointC; + pointC = temp; + } + + patterns[0] = pointA; + patterns[1] = pointB; + patterns[2] = pointC; + } + + + /// + /// distance between two points + /// + public static float distance(ResultPoint pattern1, ResultPoint pattern2) + { + return MathUtils.distance(pattern1.x, pattern1.y, pattern2.x, pattern2.y); + } + + /// + /// Returns the z component of the cross product between vectors BC and BA. + /// + private static float crossProductZ(ResultPoint pointA, ResultPoint pointB, ResultPoint pointC) + { + float bX = pointB.x; + float bY = pointB.y; + return ((pointC.x - bX) * (pointA.y - bY)) - ((pointC.y - bY) * (pointA.x - bX)); + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/ResultPointCallback.cs b/shadowsocks-csharp/3rd/zxing/ResultPointCallback.cs new file mode 100755 index 00000000..19c6f23a --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/ResultPointCallback.cs @@ -0,0 +1,26 @@ +/* +* Copyright 2009 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 +{ + /// Callback which is invoked when a possible result point (significant + /// point in the barcode image such as a corner) is found. + /// + /// + /// + /// + public delegate void ResultPointCallback(ResultPoint point); +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/Version.cs b/shadowsocks-csharp/3rd/zxing/Version.cs deleted file mode 100755 index be531ca4..00000000 --- a/shadowsocks-csharp/3rd/zxing/Version.cs +++ /dev/null @@ -1,342 +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; - -using ZXing.Common; - -namespace ZXing.QrCode.Internal -{ - /// - /// See ISO 18004:2006 Annex D - /// - /// Sean Owen - public sealed class Version - { - - private static readonly Version[] VERSIONS = buildVersions(); - - private readonly int versionNumber; - private readonly int[] alignmentPatternCenters; - private readonly ECBlocks[] ecBlocks; - private readonly int totalCodewords; - - private Version(int versionNumber, int[] alignmentPatternCenters, params ECBlocks[] ecBlocks) - { - this.versionNumber = versionNumber; - this.alignmentPatternCenters = alignmentPatternCenters; - this.ecBlocks = ecBlocks; - int total = 0; - int ecCodewords = ecBlocks[0].ECCodewordsPerBlock; - ECB[] ecbArray = ecBlocks[0].getECBlocks(); - foreach (var ecBlock in ecbArray) - { - total += ecBlock.Count * (ecBlock.DataCodewords + ecCodewords); - } - this.totalCodewords = total; - } - - /// - /// Gets the version number. - /// - public int VersionNumber - { - get - { - return versionNumber; - } - - } - - /// - /// Gets the total codewords. - /// - public int TotalCodewords - { - get - { - return totalCodewords; - } - - } - - /// - /// Gets the dimension for version. - /// - public int DimensionForVersion - { - get - { - return 17 + 4 * versionNumber; - } - - } - - /// - /// Gets the EC blocks for level. - /// - /// The ec level. - /// - public ECBlocks getECBlocksForLevel(ErrorCorrectionLevel ecLevel) - { - return ecBlocks[ecLevel.ordinal()]; - } - - /// - /// Gets the version for number. - /// - /// The version number. - /// - public static Version getVersionForNumber(int versionNumber) - { - if (versionNumber < 1 || versionNumber > 40) - { - throw new ArgumentException(); - } - return VERSIONS[versionNumber - 1]; - } - - - ///

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 - /// each set of blocks. It also holds the number of error-correction codewords per block since it - /// will be the same across all blocks within one version.

- ///
- public sealed class ECBlocks - { - private readonly int ecCodewordsPerBlock; - private readonly ECB[] ecBlocks; - - internal ECBlocks(int ecCodewordsPerBlock, params ECB[] ecBlocks) - { - this.ecCodewordsPerBlock = ecCodewordsPerBlock; - this.ecBlocks = ecBlocks; - } - - /// - /// Gets the EC codewords per block. - /// - public int ECCodewordsPerBlock - { - get - { - return ecCodewordsPerBlock; - } - } - - /// - /// Gets the num blocks. - /// - public int NumBlocks - { - get - { - int total = 0; - foreach (var ecBlock in ecBlocks) - { - total += ecBlock.Count; - } - return total; - } - } - - /// - /// Gets the total EC codewords. - /// - public int TotalECCodewords - { - get - { - return ecCodewordsPerBlock * NumBlocks; - } - } - - /// - /// Gets the EC blocks. - /// - /// - public ECB[] getECBlocks() - { - return ecBlocks; - } - } - - ///

Encapsualtes the parameters for one error-correction block in one symbol version. - /// This includes the number of data codewords, and the number of times a block with these - /// parameters is used consecutively in the QR code version's format.

- ///
- public sealed class ECB - { - private readonly int count; - private readonly int dataCodewords; - - internal ECB(int count, int dataCodewords) - { - this.count = count; - this.dataCodewords = dataCodewords; - } - - /// - /// Gets the count. - /// - public int Count - { - get - { - return count; - } - - } - /// - /// Gets the data codewords. - /// - public int DataCodewords - { - get - { - return dataCodewords; - } - - } - } - - /// - /// Returns a that represents this instance. - /// - /// - /// A that represents this instance. - /// - public override String ToString() - { - return Convert.ToString(versionNumber); - } - - /// See ISO 18004:2006 6.5.1 Table 9 - private static Version[] buildVersions() - { - return new Version[] - { - new Version(1, new int[] {}, - new ECBlocks(7, new ECB(1, 19)), - new ECBlocks(10, new ECB(1, 16)), - new ECBlocks(13, new ECB(1, 13)), - new ECBlocks(17, new ECB(1, 9))), - new Version(2, new int[] {6, 18}, - new ECBlocks(10, new ECB(1, 34)), - new ECBlocks(16, new ECB(1, 28)), - new ECBlocks(22, new ECB(1, 22)), - new ECBlocks(28, new ECB(1, 16))), - new Version(3, new int[] {6, 22}, - new ECBlocks(15, new ECB(1, 55)), - new ECBlocks(26, new ECB(1, 44)), - new ECBlocks(18, new ECB(2, 17)), - new ECBlocks(22, new ECB(2, 13))), - new Version(4, new int[] {6, 26}, - new ECBlocks(20, new ECB(1, 80)), - new ECBlocks(18, new ECB(2, 32)), - new ECBlocks(26, new ECB(2, 24)), - new ECBlocks(16, new ECB(4, 9))), - new Version(5, new int[] {6, 30}, - new ECBlocks(26, new ECB(1, 108)), - new ECBlocks(24, new ECB(2, 43)), - new ECBlocks(18, new ECB(2, 15), - new ECB(2, 16)), - new ECBlocks(22, new ECB(2, 11), - new ECB(2, 12))), - new Version(6, new int[] {6, 34}, - new ECBlocks(18, new ECB(2, 68)), - new ECBlocks(16, new ECB(4, 27)), - new ECBlocks(24, new ECB(4, 19)), - new ECBlocks(28, new ECB(4, 15))), - new Version(7, new int[] {6, 22, 38}, - new ECBlocks(20, new ECB(2, 78)), - new ECBlocks(18, new ECB(4, 31)), - new ECBlocks(18, new ECB(2, 14), - new ECB(4, 15)), - new ECBlocks(26, new ECB(4, 13), - new ECB(1, 14))), - new Version(8, new int[] {6, 24, 42}, - new ECBlocks(24, new ECB(2, 97)), - new ECBlocks(22, new ECB(2, 38), - new ECB(2, 39)), - new ECBlocks(22, new ECB(4, 18), - new ECB(2, 19)), - new ECBlocks(26, new ECB(4, 14), - new ECB(2, 15))), - new Version(9, new int[] {6, 26, 46}, - new ECBlocks(30, new ECB(2, 116)), - new ECBlocks(22, new ECB(3, 36), - new ECB(2, 37)), - new ECBlocks(20, new ECB(4, 16), - new ECB(4, 17)), - new ECBlocks(24, new ECB(4, 12), - new ECB(4, 13))), - new Version(10, new int[] {6, 28, 50}, - new ECBlocks(18, new ECB(2, 68), - new ECB(2, 69)), - new ECBlocks(26, new ECB(4, 43), - new ECB(1, 44)), - new ECBlocks(24, new ECB(6, 19), - new ECB(2, 20)), - new ECBlocks(28, new ECB(6, 15), - new ECB(2, 16))), - new Version(11, new int[] {6, 30, 54}, - new ECBlocks(20, new ECB(4, 81)), - new ECBlocks(30, new ECB(1, 50), - new ECB(4, 51)), - new ECBlocks(28, new ECB(4, 22), - new ECB(4, 23)), - new ECBlocks(24, new ECB(3, 12), - new ECB(8, 13))), - new Version(12, new int[] {6, 32, 58}, - new ECBlocks(24, new ECB(2, 92), - new ECB(2, 93)), - new ECBlocks(22, new ECB(6, 36), - new ECB(2, 37)), - new ECBlocks(26, new ECB(4, 20), - new ECB(6, 21)), - new ECBlocks(28, new ECB(7, 14), - new ECB(4, 15))), - new Version(13, new int[] {6, 34, 62}, - new ECBlocks(26, new ECB(4, 107)), - new ECBlocks(22, new ECB(8, 37), - new ECB(1, 38)), - new ECBlocks(24, new ECB(8, 20), - new ECB(4, 21)), - new ECBlocks(22, new ECB(12, 11), - new ECB(4, 12))), - new Version(14, new int[] {6, 26, 46, 66}, - new ECBlocks(30, new ECB(3, 115), - new ECB(1, 116)), - new ECBlocks(24, new ECB(4, 40), - new ECB(5, 41)), - new ECBlocks(20, new ECB(11, 16), - new ECB(5, 17)), - new ECBlocks(24, new ECB(11, 12), - new ECB(5, 13))), - new Version(15, new int[] {6, 26, 48, 70}, - new ECBlocks(22, new ECB(5, 87), - new ECB(1, 88)), - new ECBlocks(24, new ECB(5, 41), - new ECB(5, 42)), - new ECBlocks(30, new ECB(5, 24), - new ECB(7, 25)), - new ECBlocks(24, new ECB(11, 12), - new ECB(7, 13))) - }; - } - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/WriterException.cs b/shadowsocks-csharp/3rd/zxing/WriterException.cs new file mode 100755 index 00000000..f6cd3395 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/WriterException.cs @@ -0,0 +1,55 @@ +/* +* 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. +*/ + +using System; + +namespace ZXing +{ + /// + /// A base class which covers the range of exceptions which may occur when encoding a barcode using + /// the Writer framework. + /// + /// dswitkin@google.com (Daniel Switkin) + [Serializable] + public sealed class WriterException : Exception + { + /// + /// Initializes a new instance of the class. + /// + public WriterException() + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The message. + public WriterException(String message) + :base(message) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The message. + /// The inner exc. + public WriterException(String message, Exception innerExc) + : base(message, innerExc) + { + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/BitArray.cs b/shadowsocks-csharp/3rd/zxing/common/BitArray.cs new file mode 100755 index 00000000..c3676142 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/BitArray.cs @@ -0,0 +1,488 @@ +/* +* 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 +{ + /// + /// A simple, fast array of bits, represented compactly by an array of ints internally. + /// + /// Sean Owen + public sealed class BitArray + { + private int[] bits; + private int size; + + public int Size + { + get + { + return size; + } + } + + public int SizeInBytes + { + get + { + return (size + 7) >> 3; + } + } + + public bool this[int i] + { + get + { + return (bits[i >> 5] & (1 << (i & 0x1F))) != 0; + } + set + { + if (value) + bits[i >> 5] |= 1 << (i & 0x1F); + } + } + + public BitArray() + { + this.size = 0; + 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) + { + if (size > bits.Length << 5) + { + int[] newBits = makeArray(size); + System.Array.Copy(bits, 0, newBits, 0, bits.Length); + bits = newBits; + } + } + + /// Flips bit i. + /// + /// + /// bit to set + /// + 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 + }; + + /// + /// 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. + /// + /// + /// first bit to set + /// + /// 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. + /// + public void setBulk(int i, int newBits) + { + 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() + { + int max = bits.Length; + for (int i = 0; i < max; i++) + { + bits[i] = 0; + } + } + + /// 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. + /// + /// The bit. + public void appendBit(bool bit) + { + ensureCapacity(size + 1); + if (bit) + { + bits[size >> 5] |= 1 << (size & 0x1F); + } + size++; + } + + /// underlying array of ints. The first element holds the first 32 bits, and the least + /// significant bit is bit 0. + /// + public int[] Array + { + get { return bits; } + } + + /// + /// 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 + /// 0, 1, 1, 1, 1, 0 in that order. + /// + /// The value. + /// The num bits. + public void appendBits(int value, int numBits) + { + if (numBits < 0 || numBits > 32) + { + throw new ArgumentException("Num bits must be between 0 and 32"); + } + ensureCapacity(size + numBits); + for (int numBitsLeft = numBits; numBitsLeft > 0; numBitsLeft--) + { + appendBit(((value >> (numBitsLeft - 1)) & 0x01) == 1); + } + } + + public void appendBitArray(BitArray other) + { + int otherSize = other.size; + ensureCapacity(size + otherSize); + for (int i = 0; i < otherSize; i++) + { + appendBit(other[i]); + } + } + + public void xor(BitArray other) + { + if (bits.Length != other.bits.Length) + { + throw new ArgumentException("Sizes don't match"); + } + for (int i = 0; i < bits.Length; i++) + { + // The last byte could be incomplete (i.e. not have 8 bits in + // it) but there is no problem since 0 XOR 0 == 0. + bits[i] ^= other.bits[i]; + } + } + + /// + /// Toes the bytes. + /// + /// first bit to start writing + /// array to write into. Bytes are written most-significant byte first. This is the opposite + /// of the internal representation, which is exposed by BitArray + /// position in array to start writing + /// how many bytes to write + public void toBytes(int bitOffset, byte[] array, int offset, int numBytes) + { + for (int i = 0; i < numBytes; i++) + { + int theByte = 0; + for (int j = 0; j < 8; j++) + { + if (this[bitOffset]) + { + theByte |= 1 << (7 - j); + } + bitOffset++; + } + array[offset + i] = (byte)theByte; + } + } + + /// 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]; + } + + /// + /// Determines whether the specified is equal to this instance. + /// + /// The to compare with this instance. + /// + /// true if the specified is equal to this instance; otherwise, false. + /// + 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; + } + + /// + /// Returns a hash code for this instance. + /// + /// + /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. + /// + public override int GetHashCode() + { + var hash = size; + foreach (var bit in bits) + { + hash = 31 * hash + bit.GetHashCode(); + } + 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. + /// + /// + /// Ein neues Objekt, das eine Kopie dieser Instanz darstellt. + /// + public object Clone() + { + return new BitArray((int[])bits.Clone(), size); + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs b/shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs new file mode 100755 index 00000000..52dce4bd --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/BitMatrix.cs @@ -0,0 +1,427 @@ +/* +* 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 +{ + /// + ///

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.

+ ///

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.

+ ///

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.

+ ///
+ /// Sean Owen + /// dswitkin@google.com (Daniel Switkin) + public sealed partial class BitMatrix + { + private readonly int width; + private readonly int height; + private readonly int rowSize; + private readonly int[] bits; + + /// The width of the matrix + /// + public int Width + { + get + { + return width; + } + + } + /// The height of the matrix + /// + public int Height + { + get + { + 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. + 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]; + } + + private BitMatrix(int width, int height, int rowSize, int[] bits) + { + this.width = width; + this.height = height; + this.rowSize = rowSize; + this.bits = bits; + } + + ///

Gets the requested bit, where true means black.

+ /// + ///
+ /// The horizontal component (i.e. which column) + /// + /// The vertical component (i.e. which row) + /// + /// value of given bit in matrix + /// + 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); + } + } + } + + ///

Flips the given bit.

+ /// + ///
+ /// The horizontal component (i.e. which column) + /// + /// The vertical component (i.e. which row) + /// + public void flip(int x, int y) + { + int offset = y * rowSize + (x >> 5); + 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.

+ /// + ///
+ /// The horizontal position to begin at (inclusive) + /// + /// The vertical position to begin at (inclusive) + /// + /// The width of the region + /// + /// The height of the region + /// + 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); + } + } + } + + /// A fast method to retrieve one row of data from the matrix as a BitArray. + /// + /// + /// The row to retrieve + /// + /// An optional caller-allocated BitArray, will be allocated if null or too small + /// + /// The resulting BitArray - this reference should always be used even when passing + /// your own row + /// + 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; + } + + /// + /// Sets the row. + /// + /// row to set + /// {@link BitArray} to copy from + public void setRow(int y, BitArray row) + { + 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. + /// + /// {x,y} coordinate of top-left-most 1 bit, or null if it is all white + 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()); + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/BitSource.cs b/shadowsocks-csharp/3rd/zxing/common/BitSource.cs new file mode 100755 index 00000000..ba9156d2 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/BitSource.cs @@ -0,0 +1,124 @@ +/* +* 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 +{ + ///

This provides an easy abstraction to read bits at a time from a sequence of bytes, where the + /// number of bits read is not often a multiple of 8.

+ /// + ///

This class is thread-safe but not reentrant. Unless the caller modifies the bytes array + /// it passed in, in which case all bets are off.

+ /// + ///
+ /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + public sealed class BitSource + { + private readonly byte[] bytes; + private int byteOffset; + private int bitOffset; + + /// bytes from which this will read bits. Bits will be read from the first byte first. + /// Bits are read within a byte from most-significant to least-significant bit. + /// + public BitSource(byte[] bytes) + { + this.bytes = bytes; + } + + /// + /// index of next bit in current byte which would be read by the next call to {@link #readBits(int)}. + /// + public int BitOffset + { + get { return bitOffset; } + } + + /// + /// index of next byte in input byte array which would be read by the next call to {@link #readBits(int)}. + /// + public int ByteOffset + { + get { return byteOffset; } + } + + /// number of bits to read + /// + /// int representing the bits read. The bits will appear as the least-significant + /// bits of the int + /// + /// if numBits isn't in [1,32] or more than is available + public int readBits(int numBits) + { + if (numBits < 1 || numBits > 32 || numBits > available()) + { + throw new ArgumentException(numBits.ToString(), "numBits"); + } + + int result = 0; + + // First, read remainder from current byte + if (bitOffset > 0) + { + int bitsLeft = 8 - bitOffset; + int toRead = numBits < bitsLeft ? numBits : bitsLeft; + int bitsToNotRead = bitsLeft - toRead; + int mask = (0xFF >> (8 - toRead)) << bitsToNotRead; + result = (bytes[byteOffset] & mask) >> bitsToNotRead; + numBits -= toRead; + bitOffset += toRead; + if (bitOffset == 8) + { + bitOffset = 0; + byteOffset++; + } + } + + // Next read whole bytes + if (numBits > 0) + { + while (numBits >= 8) + { + result = (result << 8) | (bytes[byteOffset] & 0xFF); + byteOffset++; + numBits -= 8; + } + + // Finally read a partial byte + if (numBits > 0) + { + int bitsToNotRead = 8 - numBits; + int mask = (0xFF >> bitsToNotRead) << bitsToNotRead; + result = (result << numBits) | ((bytes[byteOffset] & mask) >> bitsToNotRead); + bitOffset += numBits; + } + } + + return result; + } + + /// number of bits that can be read successfully + /// + public int available() + { + return 8 * (bytes.Length - byteOffset) - bitOffset; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/DecoderResult.cs b/shadowsocks-csharp/3rd/zxing/common/DecoderResult.cs new file mode 100755 index 00000000..024930f2 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/DecoderResult.cs @@ -0,0 +1,76 @@ +/* +* 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; +using System.Collections.Generic; + +namespace ZXing.Common +{ + /// + /// Encapsulates the result of decoding a matrix of bits. This typically + /// applies to 2D barcode formats. For now it contains the raw bytes obtained, + /// as well as a String interpretation of those bytes, if applicable. + /// Sean Owen + /// + public sealed class DecoderResult + { + public byte[] RawBytes { get; private set; } + + public String Text { get; private set; } + + public IList ByteSegments { get; private set; } + + public String ECLevel { get; private set; } + + public bool StructuredAppend + { + get { return StructuredAppendParity >= 0 && StructuredAppendSequenceNumber >= 0; } + } + + public int ErrorsCorrected { get; set; } + + public int StructuredAppendSequenceNumber { get; private set; } + + public int Erasures { get; set; } + + public int StructuredAppendParity { get; private set; } + + /// + /// Miscellanseous data value for the various decoders + /// + /// The other. + public object Other { get; set; } + + public DecoderResult(byte[] rawBytes, String text, IList byteSegments, String ecLevel) + : this(rawBytes, text, byteSegments, ecLevel, -1, -1) + { + } + + public DecoderResult(byte[] rawBytes, String text, IList byteSegments, String ecLevel, int saSequence, int saParity) + { + if (rawBytes == null && text == null) + { + throw new ArgumentException(); + } + RawBytes = rawBytes; + Text = text; + ByteSegments = byteSegments; + ECLevel = ecLevel; + StructuredAppendParity = saParity; + StructuredAppendSequenceNumber = saSequence; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/DefaultGridSampler.cs b/shadowsocks-csharp/3rd/zxing/common/DefaultGridSampler.cs new file mode 100755 index 00000000..b3afaf8e --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/DefaultGridSampler.cs @@ -0,0 +1,82 @@ +/* +* 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 +{ + + /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + public sealed class DefaultGridSampler : GridSampler + { + public override BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, float p1ToX, float p1ToY, float p2ToX, float p2ToY, float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX, float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY) + { + PerspectiveTransform transform = PerspectiveTransform.quadrilateralToQuadrilateral( + p1ToX, p1ToY, p2ToX, p2ToY, p3ToX, p3ToY, p4ToX, p4ToY, + p1FromX, p1FromY, p2FromX, p2FromY, p3FromX, p3FromY, p4FromX, p4FromY); + return sampleGrid(image, dimensionX, dimensionY, transform); + } + + public override BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, PerspectiveTransform transform) + { + if (dimensionX <= 0 || dimensionY <= 0) + { + return null; + } + BitMatrix bits = new BitMatrix(dimensionX, dimensionY); + float[] points = new float[dimensionX << 1]; + for (int y = 0; y < dimensionY; y++) + { + int max = points.Length; + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + float iValue = (float)y + 0.5f; + for (int x = 0; x < max; x += 2) + { + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + points[x] = (float)(x >> 1) + 0.5f; + points[x + 1] = iValue; + } + transform.transformPoints(points); + // Quick check to see if points transformed to something inside the image; + // sufficient to check the endpoints + if (!checkAndNudgePoints(image, points)) + return null; + try + { + for (int x = 0; x < max; x += 2) + { + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + bits[x >> 1, y] = image[(int)points[x], (int)points[x + 1]]; + } + } + catch (System.IndexOutOfRangeException) + { + // This feels wrong, but, sometimes if the finder patterns are misidentified, the resulting + // transform gets "twisted" such that it maps a straight line of points to a set of points + // whose endpoints are in bounds, but others are not. There is probably some mathematical + // way to detect this about the transformation that I don't know yet. + // This results in an ugly runtime exception despite our clever checks above -- can't have + // that. We could check each point's coordinates but that feels duplicative. We settle for + // catching and wrapping ArrayIndexOutOfBoundsException. + return null; + } + } + return bits; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/DetectorResult.cs b/shadowsocks-csharp/3rd/zxing/common/DetectorResult.cs new file mode 100755 index 00000000..0f99b9ba --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/DetectorResult.cs @@ -0,0 +1,39 @@ +/* +* 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. +*/ + +namespace ZXing.Common +{ + ///

Encapsulates the result of detecting a barcode in an image. This includes the raw + /// matrix of black/white pixels corresponding to the barcode, and possibly points of interest + /// in the image, like the location of finder patterns or corners of the barcode in the image.

+ /// + ///
+ /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + public class DetectorResult + { + public BitMatrix Bits { get; private set; } + public ResultPoint[] Points { get; private set; } + + public DetectorResult(BitMatrix bits, ResultPoint[] points) + { + Bits = bits; + Points = points; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/EncodingOptions.cs b/shadowsocks-csharp/3rd/zxing/common/EncodingOptions.cs new file mode 100755 index 00000000..683453ec --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/EncodingOptions.cs @@ -0,0 +1,121 @@ +/* + * Copyright 2012 ZXing.Net 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 System.ComponentModel; + +namespace ZXing.Common +{ + /// + /// Defines an container for encoder options + /// + [Serializable] + public class EncodingOptions + { + /// + /// Gets the data container for all options + /// + [Browsable(false)] + public IDictionary Hints { get; private set; } + + /// + /// Specifies the height of the barcode image + /// + public int Height + { + get + { + if (Hints.ContainsKey(EncodeHintType.HEIGHT)) + { + return (int)Hints[EncodeHintType.HEIGHT]; + } + return 0; + } + set + { + Hints[EncodeHintType.HEIGHT] = value; + } + } + + /// + /// Specifies the width of the barcode image + /// + public int Width + { + get + { + if (Hints.ContainsKey(EncodeHintType.WIDTH)) + { + return (int)Hints[EncodeHintType.WIDTH]; + } + return 0; + } + set + { + Hints[EncodeHintType.WIDTH] = value; + } + } + + /// + /// Don't put the content string into the output image. + /// + public bool PureBarcode + { + get + { + if (Hints.ContainsKey(EncodeHintType.PURE_BARCODE)) + { + return (bool)Hints[EncodeHintType.PURE_BARCODE]; + } + return false; + } + set + { + Hints[EncodeHintType.PURE_BARCODE] = value; + } + } + + /// + /// 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. + /// + public int Margin + { + get + { + if (Hints.ContainsKey(EncodeHintType.MARGIN)) + { + return (int) Hints[EncodeHintType.MARGIN]; + } + return 0; + } + set + { + Hints[EncodeHintType.MARGIN] = value; + } + } + + /// + /// Initializes a new instance of the class. + /// + public EncodingOptions() + { + Hints = new Dictionary(); + } + } +} diff --git a/shadowsocks-csharp/3rd/zxing/common/GridSampler.cs b/shadowsocks-csharp/3rd/zxing/common/GridSampler.cs new file mode 100755 index 00000000..a1bffa99 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/GridSampler.cs @@ -0,0 +1,192 @@ +/* +* 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. +*/ + +namespace ZXing.Common +{ + /// Implementations of this class can, given locations of finder patterns for a QR code in an + /// image, sample the right points in the image to reconstruct the QR code, accounting for + /// perspective distortion. It is abstracted since it is relatively expensive and should be allowed + /// to take advantage of platform-specific optimized implementations, like Sun's Java Advanced + /// Imaging library, but which may not be available in other environments such as J2ME, and vice + /// versa. + /// + /// The implementation used can be controlled by calling {@link #setGridSampler(GridSampler)} + /// with an instance of a class which implements this interface. + /// + /// + /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + public abstract class GridSampler + { + /// the current implementation of {@link GridSampler} + /// + public static GridSampler Instance + { + get + { + return gridSampler; + } + + } + + private static GridSampler gridSampler = new DefaultGridSampler(); + + /// Sets the implementation of {@link GridSampler} used by the library. One global + /// instance is stored, which may sound problematic. But, the implementation provided + /// ought to be appropriate for the entire platform, and all uses of this library + /// in the whole lifetime of the JVM. For instance, an Android activity can swap in + /// an implementation that takes advantage of native platform libraries. + /// + /// + /// The platform-specific object to install. + /// + public static void setGridSampler(GridSampler newGridSampler) + { + if (newGridSampler == null) + { + throw new System.ArgumentException(); + } + gridSampler = newGridSampler; + } + + ///

Samples an image for a square matrix of bits of the given dimension. This is used to extract + /// the black/white modules of a 2D barcode like a QR Code found in an image. Because this barcode + /// may be rotated or perspective-distorted, the caller supplies four points in the source image + /// that define known points in the barcode, so that the image may be sampled appropriately.

+ /// + ///

The last eight "from" parameters are four X/Y coordinate pairs of locations of points in + /// the image that define some significant points in the image to be sample. For example, + /// these may be the location of finder pattern in a QR Code.

+ /// + ///

The first eight "to" parameters are four X/Y coordinate pairs measured in the destination + /// {@link BitMatrix}, from the top left, where the known points in the image given by the "from" + /// parameters map to.

+ /// + ///

These 16 parameters define the transformation needed to sample the image.

+ /// + ///
+ /// image to sample + /// + /// width/height of {@link BitMatrix} to sample from image + /// + /// {@link BitMatrix} representing a grid of points sampled from the image within a region + /// defined by the "from" parameters + /// + /// ReaderException if image can't be sampled, for example, if the transformation defined + /// by the given points is invalid or results in sampling outside the image boundaries + /// + public abstract BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, float p1ToX, float p1ToY, float p2ToX, float p2ToY, float p3ToX, float p3ToY, float p4ToX, float p4ToY, float p1FromX, float p1FromY, float p2FromX, float p2FromY, float p3FromX, float p3FromY, float p4FromX, float p4FromY); + + public virtual BitMatrix sampleGrid(BitMatrix image, int dimensionX, int dimensionY, PerspectiveTransform transform) + { + throw new System.NotSupportedException(); + } + + + ///

Checks a set of points that have been transformed to sample points on an image against + /// the image's dimensions to see if the point are even within the image.

+ /// + ///

This method will actually "nudge" the endpoints back onto the image if they are found to be + /// barely (less than 1 pixel) off the image. This accounts for imperfect detection of finder + /// patterns in an image where the QR Code runs all the way to the image border.

+ /// + ///

For efficiency, the method will check points from either end of the line until one is found + /// to be within the image. Because the set of points are assumed to be linear, this is valid.

+ /// + ///
+ /// image into which the points should map + /// + /// actual points in x1,y1,...,xn,yn form + /// + protected internal static bool checkAndNudgePoints(BitMatrix image, float[] points) + { + int width = image.Width; + int height = image.Height; + // Check and nudge points from start until we see some that are OK: + bool nudged = true; + for (int offset = 0; offset < points.Length && nudged; offset += 2) + { + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + int x = (int)points[offset]; + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + int y = (int)points[offset + 1]; + if (x < -1 || x > width || y < -1 || y > height) + { + return false; + } + nudged = false; + if (x == -1) + { + points[offset] = 0.0f; + nudged = true; + } + else if (x == width) + { + points[offset] = width - 1; + nudged = true; + } + if (y == -1) + { + points[offset + 1] = 0.0f; + nudged = true; + } + else if (y == height) + { + points[offset + 1] = height - 1; + nudged = true; + } + } + // Check and nudge points from end: + nudged = true; + for (int offset = points.Length - 2; offset >= 0 && nudged; offset -= 2) + { + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + int x = (int)points[offset]; + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + int y = (int)points[offset + 1]; + if (x < -1 || x > width || y < -1 || y > height) + { + return false; + } + nudged = false; + if (x == -1) + { + points[offset] = 0.0f; + nudged = true; + } + else if (x == width) + { + points[offset] = width - 1; + nudged = true; + } + if (y == -1) + { + points[offset + 1] = 0.0f; + nudged = true; + } + else if (y == height) + { + points[offset + 1] = height - 1; + nudged = true; + } + } + + return true; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/PerspectiveTransform.cs b/shadowsocks-csharp/3rd/zxing/common/PerspectiveTransform.cs new file mode 100755 index 00000000..3515ddd8 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/PerspectiveTransform.cs @@ -0,0 +1,159 @@ +/* +* 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. +*/ + +namespace ZXing.Common +{ + ///

This class implements a perspective transform in two dimensions. Given four source and four + /// destination points, it will compute the transformation implied between them. The code is based + /// directly upon section 3.4.2 of George Wolberg's "Digital Image Warping"; see pages 54-56.

+ /// + ///
+ /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + public sealed class PerspectiveTransform + { + private float a11; + private float a12; + private float a13; + private float a21; + private float a22; + private float a23; + private float a31; + private float a32; + private float a33; + + private PerspectiveTransform(float a11, float a21, float a31, float a12, float a22, float a32, float a13, float a23, float a33) + { + this.a11 = a11; + this.a12 = a12; + this.a13 = a13; + this.a21 = a21; + this.a22 = a22; + this.a23 = a23; + this.a31 = a31; + this.a32 = a32; + this.a33 = a33; + } + + public static PerspectiveTransform quadrilateralToQuadrilateral(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3, float x0p, float y0p, float x1p, float y1p, float x2p, float y2p, float x3p, float y3p) + { + + PerspectiveTransform qToS = quadrilateralToSquare(x0, y0, x1, y1, x2, y2, x3, y3); + PerspectiveTransform sToQ = squareToQuadrilateral(x0p, y0p, x1p, y1p, x2p, y2p, x3p, y3p); + return sToQ.times(qToS); + } + + public void transformPoints(float[] points) + { + int max = points.Length; + float a11 = this.a11; + float a12 = this.a12; + float a13 = this.a13; + float a21 = this.a21; + float a22 = this.a22; + float a23 = this.a23; + float a31 = this.a31; + float a32 = this.a32; + float a33 = this.a33; + for (int i = 0; i < max; i += 2) + { + float x = points[i]; + float y = points[i + 1]; + float denominator = a13 * x + a23 * y + a33; + points[i] = (a11 * x + a21 * y + a31) / denominator; + points[i + 1] = (a12 * x + a22 * y + a32) / denominator; + } + } + + /// Convenience method, not optimized for performance. + public void transformPoints(float[] xValues, float[] yValues) + { + int n = xValues.Length; + for (int i = 0; i < n; i++) + { + float x = xValues[i]; + float y = yValues[i]; + float denominator = a13 * x + a23 * y + a33; + xValues[i] = (a11 * x + a21 * y + a31) / denominator; + yValues[i] = (a12 * x + a22 * y + a32) / denominator; + } + } + + public static PerspectiveTransform squareToQuadrilateral(float x0, float y0, + float x1, float y1, + float x2, float y2, + float x3, float y3) + { + float dx3 = x0 - x1 + x2 - x3; + float dy3 = y0 - y1 + y2 - y3; + if (dx3 == 0.0f && dy3 == 0.0f) + { + // Affine + return new PerspectiveTransform(x1 - x0, x2 - x1, x0, + y1 - y0, y2 - y1, y0, + 0.0f, 0.0f, 1.0f); + } + else + { + float dx1 = x1 - x2; + float dx2 = x3 - x2; + float dy1 = y1 - y2; + float dy2 = y3 - y2; + float denominator = dx1*dy2 - dx2*dy1; + float a13 = (dx3*dy2 - dx2*dy3)/denominator; + float a23 = (dx1*dy3 - dx3*dy1)/denominator; + return new PerspectiveTransform(x1 - x0 + a13*x1, x3 - x0 + a23*x3, x0, + y1 - y0 + a13*y1, y3 - y0 + a23*y3, y0, + a13, a23, 1.0f); + } + } + + public static PerspectiveTransform quadrilateralToSquare(float x0, float y0, float x1, float y1, float x2, float y2, float x3, float y3) + { + // Here, the adjoint serves as the inverse: + return squareToQuadrilateral(x0, y0, x1, y1, x2, y2, x3, y3).buildAdjoint(); + } + + internal PerspectiveTransform buildAdjoint() + { + // Adjoint is the transpose of the cofactor matrix: + return new PerspectiveTransform(a22 * a33 - a23 * a32, + a23 * a31 - a21 * a33, + a21 * a32 - a22 * a31, + a13 * a32 - a12 * a33, + a11 * a33 - a13 * a31, + a12 * a31 - a11 * a32, + a12 * a23 - a13 * a22, + a13 * a21 - a11 * a23, + a11 * a22 - a12 * a21); + } + + internal PerspectiveTransform times(PerspectiveTransform other) + { + return new PerspectiveTransform(a11 * other.a11 + a21 * other.a12 + a31 * other.a13, + a11 * other.a21 + a21 * other.a22 + a31 * other.a23, + a11 * other.a31 + a21 * other.a32 + a31 * other.a33, + a12 * other.a11 + a22 * other.a12 + a32 * other.a13, + a12 * other.a21 + a22 * other.a22 + a32 * other.a23, + a12 * other.a31 + a22 * other.a32 + a32 * other.a33, + a13 * other.a11 + a23 * other.a12 + a33 * other.a13, + a13 * other.a21 + a23 * other.a22 + a33 * other.a23, + a13 * other.a31 + a23 * other.a32 + a33 * other.a33); + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/detector/MathUtils.cs b/shadowsocks-csharp/3rd/zxing/common/detector/MathUtils.cs new file mode 100755 index 00000000..8782202f --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/detector/MathUtils.cs @@ -0,0 +1,48 @@ +/* + * Copyright 2012 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.Detector +{ + public static class MathUtils + { + /// + /// Ends up being a bit faster than {@link Math#round(float)}. This merely rounds its + /// argument to the nearest int, where x.5 rounds up to x+1. + /// + /// The d. + /// + public static int round(float d) + { + return (int)(d + 0.5f); + } + + public static float distance(float aX, float aY, float bX, float bY) + { + float xDiff = aX - bX; + float yDiff = aY - bY; + return (float)Math.Sqrt(xDiff * xDiff + yDiff * yDiff); + } + + public static float distance(int aX, int aY, int bX, int bY) + { + int xDiff = aX - bX; + int yDiff = aY - bY; + return (float)Math.Sqrt(xDiff * xDiff + yDiff * yDiff); + } + } +} diff --git a/shadowsocks-csharp/3rd/zxing/common/detector/MonochromeRectangleDetector.cs b/shadowsocks-csharp/3rd/zxing/common/detector/MonochromeRectangleDetector.cs new file mode 100755 index 00000000..9fb4515f --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/detector/MonochromeRectangleDetector.cs @@ -0,0 +1,252 @@ +/* +* Copyright 2009 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.Common.Detector +{ + ///

A somewhat generic detector that looks for a barcode-like rectangular region within an image. + /// It looks within a mostly white region of an image for a region of black and white, but mostly + /// black. It returns the four corners of the region, as best it can determine.

+ /// + ///
+ /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + public sealed class MonochromeRectangleDetector + { + private const int MAX_MODULES = 32; + + private BitMatrix image; + + public MonochromeRectangleDetector(BitMatrix image) + { + this.image = image; + } + + ///

Detects a rectangular region of black and white -- mostly black -- with a region of mostly + /// white, in an image.

+ /// + ///
+ /// {@link ResultPoint}[] describing the corners of the rectangular region. The first and + /// last points are opposed on the diagonal, as are the second and third. The first point will be + /// the topmost point and the last, the bottommost. The second point will be leftmost and the + /// third, the rightmost + /// + public ResultPoint[] detect() + { + int height = image.Height; + int width = image.Width; + int halfHeight = height >> 1; + int halfWidth = width >> 1; + int deltaY = System.Math.Max(1, height / (MAX_MODULES << 3)); + int deltaX = System.Math.Max(1, width / (MAX_MODULES << 3)); + + int top = 0; + int bottom = height; + int left = 0; + int right = width; + ResultPoint pointA = findCornerFromCenter(halfWidth, 0, left, right, halfHeight, -deltaY, top, bottom, halfWidth >> 1); + if (pointA == null) + return null; + top = (int)pointA.Y - 1; + ResultPoint pointB = findCornerFromCenter(halfWidth, -deltaX, left, right, halfHeight, 0, top, bottom, halfHeight >> 1); + if (pointB == null) + return null; + left = (int)pointB.X - 1; + ResultPoint pointC = findCornerFromCenter(halfWidth, deltaX, left, right, halfHeight, 0, top, bottom, halfHeight >> 1); + if (pointC == null) + return null; + right = (int)pointC.X + 1; + ResultPoint pointD = findCornerFromCenter(halfWidth, 0, left, right, halfHeight, deltaY, top, bottom, halfWidth >> 1); + if (pointD == null) + return null; + bottom = (int)pointD.Y + 1; + + // Go try to find point A again with better information -- might have been off at first. + pointA = findCornerFromCenter(halfWidth, 0, left, right, halfHeight, -deltaY, top, bottom, halfWidth >> 2); + if (pointA == null) + return null; + + return new ResultPoint[] { pointA, pointB, pointC, pointD }; + } + + /// Attempts to locate a corner of the barcode by scanning up, down, left or right from a center + /// point which should be within the barcode. + /// + /// + /// center's x component (horizontal) + /// + /// same as deltaY but change in x per step instead + /// + /// minimum value of x + /// + /// maximum value of x + /// + /// center's y component (vertical) + /// + /// change in y per step. If scanning up this is negative; down, positive; + /// left or right, 0 + /// + /// minimum value of y to search through (meaningless when di == 0) + /// + /// maximum value of y + /// + /// maximum run of white pixels that can still be considered to be within + /// the barcode + /// + /// a {@link com.google.zxing.ResultPoint} encapsulating the corner that was found + /// + private ResultPoint findCornerFromCenter(int centerX, int deltaX, int left, int right, int centerY, int deltaY, int top, int bottom, int maxWhiteRun) + { + int[] lastRange = null; + for (int y = centerY, x = centerX; y < bottom && y >= top && x < right && x >= left; y += deltaY, x += deltaX) + { + int[] range; + if (deltaX == 0) + { + // horizontal slices, up and down + range = blackWhiteRange(y, maxWhiteRun, left, right, true); + } + else + { + // vertical slices, left and right + range = blackWhiteRange(x, maxWhiteRun, top, bottom, false); + } + if (range == null) + { + if (lastRange == null) + { + return null; + } + // lastRange was found + if (deltaX == 0) + { + int lastY = y - deltaY; + if (lastRange[0] < centerX) + { + if (lastRange[1] > centerX) + { + // straddle, choose one or the other based on direction + return new ResultPoint(deltaY > 0 ? lastRange[0] : lastRange[1], lastY); + } + return new ResultPoint(lastRange[0], lastY); + } + else + { + return new ResultPoint(lastRange[1], lastY); + } + } + else + { + int lastX = x - deltaX; + if (lastRange[0] < centerY) + { + if (lastRange[1] > centerY) + { + return new ResultPoint(lastX, deltaX < 0 ? lastRange[0] : lastRange[1]); + } + return new ResultPoint(lastX, lastRange[0]); + } + else + { + return new ResultPoint(lastX, lastRange[1]); + } + } + } + lastRange = range; + } + return null; + } + + /// Computes the start and end of a region of pixels, either horizontally or vertically, that could + /// be part of a Data Matrix barcode. + /// + /// + /// if scanning horizontally, this is the row (the fixed vertical location) + /// where we are scanning. If scanning vertically it's the column, the fixed horizontal location + /// + /// largest run of white pixels that can still be considered part of the + /// barcode region + /// + /// minimum pixel location, horizontally or vertically, to consider + /// + /// maximum pixel location, horizontally or vertically, to consider + /// + /// if true, we're scanning left-right, instead of up-down + /// + /// int[] with start and end of found range, or null if no such range is found + /// (e.g. only white was found) + /// + private int[] blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, bool horizontal) + { + int center = (minDim + maxDim) >> 1; + + // Scan left/up first + int start = center; + while (start >= minDim) + { + if (horizontal ? image[start, fixedDimension] : image[fixedDimension, start]) + { + start--; + } + else + { + int whiteRunStart = start; + do + { + start--; + } + while (start >= minDim && !(horizontal ? image[start, fixedDimension] : image[fixedDimension, start])); + int whiteRunSize = whiteRunStart - start; + if (start < minDim || whiteRunSize > maxWhiteRun) + { + start = whiteRunStart; + break; + } + } + } + start++; + + // Then try right/down + int end = center; + while (end < maxDim) + { + if (horizontal ? image[end, fixedDimension] : image[fixedDimension, end]) + { + end++; + } + else + { + int whiteRunStart = end; + do + { + end++; + } + while (end < maxDim && !(horizontal ? image[end, fixedDimension] : image[fixedDimension, end])); + int whiteRunSize = end - whiteRunStart; + if (end >= maxDim || whiteRunSize > maxWhiteRun) + { + end = whiteRunStart; + break; + } + } + } + end--; + + return end > start ? new int[] { start, end } : null; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/detector/WhiteRectangleDetector.cs b/shadowsocks-csharp/3rd/zxing/common/detector/WhiteRectangleDetector.cs new file mode 100755 index 00000000..9a4d4cd2 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/detector/WhiteRectangleDetector.cs @@ -0,0 +1,433 @@ +/* + * Copyright 2010 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.Detector +{ + /// + /// Detects a candidate barcode-like rectangular region within an image. It + /// starts around the center of the image, increases the size of the candidate + /// region until it finds a white rectangular region. By keeping track of the + /// last black points it encountered, it determines the corners of the barcode. + /// + /// David Olivier + public sealed class WhiteRectangleDetector + { + private const int INIT_SIZE = 10; + private const int CORR = 1; + + private readonly BitMatrix image; + private readonly int height; + private readonly int width; + private readonly int leftInit; + private readonly int rightInit; + private readonly int downInit; + private readonly int upInit; + + /// + /// Creates a WhiteRectangleDetector instance + /// + /// The image. + /// null, if image is too small, otherwise a WhiteRectangleDetector instance + public static WhiteRectangleDetector Create(BitMatrix image) + { + if (image == null) + return null; + + var instance = new WhiteRectangleDetector(image); + + if (instance.upInit < 0 || instance.leftInit < 0 || instance.downInit >= instance.height || instance.rightInit >= instance.width) + { + return null; + } + + return instance; + } + + /// + /// Creates a WhiteRectangleDetector instance + /// + /// The image. + /// Size of the init. + /// The x. + /// The y. + /// + /// null, if image is too small, otherwise a WhiteRectangleDetector instance + /// + public static WhiteRectangleDetector Create(BitMatrix image, int initSize, int x, int y) + { + var instance = new WhiteRectangleDetector(image, initSize, x, y); + + if (instance.upInit < 0 || instance.leftInit < 0 || instance.downInit >= instance.height || instance.rightInit >= instance.width) + { + return null; + } + + return instance; + } + + + /// + /// Initializes a new instance of the class. + /// + /// The image. + /// if image is too small + internal WhiteRectangleDetector(BitMatrix image) + : this(image, INIT_SIZE, image.Width/2, image.Height/2) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The image. + /// Size of the init. + /// The x. + /// The y. + internal WhiteRectangleDetector(BitMatrix image, int initSize, int x, int y) + { + this.image = image; + height = image.Height; + width = image.Width; + int halfsize = initSize / 2; + leftInit = x - halfsize; + rightInit = x + halfsize; + upInit = y - halfsize; + downInit = y + halfsize; + } + + /// + /// Detects a candidate barcode-like rectangular region within an image. It + /// starts around the center of the image, increases the size of the candidate + /// region until it finds a white rectangular region. + /// + /// [] describing the corners of the rectangular + /// region. The first and last points are opposed on the diagonal, as + /// are the second and third. The first point will be the topmost + /// point and the last, the bottommost. The second point will be + /// leftmost and the third, the rightmost + public ResultPoint[] detect() + { + int left = leftInit; + int right = rightInit; + int up = upInit; + int down = downInit; + bool sizeExceeded = false; + bool aBlackPointFoundOnBorder = true; + bool atLeastOneBlackPointFoundOnBorder = false; + + bool atLeastOneBlackPointFoundOnRight = false; + bool atLeastOneBlackPointFoundOnBottom = false; + bool atLeastOneBlackPointFoundOnLeft = false; + bool atLeastOneBlackPointFoundOnTop = false; + + while (aBlackPointFoundOnBorder) + { + + aBlackPointFoundOnBorder = false; + + // ..... + // . | + // ..... + bool rightBorderNotWhite = true; + while ((rightBorderNotWhite || !atLeastOneBlackPointFoundOnRight) && right < width) + { + rightBorderNotWhite = containsBlackPoint(up, down, right, false); + if (rightBorderNotWhite) + { + right++; + aBlackPointFoundOnBorder = true; + atLeastOneBlackPointFoundOnRight = true; + } + else if (!atLeastOneBlackPointFoundOnRight) + { + right++; + } + } + + if (right >= width) + { + sizeExceeded = true; + break; + } + + // ..... + // . . + // .___. + bool bottomBorderNotWhite = true; + while ((bottomBorderNotWhite || !atLeastOneBlackPointFoundOnBottom) && down < height) + { + bottomBorderNotWhite = containsBlackPoint(left, right, down, true); + if (bottomBorderNotWhite) + { + down++; + aBlackPointFoundOnBorder = true; + atLeastOneBlackPointFoundOnBottom = true; + } + else if (!atLeastOneBlackPointFoundOnBottom) + { + down++; + } + } + + if (down >= height) + { + sizeExceeded = true; + break; + } + + // ..... + // | . + // ..... + bool leftBorderNotWhite = true; + while ((leftBorderNotWhite || !atLeastOneBlackPointFoundOnLeft) && left >= 0) + { + leftBorderNotWhite = containsBlackPoint(up, down, left, false); + if (leftBorderNotWhite) + { + left--; + aBlackPointFoundOnBorder = true; + atLeastOneBlackPointFoundOnLeft = true; + } + else if (!atLeastOneBlackPointFoundOnLeft) + { + left--; + } + } + + if (left < 0) + { + sizeExceeded = true; + break; + } + + // .___. + // . . + // ..... + bool topBorderNotWhite = true; + while ((topBorderNotWhite || !atLeastOneBlackPointFoundOnTop) && up >= 0) + { + topBorderNotWhite = containsBlackPoint(left, right, up, true); + if (topBorderNotWhite) + { + up--; + aBlackPointFoundOnBorder = true; + atLeastOneBlackPointFoundOnTop = true; + } + else if (!atLeastOneBlackPointFoundOnTop) + { + up--; + } + } + + if (up < 0) + { + sizeExceeded = true; + break; + } + + if (aBlackPointFoundOnBorder) + { + atLeastOneBlackPointFoundOnBorder = true; + } + + } + + if (!sizeExceeded && atLeastOneBlackPointFoundOnBorder) + { + + int maxSize = right - left; + + ResultPoint z = null; + for (int i = 1; i < maxSize; i++) + { + z = getBlackPointOnSegment(left, down - i, left + i, down); + if (z != null) + { + break; + } + } + + if (z == null) + { + return null; + } + + ResultPoint t = null; + //go down right + for (int i = 1; i < maxSize; i++) + { + t = getBlackPointOnSegment(left, up + i, left + i, up); + if (t != null) + { + break; + } + } + + if (t == null) + { + return null; + } + + ResultPoint x = null; + //go down left + for (int i = 1; i < maxSize; i++) + { + x = getBlackPointOnSegment(right, up + i, right - i, up); + if (x != null) + { + break; + } + } + + if (x == null) + { + return null; + } + + ResultPoint y = null; + //go up left + for (int i = 1; i < maxSize; i++) + { + y = getBlackPointOnSegment(right, down - i, right - i, down); + if (y != null) + { + break; + } + } + + if (y == null) + { + return null; + } + + return centerEdges(y, z, x, t); + + } + else + { + return null; + } + } + + private ResultPoint getBlackPointOnSegment(float aX, float aY, float bX, float bY) + { + int dist = MathUtils.round(MathUtils.distance(aX, aY, bX, bY)); + float xStep = (bX - aX) / dist; + float yStep = (bY - aY) / dist; + + for (int i = 0; i < dist; i++) + { + int x = MathUtils.round(aX + i * xStep); + int y = MathUtils.round(aY + i * yStep); + if (image[x, y]) + { + return new ResultPoint(x, y); + } + } + return null; + } + + /// + /// recenters the points of a constant distance towards the center + /// + /// bottom most point + /// left most point + /// right most point + /// top most point + /// [] describing the corners of the rectangular + /// region. The first and last points are opposed on the diagonal, as + /// are the second and third. The first point will be the topmost + /// point and the last, the bottommost. The second point will be + /// leftmost and the third, the rightmost + private ResultPoint[] centerEdges(ResultPoint y, ResultPoint z, + ResultPoint x, ResultPoint t) + { + // + // t t + // z x + // x OR z + // y y + // + + float yi = y.X; + float yj = y.Y; + float zi = z.X; + float zj = z.Y; + float xi = x.X; + float xj = x.Y; + float ti = t.X; + float tj = t.Y; + + if (yi < width / 2.0f) + { + return new[] + { + new ResultPoint(ti - CORR, tj + CORR), + new ResultPoint(zi + CORR, zj + CORR), + new ResultPoint(xi - CORR, xj - CORR), + new ResultPoint(yi + CORR, yj - CORR) + }; + } + else + { + return new[] + { + new ResultPoint(ti + CORR, tj + CORR), + new ResultPoint(zi + CORR, zj - CORR), + new ResultPoint(xi - CORR, xj + CORR), + new ResultPoint(yi - CORR, yj - CORR) + }; + } + } + + /// + /// Determines whether a segment contains a black point + /// + /// min value of the scanned coordinate + /// max value of the scanned coordinate + /// value of fixed coordinate + /// set to true if scan must be horizontal, false if vertical + /// + /// true if a black point has been found, else false. + /// + private bool containsBlackPoint(int a, int b, int @fixed, bool horizontal) + { + if (horizontal) + { + for (int x = a; x <= b; x++) + { + if (image[x, @fixed]) + { + return true; + } + } + } + else + { + for (int y = a; y <= b; y++) + { + if (image[@fixed, y]) + { + return true; + } + } + } + return false; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/GenericGF.cs b/shadowsocks-csharp/3rd/zxing/common/reedsolomon/GenericGF.cs similarity index 68% rename from shadowsocks-csharp/3rd/zxing/GenericGF.cs rename to shadowsocks-csharp/3rd/zxing/common/reedsolomon/GenericGF.cs index 08f8ca0e..276dc999 100755 --- a/shadowsocks-csharp/3rd/zxing/GenericGF.cs +++ b/shadowsocks-csharp/3rd/zxing/common/reedsolomon/GenericGF.cs @@ -28,7 +28,16 @@ namespace ZXing.Common.ReedSolomon /// Sean Owen public sealed class GenericGF { + public static GenericGF AZTEC_DATA_12 = new GenericGF(0x1069, 4096, 1); // x^12 + x^6 + x^5 + x^3 + 1 + public static GenericGF AZTEC_DATA_10 = new GenericGF(0x409, 1024, 1); // x^10 + x^3 + 1 + public static GenericGF AZTEC_DATA_6 = new GenericGF(0x43, 64, 1); // x^6 + x + 1 + public static GenericGF AZTEC_PARAM = new GenericGF(0x13, 16, 1); // x^4 + x + 1 public static GenericGF QR_CODE_FIELD_256 = new GenericGF(0x011D, 256, 0); // x^8 + x^4 + x^3 + x^2 + 1 + public static GenericGF DATA_MATRIX_FIELD_256 = new GenericGF(0x012D, 256, 1); // x^8 + x^5 + x^3 + x^2 + 1 + public static GenericGF AZTEC_DATA_8 = DATA_MATRIX_FIELD_256; + public static GenericGF MAXICODE_FIELD_64 = AZTEC_DATA_6; + + private const int INITIALIZATION_THRESHOLD = 0; private int[] expTable; private int[] logTable; @@ -37,6 +46,7 @@ namespace ZXing.Common.ReedSolomon private readonly int size; private readonly int primitive; private readonly int generatorBase; + private bool initialized = false; /// /// Create a representation of GF(size) using the given primitive polynomial. @@ -54,6 +64,14 @@ namespace ZXing.Common.ReedSolomon this.size = size; this.generatorBase = genBase; + if (size <= INITIALIZATION_THRESHOLD) + { + initialize(); + } + } + + private void initialize() + { expTable = new int[size]; logTable = new int[size]; int x = 1; @@ -74,16 +92,35 @@ namespace ZXing.Common.ReedSolomon // logTable[0] == 0 but this should never be used zero = new GenericGFPoly(this, new int[] { 0 }); one = new GenericGFPoly(this, new int[] { 1 }); + initialized = true; + } + + private void checkInit() + { + if (!initialized) + { + initialize(); + } } internal GenericGFPoly Zero { get { + checkInit(); return zero; } } + internal GenericGFPoly One + { + get + { + checkInit(); + return one; + } + } + /// /// Builds the monomial. /// @@ -92,6 +129,8 @@ namespace ZXing.Common.ReedSolomon /// the monomial representing coefficient * x^degree internal GenericGFPoly buildMonomial(int degree, int coefficient) { + checkInit(); + if (degree < 0) { throw new ArgumentException(); @@ -120,9 +159,26 @@ namespace ZXing.Common.ReedSolomon /// 2 to the power of a in GF(size) internal int exp(int a) { + checkInit(); + return expTable[a]; } + /// + /// Logs the specified a. + /// + /// A. + /// base 2 log of a in GF(size) + internal int log(int a) + { + checkInit(); + + if (a == 0) + { + throw new ArgumentException(); + } + return logTable[a]; + } /// /// Inverses the specified a. @@ -130,6 +186,8 @@ namespace ZXing.Common.ReedSolomon /// multiplicative inverse of a internal int inverse(int a) { + checkInit(); + if (a == 0) { throw new ArithmeticException(); @@ -145,6 +203,8 @@ namespace ZXing.Common.ReedSolomon /// product of a and b in GF(size) internal int multiply(int a, int b) { + checkInit(); + if (a == 0 || b == 0) { return 0; @@ -153,11 +213,30 @@ namespace ZXing.Common.ReedSolomon } /// + /// Gets the size. + /// + public int Size + { + get { return size; } + } + + /// /// Gets the generator base. /// public int GeneratorBase { get { return generatorBase; } } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + override public String ToString() + { + return "GF(0x" + primitive.ToString("X") + ',' + size + ')'; + } } } \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/GenericGFPoly.cs b/shadowsocks-csharp/3rd/zxing/common/reedsolomon/GenericGFPoly.cs similarity index 69% rename from shadowsocks-csharp/3rd/zxing/GenericGFPoly.cs rename to shadowsocks-csharp/3rd/zxing/common/reedsolomon/GenericGFPoly.cs index eb966579..427fe11d 100755 --- a/shadowsocks-csharp/3rd/zxing/GenericGFPoly.cs +++ b/shadowsocks-csharp/3rd/zxing/common/reedsolomon/GenericGFPoly.cs @@ -59,7 +59,7 @@ namespace ZXing.Common.ReedSolomon } if (firstNonZero == coefficientsLength) { - this.coefficients = new int[]{0}; + this.coefficients = field.Zero.coefficients; } else { @@ -112,6 +112,36 @@ namespace ZXing.Common.ReedSolomon return coefficients[coefficients.Length - 1 - degree]; } + /// + /// evaluation of this polynomial at a given point + /// + /// A. + /// evaluation of this polynomial at a given point + 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) { @@ -176,6 +206,24 @@ 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) { @@ -226,5 +274,58 @@ 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(); + } } } \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/reedsolomon/ReedSolomonDecoder.cs b/shadowsocks-csharp/3rd/zxing/common/reedsolomon/ReedSolomonDecoder.cs new file mode 100755 index 00000000..1030a56d --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/reedsolomon/ReedSolomonDecoder.cs @@ -0,0 +1,227 @@ +/* +* 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. +*/ + +namespace ZXing.Common.ReedSolomon +{ + ///

Implements Reed-Solomon decoding, as the name implies.

+ /// + ///

The algorithm will not be explained here, but the following references were helpful + /// in creating this implementation:

+ /// + /// + /// + ///

Much credit is due to William Rucklidge since portions of this code are an indirect + /// port of his C++ Reed-Solomon implementation.

+ /// + ///
+ /// Sean Owen + /// William Rucklidge + /// sanfordsquires + public sealed class ReedSolomonDecoder + { + private readonly GenericGF field; + + public ReedSolomonDecoder(GenericGF field) + { + this.field = field; + } + + /// + ///

Decodes given set of received codewords, which include both data and error-correction + /// codewords. Really, this means it uses Reed-Solomon to detect and correct errors, in-place, + /// in the input.

+ ///
+ /// data and error-correction codewords + /// number of error-correction codewords available + /// false: decoding fails + public bool decode(int[] received, int twoS) + { + var poly = new GenericGFPoly(field, received); + var syndromeCoefficients = new int[twoS]; + var noError = true; + for (var i = 0; i < twoS; i++) + { + var eval = poly.evaluateAt(field.exp(i + field.GeneratorBase)); + syndromeCoefficients[syndromeCoefficients.Length - 1 - i] = eval; + if (eval != 0) + { + noError = false; + } + } + if (noError) + { + return true; + } + var syndrome = new GenericGFPoly(field, syndromeCoefficients); + + var sigmaOmega = runEuclideanAlgorithm(field.buildMonomial(twoS, 1), syndrome, twoS); + if (sigmaOmega == null) + return false; + + var sigma = sigmaOmega[0]; + var errorLocations = findErrorLocations(sigma); + if (errorLocations == null) + return false; + + var omega = sigmaOmega[1]; + var errorMagnitudes = findErrorMagnitudes(omega, errorLocations); + for (var i = 0; i < errorLocations.Length; i++) + { + var position = received.Length - 1 - field.log(errorLocations[i]); + if (position < 0) + { + // throw new ReedSolomonException("Bad error location"); + return false; + } + received[position] = GenericGF.addOrSubtract(received[position], errorMagnitudes[i]); + } + + return true; + } + + internal GenericGFPoly[] runEuclideanAlgorithm(GenericGFPoly a, GenericGFPoly b, int R) + { + // Assume a's degree is >= b's + if (a.Degree < b.Degree) + { + GenericGFPoly temp = a; + a = b; + b = temp; + } + + GenericGFPoly rLast = a; + GenericGFPoly r = b; + GenericGFPoly tLast = field.Zero; + GenericGFPoly t = field.One; + + // Run Euclidean algorithm until r's degree is less than R/2 + while (r.Degree >= R / 2) + { + GenericGFPoly rLastLast = rLast; + GenericGFPoly tLastLast = tLast; + rLast = r; + tLast = t; + + // Divide rLastLast by rLast, with quotient in q and remainder in r + if (rLast.isZero) + { + // Oops, Euclidean algorithm already terminated? + // throw new ReedSolomonException("r_{i-1} was zero"); + return null; + } + r = rLastLast; + GenericGFPoly q = field.Zero; + int denominatorLeadingTerm = rLast.getCoefficient(rLast.Degree); + int dltInverse = field.inverse(denominatorLeadingTerm); + while (r.Degree >= rLast.Degree && !r.isZero) + { + int degreeDiff = r.Degree - rLast.Degree; + int scale = field.multiply(r.getCoefficient(r.Degree), dltInverse); + q = q.addOrSubtract(field.buildMonomial(degreeDiff, scale)); + r = r.addOrSubtract(rLast.multiplyByMonomial(degreeDiff, scale)); + } + + t = q.multiply(tLast).addOrSubtract(tLastLast); + + if (r.Degree >= rLast.Degree) + { + // throw new IllegalStateException("Division algorithm failed to reduce polynomial?"); + return null; + } + } + + int sigmaTildeAtZero = t.getCoefficient(0); + if (sigmaTildeAtZero == 0) + { + // throw new ReedSolomonException("sigmaTilde(0) was zero"); + return null; + } + + int inverse = field.inverse(sigmaTildeAtZero); + GenericGFPoly sigma = t.multiply(inverse); + GenericGFPoly omega = r.multiply(inverse); + return new GenericGFPoly[] { sigma, omega }; + } + + private int[] findErrorLocations(GenericGFPoly errorLocator) + { + // This is a direct application of Chien's search + int numErrors = errorLocator.Degree; + if (numErrors == 1) + { + // shortcut + return new int[] { errorLocator.getCoefficient(1) }; + } + int[] result = new int[numErrors]; + int e = 0; + for (int i = 1; i < field.Size && e < numErrors; i++) + { + if (errorLocator.evaluateAt(i) == 0) + { + result[e] = field.inverse(i); + e++; + } + } + if (e != numErrors) + { + // throw new ReedSolomonException("Error locator degree does not match number of roots"); + return null; + } + return result; + } + + private int[] findErrorMagnitudes(GenericGFPoly errorEvaluator, int[] errorLocations) + { + // This is directly applying Forney's Formula + int s = errorLocations.Length; + int[] result = new int[s]; + for (int i = 0; i < s; i++) + { + int xiInverse = field.inverse(errorLocations[i]); + int denominator = 1; + for (int j = 0; j < s; j++) + { + if (i != j) + { + //denominator = field.multiply(denominator, + // GenericGF.addOrSubtract(1, field.multiply(errorLocations[j], xiInverse))); + // Above should work but fails on some Apple and Linux JDKs due to a Hotspot bug. + // Below is a funny-looking workaround from Steven Parkes + int term = field.multiply(errorLocations[j], xiInverse); + int termPlus1 = (term & 0x1) == 0 ? term | 1 : term & ~1; + denominator = field.multiply(denominator, termPlus1); + + // removed in java version, not sure if this is right + // denominator = field.multiply(denominator, GenericGF.addOrSubtract(1, field.multiply(errorLocations[j], xiInverse))); + } + } + result[i] = field.multiply(errorEvaluator.evaluateAt(xiInverse), field.inverse(denominator)); + if (field.GeneratorBase != 0) + { + result[i] = field.multiply(result[i], xiInverse); + } + } + return result; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/ReedSolomonEncoder.cs b/shadowsocks-csharp/3rd/zxing/common/reedsolomon/ReedSolomonEncoder.cs similarity index 100% rename from shadowsocks-csharp/3rd/zxing/ReedSolomonEncoder.cs rename to shadowsocks-csharp/3rd/zxing/common/reedsolomon/ReedSolomonEncoder.cs diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/BitMatrixParser.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/BitMatrixParser.cs new file mode 100755 index 00000000..6a328faa --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/BitMatrixParser.cs @@ -0,0 +1,281 @@ +/* +* 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 ZXing.Common; + +namespace ZXing.QrCode.Internal +{ + /// Sean Owen + sealed class BitMatrixParser + { + private readonly BitMatrix bitMatrix; + private Version parsedVersion; + private FormatInformation parsedFormatInfo; + private bool mirrored; + + /// {@link BitMatrix} to parse + /// ReaderException if dimension is not >= 21 and 1 mod 4 + internal static BitMatrixParser createBitMatrixParser(BitMatrix bitMatrix) + { + int dimension = bitMatrix.Height; + if (dimension < 21 || (dimension & 0x03) != 1) + { + return null; + } + return new BitMatrixParser(bitMatrix); + } + + private BitMatrixParser(BitMatrix bitMatrix) + { + // Should only be called from createBitMatrixParser with the important checks before + this.bitMatrix = bitMatrix; + } + + ///

Reads format information from one of its two locations within the QR Code.

+ /// + ///
+ /// {@link FormatInformation} encapsulating the QR Code's format info + /// + /// ReaderException if both format information locations cannot be parsed as + /// the valid encoding of format information + /// + internal FormatInformation readFormatInformation() + { + if (parsedFormatInfo != null) + { + return parsedFormatInfo; + } + + // Read top-left format info bits + int formatInfoBits1 = 0; + for (int i = 0; i < 6; i++) + { + formatInfoBits1 = copyBit(i, 8, formatInfoBits1); + } + // .. and skip a bit in the timing pattern ... + formatInfoBits1 = copyBit(7, 8, formatInfoBits1); + formatInfoBits1 = copyBit(8, 8, formatInfoBits1); + formatInfoBits1 = copyBit(8, 7, formatInfoBits1); + // .. and skip a bit in the timing pattern ... + for (int j = 5; j >= 0; j--) + { + formatInfoBits1 = copyBit(8, j, formatInfoBits1); + } + // Read the top-right/bottom-left pattern too + int dimension = bitMatrix.Height; + int formatInfoBits2 = 0; + int jMin = dimension - 7; + for (int j = dimension - 1; j >= jMin; j--) + { + formatInfoBits2 = copyBit(8, j, formatInfoBits2); + } + for (int i = dimension - 8; i < dimension; i++) + { + formatInfoBits2 = copyBit(i, 8, formatInfoBits2); + } + + parsedFormatInfo = FormatInformation.decodeFormatInformation(formatInfoBits1, formatInfoBits2); + if (parsedFormatInfo != null) + { + return parsedFormatInfo; + } + return null; + } + + ///

Reads version information from one of its two locations within the QR Code.

+ /// + ///
+ /// {@link Version} encapsulating the QR Code's version + /// + /// ReaderException if both version information locations cannot be parsed as + /// the valid encoding of version information + /// + internal Version readVersion() + { + if (parsedVersion != null) + { + return parsedVersion; + } + + int dimension = bitMatrix.Height; + + int provisionalVersion = (dimension - 17) >> 2; + if (provisionalVersion <= 6) + { + return Version.getVersionForNumber(provisionalVersion); + } + + // Read top-right version info: 3 wide by 6 tall + int versionBits = 0; + int ijMin = dimension - 11; + for (int j = 5; j >= 0; j--) + { + for (int i = dimension - 9; i >= ijMin; i--) + { + versionBits = copyBit(i, j, versionBits); + } + } + + parsedVersion = Version.decodeVersionInformation(versionBits); + if (parsedVersion != null && parsedVersion.DimensionForVersion == dimension) + { + return parsedVersion; + } + + // Hmm, failed. Try bottom left: 6 wide by 3 tall + versionBits = 0; + for (int i = 5; i >= 0; i--) + { + for (int j = dimension - 9; j >= ijMin; j--) + { + versionBits = copyBit(i, j, versionBits); + } + } + + parsedVersion = Version.decodeVersionInformation(versionBits); + if (parsedVersion != null && parsedVersion.DimensionForVersion == dimension) + { + return parsedVersion; + } + return null; + } + + private int copyBit(int i, int j, int versionBits) + { + bool bit = mirrored ? bitMatrix[j, i] : bitMatrix[i, j]; + return bit ? (versionBits << 1) | 0x1 : versionBits << 1; + } + + ///

Reads the bits in the {@link BitMatrix} representing the finder pattern in the + /// correct order in order to reconstruct the codewords bytes contained within the + /// QR Code.

+ /// + ///
+ /// bytes encoded within the QR Code + /// + /// ReaderException if the exact number of bytes expected is not read + internal byte[] readCodewords() + { + FormatInformation formatInfo = readFormatInformation(); + if (formatInfo == null) + return null; + Version version = readVersion(); + if (version == null) + return null; + + // Get the data mask for the format used in this QR Code. This will exclude + // some bits from reading as we wind through the bit matrix. + DataMask dataMask = DataMask.forReference(formatInfo.DataMask); + int dimension = bitMatrix.Height; + dataMask.unmaskBitMatrix(bitMatrix, dimension); + + BitMatrix functionPattern = version.buildFunctionPattern(); + + bool readingUp = true; + byte[] result = new byte[version.TotalCodewords]; + int resultOffset = 0; + int currentByte = 0; + int bitsRead = 0; + // Read columns in pairs, from right to left + for (int j = dimension - 1; j > 0; j -= 2) + { + if (j == 6) + { + // Skip whole column with vertical alignment pattern; + // saves time and makes the other code proceed more cleanly + j--; + } + // Read alternatingly from bottom to top then top to bottom + for (int count = 0; count < dimension; count++) + { + int i = readingUp ? dimension - 1 - count : count; + for (int col = 0; col < 2; col++) + { + // Ignore bits covered by the function pattern + if (!functionPattern[j - col, i]) + { + // Read a bit + bitsRead++; + currentByte <<= 1; + if (bitMatrix[j - col, i]) + { + currentByte |= 1; + } + // If we've made a whole byte, save it off + if (bitsRead == 8) + { + result[resultOffset++] = (byte)currentByte; + bitsRead = 0; + currentByte = 0; + } + } + } + } + readingUp ^= true; // readingUp = !readingUp; // switch directions + } + if (resultOffset != version.TotalCodewords) + { + return null; + } + return result; + } + + /** + * Revert the mask removal done while reading the code words. The bit matrix should revert to its original state. + */ + internal void remask() + { + if (parsedFormatInfo == null) + { + return; // We have no format information, and have no data mask + } + DataMask dataMask = DataMask.forReference(parsedFormatInfo.DataMask); + int dimension = bitMatrix.Height; + dataMask.unmaskBitMatrix(bitMatrix, dimension); + } + + /** + * Prepare the parser for a mirrored operation. + * This flag has effect only on the {@link #readFormatInformation()} and the + * {@link #readVersion()}. Before proceeding with {@link #readCodewords()} the + * {@link #mirror()} method should be called. + * + * @param mirror Whether to read version and format information mirrored. + */ + internal void setMirror(bool mirror) + { + parsedVersion = null; + parsedFormatInfo = null; + mirrored = mirror; + } + + /** Mirror the bit matrix in order to attempt a second reading. */ + internal void mirror() + { + for (int x = 0; x < bitMatrix.Width; x++) + { + for (int y = x + 1; y < bitMatrix.Height; y++) + { + if (bitMatrix[x, y] != bitMatrix[y, x]) + { + bitMatrix.flip(y, x); + bitMatrix.flip(x, y); + } + } + } + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DataBlock.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DataBlock.cs new file mode 100755 index 00000000..5860fe6a --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DataBlock.cs @@ -0,0 +1,146 @@ +/* +* 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. +*/ + +namespace ZXing.QrCode.Internal +{ + ///

Encapsulates a block of data within a QR Code. QR Codes may split their data into + /// multiple blocks, each of which is a unit of data and error-correction codewords. Each + /// is represented by an instance of this class.

+ /// + ///
+ /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + internal sealed class DataBlock + { + private readonly int numDataCodewords; + private readonly byte[] codewords; + + private DataBlock(int numDataCodewords, byte[] codewords) + { + this.numDataCodewords = numDataCodewords; + this.codewords = codewords; + } + + ///

When QR Codes use multiple data blocks, they are actually interleaved. + /// That is, the first byte of data block 1 to n is written, then the second bytes, and so on. This + /// method will separate the data into original blocks.

+ /// + ///
+ /// bytes as read directly from the QR Code + /// + /// version of the QR Code + /// + /// error-correction level of the QR Code + /// + /// {@link DataBlock}s containing original bytes, "de-interleaved" from representation in the + /// QR Code + /// + internal static DataBlock[] getDataBlocks(byte[] rawCodewords, Version version, ErrorCorrectionLevel ecLevel) + { + + if (rawCodewords.Length != version.TotalCodewords) + { + throw new System.ArgumentException(); + } + + // Figure out the number and size of data blocks used by this version and + // error correction level + Version.ECBlocks ecBlocks = version.getECBlocksForLevel(ecLevel); + + // First count the total number of data blocks + int totalBlocks = 0; + Version.ECB[] ecBlockArray = ecBlocks.getECBlocks(); + foreach (var ecBlock in ecBlockArray) + { + totalBlocks += ecBlock.Count; + } + + // Now establish DataBlocks of the appropriate size and number of data codewords + DataBlock[] result = new DataBlock[totalBlocks]; + int numResultBlocks = 0; + foreach (var ecBlock in ecBlockArray) + { + for (int i = 0; i < ecBlock.Count; i++) + { + int numDataCodewords = ecBlock.DataCodewords; + int numBlockCodewords = ecBlocks.ECCodewordsPerBlock + numDataCodewords; + result[numResultBlocks++] = new DataBlock(numDataCodewords, new byte[numBlockCodewords]); + } + } + + // All blocks have the same amount of data, except that the last n + // (where n may be 0) have 1 more byte. Figure out where these start. + int shorterBlocksTotalCodewords = result[0].codewords.Length; + int longerBlocksStartAt = result.Length - 1; + while (longerBlocksStartAt >= 0) + { + int numCodewords = result[longerBlocksStartAt].codewords.Length; + if (numCodewords == shorterBlocksTotalCodewords) + { + break; + } + longerBlocksStartAt--; + } + longerBlocksStartAt++; + + int shorterBlocksNumDataCodewords = shorterBlocksTotalCodewords - ecBlocks.ECCodewordsPerBlock; + // The last elements of result may be 1 element longer; + // first fill out as many elements as all of them have + int rawCodewordsOffset = 0; + for (int i = 0; i < shorterBlocksNumDataCodewords; i++) + { + for (int j = 0; j < numResultBlocks; j++) + { + result[j].codewords[i] = rawCodewords[rawCodewordsOffset++]; + } + } + // Fill out the last data block in the longer ones + for (int j = longerBlocksStartAt; j < numResultBlocks; j++) + { + result[j].codewords[shorterBlocksNumDataCodewords] = rawCodewords[rawCodewordsOffset++]; + } + // Now add in error correction blocks + int max = result[0].codewords.Length; + for (int i = shorterBlocksNumDataCodewords; i < max; i++) + { + for (int j = 0; j < numResultBlocks; j++) + { + int iOffset = j < longerBlocksStartAt ? i : i + 1; + result[j].codewords[iOffset] = rawCodewords[rawCodewordsOffset++]; + } + } + return result; + } + + internal int NumDataCodewords + { + get + { + return numDataCodewords; + } + } + + internal byte[] Codewords + { + get + { + return codewords; + } + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DataMask.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DataMask.cs new file mode 100755 index 00000000..a6ac93e6 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DataMask.cs @@ -0,0 +1,165 @@ +/* +* 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 ZXing.Common; + +namespace ZXing.QrCode.Internal +{ + ///

Encapsulates data masks for the data bits in a QR code, per ISO 18004:2006 6.8. Implementations + /// of this class can un-mask a raw BitMatrix. For simplicity, they will unmask the entire BitMatrix, + /// including areas used for finder patterns, timing patterns, etc. These areas should be unused + /// after the point they are unmasked anyway.

+ /// + ///

Note that the diagram in section 6.8.1 is misleading since it indicates that i is column position + /// and j is row position. In fact, as the text says, i is row position and j is column position.

+ /// + ///
+ /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + abstract class DataMask + { + /// See ISO 18004:2006 6.8.1 + private static readonly DataMask[] DATA_MASKS = new DataMask[] + { + new DataMask000(), + new DataMask001(), + new DataMask010(), + new DataMask011(), + new DataMask100(), + new DataMask101(), + new DataMask110(), + new DataMask111() + }; + + private DataMask() + { + } + + ///

Implementations of this method reverse the data masking process applied to a QR Code and + /// make its bits ready to read.

+ /// + ///
+ /// representation of QR Code bits + /// + /// dimension of QR Code, represented by bits, being unmasked + /// + internal void unmaskBitMatrix(BitMatrix bits, int dimension) + { + for (int i = 0; i < dimension; i++) + { + for (int j = 0; j < dimension; j++) + { + if (isMasked(i, j)) + { + bits.flip(j, i); + } + } + } + } + + internal abstract bool isMasked(int i, int j); + + /// a value between 0 and 7 indicating one of the eight possible + /// data mask patterns a QR Code may use + /// + /// {@link DataMask} encapsulating the data mask pattern + /// + internal static DataMask forReference(int reference) + { + if (reference < 0 || reference > 7) + { + throw new System.ArgumentException(); + } + return DATA_MASKS[reference]; + } + + /// 000: mask bits for which (x + y) mod 2 == 0 + private sealed class DataMask000 : DataMask + { + internal override bool isMasked(int i, int j) + { + return ((i + j) & 0x01) == 0; + } + } + + /// 001: mask bits for which x mod 2 == 0 + private sealed class DataMask001 : DataMask + { + internal override bool isMasked(int i, int j) + { + return (i & 0x01) == 0; + } + } + + /// 010: mask bits for which y mod 3 == 0 + private sealed class DataMask010 : DataMask + { + internal override bool isMasked(int i, int j) + { + return j % 3 == 0; + } + } + + /// 011: mask bits for which (x + y) mod 3 == 0 + private sealed class DataMask011 : DataMask + { + internal override bool isMasked(int i, int j) + { + return (i + j) % 3 == 0; + } + } + + /// 100: mask bits for which (x/2 + y/3) mod 2 == 0 + private sealed class DataMask100 : DataMask + { + internal override bool isMasked(int i, int j) + { + return ((((int)((uint)i >> 1)) + (j / 3)) & 0x01) == 0; + } + } + + /// 101: mask bits for which xy mod 2 + xy mod 3 == 0 + private sealed class DataMask101 : DataMask + { + internal override bool isMasked(int i, int j) + { + int temp = i * j; + return (temp & 0x01) + (temp % 3) == 0; + } + } + + /// 110: mask bits for which (xy mod 2 + xy mod 3) mod 2 == 0 + private sealed class DataMask110 : DataMask + { + internal override bool isMasked(int i, int j) + { + int temp = i * j; + return (((temp & 0x01) + (temp % 3)) & 0x01) == 0; + } + } + + /// 111: mask bits for which ((x+y)mod 2 + xy mod 3) mod 2 == 0 + private sealed class DataMask111 : DataMask + { + internal override bool isMasked(int i, int j) + { + return ((((i + j) & 0x01) + ((i * j) % 3)) & 0x01) == 0; + } + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs new file mode 100755 index 00000000..cb59141b --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs @@ -0,0 +1,293 @@ +/* +* 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; +using System.Collections.Generic; +using System.Text; + +using ZXing.Common; + +namespace ZXing.QrCode.Internal +{ + ///

QR Codes can encode text as bits in one of several modes, and can use multiple modes + /// in one QR Code. This class decodes the bits back into text.

+ /// + ///

See ISO 18004:2006, 6.4.3 - 6.4.7

+ /// Sean Owen + ///
+ internal static class DecodedBitStreamParser + { + /// + /// See ISO 18004:2006, 6.4.4 Table 5 + /// + private static readonly char[] ALPHANUMERIC_CHARS = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', + 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', + 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + ' ', '$', '%', '*', '+', '-', '.', '/', ':' + }; + private const int GB2312_SUBSET = 1; + + internal static DecoderResult decode(byte[] bytes, + Version version, + ErrorCorrectionLevel ecLevel, + IDictionary hints) + { + var bits = new BitSource(bytes); + var result = new StringBuilder(50); + var byteSegments = new List(1); + var symbolSequence = -1; + var parityData = -1; + + try + { + //CharacterSetECI currentCharacterSetECI = null; + bool fc1InEffect = false; + Mode mode; + do + { + // While still another segment to read... + if (bits.available() < 4) + { + // OK, assume we're done. Really, a TERMINATOR mode should have been recorded here + mode = Mode.TERMINATOR; + } + else + { + try + { + mode = Mode.forBits(bits.readBits(4)); // mode is encoded by 4 bits + } + catch (ArgumentException) + { + return null; + } + } + if (mode != Mode.TERMINATOR) + { + if (mode == Mode.FNC1_FIRST_POSITION || mode == Mode.FNC1_SECOND_POSITION) + { + // We do little with FNC1 except alter the parsed result a bit according to the spec + fc1InEffect = true; + } + else if (mode == Mode.STRUCTURED_APPEND) + { + if (bits.available() < 16) + { + return null; + } + // not really supported; but sequence number and parity is added later to the result metadata + // Read next 8 bits (symbol sequence #) and 8 bits (parity data), then continue + symbolSequence = bits.readBits(8); + parityData = bits.readBits(8); + } + else + { + // First handle Hanzi mode which does not start with character count + if (mode == Mode.HANZI) + { + //chinese mode contains a sub set indicator right after mode indicator + //int subset = bits.readBits(4); + //int countHanzi = bits.readBits(mode.getCharacterCountBits(version)); + } + else + { + // "Normal" QR code modes: + // How many characters will follow, encoded in this mode? + int count = bits.readBits(mode.getCharacterCountBits(version)); + if (mode == Mode.NUMERIC) + { + if (!decodeNumericSegment(bits, result, count)) + return null; + } + else if (mode == Mode.ALPHANUMERIC) + { + if (!decodeAlphanumericSegment(bits, result, count, fc1InEffect)) + return null; + } + else + { + return null; + } + } + } + } + } while (mode != Mode.TERMINATOR); + } + catch (ArgumentException) + { + // from readBits() calls + return null; + } + +#if WindowsCE + var resultString = result.ToString().Replace("\n", "\r\n"); +#else + var resultString = result.ToString().Replace("\r\n", "\n").Replace("\n", Environment.NewLine); +#endif + return new DecoderResult(bytes, + resultString, + byteSegments.Count == 0 ? null : byteSegments, + ecLevel == null ? null : ecLevel.ToString(), + symbolSequence, parityData); + } + + + + + private static char toAlphaNumericChar(int value) + { + if (value >= ALPHANUMERIC_CHARS.Length) + { + //throw FormatException.Instance; + } + return ALPHANUMERIC_CHARS[value]; + } + + private static bool decodeAlphanumericSegment(BitSource bits, + StringBuilder result, + int count, + bool fc1InEffect) + { + // Read two characters at a time + int start = result.Length; + while (count > 1) + { + if (bits.available() < 11) + { + return false; + } + int nextTwoCharsBits = bits.readBits(11); + result.Append(toAlphaNumericChar(nextTwoCharsBits / 45)); + result.Append(toAlphaNumericChar(nextTwoCharsBits % 45)); + count -= 2; + } + if (count == 1) + { + // special case: one character left + if (bits.available() < 6) + { + return false; + } + result.Append(toAlphaNumericChar(bits.readBits(6))); + } + + // See section 6.4.8.1, 6.4.8.2 + if (fc1InEffect) + { + // We need to massage the result a bit if in an FNC1 mode: + for (int i = start; i < result.Length; i++) + { + if (result[i] == '%') + { + if (i < result.Length - 1 && result[i + 1] == '%') + { + // %% is rendered as % + result.Remove(i + 1, 1); + } + else + { + // In alpha mode, % should be converted to FNC1 separator 0x1D + result.Remove(i, 1); + result.Insert(i, new[] { (char)0x1D }); + } + } + } + } + + return true; + } + + private static bool decodeNumericSegment(BitSource bits, + StringBuilder result, + int count) + { + // Read three digits at a time + while (count >= 3) + { + // Each 10 bits encodes three digits + if (bits.available() < 10) + { + return false; + } + int threeDigitsBits = bits.readBits(10); + if (threeDigitsBits >= 1000) + { + return false; + } + result.Append(toAlphaNumericChar(threeDigitsBits / 100)); + result.Append(toAlphaNumericChar((threeDigitsBits / 10) % 10)); + result.Append(toAlphaNumericChar(threeDigitsBits % 10)); + + count -= 3; + } + if (count == 2) + { + // Two digits left over to read, encoded in 7 bits + if (bits.available() < 7) + { + return false; + } + int twoDigitsBits = bits.readBits(7); + if (twoDigitsBits >= 100) + { + return false; + } + result.Append(toAlphaNumericChar(twoDigitsBits / 10)); + result.Append(toAlphaNumericChar(twoDigitsBits % 10)); + } + else if (count == 1) + { + // One digit left over to read + if (bits.available() < 4) + { + return false; + } + int digitBits = bits.readBits(4); + if (digitBits >= 10) + { + return false; + } + result.Append(toAlphaNumericChar(digitBits)); + } + + return true; + } + + private static int parseECIValue(BitSource bits) + { + int firstByte = bits.readBits(8); + if ((firstByte & 0x80) == 0) + { + // just one byte + return firstByte & 0x7F; + } + if ((firstByte & 0xC0) == 0x80) + { + // two bytes + int secondByte = bits.readBits(8); + return ((firstByte & 0x3F) << 8) | secondByte; + } + if ((firstByte & 0xE0) == 0xC0) + { + // three bytes + int secondThirdBytes = bits.readBits(16); + return ((firstByte & 0x1F) << 16) | secondThirdBytes; + } + throw new ArgumentException("Bad ECI bits starting with byte " + firstByte); + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/Decoder.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/Decoder.cs new file mode 100755 index 00000000..a5ec8645 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/Decoder.cs @@ -0,0 +1,195 @@ +/* +* 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.Collections.Generic; + +using ZXing.Common; +using ZXing.Common.ReedSolomon; + +namespace ZXing.QrCode.Internal +{ + /// + ///

The main class which implements QR Code decoding -- as opposed to locating and extracting + /// the QR Code from an image.

+ ///
+ /// + /// Sean Owen + /// + public sealed class Decoder + { + private readonly ReedSolomonDecoder rsDecoder; + + /// + /// Initializes a new instance of the class. + /// + public Decoder() + { + rsDecoder = new ReedSolomonDecoder(GenericGF.QR_CODE_FIELD_256); + } + + /// + ///

Convenience method that can decode a QR Code represented as a 2D array of booleans. + /// "true" is taken to mean a black module.

+ ///
+ /// booleans representing white/black QR Code modules + /// The hints. + /// + /// text and bytes encoded within the QR Code + /// + public DecoderResult decode(bool[][] image, IDictionary hints) + { + var dimension = image.Length; + var bits = new BitMatrix(dimension); + for (int i = 0; i < dimension; i++) + { + for (int j = 0; j < dimension; j++) + { + bits[j, i] = image[i][j]; + } + } + return decode(bits, hints); + } + + /// + ///

Decodes a QR Code represented as a {@link BitMatrix}. A 1 or "true" is taken to mean a black module.

+ ///
+ /// booleans representing white/black QR Code modules + /// The hints. + /// + /// text and bytes encoded within the QR Code + /// + public DecoderResult decode(BitMatrix bits, IDictionary hints) + { + // Construct a parser and read version, error-correction level + var parser = BitMatrixParser.createBitMatrixParser(bits); + if (parser == null) + return null; + + var result = decode(parser, hints); + if (result == null) + { + // Revert the bit matrix + parser.remask(); + + // Will be attempting a mirrored reading of the version and format info. + parser.setMirror(true); + + // Preemptively read the version. + var version = parser.readVersion(); + if (version == null) + return null; + + // Preemptively read the format information. + var formatinfo = parser.readFormatInformation(); + if (formatinfo == null) + return null; + + /* + * Since we're here, this means we have successfully detected some kind + * of version and format information when mirrored. This is a good sign, + * that the QR code may be mirrored, and we should try once more with a + * mirrored content. + */ + // Prepare for a mirrored reading. + parser.mirror(); + + result = decode(parser, hints); + + if (result != null) + { + // Success! Notify the caller that the code was mirrored. + result.Other = new QRCodeDecoderMetaData(true); + } + } + + return result; + } + + private DecoderResult decode(BitMatrixParser parser, IDictionary hints) + { + Version version = parser.readVersion(); + if (version == null) + return null; + var formatinfo = parser.readFormatInformation(); + if (formatinfo == null) + return null; + ErrorCorrectionLevel ecLevel = formatinfo.ErrorCorrectionLevel; + + // Read codewords + byte[] codewords = parser.readCodewords(); + if (codewords == null) + return null; + // Separate into data blocks + DataBlock[] dataBlocks = DataBlock.getDataBlocks(codewords, version, ecLevel); + + // Count total number of data bytes + int totalBytes = 0; + foreach (var dataBlock in dataBlocks) + { + totalBytes += dataBlock.NumDataCodewords; + } + byte[] resultBytes = new byte[totalBytes]; + int resultOffset = 0; + + // Error-correct and copy data blocks together into a stream of bytes + foreach (var dataBlock in dataBlocks) + { + byte[] codewordBytes = dataBlock.Codewords; + int numDataCodewords = dataBlock.NumDataCodewords; + if (!correctErrors(codewordBytes, numDataCodewords)) + return null; + for (int i = 0; i < numDataCodewords; i++) + { + resultBytes[resultOffset++] = codewordBytes[i]; + } + } + + // Decode the contents of that stream of bytes + return DecodedBitStreamParser.decode(resultBytes, version, ecLevel, hints); + } + + /// + ///

Given data and error-correction codewords received, possibly corrupted by errors, attempts to + /// correct the errors in-place using Reed-Solomon error correction.

+ ///
+ /// data and error correction codewords + /// number of codewords that are data bytes + /// + private bool correctErrors(byte[] codewordBytes, int numDataCodewords) + { + int numCodewords = codewordBytes.Length; + // First read into an array of ints + int[] codewordsInts = new int[numCodewords]; + for (int i = 0; i < numCodewords; i++) + { + codewordsInts[i] = codewordBytes[i] & 0xFF; + } + int numECCodewords = codewordBytes.Length - numDataCodewords; + + if (!rsDecoder.decode(codewordsInts, numECCodewords)) + 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 < numDataCodewords; i++) + { + codewordBytes[i] = (byte)codewordsInts[i]; + } + + return true; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/ErrorCorrectionLevel.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/ErrorCorrectionLevel.cs similarity index 100% rename from shadowsocks-csharp/3rd/zxing/ErrorCorrectionLevel.cs rename to shadowsocks-csharp/3rd/zxing/qrcode/decoder/ErrorCorrectionLevel.cs diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/FormatInformation.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/FormatInformation.cs new file mode 100755 index 00000000..88b5045e --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/FormatInformation.cs @@ -0,0 +1,197 @@ +/* +* 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 +{ + + ///

Encapsulates a QR Code's format information, including the data mask used and + /// error correction level.

+ /// + ///
+ /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + /// + /// + /// + /// + sealed class FormatInformation + { + private const int FORMAT_INFO_MASK_QR = 0x5412; + + /// See ISO 18004:2006, Annex C, Table C.1 + 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 } + }; + + /// Offset i holds the number of 1 bits in the binary representation of i + 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)]; + } + + /// + /// Decodes the format information. + /// + /// format info indicator, with mask still applied + /// The masked format info2. + /// + /// information about the format it specifies, or null + /// if doesn't seem to match any known pattern + /// + 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; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/Mode.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/Mode.cs similarity index 55% rename from shadowsocks-csharp/3rd/zxing/Mode.cs rename to shadowsocks-csharp/3rd/zxing/qrcode/decoder/Mode.cs index df1a5ebb..548ea6d7 100755 --- a/shadowsocks-csharp/3rd/zxing/Mode.cs +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/Mode.cs @@ -41,7 +41,41 @@ namespace ZXing.QrCode.Internal /// /// /// + public static readonly Mode TERMINATOR = new Mode(new int[] { 0, 0, 0 }, 0x00, "TERMINATOR"); // Not really a mode... + /// + /// + /// + public static readonly Mode NUMERIC = new Mode(new int[] { 10, 12, 14 }, 0x01, "NUMERIC"); + /// + /// + /// + public static readonly Mode ALPHANUMERIC = new Mode(new int[] { 9, 11, 13 }, 0x02, "ALPHANUMERIC"); + /// + /// + /// + public static readonly Mode STRUCTURED_APPEND = new Mode(new int[] { 0, 0, 0 }, 0x03, "STRUCTURED_APPEND"); // Not supported + /// + /// + /// public static readonly Mode BYTE = new Mode(new int[] { 8, 16, 16 }, 0x04, "BYTE"); + /// + /// + /// + public static readonly Mode ECI = new Mode(null, 0x07, "ECI"); // character counts don't apply + /// + /// + /// + public static readonly Mode KANJI = new Mode(new int[] { 8, 10, 12 }, 0x08, "KANJI"); + /// + /// + /// + public static readonly Mode FNC1_FIRST_POSITION = new Mode(null, 0x05, "FNC1_FIRST_POSITION"); + /// + /// + /// + public static readonly Mode FNC1_SECOND_POSITION = new Mode(null, 0x09, "FNC1_SECOND_POSITION"); + /// See GBT 18284-2000; "Hanzi" is a transliteration of this mode name. + public static readonly Mode HANZI = new Mode(new int[] { 8, 10, 12 }, 0x0D, "HANZI"); private readonly int[] characterCountBitsForVersions; private readonly int bits; @@ -66,8 +100,27 @@ namespace ZXing.QrCode.Internal { switch (bits) { + case 0x0: + return TERMINATOR; + case 0x1: + return NUMERIC; + case 0x2: + return ALPHANUMERIC; + case 0x3: + return STRUCTURED_APPEND; case 0x4: return BYTE; + case 0x5: + return FNC1_FIRST_POSITION; + case 0x7: + return ECI; + case 0x8: + return KANJI; + case 0x9: + return FNC1_SECOND_POSITION; + case 0xD: + // 0xD is defined in GBT 18284-2000, may not be supported in foreign country + return HANZI; default: throw new ArgumentException(); } @@ -111,5 +164,16 @@ namespace ZXing.QrCode.Internal return bits; } } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override String ToString() + { + return name; + } } } \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/QRCodeDecoderMetaData.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/QRCodeDecoderMetaData.cs new file mode 100755 index 00000000..cc059aa9 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/QRCodeDecoderMetaData.cs @@ -0,0 +1,60 @@ +/* + * Copyright 2013 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.QrCode.Internal +{ + /// + /// Meta-data container for QR Code decoding. Instances of this class may be used to convey information back to the + /// decoding caller. Callers are expected to process this. + /// + public sealed class QRCodeDecoderMetaData + { + private readonly bool mirrored; + + /// + /// Initializes a new instance of the class. + /// + /// if set to true [mirrored]. + public QRCodeDecoderMetaData(bool mirrored) + { + this.mirrored = mirrored; + } + + /// + /// true if the QR Code was mirrored. + /// + public bool IsMirrored + { + get { return mirrored; } + } + + /// + /// Apply the result points' order correction due to mirroring. + /// + /// Array of points to apply mirror correction to. + public void applyMirroredCorrection(ResultPoint[] points) + { + if (!mirrored || points == null || points.Length < 3) + { + return; + } + ResultPoint bottomLeft = points[0]; + points[0] = points[2]; + points[2] = bottomLeft; + // No need to 'fix' top-left and alignment pattern. + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/Version.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/Version.cs new file mode 100755 index 00000000..e619933d --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/Version.cs @@ -0,0 +1,424 @@ +/* +* 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; + +using ZXing.Common; + +namespace ZXing.QrCode.Internal +{ + /// + /// See ISO 18004:2006 Annex D + /// + /// Sean Owen + public sealed class Version + { + /// See ISO 18004:2006 Annex D. + /// Element i represents the raw version bits that specify version i + 7 + /// + 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(); + + private readonly int versionNumber; + private readonly int[] alignmentPatternCenters; + private readonly ECBlocks[] ecBlocks; + private readonly int totalCodewords; + + private Version(int versionNumber, int[] alignmentPatternCenters, params ECBlocks[] ecBlocks) + { + this.versionNumber = versionNumber; + this.alignmentPatternCenters = alignmentPatternCenters; + this.ecBlocks = ecBlocks; + int total = 0; + int ecCodewords = ecBlocks[0].ECCodewordsPerBlock; + ECB[] ecbArray = ecBlocks[0].getECBlocks(); + foreach (var ecBlock in ecbArray) + { + total += ecBlock.Count * (ecBlock.DataCodewords + ecCodewords); + } + this.totalCodewords = total; + } + + /// + /// Gets the version number. + /// + public int VersionNumber + { + get + { + return versionNumber; + } + + } + + /// + /// Gets the alignment pattern centers. + /// + public int[] AlignmentPatternCenters + { + get + { + return alignmentPatternCenters; + } + + } + + /// + /// Gets the total codewords. + /// + public int TotalCodewords + { + get + { + return totalCodewords; + } + + } + + /// + /// Gets the dimension for version. + /// + public int DimensionForVersion + { + get + { + return 17 + 4 * versionNumber; + } + + } + + /// + /// Gets the EC blocks for level. + /// + /// The ec level. + /// + public ECBlocks getECBlocksForLevel(ErrorCorrectionLevel ecLevel) + { + return ecBlocks[ecLevel.ordinal()]; + } + + ///

Deduces version information purely from QR Code dimensions.

+ /// + ///
+ /// dimension in modules + /// + /// for a QR Code of that dimension or null + public static Version getProvisionalVersionForDimension(int dimension) + { + if (dimension % 4 != 1) + { + return null; + } + try + { + return getVersionForNumber((dimension - 17) >> 2); + } + catch (ArgumentException) + { + return null; + } + } + + /// + /// Gets the version for number. + /// + /// The version number. + /// + public static Version getVersionForNumber(int versionNumber) + { + if (versionNumber < 1 || versionNumber > 40) + { + throw new ArgumentException(); + } + 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; + } + + /// See ISO 18004:2006 Annex E + 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; + } + + ///

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 + /// each set of blocks. It also holds the number of error-correction codewords per block since it + /// will be the same across all blocks within one version.

+ ///
+ public sealed class ECBlocks + { + private readonly int ecCodewordsPerBlock; + private readonly ECB[] ecBlocks; + + internal ECBlocks(int ecCodewordsPerBlock, params ECB[] ecBlocks) + { + this.ecCodewordsPerBlock = ecCodewordsPerBlock; + this.ecBlocks = ecBlocks; + } + + /// + /// Gets the EC codewords per block. + /// + public int ECCodewordsPerBlock + { + get + { + return ecCodewordsPerBlock; + } + } + + /// + /// Gets the num blocks. + /// + public int NumBlocks + { + get + { + int total = 0; + foreach (var ecBlock in ecBlocks) + { + total += ecBlock.Count; + } + return total; + } + } + + /// + /// Gets the total EC codewords. + /// + public int TotalECCodewords + { + get + { + return ecCodewordsPerBlock * NumBlocks; + } + } + + /// + /// Gets the EC blocks. + /// + /// + public ECB[] getECBlocks() + { + return ecBlocks; + } + } + + ///

Encapsualtes the parameters for one error-correction block in one symbol version. + /// This includes the number of data codewords, and the number of times a block with these + /// parameters is used consecutively in the QR code version's format.

+ ///
+ public sealed class ECB + { + private readonly int count; + private readonly int dataCodewords; + + internal ECB(int count, int dataCodewords) + { + this.count = count; + this.dataCodewords = dataCodewords; + } + + /// + /// Gets the count. + /// + public int Count + { + get + { + return count; + } + + } + /// + /// Gets the data codewords. + /// + public int DataCodewords + { + get + { + return dataCodewords; + } + + } + } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override String ToString() + { + return Convert.ToString(versionNumber); + } + + /// See ISO 18004:2006 6.5.1 Table 9 + private static Version[] buildVersions() + { + return new Version[]{ + new Version(1, new int[]{}, + new ECBlocks(7, new ECB(1, 19)), + new ECBlocks(10, new ECB(1, 16)), + new ECBlocks(13, new ECB(1, 13)), + new ECBlocks(17, new ECB(1, 9))), + new Version(2, new int[]{6, 18}, + new ECBlocks(10, new ECB(1, 34)), + new ECBlocks(16, new ECB(1, 28)), + new ECBlocks(22, new ECB(1, 22)), + new ECBlocks(28, new ECB(1, 16))), + new Version(3, new int[]{6, 22}, + new ECBlocks(15, new ECB(1, 55)), + new ECBlocks(26, new ECB(1, 44)), + new ECBlocks(18, new ECB(2, 17)), + new ECBlocks(22, new ECB(2, 13))), + new Version(4, new int[]{6, 26}, + new ECBlocks(20, new ECB(1, 80)), + new ECBlocks(18, new ECB(2, 32)), + new ECBlocks(26, new ECB(2, 24)), + new ECBlocks(16, new ECB(4, 9))), + new Version(5, new int[]{6, 30}, + new ECBlocks(26, new ECB(1, 108)), + new ECBlocks(24, new ECB(2, 43)), + new ECBlocks(18, new ECB(2, 15), + new ECB(2, 16)), + new ECBlocks(22, new ECB(2, 11), + new ECB(2, 12))), + new Version(6, new int[]{6, 34}, + new ECBlocks(18, new ECB(2, 68)), + new ECBlocks(16, new ECB(4, 27)), + new ECBlocks(24, new ECB(4, 19)), + new ECBlocks(28, new ECB(4, 15))), + new Version(7, new int[]{6, 22, 38}, + new ECBlocks(20, new ECB(2, 78)), + new ECBlocks(18, new ECB(4, 31)), + new ECBlocks(18, new ECB(2, 14), + new ECB(4, 15)), + new ECBlocks(26, new ECB(4, 13), + new ECB(1, 14))), + new Version(8, new int[]{6, 24, 42}, + new ECBlocks(24, new ECB(2, 97)), + new ECBlocks(22, new ECB(2, 38), + new ECB(2, 39)), + new ECBlocks(22, new ECB(4, 18), + new ECB(2, 19)), + new ECBlocks(26, new ECB(4, 14), + new ECB(2, 15))), + new Version(9, new int[]{6, 26, 46}, + new ECBlocks(30, new ECB(2, 116)), + new ECBlocks(22, new ECB(3, 36), + new ECB(2, 37)), + new ECBlocks(20, new ECB(4, 16), + new ECB(4, 17)), + new ECBlocks(24, new ECB(4, 12), + new ECB(4, 13))), + new Version(10, new int[]{6, 28, 50}, + new ECBlocks(18, new ECB(2, 68), + new ECB(2, 69)), + new ECBlocks(26, new ECB(4, 43), + new ECB(1, 44)), + new ECBlocks(24, new ECB(6, 19), + new ECB(2, 20)), + new ECBlocks(28, new ECB(6, 15), + new ECB(2, 16))), + new Version(11, new int[]{6, 30, 54}, new ECBlocks(20, new ECB(4, 81)), + new ECBlocks(30, new ECB(1, 50), new ECB(4, 51)), new ECBlocks(28, new ECB(4, 22), new ECB(4, 23)), new ECBlocks(24, new ECB(3, 12), new ECB(8, 13))), new Version(12, new int[]{6, 32, 58}, new ECBlocks(24, new ECB(2, 92), new ECB(2, 93)), new ECBlocks(22, new ECB(6, 36), new ECB(2, 37)), new ECBlocks(26, new ECB(4, 20), new ECB(6, 21)), new ECBlocks(28, new ECB(7, 14), new ECB(4, 15))), new Version(13, new int[]{6, 34, 62}, new ECBlocks(26, new ECB(4, 107)), new ECBlocks(22, new ECB(8, 37), new ECB(1, 38)), new ECBlocks(24, new ECB(8, 20), new ECB(4, 21)), new ECBlocks(22, new ECB(12, 11), new ECB(4, 12))), new Version(14, new int[]{6, 26, 46, 66}, new ECBlocks(30, new ECB(3, 115), new ECB(1, 116)), new ECBlocks(24, new ECB(4, 40), new ECB(5, 41)), new ECBlocks(20, new ECB(11, 16), new ECB(5, 17)), new ECBlocks(24, new ECB(11, 12), new ECB(5, 13))), new Version(15, new int[]{6, 26, 48, 70}, new ECBlocks(22, new ECB(5, 87), new ECB(1, 88)), new ECBlocks(24, new ECB(5, 41), new ECB(5, 42)), 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, 74, 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)))}; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/detector/AlignmentPattern.cs b/shadowsocks-csharp/3rd/zxing/qrcode/detector/AlignmentPattern.cs new file mode 100755 index 00000000..e7dd9460 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/detector/AlignmentPattern.cs @@ -0,0 +1,68 @@ +/* +* 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 +{ + ///

Encapsulates an alignment pattern, which are the smaller square patterns found in + /// all but the simplest QR Codes.

+ /// + ///
+ /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + public sealed class AlignmentPattern : ResultPoint + { + private float estimatedModuleSize; + + internal AlignmentPattern(float posX, float posY, float estimatedModuleSize) + : base(posX, posY) + { + this.estimatedModuleSize = estimatedModuleSize; + } + + ///

Determines if this alignment pattern "about equals" an alignment pattern at the stated + /// position and size -- meaning, it is at nearly the same center with nearly the same size.

+ ///
+ internal bool aboutEquals(float moduleSize, float i, float j) + { + if (Math.Abs(i - Y) <= moduleSize && Math.Abs(j - X) <= moduleSize) + { + float moduleSizeDiff = Math.Abs(moduleSize - estimatedModuleSize); + return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize; + } + return false; + } + + /// + /// Combines this object's current estimate of a finder pattern position and module size + /// with a new estimate. It returns a new {@code FinderPattern} containing an average of the two. + /// + /// The i. + /// The j. + /// New size of the module. + /// + internal AlignmentPattern combineEstimate(float i, float j, float newModuleSize) + { + float combinedX = (X + j) / 2.0f; + float combinedY = (Y + i) / 2.0f; + float combinedModuleSize = (estimatedModuleSize + newModuleSize) / 2.0f; + return new AlignmentPattern(combinedX, combinedY, combinedModuleSize); + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/detector/AlignmentPatternFinder.cs b/shadowsocks-csharp/3rd/zxing/qrcode/detector/AlignmentPatternFinder.cs new file mode 100755 index 00000000..b8cdec5b --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/detector/AlignmentPatternFinder.cs @@ -0,0 +1,324 @@ +/* +* 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; +using System.Collections.Generic; + +using ZXing.Common; + +namespace ZXing.QrCode.Internal +{ + ///

This class attempts to find alignment patterns in a QR Code. Alignment patterns look like finder + /// patterns but are smaller and appear at regular intervals throughout the image.

+ /// + ///

At the moment this only looks for the bottom-right alignment pattern.

+ /// + ///

This is mostly a simplified copy of {@link FinderPatternFinder}. It is copied, + /// pasted and stripped down here for maximum performance but does unfortunately duplicate + /// some code.

+ /// + ///

This class is thread-safe but not reentrant. Each thread must allocate its own object.

+ /// + ///
+ /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + sealed class AlignmentPatternFinder + { + private readonly BitMatrix image; + private readonly IList possibleCenters; + private readonly int startX; + private readonly int startY; + private readonly int width; + private readonly int height; + private readonly float moduleSize; + private readonly int[] crossCheckStateCount; + private readonly ResultPointCallback resultPointCallback; + + ///

Creates a finder that will look in a portion of the whole image.

+ /// + ///
+ /// image to search + /// + /// left column from which to start searching + /// + /// top row from which to start searching + /// + /// width of region to search + /// + /// height of region to search + /// + /// estimated module size so far + /// + internal AlignmentPatternFinder(BitMatrix image, int startX, int startY, int width, int height, float moduleSize, ResultPointCallback resultPointCallback) + { + this.image = image; + this.possibleCenters = new List(5); + this.startX = startX; + this.startY = startY; + this.width = width; + this.height = height; + this.moduleSize = moduleSize; + this.crossCheckStateCount = new int[3]; + this.resultPointCallback = resultPointCallback; + } + + ///

This method attempts to find the bottom-right alignment pattern in the image. It is a bit messy since + /// it's pretty performance-critical and so is written to be fast foremost.

+ /// + ///
+ /// {@link AlignmentPattern} if found + /// + internal AlignmentPattern find() + { + int startX = this.startX; + int height = this.height; + int maxJ = startX + width; + int middleI = startY + (height >> 1); + // We are looking for black/white/black modules in 1:1:1 ratio; + // this tracks the number of black/white/black modules seen so far + int[] stateCount = new int[3]; + for (int iGen = 0; iGen < height; iGen++) + { + // Search from middle outwards + int i = middleI + ((iGen & 0x01) == 0 ? ((iGen + 1) >> 1) : -((iGen + 1) >> 1)); + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + int j = startX; + // Burn off leading white pixels before anything else; if we start in the middle of + // a white run, it doesn't make sense to count its length, since we don't know if the + // white run continued to the left of the start point + while (j < maxJ && !image[j, i]) + { + j++; + } + int currentState = 0; + while (j < maxJ) + { + if (image[j, i]) + { + // Black pixel + if (currentState == 1) + { + // Counting black pixels + stateCount[currentState]++; + } + else + { + // Counting white pixels + if (currentState == 2) + { + // A winner? + if (foundPatternCross(stateCount)) + { + // Yes + AlignmentPattern confirmed = handlePossibleCenter(stateCount, i, j); + if (confirmed != null) + { + return confirmed; + } + } + stateCount[0] = stateCount[2]; + stateCount[1] = 1; + stateCount[2] = 0; + currentState = 1; + } + else + { + stateCount[++currentState]++; + } + } + } + else + { + // White pixel + if (currentState == 1) + { + // Counting black pixels + currentState++; + } + stateCount[currentState]++; + } + j++; + } + if (foundPatternCross(stateCount)) + { + AlignmentPattern confirmed = handlePossibleCenter(stateCount, i, maxJ); + if (confirmed != null) + { + return confirmed; + } + } + } + + // Hmm, nothing we saw was observed and confirmed twice. If we had + // any guess at all, return it. + if (possibleCenters.Count != 0) + { + return possibleCenters[0]; + } + + return null; + } + + /// Given a count of black/white/black pixels just seen and an end position, + /// figures the location of the center of this black/white/black run. + /// + private static float? centerFromEnd(int[] stateCount, int end) + { + var result = (end - stateCount[2]) - stateCount[1] / 2.0f; + if (Single.IsNaN(result)) + return null; + return result; + } + + /// count of black/white/black pixels just read + /// + /// true iff the proportions of the counts is close enough to the 1/1/1 ratios + /// used by alignment patterns to be considered a match + /// + private bool foundPatternCross(int[] stateCount) + { + float maxVariance = moduleSize / 2.0f; + for (int i = 0; i < 3; i++) + { + if (Math.Abs(moduleSize - stateCount[i]) >= maxVariance) + { + return false; + } + } + return true; + } + + /// + ///

After a horizontal scan finds a potential alignment pattern, this method + /// "cross-checks" by scanning down vertically through the center of the possible + /// alignment pattern to see if the same proportion is detected.

+ ///
+ /// row where an alignment pattern was detected + /// center of the section that appears to cross an alignment pattern + /// maximum reasonable number of modules that should be + /// observed in any reading state, based on the results of the horizontal scan + /// The original state count total. + /// + /// vertical center of alignment pattern, or null if not found + /// + private float? crossCheckVertical(int startI, int centerJ, int maxCount, int originalStateCountTotal) + { + int maxI = image.Height; + int[] stateCount = crossCheckStateCount; + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + + // Start counting up from center + int i = startI; + while (i >= 0 && image[centerJ, i] && stateCount[1] <= maxCount) + { + stateCount[1]++; + i--; + } + // If already too many modules in this state or ran off the edge: + if (i < 0 || stateCount[1] > maxCount) + { + return null; + } + while (i >= 0 && !image[centerJ, i] && stateCount[0] <= maxCount) + { + stateCount[0]++; + i--; + } + if (stateCount[0] > maxCount) + { + return null; + } + + // Now also count down from center + i = startI + 1; + while (i < maxI && image[centerJ, i] && stateCount[1] <= maxCount) + { + stateCount[1]++; + i++; + } + if (i == maxI || stateCount[1] > maxCount) + { + return null; + } + while (i < maxI && !image[centerJ, i] && stateCount[2] <= maxCount) + { + stateCount[2]++; + i++; + } + if (stateCount[2] > maxCount) + { + return null; + } + + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; + if (5 * Math.Abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) + { + return null; + } + + return foundPatternCross(stateCount) ? centerFromEnd(stateCount, i) : null; + } + + ///

This is called when a horizontal scan finds a possible alignment pattern. It will + /// cross check with a vertical scan, and if successful, will see if this pattern had been + /// found on a previous horizontal scan. If so, we consider it confirmed and conclude we have + /// found the alignment pattern.

+ /// + ///
+ /// reading state module counts from horizontal scan + /// + /// row where alignment pattern may be found + /// + /// end of possible alignment pattern in row + /// + /// {@link AlignmentPattern} if we have found the same pattern twice, or null if not + /// + private AlignmentPattern handlePossibleCenter(int[] stateCount, int i, int j) + { + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2]; + float? centerJ = centerFromEnd(stateCount, j); + if (centerJ == null) + return null; + float? centerI = crossCheckVertical(i, (int)centerJ, 2 * stateCount[1], stateCountTotal); + if (centerI != null) + { + float estimatedModuleSize = (stateCount[0] + stateCount[1] + stateCount[2]) / 3.0f; + foreach (var center in possibleCenters) + { + // Look for about the same center and module size: + if (center.aboutEquals(estimatedModuleSize, centerI.Value, centerJ.Value)) + { + return center.combineEstimate(centerI.Value, centerJ.Value, estimatedModuleSize); + } + } + // Hadn't found this before; save it + var point = new AlignmentPattern(centerJ.Value, centerI.Value, estimatedModuleSize); + possibleCenters.Add(point); + if (resultPointCallback != null) + { + resultPointCallback(point); + } + } + return null; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/detector/Detector.cs b/shadowsocks-csharp/3rd/zxing/qrcode/detector/Detector.cs new file mode 100755 index 00000000..7ae8e3db --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/detector/Detector.cs @@ -0,0 +1,429 @@ +/* +* 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; +using System.Collections.Generic; + +using ZXing.Common; +using ZXing.Common.Detector; + +namespace ZXing.QrCode.Internal +{ + /// + ///

Encapsulates logic that can detect a QR Code in an image, even if the QR Code + /// is rotated or skewed, or partially obscured.

+ ///
+ /// Sean Owen + public class Detector + { + private readonly BitMatrix image; + private ResultPointCallback resultPointCallback; + + /// + /// Initializes a new instance of the class. + /// + /// The image. + public Detector(BitMatrix image) + { + this.image = image; + } + + /// + /// Gets the image. + /// + virtual protected internal BitMatrix Image + { + get + { + return image; + } + } + + /// + /// Gets the result point callback. + /// + virtual protected internal ResultPointCallback ResultPointCallback + { + get + { + return resultPointCallback; + } + } + + /// + ///

Detects a QR Code in an image, simply.

+ ///
+ /// + /// encapsulating results of detecting a QR Code + /// + public virtual DetectorResult detect() + { + return detect(null); + } + + /// + ///

Detects a QR Code in an image, simply.

+ ///
+ /// optional hints to detector + /// + /// encapsulating results of detecting a QR Code + /// + public virtual DetectorResult detect(IDictionary hints) + { + resultPointCallback = hints == null || !hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK) ? null : (ResultPointCallback)hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK]; + + FinderPatternFinder finder = new FinderPatternFinder(image, resultPointCallback); + FinderPatternInfo info = finder.find(hints); + if (info == null) + return null; + + return processFinderPatternInfo(info); + } + + /// + /// Processes the finder pattern info. + /// + /// The info. + /// + protected internal virtual DetectorResult processFinderPatternInfo(FinderPatternInfo info) + { + FinderPattern topLeft = info.TopLeft; + FinderPattern topRight = info.TopRight; + FinderPattern bottomLeft = info.BottomLeft; + + float moduleSize = calculateModuleSize(topLeft, topRight, bottomLeft); + if (moduleSize < 1.0f) + { + return null; + } + int dimension; + if (!computeDimension(topLeft, topRight, bottomLeft, moduleSize, out dimension)) + return null; + Internal.Version provisionalVersion = Internal.Version.getProvisionalVersionForDimension(dimension); + if (provisionalVersion == null) + return null; + int modulesBetweenFPCenters = provisionalVersion.DimensionForVersion - 7; + + AlignmentPattern alignmentPattern = null; + // Anything above version 1 has an alignment pattern + if (provisionalVersion.AlignmentPatternCenters.Length > 0) + { + + // Guess where a "bottom right" finder pattern would have been + float bottomRightX = topRight.X - topLeft.X + bottomLeft.X; + float bottomRightY = topRight.Y - topLeft.Y + bottomLeft.Y; + + // Estimate that alignment pattern is closer by 3 modules + // from "bottom right" to known top left location + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + float correctionToTopLeft = 1.0f - 3.0f / (float)modulesBetweenFPCenters; + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + int estAlignmentX = (int)(topLeft.X + correctionToTopLeft * (bottomRightX - topLeft.X)); + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + int estAlignmentY = (int)(topLeft.Y + correctionToTopLeft * (bottomRightY - topLeft.Y)); + + // Kind of arbitrary -- expand search radius before giving up + for (int i = 4; i <= 16; i <<= 1) + { + alignmentPattern = findAlignmentInRegion(moduleSize, estAlignmentX, estAlignmentY, (float)i); + if (alignmentPattern == null) + continue; + break; + } + // If we didn't find alignment pattern... well try anyway without it + } + + PerspectiveTransform transform = createTransform(topLeft, topRight, bottomLeft, alignmentPattern, dimension); + + BitMatrix bits = sampleGrid(image, transform, dimension); + if (bits == null) + return null; + + ResultPoint[] points; + if (alignmentPattern == null) + { + points = new ResultPoint[] { bottomLeft, topLeft, topRight }; + } + else + { + points = new ResultPoint[] { bottomLeft, topLeft, topRight, alignmentPattern }; + } + return new DetectorResult(bits, points); + } + + private static PerspectiveTransform createTransform(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft, ResultPoint alignmentPattern, int dimension) + { + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + float dimMinusThree = (float)dimension - 3.5f; + float bottomRightX; + float bottomRightY; + float sourceBottomRightX; + float sourceBottomRightY; + if (alignmentPattern != null) + { + bottomRightX = alignmentPattern.X; + bottomRightY = alignmentPattern.Y; + sourceBottomRightX = sourceBottomRightY = dimMinusThree - 3.0f; + } + else + { + // Don't have an alignment pattern, just make up the bottom-right point + bottomRightX = (topRight.X - topLeft.X) + bottomLeft.X; + bottomRightY = (topRight.Y - topLeft.Y) + bottomLeft.Y; + sourceBottomRightX = sourceBottomRightY = dimMinusThree; + } + + return PerspectiveTransform.quadrilateralToQuadrilateral( + 3.5f, + 3.5f, + dimMinusThree, + 3.5f, + sourceBottomRightX, + sourceBottomRightY, + 3.5f, + dimMinusThree, + topLeft.X, + topLeft.Y, + topRight.X, + topRight.Y, + bottomRightX, + bottomRightY, + bottomLeft.X, + bottomLeft.Y); + } + + private static BitMatrix sampleGrid(BitMatrix image, PerspectiveTransform transform, int dimension) + { + GridSampler sampler = GridSampler.Instance; + return sampler.sampleGrid(image, dimension, dimension, transform); + } + + ///

Computes the dimension (number of modules on a size) of the QR Code based on the position + /// of the finder patterns and estimated module size.

+ ///
+ private static bool computeDimension(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft, float moduleSize, out int dimension) + { + int tltrCentersDimension = MathUtils.round(ResultPoint.distance(topLeft, topRight) / moduleSize); + int tlblCentersDimension = MathUtils.round(ResultPoint.distance(topLeft, bottomLeft) / moduleSize); + dimension = ((tltrCentersDimension + tlblCentersDimension) >> 1) + 7; + switch (dimension & 0x03) + { + // mod 4 + case 0: + dimension++; + break; + // 1? do nothing + case 2: + dimension--; + break; + case 3: + return true; + } + return true; + } + + ///

Computes an average estimated module size based on estimated derived from the positions + /// of the three finder patterns.

+ ///
+ protected internal virtual float calculateModuleSize(ResultPoint topLeft, ResultPoint topRight, ResultPoint bottomLeft) + { + // Take the average + return (calculateModuleSizeOneWay(topLeft, topRight) + calculateModuleSizeOneWay(topLeft, bottomLeft)) / 2.0f; + } + + ///

Estimates module size based on two finder patterns -- it uses + /// {@link #sizeOfBlackWhiteBlackRunBothWays(int, int, int, int)} to figure the + /// width of each, measuring along the axis between their centers.

+ ///
+ private float calculateModuleSizeOneWay(ResultPoint pattern, ResultPoint otherPattern) + { + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + float moduleSizeEst1 = sizeOfBlackWhiteBlackRunBothWays((int)pattern.X, (int)pattern.Y, (int)otherPattern.X, (int)otherPattern.Y); + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + float moduleSizeEst2 = sizeOfBlackWhiteBlackRunBothWays((int)otherPattern.X, (int)otherPattern.Y, (int)pattern.X, (int)pattern.Y); + if (Single.IsNaN(moduleSizeEst1)) + { + return moduleSizeEst2 / 7.0f; + } + if (Single.IsNaN(moduleSizeEst2)) + { + return moduleSizeEst1 / 7.0f; + } + // Average them, and divide by 7 since we've counted the width of 3 black modules, + // and 1 white and 1 black module on either side. Ergo, divide sum by 14. + return (moduleSizeEst1 + moduleSizeEst2) / 14.0f; + } + + /// See {@link #sizeOfBlackWhiteBlackRun(int, int, int, int)}; computes the total width of + /// a finder pattern by looking for a black-white-black run from the center in the direction + /// of another point (another finder pattern center), and in the opposite direction too. + /// + private float sizeOfBlackWhiteBlackRunBothWays(int fromX, int fromY, int toX, int toY) + { + + float result = sizeOfBlackWhiteBlackRun(fromX, fromY, toX, toY); + + // Now count other way -- don't run off image though of course + float scale = 1.0f; + int otherToX = fromX - (toX - fromX); + if (otherToX < 0) + { + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + scale = (float)fromX / (float)(fromX - otherToX); + otherToX = 0; + } + else if (otherToX >= image.Width) + { + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + scale = (float)(image.Width - 1 - fromX) / (float)(otherToX - fromX); + otherToX = image.Width - 1; + } + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + int otherToY = (int)(fromY - (toY - fromY) * scale); + + scale = 1.0f; + if (otherToY < 0) + { + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + scale = (float)fromY / (float)(fromY - otherToY); + otherToY = 0; + } + else if (otherToY >= image.Height) + { + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + scale = (float)(image.Height - 1 - fromY) / (float)(otherToY - fromY); + otherToY = image.Height - 1; + } + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + otherToX = (int)(fromX + (otherToX - fromX) * scale); + + result += sizeOfBlackWhiteBlackRun(fromX, fromY, otherToX, otherToY); + return result - 1.0f; // -1 because we counted the middle pixel twice + } + + ///

This method traces a line from a point in the image, in the direction towards another point. + /// It begins in a black region, and keeps going until it finds white, then black, then white again. + /// It reports the distance from the start to this point.

+ /// + ///

This is used when figuring out how wide a finder pattern is, when the finder pattern + /// may be skewed or rotated.

+ ///
+ private float sizeOfBlackWhiteBlackRun(int fromX, int fromY, int toX, int toY) + { + // Mild variant of Bresenham's algorithm; + // see http://en.wikipedia.org/wiki/Bresenham's_line_algorithm + bool steep = Math.Abs(toY - fromY) > Math.Abs(toX - fromX); + if (steep) + { + int temp = fromX; + fromX = fromY; + fromY = temp; + temp = toX; + toX = toY; + toY = temp; + } + + int dx = Math.Abs(toX - fromX); + int dy = Math.Abs(toY - fromY); + int error = -dx >> 1; + int xstep = fromX < toX ? 1 : -1; + int ystep = fromY < toY ? 1 : -1; + + // In black pixels, looking for white, first or second time. + int state = 0; + // Loop up until x == toX, but not beyond + int xLimit = toX + xstep; + for (int x = fromX, y = fromY; x != xLimit; x += xstep) + { + int realX = steep ? y : x; + int realY = steep ? x : y; + + // Does current pixel mean we have moved white to black or vice versa? + // Scanning black in state 0,2 and white in state 1, so if we find the wrong + // color, advance to next state or end if we are in state 2 already + if ((state == 1) == image[realX, realY]) + { + if (state == 2) + { + return MathUtils.distance(x, y, fromX, fromY); + } + state++; + } + error += dy; + if (error > 0) + { + if (y == toY) + { + + + break; + } + y += ystep; + error -= dx; + } + } + // Found black-white-black; give the benefit of the doubt that the next pixel outside the image + // is "white" so this last point at (toX+xStep,toY) is the right ending. This is really a + // small approximation; (toX+xStep,toY+yStep) might be really correct. Ignore this. + if (state == 2) + { + return MathUtils.distance(toX + xstep, toY, fromX, fromY); + } + // else we didn't find even black-white-black; no estimate is really possible + return Single.NaN; + + } + + /// + ///

Attempts to locate an alignment pattern in a limited region of the image, which is + /// guessed to contain it. This method uses {@link AlignmentPattern}.

+ ///
+ /// estimated module size so far + /// x coordinate of center of area probably containing alignment pattern + /// y coordinate of above + /// number of pixels in all directions to search from the center + /// + /// if found, or null otherwise + /// + protected AlignmentPattern findAlignmentInRegion(float overallEstModuleSize, int estAlignmentX, int estAlignmentY, float allowanceFactor) + { + // Look for an alignment pattern (3 modules in size) around where it + // should be + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + int allowance = (int)(allowanceFactor * overallEstModuleSize); + int alignmentAreaLeftX = Math.Max(0, estAlignmentX - allowance); + int alignmentAreaRightX = Math.Min(image.Width - 1, estAlignmentX + allowance); + if (alignmentAreaRightX - alignmentAreaLeftX < overallEstModuleSize * 3) + { + return null; + } + + int alignmentAreaTopY = Math.Max(0, estAlignmentY - allowance); + int alignmentAreaBottomY = Math.Min(image.Height - 1, estAlignmentY + allowance); + + var alignmentFinder = new AlignmentPatternFinder( + image, + alignmentAreaLeftX, + alignmentAreaTopY, + alignmentAreaRightX - alignmentAreaLeftX, + alignmentAreaBottomY - alignmentAreaTopY, + overallEstModuleSize, + resultPointCallback); + + return alignmentFinder.find(); + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPattern.cs b/shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPattern.cs new file mode 100755 index 00000000..80469bf7 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPattern.cs @@ -0,0 +1,107 @@ +/* +* 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 +{ + /// + ///

Encapsulates a finder pattern, which are the three square patterns found in + /// the corners of QR Codes. It also encapsulates a count of similar finder patterns, + /// as a convenience to the finder's bookkeeping.

+ ///
+ /// Sean Owen + public sealed class FinderPattern : ResultPoint + { + private readonly float estimatedModuleSize; + private int count; + + internal FinderPattern(float posX, float posY, float estimatedModuleSize) + : this(posX, posY, estimatedModuleSize, 1) + { + this.estimatedModuleSize = estimatedModuleSize; + this.count = 1; + } + + internal FinderPattern(float posX, float posY, float estimatedModuleSize, int count) + : base(posX, posY) + { + this.estimatedModuleSize = estimatedModuleSize; + this.count = count; + } + + /// + /// Gets the size of the estimated module. + /// + /// + /// The size of the estimated module. + /// + public float EstimatedModuleSize + { + get + { + return estimatedModuleSize; + } + } + + internal int Count + { + get + { + return count; + } + } + + /* + internal void incrementCount() + { + this.count++; + } + */ + + ///

Determines if this finder pattern "about equals" a finder pattern at the stated + /// position and size -- meaning, it is at nearly the same center with nearly the same size.

+ ///
+ internal bool aboutEquals(float moduleSize, float i, float j) + { + if (Math.Abs(i - Y) <= moduleSize && Math.Abs(j - X) <= moduleSize) + { + float moduleSizeDiff = Math.Abs(moduleSize - estimatedModuleSize); + return moduleSizeDiff <= 1.0f || moduleSizeDiff <= estimatedModuleSize; + + } + return false; + } + + /// + /// Combines this object's current estimate of a finder pattern position and module size + /// with a new estimate. It returns a new {@code FinderPattern} containing a weighted average + /// based on count. + /// + /// The i. + /// The j. + /// New size of the module. + /// + internal FinderPattern combineEstimate(float i, float j, float newModuleSize) + { + int combinedCount = count + 1; + float combinedX = (count * X + j) / combinedCount; + float combinedY = (count * Y + i) / combinedCount; + float combinedModuleSize = (count * estimatedModuleSize + newModuleSize) / combinedCount; + return new FinderPattern(combinedX, combinedY, combinedModuleSize, combinedCount); + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPatternFinder.cs b/shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPatternFinder.cs new file mode 100755 index 00000000..7b4c5113 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPatternFinder.cs @@ -0,0 +1,808 @@ +/* +* 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; +using System.Collections.Generic; + +using ZXing.Common; + +namespace ZXing.QrCode.Internal +{ + /// + ///

This class attempts to find finder patterns in a QR Code. Finder patterns are the square + /// markers at three corners of a QR Code.

+ /// + ///

This class is thread-safe but not reentrant. Each thread must allocate its own object. + ///

+ /// Sean Owen + public class FinderPatternFinder + { + private const int CENTER_QUORUM = 2; + /// + /// 1 pixel/module times 3 modules/center + /// + protected internal const int MIN_SKIP = 3; + /// + /// support up to version 10 for mobile clients + /// + protected internal const int MAX_MODULES = 57; + private const int INTEGER_MATH_SHIFT = 8; + + private readonly BitMatrix image; + private List possibleCenters; + private bool hasSkipped; + private readonly int[] crossCheckStateCount; + private readonly ResultPointCallback resultPointCallback; + + /// + ///

Creates a finder that will search the image for three finder patterns.

+ ///
+ /// image to search + public FinderPatternFinder(BitMatrix image) + : this(image, null) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The image. + /// The result point callback. + public FinderPatternFinder(BitMatrix image, ResultPointCallback resultPointCallback) + { + this.image = image; + this.possibleCenters = new List(); + this.crossCheckStateCount = new int[5]; + this.resultPointCallback = resultPointCallback; + } + + /// + /// Gets the image. + /// + virtual protected internal BitMatrix Image + { + get + { + return image; + } + } + + /// + /// Gets the possible centers. + /// + virtual protected internal List PossibleCenters + { + get + { + return possibleCenters; + } + } + + internal virtual FinderPatternInfo find(IDictionary hints) + { + bool tryHarder = hints != null && hints.ContainsKey(DecodeHintType.TRY_HARDER); + bool pureBarcode = hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE); + int maxI = image.Height; + int maxJ = image.Width; + // We are looking for black/white/black/white/black modules in + // 1:1:3:1:1 ratio; this tracks the number of such modules seen so far + + // Let's assume that the maximum version QR Code we support takes up 1/4 the height of the + // image, and then account for the center being 3 modules in size. This gives the smallest + // number of pixels the center could be, so skip this often. When trying harder, look for all + // QR versions regardless of how dense they are. + int iSkip = (3 * maxI) / (4 * MAX_MODULES); + if (iSkip < MIN_SKIP || tryHarder) + { + iSkip = MIN_SKIP; + } + + bool done = false; + int[] stateCount = new int[5]; + for (int i = iSkip - 1; i < maxI && !done; i += iSkip) + { + // Get a row of black/white values + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + stateCount[3] = 0; + stateCount[4] = 0; + int currentState = 0; + for (int j = 0; j < maxJ; j++) + { + if (image[j, i]) + { + // Black pixel + if ((currentState & 1) == 1) + { + // Counting white pixels + currentState++; + } + stateCount[currentState]++; + } + else + { + // White pixel + if ((currentState & 1) == 0) + { + // Counting black pixels + if (currentState == 4) + { + // A winner? + if (foundPatternCross(stateCount)) + { + // Yes + bool confirmed = handlePossibleCenter(stateCount, i, j, pureBarcode); + if (confirmed) + { + // Start examining every other line. Checking each line turned out to be too + // expensive and didn't improve performance. + iSkip = 2; + if (hasSkipped) + { + done = haveMultiplyConfirmedCenters(); + } + else + { + int rowSkip = findRowSkip(); + if (rowSkip > stateCount[2]) + { + // Skip rows between row of lower confirmed center + // and top of presumed third confirmed center + // but back up a bit to get a full chance of detecting + // it, entire width of center of finder pattern + + // Skip by rowSkip, but back off by stateCount[2] (size of last center + // of pattern we saw) to be conservative, and also back off by iSkip which + // is about to be re-added + i += rowSkip - stateCount[2] - iSkip; + j = maxJ - 1; + } + } + } + else + { + stateCount[0] = stateCount[2]; + stateCount[1] = stateCount[3]; + stateCount[2] = stateCount[4]; + stateCount[3] = 1; + stateCount[4] = 0; + currentState = 3; + continue; + } + // Clear state to start looking again + currentState = 0; + stateCount[0] = 0; + stateCount[1] = 0; + stateCount[2] = 0; + stateCount[3] = 0; + stateCount[4] = 0; + } + else + { + // No, shift counts back by two + stateCount[0] = stateCount[2]; + stateCount[1] = stateCount[3]; + stateCount[2] = stateCount[4]; + stateCount[3] = 1; + stateCount[4] = 0; + currentState = 3; + } + } + else + { + stateCount[++currentState]++; + } + } + else + { + // Counting white pixels + stateCount[currentState]++; + } + } + } + if (foundPatternCross(stateCount)) + { + bool confirmed = handlePossibleCenter(stateCount, i, maxJ, pureBarcode); + if (confirmed) + { + iSkip = stateCount[0]; + if (hasSkipped) + { + // Found a third one + done = haveMultiplyConfirmedCenters(); + } + } + } + } + + FinderPattern[] patternInfo = selectBestPatterns(); + if (patternInfo == null) + return null; + + ResultPoint.orderBestPatterns(patternInfo); + + return new FinderPatternInfo(patternInfo); + } + + /// Given a count of black/white/black/white/black pixels just seen and an end position, + /// figures the location of the center of this run. + /// + private static float? centerFromEnd(int[] stateCount, int end) + { + var result = (end - stateCount[4] - stateCount[3]) - stateCount[2] / 2.0f; + if (Single.IsNaN(result)) + return null; + return result; + } + + /// count of black/white/black/white/black pixels just read + /// + /// true iff the proportions of the counts is close enough to the 1/1/3/1/1 ratios + /// used by finder patterns to be considered a match + /// + protected internal static bool foundPatternCross(int[] stateCount) + { + int totalModuleSize = 0; + for (int i = 0; i < 5; i++) + { + int count = stateCount[i]; + if (count == 0) + { + return false; + } + totalModuleSize += count; + } + if (totalModuleSize < 7) + { + return false; + } + int moduleSize = (totalModuleSize << INTEGER_MATH_SHIFT) / 7; + int maxVariance = moduleSize / 2; + // Allow less than 50% variance from 1-1-3-1-1 proportions + return Math.Abs(moduleSize - (stateCount[0] << INTEGER_MATH_SHIFT)) < maxVariance && + Math.Abs(moduleSize - (stateCount[1] << INTEGER_MATH_SHIFT)) < maxVariance && + Math.Abs(3 * moduleSize - (stateCount[2] << INTEGER_MATH_SHIFT)) < 3 * maxVariance && + Math.Abs(moduleSize - (stateCount[3] << INTEGER_MATH_SHIFT)) < maxVariance && + Math.Abs(moduleSize - (stateCount[4] << INTEGER_MATH_SHIFT)) < maxVariance; + } + + private int[] CrossCheckStateCount + { + get + { + crossCheckStateCount[0] = 0; + crossCheckStateCount[1] = 0; + crossCheckStateCount[2] = 0; + crossCheckStateCount[3] = 0; + crossCheckStateCount[4] = 0; + return crossCheckStateCount; + } + } + + /// + /// After a vertical and horizontal scan finds a potential finder pattern, this method + /// "cross-cross-cross-checks" by scanning down diagonally through the center of the possible + /// finder pattern to see if the same proportion is detected. + /// + /// row where a finder pattern was detected + /// center of the section that appears to cross a finder pattern + /// maximum reasonable number of modules that should be observed in any reading state, based on the results of the horizontal scan + /// The original state count total. + /// true if proportions are withing expected limits + private bool crossCheckDiagonal(int startI, int centerJ, int maxCount, int originalStateCountTotal) + { + int maxI = image.Height; + int maxJ = image.Width; + int[] stateCount = CrossCheckStateCount; + + // Start counting up, left from center finding black center mass + int i = 0; + while (startI - i >= 0 && image[centerJ - i, startI - i]) + { + stateCount[2]++; + i++; + } + + if ((startI - i < 0) || (centerJ - i < 0)) + { + return false; + } + + // Continue up, left finding white space + while ((startI - i >= 0) && (centerJ - i >= 0) && !image[centerJ - i, startI - i] && stateCount[1] <= maxCount) + { + stateCount[1]++; + i++; + } + + // If already too many modules in this state or ran off the edge: + if ((startI - i < 0) || (centerJ - i < 0) || stateCount[1] > maxCount) + { + return false; + } + + // Continue up, left finding black border + while ((startI - i >= 0) && (centerJ - i >= 0) && image[centerJ - i, startI - i] && stateCount[0] <= maxCount) + { + stateCount[0]++; + i++; + } + if (stateCount[0] > maxCount) + { + return false; + } + + // Now also count down, right from center + i = 1; + while ((startI + i < maxI) && (centerJ + i < maxJ) && image[centerJ + i, startI + i]) + { + stateCount[2]++; + i++; + } + + // Ran off the edge? + if ((startI + i >= maxI) || (centerJ + i >= maxJ)) + { + return false; + } + + while ((startI + i < maxI) && (centerJ + i < maxJ) && !image[centerJ + i, startI + i] && stateCount[3] < maxCount) + { + stateCount[3]++; + i++; + } + + if ((startI + i >= maxI) || (centerJ + i >= maxJ) || stateCount[3] >= maxCount) + { + return false; + } + + while ((startI + i < maxI) && (centerJ + i < maxJ) && image[centerJ + i, startI + i] && stateCount[4] < maxCount) + { + stateCount[4]++; + i++; + } + + if (stateCount[4] >= maxCount) + { + return false; + } + + // If we found a finder-pattern-like section, but its size is more than 100% different than + // the original, assume it's a false positive + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; + return Math.Abs(stateCountTotal - originalStateCountTotal) < 2*originalStateCountTotal && + foundPatternCross(stateCount); + } + + /// + ///

After a horizontal scan finds a potential finder pattern, this method + /// "cross-checks" by scanning down vertically through the center of the possible + /// finder pattern to see if the same proportion is detected.

+ ///
+ /// row where a finder pattern was detected + /// center of the section that appears to cross a finder pattern + /// maximum reasonable number of modules that should be + /// observed in any reading state, based on the results of the horizontal scan + /// The original state count total. + /// + /// vertical center of finder pattern, or null if not found + /// + private float? crossCheckVertical(int startI, int centerJ, int maxCount, int originalStateCountTotal) + { + int maxI = image.Height; + int[] stateCount = CrossCheckStateCount; + + // Start counting up from center + int i = startI; + while (i >= 0 && image[centerJ, i]) + { + stateCount[2]++; + i--; + } + if (i < 0) + { + return null; + } + while (i >= 0 && !image[centerJ, i] && stateCount[1] <= maxCount) + { + stateCount[1]++; + i--; + } + // If already too many modules in this state or ran off the edge: + if (i < 0 || stateCount[1] > maxCount) + { + return null; + } + while (i >= 0 && image[centerJ, i] && stateCount[0] <= maxCount) + { + stateCount[0]++; + i--; + } + if (stateCount[0] > maxCount) + { + return null; + } + + // Now also count down from center + i = startI + 1; + while (i < maxI && image[centerJ, i]) + { + stateCount[2]++; + i++; + } + if (i == maxI) + { + return null; + } + while (i < maxI && !image[centerJ, i] && stateCount[3] < maxCount) + { + stateCount[3]++; + i++; + } + if (i == maxI || stateCount[3] >= maxCount) + { + return null; + } + while (i < maxI && image[centerJ, i] && stateCount[4] < maxCount) + { + stateCount[4]++; + i++; + } + if (stateCount[4] >= maxCount) + { + return null; + } + + // If we found a finder-pattern-like section, but its size is more than 40% different than + // the original, assume it's a false positive + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; + if (5 * Math.Abs(stateCountTotal - originalStateCountTotal) >= 2 * originalStateCountTotal) + { + return null; + } + + return foundPatternCross(stateCount) ? centerFromEnd(stateCount, i) : null; + } + + ///

Like {@link #crossCheckVertical(int, int, int, int)}, and in fact is basically identical, + /// except it reads horizontally instead of vertically. This is used to cross-cross + /// check a vertical cross check and locate the real center of the alignment pattern.

+ ///
+ private float? crossCheckHorizontal(int startJ, int centerI, int maxCount, int originalStateCountTotal) + { + int maxJ = image.Width; + int[] stateCount = CrossCheckStateCount; + + int j = startJ; + while (j >= 0 && image[j, centerI]) + { + stateCount[2]++; + j--; + } + if (j < 0) + { + return null; + } + while (j >= 0 && !image[j, centerI] && stateCount[1] <= maxCount) + { + stateCount[1]++; + j--; + } + if (j < 0 || stateCount[1] > maxCount) + { + return null; + } + while (j >= 0 && image[j, centerI] && stateCount[0] <= maxCount) + { + stateCount[0]++; + j--; + } + if (stateCount[0] > maxCount) + { + return null; + } + + j = startJ + 1; + while (j < maxJ && image[j, centerI]) + { + stateCount[2]++; + j++; + } + if (j == maxJ) + { + return null; + } + while (j < maxJ && !image[j, centerI] && stateCount[3] < maxCount) + { + stateCount[3]++; + j++; + } + if (j == maxJ || stateCount[3] >= maxCount) + { + return null; + } + while (j < maxJ && image[j, centerI] && stateCount[4] < maxCount) + { + stateCount[4]++; + j++; + } + if (stateCount[4] >= maxCount) + { + return null; + } + + // If we found a finder-pattern-like section, but its size is significantly different than + // the original, assume it's a false positive + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + stateCount[4]; + if (5 * Math.Abs(stateCountTotal - originalStateCountTotal) >= originalStateCountTotal) + { + return null; + } + + return foundPatternCross(stateCount) ? centerFromEnd(stateCount, j) : null; + } + + /// + ///

This is called when a horizontal scan finds a possible alignment pattern. It will + /// cross check with a vertical scan, and if successful, will, ah, cross-cross-check + /// with another horizontal scan. This is needed primarily to locate the real horizontal + /// center of the pattern in cases of extreme skew. + /// And then we cross-cross-cross check with another diagonal scan.

+ /// If that succeeds the finder pattern location is added to a list that tracks + /// the number of times each location has been nearly-matched as a finder pattern. + /// Each additional find is more evidence that the location is in fact a finder + /// pattern center + ///
+ /// reading state module counts from horizontal scan + /// row where finder pattern may be found + /// end of possible finder pattern in row + /// if set to true [pure barcode]. + /// + /// true if a finder pattern candidate was found this time + /// + protected bool handlePossibleCenter(int[] stateCount, int i, int j, bool pureBarcode) + { + int stateCountTotal = stateCount[0] + stateCount[1] + stateCount[2] + stateCount[3] + + stateCount[4]; + float? centerJ = centerFromEnd(stateCount, j); + if (centerJ == null) + return false; + float? centerI = crossCheckVertical(i, (int)centerJ.Value, stateCount[2], stateCountTotal); + if (centerI != null) + { + // Re-cross check + centerJ = crossCheckHorizontal((int)centerJ.Value, (int)centerI.Value, stateCount[2], stateCountTotal); + if (centerJ != null && + (!pureBarcode || crossCheckDiagonal((int) centerI, (int) centerJ, stateCount[2], stateCountTotal))) + { + float estimatedModuleSize = stateCountTotal / 7.0f; + bool found = false; + for (int index = 0; index < possibleCenters.Count; index++) + { + var center = possibleCenters[index]; + // Look for about the same center and module size: + if (center.aboutEquals(estimatedModuleSize, centerI.Value, centerJ.Value)) + { + possibleCenters.RemoveAt(index); + possibleCenters.Insert(index, center.combineEstimate(centerI.Value, centerJ.Value, estimatedModuleSize)); + + found = true; + break; + } + } + if (!found) + { + var point = new FinderPattern(centerJ.Value, centerI.Value, estimatedModuleSize); + + possibleCenters.Add(point); + if (resultPointCallback != null) + { + + resultPointCallback(point); + } + } + return true; + } + } + return false; + } + + /// number of rows we could safely skip during scanning, based on the first + /// two finder patterns that have been located. In some cases their position will + /// allow us to infer that the third pattern must lie below a certain point farther + /// down in the image. + /// + private int findRowSkip() + { + int max = possibleCenters.Count; + if (max <= 1) + { + return 0; + } + ResultPoint firstConfirmedCenter = null; + foreach (var center in possibleCenters) + { + if (center.Count >= CENTER_QUORUM) + { + if (firstConfirmedCenter == null) + { + firstConfirmedCenter = center; + } + else + { + // We have two confirmed centers + // How far down can we skip before resuming looking for the next + // pattern? In the worst case, only the difference between the + // difference in the x / y coordinates of the two centers. + // This is the case where you find top left last. + hasSkipped = true; + //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" + return (int)(Math.Abs(firstConfirmedCenter.X - center.X) - Math.Abs(firstConfirmedCenter.Y - center.Y)) / 2; + } + } + } + return 0; + } + + /// true iff we have found at least 3 finder patterns that have been detected + /// at least {@link #CENTER_QUORUM} times each, and, the estimated module size of the + /// candidates is "pretty similar" + /// + private bool haveMultiplyConfirmedCenters() + { + int confirmedCount = 0; + float totalModuleSize = 0.0f; + int max = possibleCenters.Count; + foreach (var pattern in possibleCenters) + { + if (pattern.Count >= CENTER_QUORUM) + { + confirmedCount++; + totalModuleSize += pattern.EstimatedModuleSize; + } + } + if (confirmedCount < 3) + { + return false; + } + // OK, we have at least 3 confirmed centers, but, it's possible that one is a "false positive" + // and that we need to keep looking. We detect this by asking if the estimated module sizes + // vary too much. We arbitrarily say that when the total deviation from average exceeds + // 5% of the total module size estimates, it's too much. + float average = totalModuleSize / max; + float totalDeviation = 0.0f; + for (int i = 0; i < max; i++) + { + var pattern = possibleCenters[i]; + totalDeviation += Math.Abs(pattern.EstimatedModuleSize - average); + } + return totalDeviation <= 0.05f * totalModuleSize; + } + + /// the 3 best {@link FinderPattern}s from our list of candidates. The "best" are + /// those that have been detected at least {@link #CENTER_QUORUM} times, and whose module + /// size differs from the average among those patterns the least + /// + private FinderPattern[] selectBestPatterns() + { + int startSize = possibleCenters.Count; + if (startSize < 3) + { + // Couldn't find enough finder patterns + return null; + } + + // Filter outlier possibilities whose module size is too different + if (startSize > 3) + { + // But we can only afford to do so if we have at least 4 possibilities to choose from + float totalModuleSize = 0.0f; + float square = 0.0f; + foreach (var center in possibleCenters) + { + float size = center.EstimatedModuleSize; + totalModuleSize += size; + square += size * size; + } + float average = totalModuleSize / startSize; + float stdDev = (float)Math.Sqrt(square / startSize - average * average); + + possibleCenters.Sort(new FurthestFromAverageComparator(average)); + + float limit = Math.Max(0.2f * average, stdDev); + + for (int i = 0; i < possibleCenters.Count && possibleCenters.Count > 3; i++) + { + FinderPattern pattern = possibleCenters[i]; + if (Math.Abs(pattern.EstimatedModuleSize - average) > limit) + { + possibleCenters.RemoveAt(i); + i--; + } + } + } + + if (possibleCenters.Count > 3) + { + // Throw away all but those first size candidate points we found. + + float totalModuleSize = 0.0f; + foreach (var possibleCenter in possibleCenters) + { + totalModuleSize += possibleCenter.EstimatedModuleSize; + } + + float average = totalModuleSize / possibleCenters.Count; + + possibleCenters.Sort(new CenterComparator(average)); + + //possibleCenters.subList(3, possibleCenters.Count).clear(); + possibleCenters = possibleCenters.GetRange(0, 3); + } + + return new[] + { + possibleCenters[0], + possibleCenters[1], + possibleCenters[2] + }; + } + + /// + /// Orders by furthest from average + /// + private sealed class FurthestFromAverageComparator : IComparer + { + private readonly float average; + + public FurthestFromAverageComparator(float f) + { + average = f; + } + + public int Compare(FinderPattern x, FinderPattern y) + { + float dA = Math.Abs(y.EstimatedModuleSize - average); + float dB = Math.Abs(x.EstimatedModuleSize - average); + return dA < dB ? -1 : dA == dB ? 0 : 1; + } + } + + ///

Orders by {@link FinderPattern#getCount()}, descending.

+ private sealed class CenterComparator : IComparer + { + private readonly float average; + + public CenterComparator(float f) + { + average = f; + } + + public int Compare(FinderPattern x, FinderPattern y) + { + if (y.Count == x.Count) + { + float dA = Math.Abs(y.EstimatedModuleSize - average); + float dB = Math.Abs(x.EstimatedModuleSize - average); + return dA < dB ? 1 : dA == dB ? 0 : -1; + } + return y.Count - x.Count; + } + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPatternInfo.cs b/shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPatternInfo.cs new file mode 100755 index 00000000..982b755a --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/detector/FinderPatternInfo.cs @@ -0,0 +1,74 @@ +/* +* 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. +*/ + +namespace ZXing.QrCode.Internal +{ + /// + ///

Encapsulates information about finder patterns in an image, including the location of + /// the three finder patterns, and their estimated module size.

+ ///
+ /// Sean Owen + public sealed class FinderPatternInfo + { + private readonly FinderPattern bottomLeft; + private readonly FinderPattern topLeft; + private readonly FinderPattern topRight; + + /// + /// Initializes a new instance of the class. + /// + /// The pattern centers. + public FinderPatternInfo(FinderPattern[] patternCenters) + { + this.bottomLeft = patternCenters[0]; + this.topLeft = patternCenters[1]; + this.topRight = patternCenters[2]; + } + + /// + /// Gets the bottom left. + /// + public FinderPattern BottomLeft + { + get + { + return bottomLeft; + } + } + + /// + /// Gets the top left. + /// + public FinderPattern TopLeft + { + get + { + return topLeft; + } + } + + /// + /// Gets the top right. + /// + public FinderPattern TopRight + { + get + { + return topRight; + } + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/BlockPair.cs b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/BlockPair.cs similarity index 100% rename from shadowsocks-csharp/3rd/zxing/BlockPair.cs rename to shadowsocks-csharp/3rd/zxing/qrcode/encoder/BlockPair.cs diff --git a/shadowsocks-csharp/3rd/zxing/ByteMatrix.cs b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/ByteMatrix.cs similarity index 100% rename from shadowsocks-csharp/3rd/zxing/ByteMatrix.cs rename to shadowsocks-csharp/3rd/zxing/qrcode/encoder/ByteMatrix.cs diff --git a/shadowsocks-csharp/3rd/zxing/Encoder.cs b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/Encoder.cs similarity index 67% rename from shadowsocks-csharp/3rd/zxing/Encoder.cs rename to shadowsocks-csharp/3rd/zxing/qrcode/encoder/Encoder.cs index ae9996e9..32826a00 100755 --- a/shadowsocks-csharp/3rd/zxing/Encoder.cs +++ b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/Encoder.cs @@ -30,6 +30,15 @@ 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"; @@ -52,15 +61,32 @@ namespace ZXing.QrCode.Internal /// Note that there is no way to encode bytes in MODE_KANJI. We might want to add EncodeWithMode() /// with which clients can specify the encoding mode. For now, we don't need the functionality. ///
- /// text to encode - /// error correction level to use - /// representing the encoded QR code + /// The content. + /// The ec level. public static QRCode encode(String content, ErrorCorrectionLevel ecLevel) { + return encode(content, ecLevel, null); + } + + /// + /// Encodes the specified content. + /// + /// The content. + /// The ec level. + /// The hints. + /// + public static QRCode encode(String content, + ErrorCorrectionLevel ecLevel, + IDictionary hints) + { // Determine what character encoding has been specified by the caller, if any #if !SILVERLIGHT || WINDOWS_PHONE - String encoding = DEFAULT_BYTE_MODE_ENCODING; - //bool generateECI = !DEFAULT_BYTE_MODE_ENCODING.Equals(encoding); + 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); #else // Silverlight supports only UTF-8 and UTF-16 out-of-the-box const string encoding = "UTF-8"; @@ -71,27 +97,12 @@ 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 = Mode.BYTE; + Mode mode = chooseMode(content, encoding); // This will store the header information, like mode and // length, as well as "header" segments like an ECI segment. BitArray headerBits = new BitArray(); - /* - // Append ECI segment if applicable - if (mode == Mode.BYTE && generateECI) - { - CharacterSetECI eci = CharacterSetECI.getCharacterSetECIByName(encoding); - if (eci != null) - { - var eciIsExplicitDisabled = (hints != null && hints.ContainsKey(EncodeHintType.DISABLE_ECI) ? (bool)hints[EncodeHintType.DISABLE_ECI] : false); - if (!eciIsExplicitDisabled) - { - appendECI(eci, headerBits); - } - } - } - * */ // (With ECI in place,) Write the mode marker appendModeInfo(mode, headerBits); @@ -156,6 +167,106 @@ namespace ZXing.QrCode.Internal return qrCode; } + /// + /// Gets the alphanumeric code. + /// + /// The code. + /// the code point of the table used in alphanumeric mode or + /// -1 if there is no corresponding code in the table. + internal static int getAlphanumericCode(int code) + { + if (code < ALPHANUMERIC_TABLE.Length) + { + return ALPHANUMERIC_TABLE[code]; + } + return -1; + } + + /// + /// Chooses the mode. + /// + /// The content. + /// + public static Mode chooseMode(String content) + { + return chooseMode(content, null); + } + + /// + /// 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}. + /// + /// The content. + /// The 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; + } + + 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, @@ -199,7 +310,7 @@ namespace ZXing.QrCode.Internal return version; } } - throw new Exception("Data too big"); + throw new WriterException("Data too big"); } /// @@ -212,7 +323,7 @@ namespace ZXing.QrCode.Internal int capacity = numDataBytes << 3; if (bits.Size > capacity) { - throw new Exception("data bits cannot fit in the QR Code" + bits.Size + " > " + + throw new WriterException("data bits cannot fit in the QR Code" + bits.Size + " > " + capacity); } for (int i = 0; i < 4 && bits.Size < capacity; ++i) @@ -237,7 +348,7 @@ namespace ZXing.QrCode.Internal } if (bits.Size != capacity) { - throw new Exception("Bits size does not equal capacity"); + throw new WriterException("Bits size does not equal capacity"); } } @@ -261,7 +372,7 @@ namespace ZXing.QrCode.Internal { if (blockID >= numRSBlocks) { - throw new Exception("Block ID too large"); + throw new WriterException("Block ID too large"); } // numRsBlocksInGroup2 = 196 % 5 = 1 int numRsBlocksInGroup2 = numTotalBytes % numRSBlocks; @@ -284,13 +395,13 @@ namespace ZXing.QrCode.Internal if (numEcBytesInGroup1 != numEcBytesInGroup2) { - throw new Exception("EC bytes mismatch"); + throw new WriterException("EC bytes mismatch"); } // 5 = 4 + 1. if (numRSBlocks != numRsBlocksInGroup1 + numRsBlocksInGroup2) { - throw new Exception("RS blocks mismatch"); + throw new WriterException("RS blocks mismatch"); } // 196 = (13 + 26) * 4 + (14 + 26) * 1 if (numTotalBytes != @@ -299,7 +410,7 @@ namespace ZXing.QrCode.Internal ((numDataBytesInGroup2 + numEcBytesInGroup2) * numRsBlocksInGroup2)) { - throw new Exception("Total bytes mismatch"); + throw new WriterException("Total bytes mismatch"); } if (blockID < numRsBlocksInGroup1) @@ -335,7 +446,7 @@ namespace ZXing.QrCode.Internal if (bits.SizeInBytes != numDataBytes) { - throw new Exception("Number of bits and data bytes does not match"); + throw new WriterException("Number of bits and data bytes does not match"); } // Step 1. Divide data bytes into blocks and generate error correction bytes for them. We'll @@ -369,7 +480,7 @@ namespace ZXing.QrCode.Internal if (numDataBytes != dataBytesOffset) { - throw new Exception("Data bytes does not match offset"); + throw new WriterException("Data bytes does not match offset"); } BitArray result = new BitArray(); @@ -400,7 +511,7 @@ namespace ZXing.QrCode.Internal } if (numTotalBytes != result.SizeInBytes) { // Should be same. - throw new Exception("Interleaving error: " + numTotalBytes + " and " + + throw new WriterException("Interleaving error: " + numTotalBytes + " and " + result.SizeInBytes + " differ."); } @@ -450,7 +561,7 @@ namespace ZXing.QrCode.Internal int numBits = mode.getCharacterCountBits(version); if (numLetters >= (1 << numBits)) { - throw new Exception(numLetters + " is bigger than " + ((1 << numBits) - 1)); + throw new WriterException(numLetters + " is bigger than " + ((1 << numBits) - 1)); } bits.appendBits(numLetters, numBits); } @@ -467,10 +578,83 @@ 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); + throw new WriterException("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 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) @@ -504,7 +688,7 @@ namespace ZXing.QrCode.Internal #endif catch (Exception uee) { - throw new Exception(uee.Message, uee); + throw new WriterException(uee.Message, uee); } foreach (byte b in bytes) { @@ -512,6 +696,42 @@ 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) diff --git a/shadowsocks-csharp/3rd/zxing/MaskUtil.cs b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/MaskUtil.cs similarity index 100% rename from shadowsocks-csharp/3rd/zxing/MaskUtil.cs rename to shadowsocks-csharp/3rd/zxing/qrcode/encoder/MaskUtil.cs diff --git a/shadowsocks-csharp/3rd/zxing/MatrixUtil.cs b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/MatrixUtil.cs similarity index 96% rename from shadowsocks-csharp/3rd/zxing/MatrixUtil.cs rename to shadowsocks-csharp/3rd/zxing/qrcode/encoder/MatrixUtil.cs index ffd9c7b4..9fcde4e1 100755 --- a/shadowsocks-csharp/3rd/zxing/MatrixUtil.cs +++ b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/MatrixUtil.cs @@ -14,7 +14,6 @@ * limitations under the License. */ -using System; using ZXing.Common; namespace ZXing.QrCode.Internal @@ -310,7 +309,7 @@ namespace ZXing.QrCode.Internal // All bits should be consumed. if (bitIndex != dataBits.Size) { - throw new Exception("Not all bits consumed: " + bitIndex + '/' + dataBits.Size); + throw new WriterException("Not all bits consumed: " + bitIndex + '/' + dataBits.Size); } } @@ -366,9 +365,6 @@ namespace ZXing.QrCode.Internal /// public static int calculateBCHCode(int value, int poly) { - if (poly == 0) - throw new ArgumentException("0 polynominal", "poly"); - // If poly is "1 1111 0010 0101" (version info poly), msbSetInPoly is 13. We'll subtract 1 // from 13 to make it 12. int msbSetInPoly = findMSBSet(poly); @@ -394,7 +390,7 @@ namespace ZXing.QrCode.Internal { if (!QRCode.isValidMaskPattern(maskPattern)) { - throw new Exception("Invalid mask pattern"); + throw new WriterException("Invalid mask pattern"); } int typeInfo = (ecLevel.Bits << 3) | maskPattern; bits.appendBits(typeInfo, 5); @@ -409,7 +405,7 @@ namespace ZXing.QrCode.Internal if (bits.Size != 15) { // Just in case. - throw new Exception("should not happen but we got: " + bits.Size); + throw new WriterException("should not happen but we got: " + bits.Size); } } @@ -428,7 +424,7 @@ namespace ZXing.QrCode.Internal if (bits.Size != 18) { // Just in case. - throw new Exception("should not happen but we got: " + bits.Size); + throw new WriterException("should not happen but we got: " + bits.Size); } } @@ -472,7 +468,7 @@ namespace ZXing.QrCode.Internal { if (matrix[8, matrix.Height - 8] == 0) { - throw new Exception(); + throw new WriterException(); } matrix[8, matrix.Height - 8] = 1; } @@ -483,7 +479,7 @@ namespace ZXing.QrCode.Internal { if (!isEmpty(matrix[xStart + x, yStart])) { - throw new Exception(); + throw new WriterException(); } matrix[xStart + x, yStart] = 0; } @@ -495,7 +491,7 @@ namespace ZXing.QrCode.Internal { if (!isEmpty(matrix[xStart, yStart + y])) { - throw new Exception(); + throw new WriterException(); } matrix[xStart, yStart + y] = 0; } diff --git a/shadowsocks-csharp/3rd/zxing/QRCode.cs b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/QRCode.cs similarity index 67% rename from shadowsocks-csharp/3rd/zxing/QRCode.cs rename to shadowsocks-csharp/3rd/zxing/qrcode/encoder/QRCode.cs index 123d4f18..90d10bf5 100755 --- a/shadowsocks-csharp/3rd/zxing/QRCode.cs +++ b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/QRCode.cs @@ -21,7 +21,7 @@ namespace ZXing.QrCode.Internal { /// satorux@google.com (Satoru Takabayashi) - creator /// dswitkin@google.com (Daniel Switkin) - ported from C++ - public class QRCode + public sealed class QRCode { /// /// @@ -77,6 +77,40 @@ namespace ZXing.QrCode.Internal public ByteMatrix Matrix { get; set; } /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + 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(); + } + + /// /// Check if "mask_pattern" is valid. /// /// The mask pattern. diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/encoder/QrCodeEncodingOptions.cs b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/QrCodeEncodingOptions.cs new file mode 100755 index 00000000..41e87a08 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/QrCodeEncodingOptions.cs @@ -0,0 +1,110 @@ +/* + * Copyright 2012 ZXing.Net 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 ZXing.Common; +using ZXing.QrCode.Internal; + +namespace ZXing.QrCode +{ + /// + /// The class holds the available options for the QrCodeWriter + /// + [Serializable] + public class QrCodeEncodingOptions : EncodingOptions + { + /// + /// 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 + /// {@link com.google.zxing.qrcode.decoder.ErrorCorrectionLevel ErrorCorrectionLevel}. + /// + public ErrorCorrectionLevel ErrorCorrection + { + get + { + if (Hints.ContainsKey(EncodeHintType.ERROR_CORRECTION)) + { + return (ErrorCorrectionLevel) Hints[EncodeHintType.ERROR_CORRECTION]; + } + return null; + } + set + { + if (value == null) + { + if (Hints.ContainsKey(EncodeHintType.ERROR_CORRECTION)) + Hints.Remove(EncodeHintType.ERROR_CORRECTION); + } + else + { + Hints[EncodeHintType.ERROR_CORRECTION] = value; + } + } + } + + /// + /// Specifies what character encoding to use where applicable (type {@link String}) + /// + public string CharacterSet + { + get + { + if (Hints.ContainsKey(EncodeHintType.CHARACTER_SET)) + { + return (string) Hints[EncodeHintType.CHARACTER_SET]; + } + return null; + } + set + { + if (value == null) + { + if (Hints.ContainsKey(EncodeHintType.CHARACTER_SET)) + Hints.Remove(EncodeHintType.CHARACTER_SET); + } + else + { + Hints[EncodeHintType.CHARACTER_SET] = value; + } + } + } + + /// + /// Explicitly disables ECI segment when generating QR Code + /// 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. + /// + public bool DisableECI + { + get + { + if (Hints.ContainsKey(EncodeHintType.DISABLE_ECI)) + { + return (bool)Hints[EncodeHintType.DISABLE_ECI]; + } + return false; + } + set + { + Hints[EncodeHintType.DISABLE_ECI] = value; + } + } + } +} diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index d14d7287..89cb782c 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -70,20 +70,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + From 7927811ba33b04d5a7e1fb8e1cd4883655f7b63f Mon Sep 17 00:00:00 2001 From: clowwindy Date: Mon, 12 Jan 2015 00:38:12 +0800 Subject: [PATCH 23/45] add reader --- shadowsocks-csharp/3rd/zxing/BarcodeFormat.cs | 89 +++++++ .../3rd/zxing/BaseLuminanceSource.cs | 206 +++++++++++++++++ shadowsocks-csharp/3rd/zxing/Binarizer.cs | 104 +++++++++ shadowsocks-csharp/3rd/zxing/BinaryBitmap.cs | 186 +++++++++++++++ .../3rd/zxing/BitmapLuminanceSource.cs | 242 +++++++++++++++++++ shadowsocks-csharp/3rd/zxing/LuminanceSource.cs | 198 ++++++++++++++++ shadowsocks-csharp/3rd/zxing/Reader.cs | 59 +++++ shadowsocks-csharp/3rd/zxing/ReaderException.cs | 71 ++++++ shadowsocks-csharp/3rd/zxing/Result.cs | 161 +++++++++++++ shadowsocks-csharp/3rd/zxing/ResultMetadataType.cs | 102 +++++++++ .../3rd/zxing/qrcode/QRCodeReader.cs | 255 +++++++++++++++++++++ shadowsocks-csharp/View/MenuViewController.cs | 39 ++++ shadowsocks-csharp/shadowsocks-csharp.csproj | 11 + 13 files changed, 1723 insertions(+) create mode 100755 shadowsocks-csharp/3rd/zxing/BarcodeFormat.cs create mode 100755 shadowsocks-csharp/3rd/zxing/BaseLuminanceSource.cs create mode 100755 shadowsocks-csharp/3rd/zxing/Binarizer.cs create mode 100755 shadowsocks-csharp/3rd/zxing/BinaryBitmap.cs create mode 100755 shadowsocks-csharp/3rd/zxing/BitmapLuminanceSource.cs create mode 100755 shadowsocks-csharp/3rd/zxing/LuminanceSource.cs create mode 100755 shadowsocks-csharp/3rd/zxing/Reader.cs create mode 100755 shadowsocks-csharp/3rd/zxing/ReaderException.cs create mode 100755 shadowsocks-csharp/3rd/zxing/Result.cs create mode 100755 shadowsocks-csharp/3rd/zxing/ResultMetadataType.cs create mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/QRCodeReader.cs diff --git a/shadowsocks-csharp/3rd/zxing/BarcodeFormat.cs b/shadowsocks-csharp/3rd/zxing/BarcodeFormat.cs new file mode 100755 index 00000000..e20f6535 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/BarcodeFormat.cs @@ -0,0 +1,89 @@ +/* +* 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. +*/ + +namespace ZXing +{ + /// + /// Enumerates barcode formats known to this package. + /// + /// Sean Owen + [System.Flags] + public enum BarcodeFormat + { + /// Aztec 2D barcode format. + AZTEC = 1, + + /// CODABAR 1D format. + CODABAR = 2, + + /// Code 39 1D format. + CODE_39 = 4, + + /// Code 93 1D format. + CODE_93 = 8, + + /// Code 128 1D format. + CODE_128 = 16, + + /// Data Matrix 2D barcode format. + DATA_MATRIX = 32, + + /// EAN-8 1D format. + EAN_8 = 64, + + /// EAN-13 1D format. + EAN_13 = 128, + + /// ITF (Interleaved Two of Five) 1D format. + ITF = 256, + + /// MaxiCode 2D barcode format. + MAXICODE = 512, + + /// PDF417 format. + PDF_417 = 1024, + + /// QR Code 2D barcode format. + QR_CODE = 2048, + + /// RSS 14 + RSS_14 = 4096, + + /// RSS EXPANDED + RSS_EXPANDED = 8192, + + /// UPC-A 1D format. + UPC_A = 16384, + + /// UPC-E 1D format. + UPC_E = 32768, + + /// UPC/EAN extension format. Not a stand-alone format. + UPC_EAN_EXTENSION = 65536, + + /// MSI + MSI = 131072, + + /// Plessey + PLESSEY = 262144, + + /// + /// UPC_A | UPC_E | EAN_13 | EAN_8 | CODABAR | CODE_39 | CODE_93 | CODE_128 | ITF | RSS_14 | RSS_EXPANDED + /// without MSI (to many false-positives) + /// + All_1D = UPC_A | UPC_E | EAN_13 | EAN_8 | CODABAR | CODE_39 | CODE_93 | CODE_128 | ITF | RSS_14 | RSS_EXPANDED + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/BaseLuminanceSource.cs b/shadowsocks-csharp/3rd/zxing/BaseLuminanceSource.cs new file mode 100755 index 00000000..c91d81db --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/BaseLuminanceSource.cs @@ -0,0 +1,206 @@ +/* +* Copyright 2012 ZXing.Net 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 +{ + /// + /// The base class for luminance sources which supports + /// cropping and rotating based upon the luminance values. + /// + public abstract class BaseLuminanceSource : LuminanceSource + { + // the following channel weights give nearly the same + // gray scale picture as the java version with BufferedImage.TYPE_BYTE_GRAY + // they are used in sub classes for luminance / gray scale calculation + protected const int RChannelWeight = 19562; + protected const int GChannelWeight = 38550; + protected const int BChannelWeight = 7424; + protected const int ChannelWeight = 16; + + /// + /// + /// + protected byte[] luminances; + + /// + /// Initializes a new instance of the class. + /// + /// The width. + /// The height. + protected BaseLuminanceSource(int width, int height) + : base(width, height) + { + luminances = new byte[width * height]; + } + + /// + /// Initializes a new instance of the class. + /// + /// The luminance array. + /// The width. + /// The height. + protected BaseLuminanceSource(byte[] luminanceArray, int width, int height) + : base(width, height) + { + luminances = new byte[width * height]; + Buffer.BlockCopy(luminanceArray, 0, luminances, 0, width * height); + } + + /// + /// Fetches one row of luminance data from the underlying platform's bitmap. Values range from + /// 0 (black) to 255 (white). It is preferable for implementations of this method + /// to only fetch this row rather than the whole image, since no 2D Readers may be installed and + /// getMatrix() may never be called. + /// + /// The row to fetch, 0 <= y < Height. + /// An optional preallocated array. If null or too small, it will be ignored. + /// Always use the returned object, and ignore the .length of the array. + /// + /// An array containing the luminance data. + /// + override public byte[] getRow(int y, byte[] row) + { + int width = Width; + if (row == null || row.Length < width) + { + row = new byte[width]; + } + for (int i = 0; i < width; i++) + row[i] = luminances[y * width + i]; + return row; + } + + public override byte[] Matrix + { + get { return luminances; } + } + + /// + /// Returns a new object with rotated image data by 90 degrees counterclockwise. + /// Only callable if {@link #isRotateSupported()} is true. + /// + /// + /// A rotated version of this object. + /// + public override LuminanceSource rotateCounterClockwise() + { + var rotatedLuminances = new byte[Width * Height]; + var newWidth = Height; + var newHeight = Width; + var localLuminances = Matrix; + for (var yold = 0; yold < Height; yold++) + { + for (var xold = 0; xold < Width; xold++) + { + var ynew = newHeight - xold - 1; + var xnew = yold; + rotatedLuminances[ynew * newWidth + xnew] = localLuminances[yold * Width + xold]; + } + } + return CreateLuminanceSource(rotatedLuminances, newWidth, newHeight); + } + + /// + /// TODO: not implemented yet + /// + /// + /// A rotated version of this object. + /// + public override LuminanceSource rotateCounterClockwise45() + { + // TODO: implement a good 45 degrees rotation without lost of information + return base.rotateCounterClockwise45(); + } + + /// + /// + /// Whether this subclass supports counter-clockwise rotation. + public override bool RotateSupported + { + get + { + return true; + } + } + + /// + /// Returns a new object with cropped image data. Implementations may keep a reference to the + /// original data rather than a copy. Only callable if CropSupported is true. + /// + /// The left coordinate, 0 <= left < Width. + /// The top coordinate, 0 <= top <= Height. + /// The width of the rectangle to crop. + /// The height of the rectangle to crop. + /// + /// A cropped version of this object. + /// + public override LuminanceSource crop(int left, int top, int width, int height) + { + if (left + width > Width || top + height > Height) + { + throw new ArgumentException("Crop rectangle does not fit within image data."); + } + var croppedLuminances = new byte[width * height]; + var oldLuminances = Matrix; + var oldWidth = Width; + var oldRightBound = left + width; + var oldBottomBound = top + height; + for (int yold = top, ynew = 0; yold < oldBottomBound; yold++, ynew++) + { + for (int xold = left, xnew = 0; xold < oldRightBound; xold++, xnew++) + { + croppedLuminances[ynew * width + xnew] = oldLuminances[yold * oldWidth + xold]; + } + } + return CreateLuminanceSource(croppedLuminances, width, height); + } + + /// + /// + /// Whether this subclass supports cropping. + public override bool CropSupported + { + get + { + return true; + } + } + + /// + /// + /// Whether this subclass supports invertion. + public override bool InversionSupported + { + get + { + return true; + } + } + + + /// + /// Should create a new luminance source with the right class type. + /// The method is used in methods crop and rotate. + /// + /// The new luminances. + /// The width. + /// The height. + /// + protected abstract LuminanceSource CreateLuminanceSource(byte[] newLuminances, int width, int height); + } +} diff --git a/shadowsocks-csharp/3rd/zxing/Binarizer.cs b/shadowsocks-csharp/3rd/zxing/Binarizer.cs new file mode 100755 index 00000000..213ec66a --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/Binarizer.cs @@ -0,0 +1,104 @@ +/* +* Copyright 2009 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 ZXing.Common; + +namespace ZXing +{ + /// This class hierarchy provides a set of methods to convert luminance data to 1 bit data. + /// It allows the algorithm to vary polymorphically, for example allowing a very expensive + /// thresholding technique for servers and a fast one for mobile. It also permits the implementation + /// to vary, e.g. a JNI version for Android and a Java fallback version for other platforms. + /// + /// dswitkin@google.com (Daniel Switkin) + /// + public abstract class Binarizer + { + private readonly LuminanceSource source; + + /// + /// Initializes a new instance of the class. + /// + /// The source. + protected internal Binarizer(LuminanceSource source) + { + if (source == null) + { + throw new ArgumentException("Source must be non-null."); + } + this.source = source; + } + + /// + /// Gets the luminance source object. + /// + virtual public LuminanceSource LuminanceSource + { + get + { + return source; + } + } + + /// Converts one row of luminance data to 1 bit data. May actually do the conversion, or return + /// cached data. Callers should assume this method is expensive and call it as seldom as possible. + /// This method is intended for decoding 1D barcodes and may choose to apply sharpening. + /// For callers which only examine one row of pixels at a time, the same BitArray should be reused + /// and passed in with each call for performance. However it is legal to keep more than one row + /// at a time if needed. + /// + /// The row to fetch, 0 <= y < bitmap height. + /// An optional preallocated array. If null or too small, it will be ignored. + /// If used, the Binarizer will call BitArray.clear(). Always use the returned object. + /// + /// The array of bits for this row (true means black). + public abstract BitArray getBlackRow(int y, BitArray row); + + /// Converts a 2D array of luminance data to 1 bit data. As above, assume this method is expensive + /// and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or + /// may not apply sharpening. Therefore, a row from this matrix may not be identical to one + /// fetched using getBlackRow(), so don't mix and match between them. + /// + /// The 2D array of bits for the image (true means black). + public abstract BitMatrix BlackMatrix { get; } + + /// Creates a new object with the same type as this Binarizer implementation, but with pristine + /// state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache + /// of 1 bit data. See Effective Java for why we can't use Java's clone() method. + /// + /// The LuminanceSource this Binarizer will operate on. + /// A new concrete Binarizer implementation object. + public abstract Binarizer createBinarizer(LuminanceSource source); + + /// + /// Gets the width of the luminance source object. + /// + public int Width + { + get { return source.Width; } + } + + /// + /// Gets the height of the luminance source object. + /// + public int Height + { + get { return source.Height; } + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/BinaryBitmap.cs b/shadowsocks-csharp/3rd/zxing/BinaryBitmap.cs new file mode 100755 index 00000000..fea1b266 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/BinaryBitmap.cs @@ -0,0 +1,186 @@ +/* +* Copyright 2009 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 ZXing.Common; + +namespace ZXing +{ + + /// This class is the core bitmap class used by ZXing to represent 1 bit data. Reader objects + /// accept a BinaryBitmap and attempt to decode it. + /// + /// + /// dswitkin@google.com (Daniel Switkin) + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + + public sealed class BinaryBitmap + { + private Binarizer binarizer; + private BitMatrix matrix; + + public BinaryBitmap(Binarizer binarizer) + { + if (binarizer == null) + { + throw new ArgumentException("Binarizer must be non-null."); + } + this.binarizer = binarizer; + } + + /// The width of the bitmap. + /// + public int Width + { + get + { + return binarizer.Width; + } + + } + /// The height of the bitmap. + /// + public int Height + { + get + { + return binarizer.Height; + } + + } + + /// Converts one row of luminance data to 1 bit data. May actually do the conversion, or return + /// cached data. Callers should assume this method is expensive and call it as seldom as possible. + /// This method is intended for decoding 1D barcodes and may choose to apply sharpening. + /// + /// + /// The row to fetch, 0 <= y < bitmap height. + /// + /// An optional preallocated array. If null or too small, it will be ignored. + /// If used, the Binarizer will call BitArray.clear(). Always use the returned object. + /// + /// The array of bits for this row (true means black). + /// + public BitArray getBlackRow(int y, BitArray row) + { + return binarizer.getBlackRow(y, row); + } + + /// Converts a 2D array of luminance data to 1 bit. As above, assume this method is expensive + /// and do not call it repeatedly. This method is intended for decoding 2D barcodes and may or + /// may not apply sharpening. Therefore, a row from this matrix may not be identical to one + /// fetched using getBlackRow(), so don't mix and match between them. + /// + /// + /// The 2D array of bits for the image (true means black). + /// + public BitMatrix BlackMatrix + { + get + { + // The matrix is created on demand the first time it is requested, then cached. There are two + // reasons for this: + // 1. This work will never be done if the caller only installs 1D Reader objects, or if a + // 1D Reader finds a barcode before the 2D Readers run. + // 2. This work will only be done once even if the caller installs multiple 2D Readers. + if (matrix == null) + { + matrix = binarizer.BlackMatrix; + } + return matrix; + } + } + + /// Whether this bitmap can be cropped. + /// + public bool CropSupported + { + get + { + return binarizer.LuminanceSource.CropSupported; + } + + } + + /// Returns a new object with cropped image data. Implementations may keep a reference to the + /// original data rather than a copy. Only callable if isCropSupported() is true. + /// + /// + /// The left coordinate, 0 <= left < getWidth(). + /// + /// The top coordinate, 0 <= top <= getHeight(). + /// + /// The width of the rectangle to crop. + /// + /// The height of the rectangle to crop. + /// + /// A cropped version of this object. + /// + public BinaryBitmap crop(int left, int top, int width, int height) + { + var newSource = binarizer.LuminanceSource.crop(left, top, width, height); + return new BinaryBitmap(binarizer.createBinarizer(newSource)); + } + + /// Whether this bitmap supports counter-clockwise rotation. + /// + public bool RotateSupported + { + get + { + return binarizer.LuminanceSource.RotateSupported; + } + + } + + /// + /// Returns a new object with rotated image data by 90 degrees counterclockwise. + /// Only callable if {@link #isRotateSupported()} is true. + /// + /// A rotated version of this object. + /// + public BinaryBitmap rotateCounterClockwise() + { + var newSource = binarizer.LuminanceSource.rotateCounterClockwise(); + return new BinaryBitmap(binarizer.createBinarizer(newSource)); + } + + /// + /// Returns a new object with rotated image data by 45 degrees counterclockwise. + /// Only callable if {@link #isRotateSupported()} is true. + /// + /// A rotated version of this object. + public BinaryBitmap rotateCounterClockwise45() + { + LuminanceSource newSource = binarizer.LuminanceSource.rotateCounterClockwise45(); + return new BinaryBitmap(binarizer.createBinarizer(newSource)); + } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override string ToString() + { + var blackMatrix = BlackMatrix; + return blackMatrix != null ? blackMatrix.ToString() : String.Empty; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/BitmapLuminanceSource.cs b/shadowsocks-csharp/3rd/zxing/BitmapLuminanceSource.cs new file mode 100755 index 00000000..8c61f531 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/BitmapLuminanceSource.cs @@ -0,0 +1,242 @@ +/* +* Copyright 2012 ZXing.Net 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.Drawing.Imaging; +using System.Drawing; +using System.Runtime.InteropServices; + +namespace ZXing +{ + public partial class BitmapLuminanceSource : BaseLuminanceSource + { + /// + /// Initializes a new instance of the class. + /// + /// The width. + /// The height. + protected BitmapLuminanceSource(int width, int height) + : base(width, height) + { + } + + /// + /// Initializes a new instance of the class + /// with the image of a Bitmap instance + /// + /// The bitmap. + public BitmapLuminanceSource(Bitmap bitmap) + : base(bitmap.Width, bitmap.Height) + { + var height = bitmap.Height; + var width = bitmap.Width; + + // In order to measure pure decoding speed, we convert the entire image to a greyscale array + // The underlying raster of image consists of bytes with the luminance values +#if WindowsCE + var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); +#else + var data = bitmap.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadOnly, bitmap.PixelFormat); +#endif + try + { + var stride = Math.Abs(data.Stride); + var pixelWidth = stride/width; + + if (pixelWidth > 4) + { + // old slow way for unsupported bit depth + Color c; + for (int y = 0; y < height; y++) + { + int offset = y*width; + for (int x = 0; x < width; x++) + { + c = bitmap.GetPixel(x, y); + luminances[offset + x] = (byte)((RChannelWeight * c.R + GChannelWeight * c.G + BChannelWeight * c.B) >> ChannelWeight); + } + } + } + else + { + var strideStep = data.Stride; + var buffer = new byte[stride]; + var ptrInBitmap = data.Scan0; + +#if !WindowsCE + // prepare palette for 1 and 8 bit indexed bitmaps + var luminancePalette = new byte[bitmap.Palette.Entries.Length]; + for (var index = 0; index < bitmap.Palette.Entries.Length; index++) + { + var color = bitmap.Palette.Entries[index]; + luminancePalette[index] = (byte) ((RChannelWeight*color.R + + GChannelWeight*color.G + + BChannelWeight*color.B) >> ChannelWeight); + } + if (bitmap.PixelFormat == PixelFormat.Format32bppArgb || + bitmap.PixelFormat == PixelFormat.Format32bppPArgb) + { + pixelWidth = 40; + } + if ((int)bitmap.PixelFormat == 8207 || + (bitmap.Flags & (int)ImageFlags.ColorSpaceCmyk) == (int)ImageFlags.ColorSpaceCmyk) + { + pixelWidth = 41; + } +#endif + + for (int y = 0; y < height; y++) + { + // copy a scanline not the whole bitmap because of memory usage + Marshal.Copy(ptrInBitmap, buffer, 0, stride); +#if NET40 + ptrInBitmap = IntPtr.Add(ptrInBitmap, strideStep); +#else + ptrInBitmap = new IntPtr(ptrInBitmap.ToInt64() + strideStep); +#endif + var offset = y*width; + switch (pixelWidth) + { +#if !WindowsCE + case 0: + for (int x = 0; x*8 < width; x++) + { + for (int subX = 0; subX < 8 && 8*x + subX < width; subX++) + { + var index = (buffer[x] >> (7 - subX)) & 1; + luminances[offset + 8*x + subX] = luminancePalette[index]; + } + } + break; + case 1: + for (int x = 0; x < width; x++) + { + luminances[offset + x] = luminancePalette[buffer[x]]; + } + break; +#endif + case 2: + // should be RGB565 or RGB555, assume RGB565 + { + var maxIndex = 2*width; + for (int index = 0; index < maxIndex; index += 2) + { + var byte1 = buffer[index]; + var byte2 = buffer[index + 1]; + + var b5 = byte1 & 0x1F; + var g5 = (((byte1 & 0xE0) >> 5) | ((byte2 & 0x03) << 3)) & 0x1F; + var r5 = (byte2 >> 2) & 0x1F; + var r8 = (r5*527 + 23) >> 6; + var g8 = (g5*527 + 23) >> 6; + var b8 = (b5*527 + 23) >> 6; + + luminances[offset] = (byte)((RChannelWeight * r8 + GChannelWeight * g8 + BChannelWeight * b8) >> ChannelWeight); + offset++; + } + } + break; + case 3: + { + var maxIndex = width*3; + for (int x = 0; x < maxIndex; x += 3) + { + var luminance = (byte) ((BChannelWeight*buffer[x] + + GChannelWeight*buffer[x + 1] + + RChannelWeight*buffer[x + 2]) >> ChannelWeight); + luminances[offset] = luminance; + offset++; + } + } + break; + case 4: + // 4 bytes without alpha channel value + { + var maxIndex = 4*width; + for (int x = 0; x < maxIndex; x += 4) + { + var luminance = (byte) ((BChannelWeight*buffer[x] + + GChannelWeight*buffer[x + 1] + + RChannelWeight*buffer[x + 2]) >> ChannelWeight); + + luminances[offset] = luminance; + offset++; + } + } + break; + case 40: + // with alpha channel; some barcodes are completely black if you + // only look at the r, g and b channel but the alpha channel controls + // the view + { + var maxIndex = 4*width; + for (int x = 0; x < maxIndex; x += 4) + { + var luminance = (byte) ((BChannelWeight*buffer[x] + + GChannelWeight*buffer[x + 1] + + RChannelWeight*buffer[x + 2]) >> ChannelWeight); + + // calculating the resulting luminance based upon a white background + // var alpha = buffer[x * pixelWidth + 3] / 255.0; + // luminance = (byte)(luminance * alpha + 255 * (1 - alpha)); + var alpha = buffer[x + 3]; + luminance = (byte) (((luminance*alpha) >> 8) + (255*(255 - alpha) >> 8) + 1); + luminances[offset] = luminance; + offset++; + } + } + break; + case 41: + // CMYK color space + { + var maxIndex = 4 * width; + for (int x = 0; x < maxIndex; x += 4) + { + var luminance = (byte) (255 - ((BChannelWeight*buffer[x] + + GChannelWeight*buffer[x + 1] + + RChannelWeight*buffer[x + 2]) >> ChannelWeight)); + // Ignore value of k at the moment + luminances[offset] = luminance; + offset++; + } + } + break; + default: + throw new NotSupportedException(); + } + } + } + } + finally + { + bitmap.UnlockBits(data); + } + } + + /// + /// Should create a new luminance source with the right class type. + /// The method is used in methods crop and rotate. + /// + /// The new luminances. + /// The width. + /// The height. + /// + protected override LuminanceSource CreateLuminanceSource(byte[] newLuminances, int width, int height) + { + return new BitmapLuminanceSource(width, height) { luminances = newLuminances }; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/LuminanceSource.cs b/shadowsocks-csharp/3rd/zxing/LuminanceSource.cs new file mode 100755 index 00000000..371a27c7 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/LuminanceSource.cs @@ -0,0 +1,198 @@ +/* +* Copyright 2009 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; + +namespace ZXing +{ + /// The purpose of this class hierarchy is to abstract different bitmap implementations across + /// platforms into a standard interface for requesting greyscale luminance values. The interface + /// only provides immutable methods; therefore crop and rotation create copies. This is to ensure + /// that one Reader does not modify the original luminance source and leave it in an unknown state + /// for other Readers in the chain. + /// + /// dswitkin@google.com (Daniel Switkin) + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + public abstract class LuminanceSource + { + private int width; + private int height; + + protected LuminanceSource(int width, int height) + { + this.width = width; + this.height = height; + } + + /// Fetches one row of luminance data from the underlying platform's bitmap. Values range from + /// 0 (black) to 255 (white). Because Java does not have an unsigned byte type, callers will have + /// to bitwise and with 0xff for each value. It is preferable for implementations of this method + /// to only fetch this row rather than the whole image, since no 2D Readers may be installed and + /// getMatrix() may never be called. + /// + /// + /// The row to fetch, 0 <= y < Height. + /// + /// An optional preallocated array. If null or too small, it will be ignored. + /// Always use the returned object, and ignore the .length of the array. + /// + /// An array containing the luminance data. + /// + public abstract byte[] getRow(int y, byte[] row); + + /// Fetches luminance data for the underlying bitmap. Values should be fetched using: + /// int luminance = array[y * width + x] & 0xff; + /// + /// + /// A row-major 2D array of luminance values. Do not use result.length as it may be + /// larger than width * height bytes on some platforms. Do not modify the contents + /// of the result. + /// + public abstract byte[] Matrix { get; } + + /// The width of the bitmap. + virtual public int Width + { + get + { + return width; + } + protected set + { + width = value; + } + } + + /// The height of the bitmap. + virtual public int Height + { + get + { + return height; + } + protected set + { + height = value; + } + } + + /// Whether this subclass supports cropping. + virtual public bool CropSupported + { + get + { + return false; + } + } + + /// Returns a new object with cropped image data. Implementations may keep a reference to the + /// original data rather than a copy. Only callable if CropSupported is true. + /// + /// + /// The left coordinate, 0 <= left < Width. + /// + /// The top coordinate, 0 <= top <= Height. + /// + /// The width of the rectangle to crop. + /// + /// The height of the rectangle to crop. + /// + /// A cropped version of this object. + /// + public virtual LuminanceSource crop(int left, int top, int width, int height) + { + throw new NotSupportedException("This luminance source does not support cropping."); + } + + /// Whether this subclass supports counter-clockwise rotation. + virtual public bool RotateSupported + { + get + { + return false; + } + } + + /// + /// Returns a new object with rotated image data by 90 degrees counterclockwise. + /// Only callable if {@link #isRotateSupported()} is true. + /// + /// A rotated version of this object. + /// + public virtual LuminanceSource rotateCounterClockwise() + { + throw new NotSupportedException("This luminance source does not support rotation."); + } + + /// + /// Returns a new object with rotated image data by 45 degrees counterclockwise. + /// Only callable if {@link #isRotateSupported()} is true. + /// + /// A rotated version of this object. + public virtual LuminanceSource rotateCounterClockwise45() + { + throw new NotSupportedException("This luminance source does not support rotation by 45 degrees."); + } + + /// + /// + /// Whether this subclass supports invertion. + virtual public bool InversionSupported + { + get + { + return false; + } + } + + override public String ToString() + { + var row = new byte[width]; + var result = new StringBuilder(height * (width + 1)); + for (int y = 0; y < height; y++) + { + row = getRow(y, row); + for (int x = 0; x < width; x++) + { + int luminance = row[x] & 0xFF; + char c; + if (luminance < 0x40) + { + c = '#'; + } + else if (luminance < 0x80) + { + c = '+'; + } + else if (luminance < 0xC0) + { + c = '.'; + } + else + { + c = ' '; + } + result.Append(c); + } + result.Append('\n'); + } + return result.ToString(); + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/Reader.cs b/shadowsocks-csharp/3rd/zxing/Reader.cs new file mode 100755 index 00000000..b96267af --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/Reader.cs @@ -0,0 +1,59 @@ +/* +* 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.Collections.Generic; + +namespace ZXing +{ + /// + /// Implementations of this interface can decode an image of a barcode in some format into + /// the String it encodes. For example, can + /// decode a QR code. The decoder may optionally receive hints from the caller which may help + /// it decode more quickly or accurately. + /// + /// See , which attempts to determine what barcode + /// format is present within the image as well, and then decodes it accordingly. + /// + /// Sean Owen + /// dswitkin@google.com (Daniel Switkin) + public interface Reader + { + /// + /// Locates and decodes a barcode in some format within an image. + /// + /// image of barcode to decode + /// String which the barcode encodes + Result decode(BinaryBitmap image); + + /// Locates and decodes a barcode in some format within an image. This method also accepts + /// hints, each possibly associated to some data, which may help the implementation decode. + /// + /// image of barcode to decode + /// passed as a from + /// to arbitrary data. The + /// meaning of the data depends upon the hint type. The implementation may or may not do + /// anything with these hints. + /// + /// String which the barcode encodes + Result decode(BinaryBitmap image, IDictionary hints); + + /// + /// Resets any internal state the implementation has after a decode, to prepare it + /// for reuse. + /// + void reset(); + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/ReaderException.cs b/shadowsocks-csharp/3rd/zxing/ReaderException.cs new file mode 100755 index 00000000..90936b5c --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/ReaderException.cs @@ -0,0 +1,71 @@ +/* +* 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 +{ + /// + /// The general exception class throw when something goes wrong during decoding of a barcode. + /// This includes, but is not limited to, failing checksums / error correction algorithms, being + /// unable to locate finder timing patterns, and so on. + /// + /// Sean Owen + [Serializable] + public class ReaderException : Exception + { + /// + /// Gets the instance. + /// + public static ReaderException Instance + { + get + { + return instance; + } + + } + + // TODO: Currently we throw up to 400 ReaderExceptions while scanning a single 240x240 image before + // rejecting it. This involves a lot of overhead and memory allocation, and affects both performance + // and latency on continuous scan clients. In the future, we should change all the decoders not to + // throw exceptions for routine events, like not finding a barcode on a given row. Instead, we + // should return error codes back to the callers, and simply delete this class. In the mean time, I + // have altered this class to be as lightweight as possible, by ignoring the exception string, and + // by disabling the generation of stack traces, which is especially time consuming. These are just + // temporary measures, pending the big cleanup. + + //UPGRADE_NOTE: Final was removed from the declaration of 'instance '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" + private static readonly ReaderException instance = new ReaderException(); + + // EXCEPTION TRACKING SUPPORT + // Identifies who is throwing exceptions and how often. To use: + // + // 1. Uncomment these lines and the code below which uses them. + // 2. Uncomment the two corresponding lines in j2se/CommandLineRunner.decode() + // 3. Change core to build as Java 1.5 temporarily + // private static int exceptionCount = 0; + // private static Map throwers = new HashMap(32); + + /// + /// Initializes a new instance of the class. + /// + protected ReaderException() + { + // do nothing + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/Result.cs b/shadowsocks-csharp/3rd/zxing/Result.cs new file mode 100755 index 00000000..3aa6f5b8 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/Result.cs @@ -0,0 +1,161 @@ +/* +* 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; +using System.Collections.Generic; + +namespace ZXing +{ + /// + /// Encapsulates the result of decoding a barcode within an image. + /// + public sealed class Result + { + /// raw text encoded by the barcode, if applicable, otherwise null + public String Text { get; private set; } + + /// raw bytes encoded by the barcode, if applicable, otherwise null + public byte[] RawBytes { get; private set; } + + /// + /// points related to the barcode in the image. These are typically points + /// identifying finder patterns or the corners of the barcode. The exact meaning is + /// specific to the type of barcode that was decoded. + /// + public ResultPoint[] ResultPoints { get; private set; } + + /// {@link BarcodeFormat} representing the format of the barcode that was decoded + public BarcodeFormat BarcodeFormat { get; private set; } + + /// + /// {@link Hashtable} mapping {@link ResultMetadataType} keys to values. May be + /// null. This contains optional metadata about what was detected about the barcode, + /// like orientation. + /// + public IDictionary ResultMetadata { get; private set; } + + /// + /// Gets the timestamp. + /// + public long Timestamp { get; private set; } + + /// + /// Initializes a new instance of the class. + /// + /// The text. + /// The raw bytes. + /// The result points. + /// The format. + public Result(String text, + byte[] rawBytes, + ResultPoint[] resultPoints, + BarcodeFormat format) + : this(text, rawBytes, resultPoints, format, DateTime.Now.Ticks) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The text. + /// The raw bytes. + /// The result points. + /// The format. + /// The timestamp. + public Result(String text, byte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format, long timestamp) + { + if (text == null && rawBytes == null) + { + throw new ArgumentException("Text and bytes are null"); + } + Text = text; + RawBytes = rawBytes; + ResultPoints = resultPoints; + BarcodeFormat = format; + ResultMetadata = null; + Timestamp = timestamp; + } + + /// + /// Adds one metadata to the result + /// + /// The type. + /// The value. + public void putMetadata(ResultMetadataType type, Object value) + { + if (ResultMetadata == null) + { + ResultMetadata = new Dictionary(); + } + ResultMetadata[type] = value; + } + + /// + /// Adds a list of metadata to the result + /// + /// The metadata. + public void putAllMetadata(IDictionary metadata) + { + if (metadata != null) + { + if (ResultMetadata == null) + { + ResultMetadata = metadata; + } + else + { + foreach (var entry in metadata) + ResultMetadata[entry.Key] = entry.Value; + } + } + } + + /// + /// Adds the result points. + /// + /// The new points. + public void addResultPoints(ResultPoint[] newPoints) + { + var oldPoints = ResultPoints; + if (oldPoints == null) + { + ResultPoints = newPoints; + } + else if (newPoints != null && newPoints.Length > 0) + { + var allPoints = new ResultPoint[oldPoints.Length + newPoints.Length]; + Array.Copy(oldPoints, 0, allPoints, 0, oldPoints.Length); + Array.Copy(newPoints, 0, allPoints, oldPoints.Length, newPoints.Length); + ResultPoints = allPoints; + } + } + + /// + /// Returns a that represents this instance. + /// + /// + /// A that represents this instance. + /// + public override String ToString() + { + if (Text == null) + { + return "[" + RawBytes.Length + " bytes]"; + } + return Text; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/ResultMetadataType.cs b/shadowsocks-csharp/3rd/zxing/ResultMetadataType.cs new file mode 100755 index 00000000..360357c8 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/ResultMetadataType.cs @@ -0,0 +1,102 @@ +/* + * 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 +{ + /// + /// Represents some type of metadata about the result of the decoding that the decoder + /// wishes to communicate back to the caller. + /// + /// Sean Owen + public enum ResultMetadataType + { + /// + /// Unspecified, application-specific metadata. Maps to an unspecified {@link Object}. + /// + OTHER, + + /// + /// Denotes the likely approximate orientation of the barcode in the image. This value + /// is given as degrees rotated clockwise from the normal, upright orientation. + /// For example a 1D barcode which was found by reading top-to-bottom would be + /// said to have orientation "90". This key maps to an {@link Integer} whose + /// value is in the range [0,360). + /// + ORIENTATION, + + /// + ///

2D barcode formats typically encode text, but allow for a sort of 'byte mode' + /// which is sometimes used to encode binary data. While {@link Result} makes available + /// the complete raw bytes in the barcode for these formats, it does not offer the bytes + /// from the byte segments alone.

+ ///

This maps to a {@link java.util.List} of byte arrays corresponding to the + /// raw bytes in the byte segments in the barcode, in order.

+ ///
+ BYTE_SEGMENTS, + + /// + /// Error correction level used, if applicable. The value type depends on the + /// format, but is typically a String. + /// + ERROR_CORRECTION_LEVEL, + + /// + /// For some periodicals, indicates the issue number as an {@link Integer}. + /// + ISSUE_NUMBER, + + /// + /// For some products, indicates the suggested retail price in the barcode as a + /// formatted {@link String}. + /// + SUGGESTED_PRICE, + + /// + /// For some products, the possible country of manufacture as a {@link String} denoting the + /// ISO country code. Some map to multiple possible countries, like "US/CA". + /// + POSSIBLE_COUNTRY, + + /// + /// For some products, the extension text + /// + UPC_EAN_EXTENSION, + + /// + /// If the code format supports structured append and + /// the current scanned code is part of one then the + /// sequence number is given with it. + /// + STRUCTURED_APPEND_SEQUENCE, + + /// + /// If the code format supports structured append and + /// the current scanned code is part of one then the + /// parity is given with it. + /// + STRUCTURED_APPEND_PARITY, + + /// + /// PDF417-specific metadata + /// + PDF417_EXTRA_METADATA, + + /// + /// Aztec-specific metadata + /// + AZTEC_EXTRA_METADATA + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/QRCodeReader.cs b/shadowsocks-csharp/3rd/zxing/qrcode/QRCodeReader.cs new file mode 100755 index 00000000..d4fcc770 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/qrcode/QRCodeReader.cs @@ -0,0 +1,255 @@ +/* + * 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; +using System.Collections.Generic; + +using ZXing.Common; +using ZXing.QrCode.Internal; + +namespace ZXing.QrCode +{ + /// + /// This implementation can detect and decode QR Codes in an image. + /// Sean Owen + /// + public class QRCodeReader : Reader + { + private static readonly ResultPoint[] NO_POINTS = new ResultPoint[0]; + + private readonly Decoder decoder = new Decoder(); + + /// + /// Gets the decoder. + /// + /// + protected Decoder getDecoder() + { + return decoder; + } + + /// + /// Locates and decodes a QR code in an image. + /// + /// a String representing the content encoded by the QR code + /// + public Result decode(BinaryBitmap image) + { + return decode(image, null); + } + + /// + /// Locates and decodes a barcode in some format within an image. This method also accepts + /// hints, each possibly associated to some data, which may help the implementation decode. + /// + /// image of barcode to decode + /// passed as a from + /// to arbitrary data. The + /// meaning of the data depends upon the hint type. The implementation may or may not do + /// anything with these hints. + /// + /// String which the barcode encodes + /// + public Result decode(BinaryBitmap image, IDictionary hints) + { + DecoderResult decoderResult; + ResultPoint[] points; + if (image == null || image.BlackMatrix == null) + { + // something is wrong with the image + return null; + } + if (hints != null && hints.ContainsKey(DecodeHintType.PURE_BARCODE)) + { + var bits = extractPureBits(image.BlackMatrix); + if (bits == null) + return null; + decoderResult = decoder.decode(bits, hints); + points = NO_POINTS; + } + else + { + var detectorResult = new Detector(image.BlackMatrix).detect(hints); + if (detectorResult == null) + return null; + decoderResult = decoder.decode(detectorResult.Bits, hints); + points = detectorResult.Points; + } + if (decoderResult == null) + return null; + + // If the code was mirrored: swap the bottom-left and the top-right points. + var data = decoderResult.Other as QRCodeDecoderMetaData; + if (data != null) + { + data.applyMirroredCorrection(points); + } + + var result = new Result(decoderResult.Text, decoderResult.RawBytes, points, BarcodeFormat.QR_CODE); + var byteSegments = decoderResult.ByteSegments; + if (byteSegments != null) + { + result.putMetadata(ResultMetadataType.BYTE_SEGMENTS, byteSegments); + } + var ecLevel = decoderResult.ECLevel; + if (ecLevel != null) + { + result.putMetadata(ResultMetadataType.ERROR_CORRECTION_LEVEL, ecLevel); + } + if (decoderResult.StructuredAppend) + { + result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_SEQUENCE, decoderResult.StructuredAppendSequenceNumber); + result.putMetadata(ResultMetadataType.STRUCTURED_APPEND_PARITY, decoderResult.StructuredAppendParity); + } + return result; + } + + /// + /// Resets any internal state the implementation has after a decode, to prepare it + /// for reuse. + /// + public void reset() + { + // do nothing + } + + /// + /// This method detects a code in a "pure" image -- that is, pure monochrome image + /// which contains only an unrotated, unskewed, image of a code, with some white border + /// around it. This is a specialized method that works exceptionally fast in this special + /// case. + /// + /// + /// + private static BitMatrix extractPureBits(BitMatrix image) + { + int[] leftTopBlack = image.getTopLeftOnBit(); + int[] rightBottomBlack = image.getBottomRightOnBit(); + if (leftTopBlack == null || rightBottomBlack == null) + { + return null; + } + + float moduleSize; + if (!QRCodeReader.moduleSize(leftTopBlack, image, out moduleSize)) + return null; + + int top = leftTopBlack[1]; + int bottom = rightBottomBlack[1]; + int left = leftTopBlack[0]; + int right = rightBottomBlack[0]; + + // Sanity check! + if (left >= right || top >= bottom) + { + return null; + } + + if (bottom - top != right - left) + { + // Special case, where bottom-right module wasn't black so we found something else in the last row + // Assume it's a square, so use height as the width + right = left + (bottom - top); + } + + int matrixWidth = (int)Math.Round((right - left + 1) / moduleSize); + int matrixHeight = (int)Math.Round((bottom - top + 1) / moduleSize); + if (matrixWidth <= 0 || matrixHeight <= 0) + { + return null; + } + if (matrixHeight != matrixWidth) + { + // Only possibly decode square regions + return null; + } + + // Push in the "border" by half the module width so that we start + // sampling in the middle of the module. Just in case the image is a + // little off, this will help recover. + int nudge = (int)(moduleSize / 2.0f); + top += nudge; + left += nudge; + + // But careful that this does not sample off the edge + int nudgedTooFarRight = left + (int)((matrixWidth - 1) * moduleSize) - (right - 1); + if (nudgedTooFarRight > 0) + { + if (nudgedTooFarRight > nudge) + { + // Neither way fits; abort + return null; + } + left -= nudgedTooFarRight; + } + int nudgedTooFarDown = top + (int)((matrixHeight - 1) * moduleSize) - (bottom - 1); + if (nudgedTooFarDown > 0) + { + if (nudgedTooFarDown > nudge) + { + // Neither way fits; abort + return null; + } + top -= nudgedTooFarDown; + } + + // Now just read off the bits + BitMatrix bits = new BitMatrix(matrixWidth, matrixHeight); + for (int y = 0; y < matrixHeight; y++) + { + int iOffset = top + (int)(y * moduleSize); + for (int x = 0; x < matrixWidth; x++) + { + if (image[left + (int)(x * moduleSize), iOffset]) + { + bits[x, y] = true; + } + } + } + return bits; + } + + private static bool moduleSize(int[] leftTopBlack, BitMatrix image, out float msize) + { + int height = image.Height; + int width = image.Width; + int x = leftTopBlack[0]; + int y = leftTopBlack[1]; + bool inBlack = true; + int transitions = 0; + while (x < width && y < height) + { + if (inBlack != image[x, y]) + { + if (++transitions == 5) + { + break; + } + inBlack = !inBlack; + } + x++; + y++; + } + if (x == width || y == height) + { + msize = 0.0f; + return false; + } + msize = (x - leftTopBlack[0]) / 7.0f; + return true; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 3d875f3e..acd46995 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -357,6 +357,45 @@ namespace Shadowsocks.View qrCodeForm.Show(); } + private void ScanQRCodeItem_Click(object sender, EventArgs e) + { + /* + using (Bitmap image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, + Screen.PrimaryScreen.Bounds.Height)) + { + using (Graphics g = Graphics.FromImage(bmpScreenCapture)) + { + g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, + Screen.PrimaryScreen.Bounds.Y, + 0, 0, + bmpScreenCapture.Size, + CopyPixelOperation.SourceCopy); + } + resultPoints.Clear(); + /* var reader = new BarcodeReader + { + PossibleFormats = new List + { + BarcodeFormat.QR_CODE + } + }; + + var result = reader.Decode(image); + var result = barcodeReader.Decode(image); + var timerStart = DateTime.Now.Ticks; + var timerStop = DateTime.Now.Ticks; + + if (result == null) + { + txtDecoderContent.Text = "No barcode recognized"; + } + labDuration.Text = new TimeSpan(timerStop - timerStart).Milliseconds.ToString("0 ms"); + + } + } + * */ + } + private void AutoStartupItem_Click(object sender, EventArgs e) { AutoStartupItem.Checked = !AutoStartupItem.Checked; if (!AutoStartup.Set(AutoStartupItem.Checked)) { diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 89cb782c..4c335313 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -70,6 +70,11 @@
+ + + + + @@ -88,6 +93,7 @@ + @@ -112,6 +118,11 @@ + + + + + From f6939f111975601442c69f5cd63ca4d601d06b82 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Mon, 12 Jan 2015 01:04:36 +0800 Subject: [PATCH 24/45] qrcode scan works --- shadowsocks-csharp/3rd/zxing/BarcodeReader.cs | 152 +++++++ .../3rd/zxing/BarcodeReaderGeneric.cs | 436 +++++++++++++++++++++ shadowsocks-csharp/3rd/zxing/IBarcodeReader.cs | 161 ++++++++ .../3rd/zxing/IBarcodeReaderGeneric.cs | 123 ++++++ shadowsocks-csharp/3rd/zxing/RGBLuminanceSource.cs | 314 +++++++++++++++ .../3rd/zxing/common/CharacterSetECI.cs | 128 ++++++ .../3rd/zxing/common/DecodingOptions.cs | 370 +++++++++++++++++ shadowsocks-csharp/3rd/zxing/common/ECI.cs | 66 ++++ .../3rd/zxing/common/GlobalHistogramBinarizer.cs | 243 ++++++++++++ .../3rd/zxing/common/HybridBinarizer.cs | 288 ++++++++++++++ shadowsocks-csharp/3rd/zxing/common/StringUtils.cs | 266 +++++++++++++ shadowsocks-csharp/3rd/zxing/net2.0/Action.cs | 102 +++++ shadowsocks-csharp/3rd/zxing/net2.0/Func.cs | 122 ++++++ .../3rd/zxing/net2.0/TimeZoneInfo.cs | 29 ++ .../zxing/qrcode/decoder/DecodedBitStreamParser.cs | 237 ++++++++++- shadowsocks-csharp/View/MenuViewController.cs | 31 +- shadowsocks-csharp/shadowsocks-csharp.csproj | 14 + 17 files changed, 3060 insertions(+), 22 deletions(-) create mode 100755 shadowsocks-csharp/3rd/zxing/BarcodeReader.cs create mode 100755 shadowsocks-csharp/3rd/zxing/BarcodeReaderGeneric.cs create mode 100755 shadowsocks-csharp/3rd/zxing/IBarcodeReader.cs create mode 100755 shadowsocks-csharp/3rd/zxing/IBarcodeReaderGeneric.cs create mode 100755 shadowsocks-csharp/3rd/zxing/RGBLuminanceSource.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/CharacterSetECI.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/DecodingOptions.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/ECI.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/GlobalHistogramBinarizer.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/HybridBinarizer.cs create mode 100755 shadowsocks-csharp/3rd/zxing/common/StringUtils.cs create mode 100755 shadowsocks-csharp/3rd/zxing/net2.0/Action.cs create mode 100755 shadowsocks-csharp/3rd/zxing/net2.0/Func.cs create mode 100755 shadowsocks-csharp/3rd/zxing/net2.0/TimeZoneInfo.cs diff --git a/shadowsocks-csharp/3rd/zxing/BarcodeReader.cs b/shadowsocks-csharp/3rd/zxing/BarcodeReader.cs new file mode 100755 index 00000000..5363a4d9 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/BarcodeReader.cs @@ -0,0 +1,152 @@ +/* + * Copyright 2012 ZXing.Net 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; +#if !PORTABLE +#if !(SILVERLIGHT || NETFX_CORE) +#if !UNITY +using System.Drawing; +using ZXing.QrCode; +#else +using UnityEngine; +#endif +#elif NETFX_CORE +using Windows.UI.Xaml.Media.Imaging; +#else +using System.Windows.Media.Imaging; +#endif +#endif +#if MONOANDROID +using Android.Graphics; +#endif + +namespace ZXing +{ + /// + /// A smart class to decode the barcode inside a bitmap object + /// +#if MONOTOUCH + public class BarcodeReader : BarcodeReaderGeneric, IBarcodeReader, IMultipleBarcodeReader + { + private static readonly Func defaultCreateLuminanceSource = + (img) => new RGBLuminanceSource(img); +#else +#if !PORTABLE +#if !(SILVERLIGHT || NETFX_CORE) +#if !UNITY + public class BarcodeReader : BarcodeReaderGeneric, IBarcodeReader + { + private static readonly Func defaultCreateLuminanceSource = + (bitmap) => new BitmapLuminanceSource(bitmap); +#else + public class BarcodeReader : BarcodeReaderGeneric, IBarcodeReader, IMultipleBarcodeReader + { + private static readonly Func defaultCreateLuminanceSource = + (rawColor32, width, height) => new Color32LuminanceSource(rawColor32, width, height); +#endif +#else + public class BarcodeReader : BarcodeReaderGeneric, IBarcodeReader, IMultipleBarcodeReader + { + private static readonly Func defaultCreateLuminanceSource = + (bitmap) => new BitmapLuminanceSource(bitmap); +#endif +#else + public class BarcodeReader : BarcodeReaderGeneric, IBarcodeReader, IMultipleBarcodeReader + { + private static readonly Func defaultCreateLuminanceSource = + (data) => null; +#endif +#endif + /// + /// Initializes a new instance of the class. + /// + public BarcodeReader() + : this(new QRCodeReader(), defaultCreateLuminanceSource, null) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Sets the reader which should be used to find and decode the barcode. + /// If null then MultiFormatReader is used + /// Sets the function to create a luminance source object for a bitmap. + /// If null, an exception is thrown when Decode is called + /// Sets the function to create a binarizer object for a luminance source. + /// If null then HybridBinarizer is used + public BarcodeReader(Reader reader, +#if MONOTOUCH + Func createLuminanceSource, +#elif MONOANDROID + Func createLuminanceSource, +#else +#if !(SILVERLIGHT || NETFX_CORE) +#if !UNITY +#if !PORTABLE + Func createLuminanceSource, +#else + Func createLuminanceSource, +#endif +#else + Func createLuminanceSource, +#endif +#else + Func createLuminanceSource, +#endif +#endif + Func createBinarizer + ) + : base(reader, createLuminanceSource ?? defaultCreateLuminanceSource, createBinarizer) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Sets the reader which should be used to find and decode the barcode. + /// If null then MultiFormatReader is used + /// Sets the function to create a luminance source object for a bitmap. + /// If null, an exception is thrown when Decode is called + /// Sets the function to create a binarizer object for a luminance source. + /// If null then HybridBinarizer is used + public BarcodeReader(Reader reader, +#if MONOTOUCH + Func createLuminanceSource, +#elif MONOANDROID + Func createLuminanceSource, +#else +#if !(SILVERLIGHT || NETFX_CORE) +#if !UNITY +#if !PORTABLE + Func createLuminanceSource, +#else + Func createLuminanceSource, +#endif +#else + Func createLuminanceSource, +#endif +#else + Func createLuminanceSource, +#endif +#endif + Func createBinarizer, + Func createRGBLuminanceSource + ) + : base(reader, createLuminanceSource ?? defaultCreateLuminanceSource, createBinarizer, createRGBLuminanceSource) + { + } + } +} diff --git a/shadowsocks-csharp/3rd/zxing/BarcodeReaderGeneric.cs b/shadowsocks-csharp/3rd/zxing/BarcodeReaderGeneric.cs new file mode 100755 index 00000000..3ce46568 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/BarcodeReaderGeneric.cs @@ -0,0 +1,436 @@ +/* + * Copyright 2012 ZXing.Net 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.QrCode; + +namespace ZXing +{ + /// + /// A smart class to decode the barcode inside a bitmap object + /// + public class BarcodeReaderGeneric : IBarcodeReaderGeneric + { + private static readonly Func defaultCreateBinarizer = + (luminanceSource) => new HybridBinarizer(luminanceSource); + + protected static readonly Func defaultCreateRGBLuminanceSource = + (rawBytes, width, height, format) => new RGBLuminanceSource(rawBytes, width, height, format); + + private Reader reader; + private readonly Func createRGBLuminanceSource; +#if !UNITY + private readonly Func createLuminanceSource; +#else + private readonly Func createLuminanceSource; +#endif + private readonly Func createBinarizer; + private bool usePreviousState; + private DecodingOptions options; + + /// + /// Gets or sets the options. + /// + /// + /// The options. + /// + public DecodingOptions Options + { + get { return options ?? (options = new DecodingOptions()); } + set { options = value; } + } + + /// + /// Gets the reader which should be used to find and decode the barcode. + /// + /// + /// The reader. + /// + protected Reader Reader + { + get + { + return reader ?? (reader = new QRCodeReader()); + } + } + + /// + /// Gets or sets a method which is called if an important point is found + /// + /// + /// The result point callback. + /// + public event Action ResultPointFound + { + add + { + if (!Options.Hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK)) + { + var callback = new ResultPointCallback(OnResultPointFound); + Options.Hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK] = callback; + } + explicitResultPointFound += value; + usePreviousState = false; + } + remove + { + explicitResultPointFound -= value; + if (explicitResultPointFound == null) + Options.Hints.Remove(DecodeHintType.NEED_RESULT_POINT_CALLBACK); + usePreviousState = false; + } + } + + private event Action explicitResultPointFound; + + /// + /// event is executed if a result was found via decode + /// + public event Action ResultFound; + + /// + /// Gets or sets a flag which cause a deeper look into the bitmap + /// + /// + /// true if [try harder]; otherwise, false. + /// + [Obsolete("Please use the Options.TryHarder property instead.")] + public bool TryHarder + { + get { return Options.TryHarder; } + set { Options.TryHarder = value; } + } + + /// + /// Image is a pure monochrome image of a barcode. + /// + /// + /// true if monochrome image of a barcode; otherwise, false. + /// + [Obsolete("Please use the Options.PureBarcode property instead.")] + public bool PureBarcode + { + get { return Options.PureBarcode; } + set { Options.PureBarcode = value; } + } + + /// + /// Specifies what character encoding to use when decoding, where applicable (type String) + /// + /// + /// The character set. + /// + [Obsolete("Please use the Options.CharacterSet property instead.")] + public string CharacterSet + { + get { return Options.CharacterSet; } + set { Options.CharacterSet = value; } + } + + /// + /// Image is known to be of one of a few possible formats. + /// Maps to a {@link java.util.List} of {@link BarcodeFormat}s. + /// + /// + /// The possible formats. + /// + [Obsolete("Please use the Options.PossibleFormats property instead.")] + public IList PossibleFormats + { + get { return Options.PossibleFormats; } + set { Options.PossibleFormats = value; } + } + + /// + /// Gets or sets a value indicating whether the image should be automatically rotated. + /// Rotation is supported for 90, 180 and 270 degrees + /// + /// + /// true if image should be rotated; otherwise, false. + /// + public bool AutoRotate { get; set; } + + /// + /// Gets or sets a value indicating whether the image should be automatically inverted + /// if no result is found in the original image. + /// ATTENTION: Please be carefully because it slows down the decoding process if it is used + /// + /// + /// true if image should be inverted; otherwise, false. + /// + public bool TryInverted { get; set; } + +#if !UNITY + /// + /// Optional: Gets or sets the function to create a luminance source object for a bitmap. + /// If null a platform specific default LuminanceSource is used + /// + /// + /// The function to create a luminance source object. + /// + protected Func CreateLuminanceSource +#else + /// + /// Optional: Gets or sets the function to create a luminance source object for a bitmap. + /// If null a platform specific default LuminanceSource is used + /// + /// + /// The function to create a luminance source object. + /// + protected Func CreateLuminanceSource +#endif + { + get + { + return createLuminanceSource; + } + } + + /// + /// Optional: Gets or sets the function to create a binarizer object for a luminance source. + /// If null then HybridBinarizer is used + /// + /// + /// The function to create a binarizer object. + /// + protected Func CreateBinarizer + { + get + { + return createBinarizer ?? defaultCreateBinarizer; + } + } + + /// + /// Initializes a new instance of the class. + /// + public BarcodeReaderGeneric() + : this(new QRCodeReader(), null, defaultCreateBinarizer) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Sets the reader which should be used to find and decode the barcode. + /// If null then MultiFormatReader is used + /// Sets the function to create a luminance source object for a bitmap. + /// If null, an exception is thrown when Decode is called + /// Sets the function to create a binarizer object for a luminance source. + /// If null then HybridBinarizer is used + public BarcodeReaderGeneric(Reader reader, +#if !UNITY + Func createLuminanceSource, +#else + Func createLuminanceSource, +#endif + Func createBinarizer + ) + : this(reader, createLuminanceSource, createBinarizer, null) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// Sets the reader which should be used to find and decode the barcode. + /// If null then MultiFormatReader is used + /// Sets the function to create a luminance source object for a bitmap. + /// If null, an exception is thrown when Decode is called + /// Sets the function to create a binarizer object for a luminance source. + /// If null then HybridBinarizer is used + /// Sets the function to create a luminance source object for a rgb array. + /// If null the RGBLuminanceSource is used. The handler is only called when Decode with a byte[] array is called. + public BarcodeReaderGeneric(Reader reader, +#if !UNITY + Func createLuminanceSource, +#else + Func createLuminanceSource, +#endif + Func createBinarizer, + Func createRGBLuminanceSource + ) + { + this.reader = reader ?? new QRCodeReader(); + this.createLuminanceSource = createLuminanceSource; + this.createBinarizer = createBinarizer ?? defaultCreateBinarizer; + this.createRGBLuminanceSource = createRGBLuminanceSource ?? defaultCreateRGBLuminanceSource; + Options.ValueChanged += (o, args) => usePreviousState = false; + usePreviousState = false; + } + +#if !PORTABLE +#if !UNITY + /// + /// Decodes the specified barcode bitmap. + /// + /// The barcode bitmap. + /// the result data or null + public Result Decode(T barcodeBitmap) +#else + /// + /// Decodes the specified barcode bitmap. + /// + /// raw bytes of the image in RGB order + /// + /// + /// + /// the result data or null + /// + public Result Decode(T rawRGB, int width, int height) +#endif + { + if (CreateLuminanceSource == null) + { + throw new InvalidOperationException("You have to declare a luminance source delegate."); + } + +#if !UNITY + if (barcodeBitmap == null) + throw new ArgumentNullException("barcodeBitmap"); +#else + if (rawRGB == null) + throw new ArgumentNullException("rawRGB"); +#endif + +#if !UNITY + var luminanceSource = CreateLuminanceSource(barcodeBitmap); +#else + var luminanceSource = CreateLuminanceSource(rawRGB, width, height); +#endif + + return Decode(luminanceSource); + } +#endif + + /// + /// Tries to decode a barcode within an image which is given by a luminance source. + /// That method gives a chance to prepare a luminance source completely before calling + /// the time consuming decoding method. On the other hand there is a chance to create + /// a luminance source which is independent from external resources (like Bitmap objects) + /// and the decoding call can be made in a background thread. + /// + /// The luminance source. + /// + virtual public Result Decode(LuminanceSource luminanceSource) + { + var result = default(Result); + var binarizer = CreateBinarizer(luminanceSource); + var binaryBitmap = new BinaryBitmap(binarizer); + var multiformatReader = Reader as QRCodeReader; + var rotationCount = 0; + var rotationMaxCount = 1; + + if (AutoRotate) + { + Options.Hints[DecodeHintType.TRY_HARDER_WITHOUT_ROTATION] = true; + rotationMaxCount = 4; + } + else + { + if (Options.Hints.ContainsKey(DecodeHintType.TRY_HARDER_WITHOUT_ROTATION)) + Options.Hints.Remove(DecodeHintType.TRY_HARDER_WITHOUT_ROTATION); + } + + for (; rotationCount < rotationMaxCount; rotationCount++) + { + result = Reader.decode(binaryBitmap, Options.Hints); + usePreviousState = true; + + + if (result != null || + !luminanceSource.RotateSupported || + !AutoRotate) + break; + + binaryBitmap = new BinaryBitmap(CreateBinarizer(luminanceSource.rotateCounterClockwise())); + } + + if (result != null) + { + if (result.ResultMetadata == null) + { + result.putMetadata(ResultMetadataType.ORIENTATION, rotationCount * 90); + } + else if (!result.ResultMetadata.ContainsKey(ResultMetadataType.ORIENTATION)) + { + result.ResultMetadata[ResultMetadataType.ORIENTATION] = rotationCount * 90; + } + else + { + // perhaps the core decoder rotates the image already (can happen if TryHarder is specified) + result.ResultMetadata[ResultMetadataType.ORIENTATION] = ((int)(result.ResultMetadata[ResultMetadataType.ORIENTATION]) + rotationCount * 90) % 360; + } + + OnResultFound(result); + } + + return result; + } + + + protected void OnResultsFound(IEnumerable results) + { + if (ResultFound != null) + { + foreach (var result in results) + { + ResultFound(result); + } + } + } + + protected void OnResultFound(Result result) + { + if (ResultFound != null) + { + ResultFound(result); + } + } + + protected void OnResultPointFound(ResultPoint resultPoint) + { + if (explicitResultPointFound != null) + { + explicitResultPointFound(resultPoint); + } + } + + /// + /// Decodes the specified barcode bitmap. + /// + /// The image as byte[] array. + /// The width. + /// The height. + /// The format. + /// + /// the result data or null + /// + public Result Decode(byte[] rawRGB, int width, int height, RGBLuminanceSource.BitmapFormat format) + { + if (rawRGB == null) + throw new ArgumentNullException("rawRGB"); + + var luminanceSource = createRGBLuminanceSource(rawRGB, width, height, format); + + return Decode(luminanceSource); + } + + } +} diff --git a/shadowsocks-csharp/3rd/zxing/IBarcodeReader.cs b/shadowsocks-csharp/3rd/zxing/IBarcodeReader.cs new file mode 100755 index 00000000..66d90ffb --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/IBarcodeReader.cs @@ -0,0 +1,161 @@ +/* + * Copyright 2012 ZXing.Net 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; + +#if !(SILVERLIGHT || NETFX_CORE) +#if !UNITY +#if !PORTABLE +using System.Drawing; +#endif +#else +using UnityEngine; +#endif +#elif NETFX_CORE +using Windows.UI.Xaml.Media.Imaging; +#else +using System.Windows.Media.Imaging; +#endif + +using ZXing.Common; + +namespace ZXing +{ + /// + /// Interface for a smart class to decode the barcode inside a bitmap object + /// + public interface IBarcodeReader + { + /// + /// event is executed when a result point was found + /// + event Action ResultPointFound; + + /// + /// event is executed when a result was found via decode + /// + event Action ResultFound; + + /// + /// Gets or sets a flag which cause a deeper look into the bitmap + /// + /// + /// true if [try harder]; otherwise, false. + /// + [Obsolete("Please use the Options.TryHarder property instead.")] + bool TryHarder { get; set; } + + /// + /// Image is a pure monochrome image of a barcode. + /// + /// + /// true if monochrome image of a barcode; otherwise, false. + /// + [Obsolete("Please use the Options.PureBarcode property instead.")] + bool PureBarcode { get; set; } + + /// + /// Specifies what character encoding to use when decoding, where applicable (type String) + /// + /// + /// The character set. + /// + [Obsolete("Please use the Options.CharacterSet property instead.")] + string CharacterSet { get; set; } + + /// + /// Image is known to be of one of a few possible formats. + /// Maps to a {@link java.util.List} of {@link BarcodeFormat}s. + /// + /// + /// The possible formats. + /// + [Obsolete("Please use the Options.PossibleFormats property instead.")] + IList PossibleFormats { get; set; } + + /// + /// Specifies some options which influence the decoding process + /// + DecodingOptions Options { get; set; } + + /// + /// Decodes the specified barcode bitmap which is given by a generic byte array with the order RGB24. + /// + /// The image as RGB24 array. + /// The width. + /// The height. + /// The format. + /// + /// the result data or null + /// + Result Decode(byte[] rawRGB, int width, int height, RGBLuminanceSource.BitmapFormat format); + + /// + /// Tries to decode a barcode within an image which is given by a luminance source. + /// That method gives a chance to prepare a luminance source completely before calling + /// the time consuming decoding method. On the other hand there is a chance to create + /// a luminance source which is independent from external resources (like Bitmap objects) + /// and the decoding call can be made in a background thread. + /// + /// The luminance source. + /// + Result Decode(LuminanceSource luminanceSource); + +#if MONOTOUCH + /// + /// Decodes the specified barcode bitmap. + /// + /// The barcode bitmap. + /// the result data or null + Result Decode(MonoTouch.UIKit.UIImage barcodeImage); +#elif MONOANDROID + /// + /// Decodes the specified barcode bitmap. + /// + /// The barcode bitmap. + /// the result data or null + Result Decode(Android.Graphics.Bitmap barcodeImage); +#else +#if !PORTABLE +#if !(SILVERLIGHT || NETFX_CORE) +#if !UNITY + /// + /// Decodes the specified barcode bitmap. + /// + /// The barcode bitmap. + /// the result data or null + Result Decode(Bitmap barcodeBitmap); +#else + /// + /// Decodes the specified barcode bitmap. + /// + /// The image as Color32 array. + /// the result data or null + Result Decode(Color32[] rawColor32, int width, int height); +#endif +#else + /// + /// Decodes the specified barcode bitmap. + /// + /// The barcode bitmap. + /// the result data or null + Result Decode(WriteableBitmap barcodeBitmap); +#endif +#endif +#endif + } +} diff --git a/shadowsocks-csharp/3rd/zxing/IBarcodeReaderGeneric.cs b/shadowsocks-csharp/3rd/zxing/IBarcodeReaderGeneric.cs new file mode 100755 index 00000000..1860988a --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/IBarcodeReaderGeneric.cs @@ -0,0 +1,123 @@ +/* + * Copyright 2012 ZXing.Net 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; + +namespace ZXing +{ + /// + /// Interface for a smart class to decode the barcode inside a bitmap object + /// + /// gives the type of the input data + public interface IBarcodeReaderGeneric + { + /// + /// event is executed when a result point was found + /// + event Action ResultPointFound; + + /// + /// event is executed when a result was found via decode + /// + event Action ResultFound; + + /// + /// Gets or sets a flag which cause a deeper look into the bitmap + /// + /// + /// true if [try harder]; otherwise, false. + /// + [Obsolete("Please use the Options.TryHarder property instead.")] + bool TryHarder { get; set; } + + /// + /// Image is a pure monochrome image of a barcode. + /// + /// + /// true if monochrome image of a barcode; otherwise, false. + /// + [Obsolete("Please use the Options.PureBarcode property instead.")] + bool PureBarcode { get; set; } + + /// + /// Specifies what character encoding to use when decoding, where applicable (type String) + /// + /// + /// The character set. + /// + [Obsolete("Please use the Options.CharacterSet property instead.")] + string CharacterSet { get; set; } + + /// + /// Image is known to be of one of a few possible formats. + /// Maps to a {@link java.util.List} of {@link BarcodeFormat}s. + /// + /// + /// The possible formats. + /// + [Obsolete("Please use the Options.PossibleFormats property instead.")] + IList PossibleFormats { get; set; } + + /// + /// Specifies some options which influence the decoding process + /// + DecodingOptions Options { get; set; } + + /// + /// Decodes the specified barcode bitmap which is given by a generic byte array. + /// + /// The barcode bitmap. + /// The width. + /// The height. + /// The format. + /// + /// the result data or null + /// + Result Decode(byte[] rawRGB, int width, int height, RGBLuminanceSource.BitmapFormat format); + + /// + /// Tries to decode a barcode within an image which is given by a luminance source. + /// That method gives a chance to prepare a luminance source completely before calling + /// the time consuming decoding method. On the other hand there is a chance to create + /// a luminance source which is independent from external resources (like Bitmap objects) + /// and the decoding call can be made in a background thread. + /// + /// The luminance source. + /// + Result Decode(LuminanceSource luminanceSource); + +#if !PORTABLE +#if !UNITY + /// + /// Decodes the specified barcode bitmap. + /// + /// The barcode bitmap. + /// the result data or null + Result Decode(T barcodeBitmap); +#else + /// + /// Decodes the specified barcode bitmap. + /// + /// The barcode bitmap. + /// the result data or null + Result Decode(T rawRGB, int width, int height); +#endif +#endif + } +} diff --git a/shadowsocks-csharp/3rd/zxing/RGBLuminanceSource.cs b/shadowsocks-csharp/3rd/zxing/RGBLuminanceSource.cs new file mode 100755 index 00000000..6af439ef --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/RGBLuminanceSource.cs @@ -0,0 +1,314 @@ +/* +* Copyright 2012 ZXing.Net 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 +{ + /// + /// Luminance source class which support different formats of images. + /// + public partial class RGBLuminanceSource : BaseLuminanceSource + { + /// + /// enumeration of supported bitmap format which the RGBLuminanceSource can process + /// + public enum BitmapFormat + { + /// + /// format of the byte[] isn't known. RGBLuminanceSource tries to determine the best possible value + /// + Unknown, + /// + /// grayscale array, the byte array is a luminance array with 1 byte per pixel + /// + Gray8, + /// + /// 3 bytes per pixel with the channels red, green and blue + /// + RGB24, + /// + /// 4 bytes per pixel with the channels red, green and blue + /// + RGB32, + /// + /// 4 bytes per pixel with the channels alpha, red, green and blue + /// + ARGB32, + /// + /// 3 bytes per pixel with the channels blue, green and red + /// + BGR24, + /// + /// 4 bytes per pixel with the channels blue, green and red + /// + BGR32, + /// + /// 4 bytes per pixel with the channels blue, green, red and alpha + /// + BGRA32, + /// + /// 2 bytes per pixel, 5 bit red, 6 bits green and 5 bits blue + /// + RGB565, + /// + /// 4 bytes per pixel with the channels red, green, blue and alpha + /// + RGBA32, + } + + /// + /// Initializes a new instance of the class. + /// + /// The width. + /// The height. + protected RGBLuminanceSource(int width, int height) + : base(width, height) + { + } + + /// + /// Initializes a new instance of the class. + /// It supports a byte array with 3 bytes per pixel (RGB24). + /// + /// The RGB raw bytes. + /// The width. + /// The height. + public RGBLuminanceSource(byte[] rgbRawBytes, int width, int height) + : this(rgbRawBytes, width, height, BitmapFormat.RGB24) + { + } + + /// + /// Initializes a new instance of the class. + /// It supports a byte array with 1 byte per pixel (Gray8). + /// That means the whole array consists of the luminance values (grayscale). + /// + /// The luminance array. + /// The width. + /// The height. + /// if set to true [is8 bit]. + [Obsolete("Use RGBLuminanceSource(luminanceArray, width, height, BitmapFormat.Gray8)")] + public RGBLuminanceSource(byte[] luminanceArray, int width, int height, bool is8Bit) + : this(luminanceArray, width, height, BitmapFormat.Gray8) + { + } + + /// + /// Initializes a new instance of the class. + /// It supports a byte array with 3 bytes per pixel (RGB24). + /// + /// The RGB raw bytes. + /// The width. + /// The height. + /// The bitmap format. + public RGBLuminanceSource(byte[] rgbRawBytes, int width, int height, BitmapFormat bitmapFormat) + : base(width, height) + { + CalculateLuminance(rgbRawBytes, bitmapFormat); + } + + /// + /// Should create a new luminance source with the right class type. + /// The method is used in methods crop and rotate. + /// + /// The new luminances. + /// The width. + /// The height. + /// + protected override LuminanceSource CreateLuminanceSource(byte[] newLuminances, int width, int height) + { + return new RGBLuminanceSource(width, height) { luminances = newLuminances }; + } + + private static BitmapFormat DetermineBitmapFormat(byte[] rgbRawBytes, int width, int height) + { + var square = width*height; + var byteperpixel = rgbRawBytes.Length/square; + + switch (byteperpixel) + { + case 1: + return BitmapFormat.Gray8; + case 2: + return BitmapFormat.RGB565; + case 3: + return BitmapFormat.RGB24; + case 4: + return BitmapFormat.RGB32; + default: + throw new ArgumentException("The bitmap format could not be determined. Please specify the correct value."); + } + } + + protected void CalculateLuminance(byte[] rgbRawBytes, BitmapFormat bitmapFormat) + { + if (bitmapFormat == BitmapFormat.Unknown) + { + bitmapFormat = DetermineBitmapFormat(rgbRawBytes, Width, Height); + } + switch (bitmapFormat) + { + case BitmapFormat.Gray8: + Buffer.BlockCopy(rgbRawBytes, 0, luminances, 0, rgbRawBytes.Length < luminances.Length ? rgbRawBytes.Length : luminances.Length); + break; + case BitmapFormat.RGB24: + CalculateLuminanceRGB24(rgbRawBytes); + break; + case BitmapFormat.BGR24: + CalculateLuminanceBGR24(rgbRawBytes); + break; + case BitmapFormat.RGB32: + CalculateLuminanceRGB32(rgbRawBytes); + break; + case BitmapFormat.BGR32: + CalculateLuminanceBGR32(rgbRawBytes); + break; + case BitmapFormat.RGBA32: + CalculateLuminanceRGBA32(rgbRawBytes); + break; + case BitmapFormat.ARGB32: + CalculateLuminanceARGB32(rgbRawBytes); + break; + case BitmapFormat.BGRA32: + CalculateLuminanceBGRA32(rgbRawBytes); + break; + case BitmapFormat.RGB565: + CalculateLuminanceRGB565(rgbRawBytes); + break; + default: + throw new ArgumentException("The bitmap format isn't supported.", bitmapFormat.ToString()); + } + } + + private void CalculateLuminanceRGB565(byte[] rgb565RawData) + { + var luminanceIndex = 0; + for (var index = 0; index < rgb565RawData.Length && luminanceIndex < luminances.Length; index += 2, luminanceIndex++) + { + var byte1 = rgb565RawData[index]; + var byte2 = rgb565RawData[index + 1]; + + var b5 = byte1 & 0x1F; + var g5 = (((byte1 & 0xE0) >> 5) | ((byte2 & 0x03) << 3)) & 0x1F; + var r5 = (byte2 >> 2) & 0x1F; + var r8 = (r5 * 527 + 23) >> 6; + var g8 = (g5 * 527 + 23) >> 6; + var b8 = (b5 * 527 + 23) >> 6; + + // cheap, not fully accurate conversion + //var pixel = (byte2 << 8) | byte1; + //b8 = (((pixel) & 0x001F) << 3); + //g8 = (((pixel) & 0x07E0) >> 2) & 0xFF; + //r8 = (((pixel) & 0xF800) >> 8); + + luminances[luminanceIndex] = (byte)((RChannelWeight * r8 + GChannelWeight * g8 + BChannelWeight * b8) >> ChannelWeight); + } + } + + private void CalculateLuminanceRGB24(byte[] rgbRawBytes) + { + for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) + { + // Calculate luminance cheaply, favoring green. + int r = rgbRawBytes[rgbIndex++]; + int g = rgbRawBytes[rgbIndex++]; + int b = rgbRawBytes[rgbIndex++]; + luminances[luminanceIndex] = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); + } + } + + private void CalculateLuminanceBGR24(byte[] rgbRawBytes) + { + for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) + { + // Calculate luminance cheaply, favoring green. + int b = rgbRawBytes[rgbIndex++]; + int g = rgbRawBytes[rgbIndex++]; + int r = rgbRawBytes[rgbIndex++]; + luminances[luminanceIndex] = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); + } + } + + private void CalculateLuminanceRGB32(byte[] rgbRawBytes) + { + for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) + { + // Calculate luminance cheaply, favoring green. + int r = rgbRawBytes[rgbIndex++]; + int g = rgbRawBytes[rgbIndex++]; + int b = rgbRawBytes[rgbIndex++]; + rgbIndex++; + luminances[luminanceIndex] = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); + } + } + + private void CalculateLuminanceBGR32(byte[] rgbRawBytes) + { + for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) + { + // Calculate luminance cheaply, favoring green. + int b = rgbRawBytes[rgbIndex++]; + int g = rgbRawBytes[rgbIndex++]; + int r = rgbRawBytes[rgbIndex++]; + rgbIndex++; + luminances[luminanceIndex] = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); + } + } + + private void CalculateLuminanceBGRA32(byte[] rgbRawBytes) + { + for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) + { + // Calculate luminance cheaply, favoring green. + var b = rgbRawBytes[rgbIndex++]; + var g = rgbRawBytes[rgbIndex++]; + var r = rgbRawBytes[rgbIndex++]; + var alpha = rgbRawBytes[rgbIndex++]; + var luminance = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); + luminances[luminanceIndex] = (byte)(((luminance * alpha) >> 8) + (255 * (255 - alpha) >> 8)); + } + } + + private void CalculateLuminanceRGBA32(byte[] rgbRawBytes) + { + for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) + { + // Calculate luminance cheaply, favoring green. + var r = rgbRawBytes[rgbIndex++]; + var g = rgbRawBytes[rgbIndex++]; + var b = rgbRawBytes[rgbIndex++]; + var alpha = rgbRawBytes[rgbIndex++]; + var luminance = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); + luminances[luminanceIndex] = (byte)(((luminance * alpha) >> 8) + (255 * (255 - alpha) >> 8)); + } + } + + private void CalculateLuminanceARGB32(byte[] rgbRawBytes) + { + for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) + { + // Calculate luminance cheaply, favoring green. + var alpha = rgbRawBytes[rgbIndex++]; + var r = rgbRawBytes[rgbIndex++]; + var g = rgbRawBytes[rgbIndex++]; + var b = rgbRawBytes[rgbIndex++]; + var luminance = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); + luminances[luminanceIndex] = (byte)(((luminance * alpha) >> 8) + (255 * (255 - alpha) >> 8)); + } + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/CharacterSetECI.cs b/shadowsocks-csharp/3rd/zxing/common/CharacterSetECI.cs new file mode 100755 index 00000000..cb42eb5f --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/CharacterSetECI.cs @@ -0,0 +1,128 @@ +/* +* 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. +*/ + +using System; +using System.Collections.Generic; + +namespace ZXing.Common +{ + /// Encapsulates a Character Set ECI, according to "Extended Channel Interpretations" 5.3.1.1 + /// of ISO 18004. + /// + /// + /// Sean Owen + public sealed class CharacterSetECI : ECI + { + internal static readonly IDictionary VALUE_TO_ECI; + internal static readonly IDictionary NAME_TO_ECI; + + private readonly String encodingName; + + public String EncodingName + { + get + { + return encodingName; + } + + } + + static CharacterSetECI() + { + VALUE_TO_ECI = new Dictionary(); + NAME_TO_ECI = new Dictionary(); + // TODO figure out if these values are even right! + addCharacterSet(0, "CP437"); + addCharacterSet(1, new[] { "ISO-8859-1", "ISO8859_1" }); + addCharacterSet(2, "CP437"); + addCharacterSet(3, new[] { "ISO-8859-1", "ISO8859_1" }); + addCharacterSet(4, new[] { "ISO-8859-2", "ISO8859_2" }); + addCharacterSet(5, new[] { "ISO-8859-3", "ISO8859_3" }); + addCharacterSet(6, new[] { "ISO-8859-4", "ISO8859_4" }); + addCharacterSet(7, new[] { "ISO-8859-5", "ISO8859_5" }); + addCharacterSet(8, new[] { "ISO-8859-6", "ISO8859_6" }); + addCharacterSet(9, new[] { "ISO-8859-7", "ISO8859_7" }); + addCharacterSet(10, new[] { "ISO-8859-8", "ISO8859_8" }); + addCharacterSet(11, new[] { "ISO-8859-9", "ISO8859_9" }); + addCharacterSet(12, new[] { "ISO-8859-4", "ISO-8859-10", "ISO8859_10" }); // use ISO-8859-4 because ISO-8859-16 isn't supported + addCharacterSet(13, new[] { "ISO-8859-11", "ISO8859_11" }); + addCharacterSet(15, new[] { "ISO-8859-13", "ISO8859_13" }); + addCharacterSet(16, new[] { "ISO-8859-1", "ISO-8859-14", "ISO8859_14" }); // use ISO-8859-1 because ISO-8859-16 isn't supported + addCharacterSet(17, new[] { "ISO-8859-15", "ISO8859_15" }); + addCharacterSet(18, new[] { "ISO-8859-3", "ISO-8859-16", "ISO8859_16" }); // use ISO-8859-3 because ISO-8859-16 isn't supported + addCharacterSet(20, new[] { "SJIS", "Shift_JIS" }); + addCharacterSet(21, new[] { "WINDOWS-1250", "CP1250" }); + addCharacterSet(22, new[] { "WINDOWS-1251", "CP1251" }); + addCharacterSet(23, new[] { "WINDOWS-1252", "CP1252" }); + addCharacterSet(24, new[] { "WINDOWS-1256", "CP1256" }); + addCharacterSet(25, new[] { "UTF-16BE", "UNICODEBIG" }); + addCharacterSet(26, new[] { "UTF-8", "UTF8" }); + addCharacterSet(27, "US-ASCII"); + addCharacterSet(170, "US-ASCII"); + addCharacterSet(28, "BIG5"); + addCharacterSet(29, new[] { "GB18030", "GB2312", "EUC_CN", "GBK" }); + addCharacterSet(30, new[] { "EUC-KR", "EUC_KR" }); + } + + private CharacterSetECI(int value, String encodingName) + : base(value) + { + this.encodingName = encodingName; + } + + private static void addCharacterSet(int value, String encodingName) + { + var eci = new CharacterSetECI(value, encodingName); + VALUE_TO_ECI[value] = eci; // can't use valueOf + NAME_TO_ECI[encodingName] = eci; + } + + private static void addCharacterSet(int value, String[] encodingNames) + { + var eci = new CharacterSetECI(value, encodingNames[0]); + VALUE_TO_ECI[value] = eci; // can't use valueOf + foreach (string t in encodingNames) + { + NAME_TO_ECI[t] = eci; + } + } + + /// character set ECI value + /// + /// {@link CharacterSetECI} representing ECI of given value, or null if it is legal but + /// unsupported + /// + /// IllegalArgumentException if ECI value is invalid + public static CharacterSetECI getCharacterSetECIByValue(int value) + { + if (value < 0 || value >= 900) + { + return null; + } + return VALUE_TO_ECI[value]; + } + + /// character set ECI encoding name + /// + /// {@link CharacterSetECI} representing ECI for character encoding, or null if it is legal + /// but unsupported + /// + public static CharacterSetECI getCharacterSetECIByName(String name) + { + return NAME_TO_ECI[name.ToUpper()]; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/DecodingOptions.cs b/shadowsocks-csharp/3rd/zxing/common/DecodingOptions.cs new file mode 100755 index 00000000..9a58f9af --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/DecodingOptions.cs @@ -0,0 +1,370 @@ +/* + * Copyright 2013 ZXing.Net 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 System.ComponentModel; + +namespace ZXing.Common +{ + /// + /// Defines an container for encoder options + /// + [Serializable] + public class DecodingOptions + { + /// + /// Gets the data container for all options + /// + [Browsable(false)] + public IDictionary Hints { get; private set; } + + [field: NonSerialized] + public event Action ValueChanged; + + /// + /// Gets or sets a flag which cause a deeper look into the bitmap + /// + /// + /// true if [try harder]; otherwise, false. + /// + public bool TryHarder + { + get + { + if (Hints.ContainsKey(DecodeHintType.TRY_HARDER)) + return (bool)Hints[DecodeHintType.TRY_HARDER]; + return false; + } + set + { + if (value) + { + Hints[DecodeHintType.TRY_HARDER] = true; + } + else + { + if (Hints.ContainsKey(DecodeHintType.TRY_HARDER)) + { + Hints.Remove(DecodeHintType.TRY_HARDER); + } + } + } + } + + /// + /// Image is a pure monochrome image of a barcode. + /// + /// + /// true if monochrome image of a barcode; otherwise, false. + /// + public bool PureBarcode + { + get + { + if (Hints.ContainsKey(DecodeHintType.PURE_BARCODE)) + return (bool)Hints[DecodeHintType.PURE_BARCODE]; + return false; + } + set + { + if (value) + { + Hints[DecodeHintType.PURE_BARCODE] = true; + } + else + { + if (Hints.ContainsKey(DecodeHintType.PURE_BARCODE)) + { + Hints.Remove(DecodeHintType.PURE_BARCODE); + } + } + } + } + + /// + /// Specifies what character encoding to use when decoding, where applicable (type String) + /// + /// + /// The character set. + /// + public string CharacterSet + { + get + { + if (Hints.ContainsKey(DecodeHintType.CHARACTER_SET)) + return (string)Hints[DecodeHintType.CHARACTER_SET]; + return null; + } + set + { + if (value != null) + { + Hints[DecodeHintType.CHARACTER_SET] = value; + } + else + { + if (Hints.ContainsKey(DecodeHintType.CHARACTER_SET)) + { + Hints.Remove(DecodeHintType.CHARACTER_SET); + } + } + } + } + + /// + /// Image is known to be of one of a few possible formats. + /// Maps to a {@link java.util.List} of {@link BarcodeFormat}s. + /// + /// + /// The possible formats. + /// + public IList PossibleFormats + { + get + { + if (Hints.ContainsKey(DecodeHintType.POSSIBLE_FORMATS)) + return (IList)Hints[DecodeHintType.POSSIBLE_FORMATS]; + return null; + } + set + { + if (value != null) + { + Hints[DecodeHintType.POSSIBLE_FORMATS] = value; + } + else + { + if (Hints.ContainsKey(DecodeHintType.POSSIBLE_FORMATS)) + { + Hints.Remove(DecodeHintType.POSSIBLE_FORMATS); + } + } + } + } + + /// + /// if Code39 could be detected try to use extended mode for full ASCII character set + /// + public bool UseCode39ExtendedMode + { + get + { + if (Hints.ContainsKey(DecodeHintType.USE_CODE_39_EXTENDED_MODE)) + return (bool)Hints[DecodeHintType.USE_CODE_39_EXTENDED_MODE]; + return false; + } + set + { + if (value) + { + Hints[DecodeHintType.USE_CODE_39_EXTENDED_MODE] = true; + } + else + { + if (Hints.ContainsKey(DecodeHintType.USE_CODE_39_EXTENDED_MODE)) + { + Hints.Remove(DecodeHintType.USE_CODE_39_EXTENDED_MODE); + } + } + } + } + + /// + /// Don't fail if a Code39 is detected but can't be decoded in extended mode. + /// Return the raw Code39 result instead. Maps to . + /// + public bool UseCode39RelaxedExtendedMode + { + get + { + if (Hints.ContainsKey(DecodeHintType.RELAXED_CODE_39_EXTENDED_MODE)) + return (bool)Hints[DecodeHintType.RELAXED_CODE_39_EXTENDED_MODE]; + return false; + } + set + { + if (value) + { + Hints[DecodeHintType.RELAXED_CODE_39_EXTENDED_MODE] = true; + } + else + { + if (Hints.ContainsKey(DecodeHintType.RELAXED_CODE_39_EXTENDED_MODE)) + { + Hints.Remove(DecodeHintType.RELAXED_CODE_39_EXTENDED_MODE); + } + } + } + } + + /// + /// If true, return the start and end digits in a Codabar barcode instead of stripping them. They + /// are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them + /// to not be. Doesn't matter what it maps to; use . + /// + public bool ReturnCodabarStartEnd + { + get + { + if (Hints.ContainsKey(DecodeHintType.RETURN_CODABAR_START_END)) + return (bool)Hints[DecodeHintType.RETURN_CODABAR_START_END]; + return false; + } + set + { + if (value) + { + Hints[DecodeHintType.RETURN_CODABAR_START_END] = true; + } + else + { + if (Hints.ContainsKey(DecodeHintType.RETURN_CODABAR_START_END)) + { + Hints.Remove(DecodeHintType.RETURN_CODABAR_START_END); + } + } + } + } + /// + /// Initializes a new instance of the class. + /// + public DecodingOptions() + { + var hints = new ChangeNotifyDictionary(); + Hints = hints; + UseCode39ExtendedMode = true; + UseCode39RelaxedExtendedMode = true; + hints.ValueChanged += (o, args) => { if (ValueChanged != null) ValueChanged(this, EventArgs.Empty); }; + } + + [Serializable] + private class ChangeNotifyDictionary: IDictionary + { + private readonly IDictionary values; + + [field: NonSerialized] + public event Action ValueChanged; + + public ChangeNotifyDictionary() + { + values = new Dictionary(); + } + + private void OnValueChanged() + { + if (ValueChanged != null) + ValueChanged(this, EventArgs.Empty); + } + + public void Add(TKey key, TValue value) + { + values.Add(key, value); + OnValueChanged(); + } + + public bool ContainsKey(TKey key) + { + return values.ContainsKey(key); + } + + public ICollection Keys + { + get { return values.Keys; } + } + + public bool Remove(TKey key) + { + var result = values.Remove(key); + OnValueChanged(); + return result; + } + + public bool TryGetValue(TKey key, out TValue value) + { + return values.TryGetValue(key, out value); + } + + public ICollection Values + { + get { return values.Values; } + } + + public TValue this[TKey key] + { + get + { + return values[key]; + } + set + { + values[key] = value; + OnValueChanged(); + } + } + + public void Add(KeyValuePair item) + { + values.Add(item); + OnValueChanged(); + } + + public void Clear() + { + values.Clear(); + OnValueChanged(); + } + + public bool Contains(KeyValuePair item) + { + return values.Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int arrayIndex) + { + values.CopyTo(array, arrayIndex); + } + + public int Count + { + get { return values.Count; } + } + + public bool IsReadOnly + { + get { return values.IsReadOnly; } + } + + public bool Remove(KeyValuePair item) + { + var result = values.Remove(item); + OnValueChanged(); + + return result; + } + + public IEnumerator> GetEnumerator() + { + return values.GetEnumerator(); + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return ((System.Collections.IEnumerable)values).GetEnumerator(); + } + } + } +} diff --git a/shadowsocks-csharp/3rd/zxing/common/ECI.cs b/shadowsocks-csharp/3rd/zxing/common/ECI.cs new file mode 100755 index 00000000..fa947ba2 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/ECI.cs @@ -0,0 +1,66 @@ +/* +* 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. +*/ +using System; +namespace ZXing.Common +{ + + /// Superclass of classes encapsulating types ECIs, according to "Extended Channel Interpretations" + /// 5.3 of ISO 18004. + /// + /// + /// Sean Owen + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + public abstract class ECI + { + virtual public int Value + { + get + { + return value_Renamed; + } + + } + + //UPGRADE_NOTE: Final was removed from the declaration of 'value '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" + private int value_Renamed; + + internal ECI(int value_Renamed) + { + this.value_Renamed = value_Renamed; + } + + /// ECI value + /// + /// {@link ECI} representing ECI of given value, or null if it is legal but unsupported + /// + /// IllegalArgumentException if ECI value is invalid + public static ECI getECIByValue(int value_Renamed) + { + if (value_Renamed < 0 || value_Renamed > 999999) + { + throw new System.ArgumentException("Bad ECI value: " + value_Renamed); + } + if (value_Renamed < 900) + { + // Character set ECIs use 000000 - 000899 + return CharacterSetECI.getCharacterSetECIByValue(value_Renamed); + } + return null; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/GlobalHistogramBinarizer.cs b/shadowsocks-csharp/3rd/zxing/common/GlobalHistogramBinarizer.cs new file mode 100755 index 00000000..91f20d55 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/GlobalHistogramBinarizer.cs @@ -0,0 +1,243 @@ +/* +* Copyright 2009 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.Common +{ + /// This Binarizer implementation uses the old ZXing global histogram approach. It is suitable + /// for low-end mobile devices which don't have enough CPU or memory to use a local thresholding + /// algorithm. However, because it picks a global black point, it cannot handle difficult shadows + /// and gradients. + /// + /// Faster mobile devices and all desktop applications should probably use HybridBinarizer instead. + /// + /// dswitkin@google.com (Daniel Switkin) + /// Sean Owen + /// + public class GlobalHistogramBinarizer : Binarizer + { + private const int LUMINANCE_BITS = 5; + private const int LUMINANCE_SHIFT = 8 - LUMINANCE_BITS; + private const int LUMINANCE_BUCKETS = 1 << LUMINANCE_BITS; + private static readonly byte[] EMPTY = new byte[0]; + + private byte[] luminances; + private readonly int[] buckets; + + /// + /// Initializes a new instance of the class. + /// + /// The source. + public GlobalHistogramBinarizer(LuminanceSource source) + : base(source) + { + luminances = EMPTY; + buckets = new int[LUMINANCE_BUCKETS]; + } + + /// + /// Applies simple sharpening to the row data to improve performance of the 1D Readers. + /// + /// + /// + /// + public override BitArray getBlackRow(int y, BitArray row) + { + LuminanceSource source = LuminanceSource; + int width = source.Width; + if (row == null || row.Size < width) + { + row = new BitArray(width); + } + else + { + row.clear(); + } + + initArrays(width); + byte[] localLuminances = source.getRow(y, luminances); + int[] localBuckets = buckets; + for (int x = 0; x < width; x++) + { + int pixel = localLuminances[x] & 0xff; + localBuckets[pixel >> LUMINANCE_SHIFT]++; + } + int blackPoint; + if (!estimateBlackPoint(localBuckets, out blackPoint)) + return null; + + int left = localLuminances[0] & 0xff; + int center = localLuminances[1] & 0xff; + for (int x = 1; x < width - 1; x++) + { + int right = localLuminances[x + 1] & 0xff; + // A simple -1 4 -1 box filter with a weight of 2. + int luminance = ((center << 2) - left - right) >> 1; + row[x] = (luminance < blackPoint); + left = center; + center = right; + } + return row; + } + + /// + /// Does not sharpen the data, as this call is intended to only be used by 2D Readers. + /// + override public BitMatrix BlackMatrix + { + get + { + LuminanceSource source = LuminanceSource; + byte[] localLuminances; + + int width = source.Width; + int height = source.Height; + BitMatrix matrix = new BitMatrix(width, height); + + // Quickly calculates the histogram by sampling four rows from the image. This proved to be + // more robust on the blackbox tests than sampling a diagonal as we used to do. + initArrays(width); + int[] localBuckets = buckets; + for (int y = 1; y < 5; y++) + { + int row = height * y / 5; + localLuminances = source.getRow(row, luminances); + int right = (width << 2) / 5; + for (int x = width / 5; x < right; x++) + { + int pixel = localLuminances[x] & 0xff; + localBuckets[pixel >> LUMINANCE_SHIFT]++; + } + } + int blackPoint; + if (!estimateBlackPoint(localBuckets, out blackPoint)) + return null; + + // We delay reading the entire image luminance until the black point estimation succeeds. + // Although we end up reading four rows twice, it is consistent with our motto of + // "fail quickly" which is necessary for continuous scanning. + localLuminances = source.Matrix; + for (int y = 0; y < height; y++) + { + int offset = y * width; + for (int x = 0; x < width; x++) + { + int pixel = localLuminances[offset + x] & 0xff; + matrix[x, y] = (pixel < blackPoint); + } + } + + return matrix; + } + } + + /// + /// Creates a new object with the same type as this Binarizer implementation, but with pristine + /// state. This is needed because Binarizer implementations may be stateful, e.g. keeping a cache + /// of 1 bit data. See Effective Java for why we can't use Java's clone() method. + /// + /// The LuminanceSource this Binarizer will operate on. + /// + /// A new concrete Binarizer implementation object. + /// + public override Binarizer createBinarizer(LuminanceSource source) + { + return new GlobalHistogramBinarizer(source); + } + + private void initArrays(int luminanceSize) + { + if (luminances.Length < luminanceSize) + { + luminances = new byte[luminanceSize]; + } + for (int x = 0; x < LUMINANCE_BUCKETS; x++) + { + buckets[x] = 0; + } + } + + private static bool estimateBlackPoint(int[] buckets, out int blackPoint) + { + blackPoint = 0; + // Find the tallest peak in the histogram. + int numBuckets = buckets.Length; + int maxBucketCount = 0; + int firstPeak = 0; + int firstPeakSize = 0; + for (int x = 0; x < numBuckets; x++) + { + if (buckets[x] > firstPeakSize) + { + firstPeak = x; + firstPeakSize = buckets[x]; + } + if (buckets[x] > maxBucketCount) + { + maxBucketCount = buckets[x]; + } + } + + // Find the second-tallest peak which is somewhat far from the tallest peak. + int secondPeak = 0; + int secondPeakScore = 0; + for (int x = 0; x < numBuckets; x++) + { + int distanceToBiggest = x - firstPeak; + // Encourage more distant second peaks by multiplying by square of distance. + int score = buckets[x] * distanceToBiggest * distanceToBiggest; + if (score > secondPeakScore) + { + secondPeak = x; + secondPeakScore = score; + } + } + + // Make sure firstPeak corresponds to the black peak. + if (firstPeak > secondPeak) + { + int temp = firstPeak; + firstPeak = secondPeak; + secondPeak = temp; + } + + // If there is too little contrast in the image to pick a meaningful black point, throw rather + // than waste time trying to decode the image, and risk false positives. + // TODO: It might be worth comparing the brightest and darkest pixels seen, rather than the + // two peaks, to determine the contrast. + if (secondPeak - firstPeak <= numBuckets >> 4) + { + return false; + } + + // Find a valley between them that is low and closer to the white peak. + int bestValley = secondPeak - 1; + int bestValleyScore = -1; + for (int x = secondPeak - 1; x > firstPeak; x--) + { + int fromFirst = x - firstPeak; + int score = fromFirst*fromFirst*(secondPeak - x)*(maxBucketCount - buckets[x]); + if (score > bestValleyScore) + { + bestValley = x; + bestValleyScore = score; + } + } + + blackPoint = bestValley << LUMINANCE_SHIFT; + return true; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/HybridBinarizer.cs b/shadowsocks-csharp/3rd/zxing/common/HybridBinarizer.cs new file mode 100755 index 00000000..d8185505 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/HybridBinarizer.cs @@ -0,0 +1,288 @@ +/* +* Copyright 2009 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.Common +{ + /// This class implements a local thresholding algorithm, which while slower than the + /// GlobalHistogramBinarizer, is fairly efficient for what it does. It is designed for + /// high frequency images of barcodes with black data on white backgrounds. For this application, + /// it does a much better job than a global blackpoint with severe shadows and gradients. + /// However it tends to produce artifacts on lower frequency images and is therefore not + /// a good general purpose binarizer for uses outside ZXing. + /// + /// This class extends GlobalHistogramBinarizer, using the older histogram approach for 1D readers, + /// and the newer local approach for 2D readers. 1D decoding using a per-row histogram is already + /// inherently local, and only fails for horizontal gradients. We can revisit that problem later, + /// but for now it was not a win to use local blocks for 1D. + /// + /// This Binarizer is the default for the unit tests and the recommended class for library users. + /// + /// + /// dswitkin@google.com (Daniel Switkin) + /// + /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source + /// + public sealed class HybridBinarizer : GlobalHistogramBinarizer + { + override public BitMatrix BlackMatrix + { + get + { + binarizeEntireImage(); + return matrix; + } + } + + // This class uses 5x5 blocks to compute local luminance, where each block is 8x8 pixels. + // So this is the smallest dimension in each axis we can accept. + private const int BLOCK_SIZE_POWER = 3; + private const int BLOCK_SIZE = 1 << BLOCK_SIZE_POWER; // ...0100...00 + private const int BLOCK_SIZE_MASK = BLOCK_SIZE - 1; // ...0011...11 + private const int MINIMUM_DIMENSION = 40; + private const int MIN_DYNAMIC_RANGE = 24; + + private BitMatrix matrix = null; + + public HybridBinarizer(LuminanceSource source) + : base(source) + { + } + + public override Binarizer createBinarizer(LuminanceSource source) + { + return new HybridBinarizer(source); + } + + /// + /// Calculates the final BitMatrix once for all requests. This could be called once from the + /// constructor instead, but there are some advantages to doing it lazily, such as making + /// profiling easier, and not doing heavy lifting when callers don't expect it. + /// + private void binarizeEntireImage() + { + if (matrix == null) + { + LuminanceSource source = LuminanceSource; + int width = source.Width; + int height = source.Height; + if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) + { + byte[] luminances = source.Matrix; + + int subWidth = width >> BLOCK_SIZE_POWER; + if ((width & BLOCK_SIZE_MASK) != 0) + { + subWidth++; + } + int subHeight = height >> BLOCK_SIZE_POWER; + if ((height & BLOCK_SIZE_MASK) != 0) + { + subHeight++; + } + int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height); + + var newMatrix = new BitMatrix(width, height); + calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix); + matrix = newMatrix; + } + else + { + // If the image is too small, fall back to the global histogram approach. + matrix = base.BlackMatrix; + } + } + } + + /// + /// For each 8x8 block in the image, calculate the average black point using a 5x5 grid + /// of the blocks around it. Also handles the corner cases (fractional blocks are computed based + /// on the last 8 pixels in the row/column which are also used in the previous block). + /// + /// The luminances. + /// Width of the sub. + /// Height of the sub. + /// The width. + /// The height. + /// The black points. + /// The matrix. + private static void calculateThresholdForBlock(byte[] luminances, int subWidth, int subHeight, int width, int height, int[][] blackPoints, BitMatrix matrix) + { + for (int y = 0; y < subHeight; y++) + { + int yoffset = y << BLOCK_SIZE_POWER; + int maxYOffset = height - BLOCK_SIZE; + if (yoffset > maxYOffset) + { + yoffset = maxYOffset; + } + for (int x = 0; x < subWidth; x++) + { + int xoffset = x << BLOCK_SIZE_POWER; + int maxXOffset = width - BLOCK_SIZE; + if (xoffset > maxXOffset) + { + xoffset = maxXOffset; + } + int left = cap(x, 2, subWidth - 3); + int top = cap(y, 2, subHeight - 3); + int sum = 0; + for (int z = -2; z <= 2; z++) + { + int[] blackRow = blackPoints[top + z]; + sum += blackRow[left - 2]; + sum += blackRow[left - 1]; + sum += blackRow[left]; + sum += blackRow[left + 1]; + sum += blackRow[left + 2]; + } + int average = sum / 25; + thresholdBlock(luminances, xoffset, yoffset, average, width, matrix); + } + } + } + + private static int cap(int value, int min, int max) + { + return value < min ? min : value > max ? max : value; + } + + /// + /// Applies a single threshold to an 8x8 block of pixels. + /// + /// The luminances. + /// The xoffset. + /// The yoffset. + /// The threshold. + /// The stride. + /// The matrix. + private static void thresholdBlock(byte[] luminances, int xoffset, int yoffset, int threshold, int stride, BitMatrix matrix) + { + int offset = (yoffset * stride) + xoffset; + for (int y = 0; y < BLOCK_SIZE; y++, offset += stride) + { + for (int x = 0; x < BLOCK_SIZE; x++) + { + int pixel = luminances[offset + x] & 0xff; + // Comparison needs to be <= so that black == 0 pixels are black even if the threshold is 0. + matrix[xoffset + x, yoffset + y] = (pixel <= threshold); + } + } + } + + /// + /// Calculates a single black point for each 8x8 block of pixels and saves it away. + /// See the following thread for a discussion of this algorithm: + /// http://groups.google.com/group/zxing/browse_thread/thread/d06efa2c35a7ddc0 + /// + /// The luminances. + /// Width of the sub. + /// Height of the sub. + /// The width. + /// The height. + /// + private static int[][] calculateBlackPoints(byte[] luminances, int subWidth, int subHeight, int width, int height) + { + int[][] blackPoints = new int[subHeight][]; + for (int i = 0; i < subHeight; i++) + { + blackPoints[i] = new int[subWidth]; + } + + for (int y = 0; y < subHeight; y++) + { + int yoffset = y << BLOCK_SIZE_POWER; + int maxYOffset = height - BLOCK_SIZE; + if (yoffset > maxYOffset) + { + yoffset = maxYOffset; + } + for (int x = 0; x < subWidth; x++) + { + int xoffset = x << BLOCK_SIZE_POWER; + int maxXOffset = width - BLOCK_SIZE; + if (xoffset > maxXOffset) + { + xoffset = maxXOffset; + } + int sum = 0; + int min = 0xFF; + int max = 0; + for (int yy = 0, offset = yoffset * width + xoffset; yy < BLOCK_SIZE; yy++, offset += width) + { + for (int xx = 0; xx < BLOCK_SIZE; xx++) + { + int pixel = luminances[offset + xx] & 0xFF; + // still looking for good contrast + sum += pixel; + if (pixel < min) + { + min = pixel; + } + if (pixel > max) + { + max = pixel; + } + } + // short-circuit min/max tests once dynamic range is met + if (max - min > MIN_DYNAMIC_RANGE) + { + // finish the rest of the rows quickly + for (yy++, offset += width; yy < BLOCK_SIZE; yy++, offset += width) + { + for (int xx = 0; xx < BLOCK_SIZE; xx++) + { + sum += luminances[offset + xx] & 0xFF; + } + } + } + } + + // The default estimate is the average of the values in the block. + int average = sum >> (BLOCK_SIZE_POWER * 2); + if (max - min <= MIN_DYNAMIC_RANGE) + { + // If variation within the block is low, assume this is a block with only light or only + // dark pixels. In that case we do not want to use the average, as it would divide this + // low contrast area into black and white pixels, essentially creating data out of noise. + // + // The default assumption is that the block is light/background. Since no estimate for + // the level of dark pixels exists locally, use half the min for the block. + average = min >> 1; + + if (y > 0 && x > 0) + { + // Correct the "white background" assumption for blocks that have neighbors by comparing + // the pixels in this block to the previously calculated black points. This is based on + // the fact that dark barcode symbology is always surrounded by some amount of light + // background for which reasonable black point estimates were made. The bp estimated at + // the boundaries is used for the interior. + + // The (min < bp) is arbitrary but works better than other heuristics that were tried. + int averageNeighborBlackPoint = (blackPoints[y - 1][x] + (2 * blackPoints[y][x - 1]) + + blackPoints[y - 1][x - 1]) >> 2; + if (min < averageNeighborBlackPoint) + { + average = averageNeighborBlackPoint; + } + } + } + blackPoints[y][x] = average; + } + } + return blackPoints; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/StringUtils.cs b/shadowsocks-csharp/3rd/zxing/common/StringUtils.cs new file mode 100755 index 00000000..55b5ec91 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/common/StringUtils.cs @@ -0,0 +1,266 @@ +/* + * Copyright (C) 2010 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 System.Text; + +namespace ZXing.Common +{ + /// + /// Common string-related functions. + /// + /// Sean Owen + /// Alex Dupre + public static class StringUtils + { +#if (WINDOWS_PHONE70 || WINDOWS_PHONE71 || WINDOWS_PHONE80 || SILVERLIGHT4 || SILVERLIGHT5 || NETFX_CORE || PORTABLE) + private const String PLATFORM_DEFAULT_ENCODING = "UTF-8"; +#else + private static String PLATFORM_DEFAULT_ENCODING = Encoding.Default.WebName; +#endif + public static String SHIFT_JIS = "SJIS"; + public static String GB2312 = "GB2312"; + private const String EUC_JP = "EUC-JP"; + private const String UTF8 = "UTF-8"; + private const String ISO88591 = "ISO-8859-1"; + private static readonly bool ASSUME_SHIFT_JIS = + String.Compare(SHIFT_JIS, PLATFORM_DEFAULT_ENCODING, StringComparison.OrdinalIgnoreCase) == 0 || + String.Compare(EUC_JP, PLATFORM_DEFAULT_ENCODING, StringComparison.OrdinalIgnoreCase) == 0; + + /// + /// Guesses the encoding. + /// + /// bytes encoding a string, whose encoding should be guessed + /// decode hints if applicable + /// name of guessed encoding; at the moment will only guess one of: + /// {@link #SHIFT_JIS}, {@link #UTF8}, {@link #ISO88591}, or the platform + /// default encoding if none of these can possibly be correct + public static String guessEncoding(byte[] bytes, IDictionary hints) + { + if (hints != null && hints.ContainsKey(DecodeHintType.CHARACTER_SET)) + { + String characterSet = (String)hints[DecodeHintType.CHARACTER_SET]; + if (characterSet != null) + { + return characterSet; + } + } + + // For now, merely tries to distinguish ISO-8859-1, UTF-8 and Shift_JIS, + // which should be by far the most common encodings. + int length = bytes.Length; + bool canBeISO88591 = true; + bool canBeShiftJIS = true; + bool canBeUTF8 = true; + int utf8BytesLeft = 0; + //int utf8LowChars = 0; + int utf2BytesChars = 0; + int utf3BytesChars = 0; + int utf4BytesChars = 0; + int sjisBytesLeft = 0; + //int sjisLowChars = 0; + int sjisKatakanaChars = 0; + //int sjisDoubleBytesChars = 0; + int sjisCurKatakanaWordLength = 0; + int sjisCurDoubleBytesWordLength = 0; + int sjisMaxKatakanaWordLength = 0; + int sjisMaxDoubleBytesWordLength = 0; + //int isoLowChars = 0; + //int isoHighChars = 0; + int isoHighOther = 0; + + bool utf8bom = bytes.Length > 3 && + bytes[0] == 0xEF && + bytes[1] == 0xBB && + bytes[2] == 0xBF; + + for (int i = 0; + i < length && (canBeISO88591 || canBeShiftJIS || canBeUTF8); + i++) + { + + int value = bytes[i] & 0xFF; + + // UTF-8 stuff + if (canBeUTF8) + { + if (utf8BytesLeft > 0) + { + if ((value & 0x80) == 0) + { + canBeUTF8 = false; + } + else + { + utf8BytesLeft--; + } + } + else if ((value & 0x80) != 0) + { + if ((value & 0x40) == 0) + { + canBeUTF8 = false; + } + else + { + utf8BytesLeft++; + if ((value & 0x20) == 0) + { + utf2BytesChars++; + } + else + { + utf8BytesLeft++; + if ((value & 0x10) == 0) + { + utf3BytesChars++; + } + else + { + utf8BytesLeft++; + if ((value & 0x08) == 0) + { + utf4BytesChars++; + } + else + { + canBeUTF8 = false; + } + } + } + } + } //else { + //utf8LowChars++; + //} + } + + // ISO-8859-1 stuff + if (canBeISO88591) + { + if (value > 0x7F && value < 0xA0) + { + canBeISO88591 = false; + } + else if (value > 0x9F) + { + if (value < 0xC0 || value == 0xD7 || value == 0xF7) + { + isoHighOther++; + } //else { + //isoHighChars++; + //} + } //else { + //isoLowChars++; + //} + } + + // Shift_JIS stuff + if (canBeShiftJIS) + { + if (sjisBytesLeft > 0) + { + if (value < 0x40 || value == 0x7F || value > 0xFC) + { + canBeShiftJIS = false; + } + else + { + sjisBytesLeft--; + } + } + else if (value == 0x80 || value == 0xA0 || value > 0xEF) + { + canBeShiftJIS = false; + } + else if (value > 0xA0 && value < 0xE0) + { + sjisKatakanaChars++; + sjisCurDoubleBytesWordLength = 0; + sjisCurKatakanaWordLength++; + if (sjisCurKatakanaWordLength > sjisMaxKatakanaWordLength) + { + sjisMaxKatakanaWordLength = sjisCurKatakanaWordLength; + } + } + else if (value > 0x7F) + { + sjisBytesLeft++; + //sjisDoubleBytesChars++; + sjisCurKatakanaWordLength = 0; + sjisCurDoubleBytesWordLength++; + if (sjisCurDoubleBytesWordLength > sjisMaxDoubleBytesWordLength) + { + sjisMaxDoubleBytesWordLength = sjisCurDoubleBytesWordLength; + } + } + else + { + //sjisLowChars++; + sjisCurKatakanaWordLength = 0; + sjisCurDoubleBytesWordLength = 0; + } + } + } + + if (canBeUTF8 && utf8BytesLeft > 0) + { + canBeUTF8 = false; + } + if (canBeShiftJIS && sjisBytesLeft > 0) + { + canBeShiftJIS = false; + } + + // Easy -- if there is BOM or at least 1 valid not-single byte character (and no evidence it can't be UTF-8), done + if (canBeUTF8 && (utf8bom || utf2BytesChars + utf3BytesChars + utf4BytesChars > 0)) + { + return UTF8; + } + // Easy -- if assuming Shift_JIS or at least 3 valid consecutive not-ascii characters (and no evidence it can't be), done + if (canBeShiftJIS && (ASSUME_SHIFT_JIS || sjisMaxKatakanaWordLength >= 3 || sjisMaxDoubleBytesWordLength >= 3)) + { + return SHIFT_JIS; + } + // Distinguishing Shift_JIS and ISO-8859-1 can be a little tough for short words. The crude heuristic is: + // - If we saw + // - only two consecutive katakana chars in the whole text, or + // - at least 10% of bytes that could be "upper" not-alphanumeric Latin1, + // - then we conclude Shift_JIS, else ISO-8859-1 + if (canBeISO88591 && canBeShiftJIS) + { + return (sjisMaxKatakanaWordLength == 2 && sjisKatakanaChars == 2) || isoHighOther * 10 >= length + ? SHIFT_JIS : ISO88591; + } + + // Otherwise, try in order ISO-8859-1, Shift JIS, UTF-8 and fall back to default platform encoding + if (canBeISO88591) + { + return ISO88591; + } + if (canBeShiftJIS) + { + return SHIFT_JIS; + } + if (canBeUTF8) + { + return UTF8; + } + // Otherwise, we take a wild guess with platform encoding + return PLATFORM_DEFAULT_ENCODING; + } + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/net2.0/Action.cs b/shadowsocks-csharp/3rd/zxing/net2.0/Action.cs new file mode 100755 index 00000000..88601bc1 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/net2.0/Action.cs @@ -0,0 +1,102 @@ +/* + * Copyright 2013 ZXing.Net 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 +{ +#if !WindowsCE + /// + /// for compatibility with .net 4.0 + /// + public delegate void Action(); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The param1. + public delegate void Action(T1 param1); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The param1. + /// The param2. + public delegate void Action(T1 param1, T2 param2); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The type of the 3. + /// The param1. + /// The param2. + /// The param3. + public delegate void Action(T1 param1, T2 param2, T3 param3); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The type of the 3. + /// The type of the 4. + /// The param1. + /// The param2. + /// The param3. + /// The param4. + public delegate void Action(T1 param1, T2 param2, T3 param3, T4 param4); +#else + /// + /// for compatibility with .net 4.0 + /// + public delegate void Action(); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The param1. + public delegate void Action(T1 param1); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The param1. + /// The param2. + public delegate void Action(T1 param1, T2 param2); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The type of the 3. + /// The param1. + /// The param2. + /// The param3. + public delegate void Action(T1 param1, T2 param2, T3 param3); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The type of the 3. + /// The type of the 4. + /// The param1. + /// The param2. + /// The param3. + /// The param4. + public delegate void Action(T1 param1, T2 param2, T3 param3, T4 param4); +#endif +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/net2.0/Func.cs b/shadowsocks-csharp/3rd/zxing/net2.0/Func.cs new file mode 100755 index 00000000..2b2388f1 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/net2.0/Func.cs @@ -0,0 +1,122 @@ +/* + * Copyright 2012 ZXing.Net 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 +{ +#if !WindowsCE + /// + /// for compatibility with .net 4.0 + /// + /// The type of the result. + /// + public delegate TResult Func(); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the result. + /// The param1. + /// + public delegate TResult Func(T1 param1); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The type of the result. + /// The param1. + /// The param2. + /// + public delegate TResult Func(T1 param1, T2 param2); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The type of the 3. + /// The type of the result. + /// The param1. + /// The param2. + /// The param3. + /// + public delegate TResult Func(T1 param1, T2 param2, T3 param3); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The type of the 3. + /// The type of the 4. + /// The type of the result. + /// The param1. + /// The param2. + /// The param3. + /// The param4. + /// + public delegate TResult Func(T1 param1, T2 param2, T3 param3, T4 param4); +#else + /// + /// for compatibility with .net 4.0 + /// + /// The type of the result. + /// + public delegate TResult Func(); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the result. + /// The param1. + /// + public delegate TResult Func(T1 param1); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The type of the result. + /// The param1. + /// The param2. + /// + public delegate TResult Func(T1 param1, T2 param2); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The type of the 3. + /// The type of the result. + /// The param1. + /// The param2. + /// The param3. + /// + public delegate TResult Func(T1 param1, T2 param2, T3 param3); + /// + /// for compatibility with .net 4.0 + /// + /// The type of the 1. + /// The type of the 2. + /// The type of the 3. + /// The type of the 4. + /// The type of the result. + /// The param1. + /// The param2. + /// The param3. + /// The param4. + /// + public delegate TResult Func(T1 param1, T2 param2, T3 param3, T4 param4); +#endif +} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/net2.0/TimeZoneInfo.cs b/shadowsocks-csharp/3rd/zxing/net2.0/TimeZoneInfo.cs new file mode 100755 index 00000000..c96f52c2 --- /dev/null +++ b/shadowsocks-csharp/3rd/zxing/net2.0/TimeZoneInfo.cs @@ -0,0 +1,29 @@ +/* + * Copyright 2012 ZXing.Net 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 System +{ + internal class TimeZoneInfo + { + internal static TimeZoneInfo Local = null; + + internal static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo destinationTimeZone) + { + // TODO: fix it for .net 2.0 + return dateTime; + } + } +} diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs index cb59141b..77a0b2cc 100755 --- a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs @@ -54,7 +54,7 @@ namespace ZXing.QrCode.Internal try { - //CharacterSetECI currentCharacterSetECI = null; + CharacterSetECI currentCharacterSetECI = null; bool fc1InEffect = false; Mode mode; do @@ -94,14 +94,29 @@ namespace ZXing.QrCode.Internal symbolSequence = bits.readBits(8); parityData = bits.readBits(8); } + else if (mode == Mode.ECI) + { + // Count doesn't apply to ECI + int value = parseECIValue(bits); + currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value); + if (currentCharacterSetECI == null) + { + return null; + } + } else { // First handle Hanzi mode which does not start with character count if (mode == Mode.HANZI) { //chinese mode contains a sub set indicator right after mode indicator - //int subset = bits.readBits(4); - //int countHanzi = bits.readBits(mode.getCharacterCountBits(version)); + int subset = bits.readBits(4); + int countHanzi = bits.readBits(mode.getCharacterCountBits(version)); + if (subset == GB2312_SUBSET) + { + if (!decodeHanziSegment(bits, result, countHanzi)) + return null; + } } else { @@ -118,6 +133,16 @@ namespace ZXing.QrCode.Internal if (!decodeAlphanumericSegment(bits, result, count, fc1InEffect)) return null; } + else if (mode == Mode.BYTE) + { + if (!decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints)) + return null; + } + else if (mode == Mode.KANJI) + { + if (!decodeKanjiSegment(bits, result, count)) + return null; + } else { return null; @@ -145,8 +170,214 @@ namespace ZXing.QrCode.Internal symbolSequence, parityData); } + /// + /// See specification GBT 18284-2000 + /// + /// The bits. + /// The result. + /// The count. + /// + private static bool decodeHanziSegment(BitSource bits, + StringBuilder result, + int count) + { + // Don't crash trying to read more bits than we have available. + if (count * 13 > bits.available()) + { + return false; + } + + // Each character will require 2 bytes. Read the characters as 2-byte pairs + // and decode as GB2312 afterwards + byte[] buffer = new byte[2 * count]; + int offset = 0; + while (count > 0) + { + // Each 13 bits encodes a 2-byte character + int twoBytes = bits.readBits(13); + int assembledTwoBytes = ((twoBytes / 0x060) << 8) | (twoBytes % 0x060); + if (assembledTwoBytes < 0x003BF) + { + // In the 0xA1A1 to 0xAAFE range + assembledTwoBytes += 0x0A1A1; + } + else + { + // In the 0xB0A1 to 0xFAFE range + assembledTwoBytes += 0x0A6A1; + } + buffer[offset] = (byte)((assembledTwoBytes >> 8) & 0xFF); + buffer[offset + 1] = (byte)(assembledTwoBytes & 0xFF); + offset += 2; + count--; + } + + try + { + result.Append(Encoding.GetEncoding(StringUtils.GB2312).GetString(buffer, 0, buffer.Length)); + } +#if (WINDOWS_PHONE70 || WINDOWS_PHONE71 || SILVERLIGHT4 || SILVERLIGHT5 || NETFX_CORE || MONOANDROID || MONOTOUCH) + catch (ArgumentException) + { + try + { + // Silverlight only supports a limited number of character sets, trying fallback to UTF-8 + result.Append(Encoding.GetEncoding("UTF-8").GetString(buffer, 0, buffer.Length)); + } + catch (Exception) + { + return false; + } + } +#endif + catch (Exception) + { + return false; + } + + return true; + } + private static bool decodeKanjiSegment(BitSource bits, + StringBuilder result, + int count) + { + // Don't crash trying to read more bits than we have available. + if (count * 13 > bits.available()) + { + return false; + } + // Each character will require 2 bytes. Read the characters as 2-byte pairs + // and decode as Shift_JIS afterwards + byte[] buffer = new byte[2 * count]; + int offset = 0; + while (count > 0) + { + // Each 13 bits encodes a 2-byte character + int twoBytes = bits.readBits(13); + int assembledTwoBytes = ((twoBytes / 0x0C0) << 8) | (twoBytes % 0x0C0); + if (assembledTwoBytes < 0x01F00) + { + // In the 0x8140 to 0x9FFC range + assembledTwoBytes += 0x08140; + } + else + { + // In the 0xE040 to 0xEBBF range + assembledTwoBytes += 0x0C140; + } + buffer[offset] = (byte)(assembledTwoBytes >> 8); + buffer[offset + 1] = (byte)assembledTwoBytes; + offset += 2; + count--; + } + // Shift_JIS may not be supported in some environments: + try + { + result.Append(Encoding.GetEncoding(StringUtils.SHIFT_JIS).GetString(buffer, 0, buffer.Length)); + } +#if (WINDOWS_PHONE70 || WINDOWS_PHONE71 || SILVERLIGHT4 || SILVERLIGHT5 || NETFX_CORE || MONOANDROID || MONOTOUCH) + catch (ArgumentException) + { + try + { + // Silverlight only supports a limited number of character sets, trying fallback to UTF-8 + result.Append(Encoding.GetEncoding("UTF-8").GetString(buffer, 0, buffer.Length)); + } + catch (Exception) + { + return false; + } + } +#endif + catch (Exception) + { + return false; + } + return true; + } + + private static bool decodeByteSegment(BitSource bits, + StringBuilder result, + int count, + CharacterSetECI currentCharacterSetECI, + IList byteSegments, + IDictionary hints) + { + // Don't crash trying to read more bits than we have available. + if (count << 3 > bits.available()) + { + return false; + } + + byte[] readBytes = new byte[count]; + for (int i = 0; i < count; i++) + { + readBytes[i] = (byte)bits.readBits(8); + } + String encoding; + if (currentCharacterSetECI == null) + { + // The spec isn't clear on this mode; see + // section 6.4.5: t does not say which encoding to assuming + // upon decoding. I have seen ISO-8859-1 used as well as + // Shift_JIS -- without anything like an ECI designator to + // give a hint. + encoding = StringUtils.guessEncoding(readBytes, hints); + } + else + { + encoding = currentCharacterSetECI.EncodingName; + } + try + { + result.Append(Encoding.GetEncoding(encoding).GetString(readBytes, 0, readBytes.Length)); + } +#if (WINDOWS_PHONE70 || WINDOWS_PHONE71 || SILVERLIGHT4 || SILVERLIGHT5 || NETFX_CORE || MONOANDROID || MONOTOUCH) + catch (ArgumentException) + { + try + { + // Silverlight only supports a limited number of character sets, trying fallback to UTF-8 + result.Append(Encoding.GetEncoding("UTF-8").GetString(readBytes, 0, readBytes.Length)); + } + catch (Exception) + { + return false; + } + } +#endif +#if WindowsCE + catch (PlatformNotSupportedException) + { + try + { + // WindowsCE doesn't support all encodings. But it is device depended. + // So we try here the some different ones + if (encoding == "ISO-8859-1") + { + result.Append(Encoding.GetEncoding(1252).GetString(readBytes, 0, readBytes.Length)); + } + else + { + result.Append(Encoding.GetEncoding("UTF-8").GetString(readBytes, 0, readBytes.Length)); + } + } + catch (Exception) + { + return false; + } + } +#endif + catch (Exception) + { + return false; + } + byteSegments.Add(readBytes); + + return true; + } private static char toAlphaNumericChar(int value) { diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index acd46995..a4d43563 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.Drawing; using System.Text; using System.Windows.Forms; +using ZXing; namespace Shadowsocks.View { @@ -143,6 +144,7 @@ namespace Shadowsocks.View CreateMenuItem("Update PAC from GFWList", new EventHandler(this.UpdatePACFromGFWListItem_Click)), new MenuItem("-"), CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)), + CreateMenuItem("Scan QRCode...", new EventHandler(this.ScanQRCodeItem_Click)), CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)), CreateMenuItem("About...", new EventHandler(this.AboutItem_Click)), new MenuItem("-"), @@ -359,41 +361,32 @@ namespace Shadowsocks.View private void ScanQRCodeItem_Click(object sender, EventArgs e) { - /* - using (Bitmap image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, + + using (Bitmap image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)) { - using (Graphics g = Graphics.FromImage(bmpScreenCapture)) + using (Graphics g = Graphics.FromImage(image)) { g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, - bmpScreenCapture.Size, + image.Size, CopyPixelOperation.SourceCopy); } - resultPoints.Clear(); - /* var reader = new BarcodeReader + var reader = new BarcodeReader { + TryHarder = true, PossibleFormats = new List - { + { BarcodeFormat.QR_CODE - } + } }; - var result = reader.Decode(image); - var result = barcodeReader.Decode(image); - var timerStart = DateTime.Now.Ticks; - var timerStop = DateTime.Now.Ticks; - - if (result == null) + if (result != null) { - txtDecoderContent.Text = "No barcode recognized"; + Console.WriteLine(result.Text); } - labDuration.Text = new TimeSpan(timerStop - timerStart).Milliseconds.ToString("0 ms"); - } - } - * */ } private void AutoStartupItem_Click(object sender, EventArgs e) { diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 4c335313..1d91db51 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -71,6 +71,8 @@ + + @@ -78,22 +80,33 @@ + + + + + + + + + + + @@ -125,6 +138,7 @@ + From e878b415190f3afdb18918b056f24aedcc979236 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Mon, 12 Jan 2015 01:55:03 +0800 Subject: [PATCH 25/45] implement ssurl scan --- .../Controller/ShadowsocksController.cs | 17 ++++++++++ shadowsocks-csharp/Data/cn.txt | 3 +- shadowsocks-csharp/Model/Configuration.cs | 10 +----- shadowsocks-csharp/Model/Server.cs | 37 ++++++++++++++++++++++ shadowsocks-csharp/View/MenuViewController.cs | 24 ++++++++------ 5 files changed, 72 insertions(+), 19 deletions(-) diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index 1e193158..113242a7 100755 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -80,6 +80,23 @@ namespace Shadowsocks.Controller SaveConfig(_config); } + public bool AddServerBySSURL(string ssURL) + { + try + { + var server = new Server(ssURL); + _config.configs.Add(server); + _config.index = _config.configs.Count - 1; + SaveConfig(_config); + return true; + } + catch (Exception e) + { + Logging.LogUsefulException(e); + return false; + } + } + public void ToggleEnable(bool enabled) { _config.enabled = enabled; diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index 9f8c6da1..e091b276 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -3,12 +3,13 @@ Enable=启用代理 Mode=代理模式 PAC=PAC 模式 Global=全局模式 -Servers=服务器选择 +Servers=服务器 Edit Servers...=编辑服务器... Start on Boot=开机启动 Share over LAN=在局域网共享代理 Edit PAC File...=编辑 PAC 文件... Show QRCode...=显示二维码... +Scan QRCode from Screen...=扫描屏幕上的二维码... Show Logs...=显示日志... About...=关于... Quit=退出 diff --git a/shadowsocks-csharp/Model/Configuration.cs b/shadowsocks-csharp/Model/Configuration.cs index 63b4c750..4b6e0ecb 100755 --- a/shadowsocks-csharp/Model/Configuration.cs +++ b/shadowsocks-csharp/Model/Configuration.cs @@ -94,15 +94,7 @@ namespace Shadowsocks.Model public static Server GetDefaultServer() { - return new Server() - { - server = "", - server_port = 8388, - local_port = 1080, - method = "aes-256-cfb", - password = "", - remarks = "" - }; + return new Server(); } private static void Assert(bool condition) diff --git a/shadowsocks-csharp/Model/Server.cs b/shadowsocks-csharp/Model/Server.cs index 382efcbe..b4486db9 100755 --- a/shadowsocks-csharp/Model/Server.cs +++ b/shadowsocks-csharp/Model/Server.cs @@ -5,6 +5,7 @@ using System.IO; using System.Diagnostics; using SimpleJson; using Shadowsocks.Controller; +using System.Text.RegularExpressions; namespace Shadowsocks.Model { @@ -33,5 +34,41 @@ namespace Shadowsocks.Model return remarks + " (" + server + ":" + server_port + ")"; } } + + public Server() + { + this.server = ""; + this.server_port = 8388; + this.local_port = 1080; + this.method = "aes-256-cfb"; + this.password = ""; + this.remarks = ""; + } + + public Server(string ssURL) : this() + { + string[] r1 = Regex.Split(ssURL, "ss://", RegexOptions.IgnoreCase); + string base64 = r1[1].ToString(); + byte[] bytes = null; + for (var i = 0; i < 3; i++) { + try + { + bytes = System.Convert.FromBase64String(base64); + } + catch (FormatException) + { + base64 += "="; + } + } + if (bytes == null) + { + throw new FormatException(); + } + string[] parts = Encoding.UTF8.GetString(bytes).Split(new char[2] { ':', '@' }); + this.method = parts[0].ToString(); + this.password = parts[1].ToString(); + this.server = parts[2].ToString(); + this.server_port = int.Parse(parts[3].ToString()); + } } } diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index a4d43563..4a514ac0 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -135,7 +135,9 @@ namespace Shadowsocks.View }), this.ServersItem = CreateMenuGroup("Servers", new MenuItem[] { this.SeperatorItem = new MenuItem("-"), - this.ConfigItem = CreateMenuItem("Edit Servers...", new EventHandler(this.Config_Click)) + this.ConfigItem = CreateMenuItem("Edit Servers...", new EventHandler(this.Config_Click)), + CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)), + CreateMenuItem("Scan QRCode from Screen...", new EventHandler(this.ScanQRCodeItem_Click)) }), new MenuItem("-"), this.AutoStartupItem = CreateMenuItem("Start on Boot", new EventHandler(this.AutoStartupItem_Click)), @@ -143,8 +145,6 @@ namespace Shadowsocks.View CreateMenuItem("Edit PAC File...", new EventHandler(this.EditPACFileItem_Click)), CreateMenuItem("Update PAC from GFWList", new EventHandler(this.UpdatePACFromGFWListItem_Click)), new MenuItem("-"), - CreateMenuItem("Show QRCode...", new EventHandler(this.QRCodeItem_Click)), - CreateMenuItem("Scan QRCode...", new EventHandler(this.ScanQRCodeItem_Click)), CreateMenuItem("Show Logs...", new EventHandler(this.ShowLogItem_Click)), CreateMenuItem("About...", new EventHandler(this.AboutItem_Click)), new MenuItem("-"), @@ -228,8 +228,10 @@ namespace Shadowsocks.View private void UpdateServersMenu() { var items = ServersItem.MenuItems; - - items.Clear(); + while (items[0] != SeperatorItem) + { + items.RemoveAt(0); + } Configuration configuration = controller.GetConfiguration(); for (int i = 0; i < configuration.configs.Count; i++) @@ -238,10 +240,8 @@ namespace Shadowsocks.View MenuItem item = new MenuItem(server.FriendlyName()); item.Tag = i; item.Click += AServerItem_Click; - items.Add(item); + items.Add(i, item); } - items.Add(SeperatorItem); - items.Add(ConfigItem); if (configuration.index >= 0 && configuration.index < configuration.configs.Count) { @@ -384,8 +384,14 @@ namespace Shadowsocks.View var result = reader.Decode(image); if (result != null) { - Console.WriteLine(result.Text); + var success = controller.AddServerBySSURL(result.Text); + if (success) + { + ShowConfigForm(); + return; + } } + MessageBox.Show(I18N.GetString("Failed to scan QRCode")); } } From de0f752cc8ff914a232ce31e034a4f31aca93bb1 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Mon, 12 Jan 2015 02:44:24 +0800 Subject: [PATCH 26/45] add visual feedback --- shadowsocks-csharp/View/MenuViewController.cs | 26 +++++++++++++++++++++++++- shadowsocks-csharp/View/QRCodeForm.Designer.cs | 6 +++--- shadowsocks-csharp/View/QRCodeForm.cs | 2 +- shadowsocks-csharp/shadowsocks-csharp.csproj | 9 +++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 4a514ac0..d0eb8d92 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -387,7 +387,26 @@ namespace Shadowsocks.View var success = controller.AddServerBySSURL(result.Text); if (success) { - ShowConfigForm(); + float minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0; + foreach (ResultPoint point in result.ResultPoints) + { + minX = Math.Min(minX, point.X); + minY = Math.Min(minY, point.Y); + maxX = Math.Max(maxX, point.X); + maxY = Math.Max(maxY, point.Y); + } + // make it 20% larger + float margin = (maxX - minX) * 0.20f; + minX -= margin; + maxX += margin; + minY -= margin; + maxY += margin; + + QRCodeSplashForm splash = new QRCodeSplashForm(); + splash.FormClosed += splash_FormClosed; + splash.Location = new Point((int)minX, (int)minY); + splash.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY); + splash.Show(); return; } } @@ -395,6 +414,11 @@ namespace Shadowsocks.View } } + void splash_FormClosed(object sender, FormClosedEventArgs e) + { + ShowConfigForm(); + } + private void AutoStartupItem_Click(object sender, EventArgs e) { AutoStartupItem.Checked = !AutoStartupItem.Checked; if (!AutoStartup.Set(AutoStartupItem.Checked)) { diff --git a/shadowsocks-csharp/View/QRCodeForm.Designer.cs b/shadowsocks-csharp/View/QRCodeForm.Designer.cs index 89a07907..d334c761 100755 --- a/shadowsocks-csharp/View/QRCodeForm.Designer.cs +++ b/shadowsocks-csharp/View/QRCodeForm.Designer.cs @@ -34,10 +34,10 @@ // // pictureBox1 // - this.pictureBox1.Location = new System.Drawing.Point(9, 9); + this.pictureBox1.Location = new System.Drawing.Point(10, 10); this.pictureBox1.Margin = new System.Windows.Forms.Padding(0); this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(210, 210); + this.pictureBox1.Size = new System.Drawing.Size(240, 240); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox1.TabIndex = 1; this.pictureBox1.TabStop = false; @@ -55,7 +55,7 @@ this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "QRCodeForm"; - this.Padding = new System.Windows.Forms.Padding(9); + this.Padding = new System.Windows.Forms.Padding(10); this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "QRCode"; this.Load += new System.EventHandler(this.QRCodeForm_Load); diff --git a/shadowsocks-csharp/View/QRCodeForm.cs b/shadowsocks-csharp/View/QRCodeForm.cs index 21ea3ab5..2741d4ff 100755 --- a/shadowsocks-csharp/View/QRCodeForm.cs +++ b/shadowsocks-csharp/View/QRCodeForm.cs @@ -30,7 +30,7 @@ namespace Shadowsocks.View string qrText = ssconfig; QRCode code = ZXing.QrCode.Internal.Encoder.encode(qrText, ErrorCorrectionLevel.M); ByteMatrix m = code.Matrix; - int blockSize = Math.Max(200 / m.Height, 1); + int blockSize = Math.Max(pictureBox1.Height / m.Height, 1); Bitmap drawArea = new Bitmap((m.Width * blockSize), (m.Height * blockSize)); using (Graphics g = Graphics.FromImage(drawArea)) { diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 1d91db51..15a53037 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -183,6 +183,12 @@ QRCodeForm.cs + + Form + + + QRCodeSplashForm.cs + ConfigForm.cs Designer @@ -195,6 +201,9 @@ QRCodeForm.cs + + QRCodeSplashForm.cs + Designer From d995169fecf4f06552bb07656343dd11d3c6ccb1 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Mon, 12 Jan 2015 03:06:21 +0800 Subject: [PATCH 27/45] add feedback --- .../View/QRCodeSplashForm.Designer.cs | 57 ++++++++++ shadowsocks-csharp/View/QRCodeSplashForm.cs | 64 +++++++++++ shadowsocks-csharp/View/QRCodeSplashForm.resx | 120 +++++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100755 shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs create mode 100755 shadowsocks-csharp/View/QRCodeSplashForm.cs create mode 100755 shadowsocks-csharp/View/QRCodeSplashForm.resx diff --git a/shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs b/shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs new file mode 100755 index 00000000..87f9dd68 --- /dev/null +++ b/shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs @@ -0,0 +1,57 @@ +namespace Shadowsocks.View +{ + partial class QRCodeSplashForm + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.SuspendLayout(); + // + // QRCodeSplashForm + // + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.BackColor = System.Drawing.Color.Crimson; + this.ClientSize = new System.Drawing.Size(284, 262); + this.ControlBox = false; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "QRCodeSplashForm"; + this.Opacity = 0.3D; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; + this.Text = "QRCodeSplashForm"; + this.TopMost = true; + this.Load += new System.EventHandler(this.QRCodeSplashForm_Load); + this.ResumeLayout(false); + + } + + #endregion + } +} \ No newline at end of file diff --git a/shadowsocks-csharp/View/QRCodeSplashForm.cs b/shadowsocks-csharp/View/QRCodeSplashForm.cs new file mode 100755 index 00000000..3d14785e --- /dev/null +++ b/shadowsocks-csharp/View/QRCodeSplashForm.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Text; +using System.Windows.Forms; + +namespace Shadowsocks.View +{ + public partial class QRCodeSplashForm : Form + { + public QRCodeSplashForm() + { + InitializeComponent(); + } + + private Timer timer; + private int step; + + private void QRCodeSplashForm_Load(object sender, EventArgs e) + { + step = 0; + timer = new Timer(); + timer.Interval = 300; + timer.Tick += timer_Tick; + timer.Start(); + } + + void timer_Tick(object sender, EventArgs e) + { + timer.Interval = 40; + if (step == 0) + { + this.Opacity = 0; + } + else if (step == 1) + { + this.Opacity = 0.3; + } + else if (step == 1) + { + this.Opacity = 0.0; + } + else if (step == 2) + { + this.Opacity = 0.3; + } + else if (step == 3) + { + this.Opacity = 0.0; + } + else if (step == 4) + { + this.Opacity = 0.3; + } + else + { + this.Close(); + } + step++; + } + } +} diff --git a/shadowsocks-csharp/View/QRCodeSplashForm.resx b/shadowsocks-csharp/View/QRCodeSplashForm.resx new file mode 100755 index 00000000..5ea0895e --- /dev/null +++ b/shadowsocks-csharp/View/QRCodeSplashForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file From 0f1aff24a5e2d2f5f36579d35649af229faad218 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 13 Jan 2015 01:32:08 +0800 Subject: [PATCH 28/45] try 5 different focus --- shadowsocks-csharp/Data/cn.txt | 2 + shadowsocks-csharp/View/MenuViewController.cs | 75 +++++++++++++++------- .../View/QRCodeSplashForm.Designer.cs | 17 ++++- 3 files changed, 71 insertions(+), 23 deletions(-) diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index e091b276..82ea1744 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -43,3 +43,5 @@ Disabled=已禁用代理 Update PAC from GFWList=从 GFWList 更新 PAC Failed to update PAC file =更新 PAC 文件失败 PAC updated=更新 PAC 成功 +"Failed to find QRCode=无法找到二维码 +Failed to decode QRCode=无法解析二维码 diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index d0eb8d92..fb09202f 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -33,6 +33,7 @@ namespace Shadowsocks.View private MenuItem globalModeItem; private MenuItem PACModeItem; private ConfigForm configForm; + private string _urlToOpen; public MenuViewController(ShadowsocksController controller) { @@ -362,31 +363,57 @@ namespace Shadowsocks.View private void ScanQRCodeItem_Click(object sender, EventArgs e) { - using (Bitmap image = new Bitmap(Screen.PrimaryScreen.Bounds.Width, + using (Bitmap fullImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height)) { - using (Graphics g = Graphics.FromImage(image)) + using (Graphics g = Graphics.FromImage(fullImage)) { g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, - image.Size, + fullImage.Size, CopyPixelOperation.SourceCopy); } - var reader = new BarcodeReader + for (int i = 0; i < 5; i++) { - TryHarder = true, - PossibleFormats = new List + int marginLeft = fullImage.Width * i / 3 / 5; + int marginTop = fullImage.Height * i / 3 / 5; + Rectangle cropRect = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2); + Bitmap target = new Bitmap(cropRect.Width, cropRect.Height); + + using (Graphics g = Graphics.FromImage(target)) { - BarcodeFormat.QR_CODE + g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height), + cropRect, + GraphicsUnit.Pixel); } - }; - var result = reader.Decode(image); - if (result != null) - { - var success = controller.AddServerBySSURL(result.Text); - if (success) + var reader = new BarcodeReader + { + TryHarder = true, + PossibleFormats = new List + { + BarcodeFormat.QR_CODE + } + }; + var result = reader.Decode(target); + if (result != null) { + var success = controller.AddServerBySSURL(result.Text); + QRCodeSplashForm splash = new QRCodeSplashForm(); + if (success) + { + splash.FormClosed += splash_FormClosed; + } + else if (result.Text.StartsWith("http://") || result.Text.StartsWith("https://")) + { + _urlToOpen = result.Text; + splash.FormClosed += openURLFromQRCode; + } + else + { + MessageBox.Show(I18N.GetString("Failed to decode QRCode")); + return; + } float minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0; foreach (ResultPoint point in result.ResultPoints) { @@ -397,21 +424,20 @@ namespace Shadowsocks.View } // make it 20% larger float margin = (maxX - minX) * 0.20f; - minX -= margin; - maxX += margin; - minY -= margin; - maxY += margin; - - QRCodeSplashForm splash = new QRCodeSplashForm(); - splash.FormClosed += splash_FormClosed; + minX += -margin + marginLeft; + maxX += margin + marginLeft; + minY += -margin + marginTop; + maxY += margin + marginTop; splash.Location = new Point((int)minX, (int)minY); - splash.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY); + // we need a panel because a window has a minimal size + splash.Panel.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY); + splash.Size = splash.Panel.Size; splash.Show(); return; } } - MessageBox.Show(I18N.GetString("Failed to scan QRCode")); } + MessageBox.Show(I18N.GetString("Failed to find QRCode")); } void splash_FormClosed(object sender, FormClosedEventArgs e) @@ -419,6 +445,11 @@ namespace Shadowsocks.View ShowConfigForm(); } + void openURLFromQRCode(object sender, FormClosedEventArgs e) + { + Process.Start(_urlToOpen); + } + private void AutoStartupItem_Click(object sender, EventArgs e) { AutoStartupItem.Checked = !AutoStartupItem.Checked; if (!AutoStartup.Set(AutoStartupItem.Checked)) { diff --git a/shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs b/shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs index 87f9dd68..0c7e1601 100755 --- a/shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs +++ b/shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs @@ -28,14 +28,25 @@ ///
private void InitializeComponent() { + this.Panel = new System.Windows.Forms.Panel(); this.SuspendLayout(); // + // Panel + // + this.Panel.BackColor = System.Drawing.Color.Crimson; + this.Panel.Location = new System.Drawing.Point(0, 0); + this.Panel.Margin = new System.Windows.Forms.Padding(0); + this.Panel.Name = "Panel"; + this.Panel.Size = new System.Drawing.Size(168, 158); + this.Panel.TabIndex = 0; + // // QRCodeSplashForm // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.BackColor = System.Drawing.Color.Crimson; + this.BackColor = System.Drawing.Color.White; this.ClientSize = new System.Drawing.Size(284, 262); this.ControlBox = false; + this.Controls.Add(this.Panel); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.MaximizeBox = false; this.MinimizeBox = false; @@ -47,11 +58,15 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Text = "QRCodeSplashForm"; this.TopMost = true; + this.TransparencyKey = System.Drawing.Color.White; this.Load += new System.EventHandler(this.QRCodeSplashForm_Load); this.ResumeLayout(false); } #endregion + + public System.Windows.Forms.Panel Panel; + } } \ No newline at end of file From dce38883a5e77f1618674efc8903d385e280f56d Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 13 Jan 2015 01:51:51 +0800 Subject: [PATCH 29/45] refactor --- shadowsocks-csharp/View/MenuViewController.cs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index fb09202f..f8b33e92 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -8,6 +8,8 @@ using System.Drawing; using System.Text; using System.Windows.Forms; using ZXing; +using ZXing.Common; +using ZXing.QrCode; namespace Shadowsocks.View { @@ -387,15 +389,10 @@ namespace Shadowsocks.View cropRect, GraphicsUnit.Pixel); } - var reader = new BarcodeReader - { - TryHarder = true, - PossibleFormats = new List - { - BarcodeFormat.QR_CODE - } - }; - var result = reader.Decode(target); + var source = new BitmapLuminanceSource(target); + var bitmap = new BinaryBitmap(new HybridBinarizer(source)); + QRCodeReader reader = new QRCodeReader(); + var result = reader.decode(bitmap); if (result != null) { var success = controller.AddServerBySSURL(result.Text); From 49d04316cdb46d1218da8200d1091d7b2bfe21a0 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 13 Jan 2015 01:53:49 +0800 Subject: [PATCH 30/45] remove some class --- shadowsocks-csharp/3rd/zxing/BarcodeReader.cs | 152 ------- .../3rd/zxing/BarcodeReaderGeneric.cs | 436 --------------------- shadowsocks-csharp/3rd/zxing/IBarcodeReader.cs | 161 -------- .../3rd/zxing/IBarcodeReaderGeneric.cs | 123 ------ shadowsocks-csharp/3rd/zxing/RGBLuminanceSource.cs | 314 --------------- shadowsocks-csharp/shadowsocks-csharp.csproj | 5 - 6 files changed, 1191 deletions(-) delete mode 100755 shadowsocks-csharp/3rd/zxing/BarcodeReader.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/BarcodeReaderGeneric.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/IBarcodeReader.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/IBarcodeReaderGeneric.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/RGBLuminanceSource.cs diff --git a/shadowsocks-csharp/3rd/zxing/BarcodeReader.cs b/shadowsocks-csharp/3rd/zxing/BarcodeReader.cs deleted file mode 100755 index 5363a4d9..00000000 --- a/shadowsocks-csharp/3rd/zxing/BarcodeReader.cs +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright 2012 ZXing.Net 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; -#if !PORTABLE -#if !(SILVERLIGHT || NETFX_CORE) -#if !UNITY -using System.Drawing; -using ZXing.QrCode; -#else -using UnityEngine; -#endif -#elif NETFX_CORE -using Windows.UI.Xaml.Media.Imaging; -#else -using System.Windows.Media.Imaging; -#endif -#endif -#if MONOANDROID -using Android.Graphics; -#endif - -namespace ZXing -{ - /// - /// A smart class to decode the barcode inside a bitmap object - /// -#if MONOTOUCH - public class BarcodeReader : BarcodeReaderGeneric, IBarcodeReader, IMultipleBarcodeReader - { - private static readonly Func defaultCreateLuminanceSource = - (img) => new RGBLuminanceSource(img); -#else -#if !PORTABLE -#if !(SILVERLIGHT || NETFX_CORE) -#if !UNITY - public class BarcodeReader : BarcodeReaderGeneric, IBarcodeReader - { - private static readonly Func defaultCreateLuminanceSource = - (bitmap) => new BitmapLuminanceSource(bitmap); -#else - public class BarcodeReader : BarcodeReaderGeneric, IBarcodeReader, IMultipleBarcodeReader - { - private static readonly Func defaultCreateLuminanceSource = - (rawColor32, width, height) => new Color32LuminanceSource(rawColor32, width, height); -#endif -#else - public class BarcodeReader : BarcodeReaderGeneric, IBarcodeReader, IMultipleBarcodeReader - { - private static readonly Func defaultCreateLuminanceSource = - (bitmap) => new BitmapLuminanceSource(bitmap); -#endif -#else - public class BarcodeReader : BarcodeReaderGeneric, IBarcodeReader, IMultipleBarcodeReader - { - private static readonly Func defaultCreateLuminanceSource = - (data) => null; -#endif -#endif - /// - /// Initializes a new instance of the class. - /// - public BarcodeReader() - : this(new QRCodeReader(), defaultCreateLuminanceSource, null) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Sets the reader which should be used to find and decode the barcode. - /// If null then MultiFormatReader is used - /// Sets the function to create a luminance source object for a bitmap. - /// If null, an exception is thrown when Decode is called - /// Sets the function to create a binarizer object for a luminance source. - /// If null then HybridBinarizer is used - public BarcodeReader(Reader reader, -#if MONOTOUCH - Func createLuminanceSource, -#elif MONOANDROID - Func createLuminanceSource, -#else -#if !(SILVERLIGHT || NETFX_CORE) -#if !UNITY -#if !PORTABLE - Func createLuminanceSource, -#else - Func createLuminanceSource, -#endif -#else - Func createLuminanceSource, -#endif -#else - Func createLuminanceSource, -#endif -#endif - Func createBinarizer - ) - : base(reader, createLuminanceSource ?? defaultCreateLuminanceSource, createBinarizer) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Sets the reader which should be used to find and decode the barcode. - /// If null then MultiFormatReader is used - /// Sets the function to create a luminance source object for a bitmap. - /// If null, an exception is thrown when Decode is called - /// Sets the function to create a binarizer object for a luminance source. - /// If null then HybridBinarizer is used - public BarcodeReader(Reader reader, -#if MONOTOUCH - Func createLuminanceSource, -#elif MONOANDROID - Func createLuminanceSource, -#else -#if !(SILVERLIGHT || NETFX_CORE) -#if !UNITY -#if !PORTABLE - Func createLuminanceSource, -#else - Func createLuminanceSource, -#endif -#else - Func createLuminanceSource, -#endif -#else - Func createLuminanceSource, -#endif -#endif - Func createBinarizer, - Func createRGBLuminanceSource - ) - : base(reader, createLuminanceSource ?? defaultCreateLuminanceSource, createBinarizer, createRGBLuminanceSource) - { - } - } -} diff --git a/shadowsocks-csharp/3rd/zxing/BarcodeReaderGeneric.cs b/shadowsocks-csharp/3rd/zxing/BarcodeReaderGeneric.cs deleted file mode 100755 index 3ce46568..00000000 --- a/shadowsocks-csharp/3rd/zxing/BarcodeReaderGeneric.cs +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright 2012 ZXing.Net 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.QrCode; - -namespace ZXing -{ - /// - /// A smart class to decode the barcode inside a bitmap object - /// - public class BarcodeReaderGeneric : IBarcodeReaderGeneric - { - private static readonly Func defaultCreateBinarizer = - (luminanceSource) => new HybridBinarizer(luminanceSource); - - protected static readonly Func defaultCreateRGBLuminanceSource = - (rawBytes, width, height, format) => new RGBLuminanceSource(rawBytes, width, height, format); - - private Reader reader; - private readonly Func createRGBLuminanceSource; -#if !UNITY - private readonly Func createLuminanceSource; -#else - private readonly Func createLuminanceSource; -#endif - private readonly Func createBinarizer; - private bool usePreviousState; - private DecodingOptions options; - - /// - /// Gets or sets the options. - /// - /// - /// The options. - /// - public DecodingOptions Options - { - get { return options ?? (options = new DecodingOptions()); } - set { options = value; } - } - - /// - /// Gets the reader which should be used to find and decode the barcode. - /// - /// - /// The reader. - /// - protected Reader Reader - { - get - { - return reader ?? (reader = new QRCodeReader()); - } - } - - /// - /// Gets or sets a method which is called if an important point is found - /// - /// - /// The result point callback. - /// - public event Action ResultPointFound - { - add - { - if (!Options.Hints.ContainsKey(DecodeHintType.NEED_RESULT_POINT_CALLBACK)) - { - var callback = new ResultPointCallback(OnResultPointFound); - Options.Hints[DecodeHintType.NEED_RESULT_POINT_CALLBACK] = callback; - } - explicitResultPointFound += value; - usePreviousState = false; - } - remove - { - explicitResultPointFound -= value; - if (explicitResultPointFound == null) - Options.Hints.Remove(DecodeHintType.NEED_RESULT_POINT_CALLBACK); - usePreviousState = false; - } - } - - private event Action explicitResultPointFound; - - /// - /// event is executed if a result was found via decode - /// - public event Action ResultFound; - - /// - /// Gets or sets a flag which cause a deeper look into the bitmap - /// - /// - /// true if [try harder]; otherwise, false. - /// - [Obsolete("Please use the Options.TryHarder property instead.")] - public bool TryHarder - { - get { return Options.TryHarder; } - set { Options.TryHarder = value; } - } - - /// - /// Image is a pure monochrome image of a barcode. - /// - /// - /// true if monochrome image of a barcode; otherwise, false. - /// - [Obsolete("Please use the Options.PureBarcode property instead.")] - public bool PureBarcode - { - get { return Options.PureBarcode; } - set { Options.PureBarcode = value; } - } - - /// - /// Specifies what character encoding to use when decoding, where applicable (type String) - /// - /// - /// The character set. - /// - [Obsolete("Please use the Options.CharacterSet property instead.")] - public string CharacterSet - { - get { return Options.CharacterSet; } - set { Options.CharacterSet = value; } - } - - /// - /// Image is known to be of one of a few possible formats. - /// Maps to a {@link java.util.List} of {@link BarcodeFormat}s. - /// - /// - /// The possible formats. - /// - [Obsolete("Please use the Options.PossibleFormats property instead.")] - public IList PossibleFormats - { - get { return Options.PossibleFormats; } - set { Options.PossibleFormats = value; } - } - - /// - /// Gets or sets a value indicating whether the image should be automatically rotated. - /// Rotation is supported for 90, 180 and 270 degrees - /// - /// - /// true if image should be rotated; otherwise, false. - /// - public bool AutoRotate { get; set; } - - /// - /// Gets or sets a value indicating whether the image should be automatically inverted - /// if no result is found in the original image. - /// ATTENTION: Please be carefully because it slows down the decoding process if it is used - /// - /// - /// true if image should be inverted; otherwise, false. - /// - public bool TryInverted { get; set; } - -#if !UNITY - /// - /// Optional: Gets or sets the function to create a luminance source object for a bitmap. - /// If null a platform specific default LuminanceSource is used - /// - /// - /// The function to create a luminance source object. - /// - protected Func CreateLuminanceSource -#else - /// - /// Optional: Gets or sets the function to create a luminance source object for a bitmap. - /// If null a platform specific default LuminanceSource is used - /// - /// - /// The function to create a luminance source object. - /// - protected Func CreateLuminanceSource -#endif - { - get - { - return createLuminanceSource; - } - } - - /// - /// Optional: Gets or sets the function to create a binarizer object for a luminance source. - /// If null then HybridBinarizer is used - /// - /// - /// The function to create a binarizer object. - /// - protected Func CreateBinarizer - { - get - { - return createBinarizer ?? defaultCreateBinarizer; - } - } - - /// - /// Initializes a new instance of the class. - /// - public BarcodeReaderGeneric() - : this(new QRCodeReader(), null, defaultCreateBinarizer) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Sets the reader which should be used to find and decode the barcode. - /// If null then MultiFormatReader is used - /// Sets the function to create a luminance source object for a bitmap. - /// If null, an exception is thrown when Decode is called - /// Sets the function to create a binarizer object for a luminance source. - /// If null then HybridBinarizer is used - public BarcodeReaderGeneric(Reader reader, -#if !UNITY - Func createLuminanceSource, -#else - Func createLuminanceSource, -#endif - Func createBinarizer - ) - : this(reader, createLuminanceSource, createBinarizer, null) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// Sets the reader which should be used to find and decode the barcode. - /// If null then MultiFormatReader is used - /// Sets the function to create a luminance source object for a bitmap. - /// If null, an exception is thrown when Decode is called - /// Sets the function to create a binarizer object for a luminance source. - /// If null then HybridBinarizer is used - /// Sets the function to create a luminance source object for a rgb array. - /// If null the RGBLuminanceSource is used. The handler is only called when Decode with a byte[] array is called. - public BarcodeReaderGeneric(Reader reader, -#if !UNITY - Func createLuminanceSource, -#else - Func createLuminanceSource, -#endif - Func createBinarizer, - Func createRGBLuminanceSource - ) - { - this.reader = reader ?? new QRCodeReader(); - this.createLuminanceSource = createLuminanceSource; - this.createBinarizer = createBinarizer ?? defaultCreateBinarizer; - this.createRGBLuminanceSource = createRGBLuminanceSource ?? defaultCreateRGBLuminanceSource; - Options.ValueChanged += (o, args) => usePreviousState = false; - usePreviousState = false; - } - -#if !PORTABLE -#if !UNITY - /// - /// Decodes the specified barcode bitmap. - /// - /// The barcode bitmap. - /// the result data or null - public Result Decode(T barcodeBitmap) -#else - /// - /// Decodes the specified barcode bitmap. - /// - /// raw bytes of the image in RGB order - /// - /// - /// - /// the result data or null - /// - public Result Decode(T rawRGB, int width, int height) -#endif - { - if (CreateLuminanceSource == null) - { - throw new InvalidOperationException("You have to declare a luminance source delegate."); - } - -#if !UNITY - if (barcodeBitmap == null) - throw new ArgumentNullException("barcodeBitmap"); -#else - if (rawRGB == null) - throw new ArgumentNullException("rawRGB"); -#endif - -#if !UNITY - var luminanceSource = CreateLuminanceSource(barcodeBitmap); -#else - var luminanceSource = CreateLuminanceSource(rawRGB, width, height); -#endif - - return Decode(luminanceSource); - } -#endif - - /// - /// Tries to decode a barcode within an image which is given by a luminance source. - /// That method gives a chance to prepare a luminance source completely before calling - /// the time consuming decoding method. On the other hand there is a chance to create - /// a luminance source which is independent from external resources (like Bitmap objects) - /// and the decoding call can be made in a background thread. - /// - /// The luminance source. - /// - virtual public Result Decode(LuminanceSource luminanceSource) - { - var result = default(Result); - var binarizer = CreateBinarizer(luminanceSource); - var binaryBitmap = new BinaryBitmap(binarizer); - var multiformatReader = Reader as QRCodeReader; - var rotationCount = 0; - var rotationMaxCount = 1; - - if (AutoRotate) - { - Options.Hints[DecodeHintType.TRY_HARDER_WITHOUT_ROTATION] = true; - rotationMaxCount = 4; - } - else - { - if (Options.Hints.ContainsKey(DecodeHintType.TRY_HARDER_WITHOUT_ROTATION)) - Options.Hints.Remove(DecodeHintType.TRY_HARDER_WITHOUT_ROTATION); - } - - for (; rotationCount < rotationMaxCount; rotationCount++) - { - result = Reader.decode(binaryBitmap, Options.Hints); - usePreviousState = true; - - - if (result != null || - !luminanceSource.RotateSupported || - !AutoRotate) - break; - - binaryBitmap = new BinaryBitmap(CreateBinarizer(luminanceSource.rotateCounterClockwise())); - } - - if (result != null) - { - if (result.ResultMetadata == null) - { - result.putMetadata(ResultMetadataType.ORIENTATION, rotationCount * 90); - } - else if (!result.ResultMetadata.ContainsKey(ResultMetadataType.ORIENTATION)) - { - result.ResultMetadata[ResultMetadataType.ORIENTATION] = rotationCount * 90; - } - else - { - // perhaps the core decoder rotates the image already (can happen if TryHarder is specified) - result.ResultMetadata[ResultMetadataType.ORIENTATION] = ((int)(result.ResultMetadata[ResultMetadataType.ORIENTATION]) + rotationCount * 90) % 360; - } - - OnResultFound(result); - } - - return result; - } - - - protected void OnResultsFound(IEnumerable results) - { - if (ResultFound != null) - { - foreach (var result in results) - { - ResultFound(result); - } - } - } - - protected void OnResultFound(Result result) - { - if (ResultFound != null) - { - ResultFound(result); - } - } - - protected void OnResultPointFound(ResultPoint resultPoint) - { - if (explicitResultPointFound != null) - { - explicitResultPointFound(resultPoint); - } - } - - /// - /// Decodes the specified barcode bitmap. - /// - /// The image as byte[] array. - /// The width. - /// The height. - /// The format. - /// - /// the result data or null - /// - public Result Decode(byte[] rawRGB, int width, int height, RGBLuminanceSource.BitmapFormat format) - { - if (rawRGB == null) - throw new ArgumentNullException("rawRGB"); - - var luminanceSource = createRGBLuminanceSource(rawRGB, width, height, format); - - return Decode(luminanceSource); - } - - } -} diff --git a/shadowsocks-csharp/3rd/zxing/IBarcodeReader.cs b/shadowsocks-csharp/3rd/zxing/IBarcodeReader.cs deleted file mode 100755 index 66d90ffb..00000000 --- a/shadowsocks-csharp/3rd/zxing/IBarcodeReader.cs +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2012 ZXing.Net 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; - -#if !(SILVERLIGHT || NETFX_CORE) -#if !UNITY -#if !PORTABLE -using System.Drawing; -#endif -#else -using UnityEngine; -#endif -#elif NETFX_CORE -using Windows.UI.Xaml.Media.Imaging; -#else -using System.Windows.Media.Imaging; -#endif - -using ZXing.Common; - -namespace ZXing -{ - /// - /// Interface for a smart class to decode the barcode inside a bitmap object - /// - public interface IBarcodeReader - { - /// - /// event is executed when a result point was found - /// - event Action ResultPointFound; - - /// - /// event is executed when a result was found via decode - /// - event Action ResultFound; - - /// - /// Gets or sets a flag which cause a deeper look into the bitmap - /// - /// - /// true if [try harder]; otherwise, false. - /// - [Obsolete("Please use the Options.TryHarder property instead.")] - bool TryHarder { get; set; } - - /// - /// Image is a pure monochrome image of a barcode. - /// - /// - /// true if monochrome image of a barcode; otherwise, false. - /// - [Obsolete("Please use the Options.PureBarcode property instead.")] - bool PureBarcode { get; set; } - - /// - /// Specifies what character encoding to use when decoding, where applicable (type String) - /// - /// - /// The character set. - /// - [Obsolete("Please use the Options.CharacterSet property instead.")] - string CharacterSet { get; set; } - - /// - /// Image is known to be of one of a few possible formats. - /// Maps to a {@link java.util.List} of {@link BarcodeFormat}s. - /// - /// - /// The possible formats. - /// - [Obsolete("Please use the Options.PossibleFormats property instead.")] - IList PossibleFormats { get; set; } - - /// - /// Specifies some options which influence the decoding process - /// - DecodingOptions Options { get; set; } - - /// - /// Decodes the specified barcode bitmap which is given by a generic byte array with the order RGB24. - /// - /// The image as RGB24 array. - /// The width. - /// The height. - /// The format. - /// - /// the result data or null - /// - Result Decode(byte[] rawRGB, int width, int height, RGBLuminanceSource.BitmapFormat format); - - /// - /// Tries to decode a barcode within an image which is given by a luminance source. - /// That method gives a chance to prepare a luminance source completely before calling - /// the time consuming decoding method. On the other hand there is a chance to create - /// a luminance source which is independent from external resources (like Bitmap objects) - /// and the decoding call can be made in a background thread. - /// - /// The luminance source. - /// - Result Decode(LuminanceSource luminanceSource); - -#if MONOTOUCH - /// - /// Decodes the specified barcode bitmap. - /// - /// The barcode bitmap. - /// the result data or null - Result Decode(MonoTouch.UIKit.UIImage barcodeImage); -#elif MONOANDROID - /// - /// Decodes the specified barcode bitmap. - /// - /// The barcode bitmap. - /// the result data or null - Result Decode(Android.Graphics.Bitmap barcodeImage); -#else -#if !PORTABLE -#if !(SILVERLIGHT || NETFX_CORE) -#if !UNITY - /// - /// Decodes the specified barcode bitmap. - /// - /// The barcode bitmap. - /// the result data or null - Result Decode(Bitmap barcodeBitmap); -#else - /// - /// Decodes the specified barcode bitmap. - /// - /// The image as Color32 array. - /// the result data or null - Result Decode(Color32[] rawColor32, int width, int height); -#endif -#else - /// - /// Decodes the specified barcode bitmap. - /// - /// The barcode bitmap. - /// the result data or null - Result Decode(WriteableBitmap barcodeBitmap); -#endif -#endif -#endif - } -} diff --git a/shadowsocks-csharp/3rd/zxing/IBarcodeReaderGeneric.cs b/shadowsocks-csharp/3rd/zxing/IBarcodeReaderGeneric.cs deleted file mode 100755 index 1860988a..00000000 --- a/shadowsocks-csharp/3rd/zxing/IBarcodeReaderGeneric.cs +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2012 ZXing.Net 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; - -namespace ZXing -{ - /// - /// Interface for a smart class to decode the barcode inside a bitmap object - /// - /// gives the type of the input data - public interface IBarcodeReaderGeneric - { - /// - /// event is executed when a result point was found - /// - event Action ResultPointFound; - - /// - /// event is executed when a result was found via decode - /// - event Action ResultFound; - - /// - /// Gets or sets a flag which cause a deeper look into the bitmap - /// - /// - /// true if [try harder]; otherwise, false. - /// - [Obsolete("Please use the Options.TryHarder property instead.")] - bool TryHarder { get; set; } - - /// - /// Image is a pure monochrome image of a barcode. - /// - /// - /// true if monochrome image of a barcode; otherwise, false. - /// - [Obsolete("Please use the Options.PureBarcode property instead.")] - bool PureBarcode { get; set; } - - /// - /// Specifies what character encoding to use when decoding, where applicable (type String) - /// - /// - /// The character set. - /// - [Obsolete("Please use the Options.CharacterSet property instead.")] - string CharacterSet { get; set; } - - /// - /// Image is known to be of one of a few possible formats. - /// Maps to a {@link java.util.List} of {@link BarcodeFormat}s. - /// - /// - /// The possible formats. - /// - [Obsolete("Please use the Options.PossibleFormats property instead.")] - IList PossibleFormats { get; set; } - - /// - /// Specifies some options which influence the decoding process - /// - DecodingOptions Options { get; set; } - - /// - /// Decodes the specified barcode bitmap which is given by a generic byte array. - /// - /// The barcode bitmap. - /// The width. - /// The height. - /// The format. - /// - /// the result data or null - /// - Result Decode(byte[] rawRGB, int width, int height, RGBLuminanceSource.BitmapFormat format); - - /// - /// Tries to decode a barcode within an image which is given by a luminance source. - /// That method gives a chance to prepare a luminance source completely before calling - /// the time consuming decoding method. On the other hand there is a chance to create - /// a luminance source which is independent from external resources (like Bitmap objects) - /// and the decoding call can be made in a background thread. - /// - /// The luminance source. - /// - Result Decode(LuminanceSource luminanceSource); - -#if !PORTABLE -#if !UNITY - /// - /// Decodes the specified barcode bitmap. - /// - /// The barcode bitmap. - /// the result data or null - Result Decode(T barcodeBitmap); -#else - /// - /// Decodes the specified barcode bitmap. - /// - /// The barcode bitmap. - /// the result data or null - Result Decode(T rawRGB, int width, int height); -#endif -#endif - } -} diff --git a/shadowsocks-csharp/3rd/zxing/RGBLuminanceSource.cs b/shadowsocks-csharp/3rd/zxing/RGBLuminanceSource.cs deleted file mode 100755 index 6af439ef..00000000 --- a/shadowsocks-csharp/3rd/zxing/RGBLuminanceSource.cs +++ /dev/null @@ -1,314 +0,0 @@ -/* -* Copyright 2012 ZXing.Net 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 -{ - /// - /// Luminance source class which support different formats of images. - /// - public partial class RGBLuminanceSource : BaseLuminanceSource - { - /// - /// enumeration of supported bitmap format which the RGBLuminanceSource can process - /// - public enum BitmapFormat - { - /// - /// format of the byte[] isn't known. RGBLuminanceSource tries to determine the best possible value - /// - Unknown, - /// - /// grayscale array, the byte array is a luminance array with 1 byte per pixel - /// - Gray8, - /// - /// 3 bytes per pixel with the channels red, green and blue - /// - RGB24, - /// - /// 4 bytes per pixel with the channels red, green and blue - /// - RGB32, - /// - /// 4 bytes per pixel with the channels alpha, red, green and blue - /// - ARGB32, - /// - /// 3 bytes per pixel with the channels blue, green and red - /// - BGR24, - /// - /// 4 bytes per pixel with the channels blue, green and red - /// - BGR32, - /// - /// 4 bytes per pixel with the channels blue, green, red and alpha - /// - BGRA32, - /// - /// 2 bytes per pixel, 5 bit red, 6 bits green and 5 bits blue - /// - RGB565, - /// - /// 4 bytes per pixel with the channels red, green, blue and alpha - /// - RGBA32, - } - - /// - /// Initializes a new instance of the class. - /// - /// The width. - /// The height. - protected RGBLuminanceSource(int width, int height) - : base(width, height) - { - } - - /// - /// Initializes a new instance of the class. - /// It supports a byte array with 3 bytes per pixel (RGB24). - /// - /// The RGB raw bytes. - /// The width. - /// The height. - public RGBLuminanceSource(byte[] rgbRawBytes, int width, int height) - : this(rgbRawBytes, width, height, BitmapFormat.RGB24) - { - } - - /// - /// Initializes a new instance of the class. - /// It supports a byte array with 1 byte per pixel (Gray8). - /// That means the whole array consists of the luminance values (grayscale). - /// - /// The luminance array. - /// The width. - /// The height. - /// if set to true [is8 bit]. - [Obsolete("Use RGBLuminanceSource(luminanceArray, width, height, BitmapFormat.Gray8)")] - public RGBLuminanceSource(byte[] luminanceArray, int width, int height, bool is8Bit) - : this(luminanceArray, width, height, BitmapFormat.Gray8) - { - } - - /// - /// Initializes a new instance of the class. - /// It supports a byte array with 3 bytes per pixel (RGB24). - /// - /// The RGB raw bytes. - /// The width. - /// The height. - /// The bitmap format. - public RGBLuminanceSource(byte[] rgbRawBytes, int width, int height, BitmapFormat bitmapFormat) - : base(width, height) - { - CalculateLuminance(rgbRawBytes, bitmapFormat); - } - - /// - /// Should create a new luminance source with the right class type. - /// The method is used in methods crop and rotate. - /// - /// The new luminances. - /// The width. - /// The height. - /// - protected override LuminanceSource CreateLuminanceSource(byte[] newLuminances, int width, int height) - { - return new RGBLuminanceSource(width, height) { luminances = newLuminances }; - } - - private static BitmapFormat DetermineBitmapFormat(byte[] rgbRawBytes, int width, int height) - { - var square = width*height; - var byteperpixel = rgbRawBytes.Length/square; - - switch (byteperpixel) - { - case 1: - return BitmapFormat.Gray8; - case 2: - return BitmapFormat.RGB565; - case 3: - return BitmapFormat.RGB24; - case 4: - return BitmapFormat.RGB32; - default: - throw new ArgumentException("The bitmap format could not be determined. Please specify the correct value."); - } - } - - protected void CalculateLuminance(byte[] rgbRawBytes, BitmapFormat bitmapFormat) - { - if (bitmapFormat == BitmapFormat.Unknown) - { - bitmapFormat = DetermineBitmapFormat(rgbRawBytes, Width, Height); - } - switch (bitmapFormat) - { - case BitmapFormat.Gray8: - Buffer.BlockCopy(rgbRawBytes, 0, luminances, 0, rgbRawBytes.Length < luminances.Length ? rgbRawBytes.Length : luminances.Length); - break; - case BitmapFormat.RGB24: - CalculateLuminanceRGB24(rgbRawBytes); - break; - case BitmapFormat.BGR24: - CalculateLuminanceBGR24(rgbRawBytes); - break; - case BitmapFormat.RGB32: - CalculateLuminanceRGB32(rgbRawBytes); - break; - case BitmapFormat.BGR32: - CalculateLuminanceBGR32(rgbRawBytes); - break; - case BitmapFormat.RGBA32: - CalculateLuminanceRGBA32(rgbRawBytes); - break; - case BitmapFormat.ARGB32: - CalculateLuminanceARGB32(rgbRawBytes); - break; - case BitmapFormat.BGRA32: - CalculateLuminanceBGRA32(rgbRawBytes); - break; - case BitmapFormat.RGB565: - CalculateLuminanceRGB565(rgbRawBytes); - break; - default: - throw new ArgumentException("The bitmap format isn't supported.", bitmapFormat.ToString()); - } - } - - private void CalculateLuminanceRGB565(byte[] rgb565RawData) - { - var luminanceIndex = 0; - for (var index = 0; index < rgb565RawData.Length && luminanceIndex < luminances.Length; index += 2, luminanceIndex++) - { - var byte1 = rgb565RawData[index]; - var byte2 = rgb565RawData[index + 1]; - - var b5 = byte1 & 0x1F; - var g5 = (((byte1 & 0xE0) >> 5) | ((byte2 & 0x03) << 3)) & 0x1F; - var r5 = (byte2 >> 2) & 0x1F; - var r8 = (r5 * 527 + 23) >> 6; - var g8 = (g5 * 527 + 23) >> 6; - var b8 = (b5 * 527 + 23) >> 6; - - // cheap, not fully accurate conversion - //var pixel = (byte2 << 8) | byte1; - //b8 = (((pixel) & 0x001F) << 3); - //g8 = (((pixel) & 0x07E0) >> 2) & 0xFF; - //r8 = (((pixel) & 0xF800) >> 8); - - luminances[luminanceIndex] = (byte)((RChannelWeight * r8 + GChannelWeight * g8 + BChannelWeight * b8) >> ChannelWeight); - } - } - - private void CalculateLuminanceRGB24(byte[] rgbRawBytes) - { - for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) - { - // Calculate luminance cheaply, favoring green. - int r = rgbRawBytes[rgbIndex++]; - int g = rgbRawBytes[rgbIndex++]; - int b = rgbRawBytes[rgbIndex++]; - luminances[luminanceIndex] = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); - } - } - - private void CalculateLuminanceBGR24(byte[] rgbRawBytes) - { - for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) - { - // Calculate luminance cheaply, favoring green. - int b = rgbRawBytes[rgbIndex++]; - int g = rgbRawBytes[rgbIndex++]; - int r = rgbRawBytes[rgbIndex++]; - luminances[luminanceIndex] = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); - } - } - - private void CalculateLuminanceRGB32(byte[] rgbRawBytes) - { - for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) - { - // Calculate luminance cheaply, favoring green. - int r = rgbRawBytes[rgbIndex++]; - int g = rgbRawBytes[rgbIndex++]; - int b = rgbRawBytes[rgbIndex++]; - rgbIndex++; - luminances[luminanceIndex] = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); - } - } - - private void CalculateLuminanceBGR32(byte[] rgbRawBytes) - { - for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) - { - // Calculate luminance cheaply, favoring green. - int b = rgbRawBytes[rgbIndex++]; - int g = rgbRawBytes[rgbIndex++]; - int r = rgbRawBytes[rgbIndex++]; - rgbIndex++; - luminances[luminanceIndex] = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); - } - } - - private void CalculateLuminanceBGRA32(byte[] rgbRawBytes) - { - for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) - { - // Calculate luminance cheaply, favoring green. - var b = rgbRawBytes[rgbIndex++]; - var g = rgbRawBytes[rgbIndex++]; - var r = rgbRawBytes[rgbIndex++]; - var alpha = rgbRawBytes[rgbIndex++]; - var luminance = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); - luminances[luminanceIndex] = (byte)(((luminance * alpha) >> 8) + (255 * (255 - alpha) >> 8)); - } - } - - private void CalculateLuminanceRGBA32(byte[] rgbRawBytes) - { - for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) - { - // Calculate luminance cheaply, favoring green. - var r = rgbRawBytes[rgbIndex++]; - var g = rgbRawBytes[rgbIndex++]; - var b = rgbRawBytes[rgbIndex++]; - var alpha = rgbRawBytes[rgbIndex++]; - var luminance = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); - luminances[luminanceIndex] = (byte)(((luminance * alpha) >> 8) + (255 * (255 - alpha) >> 8)); - } - } - - private void CalculateLuminanceARGB32(byte[] rgbRawBytes) - { - for (int rgbIndex = 0, luminanceIndex = 0; rgbIndex < rgbRawBytes.Length && luminanceIndex < luminances.Length; luminanceIndex++) - { - // Calculate luminance cheaply, favoring green. - var alpha = rgbRawBytes[rgbIndex++]; - var r = rgbRawBytes[rgbIndex++]; - var g = rgbRawBytes[rgbIndex++]; - var b = rgbRawBytes[rgbIndex++]; - var luminance = (byte)((RChannelWeight * r + GChannelWeight * g + BChannelWeight * b) >> ChannelWeight); - luminances[luminanceIndex] = (byte)(((luminance * alpha) >> 8) + (255 * (255 - alpha) >> 8)); - } - } - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 15a53037..d132e788 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -71,8 +71,6 @@ - - @@ -101,8 +99,6 @@ - - @@ -138,7 +134,6 @@ - From b8fbc208587f347d2ec9d5f9d208f7d2f2d7032c Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 13 Jan 2015 01:58:38 +0800 Subject: [PATCH 31/45] remove some class --- shadowsocks-csharp/3rd/zxing/Reader.cs | 59 --- shadowsocks-csharp/3rd/zxing/ReaderException.cs | 71 ---- .../3rd/zxing/common/DecodingOptions.cs | 370 ------------------ .../3rd/zxing/common/EncodingOptions.cs | 121 ------ .../common/detector/MonochromeRectangleDetector.cs | 252 ------------ .../common/detector/WhiteRectangleDetector.cs | 433 --------------------- shadowsocks-csharp/3rd/zxing/net2.0/Action.cs | 102 ----- shadowsocks-csharp/3rd/zxing/net2.0/Func.cs | 122 ------ .../3rd/zxing/net2.0/TimeZoneInfo.cs | 29 -- .../3rd/zxing/qrcode/QRCodeReader.cs | 2 +- .../zxing/qrcode/encoder/QrCodeEncodingOptions.cs | 110 ------ shadowsocks-csharp/View/QRCodeForm.Designer.cs | 2 +- shadowsocks-csharp/shadowsocks-csharp.csproj | 10 - 13 files changed, 2 insertions(+), 1681 deletions(-) delete mode 100755 shadowsocks-csharp/3rd/zxing/Reader.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/ReaderException.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/common/DecodingOptions.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/common/EncodingOptions.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/common/detector/MonochromeRectangleDetector.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/common/detector/WhiteRectangleDetector.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/net2.0/Action.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/net2.0/Func.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/net2.0/TimeZoneInfo.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/qrcode/encoder/QrCodeEncodingOptions.cs diff --git a/shadowsocks-csharp/3rd/zxing/Reader.cs b/shadowsocks-csharp/3rd/zxing/Reader.cs deleted file mode 100755 index b96267af..00000000 --- a/shadowsocks-csharp/3rd/zxing/Reader.cs +++ /dev/null @@ -1,59 +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.Collections.Generic; - -namespace ZXing -{ - /// - /// Implementations of this interface can decode an image of a barcode in some format into - /// the String it encodes. For example, can - /// decode a QR code. The decoder may optionally receive hints from the caller which may help - /// it decode more quickly or accurately. - /// - /// See , which attempts to determine what barcode - /// format is present within the image as well, and then decodes it accordingly. - /// - /// Sean Owen - /// dswitkin@google.com (Daniel Switkin) - public interface Reader - { - /// - /// Locates and decodes a barcode in some format within an image. - /// - /// image of barcode to decode - /// String which the barcode encodes - Result decode(BinaryBitmap image); - - /// Locates and decodes a barcode in some format within an image. This method also accepts - /// hints, each possibly associated to some data, which may help the implementation decode. - /// - /// image of barcode to decode - /// passed as a from - /// to arbitrary data. The - /// meaning of the data depends upon the hint type. The implementation may or may not do - /// anything with these hints. - /// - /// String which the barcode encodes - Result decode(BinaryBitmap image, IDictionary hints); - - /// - /// Resets any internal state the implementation has after a decode, to prepare it - /// for reuse. - /// - void reset(); - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/ReaderException.cs b/shadowsocks-csharp/3rd/zxing/ReaderException.cs deleted file mode 100755 index 90936b5c..00000000 --- a/shadowsocks-csharp/3rd/zxing/ReaderException.cs +++ /dev/null @@ -1,71 +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 -{ - /// - /// The general exception class throw when something goes wrong during decoding of a barcode. - /// This includes, but is not limited to, failing checksums / error correction algorithms, being - /// unable to locate finder timing patterns, and so on. - /// - /// Sean Owen - [Serializable] - public class ReaderException : Exception - { - /// - /// Gets the instance. - /// - public static ReaderException Instance - { - get - { - return instance; - } - - } - - // TODO: Currently we throw up to 400 ReaderExceptions while scanning a single 240x240 image before - // rejecting it. This involves a lot of overhead and memory allocation, and affects both performance - // and latency on continuous scan clients. In the future, we should change all the decoders not to - // throw exceptions for routine events, like not finding a barcode on a given row. Instead, we - // should return error codes back to the callers, and simply delete this class. In the mean time, I - // have altered this class to be as lightweight as possible, by ignoring the exception string, and - // by disabling the generation of stack traces, which is especially time consuming. These are just - // temporary measures, pending the big cleanup. - - //UPGRADE_NOTE: Final was removed from the declaration of 'instance '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" - private static readonly ReaderException instance = new ReaderException(); - - // EXCEPTION TRACKING SUPPORT - // Identifies who is throwing exceptions and how often. To use: - // - // 1. Uncomment these lines and the code below which uses them. - // 2. Uncomment the two corresponding lines in j2se/CommandLineRunner.decode() - // 3. Change core to build as Java 1.5 temporarily - // private static int exceptionCount = 0; - // private static Map throwers = new HashMap(32); - - /// - /// Initializes a new instance of the class. - /// - protected ReaderException() - { - // do nothing - } - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/DecodingOptions.cs b/shadowsocks-csharp/3rd/zxing/common/DecodingOptions.cs deleted file mode 100755 index 9a58f9af..00000000 --- a/shadowsocks-csharp/3rd/zxing/common/DecodingOptions.cs +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright 2013 ZXing.Net 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 System.ComponentModel; - -namespace ZXing.Common -{ - /// - /// Defines an container for encoder options - /// - [Serializable] - public class DecodingOptions - { - /// - /// Gets the data container for all options - /// - [Browsable(false)] - public IDictionary Hints { get; private set; } - - [field: NonSerialized] - public event Action ValueChanged; - - /// - /// Gets or sets a flag which cause a deeper look into the bitmap - /// - /// - /// true if [try harder]; otherwise, false. - /// - public bool TryHarder - { - get - { - if (Hints.ContainsKey(DecodeHintType.TRY_HARDER)) - return (bool)Hints[DecodeHintType.TRY_HARDER]; - return false; - } - set - { - if (value) - { - Hints[DecodeHintType.TRY_HARDER] = true; - } - else - { - if (Hints.ContainsKey(DecodeHintType.TRY_HARDER)) - { - Hints.Remove(DecodeHintType.TRY_HARDER); - } - } - } - } - - /// - /// Image is a pure monochrome image of a barcode. - /// - /// - /// true if monochrome image of a barcode; otherwise, false. - /// - public bool PureBarcode - { - get - { - if (Hints.ContainsKey(DecodeHintType.PURE_BARCODE)) - return (bool)Hints[DecodeHintType.PURE_BARCODE]; - return false; - } - set - { - if (value) - { - Hints[DecodeHintType.PURE_BARCODE] = true; - } - else - { - if (Hints.ContainsKey(DecodeHintType.PURE_BARCODE)) - { - Hints.Remove(DecodeHintType.PURE_BARCODE); - } - } - } - } - - /// - /// Specifies what character encoding to use when decoding, where applicable (type String) - /// - /// - /// The character set. - /// - public string CharacterSet - { - get - { - if (Hints.ContainsKey(DecodeHintType.CHARACTER_SET)) - return (string)Hints[DecodeHintType.CHARACTER_SET]; - return null; - } - set - { - if (value != null) - { - Hints[DecodeHintType.CHARACTER_SET] = value; - } - else - { - if (Hints.ContainsKey(DecodeHintType.CHARACTER_SET)) - { - Hints.Remove(DecodeHintType.CHARACTER_SET); - } - } - } - } - - /// - /// Image is known to be of one of a few possible formats. - /// Maps to a {@link java.util.List} of {@link BarcodeFormat}s. - /// - /// - /// The possible formats. - /// - public IList PossibleFormats - { - get - { - if (Hints.ContainsKey(DecodeHintType.POSSIBLE_FORMATS)) - return (IList)Hints[DecodeHintType.POSSIBLE_FORMATS]; - return null; - } - set - { - if (value != null) - { - Hints[DecodeHintType.POSSIBLE_FORMATS] = value; - } - else - { - if (Hints.ContainsKey(DecodeHintType.POSSIBLE_FORMATS)) - { - Hints.Remove(DecodeHintType.POSSIBLE_FORMATS); - } - } - } - } - - /// - /// if Code39 could be detected try to use extended mode for full ASCII character set - /// - public bool UseCode39ExtendedMode - { - get - { - if (Hints.ContainsKey(DecodeHintType.USE_CODE_39_EXTENDED_MODE)) - return (bool)Hints[DecodeHintType.USE_CODE_39_EXTENDED_MODE]; - return false; - } - set - { - if (value) - { - Hints[DecodeHintType.USE_CODE_39_EXTENDED_MODE] = true; - } - else - { - if (Hints.ContainsKey(DecodeHintType.USE_CODE_39_EXTENDED_MODE)) - { - Hints.Remove(DecodeHintType.USE_CODE_39_EXTENDED_MODE); - } - } - } - } - - /// - /// Don't fail if a Code39 is detected but can't be decoded in extended mode. - /// Return the raw Code39 result instead. Maps to . - /// - public bool UseCode39RelaxedExtendedMode - { - get - { - if (Hints.ContainsKey(DecodeHintType.RELAXED_CODE_39_EXTENDED_MODE)) - return (bool)Hints[DecodeHintType.RELAXED_CODE_39_EXTENDED_MODE]; - return false; - } - set - { - if (value) - { - Hints[DecodeHintType.RELAXED_CODE_39_EXTENDED_MODE] = true; - } - else - { - if (Hints.ContainsKey(DecodeHintType.RELAXED_CODE_39_EXTENDED_MODE)) - { - Hints.Remove(DecodeHintType.RELAXED_CODE_39_EXTENDED_MODE); - } - } - } - } - - /// - /// If true, return the start and end digits in a Codabar barcode instead of stripping them. They - /// are alpha, whereas the rest are numeric. By default, they are stripped, but this causes them - /// to not be. Doesn't matter what it maps to; use . - /// - public bool ReturnCodabarStartEnd - { - get - { - if (Hints.ContainsKey(DecodeHintType.RETURN_CODABAR_START_END)) - return (bool)Hints[DecodeHintType.RETURN_CODABAR_START_END]; - return false; - } - set - { - if (value) - { - Hints[DecodeHintType.RETURN_CODABAR_START_END] = true; - } - else - { - if (Hints.ContainsKey(DecodeHintType.RETURN_CODABAR_START_END)) - { - Hints.Remove(DecodeHintType.RETURN_CODABAR_START_END); - } - } - } - } - /// - /// Initializes a new instance of the class. - /// - public DecodingOptions() - { - var hints = new ChangeNotifyDictionary(); - Hints = hints; - UseCode39ExtendedMode = true; - UseCode39RelaxedExtendedMode = true; - hints.ValueChanged += (o, args) => { if (ValueChanged != null) ValueChanged(this, EventArgs.Empty); }; - } - - [Serializable] - private class ChangeNotifyDictionary: IDictionary - { - private readonly IDictionary values; - - [field: NonSerialized] - public event Action ValueChanged; - - public ChangeNotifyDictionary() - { - values = new Dictionary(); - } - - private void OnValueChanged() - { - if (ValueChanged != null) - ValueChanged(this, EventArgs.Empty); - } - - public void Add(TKey key, TValue value) - { - values.Add(key, value); - OnValueChanged(); - } - - public bool ContainsKey(TKey key) - { - return values.ContainsKey(key); - } - - public ICollection Keys - { - get { return values.Keys; } - } - - public bool Remove(TKey key) - { - var result = values.Remove(key); - OnValueChanged(); - return result; - } - - public bool TryGetValue(TKey key, out TValue value) - { - return values.TryGetValue(key, out value); - } - - public ICollection Values - { - get { return values.Values; } - } - - public TValue this[TKey key] - { - get - { - return values[key]; - } - set - { - values[key] = value; - OnValueChanged(); - } - } - - public void Add(KeyValuePair item) - { - values.Add(item); - OnValueChanged(); - } - - public void Clear() - { - values.Clear(); - OnValueChanged(); - } - - public bool Contains(KeyValuePair item) - { - return values.Contains(item); - } - - public void CopyTo(KeyValuePair[] array, int arrayIndex) - { - values.CopyTo(array, arrayIndex); - } - - public int Count - { - get { return values.Count; } - } - - public bool IsReadOnly - { - get { return values.IsReadOnly; } - } - - public bool Remove(KeyValuePair item) - { - var result = values.Remove(item); - OnValueChanged(); - - return result; - } - - public IEnumerator> GetEnumerator() - { - return values.GetEnumerator(); - } - - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return ((System.Collections.IEnumerable)values).GetEnumerator(); - } - } - } -} diff --git a/shadowsocks-csharp/3rd/zxing/common/EncodingOptions.cs b/shadowsocks-csharp/3rd/zxing/common/EncodingOptions.cs deleted file mode 100755 index 683453ec..00000000 --- a/shadowsocks-csharp/3rd/zxing/common/EncodingOptions.cs +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2012 ZXing.Net 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 System.ComponentModel; - -namespace ZXing.Common -{ - /// - /// Defines an container for encoder options - /// - [Serializable] - public class EncodingOptions - { - /// - /// Gets the data container for all options - /// - [Browsable(false)] - public IDictionary Hints { get; private set; } - - /// - /// Specifies the height of the barcode image - /// - public int Height - { - get - { - if (Hints.ContainsKey(EncodeHintType.HEIGHT)) - { - return (int)Hints[EncodeHintType.HEIGHT]; - } - return 0; - } - set - { - Hints[EncodeHintType.HEIGHT] = value; - } - } - - /// - /// Specifies the width of the barcode image - /// - public int Width - { - get - { - if (Hints.ContainsKey(EncodeHintType.WIDTH)) - { - return (int)Hints[EncodeHintType.WIDTH]; - } - return 0; - } - set - { - Hints[EncodeHintType.WIDTH] = value; - } - } - - /// - /// Don't put the content string into the output image. - /// - public bool PureBarcode - { - get - { - if (Hints.ContainsKey(EncodeHintType.PURE_BARCODE)) - { - return (bool)Hints[EncodeHintType.PURE_BARCODE]; - } - return false; - } - set - { - Hints[EncodeHintType.PURE_BARCODE] = value; - } - } - - /// - /// 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. - /// - public int Margin - { - get - { - if (Hints.ContainsKey(EncodeHintType.MARGIN)) - { - return (int) Hints[EncodeHintType.MARGIN]; - } - return 0; - } - set - { - Hints[EncodeHintType.MARGIN] = value; - } - } - - /// - /// Initializes a new instance of the class. - /// - public EncodingOptions() - { - Hints = new Dictionary(); - } - } -} diff --git a/shadowsocks-csharp/3rd/zxing/common/detector/MonochromeRectangleDetector.cs b/shadowsocks-csharp/3rd/zxing/common/detector/MonochromeRectangleDetector.cs deleted file mode 100755 index 9fb4515f..00000000 --- a/shadowsocks-csharp/3rd/zxing/common/detector/MonochromeRectangleDetector.cs +++ /dev/null @@ -1,252 +0,0 @@ -/* -* Copyright 2009 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.Common.Detector -{ - ///

A somewhat generic detector that looks for a barcode-like rectangular region within an image. - /// It looks within a mostly white region of an image for a region of black and white, but mostly - /// black. It returns the four corners of the region, as best it can determine.

- /// - ///
- /// Sean Owen - /// - /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source - /// - public sealed class MonochromeRectangleDetector - { - private const int MAX_MODULES = 32; - - private BitMatrix image; - - public MonochromeRectangleDetector(BitMatrix image) - { - this.image = image; - } - - ///

Detects a rectangular region of black and white -- mostly black -- with a region of mostly - /// white, in an image.

- /// - ///
- /// {@link ResultPoint}[] describing the corners of the rectangular region. The first and - /// last points are opposed on the diagonal, as are the second and third. The first point will be - /// the topmost point and the last, the bottommost. The second point will be leftmost and the - /// third, the rightmost - /// - public ResultPoint[] detect() - { - int height = image.Height; - int width = image.Width; - int halfHeight = height >> 1; - int halfWidth = width >> 1; - int deltaY = System.Math.Max(1, height / (MAX_MODULES << 3)); - int deltaX = System.Math.Max(1, width / (MAX_MODULES << 3)); - - int top = 0; - int bottom = height; - int left = 0; - int right = width; - ResultPoint pointA = findCornerFromCenter(halfWidth, 0, left, right, halfHeight, -deltaY, top, bottom, halfWidth >> 1); - if (pointA == null) - return null; - top = (int)pointA.Y - 1; - ResultPoint pointB = findCornerFromCenter(halfWidth, -deltaX, left, right, halfHeight, 0, top, bottom, halfHeight >> 1); - if (pointB == null) - return null; - left = (int)pointB.X - 1; - ResultPoint pointC = findCornerFromCenter(halfWidth, deltaX, left, right, halfHeight, 0, top, bottom, halfHeight >> 1); - if (pointC == null) - return null; - right = (int)pointC.X + 1; - ResultPoint pointD = findCornerFromCenter(halfWidth, 0, left, right, halfHeight, deltaY, top, bottom, halfWidth >> 1); - if (pointD == null) - return null; - bottom = (int)pointD.Y + 1; - - // Go try to find point A again with better information -- might have been off at first. - pointA = findCornerFromCenter(halfWidth, 0, left, right, halfHeight, -deltaY, top, bottom, halfWidth >> 2); - if (pointA == null) - return null; - - return new ResultPoint[] { pointA, pointB, pointC, pointD }; - } - - /// Attempts to locate a corner of the barcode by scanning up, down, left or right from a center - /// point which should be within the barcode. - /// - /// - /// center's x component (horizontal) - /// - /// same as deltaY but change in x per step instead - /// - /// minimum value of x - /// - /// maximum value of x - /// - /// center's y component (vertical) - /// - /// change in y per step. If scanning up this is negative; down, positive; - /// left or right, 0 - /// - /// minimum value of y to search through (meaningless when di == 0) - /// - /// maximum value of y - /// - /// maximum run of white pixels that can still be considered to be within - /// the barcode - /// - /// a {@link com.google.zxing.ResultPoint} encapsulating the corner that was found - /// - private ResultPoint findCornerFromCenter(int centerX, int deltaX, int left, int right, int centerY, int deltaY, int top, int bottom, int maxWhiteRun) - { - int[] lastRange = null; - for (int y = centerY, x = centerX; y < bottom && y >= top && x < right && x >= left; y += deltaY, x += deltaX) - { - int[] range; - if (deltaX == 0) - { - // horizontal slices, up and down - range = blackWhiteRange(y, maxWhiteRun, left, right, true); - } - else - { - // vertical slices, left and right - range = blackWhiteRange(x, maxWhiteRun, top, bottom, false); - } - if (range == null) - { - if (lastRange == null) - { - return null; - } - // lastRange was found - if (deltaX == 0) - { - int lastY = y - deltaY; - if (lastRange[0] < centerX) - { - if (lastRange[1] > centerX) - { - // straddle, choose one or the other based on direction - return new ResultPoint(deltaY > 0 ? lastRange[0] : lastRange[1], lastY); - } - return new ResultPoint(lastRange[0], lastY); - } - else - { - return new ResultPoint(lastRange[1], lastY); - } - } - else - { - int lastX = x - deltaX; - if (lastRange[0] < centerY) - { - if (lastRange[1] > centerY) - { - return new ResultPoint(lastX, deltaX < 0 ? lastRange[0] : lastRange[1]); - } - return new ResultPoint(lastX, lastRange[0]); - } - else - { - return new ResultPoint(lastX, lastRange[1]); - } - } - } - lastRange = range; - } - return null; - } - - /// Computes the start and end of a region of pixels, either horizontally or vertically, that could - /// be part of a Data Matrix barcode. - /// - /// - /// if scanning horizontally, this is the row (the fixed vertical location) - /// where we are scanning. If scanning vertically it's the column, the fixed horizontal location - /// - /// largest run of white pixels that can still be considered part of the - /// barcode region - /// - /// minimum pixel location, horizontally or vertically, to consider - /// - /// maximum pixel location, horizontally or vertically, to consider - /// - /// if true, we're scanning left-right, instead of up-down - /// - /// int[] with start and end of found range, or null if no such range is found - /// (e.g. only white was found) - /// - private int[] blackWhiteRange(int fixedDimension, int maxWhiteRun, int minDim, int maxDim, bool horizontal) - { - int center = (minDim + maxDim) >> 1; - - // Scan left/up first - int start = center; - while (start >= minDim) - { - if (horizontal ? image[start, fixedDimension] : image[fixedDimension, start]) - { - start--; - } - else - { - int whiteRunStart = start; - do - { - start--; - } - while (start >= minDim && !(horizontal ? image[start, fixedDimension] : image[fixedDimension, start])); - int whiteRunSize = whiteRunStart - start; - if (start < minDim || whiteRunSize > maxWhiteRun) - { - start = whiteRunStart; - break; - } - } - } - start++; - - // Then try right/down - int end = center; - while (end < maxDim) - { - if (horizontal ? image[end, fixedDimension] : image[fixedDimension, end]) - { - end++; - } - else - { - int whiteRunStart = end; - do - { - end++; - } - while (end < maxDim && !(horizontal ? image[end, fixedDimension] : image[fixedDimension, end])); - int whiteRunSize = end - whiteRunStart; - if (end >= maxDim || whiteRunSize > maxWhiteRun) - { - end = whiteRunStart; - break; - } - } - } - end--; - - return end > start ? new int[] { start, end } : null; - } - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/detector/WhiteRectangleDetector.cs b/shadowsocks-csharp/3rd/zxing/common/detector/WhiteRectangleDetector.cs deleted file mode 100755 index 9a4d4cd2..00000000 --- a/shadowsocks-csharp/3rd/zxing/common/detector/WhiteRectangleDetector.cs +++ /dev/null @@ -1,433 +0,0 @@ -/* - * Copyright 2010 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.Detector -{ - /// - /// Detects a candidate barcode-like rectangular region within an image. It - /// starts around the center of the image, increases the size of the candidate - /// region until it finds a white rectangular region. By keeping track of the - /// last black points it encountered, it determines the corners of the barcode. - /// - /// David Olivier - public sealed class WhiteRectangleDetector - { - private const int INIT_SIZE = 10; - private const int CORR = 1; - - private readonly BitMatrix image; - private readonly int height; - private readonly int width; - private readonly int leftInit; - private readonly int rightInit; - private readonly int downInit; - private readonly int upInit; - - /// - /// Creates a WhiteRectangleDetector instance - /// - /// The image. - /// null, if image is too small, otherwise a WhiteRectangleDetector instance - public static WhiteRectangleDetector Create(BitMatrix image) - { - if (image == null) - return null; - - var instance = new WhiteRectangleDetector(image); - - if (instance.upInit < 0 || instance.leftInit < 0 || instance.downInit >= instance.height || instance.rightInit >= instance.width) - { - return null; - } - - return instance; - } - - /// - /// Creates a WhiteRectangleDetector instance - /// - /// The image. - /// Size of the init. - /// The x. - /// The y. - /// - /// null, if image is too small, otherwise a WhiteRectangleDetector instance - /// - public static WhiteRectangleDetector Create(BitMatrix image, int initSize, int x, int y) - { - var instance = new WhiteRectangleDetector(image, initSize, x, y); - - if (instance.upInit < 0 || instance.leftInit < 0 || instance.downInit >= instance.height || instance.rightInit >= instance.width) - { - return null; - } - - return instance; - } - - - /// - /// Initializes a new instance of the class. - /// - /// The image. - /// if image is too small - internal WhiteRectangleDetector(BitMatrix image) - : this(image, INIT_SIZE, image.Width/2, image.Height/2) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// The image. - /// Size of the init. - /// The x. - /// The y. - internal WhiteRectangleDetector(BitMatrix image, int initSize, int x, int y) - { - this.image = image; - height = image.Height; - width = image.Width; - int halfsize = initSize / 2; - leftInit = x - halfsize; - rightInit = x + halfsize; - upInit = y - halfsize; - downInit = y + halfsize; - } - - /// - /// Detects a candidate barcode-like rectangular region within an image. It - /// starts around the center of the image, increases the size of the candidate - /// region until it finds a white rectangular region. - /// - /// [] describing the corners of the rectangular - /// region. The first and last points are opposed on the diagonal, as - /// are the second and third. The first point will be the topmost - /// point and the last, the bottommost. The second point will be - /// leftmost and the third, the rightmost - public ResultPoint[] detect() - { - int left = leftInit; - int right = rightInit; - int up = upInit; - int down = downInit; - bool sizeExceeded = false; - bool aBlackPointFoundOnBorder = true; - bool atLeastOneBlackPointFoundOnBorder = false; - - bool atLeastOneBlackPointFoundOnRight = false; - bool atLeastOneBlackPointFoundOnBottom = false; - bool atLeastOneBlackPointFoundOnLeft = false; - bool atLeastOneBlackPointFoundOnTop = false; - - while (aBlackPointFoundOnBorder) - { - - aBlackPointFoundOnBorder = false; - - // ..... - // . | - // ..... - bool rightBorderNotWhite = true; - while ((rightBorderNotWhite || !atLeastOneBlackPointFoundOnRight) && right < width) - { - rightBorderNotWhite = containsBlackPoint(up, down, right, false); - if (rightBorderNotWhite) - { - right++; - aBlackPointFoundOnBorder = true; - atLeastOneBlackPointFoundOnRight = true; - } - else if (!atLeastOneBlackPointFoundOnRight) - { - right++; - } - } - - if (right >= width) - { - sizeExceeded = true; - break; - } - - // ..... - // . . - // .___. - bool bottomBorderNotWhite = true; - while ((bottomBorderNotWhite || !atLeastOneBlackPointFoundOnBottom) && down < height) - { - bottomBorderNotWhite = containsBlackPoint(left, right, down, true); - if (bottomBorderNotWhite) - { - down++; - aBlackPointFoundOnBorder = true; - atLeastOneBlackPointFoundOnBottom = true; - } - else if (!atLeastOneBlackPointFoundOnBottom) - { - down++; - } - } - - if (down >= height) - { - sizeExceeded = true; - break; - } - - // ..... - // | . - // ..... - bool leftBorderNotWhite = true; - while ((leftBorderNotWhite || !atLeastOneBlackPointFoundOnLeft) && left >= 0) - { - leftBorderNotWhite = containsBlackPoint(up, down, left, false); - if (leftBorderNotWhite) - { - left--; - aBlackPointFoundOnBorder = true; - atLeastOneBlackPointFoundOnLeft = true; - } - else if (!atLeastOneBlackPointFoundOnLeft) - { - left--; - } - } - - if (left < 0) - { - sizeExceeded = true; - break; - } - - // .___. - // . . - // ..... - bool topBorderNotWhite = true; - while ((topBorderNotWhite || !atLeastOneBlackPointFoundOnTop) && up >= 0) - { - topBorderNotWhite = containsBlackPoint(left, right, up, true); - if (topBorderNotWhite) - { - up--; - aBlackPointFoundOnBorder = true; - atLeastOneBlackPointFoundOnTop = true; - } - else if (!atLeastOneBlackPointFoundOnTop) - { - up--; - } - } - - if (up < 0) - { - sizeExceeded = true; - break; - } - - if (aBlackPointFoundOnBorder) - { - atLeastOneBlackPointFoundOnBorder = true; - } - - } - - if (!sizeExceeded && atLeastOneBlackPointFoundOnBorder) - { - - int maxSize = right - left; - - ResultPoint z = null; - for (int i = 1; i < maxSize; i++) - { - z = getBlackPointOnSegment(left, down - i, left + i, down); - if (z != null) - { - break; - } - } - - if (z == null) - { - return null; - } - - ResultPoint t = null; - //go down right - for (int i = 1; i < maxSize; i++) - { - t = getBlackPointOnSegment(left, up + i, left + i, up); - if (t != null) - { - break; - } - } - - if (t == null) - { - return null; - } - - ResultPoint x = null; - //go down left - for (int i = 1; i < maxSize; i++) - { - x = getBlackPointOnSegment(right, up + i, right - i, up); - if (x != null) - { - break; - } - } - - if (x == null) - { - return null; - } - - ResultPoint y = null; - //go up left - for (int i = 1; i < maxSize; i++) - { - y = getBlackPointOnSegment(right, down - i, right - i, down); - if (y != null) - { - break; - } - } - - if (y == null) - { - return null; - } - - return centerEdges(y, z, x, t); - - } - else - { - return null; - } - } - - private ResultPoint getBlackPointOnSegment(float aX, float aY, float bX, float bY) - { - int dist = MathUtils.round(MathUtils.distance(aX, aY, bX, bY)); - float xStep = (bX - aX) / dist; - float yStep = (bY - aY) / dist; - - for (int i = 0; i < dist; i++) - { - int x = MathUtils.round(aX + i * xStep); - int y = MathUtils.round(aY + i * yStep); - if (image[x, y]) - { - return new ResultPoint(x, y); - } - } - return null; - } - - /// - /// recenters the points of a constant distance towards the center - /// - /// bottom most point - /// left most point - /// right most point - /// top most point - /// [] describing the corners of the rectangular - /// region. The first and last points are opposed on the diagonal, as - /// are the second and third. The first point will be the topmost - /// point and the last, the bottommost. The second point will be - /// leftmost and the third, the rightmost - private ResultPoint[] centerEdges(ResultPoint y, ResultPoint z, - ResultPoint x, ResultPoint t) - { - // - // t t - // z x - // x OR z - // y y - // - - float yi = y.X; - float yj = y.Y; - float zi = z.X; - float zj = z.Y; - float xi = x.X; - float xj = x.Y; - float ti = t.X; - float tj = t.Y; - - if (yi < width / 2.0f) - { - return new[] - { - new ResultPoint(ti - CORR, tj + CORR), - new ResultPoint(zi + CORR, zj + CORR), - new ResultPoint(xi - CORR, xj - CORR), - new ResultPoint(yi + CORR, yj - CORR) - }; - } - else - { - return new[] - { - new ResultPoint(ti + CORR, tj + CORR), - new ResultPoint(zi + CORR, zj - CORR), - new ResultPoint(xi - CORR, xj + CORR), - new ResultPoint(yi - CORR, yj - CORR) - }; - } - } - - /// - /// Determines whether a segment contains a black point - /// - /// min value of the scanned coordinate - /// max value of the scanned coordinate - /// value of fixed coordinate - /// set to true if scan must be horizontal, false if vertical - /// - /// true if a black point has been found, else false. - /// - private bool containsBlackPoint(int a, int b, int @fixed, bool horizontal) - { - if (horizontal) - { - for (int x = a; x <= b; x++) - { - if (image[x, @fixed]) - { - return true; - } - } - } - else - { - for (int y = a; y <= b; y++) - { - if (image[@fixed, y]) - { - return true; - } - } - } - return false; - } - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/net2.0/Action.cs b/shadowsocks-csharp/3rd/zxing/net2.0/Action.cs deleted file mode 100755 index 88601bc1..00000000 --- a/shadowsocks-csharp/3rd/zxing/net2.0/Action.cs +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2013 ZXing.Net 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 -{ -#if !WindowsCE - /// - /// for compatibility with .net 4.0 - /// - public delegate void Action(); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The param1. - public delegate void Action(T1 param1); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The param1. - /// The param2. - public delegate void Action(T1 param1, T2 param2); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The type of the 3. - /// The param1. - /// The param2. - /// The param3. - public delegate void Action(T1 param1, T2 param2, T3 param3); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The type of the 3. - /// The type of the 4. - /// The param1. - /// The param2. - /// The param3. - /// The param4. - public delegate void Action(T1 param1, T2 param2, T3 param3, T4 param4); -#else - /// - /// for compatibility with .net 4.0 - /// - public delegate void Action(); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The param1. - public delegate void Action(T1 param1); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The param1. - /// The param2. - public delegate void Action(T1 param1, T2 param2); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The type of the 3. - /// The param1. - /// The param2. - /// The param3. - public delegate void Action(T1 param1, T2 param2, T3 param3); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The type of the 3. - /// The type of the 4. - /// The param1. - /// The param2. - /// The param3. - /// The param4. - public delegate void Action(T1 param1, T2 param2, T3 param3, T4 param4); -#endif -} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/net2.0/Func.cs b/shadowsocks-csharp/3rd/zxing/net2.0/Func.cs deleted file mode 100755 index 2b2388f1..00000000 --- a/shadowsocks-csharp/3rd/zxing/net2.0/Func.cs +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Copyright 2012 ZXing.Net 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 -{ -#if !WindowsCE - /// - /// for compatibility with .net 4.0 - /// - /// The type of the result. - /// - public delegate TResult Func(); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the result. - /// The param1. - /// - public delegate TResult Func(T1 param1); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The type of the result. - /// The param1. - /// The param2. - /// - public delegate TResult Func(T1 param1, T2 param2); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The type of the 3. - /// The type of the result. - /// The param1. - /// The param2. - /// The param3. - /// - public delegate TResult Func(T1 param1, T2 param2, T3 param3); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The type of the 3. - /// The type of the 4. - /// The type of the result. - /// The param1. - /// The param2. - /// The param3. - /// The param4. - /// - public delegate TResult Func(T1 param1, T2 param2, T3 param3, T4 param4); -#else - /// - /// for compatibility with .net 4.0 - /// - /// The type of the result. - /// - public delegate TResult Func(); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the result. - /// The param1. - /// - public delegate TResult Func(T1 param1); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The type of the result. - /// The param1. - /// The param2. - /// - public delegate TResult Func(T1 param1, T2 param2); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The type of the 3. - /// The type of the result. - /// The param1. - /// The param2. - /// The param3. - /// - public delegate TResult Func(T1 param1, T2 param2, T3 param3); - /// - /// for compatibility with .net 4.0 - /// - /// The type of the 1. - /// The type of the 2. - /// The type of the 3. - /// The type of the 4. - /// The type of the result. - /// The param1. - /// The param2. - /// The param3. - /// The param4. - /// - public delegate TResult Func(T1 param1, T2 param2, T3 param3, T4 param4); -#endif -} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/net2.0/TimeZoneInfo.cs b/shadowsocks-csharp/3rd/zxing/net2.0/TimeZoneInfo.cs deleted file mode 100755 index c96f52c2..00000000 --- a/shadowsocks-csharp/3rd/zxing/net2.0/TimeZoneInfo.cs +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2012 ZXing.Net 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 System -{ - internal class TimeZoneInfo - { - internal static TimeZoneInfo Local = null; - - internal static DateTime ConvertTime(DateTime dateTime, TimeZoneInfo destinationTimeZone) - { - // TODO: fix it for .net 2.0 - return dateTime; - } - } -} diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/QRCodeReader.cs b/shadowsocks-csharp/3rd/zxing/qrcode/QRCodeReader.cs index d4fcc770..597797bc 100755 --- a/shadowsocks-csharp/3rd/zxing/qrcode/QRCodeReader.cs +++ b/shadowsocks-csharp/3rd/zxing/qrcode/QRCodeReader.cs @@ -26,7 +26,7 @@ namespace ZXing.QrCode /// This implementation can detect and decode QR Codes in an image. /// Sean Owen ///
- public class QRCodeReader : Reader + public class QRCodeReader { private static readonly ResultPoint[] NO_POINTS = new ResultPoint[0]; diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/encoder/QrCodeEncodingOptions.cs b/shadowsocks-csharp/3rd/zxing/qrcode/encoder/QrCodeEncodingOptions.cs deleted file mode 100755 index 41e87a08..00000000 --- a/shadowsocks-csharp/3rd/zxing/qrcode/encoder/QrCodeEncodingOptions.cs +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright 2012 ZXing.Net 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 ZXing.Common; -using ZXing.QrCode.Internal; - -namespace ZXing.QrCode -{ - /// - /// The class holds the available options for the QrCodeWriter - /// - [Serializable] - public class QrCodeEncodingOptions : EncodingOptions - { - /// - /// 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 - /// {@link com.google.zxing.qrcode.decoder.ErrorCorrectionLevel ErrorCorrectionLevel}. - /// - public ErrorCorrectionLevel ErrorCorrection - { - get - { - if (Hints.ContainsKey(EncodeHintType.ERROR_CORRECTION)) - { - return (ErrorCorrectionLevel) Hints[EncodeHintType.ERROR_CORRECTION]; - } - return null; - } - set - { - if (value == null) - { - if (Hints.ContainsKey(EncodeHintType.ERROR_CORRECTION)) - Hints.Remove(EncodeHintType.ERROR_CORRECTION); - } - else - { - Hints[EncodeHintType.ERROR_CORRECTION] = value; - } - } - } - - /// - /// Specifies what character encoding to use where applicable (type {@link String}) - /// - public string CharacterSet - { - get - { - if (Hints.ContainsKey(EncodeHintType.CHARACTER_SET)) - { - return (string) Hints[EncodeHintType.CHARACTER_SET]; - } - return null; - } - set - { - if (value == null) - { - if (Hints.ContainsKey(EncodeHintType.CHARACTER_SET)) - Hints.Remove(EncodeHintType.CHARACTER_SET); - } - else - { - Hints[EncodeHintType.CHARACTER_SET] = value; - } - } - } - - /// - /// Explicitly disables ECI segment when generating QR Code - /// 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. - /// - public bool DisableECI - { - get - { - if (Hints.ContainsKey(EncodeHintType.DISABLE_ECI)) - { - return (bool)Hints[EncodeHintType.DISABLE_ECI]; - } - return false; - } - set - { - Hints[EncodeHintType.DISABLE_ECI] = value; - } - } - } -} diff --git a/shadowsocks-csharp/View/QRCodeForm.Designer.cs b/shadowsocks-csharp/View/QRCodeForm.Designer.cs index d334c761..ca0a0006 100755 --- a/shadowsocks-csharp/View/QRCodeForm.Designer.cs +++ b/shadowsocks-csharp/View/QRCodeForm.Designer.cs @@ -37,7 +37,7 @@ this.pictureBox1.Location = new System.Drawing.Point(10, 10); this.pictureBox1.Margin = new System.Windows.Forms.Padding(0); this.pictureBox1.Name = "pictureBox1"; - this.pictureBox1.Size = new System.Drawing.Size(240, 240); + this.pictureBox1.Size = new System.Drawing.Size(210, 210); this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.pictureBox1.TabIndex = 1; this.pictureBox1.TabStop = false; diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index d132e788..cd5b2683 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -80,14 +80,10 @@ - - - - @@ -100,9 +96,6 @@ - - - @@ -125,11 +118,8 @@ - - - From c2f714598002d7e16a44522970da9deab2edf194 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 13 Jan 2015 02:12:22 +0800 Subject: [PATCH 32/45] remove ECI --- .../3rd/zxing/common/CharacterSetECI.cs | 128 --------------------- shadowsocks-csharp/3rd/zxing/common/ECI.cs | 66 ----------- .../zxing/qrcode/decoder/DecodedBitStreamParser.cs | 22 +--- shadowsocks-csharp/shadowsocks-csharp.csproj | 2 - 4 files changed, 6 insertions(+), 212 deletions(-) delete mode 100755 shadowsocks-csharp/3rd/zxing/common/CharacterSetECI.cs delete mode 100755 shadowsocks-csharp/3rd/zxing/common/ECI.cs diff --git a/shadowsocks-csharp/3rd/zxing/common/CharacterSetECI.cs b/shadowsocks-csharp/3rd/zxing/common/CharacterSetECI.cs deleted file mode 100755 index cb42eb5f..00000000 --- a/shadowsocks-csharp/3rd/zxing/common/CharacterSetECI.cs +++ /dev/null @@ -1,128 +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. -*/ - -using System; -using System.Collections.Generic; - -namespace ZXing.Common -{ - /// Encapsulates a Character Set ECI, according to "Extended Channel Interpretations" 5.3.1.1 - /// of ISO 18004. - /// - /// - /// Sean Owen - public sealed class CharacterSetECI : ECI - { - internal static readonly IDictionary VALUE_TO_ECI; - internal static readonly IDictionary NAME_TO_ECI; - - private readonly String encodingName; - - public String EncodingName - { - get - { - return encodingName; - } - - } - - static CharacterSetECI() - { - VALUE_TO_ECI = new Dictionary(); - NAME_TO_ECI = new Dictionary(); - // TODO figure out if these values are even right! - addCharacterSet(0, "CP437"); - addCharacterSet(1, new[] { "ISO-8859-1", "ISO8859_1" }); - addCharacterSet(2, "CP437"); - addCharacterSet(3, new[] { "ISO-8859-1", "ISO8859_1" }); - addCharacterSet(4, new[] { "ISO-8859-2", "ISO8859_2" }); - addCharacterSet(5, new[] { "ISO-8859-3", "ISO8859_3" }); - addCharacterSet(6, new[] { "ISO-8859-4", "ISO8859_4" }); - addCharacterSet(7, new[] { "ISO-8859-5", "ISO8859_5" }); - addCharacterSet(8, new[] { "ISO-8859-6", "ISO8859_6" }); - addCharacterSet(9, new[] { "ISO-8859-7", "ISO8859_7" }); - addCharacterSet(10, new[] { "ISO-8859-8", "ISO8859_8" }); - addCharacterSet(11, new[] { "ISO-8859-9", "ISO8859_9" }); - addCharacterSet(12, new[] { "ISO-8859-4", "ISO-8859-10", "ISO8859_10" }); // use ISO-8859-4 because ISO-8859-16 isn't supported - addCharacterSet(13, new[] { "ISO-8859-11", "ISO8859_11" }); - addCharacterSet(15, new[] { "ISO-8859-13", "ISO8859_13" }); - addCharacterSet(16, new[] { "ISO-8859-1", "ISO-8859-14", "ISO8859_14" }); // use ISO-8859-1 because ISO-8859-16 isn't supported - addCharacterSet(17, new[] { "ISO-8859-15", "ISO8859_15" }); - addCharacterSet(18, new[] { "ISO-8859-3", "ISO-8859-16", "ISO8859_16" }); // use ISO-8859-3 because ISO-8859-16 isn't supported - addCharacterSet(20, new[] { "SJIS", "Shift_JIS" }); - addCharacterSet(21, new[] { "WINDOWS-1250", "CP1250" }); - addCharacterSet(22, new[] { "WINDOWS-1251", "CP1251" }); - addCharacterSet(23, new[] { "WINDOWS-1252", "CP1252" }); - addCharacterSet(24, new[] { "WINDOWS-1256", "CP1256" }); - addCharacterSet(25, new[] { "UTF-16BE", "UNICODEBIG" }); - addCharacterSet(26, new[] { "UTF-8", "UTF8" }); - addCharacterSet(27, "US-ASCII"); - addCharacterSet(170, "US-ASCII"); - addCharacterSet(28, "BIG5"); - addCharacterSet(29, new[] { "GB18030", "GB2312", "EUC_CN", "GBK" }); - addCharacterSet(30, new[] { "EUC-KR", "EUC_KR" }); - } - - private CharacterSetECI(int value, String encodingName) - : base(value) - { - this.encodingName = encodingName; - } - - private static void addCharacterSet(int value, String encodingName) - { - var eci = new CharacterSetECI(value, encodingName); - VALUE_TO_ECI[value] = eci; // can't use valueOf - NAME_TO_ECI[encodingName] = eci; - } - - private static void addCharacterSet(int value, String[] encodingNames) - { - var eci = new CharacterSetECI(value, encodingNames[0]); - VALUE_TO_ECI[value] = eci; // can't use valueOf - foreach (string t in encodingNames) - { - NAME_TO_ECI[t] = eci; - } - } - - /// character set ECI value - /// - /// {@link CharacterSetECI} representing ECI of given value, or null if it is legal but - /// unsupported - /// - /// IllegalArgumentException if ECI value is invalid - public static CharacterSetECI getCharacterSetECIByValue(int value) - { - if (value < 0 || value >= 900) - { - return null; - } - return VALUE_TO_ECI[value]; - } - - /// character set ECI encoding name - /// - /// {@link CharacterSetECI} representing ECI for character encoding, or null if it is legal - /// but unsupported - /// - public static CharacterSetECI getCharacterSetECIByName(String name) - { - return NAME_TO_ECI[name.ToUpper()]; - } - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/common/ECI.cs b/shadowsocks-csharp/3rd/zxing/common/ECI.cs deleted file mode 100755 index fa947ba2..00000000 --- a/shadowsocks-csharp/3rd/zxing/common/ECI.cs +++ /dev/null @@ -1,66 +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. -*/ -using System; -namespace ZXing.Common -{ - - /// Superclass of classes encapsulating types ECIs, according to "Extended Channel Interpretations" - /// 5.3 of ISO 18004. - /// - /// - /// Sean Owen - /// - /// www.Redivivus.in (suraj.supekar@redivivus.in) - Ported from ZXING Java Source - /// - public abstract class ECI - { - virtual public int Value - { - get - { - return value_Renamed; - } - - } - - //UPGRADE_NOTE: Final was removed from the declaration of 'value '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'" - private int value_Renamed; - - internal ECI(int value_Renamed) - { - this.value_Renamed = value_Renamed; - } - - /// ECI value - /// - /// {@link ECI} representing ECI of given value, or null if it is legal but unsupported - /// - /// IllegalArgumentException if ECI value is invalid - public static ECI getECIByValue(int value_Renamed) - { - if (value_Renamed < 0 || value_Renamed > 999999) - { - throw new System.ArgumentException("Bad ECI value: " + value_Renamed); - } - if (value_Renamed < 900) - { - // Character set ECIs use 000000 - 000899 - return CharacterSetECI.getCharacterSetECIByValue(value_Renamed); - } - return null; - } - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs index 77a0b2cc..189fb41f 100755 --- a/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs +++ b/shadowsocks-csharp/3rd/zxing/qrcode/decoder/DecodedBitStreamParser.cs @@ -54,7 +54,7 @@ namespace ZXing.QrCode.Internal try { - CharacterSetECI currentCharacterSetECI = null; + // CharacterSetECI currentCharacterSetECI = null; bool fc1InEffect = false; Mode mode; do @@ -96,6 +96,7 @@ namespace ZXing.QrCode.Internal } else if (mode == Mode.ECI) { + /* // Count doesn't apply to ECI int value = parseECIValue(bits); currentCharacterSetECI = CharacterSetECI.getCharacterSetECIByValue(value); @@ -103,6 +104,7 @@ namespace ZXing.QrCode.Internal { return null; } + * */ } else { @@ -135,7 +137,7 @@ namespace ZXing.QrCode.Internal } else if (mode == Mode.BYTE) { - if (!decodeByteSegment(bits, result, count, currentCharacterSetECI, byteSegments, hints)) + if (!decodeByteSegment(bits, result, count, byteSegments, hints)) return null; } else if (mode == Mode.KANJI) @@ -301,7 +303,6 @@ namespace ZXing.QrCode.Internal private static bool decodeByteSegment(BitSource bits, StringBuilder result, int count, - CharacterSetECI currentCharacterSetECI, IList byteSegments, IDictionary hints) { @@ -317,19 +318,8 @@ namespace ZXing.QrCode.Internal readBytes[i] = (byte)bits.readBits(8); } String encoding; - if (currentCharacterSetECI == null) - { - // The spec isn't clear on this mode; see - // section 6.4.5: t does not say which encoding to assuming - // upon decoding. I have seen ISO-8859-1 used as well as - // Shift_JIS -- without anything like an ECI designator to - // give a hint. - encoding = StringUtils.guessEncoding(readBytes, hints); - } - else - { - encoding = currentCharacterSetECI.EncodingName; - } + encoding = StringUtils.guessEncoding(readBytes, hints); + try { result.Append(Encoding.GetEncoding(encoding).GetString(readBytes, 0, readBytes.Length)); diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index cd5b2683..e5da1098 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -78,12 +78,10 @@ - - From 25c133070fe344ceb3db0a1fc3270bd8e98fb5f7 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 13 Jan 2015 02:16:45 +0800 Subject: [PATCH 33/45] remove some methods --- shadowsocks-csharp/3rd/zxing/common/BitArray.cs | 210 --------------------- shadowsocks-csharp/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 @@ -57,24 +57,6 @@ namespace ZXing.Common } } - /// 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. public BitMatrix(int dimension) @@ -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 From 794c8bb080d42cde39dac5c871755abe28c94c76 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 13 Jan 2015 22:13:52 +0800 Subject: [PATCH 34/45] refine qrcode --- .../Properties/Resources.Designer.cs | 7 +- shadowsocks-csharp/View/MenuViewController.cs | 6 +- .../View/QRCodeSplashForm.Designer.cs | 72 ----- shadowsocks-csharp/View/QRCodeSplashForm.cs | 309 +++++++++++++++++++-- shadowsocks-csharp/View/QRCodeSplashForm.resx | 120 -------- shadowsocks-csharp/shadowsocks-csharp.csproj | 6 - 6 files changed, 291 insertions(+), 229 deletions(-) delete mode 100755 shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs delete mode 100755 shadowsocks-csharp/View/QRCodeSplashForm.resx diff --git a/shadowsocks-csharp/Properties/Resources.Designer.cs b/shadowsocks-csharp/Properties/Resources.Designer.cs index 5139429f..f6db05ad 100755 --- a/shadowsocks-csharp/Properties/Resources.Designer.cs +++ b/shadowsocks-csharp/Properties/Resources.Designer.cs @@ -76,12 +76,13 @@ namespace Shadowsocks.Properties { ///Mode=代理模式 ///PAC=PAC 模式 ///Global=全局模式 - ///Servers=服务器选择 + ///Servers=服务器 ///Edit Servers...=编辑服务器... ///Start on Boot=开机启动 ///Share over LAN=在局域网共享代理 ///Edit PAC File...=编辑 PAC 文件... ///Show QRCode...=显示二维码... + ///Scan QRCode from Screen...=扫描屏幕上的二维码... ///Show Logs...=显示日志... ///About...=关于... ///Quit=退出 @@ -99,9 +100,7 @@ namespace Shadowsocks.Properties { ///Cancel=取消 ///New server=未配置的服务器 ///QRCode=二维码 - ///Shadowsocks Error: {0}=Shadowsocks 错误: {0} - ///Port already in use=端口已被占用 - ///Il [rest of string was truncated]";. + ///Shadowsocks Error: {0}=Shadowsocks [rest of string was truncated]";. /// internal static string cn { get { diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index f8b33e92..1794e7e2 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -425,10 +425,10 @@ namespace Shadowsocks.View maxX += margin + marginLeft; minY += -margin + marginTop; maxY += margin + marginTop; - splash.Location = new Point((int)minX, (int)minY); + splash.Location = new Point(0, 0); // we need a panel because a window has a minimal size - splash.Panel.Size = new Size((int)maxX - (int)minX, (int)maxY - (int)minY); - splash.Size = splash.Panel.Size; + splash.TargetRect = new Rectangle((int)minX, (int)minY, (int)maxX - (int)minX, (int)maxY - (int)minY); + splash.Size = new Size(fullImage.Width, fullImage.Height); splash.Show(); return; } diff --git a/shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs b/shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs deleted file mode 100755 index 0c7e1601..00000000 --- a/shadowsocks-csharp/View/QRCodeSplashForm.Designer.cs +++ /dev/null @@ -1,72 +0,0 @@ -namespace Shadowsocks.View -{ - partial class QRCodeSplashForm - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.Panel = new System.Windows.Forms.Panel(); - this.SuspendLayout(); - // - // Panel - // - this.Panel.BackColor = System.Drawing.Color.Crimson; - this.Panel.Location = new System.Drawing.Point(0, 0); - this.Panel.Margin = new System.Windows.Forms.Padding(0); - this.Panel.Name = "Panel"; - this.Panel.Size = new System.Drawing.Size(168, 158); - this.Panel.TabIndex = 0; - // - // QRCodeSplashForm - // - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; - this.BackColor = System.Drawing.Color.White; - this.ClientSize = new System.Drawing.Size(284, 262); - this.ControlBox = false; - this.Controls.Add(this.Panel); - this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "QRCodeSplashForm"; - this.Opacity = 0.3D; - this.ShowIcon = false; - this.ShowInTaskbar = false; - this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; - this.Text = "QRCodeSplashForm"; - this.TopMost = true; - this.TransparencyKey = System.Drawing.Color.White; - this.Load += new System.EventHandler(this.QRCodeSplashForm_Load); - this.ResumeLayout(false); - - } - - #endregion - - public System.Windows.Forms.Panel Panel; - - } -} \ No newline at end of file diff --git a/shadowsocks-csharp/View/QRCodeSplashForm.cs b/shadowsocks-csharp/View/QRCodeSplashForm.cs index 3d14785e..f18377b9 100755 --- a/shadowsocks-csharp/View/QRCodeSplashForm.cs +++ b/shadowsocks-csharp/View/QRCodeSplashForm.cs @@ -5,60 +5,321 @@ using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; +using System.Drawing.Imaging; +using System.Runtime.InteropServices; + namespace Shadowsocks.View { - public partial class QRCodeSplashForm : Form + public class QRCodeSplashForm : PerPixelAlphaForm { + public class QRRectView : Control + { + private Pen pen; + private Brush brush; + + public QRRectView() + { + pen = new Pen(Color.Red, 3); + brush = new SolidBrush(Color.FromArgb(100, Color.Red)); + SetStyle(ControlStyles.ResizeRedraw, true); + SetStyle(ControlStyles.SupportsTransparentBackColor, true); + this.BackColor = Color.Transparent; + this.DoubleBuffered = true; + } + + protected override void OnPaint(PaintEventArgs e) + { + Graphics g = e.Graphics; + g.FillRectangle(brush, 0, 0, Width, Height); + g.DrawRectangle(pen, 0, 0, Width, Height); + } + } + public Rectangle TargetRect; + public QRCodeSplashForm() { - InitializeComponent(); + this.Load += QRCodeSplashForm_Load; + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; + this.BackColor = System.Drawing.Color.White; + this.ClientSize = new System.Drawing.Size(284, 262); + this.ControlBox = false; + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "QRCodeSplashForm"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; + this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; + this.TopMost = true; + } private Timer timer; - private int step; + private int animationStep; + private int flashStep; + private static int ANIMATION_STEPS = 30; + private static double ANIMATION_TIME = 0.3; + private QRRectView codeRectView; + int x; + int y; + int w; + int h; + Bitmap bitmap; + Graphics g; + Pen pen; + SolidBrush brush; private void QRCodeSplashForm_Load(object sender, EventArgs e) { - step = 0; + SetStyle(ControlStyles.SupportsTransparentBackColor, true); + this.BackColor = Color.Transparent; + animationStep = 0; + flashStep = 0; + //codeRectView = new QRRectView(); + x = 0; + y = 0; + w = Width; + h = Height; + //this.Controls.Add(codeRectView); timer = new Timer(); - timer.Interval = 300; + timer.Interval = (int)(ANIMATION_TIME * 1000 / ANIMATION_STEPS); timer.Tick += timer_Tick; timer.Start(); + bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppArgb); + g = Graphics.FromImage(bitmap); + pen = new Pen(Color.Red, 3); + brush = new SolidBrush(Color.FromArgb(30, Color.Red)); } - void timer_Tick(object sender, EventArgs e) + protected override CreateParams CreateParams { - timer.Interval = 40; - if (step == 0) + get { - this.Opacity = 0; + CreateParams cp = base.CreateParams; + cp.ExStyle |= 0x00080000; // This form has to have the WS_EX_LAYERED extended style + return cp; } - else if (step == 1) - { - this.Opacity = 0.3; - } - else if (step == 1) + } + + void timer_Tick(object sender, EventArgs e) + { + if (animationStep < ANIMATION_STEPS) { - this.Opacity = 0.0; + animationStep++; + double percent = (double)animationStep / (double)ANIMATION_STEPS; + // ease out + percent = 1 - Math.Pow((1 - percent), 4); + x = (int)(TargetRect.X * percent); + y = (int)(TargetRect.Y * percent); + w = (int)(TargetRect.Width * percent + this.Size.Width * (1 - percent)); + h = (int)(TargetRect.Height * percent + this.Size.Height * (1 - percent)); + //codeRectView.Location = new Point(x, y); + //codeRectView.Size = new Size(w, h); + pen.Color = Color.FromArgb((int)(255 * percent), Color.Red); + brush.Color = Color.FromArgb((int)(30 * percent), Color.Red); + g.Clear(Color.Transparent); + g.FillRectangle(brush, x, y, w, h); + g.DrawRectangle(pen, x, y, w, h); + SetBitmap(bitmap); } - else if (step == 2) + else { - this.Opacity = 0.3; + timer.Interval = 50; + if (flashStep == 0) + { + g.Clear(Color.Transparent); + SetBitmap(bitmap); + } + else if (flashStep == 1) + { + g.FillRectangle(brush, x, y, w, h); + g.DrawRectangle(pen, x, y, w, h); + SetBitmap(bitmap); + } + else if (flashStep == 1) + { + g.Clear(Color.Transparent); + SetBitmap(bitmap); + } + else if (flashStep == 2) + { + g.FillRectangle(brush, x, y, w, h); + g.DrawRectangle(pen, x, y, w, h); + SetBitmap(bitmap); + } + else if (flashStep == 3) + { + g.Clear(Color.Transparent); + SetBitmap(bitmap); + } + else if (flashStep == 4) + { + g.FillRectangle(brush, x, y, w, h); + g.DrawRectangle(pen, x, y, w, h); + SetBitmap(bitmap); + } + else + { + timer.Stop(); + pen.Dispose(); + brush.Dispose(); + bitmap.Dispose(); + this.Close(); + } + flashStep++; } - else if (step == 3) + } + } + + + // class that exposes needed win32 gdi functions. + class Win32 + { + + [StructLayout(LayoutKind.Sequential)] + public struct Point + { + public Int32 x; + public Int32 y; + + public Point(Int32 x, Int32 y) { this.x = x; this.y = y; } + } + + + [StructLayout(LayoutKind.Sequential)] + public struct Size + { + public Int32 cx; + public Int32 cy; + + public Size(Int32 cx, Int32 cy) { this.cx = cx; this.cy = cy; } + } + + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + struct ARGB + { + public byte Blue; + public byte Green; + public byte Red; + public byte Alpha; + } + + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct BLENDFUNCTION + { + public byte BlendOp; + public byte BlendFlags; + public byte SourceConstantAlpha; + public byte AlphaFormat; + } + + + public const Int32 ULW_COLORKEY = 0x00000001; + public const Int32 ULW_ALPHA = 0x00000002; + public const Int32 ULW_OPAQUE = 0x00000004; + + public const byte AC_SRC_OVER = 0x00; + public const byte AC_SRC_ALPHA = 0x01; + + + [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)] + public static extern int UpdateLayeredWindow(IntPtr hwnd, IntPtr hdcDst, ref Point pptDst, ref Size psize, IntPtr hdcSrc, ref Point pprSrc, Int32 crKey, ref BLENDFUNCTION pblend, Int32 dwFlags); + + [DllImport("user32.dll", ExactSpelling = true, SetLastError = true)] + public static extern IntPtr GetDC(IntPtr hWnd); + + [DllImport("user32.dll", ExactSpelling = true)] + public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC); + + [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)] + public static extern IntPtr CreateCompatibleDC(IntPtr hDC); + + [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)] + public static extern int DeleteDC(IntPtr hdc); + + [DllImport("gdi32.dll", ExactSpelling = true)] + public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject); + + [DllImport("gdi32.dll", ExactSpelling = true, SetLastError = true)] + public static extern int DeleteObject(IntPtr hObject); + } + + + public class PerPixelAlphaForm : Form + { + // http://www.codeproject.com/Articles/1822/Per-Pixel-Alpha-Blend-in-C + // Rui Lopes + + public PerPixelAlphaForm() + { + // This form should not have a border or else Windows will clip it. + FormBorderStyle = FormBorderStyle.None; + } + + public void SetBitmap(Bitmap bitmap) + { + SetBitmap(bitmap, 255); + } + + + /// Changes the current bitmap with a custom opacity level. Here is where all happens! + public void SetBitmap(Bitmap bitmap, byte opacity) + { + if (bitmap.PixelFormat != PixelFormat.Format32bppArgb) + throw new ApplicationException("The bitmap must be 32ppp with alpha-channel."); + + // The ideia of this is very simple, + // 1. Create a compatible DC with screen; + // 2. Select the bitmap with 32bpp with alpha-channel in the compatible DC; + // 3. Call the UpdateLayeredWindow. + + IntPtr screenDc = Win32.GetDC(IntPtr.Zero); + IntPtr memDc = Win32.CreateCompatibleDC(screenDc); + IntPtr hBitmap = IntPtr.Zero; + IntPtr oldBitmap = IntPtr.Zero; + + try { - this.Opacity = 0.0; + hBitmap = bitmap.GetHbitmap(Color.FromArgb(0)); // grab a GDI handle from this GDI+ bitmap + oldBitmap = Win32.SelectObject(memDc, hBitmap); + + Win32.Size size = new Win32.Size(bitmap.Width, bitmap.Height); + Win32.Point pointSource = new Win32.Point(0, 0); + Win32.Point topPos = new Win32.Point(Left, Top); + Win32.BLENDFUNCTION blend = new Win32.BLENDFUNCTION(); + blend.BlendOp = Win32.AC_SRC_OVER; + blend.BlendFlags = 0; + blend.SourceConstantAlpha = opacity; + blend.AlphaFormat = Win32.AC_SRC_ALPHA; + + Win32.UpdateLayeredWindow(Handle, screenDc, ref topPos, ref size, memDc, ref pointSource, 0, ref blend, Win32.ULW_ALPHA); } - else if (step == 4) + finally { - this.Opacity = 0.3; + Win32.ReleaseDC(IntPtr.Zero, screenDc); + if (hBitmap != IntPtr.Zero) + { + Win32.SelectObject(memDc, oldBitmap); + //Windows.DeleteObject(hBitmap); // The documentation says that we have to use the Windows.DeleteObject... but since there is no such method I use the normal DeleteObject from Win32 GDI and it's working fine without any resource leak. + Win32.DeleteObject(hBitmap); + } + Win32.DeleteDC(memDc); } - else + } + + + protected override CreateParams CreateParams + { + get { - this.Close(); + CreateParams cp = base.CreateParams; + cp.ExStyle |= 0x00080000; // This form has to have the WS_EX_LAYERED extended style + return cp; } - step++; } } } diff --git a/shadowsocks-csharp/View/QRCodeSplashForm.resx b/shadowsocks-csharp/View/QRCodeSplashForm.resx deleted file mode 100755 index 5ea0895e..00000000 --- a/shadowsocks-csharp/View/QRCodeSplashForm.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index e5da1098..61820eaa 100755 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -169,9 +169,6 @@ Form - - QRCodeSplashForm.cs - ConfigForm.cs Designer @@ -184,9 +181,6 @@ QRCodeForm.cs - - QRCodeSplashForm.cs - Designer From ef74cd497c175b73e4659ead0867d68f740bfdd2 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 13 Jan 2015 22:15:24 +0800 Subject: [PATCH 35/45] remove qrrectview --- shadowsocks-csharp/View/QRCodeSplashForm.cs | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/shadowsocks-csharp/View/QRCodeSplashForm.cs b/shadowsocks-csharp/View/QRCodeSplashForm.cs index f18377b9..73a65a21 100755 --- a/shadowsocks-csharp/View/QRCodeSplashForm.cs +++ b/shadowsocks-csharp/View/QRCodeSplashForm.cs @@ -13,28 +13,6 @@ namespace Shadowsocks.View { public class QRCodeSplashForm : PerPixelAlphaForm { - public class QRRectView : Control - { - private Pen pen; - private Brush brush; - - public QRRectView() - { - pen = new Pen(Color.Red, 3); - brush = new SolidBrush(Color.FromArgb(100, Color.Red)); - SetStyle(ControlStyles.ResizeRedraw, true); - SetStyle(ControlStyles.SupportsTransparentBackColor, true); - this.BackColor = Color.Transparent; - this.DoubleBuffered = true; - } - - protected override void OnPaint(PaintEventArgs e) - { - Graphics g = e.Graphics; - g.FillRectangle(brush, 0, 0, Width, Height); - g.DrawRectangle(pen, 0, 0, Width, Height); - } - } public Rectangle TargetRect; public QRCodeSplashForm() @@ -61,7 +39,6 @@ namespace Shadowsocks.View private int flashStep; private static int ANIMATION_STEPS = 30; private static double ANIMATION_TIME = 0.3; - private QRRectView codeRectView; int x; int y; int w; @@ -77,12 +54,10 @@ namespace Shadowsocks.View this.BackColor = Color.Transparent; animationStep = 0; flashStep = 0; - //codeRectView = new QRRectView(); x = 0; y = 0; w = Width; h = Height; - //this.Controls.Add(codeRectView); timer = new Timer(); timer.Interval = (int)(ANIMATION_TIME * 1000 / ANIMATION_STEPS); timer.Tick += timer_Tick; From 1b38b9060d90545e5f27dd98a72cb401e297de32 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Tue, 13 Jan 2015 22:17:24 +0800 Subject: [PATCH 36/45] add TODO: test on high DPI --- shadowsocks-csharp/View/MenuViewController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 1794e7e2..c64be08c 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -427,6 +427,7 @@ namespace Shadowsocks.View maxY += margin + marginTop; splash.Location = new Point(0, 0); // we need a panel because a window has a minimal size + // TODO: test on high DPI splash.TargetRect = new Rectangle((int)minX, (int)minY, (int)maxX - (int)minX, (int)maxY - (int)minY); splash.Size = new Size(fullImage.Width, fullImage.Height); splash.Show(); From 179eb818a7c240feea26c292de76dd8d4bc7662a Mon Sep 17 00:00:00 2001 From: clowwindy Date: Wed, 14 Jan 2015 01:17:33 +0800 Subject: [PATCH 37/45] fix typo --- shadowsocks-csharp/View/QRCodeSplashForm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shadowsocks-csharp/View/QRCodeSplashForm.cs b/shadowsocks-csharp/View/QRCodeSplashForm.cs index 73a65a21..bd5bb404 100755 --- a/shadowsocks-csharp/View/QRCodeSplashForm.cs +++ b/shadowsocks-csharp/View/QRCodeSplashForm.cs @@ -247,7 +247,7 @@ namespace Shadowsocks.View if (bitmap.PixelFormat != PixelFormat.Format32bppArgb) throw new ApplicationException("The bitmap must be 32ppp with alpha-channel."); - // The ideia of this is very simple, + // The idea of this is very simple, // 1. Create a compatible DC with screen; // 2. Select the bitmap with 32bpp with alpha-channel in the compatible DC; // 3. Call the UpdateLayeredWindow. From 4dae44c59bfb14d49b87eaee59ed2a0c976763c1 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Wed, 14 Jan 2015 01:17:41 +0800 Subject: [PATCH 38/45] don't unpack polipo every time --- shadowsocks-csharp/Controller/PolipoRunner.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/shadowsocks-csharp/Controller/PolipoRunner.cs b/shadowsocks-csharp/Controller/PolipoRunner.cs index a44e5ea1..42bf3bfa 100755 --- a/shadowsocks-csharp/Controller/PolipoRunner.cs +++ b/shadowsocks-csharp/Controller/PolipoRunner.cs @@ -12,6 +12,20 @@ namespace Shadowsocks.Controller class PolipoRunner { private Process _process; + private static string temppath; + + static PolipoRunner() + { + temppath = Path.GetTempPath(); + try + { + FileManager.UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe); + } + catch (IOException e) + { + Logging.LogUsefulException(e); + } + } public void Start(Configuration configuration) { @@ -31,12 +45,10 @@ namespace Shadowsocks.Controller Console.WriteLine(e.ToString()); } } - string temppath = Path.GetTempPath(); string polipoConfig = Resources.polipo_config; polipoConfig = polipoConfig.Replace("__SOCKS_PORT__", server.local_port.ToString()); polipoConfig = polipoConfig.Replace("__POLIPO_BIND_IP__", configuration.shareOverLan ? "0.0.0.0" : "127.0.0.1"); FileManager.ByteArrayToFile(temppath + "/polipo.conf", System.Text.Encoding.UTF8.GetBytes(polipoConfig)); - FileManager.UncompressFile(temppath + "/ss_polipo.exe", Resources.polipo_exe); _process = new Process(); // Configure the process using the StartInfo properties. From 38c597ba0ca158aa776e8572a5c76e248c38e680 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Wed, 14 Jan 2015 01:22:29 +0800 Subject: [PATCH 39/45] bump --- shadowsocks-csharp/Controller/UpdateChecker.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shadowsocks-csharp/Controller/UpdateChecker.cs b/shadowsocks-csharp/Controller/UpdateChecker.cs index 7996a687..3fe76f98 100755 --- a/shadowsocks-csharp/Controller/UpdateChecker.cs +++ b/shadowsocks-csharp/Controller/UpdateChecker.cs @@ -17,7 +17,7 @@ namespace Shadowsocks.Controller public string LatestVersionURL; public event EventHandler NewVersionFound; - public const string Version = "2.1.6"; + public const string Version = "2.2"; public void CheckUpdate() { From 40aded9571ff5e78c89aa6b554f4ee15ab76c065 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Wed, 14 Jan 2015 01:45:27 +0800 Subject: [PATCH 40/45] refine error message --- shadowsocks-csharp/Controller/SystemProxy.cs | 14 ++++++++------ shadowsocks-csharp/Data/cn.txt | 3 ++- shadowsocks-csharp/View/MenuViewController.cs | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/shadowsocks-csharp/Controller/SystemProxy.cs b/shadowsocks-csharp/Controller/SystemProxy.cs index fa3c5a8e..c8cc6f8d 100755 --- a/shadowsocks-csharp/Controller/SystemProxy.cs +++ b/shadowsocks-csharp/Controller/SystemProxy.cs @@ -48,10 +48,11 @@ namespace Shadowsocks.Controller //Must Notify IE first, or the connections do not chanage CopyProxySettingFromLan(); } - catch (Exception) + catch (Exception e) { - MessageBox.Show("can not change registry!"); - throw; + Logging.LogUsefulException(e); + // TODO this should be moved into views + MessageBox.Show(I18N.GetString("Failed to update registry")); } } @@ -68,10 +69,11 @@ namespace Shadowsocks.Controller SystemProxy.NotifyIE(); CopyProxySettingFromLan(); } - catch (Exception) + catch (Exception e) { - MessageBox.Show("can not change registry!"); - throw; + Logging.LogUsefulException(e); + // TODO this should be moved into views + MessageBox.Show(I18N.GetString("Failed to update registry")); } } diff --git a/shadowsocks-csharp/Data/cn.txt b/shadowsocks-csharp/Data/cn.txt index 82ea1744..ed6dfbd8 100644 --- a/shadowsocks-csharp/Data/cn.txt +++ b/shadowsocks-csharp/Data/cn.txt @@ -43,5 +43,6 @@ Disabled=已禁用代理 Update PAC from GFWList=从 GFWList 更新 PAC Failed to update PAC file =更新 PAC 文件失败 PAC updated=更新 PAC 成功 -"Failed to find QRCode=无法找到二维码 +No QRCode found. Try to zoom in or move it to the center of the screen.=找不到二维码,尝试把它放大或者移动到靠近屏幕中间的位置 Failed to decode QRCode=无法解析二维码 +Failed to update registry=无法修改注册表 diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index c64be08c..f1258cd0 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -435,7 +435,7 @@ namespace Shadowsocks.View } } } - MessageBox.Show(I18N.GetString("Failed to find QRCode")); + MessageBox.Show(I18N.GetString("No QRCode found. Try to zoom in or move it to the center of the screen.")); } void splash_FormClosed(object sender, FormClosedEventArgs e) @@ -451,7 +451,7 @@ namespace Shadowsocks.View private void AutoStartupItem_Click(object sender, EventArgs e) { AutoStartupItem.Checked = !AutoStartupItem.Checked; if (!AutoStartup.Set(AutoStartupItem.Checked)) { - MessageBox.Show("Failed to edit registry"); + MessageBox.Show(I18N.GetString("Failed to update registry")); } } } From a231cba73b345baf6bdbb4aade03f4837720d936 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Wed, 14 Jan 2015 21:08:53 +0800 Subject: [PATCH 41/45] refine animation --- shadowsocks-csharp/View/QRCodeSplashForm.cs | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/shadowsocks-csharp/View/QRCodeSplashForm.cs b/shadowsocks-csharp/View/QRCodeSplashForm.cs index bd5bb404..ac9828e4 100755 --- a/shadowsocks-csharp/View/QRCodeSplashForm.cs +++ b/shadowsocks-csharp/View/QRCodeSplashForm.cs @@ -7,6 +7,7 @@ using System.Text; using System.Windows.Forms; using System.Drawing.Imaging; using System.Runtime.InteropServices; +using System.Diagnostics; namespace Shadowsocks.View @@ -20,7 +21,7 @@ namespace Shadowsocks.View this.Load += QRCodeSplashForm_Load; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.BackColor = System.Drawing.Color.White; - this.ClientSize = new System.Drawing.Size(284, 262); + this.ClientSize = new System.Drawing.Size(1, 1); this.ControlBox = false; this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.MaximizeBox = false; @@ -31,14 +32,14 @@ namespace Shadowsocks.View this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.TopMost = true; - } private Timer timer; - private int animationStep; private int flashStep; - private static int ANIMATION_STEPS = 30; - private static double ANIMATION_TIME = 0.3; + private static double FPS = 1.0 / 15 * 1000; // System.Windows.Forms.Timer resolution is 15ms + private static double ANIMATION_TIME = 0.5; + private static int ANIMATION_STEPS = (int)(ANIMATION_TIME * FPS); + Stopwatch sw; int x; int y; int w; @@ -52,12 +53,12 @@ namespace Shadowsocks.View { SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent; - animationStep = 0; flashStep = 0; x = 0; y = 0; w = Width; h = Height; + sw = Stopwatch.StartNew(); timer = new Timer(); timer.Interval = (int)(ANIMATION_TIME * 1000 / ANIMATION_STEPS); timer.Tick += timer_Tick; @@ -80,10 +81,9 @@ namespace Shadowsocks.View void timer_Tick(object sender, EventArgs e) { - if (animationStep < ANIMATION_STEPS) + double percent = (double)sw.ElapsedMilliseconds / 1000.0 / (double)ANIMATION_TIME; + if (percent < 1) { - animationStep++; - double percent = (double)animationStep / (double)ANIMATION_STEPS; // ease out percent = 1 - Math.Pow((1 - percent), 4); x = (int)(TargetRect.X * percent); @@ -101,14 +101,15 @@ namespace Shadowsocks.View } else { - timer.Interval = 50; if (flashStep == 0) { + timer.Interval = 100; g.Clear(Color.Transparent); SetBitmap(bitmap); } else if (flashStep == 1) { + timer.Interval = 50; g.FillRectangle(brush, x, y, w, h); g.DrawRectangle(pen, x, y, w, h); SetBitmap(bitmap); @@ -137,6 +138,7 @@ namespace Shadowsocks.View } else { + sw.Stop(); timer.Stop(); pen.Dispose(); brush.Dispose(); From 5cfb870bbcb2f98521f9c3077e7dec289b2041cc Mon Sep 17 00:00:00 2001 From: clowwindy Date: Wed, 14 Jan 2015 21:40:12 +0800 Subject: [PATCH 42/45] update CHANGES --- CHANGES | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES b/CHANGES index a9554b6a..0fc9e1f9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +2.2 2015-01-14 +- Support updating PAC from GFWList +- Support adding server by scanning QR Code +- Output timestamp in logs +- Minor fixes + 2.1.6 2015-01-02 - Fix OPTIONS requests - Improve logs From 15f57a4d04f819944ae41eb94d6f2e1910926fd5 Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 15 Jan 2015 01:12:04 +0800 Subject: [PATCH 43/45] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 05c1dfd0..7b05714a 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Download [latest release]. For <= Windows 7, download Shadowsocks-win-x.x.x.zip. -For >= Windows 8, download Shadowsocks-win-dotnet4.0-x.x.x.zip. +For >= Windows 8, download Shadowsocks-win-dotnet4.0-x.x.x.zip, unless you have .Net 2.0 installed. #### Usage From 00409728865c166a11a7f90224023ba2da23186f Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 15 Jan 2015 19:36:34 +0800 Subject: [PATCH 44/45] support multiple screens --- shadowsocks-csharp/View/MenuViewController.cs | 119 +++++++++++++------------- 1 file changed, 61 insertions(+), 58 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index f1258cd0..3da29c7c 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -364,74 +364,77 @@ namespace Shadowsocks.View private void ScanQRCodeItem_Click(object sender, EventArgs e) { - - using (Bitmap fullImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, - Screen.PrimaryScreen.Bounds.Height)) + foreach (Screen screen in Screen.AllScreens) { - using (Graphics g = Graphics.FromImage(fullImage)) - { - g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, - Screen.PrimaryScreen.Bounds.Y, - 0, 0, - fullImage.Size, - CopyPixelOperation.SourceCopy); - } - for (int i = 0; i < 5; i++) + using (Bitmap fullImage = new Bitmap(screen.Bounds.Width, + screen.Bounds.Height)) { - int marginLeft = fullImage.Width * i / 3 / 5; - int marginTop = fullImage.Height * i / 3 / 5; - Rectangle cropRect = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2); - Bitmap target = new Bitmap(cropRect.Width, cropRect.Height); - - using (Graphics g = Graphics.FromImage(target)) + using (Graphics g = Graphics.FromImage(fullImage)) { - g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height), - cropRect, - GraphicsUnit.Pixel); + g.CopyFromScreen(screen.Bounds.X, + screen.Bounds.Y, + 0, 0, + fullImage.Size, + CopyPixelOperation.SourceCopy); } - var source = new BitmapLuminanceSource(target); - var bitmap = new BinaryBitmap(new HybridBinarizer(source)); - QRCodeReader reader = new QRCodeReader(); - var result = reader.decode(bitmap); - if (result != null) + int maxTry = 10; + for (int i = 0; i < maxTry; i++) { - var success = controller.AddServerBySSURL(result.Text); - QRCodeSplashForm splash = new QRCodeSplashForm(); - if (success) - { - splash.FormClosed += splash_FormClosed; - } - else if (result.Text.StartsWith("http://") || result.Text.StartsWith("https://")) + int marginLeft = fullImage.Width * i / 3 / maxTry; + int marginTop = fullImage.Height * i / 3 / maxTry; + Rectangle cropRect = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2); + Bitmap target = new Bitmap(cropRect.Width, cropRect.Height); + + using (Graphics g = Graphics.FromImage(target)) { - _urlToOpen = result.Text; - splash.FormClosed += openURLFromQRCode; + g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height), + cropRect, + GraphicsUnit.Pixel); } - else + var source = new BitmapLuminanceSource(target); + var bitmap = new BinaryBitmap(new HybridBinarizer(source)); + QRCodeReader reader = new QRCodeReader(); + var result = reader.decode(bitmap); + if (result != null) { - MessageBox.Show(I18N.GetString("Failed to decode QRCode")); + var success = controller.AddServerBySSURL(result.Text); + QRCodeSplashForm splash = new QRCodeSplashForm(); + if (success) + { + splash.FormClosed += splash_FormClosed; + } + else if (result.Text.StartsWith("http://") || result.Text.StartsWith("https://")) + { + _urlToOpen = result.Text; + splash.FormClosed += openURLFromQRCode; + } + else + { + MessageBox.Show(I18N.GetString("Failed to decode QRCode")); + return; + } + float minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0; + foreach (ResultPoint point in result.ResultPoints) + { + minX = Math.Min(minX, point.X); + minY = Math.Min(minY, point.Y); + maxX = Math.Max(maxX, point.X); + maxY = Math.Max(maxY, point.Y); + } + // make it 20% larger + float margin = (maxX - minX) * 0.20f; + minX += -margin + marginLeft; + maxX += margin + marginLeft; + minY += -margin + marginTop; + maxY += margin + marginTop; + splash.Location = new Point(screen.Bounds.X, screen.Bounds.Y); + // we need a panel because a window has a minimal size + // TODO: test on high DPI + splash.TargetRect = new Rectangle((int)minX + screen.Bounds.X, (int)minY + screen.Bounds.Y, (int)maxX - (int)minX, (int)maxY - (int)minY); + splash.Size = new Size(fullImage.Width, fullImage.Height); + splash.Show(); return; } - float minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0; - foreach (ResultPoint point in result.ResultPoints) - { - minX = Math.Min(minX, point.X); - minY = Math.Min(minY, point.Y); - maxX = Math.Max(maxX, point.X); - maxY = Math.Max(maxY, point.Y); - } - // make it 20% larger - float margin = (maxX - minX) * 0.20f; - minX += -margin + marginLeft; - maxX += margin + marginLeft; - minY += -margin + marginTop; - maxY += margin + marginTop; - splash.Location = new Point(0, 0); - // we need a panel because a window has a minimal size - // TODO: test on high DPI - splash.TargetRect = new Rectangle((int)minX, (int)minY, (int)maxX - (int)minX, (int)maxY - (int)minY); - splash.Size = new Size(fullImage.Width, fullImage.Height); - splash.Show(); - return; } } } From 1bf0c8bd46b4f3847e453c12df8fdf162089e29c Mon Sep 17 00:00:00 2001 From: clowwindy Date: Thu, 15 Jan 2015 19:56:36 +0800 Subject: [PATCH 45/45] refine qr code scan --- shadowsocks-csharp/View/MenuViewController.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/shadowsocks-csharp/View/MenuViewController.cs b/shadowsocks-csharp/View/MenuViewController.cs index 3da29c7c..9fe27bec 100755 --- a/shadowsocks-csharp/View/MenuViewController.cs +++ b/shadowsocks-csharp/View/MenuViewController.cs @@ -380,11 +380,12 @@ namespace Shadowsocks.View int maxTry = 10; for (int i = 0; i < maxTry; i++) { - int marginLeft = fullImage.Width * i / 3 / maxTry; - int marginTop = fullImage.Height * i / 3 / maxTry; + int marginLeft = (int)((double)fullImage.Width * i / 2.5 / maxTry); + int marginTop = (int)((double)fullImage.Height * i / 2.5 / maxTry); Rectangle cropRect = new Rectangle(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2); - Bitmap target = new Bitmap(cropRect.Width, cropRect.Height); + Bitmap target = new Bitmap(screen.Bounds.Width, screen.Bounds.Height); + double imageScale = (double)screen.Bounds.Width / (double)cropRect.Width; using (Graphics g = Graphics.FromImage(target)) { g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height), @@ -413,7 +414,7 @@ namespace Shadowsocks.View MessageBox.Show(I18N.GetString("Failed to decode QRCode")); return; } - float minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0; + double minX = Int32.MaxValue, minY = Int32.MaxValue, maxX = 0, maxY = 0; foreach (ResultPoint point in result.ResultPoints) { minX = Math.Min(minX, point.X); @@ -421,8 +422,12 @@ namespace Shadowsocks.View maxX = Math.Max(maxX, point.X); maxY = Math.Max(maxY, point.Y); } + minX /= imageScale; + minY /= imageScale; + maxX /= imageScale; + maxY /= imageScale; // make it 20% larger - float margin = (maxX - minX) * 0.20f; + double margin = (maxX - minX) * 0.20f; minX += -margin + marginLeft; maxX += margin + marginLeft; minY += -margin + marginTop;