diff --git a/Color.cs b/Color.cs index 6418515..489c715 100644 --- a/Color.cs +++ b/Color.cs @@ -1,8 +1,14 @@ -using ColorMine.ColorSpaces; -using System; +using System; namespace RiverTrace { + struct Lab + { + public double L; + public double A; + public double B; + } + struct Color { public Color(byte r, byte g, byte b) @@ -14,7 +20,28 @@ public Color(byte r, byte g, byte b) public Lab ToLab() { - return new Rgb { R = R, G = G, B = B }.To(); + double r = R * (1.0 / 255.0); + double g = G * (1.0 / 255.0); + double b = B * (1.0 / 255.0); + + r = (r > 0.04045) ? Math.Exp(Math.Log((r + 0.055) * (1.0 / 1.055)) * 2.4) : r * (1.0 / 12.92); + g = (g > 0.04045) ? Math.Exp(Math.Log((g + 0.055) * (1.0 / 1.055)) * 2.4) : g * (1.0 / 12.92); + b = (b > 0.04045) ? Math.Exp(Math.Log((b + 0.055) * (1.0 / 1.055)) * 2.4) : b * (1.0 / 12.92); + + double x = (r * 0.4124 + g * 0.3576 + b * 0.1805) * (1.0 / 0.95047); + double y = r * 0.2126 + g * 0.7152 + b * 0.0722; + double z = (r * 0.0193 + g * 0.1192 + b * 0.9505) * (1.0 / 1.08883); + + x = (x > 0.008856) ? Math.Exp(Math.Log(x) * (1.0 / 3)) : (x * 7.787) + 16.0 / 116; + y = (y > 0.008856) ? Math.Exp(Math.Log(y) * (1.0 / 3)) : (y * 7.787) + 16.0 / 116; + z = (z > 0.008856) ? Math.Exp(Math.Log(z) * (1.0 / 3)) : (z * 7.787) + 16.0 / 116; + + return new Lab + { + L = (116.0 * y) - 16.0, + A = 500.0 * (x - y), + B = 200.0 * (y - z) + }; } public static double Difference(Lab c1, Color c2) diff --git a/DebugFrame.cs b/DebugFrame.cs index 42ca561..0d48e38 100644 --- a/DebugFrame.cs +++ b/DebugFrame.cs @@ -1,5 +1,4 @@ -using ColorMine.ColorSpaces; -using System; +using System; using System.Linq; using System.Threading.Tasks; diff --git a/RiverTrace.csproj b/RiverTrace.csproj index 9b069de..eeec737 100644 --- a/RiverTrace.csproj +++ b/RiverTrace.csproj @@ -35,10 +35,6 @@ false - - packages\ColorMine.1.1.3.0\lib\ColorMine.dll - True - packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll True diff --git a/Tracer.cs b/Tracer.cs index 0756e7d..222e49d 100644 --- a/Tracer.cs +++ b/Tracer.cs @@ -1,5 +1,4 @@ -using ColorMine.ColorSpaces; -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; diff --git a/Vector.cs b/Vector.cs index 7e8c08b..d31c4a6 100644 --- a/Vector.cs +++ b/Vector.cs @@ -2,14 +2,8 @@ namespace RiverTrace { - class Vector + struct Vector { - public Vector() - { - X = 0.0; - Y = 0.0; - } - public Vector(double x, double y) { X = x; diff --git a/packages.config b/packages.config index 0935b1f..f0bf0dc 100644 --- a/packages.config +++ b/packages.config @@ -1,6 +1,5 @@  -