Browse Source

Update IccProfile Entries to Array

pull/747/head
Jason Nelson 7 years ago
parent
commit
2293494a77
  1. 11
      src/ImageSharp/MetaData/Profiles/ICC/IccProfile.cs
  2. 4
      src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs
  3. 4
      tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccReaderTests.cs

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

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
@ -20,7 +21,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// The backing file for the <see cref="Entries"/> property
/// </summary>
private List<IccTagDataEntry> entries;
private IccTagDataEntry[] entries;
/// <summary>
/// ICC profile header
@ -52,7 +53,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
Guard.NotNull(entries, nameof(entries));
this.header = header;
this.entries = new List<IccTagDataEntry>(entries);
this.entries = entries.ToArray();
}
/// <summary>
@ -85,7 +86,7 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
/// <summary>
/// Gets the actual profile data
/// </summary>
public List<IccTagDataEntry> Entries
public IccTagDataEntry[] Entries
{
get
{
@ -212,12 +213,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
if (this.data is null)
{
this.entries = new List<IccTagDataEntry>();
this.entries = Array.Empty<IccTagDataEntry>();
return;
}
var reader = new IccReader();
this.entries = new List<IccTagDataEntry>(reader.ReadTagData(this.data));
this.entries = reader.ReadTagData(this.data);
}
}
}

4
src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs

@ -68,12 +68,12 @@ namespace SixLabors.ImageSharp.MetaData.Profiles.Icc
}
}
private IccTagTableEntry[] WriteTagData(IccDataWriter writer, List<IccTagDataEntry> entries)
private IccTagTableEntry[] WriteTagData(IccDataWriter writer, IccTagDataEntry[] entries)
{
IEnumerable<IGrouping<IccTagDataEntry, IccTagDataEntry>> grouped = entries.GroupBy(t => t);
// (Header size) + (entry count) + (nr of entries) * (size of table entry)
writer.SetIndex(128 + 4 + (entries.Count * 12));
writer.SetIndex(128 + 4 + (entries.Length * 12));
var table = new List<IccTagTableEntry>();
foreach (IGrouping<IccTagDataEntry, IccTagDataEntry> group in grouped)

4
tests/ImageSharp.Tests/MetaData/Profiles/ICC/IccReaderTests.cs

@ -15,7 +15,7 @@ namespace SixLabors.ImageSharp.Tests.Icc
IccProfile output = reader.Read(IccTestDataProfiles.Header_Random_Array);
Assert.Equal(0, output.Entries.Count);
Assert.Equal(0, output.Entries.Length);
Assert.NotNull(output.Header);
IccProfileHeader header = output.Header;
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Tests.Icc
IccProfile output = reader.Read(IccTestDataProfiles.Profile_Random_Array);
Assert.Equal(2, output.Entries.Count);
Assert.Equal(2, output.Entries.Length);
Assert.True(ReferenceEquals(output.Entries[0], output.Entries[1]));
}

Loading…
Cancel
Save