IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
ColorCorrectionMatrix.cs
Go to the documentation of this file.
3
5
32public sealed class ColorCorrectionMatrix : Matrix<float>, ISerializable
33{
34 private const int _numberOfRows = 3;
35 private const int _numberOfColumns = 3;
36 private readonly string _name = "Matrix";
37
47 public ColorCorrectionMatrix(string name, float[,] data) : this(data)
48 {
49 _name = name;
50 }
51
58 public ColorCorrectionMatrix(float[,] data) : base(_numberOfRows, _numberOfColumns, data)
59 {
60 }
61
68 public ColorCorrectionMatrix(float[] data) : base(_numberOfRows, _numberOfColumns, data)
69 {
70 }
71
72 internal ColorCorrectionMatrix(Backend.Types.peak_icv_color_correction_matrix matrix) : this(new[,]
73 {
74 { matrix.m_00, matrix.m_01, matrix.m_02 },
75 { matrix.m_10, matrix.m_11, matrix.m_12 },
76 { matrix.m_20, matrix.m_21, matrix.m_22 }
77 })
78 {
79 }
80
85 public new static IEqualityComparer<ColorCorrectionMatrix> Comparer { get; } = new MatrixEqualityComparer();
86
98 public void Serialize(IArchive archive)
99 {
100 archive.SetDoubleArray(_name, Flatten().Select(x => (double) x).ToArray());
101 }
102
114 public void Deserialize(IArchive archive)
115 {
116 IReadOnlyList<double> values = archive.GetDoubleArray(_name);
117
118 if (values.Count != Rows * Columns)
119 {
120 throw new IcvCorruptedException(
121 $"ColorCorrectionMatrix requires exactly 9 elements, but {values.Count} values were given.");
122 }
123
124 Values = To2DArray(values.Select(x => (float) x).ToArray(), Rows, Columns);
125 }
126
137 public static ColorCorrectionMatrix Diagonal(float value)
138 {
139 var data = new float[9];
140 for (var i = 0; i < _numberOfRows; i++)
141 {
142 data[i * _numberOfRows + i] = value;
143 }
144
145 return new ColorCorrectionMatrix(data);
146 }
147
156 {
157 return Diagonal(1);
158 }
159
161 {
163 {
164 m_00 = this[0, 0],
165 m_01 = this[0, 1],
166 m_02 = this[0, 2],
167 m_10 = this[1, 0],
168 m_11 = this[1, 1],
169 m_12 = this[1, 2],
170 m_20 = this[2, 0],
171 m_21 = this[2, 1],
172 m_22 = this[2, 2]
173 };
174 }
175}
Occurs when reading from a file or stream that is incomplete, damaged, or in an unexpected format.
Definition Exception.cs:75
void Serialize(IArchive archive)
Serializes the object's internal state into the provided archive.
ColorCorrectionMatrix(string name, float[,] data)
Creates an instance of class ColorCorrectionMatrix.
ColorCorrectionMatrix(float[] data)
Creates an instance of class ColorCorrectionMatrix with data .
ColorCorrectionMatrix(float[,] data)
Creates an instance of class ColorCorrectionMatrix with data .
static ColorCorrectionMatrix Identity()
Constructs a uniform identity matrix.
void Deserialize(IArchive archive)
Restores the object's state from the provided archive.
static ColorCorrectionMatrix Diagonal(float value)
Constructs a uniform diagonal matrix.
static new IEqualityComparer< ColorCorrectionMatrix > Comparer
Gets a default equality comparer for comparing ColorCorrectionMatrix data values.
Represents a generic 2D matrix of elements with a specified number of rows and columns.
Definition Matrix.cs:19
Represents a hierarchical, strongly-typed key-value archive.
Definition IArchive.cs:79
IReadOnlyList< double > GetDoubleArray(string key)
Retrieves an array of double-precision floating-point values by key.
void SetDoubleArray(string key, IEnumerable< double > value)
Stores an array of double-precision floating-point values under the specified key.
Interface for objects that can be serialized to and deserialized from an archive.