diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs index 75b77a0b2..12b7a5500 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs @@ -24,21 +24,19 @@ namespace ImageSharp /// /// The backing file for the property /// - private readonly List entries; + private List entries; /// /// ICC profile header /// - private readonly IccProfileHeader header; + private IccProfileHeader header; /// /// Initializes a new instance of the class. /// public IccProfile() + : this(null) { - this.data = null; - this.entries = new List(); - this.header = new IccProfileHeader(); } /// @@ -47,12 +45,7 @@ namespace ImageSharp /// The raw ICC profile data public IccProfile(byte[] data) { - Guard.NotNull(data, nameof(data)); - this.data = data; - IccReader reader = new IccReader(); - this.header = reader.ReadHeader(data); - this.entries = new List(reader.ReadTagData(data)); } /// @@ -60,7 +53,11 @@ namespace ImageSharp /// public IccProfileHeader Header { - get { return this.header; } + get + { + this.InitializeHeader(); + return this.header; + } } /// @@ -68,7 +65,11 @@ namespace ImageSharp /// public List Entries { - get { return this.entries; } + get + { + this.InitializeEntries(); + return this.entries; + } } #if !NETSTANDARD1_1 @@ -103,5 +104,39 @@ namespace ImageSharp } #endif + + private void InitializeHeader() + { + if (this.header != null) + { + return; + } + + if (this.data == null) + { + this.header = new IccProfileHeader(); + return; + } + + IccReader reader = new IccReader(); + this.header = reader.ReadHeader(this.data); + } + + private void InitializeEntries() + { + if (this.entries != null) + { + return; + } + + if (this.data == null) + { + this.entries = new List(); + return; + } + + IccReader reader = new IccReader(); + this.entries = new List(reader.ReadTagData(this.data)); + } } }