blob: f8f7b8e49c6ddd66d10ced4ee710c0eaef681768 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
using Matrix = System.Collections.Generic.IReadOnlyList<System.Collections.Generic.IReadOnlyList<double>>;
namespace Colourful.Implementation.Conversion
{
/// <summary>
/// Converts from <see cref="XYZColor" /> to <see cref="LMSColor" /> and back.
/// </summary>
public sealed class XYZAndLMSConverter : IColorConversion<XYZColor, LMSColor>, IColorConversion<LMSColor, XYZColor>
{
/// <summary>
/// Default transformation matrix used, when no other is set. (Bradford)
/// <see cref="LMSTransformationMatrix" />
/// </summary>
public static readonly Matrix DefaultTransformationMatrix = LMSTransformationMatrix.Bradford;
private Matrix _transformationMatrix;
private Matrix _transformationMatrixInverse;
/// <summary>
/// Constructs with <see cref="DefaultTransformationMatrix" />
/// </summary>
public XYZAndLMSConverter() : this(DefaultTransformationMatrix)
{
}
/// <param name="transformationMatrix">Definition of the cone response domain (see <see cref="LMSTransformationMatrix" />), if not set <see cref="DefaultTransformationMatrix" /> will be used.</param>
public XYZAndLMSConverter(Matrix transformationMatrix)
{
TransformationMatrix = transformationMatrix;
}
/// <summary>
/// Transformation matrix used for the conversion (definition of the cone response domain).
/// <see cref="LMSTransformationMatrix" />
/// </summary>
public Matrix TransformationMatrix
{
get => _transformationMatrix;
internal set
{
_transformationMatrix = value;
_transformationMatrixInverse = TransformationMatrix.Inverse();
}
}
/// <summary>
/// Converts from <see cref="LMSColor" /> to <see cref="XYZColor" />.
/// </summary>
public XYZColor Convert(in LMSColor input)
{
var outputVector = _transformationMatrixInverse.MultiplyBy(input.Vector);
var output = new XYZColor(outputVector);
return output;
}
/// <summary>
/// Converts from <see cref="XYZColor" /> to <see cref="LMSColor" />.
/// </summary>
public LMSColor Convert(in XYZColor input)
{
var outputVector = TransformationMatrix.MultiplyBy(input.Vector);
var output = new LMSColor(outputVector);
return output;
}
}
}
|