diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs index 8f0b35727..5080b2313 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut16TagDataEntry.cs @@ -15,6 +15,8 @@ namespace ImageSharp /// internal sealed class IccLut16TagDataEntry : IccTagDataEntry, IEquatable { + private static readonly float[,] IdentityMatrix = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }; + /// /// Initializes a new instance of the class. /// @@ -22,7 +24,7 @@ namespace ImageSharp /// CLUT /// Output LUT public IccLut16TagDataEntry(IccLut[] inputValues, IccClut clutValues, IccLut[] outputValues) - : this(null, inputValues, clutValues, outputValues, IccProfileTag.Unknown) + : this(IdentityMatrix, inputValues, clutValues, outputValues, IccProfileTag.Unknown) { } @@ -34,7 +36,7 @@ namespace ImageSharp /// Output LUT /// Tag Signature public IccLut16TagDataEntry(IccLut[] inputValues, IccClut clutValues, IccLut[] outputValues, IccProfileTag tagSignature) - : this(null, inputValues, clutValues, outputValues, tagSignature) + : this(IdentityMatrix, inputValues, clutValues, outputValues, tagSignature) { } @@ -69,13 +71,13 @@ namespace ImageSharp bool is3By3 = matrix.GetLength(0) == 3 && matrix.GetLength(1) == 3; Guard.IsTrue(is3By3, nameof(matrix), "Matrix must have a size of three by three"); - Guard.IsTrue(this.InputChannelCount == clutValues.InputChannelCount, nameof(clutValues), "Input channel count does not match the CLUT size"); - Guard.IsTrue(this.OutputChannelCount == clutValues.OutputChannelCount, nameof(clutValues), "Output channel count does not match the CLUT size"); - this.Matrix = this.CreateMatrix(matrix); this.InputValues = inputValues; this.ClutValues = clutValues; this.OutputValues = outputValues; + + Guard.IsTrue(this.InputChannelCount == clutValues.InputChannelCount, nameof(clutValues), "Input channel count does not match the CLUT size"); + Guard.IsTrue(this.OutputChannelCount == clutValues.OutputChannelCount, nameof(clutValues), "Output channel count does not match the CLUT size"); } /// diff --git a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs index 91e23223d..b560c52ac 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/TagDataEntries/IccLut8TagDataEntry.cs @@ -15,6 +15,8 @@ namespace ImageSharp /// internal sealed class IccLut8TagDataEntry : IccTagDataEntry, IEquatable { + private static readonly float[,] IdentityMatrix = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } }; + /// /// Initializes a new instance of the class. /// @@ -22,7 +24,7 @@ namespace ImageSharp /// CLUT /// Output LUT public IccLut8TagDataEntry(IccLut[] inputValues, IccClut clutValues, IccLut[] outputValues) - : this(null, inputValues, clutValues, outputValues, IccProfileTag.Unknown) + : this(IdentityMatrix, inputValues, clutValues, outputValues, IccProfileTag.Unknown) { } @@ -34,7 +36,7 @@ namespace ImageSharp /// Output LUT /// Tag Signature public IccLut8TagDataEntry(IccLut[] inputValues, IccClut clutValues, IccLut[] outputValues, IccProfileTag tagSignature) - : this(null, inputValues, clutValues, outputValues, tagSignature) + : this(IdentityMatrix, inputValues, clutValues, outputValues, tagSignature) { } @@ -69,16 +71,16 @@ namespace ImageSharp bool is3By3 = matrix.GetLength(0) == 3 && matrix.GetLength(1) == 3; Guard.IsTrue(is3By3, nameof(matrix), "Matrix must have a size of three by three"); + this.Matrix = this.CreateMatrix(matrix); + this.InputValues = inputValues; + this.ClutValues = clutValues; + this.OutputValues = outputValues; + Guard.IsTrue(this.InputChannelCount == clutValues.InputChannelCount, nameof(clutValues), "Input channel count does not match the CLUT size"); Guard.IsTrue(this.OutputChannelCount == clutValues.OutputChannelCount, nameof(clutValues), "Output channel count does not match the CLUT size"); Guard.IsFalse(inputValues.Any(t => t.Values.Length != 256), nameof(inputValues), "Input lookup table has to have a length of 256"); Guard.IsFalse(outputValues.Any(t => t.Values.Length != 256), nameof(outputValues), "Output lookup table has to have a length of 256"); - - this.Matrix = this.CreateMatrix(matrix); - this.InputValues = inputValues; - this.ClutValues = clutValues; - this.OutputValues = outputValues; } ///