Skip to content

Commit

Permalink
Lost dependency on Math.NET.
Browse files Browse the repository at this point in the history
(closes #11)
  • Loading branch information
tompazourek committed May 29, 2014
1 parent e4bc54d commit fbc4d98
Show file tree
Hide file tree
Showing 31 changed files with 319 additions and 167 deletions.
16 changes: 8 additions & 8 deletions Colourful/ChromaticAdaptation/BradfordChromaticAdaptation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using Vector = System.Collections.Generic.IReadOnlyList<double>;
using Matrix = System.Collections.Generic.IReadOnlyList<System.Collections.Generic.IReadOnlyList<double>>;

namespace Colourful.ChromaticAdaptation
{
Expand All @@ -28,14 +28,14 @@ namespace Colourful.ChromaticAdaptation
/// </remarks>
public class BradfordChromaticAdaptation : ChromaticAdaptationBase
{
private readonly DenseMatrix _matrix = DenseMatrix.OfRows(3, 3, new[]
private readonly Matrix _matrix = new []
{
new[] { 0.8951000, 0.2664000, -0.1614000 },
new[] { -0.7502000, 1.7135000, 0.0367000 },
new[] { 0.0389000, -0.0685000, 1.0296000 },
});
new [] { 0.8951000, 0.2664000, -0.1614000 },
new [] { -0.7502000, 1.7135000, 0.0367000 },
new [] { 0.0389000, -0.0685000, 1.0296000 },
};

protected override Matrix<double> MA
protected override Matrix MA
{
get { return _matrix; }
}
Expand Down
16 changes: 8 additions & 8 deletions Colourful/ChromaticAdaptation/ChromaticAdaptationBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
using System.Text;
using System.Threading.Tasks;
using Colourful.Implementation;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using Matrix = System.Collections.Generic.IReadOnlyList<System.Collections.Generic.IReadOnlyList<double>>;

namespace Colourful.ChromaticAdaptation
{
Expand All @@ -32,7 +31,8 @@ public abstract class ChromaticAdaptationBase : IChromaticAdaptation
/// <summary>
/// Definition of the cone response domain
/// </summary>
protected abstract Matrix<double> MA { get; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")]
protected abstract Matrix MA { get; }

/// <summary>
/// Transforms XYZ color to destination reference white.
Expand All @@ -55,13 +55,13 @@ public XYZColor Transform(XYZColor sourceColor, XYZColor sourceWhitePoint, XYZCo
private void TransformCore(XYZColor sourceColor, XYZColor sourceWhitePoint, XYZColor targetWhitePoint, out double XD, out double YD, out double ZD)
{
double rhoS, gammaS, betaS, rhoD, gammaD, betaD;
(MA * sourceWhitePoint.Vector).AssignVariables(out rhoS, out gammaS, out betaS);
(MA * targetWhitePoint.Vector).AssignVariables(out rhoD, out gammaD, out betaD);
(MA.MultiplyBy(sourceWhitePoint.Vector)).AssignVariables(out rhoS, out gammaS, out betaS);
(MA.MultiplyBy(targetWhitePoint.Vector)).AssignVariables(out rhoD, out gammaD, out betaD);

DiagonalMatrix diagonalMatrix = DiagonalMatrix.OfDiagonal(3, 3, new[] { rhoD / rhoS, gammaD / gammaS, betaD / betaS });
Matrix<double> M = MA.Inverse() * diagonalMatrix * MA;
Matrix diagonalMatrix = MatrixFactory.CreateDiagonal(rhoD / rhoS, gammaD / gammaS, betaD / betaS);
Matrix M = MA.Inverse().MultiplyBy(diagonalMatrix).MultiplyBy(MA);

(M * sourceColor.Vector).AssignVariables(out XD, out YD, out ZD);
(M.MultiplyBy(sourceColor.Vector)).AssignVariables(out XD, out YD, out ZD);
}
}
}
9 changes: 4 additions & 5 deletions Colourful/ChromaticAdaptation/VonKriesChromaticAdaptation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using Matrix = System.Collections.Generic.IReadOnlyList<System.Collections.Generic.IReadOnlyList<double>>;

namespace Colourful.ChromaticAdaptation
{
Expand All @@ -28,14 +27,14 @@ namespace Colourful.ChromaticAdaptation
/// </remarks>
public class VonKriesChromaticAdaptation : ChromaticAdaptationBase
{
private readonly DenseMatrix _matrix = DenseMatrix.OfRows(3, 3, new[]
private readonly Matrix _matrix = new[]
{
new[] { 0.4002400, 0.7076000, -0.0808100 },
new[] { -0.2263000, 1.1653200, 0.0457000 },
new[] { 0.0000000, 0.0000000, 0.9182200 },
});
};

protected override Matrix<double> MA
protected override Matrix MA
{
get { return _matrix; }
}
Expand Down
8 changes: 4 additions & 4 deletions Colourful/ChromaticAdaptation/XYZScaling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using Colourful.Implementation;
using Matrix = System.Collections.Generic.IReadOnlyList<System.Collections.Generic.IReadOnlyList<double>>;

namespace Colourful.ChromaticAdaptation
{
Expand All @@ -28,9 +28,9 @@ namespace Colourful.ChromaticAdaptation
/// </remarks>
public class XYZScaling : ChromaticAdaptationBase
{
private readonly DiagonalMatrix _matrix = DiagonalMatrix.Identity(3);
private readonly Matrix _matrix = MatrixFactory.CreateIdentity(3);

protected override Matrix<double> MA
protected override Matrix MA
{
get { return _matrix; }
}
Expand Down
9 changes: 4 additions & 5 deletions Colourful/Colors/HunterLabColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using System.Globalization;
using Vector = System.Collections.Generic.IReadOnlyList<double>;

namespace Colourful
{
Expand Down Expand Up @@ -94,9 +93,9 @@ public HunterLabColor(double l, double a, double b, XYZColor whitePoint)
/// <summary>
/// <see cref="IColorVector"/>
/// </summary>
public Vector<double> Vector
public Vector Vector
{
get { return DenseVector.OfEnumerable(new[] { L, a, b }); }
get { return new[] { L, a, b }; }
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions Colourful/Colors/IColorVector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Generic;
using Vector = System.Collections.Generic.IReadOnlyList<double>;

namespace Colourful
{
Expand All @@ -23,6 +23,6 @@ namespace Colourful
/// </summary>
public interface IColorVector
{
Vector<double> Vector { get; }
Vector Vector { get; }
}
}
7 changes: 3 additions & 4 deletions Colourful/Colors/LChabColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using System.Globalization;
using Vector = System.Collections.Generic.IReadOnlyList<double>;

namespace Colourful
{
Expand Down Expand Up @@ -87,9 +86,9 @@ public LChabColor(double l, double c, double h, XYZColor whitePoint)
/// <summary>
/// <see cref="IColorVector"/>
/// </summary>
public Vector<double> Vector
public Vector Vector
{
get { return DenseVector.OfEnumerable(new[] { L, C, h }); }
get { return new[] { L, C, h }; }
}

#endregion
Expand Down
7 changes: 3 additions & 4 deletions Colourful/Colors/LChuvColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using System.Globalization;
using Vector = System.Collections.Generic.IReadOnlyList<double>;

namespace Colourful
{
Expand Down Expand Up @@ -87,9 +86,9 @@ public LChuvColor(double l, double c, double h, XYZColor whitePoint)
/// <summary>
/// <see cref="IColorVector"/>
/// </summary>
public Vector<double> Vector
public Vector Vector
{
get { return DenseVector.OfEnumerable(new[] { L, C, h }); }
get { return new[] { L, C, h }; }
}

#endregion
Expand Down
7 changes: 3 additions & 4 deletions Colourful/Colors/LabColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using System.Globalization;
using Vector = System.Collections.Generic.IReadOnlyList<double>;

namespace Colourful
{
Expand Down Expand Up @@ -94,9 +93,9 @@ public LabColor(double l, double a, double b, XYZColor whitePoint)
/// <summary>
/// <see cref="IColorVector"/>
/// </summary>
public Vector<double> Vector
public Vector Vector
{
get { return DenseVector.OfEnumerable(new[] { L, a, b }); }
get { return new[] { L, a, b }; }
}

#endregion
Expand Down
7 changes: 3 additions & 4 deletions Colourful/Colors/LuvColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using System.Globalization;
using Vector = System.Collections.Generic.IReadOnlyList<double>;

namespace Colourful
{
Expand Down Expand Up @@ -88,9 +87,9 @@ public LuvColor(double l, double u, double v, XYZColor whitePoint)
/// <summary>
/// <see cref="IColorVector"/>
/// </summary>
public Vector<double> Vector
public Vector Vector
{
get { return DenseVector.OfEnumerable(new[] { L, u, v }); }
get { return new[] { L, u, v }; }
}

#endregion
Expand Down
7 changes: 3 additions & 4 deletions Colourful/Colors/RGBColorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
using System.Text;
using System.Threading.Tasks;
using Colourful.Implementation;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using Vector = System.Collections.Generic.IReadOnlyList<double>;

namespace Colourful
{
Expand Down Expand Up @@ -72,9 +71,9 @@ internal RGBColorBase(double r, double g, double b)
/// <summary>
/// <see cref="IColorVector"/>
/// </summary>
public Vector<double> Vector
public Vector Vector
{
get { return DenseVector.OfEnumerable(new[] { R, G, B }); }
get { return new[] { R, G, B }; }
}

#endregion
Expand Down
7 changes: 3 additions & 4 deletions Colourful/Colors/XYZColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using System.Globalization;
using Vector = System.Collections.Generic.IReadOnlyList<double>;

namespace Colourful
{
Expand Down Expand Up @@ -64,9 +63,9 @@ public XYZColor(double x, double y, double z)
/// <summary>
/// <see cref="IColorVector"/>
/// </summary>
public Vector<double> Vector
public Vector Vector
{
get { return DenseVector.OfEnumerable(new[] { X, Y, Z }); }
get { return new[] { X, Y, Z }; }
}

#endregion
Expand Down
7 changes: 3 additions & 4 deletions Colourful/Colors/xyYColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MathNet.Numerics.LinearAlgebra.Double;
using MathNet.Numerics.LinearAlgebra.Generic;
using System.Globalization;
using Vector = System.Collections.Generic.IReadOnlyList<double>;

namespace Colourful
{
Expand Down Expand Up @@ -86,9 +85,9 @@ public double y
/// <summary>
/// <see cref="IColorVector"/>
/// </summary>
public Vector<double> Vector
public Vector Vector
{
get { return DenseVector.OfEnumerable(new[] { x, y, Y }); }
get { return new[] { x, y, Y }; }
}

#endregion
Expand Down
9 changes: 3 additions & 6 deletions Colourful/Colourful.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="MathNet.Numerics, Version=2.6.1.30, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\MathNet.Numerics.2.6.2\lib\net40\MathNet.Numerics.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
Expand Down Expand Up @@ -95,17 +91,19 @@
<Compile Include="Difference\CIEDE2000ColorDifference.cs" />
<Compile Include="Difference\IColorDifference.cs" />
<Compile Include="Implementation\Conversion\xyY\xyYAndXYZConverter.cs" />
<Compile Include="Implementation\Extensions.cs" />
<Compile Include="Implementation\Utils\Extensions.cs" />
<Compile Include="Colors\IColorVector.cs" />
<Compile Include="Colors\Illuminants.cs" />
<Compile Include="Colors\RGBColor.cs" />
<Compile Include="Colors\XYZColor.cs" />
<Compile Include="Implementation\Conversion\IColorConversion.cs" />
<Compile Include="Implementation\Conversion\RGB\RGBToXYZConverter.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Implementation\Utils\Angle.cs" />
<Compile Include="Implementation\RGB\GammaCompanding.cs" />
<Compile Include="Implementation\RGB\Rec2020Companding.cs" />
<Compile Include="Implementation\RGB\Rec709Companding.cs" />
<Compile Include="Implementation\Utils\MatrixFactory.cs" />
<Compile Include="Other\CCTConverter.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Colors\RGBColorBase.cs" />
Expand All @@ -118,7 +116,6 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="CustomDictionary.xml" />
Expand Down
1 change: 1 addition & 0 deletions Colourful/Colourful.csproj.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Implementation_005CConversion_005CLuv/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Implementation_005CConversion_005CRGB/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Implementation_005CConversion_005CxyY/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Implementation_005CUtils/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=Other/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
3 changes: 2 additions & 1 deletion Colourful/Difference/CIE76ColorDifference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Colourful.Implementation;

namespace Colourful.Difference
{
Expand All @@ -33,7 +34,7 @@ public double ComputeDifference(LabColor x, LabColor y)
if (x.WhitePoint != y.WhitePoint)
throw new ArgumentException("Colors must have same white point to be compared.");

var distance = (x.Vector - y.Vector).Norm(2);
var distance = Extensions.EuclideanDistance(x.Vector, y.Vector);
return distance;
}
}
Expand Down
Loading

0 comments on commit fbc4d98

Please sign in to comment.