|
|
|
@ -8,15 +8,15 @@ using System.Numerics; |
|
|
|
namespace SixLabors.ImageSharp.Metadata.Profiles.Icc; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Provides methods to read ICC data types
|
|
|
|
/// Provides methods to read ICC data types.
|
|
|
|
/// </summary>
|
|
|
|
internal sealed partial class IccDataReader |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Reads a tag data entry
|
|
|
|
/// Reads a tag data entry.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="info">The table entry with reading information</param>
|
|
|
|
/// <returns>the tag data entry</returns>
|
|
|
|
/// <param name="info">The table entry with reading information.</param>
|
|
|
|
/// <returns>The tag data entry.</returns>
|
|
|
|
public IccTagDataEntry ReadTagDataEntry(IccTagTableEntry info) |
|
|
|
{ |
|
|
|
this.currentIndex = (int)info.Offset; |
|
|
|
@ -101,7 +101,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads the header of a <see cref="IccTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read signature</returns>
|
|
|
|
/// <returns>The read signature.</returns>
|
|
|
|
public IccTypeSignature ReadTagDataEntryHeader() |
|
|
|
{ |
|
|
|
IccTypeSignature type = (IccTypeSignature)this.ReadUInt32(); |
|
|
|
@ -112,7 +112,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads the header of a <see cref="IccTagDataEntry"/> and checks if it's the expected value
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="expected">expected value to check against</param>
|
|
|
|
/// <param name="expected">The expected value to check against.</param>
|
|
|
|
public void ReadCheckTagDataEntryHeader(IccTypeSignature expected) |
|
|
|
{ |
|
|
|
IccTypeSignature type = this.ReadTagDataEntryHeader(); |
|
|
|
@ -125,8 +125,8 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccTagDataEntry"/> with an unknown <see cref="IccTypeSignature"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccUnknownTagDataEntry ReadUnknownTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
int count = (int)size - 8; // 8 is the tag header size
|
|
|
|
@ -136,7 +136,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccChromaticityTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccChromaticityTagDataEntry ReadChromaticityTagDataEntry() |
|
|
|
{ |
|
|
|
ushort channelCount = this.ReadUInt16(); |
|
|
|
@ -150,7 +150,7 @@ internal sealed partial class IccDataReader |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// The type is not know, so the values need be read
|
|
|
|
// The type is not know, so the values need be read.
|
|
|
|
double[][] values = new double[channelCount][]; |
|
|
|
for (int i = 0; i < channelCount; i++) |
|
|
|
{ |
|
|
|
@ -164,7 +164,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccColorantOrderTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccColorantOrderTagDataEntry ReadColorantOrderTagDataEntry() |
|
|
|
{ |
|
|
|
uint colorantCount = this.ReadUInt32(); |
|
|
|
@ -175,7 +175,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccColorantTableTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccColorantTableTagDataEntry ReadColorantTableTagDataEntry() |
|
|
|
{ |
|
|
|
uint colorantCount = this.ReadUInt32(); |
|
|
|
@ -191,7 +191,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccCurveTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccCurveTagDataEntry ReadCurveTagDataEntry() |
|
|
|
{ |
|
|
|
uint pointCount = this.ReadUInt32(); |
|
|
|
@ -220,7 +220,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccDataTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
public IccDataTagDataEntry ReadDataTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
@ -238,16 +238,13 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccDateTimeTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
public IccDateTimeTagDataEntry ReadDateTimeTagDataEntry() |
|
|
|
{ |
|
|
|
return new IccDateTimeTagDataEntry(this.ReadDateTime()); |
|
|
|
} |
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccDateTimeTagDataEntry ReadDateTimeTagDataEntry() => new IccDateTimeTagDataEntry(this.ReadDateTime()); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccLut16TagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccLut16TagDataEntry ReadLut16TagDataEntry() |
|
|
|
{ |
|
|
|
byte inChCount = this.data[this.AddIndex(1)]; |
|
|
|
@ -285,7 +282,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccLut8TagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccLut8TagDataEntry ReadLut8TagDataEntry() |
|
|
|
{ |
|
|
|
byte inChCount = this.data[this.AddIndex(1)]; |
|
|
|
@ -320,7 +317,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccLutAToBTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccLutAToBTagDataEntry ReadLutAtoBTagDataEntry() |
|
|
|
{ |
|
|
|
int start = this.currentIndex - 8; // 8 is the tag header size
|
|
|
|
@ -379,7 +376,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccLutBToATagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccLutBToATagDataEntry ReadLutBtoATagDataEntry() |
|
|
|
{ |
|
|
|
int start = this.currentIndex - 8; // 8 is the tag header size
|
|
|
|
@ -438,21 +435,18 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccMeasurementTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
public IccMeasurementTagDataEntry ReadMeasurementTagDataEntry() |
|
|
|
{ |
|
|
|
return new IccMeasurementTagDataEntry( |
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccMeasurementTagDataEntry ReadMeasurementTagDataEntry() => new( |
|
|
|
observer: (IccStandardObserver)this.ReadUInt32(), |
|
|
|
xyzBacking: this.ReadXyzNumber(), |
|
|
|
geometry: (IccMeasurementGeometry)this.ReadUInt32(), |
|
|
|
flare: this.ReadUFix16(), |
|
|
|
illuminant: (IccStandardIlluminant)this.ReadUInt32()); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccMultiLocalizedUnicodeTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccMultiLocalizedUnicodeTagDataEntry ReadMultiLocalizedUnicodeTagDataEntry() |
|
|
|
{ |
|
|
|
int start = this.currentIndex - 8; // 8 is the tag header size
|
|
|
|
@ -517,7 +511,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccMultiProcessElementsTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccMultiProcessElementsTagDataEntry ReadMultiProcessElementsTagDataEntry() |
|
|
|
{ |
|
|
|
int start = this.currentIndex - 8; |
|
|
|
@ -545,7 +539,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccNamedColor2TagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccNamedColor2TagDataEntry ReadNamedColor2TagDataEntry() |
|
|
|
{ |
|
|
|
int vendorFlag = this.ReadInt32(); |
|
|
|
@ -567,15 +561,12 @@ internal sealed partial class IccDataReader |
|
|
|
/// Reads a <see cref="IccParametricCurveTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
public IccParametricCurveTagDataEntry ReadParametricCurveTagDataEntry() |
|
|
|
{ |
|
|
|
return new IccParametricCurveTagDataEntry(this.ReadParametricCurve()); |
|
|
|
} |
|
|
|
public IccParametricCurveTagDataEntry ReadParametricCurveTagDataEntry() => new(this.ReadParametricCurve()); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccProfileSequenceDescTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccProfileSequenceDescTagDataEntry ReadProfileSequenceDescTagDataEntry() |
|
|
|
{ |
|
|
|
uint count = this.ReadUInt32(); |
|
|
|
@ -591,7 +582,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccProfileSequenceIdentifierTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccProfileSequenceIdentifierTagDataEntry ReadProfileSequenceIdentifierTagDataEntry() |
|
|
|
{ |
|
|
|
int start = this.currentIndex - 8; // 8 is the tag header size
|
|
|
|
@ -618,7 +609,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccResponseCurveSet16TagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccResponseCurveSet16TagDataEntry ReadResponseCurveSet16TagDataEntry() |
|
|
|
{ |
|
|
|
int start = this.currentIndex - 8; // 8 is the tag header size
|
|
|
|
@ -644,8 +635,8 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccFix16ArrayTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccFix16ArrayTagDataEntry ReadFix16ArrayTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
uint count = (size - 8) / 4; |
|
|
|
@ -661,27 +652,21 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccSignatureTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
public IccSignatureTagDataEntry ReadSignatureTagDataEntry() |
|
|
|
{ |
|
|
|
return new IccSignatureTagDataEntry(this.ReadAsciiString(4)); |
|
|
|
} |
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccSignatureTagDataEntry ReadSignatureTagDataEntry() => new(this.ReadAsciiString(4)); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccTextTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
public IccTextTagDataEntry ReadTextTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
return new IccTextTagDataEntry(this.ReadAsciiString((int)size - 8)); // 8 is the tag header size
|
|
|
|
} |
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccTextTagDataEntry ReadTextTagDataEntry(uint size) => new(this.ReadAsciiString((int)size - 8)); // 8 is the tag header size
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccUFix16ArrayTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccUFix16ArrayTagDataEntry ReadUFix16ArrayTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
uint count = (size - 8) / 4; |
|
|
|
@ -697,8 +682,8 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccUInt16ArrayTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccUInt16ArrayTagDataEntry ReadUInt16ArrayTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
uint count = (size - 8) / 2; |
|
|
|
@ -714,8 +699,8 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccUInt32ArrayTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccUInt32ArrayTagDataEntry ReadUInt32ArrayTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
uint count = (size - 8) / 4; |
|
|
|
@ -731,8 +716,8 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccUInt64ArrayTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccUInt64ArrayTagDataEntry ReadUInt64ArrayTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
uint count = (size - 8) / 8; |
|
|
|
@ -748,8 +733,8 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccUInt8ArrayTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccUInt8ArrayTagDataEntry ReadUInt8ArrayTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
int count = (int)size - 8; // 8 is the tag header size
|
|
|
|
@ -761,20 +746,17 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccViewingConditionsTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
public IccViewingConditionsTagDataEntry ReadViewingConditionsTagDataEntry() |
|
|
|
{ |
|
|
|
return new IccViewingConditionsTagDataEntry( |
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccViewingConditionsTagDataEntry ReadViewingConditionsTagDataEntry() => new( |
|
|
|
illuminantXyz: this.ReadXyzNumber(), |
|
|
|
surroundXyz: this.ReadXyzNumber(), |
|
|
|
illuminant: (IccStandardIlluminant)this.ReadUInt32()); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccXyzTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccXyzTagDataEntry ReadXyzTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
uint count = (size - 8) / 12; |
|
|
|
@ -790,7 +772,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccTextDescriptionTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccTextDescriptionTagDataEntry ReadTextDescriptionTagDataEntry() |
|
|
|
{ |
|
|
|
string unicodeValue, scriptcodeValue; |
|
|
|
@ -830,7 +812,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccTextDescriptionTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccCrdInfoTagDataEntry ReadCrdInfoTagDataEntry() |
|
|
|
{ |
|
|
|
uint productNameCount = this.ReadUInt32(); |
|
|
|
@ -854,7 +836,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccScreeningTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
/// <returns>The read entry.</returns>
|
|
|
|
public IccScreeningTagDataEntry ReadScreeningTagDataEntry() |
|
|
|
{ |
|
|
|
var flags = (IccScreeningFlag)this.ReadInt32(); |
|
|
|
@ -871,7 +853,7 @@ internal sealed partial class IccDataReader |
|
|
|
/// <summary>
|
|
|
|
/// Reads a <see cref="IccUcrBgTagDataEntry"/>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="size">The size of the entry in bytes</param>
|
|
|
|
/// <param name="size">The size of the entry in bytes.</param>
|
|
|
|
/// <returns>The read entry</returns>
|
|
|
|
public IccUcrBgTagDataEntry ReadUcrBgTagDataEntry(uint size) |
|
|
|
{ |
|
|
|
|