Skip to content

Commit

Permalink
Speed optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
Vort committed Jan 15, 2017
1 parent 9466d56 commit ebe330d
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 19 deletions.
33 changes: 30 additions & 3 deletions Color.cs
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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<Lab>();
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)
Expand Down
3 changes: 1 addition & 2 deletions DebugFrame.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ColorMine.ColorSpaces;
using System;
using System;
using System.Linq;
using System.Threading.Tasks;

Expand Down
4 changes: 0 additions & 4 deletions RiverTrace.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="ColorMine, Version=1.1.3.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\ColorMine.1.1.3.0\lib\ColorMine.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
Expand Down
3 changes: 1 addition & 2 deletions Tracer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using ColorMine.ColorSpaces;
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand Down
8 changes: 1 addition & 7 deletions Vector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ColorMine" version="1.1.3.0" targetFramework="net45" />
<package id="Costura.Fody" version="1.3.3.0" targetFramework="net45" developmentDependency="true" />
<package id="Fody" version="1.28.3" targetFramework="net45" developmentDependency="true" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
Expand Down

0 comments on commit ebe330d

Please sign in to comment.