blob: b32b018d150400cbb53ef1549490513e06546c7b (
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
using Colourful.Implementation.Conversion;
using Matrix = System.Collections.Generic.IReadOnlyList<System.Collections.Generic.IReadOnlyList<double>>;
namespace Colourful.Conversion
{
/// <summary>
/// Converts between color spaces and makes sure that the color is adapted using chromatic adaptation.
/// </summary>
public partial class ColourfulConverter
{
/// <summary>
/// Constructs the converter and sets the defaults
/// </summary>
public ColourfulConverter()
{
WhitePoint = DefaultWhitePoint;
LMSTransformationMatrix = XYZAndLMSConverter.DefaultTransformationMatrix;
ChromaticAdaptation = new VonKriesChromaticAdaptation(_cachedXYZAndLMSConverter, _cachedXYZAndLMSConverter);
TargetLabWhitePoint = LabColor.DefaultWhitePoint;
TargetHunterLabWhitePoint = HunterLabColor.DefaultWhitePoint;
TargetLuvWhitePoint = LuvColor.DefaultWhitePoint;
TargetRGBWorkingSpace = RGBColor.DefaultWorkingSpace;
}
private bool IsChromaticAdaptationPerformed => ChromaticAdaptation != null;
#region Attributes
/// <summary>
/// Default white point
/// </summary>
public static readonly XYZColor DefaultWhitePoint = Illuminants.D65;
private Matrix _transformationMatrix;
/// <summary>
/// Chromatic adaptation method used. When null, no adaptation will be performed.
/// </summary>
public IChromaticAdaptation ChromaticAdaptation { get; set; }
/// <summary>
/// Transformation matrix used in conversion to <see cref="LMSColor" />, also used in the default Von Kries Chromatic Adaptation method.
/// </summary>
public Matrix LMSTransformationMatrix
{
get => _transformationMatrix;
set
{
_transformationMatrix = value;
if (_cachedXYZAndLMSConverter == null)
{
_cachedXYZAndLMSConverter = new XYZAndLMSConverter(value);
}
else
{
_cachedXYZAndLMSConverter.TransformationMatrix = value;
}
}
}
private XYZAndLMSConverter _cachedXYZAndLMSConverter;
/// <summary>
/// White point used for chromatic adaptation in conversions from/to XYZ color space.
/// When null, no adaptation will be performed.
/// <seealso cref="TargetLabWhitePoint" />
/// </summary>
public XYZColor WhitePoint { get; set; }
/// <summary>
/// White point used *when creating* Lab/LChab colors. (Lab/LChab colors on the input already contain the white point information)
/// Defaults to: <see cref="LabColor.DefaultWhitePoint" />.
/// </summary>
public XYZColor TargetLabWhitePoint { get; set; }
/// <summary>
/// White point used *when creating* Luv/LChuv colors. (Luv/LChuv colors on the input already contain the white point information)
/// Defaults to: <see cref="LuvColor.DefaultWhitePoint" />.
/// </summary>
public XYZColor TargetLuvWhitePoint { get; set; }
/// <summary>
/// White point used *when creating* HunterLab colors. (HunterLab colors on the input already contain the white point information)
/// Defaults to: <see cref="HunterLabColor.DefaultWhitePoint" />.
/// </summary>
public XYZColor TargetHunterLabWhitePoint { get; set; }
/// <summary>
/// Working space used *when creating* RGB colors. (RGB colors on the input already contain the working space information)
/// Defaults to: <see cref="RGBColor.DefaultWorkingSpace" />.
/// </summary>
public IRGBWorkingSpace TargetRGBWorkingSpace { get; set; }
#endregion
}
}
|