Browse Source

lazy load ICC profile

af/merge-core
Johannes Bildstein 9 years ago
parent
commit
bb8ceb7d25
  1. 59
      src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs

59
src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs

@ -24,21 +24,19 @@ namespace ImageSharp
/// <summary> /// <summary>
/// The backing file for the <see cref="Entries"/> property /// The backing file for the <see cref="Entries"/> property
/// </summary> /// </summary>
private readonly List<IccTagDataEntry> entries; private List<IccTagDataEntry> entries;
/// <summary> /// <summary>
/// ICC profile header /// ICC profile header
/// </summary> /// </summary>
private readonly IccProfileHeader header; private IccProfileHeader header;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="IccProfile"/> class. /// Initializes a new instance of the <see cref="IccProfile"/> class.
/// </summary> /// </summary>
public IccProfile() public IccProfile()
: this(null)
{ {
this.data = null;
this.entries = new List<IccTagDataEntry>();
this.header = new IccProfileHeader();
} }
/// <summary> /// <summary>
@ -47,12 +45,7 @@ namespace ImageSharp
/// <param name="data">The raw ICC profile data</param> /// <param name="data">The raw ICC profile data</param>
public IccProfile(byte[] data) public IccProfile(byte[] data)
{ {
Guard.NotNull(data, nameof(data));
this.data = data; this.data = data;
IccReader reader = new IccReader();
this.header = reader.ReadHeader(data);
this.entries = new List<IccTagDataEntry>(reader.ReadTagData(data));
} }
/// <summary> /// <summary>
@ -60,7 +53,11 @@ namespace ImageSharp
/// </summary> /// </summary>
public IccProfileHeader Header public IccProfileHeader Header
{ {
get { return this.header; } get
{
this.InitializeHeader();
return this.header;
}
} }
/// <summary> /// <summary>
@ -68,7 +65,11 @@ namespace ImageSharp
/// </summary> /// </summary>
public List<IccTagDataEntry> Entries public List<IccTagDataEntry> Entries
{ {
get { return this.entries; } get
{
this.InitializeEntries();
return this.entries;
}
} }
#if !NETSTANDARD1_1 #if !NETSTANDARD1_1
@ -103,5 +104,39 @@ namespace ImageSharp
} }
#endif #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<IccTagDataEntry>();
return;
}
IccReader reader = new IccReader();
this.entries = new List<IccTagDataEntry>(reader.ReadTagData(this.data));
}
} }
} }

Loading…
Cancel
Save