Browse Source

Clean up code a little

pull/144/head
James Jackson-South 9 years ago
parent
commit
450ad2eb22
  1. 10
      src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs
  2. 37
      src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs
  3. 6
      src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs
  4. 80
      src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs
  5. 27
      src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs
  6. 26
      src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs
  7. 8
      src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs
  8. 2
      src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs
  9. 24
      src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs
  10. 8
      src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs
  11. 7
      src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs
  12. 6
      src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs
  13. 10
      src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs
  14. 8
      src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs
  15. 4
      tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntryTests.cs
  16. 4
      tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntryTests.cs

10
src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs

@ -42,7 +42,7 @@ namespace ImageSharp
/// <returns>The read curve</returns>
public IccResponseCurve ReadResponseCurve(int channelCount)
{
IccCurveMeasurementEncodings type = (IccCurveMeasurementEncodings)this.ReadUInt32();
var type = (IccCurveMeasurementEncodings)this.ReadUInt32();
uint[] measurment = new uint[channelCount];
for (int i = 0; i < channelCount; i++)
{
@ -79,7 +79,7 @@ namespace ImageSharp
float gamma, a, b, c, d, e, f;
gamma = a = b = c = d = e = f = 0;
if (type >= 0 && type <= 4)
if (type <= 4)
{
gamma = this.ReadFix16();
}
@ -123,7 +123,7 @@ namespace ImageSharp
/// <returns>The read segment</returns>
public IccCurveSegment ReadCurveSegment()
{
IccCurveSegmentSignature signature = (IccCurveSegmentSignature)this.ReadUInt32();
var signature = (IccCurveSegmentSignature)this.ReadUInt32();
this.AddIndex(4); // 4 bytes reserved
switch (signature)
@ -143,10 +143,10 @@ namespace ImageSharp
/// <returns>The read segment</returns>
public IccFormulaCurveElement ReadFormulaCurveElement()
{
IccFormulaCurveType type = (IccFormulaCurveType)this.ReadUInt16();
var type = (IccFormulaCurveType)this.ReadUInt16();
this.AddIndex(2); // 2 bytes reserved
float gamma, a, b, c, d, e;
gamma = a = b = c = d = e = 0;
gamma = d = e = 0;
if (type == IccFormulaCurveType.Type1 || type == IccFormulaCurveType.Type2)
{

37
src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs

@ -58,19 +58,16 @@ namespace ImageSharp
{
return this.ReadClut8(inChannelCount, outChannelCount, gridPointCount);
}
else if (size == 2)
if (size == 2)
{
return this.ReadClut16(inChannelCount, outChannelCount, gridPointCount);
}
else
{
throw new InvalidIccProfileException($"Invalid CLUT size of {size}");
}
}
else
{
return this.ReadClutF32(inChannelCount, outChannelCount, gridPointCount);
throw new InvalidIccProfileException($"Invalid CLUT size of {size}");
}
return this.ReadClutF32(inChannelCount, outChannelCount, gridPointCount);
}
/// <summary>
@ -82,7 +79,7 @@ namespace ImageSharp
/// <returns>The read CLUT8</returns>
public IccClut ReadClut8(int inChannelCount, int outChannelCount, byte[] gridPointCount)
{
int start = this.index;
int start = this.currentIndex;
int length = 0;
for (int i = 0; i < inChannelCount; i++)
{
@ -91,7 +88,7 @@ namespace ImageSharp
length /= inChannelCount;
const float max = byte.MaxValue;
const float Max = byte.MaxValue;
float[][] values = new float[length][];
for (int i = 0; i < length; i++)
@ -99,11 +96,11 @@ namespace ImageSharp
values[i] = new float[outChannelCount];
for (int j = 0; j < outChannelCount; j++)
{
values[i][j] = this.data[this.index++] / max;
values[i][j] = this.data[this.currentIndex++] / Max;
}
}
this.index = start + (length * outChannelCount);
this.currentIndex = start + (length * outChannelCount);
return new IccClut(values, gridPointCount, IccClutDataType.UInt8);
}
@ -116,7 +113,7 @@ namespace ImageSharp
/// <returns>The read CLUT16</returns>
public IccClut ReadClut16(int inChannelCount, int outChannelCount, byte[] gridPointCount)
{
int start = this.index;
int start = this.currentIndex;
int length = 0;
for (int i = 0; i < inChannelCount; i++)
{
@ -125,7 +122,7 @@ namespace ImageSharp
length /= inChannelCount;
const float max = ushort.MaxValue;
const float Max = ushort.MaxValue;
float[][] values = new float[length][];
for (int i = 0; i < length; i++)
@ -133,11 +130,11 @@ namespace ImageSharp
values[i] = new float[outChannelCount];
for (int j = 0; j < outChannelCount; j++)
{
values[i][j] = this.ReadUInt16() / max;
values[i][j] = this.ReadUInt16() / Max;
}
}
this.index = start + (length * outChannelCount * 2);
this.currentIndex = start + (length * outChannelCount * 2);
return new IccClut(values, gridPointCount, IccClutDataType.UInt16);
}
@ -150,7 +147,7 @@ namespace ImageSharp
/// <returns>The read CLUTf32</returns>
public IccClut ReadClutF32(int inChCount, int outChCount, byte[] gridPointCount)
{
int start = this.index;
int start = this.currentIndex;
int length = 0;
for (int i = 0; i < inChCount; i++)
{
@ -169,8 +166,8 @@ namespace ImageSharp
}
}
this.index = start + (length * outChCount * 4);
this.currentIndex = start + (length * outChCount * 4);
return new IccClut(values, gridPointCount, IccClutDataType.Float);
}
}
}
}

6
src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs

@ -106,7 +106,7 @@ namespace ImageSharp
public IccNamedColor ReadNamedColor(uint deviceCoordCount)
{
string name = this.ReadAsciiString(32);
ushort[] pcsCoord = new ushort[3] { this.ReadUInt16(), this.ReadUInt16(), this.ReadUInt16() };
ushort[] pcsCoord = { this.ReadUInt16(), this.ReadUInt16(), this.ReadUInt16() };
ushort[] deviceCoord = new ushort[deviceCoordCount];
for (int i = 0; i < deviceCoordCount; i++)
@ -125,8 +125,8 @@ namespace ImageSharp
{
uint manufacturer = this.ReadUInt32();
uint model = this.ReadUInt32();
IccDeviceAttribute attributes = (IccDeviceAttribute)this.ReadInt64();
IccProfileTag technologyInfo = (IccProfileTag)this.ReadUInt32();
var attributes = (IccDeviceAttribute)this.ReadInt64();
var technologyInfo = (IccProfileTag)this.ReadUInt32();
IccMultiLocalizedUnicodeTagDataEntry manufacturerInfo = ReadText();
IccMultiLocalizedUnicodeTagDataEntry modelInfo = ReadText();

80
src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs

@ -21,7 +21,7 @@ namespace ImageSharp
/// <returns>the tag data entry</returns>
public IccTagDataEntry ReadTagDataEntry(IccTagTableEntry info)
{
this.index = (int)info.Offset;
this.currentIndex = (int)info.Offset;
IccTypeSignature type = this.ReadTagDataEntryHeader();
switch (type)
@ -43,9 +43,9 @@ namespace ImageSharp
case IccTypeSignature.Lut8:
return this.ReadLut8TagDataEntry();
case IccTypeSignature.LutAToB:
return this.ReadLutAToBTagDataEntry();
return this.ReadLutAtoBTagDataEntry();
case IccTypeSignature.LutBToA:
return this.ReadLutBToATagDataEntry();
return this.ReadLutBtoATagDataEntry();
case IccTypeSignature.Measurement:
return this.ReadMeasurementTagDataEntry();
case IccTypeSignature.MultiLocalizedUnicode:
@ -108,7 +108,7 @@ namespace ImageSharp
/// <returns>The read signature</returns>
public IccTypeSignature ReadTagDataEntryHeader()
{
IccTypeSignature type = (IccTypeSignature)this.ReadUInt32();
var type = (IccTypeSignature)this.ReadUInt32();
this.AddIndex(4); // 4 bytes are not used
return type;
}
@ -144,7 +144,7 @@ namespace ImageSharp
public IccChromaticityTagDataEntry ReadChromaticityTagDataEntry()
{
ushort channelCount = this.ReadUInt16();
IccColorantEncoding colorant = (IccColorantEncoding)this.ReadUInt16();
var colorant = (IccColorantEncoding)this.ReadUInt16();
if (Enum.IsDefined(typeof(IccColorantEncoding), colorant) && colorant != IccColorantEncoding.Unknown)
{
@ -206,21 +206,20 @@ namespace ImageSharp
{
return new IccCurveTagDataEntry();
}
else if (pointCount == 1)
if (pointCount == 1)
{
return new IccCurveTagDataEntry(this.ReadUFix8());
}
else
{
float[] cdata = new float[pointCount];
for (int i = 0; i < pointCount; i++)
{
cdata[i] = this.ReadUInt16() / 65535f;
}
return new IccCurveTagDataEntry(cdata);
float[] cdata = new float[pointCount];
for (int i = 0; i < pointCount; i++)
{
cdata[i] = this.ReadUInt16() / 65535f;
}
return new IccCurveTagDataEntry(cdata);
// TODO: If the input is PCSXYZ, 1+(32 767/32 768) shall be mapped to the value 1,0. If the output is PCSXYZ, the value 1,0 shall be mapped to 1+(32 767/32 768).
}
@ -328,9 +327,9 @@ namespace ImageSharp
/// Reads a <see cref="IccLutAToBTagDataEntry"/>
/// </summary>
/// <returns>The read entry</returns>
public IccLutAToBTagDataEntry ReadLutAToBTagDataEntry()
public IccLutAToBTagDataEntry ReadLutAtoBTagDataEntry()
{
int start = this.index - 8; // 8 is the tag header size
int start = this.currentIndex - 8; // 8 is the tag header size
byte inChCount = this.data[this.AddIndex(1)];
byte outChCount = this.data[this.AddIndex(1)];
@ -351,31 +350,31 @@ namespace ImageSharp
if (bCurveOffset != 0)
{
this.index = (int)bCurveOffset + start;
this.currentIndex = (int)bCurveOffset + start;
bCurve = this.ReadCurves(outChCount);
}
if (mCurveOffset != 0)
{
this.index = (int)mCurveOffset + start;
this.currentIndex = (int)mCurveOffset + start;
mCurve = this.ReadCurves(outChCount);
}
if (aCurveOffset != 0)
{
this.index = (int)aCurveOffset + start;
this.currentIndex = (int)aCurveOffset + start;
aCurve = this.ReadCurves(inChCount);
}
if (clutOffset != 0)
{
this.index = (int)clutOffset + start;
this.currentIndex = (int)clutOffset + start;
clut = this.ReadClut(inChCount, outChCount, false);
}
if (matrixOffset != 0)
{
this.index = (int)matrixOffset + start;
this.currentIndex = (int)matrixOffset + start;
matrix3x3 = this.ReadMatrix(3, 3, false);
matrix3x1 = this.ReadMatrix(3, false);
}
@ -387,9 +386,9 @@ namespace ImageSharp
/// Reads a <see cref="IccLutBToATagDataEntry"/>
/// </summary>
/// <returns>The read entry</returns>
public IccLutBToATagDataEntry ReadLutBToATagDataEntry()
public IccLutBToATagDataEntry ReadLutBtoATagDataEntry()
{
int start = this.index - 8; // 8 is the tag header size
int start = this.currentIndex - 8; // 8 is the tag header size
byte inChCount = this.data[this.AddIndex(1)];
byte outChCount = this.data[this.AddIndex(1)];
@ -410,31 +409,31 @@ namespace ImageSharp
if (bCurveOffset != 0)
{
this.index = (int)bCurveOffset + start;
this.currentIndex = (int)bCurveOffset + start;
bCurve = this.ReadCurves(inChCount);
}
if (mCurveOffset != 0)
{
this.index = (int)mCurveOffset + start;
this.currentIndex = (int)mCurveOffset + start;
mCurve = this.ReadCurves(inChCount);
}
if (aCurveOffset != 0)
{
this.index = (int)aCurveOffset + start;
this.currentIndex = (int)aCurveOffset + start;
aCurve = this.ReadCurves(outChCount);
}
if (clutOffset != 0)
{
this.index = (int)clutOffset + start;
this.currentIndex = (int)clutOffset + start;
clut = this.ReadClut(inChCount, outChCount, false);
}
if (matrixOffset != 0)
{
this.index = (int)matrixOffset + start;
this.currentIndex = (int)matrixOffset + start;
matrix3x3 = this.ReadMatrix(3, 3, false);
matrix3x1 = this.ReadMatrix(3, false);
}
@ -462,8 +461,10 @@ namespace ImageSharp
/// <returns>The read entry</returns>
public IccMultiLocalizedUnicodeTagDataEntry ReadMultiLocalizedUnicodeTagDataEntry()
{
int start = this.index - 8; // 8 is the tag header size
int start = this.currentIndex - 8; // 8 is the tag header size
uint recordCount = this.ReadUInt32();
// TODO: Why are we storing variable
uint recordSize = this.ReadUInt32();
IccLocalizedString[] text = new IccLocalizedString[recordCount];
@ -480,7 +481,7 @@ namespace ImageSharp
for (int i = 0; i < recordCount; i++)
{
this.index = (int)(start + offset[i]);
this.currentIndex = (int)(start + offset[i]);
text[i] = new IccLocalizedString(new CultureInfo(culture[i]), this.ReadUnicodeString((int)length[i]));
}
@ -493,8 +494,9 @@ namespace ImageSharp
/// <returns>The read entry</returns>
public IccMultiProcessElementsTagDataEntry ReadMultiProcessElementsTagDataEntry()
{
int start = this.index - 8;
int start = this.currentIndex - 8;
// TODO: Why are we storing variable
ushort inChannelCount = this.ReadUInt16();
ushort outChannelCount = this.ReadUInt16();
uint elementCount = this.ReadUInt32();
@ -508,7 +510,7 @@ namespace ImageSharp
IccMultiProcessElement[] elements = new IccMultiProcessElement[elementCount];
for (int i = 0; i < elementCount; i++)
{
this.index = (int)positionTable[i].Offset + start;
this.currentIndex = (int)positionTable[i].Offset + start;
elements[i] = this.ReadMultiProcessElement();
}
@ -567,7 +569,7 @@ namespace ImageSharp
/// <returns>The read entry</returns>
public IccProfileSequenceIdentifierTagDataEntry ReadProfileSequenceIdentifierTagDataEntry()
{
int start = this.index - 8; // 8 is the tag header size
int start = this.currentIndex - 8; // 8 is the tag header size
uint count = this.ReadUInt32();
IccPositionNumber[] table = new IccPositionNumber[count];
for (int i = 0; i < count; i++)
@ -578,7 +580,7 @@ namespace ImageSharp
IccProfileSequenceIdentifier[] entries = new IccProfileSequenceIdentifier[count];
for (int i = 0; i < count; i++)
{
this.index = (int)(start + table[i].Offset);
this.currentIndex = (int)(start + table[i].Offset);
IccProfileId id = this.ReadProfileId();
this.ReadCheckTagDataEntryHeader(IccTypeSignature.MultiLocalizedUnicode);
IccMultiLocalizedUnicodeTagDataEntry description = this.ReadMultiLocalizedUnicodeTagDataEntry();
@ -594,7 +596,7 @@ namespace ImageSharp
/// <returns>The read entry</returns>
public IccResponseCurveSet16TagDataEntry ReadResponseCurveSet16TagDataEntry()
{
int start = this.index - 8; // 8 is the tag header size
int start = this.currentIndex - 8; // 8 is the tag header size
ushort channelCount = this.ReadUInt16();
ushort measurmentCount = this.ReadUInt16();
@ -607,7 +609,7 @@ namespace ImageSharp
IccResponseCurve[] curves = new IccResponseCurve[measurmentCount];
for (int i = 0; i < measurmentCount; i++)
{
this.index = (int)(start + offset[i]);
this.currentIndex = (int)(start + offset[i]);
curves[i] = this.ReadResponseCurve(channelCount);
}
@ -766,8 +768,8 @@ namespace ImageSharp
/// <returns>The read entry</returns>
public IccTextDescriptionTagDataEntry ReadTextDescriptionTagDataEntry()
{
string asciiValue, unicodeValue, scriptcodeValue;
asciiValue = unicodeValue = scriptcodeValue = null;
string unicodeValue, scriptcodeValue;
string asciiValue = unicodeValue = scriptcodeValue = null;
int asciiCount = (int)this.ReadUInt32();
if (asciiCount > 0)
@ -830,7 +832,7 @@ namespace ImageSharp
/// <returns>The read entry</returns>
public IccScreeningTagDataEntry ReadScreeningTagDataEntry()
{
IccScreeningFlag flags = (IccScreeningFlag)this.ReadInt32();
var flags = (IccScreeningFlag)this.ReadInt32();
uint channelCount = this.ReadUInt32();
IccScreeningChannel[] channels = new IccScreeningChannel[channelCount];
for (int i = 0; i < channels.Length; i++)

27
src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs

@ -23,11 +23,14 @@ namespace ImageSharp
private readonly byte[] data;
/// <summary>
/// The current reading position
/// The bit converter
/// </summary>
private int index;
private readonly EndianBitConverter converter = new BigEndianBitConverter();
private EndianBitConverter converter = new BigEndianBitConverter();
/// <summary>
/// The current reading position
/// </summary>
private int currentIndex;
/// <summary>
/// Initializes a new instance of the <see cref="IccDataReader"/> class.
@ -45,27 +48,27 @@ namespace ImageSharp
/// <param name="index">The new index position</param>
public void SetIndex(int index)
{
this.index = index.Clamp(0, this.data.Length);
this.currentIndex = index.Clamp(0, this.data.Length);
}
/// <summary>
/// Returns the current <see cref="index"/> without increment and adds the given increment
/// Returns the current <see cref="currentIndex"/> without increment and adds the given increment
/// </summary>
/// <param name="increment">The value to increment <see cref="index"/></param>
/// <returns>The current <see cref="index"/> without the increment</returns>
/// <param name="increment">The value to increment <see cref="currentIndex"/></param>
/// <returns>The current <see cref="currentIndex"/> without the increment</returns>
private int AddIndex(int increment)
{
int tmp = this.index;
this.index += increment;
int tmp = this.currentIndex;
this.currentIndex += increment;
return tmp;
}
/// <summary>
/// Calculates the 4 byte padding and adds it to the <see cref="index"/> variable
/// Calculates the 4 byte padding and adds it to the <see cref="currentIndex"/> variable
/// </summary>
private void AddPadding()
{
this.index += this.CalcPadding();
this.currentIndex += this.CalcPadding();
}
/// <summary>
@ -74,7 +77,7 @@ namespace ImageSharp
/// <returns>the number of bytes to pad</returns>
private int CalcPadding()
{
int p = 4 - (this.index % 4);
int p = 4 - (this.currentIndex % 4);
return p >= 4 ? 0 : p;
}

26
src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs

@ -7,9 +7,9 @@ namespace ImageSharp
{
using System.Numerics;
/// <summary>
/// <content>
/// Provides methods to write ICC data types
/// </summary>
/// </content>
internal sealed partial class IccDataWriter
{
/// <summary>
@ -22,9 +22,9 @@ namespace ImageSharp
int count = this.WriteUInt16((ushort)value.Segments.Length);
count += this.WriteEmpty(2);
foreach (double point in value.BreakPoints)
foreach (float point in value.BreakPoints)
{
count += this.WriteSingle((float)point);
count += this.WriteSingle(point);
}
foreach (IccCurveSegment segment in value.Segments)
@ -77,7 +77,7 @@ namespace ImageSharp
int count = this.WriteUInt16(typeValue);
count += this.WriteEmpty(2);
if (typeValue >= 0 && typeValue <= 4)
if (typeValue <= 4)
{
count += this.WriteFix16(value.G);
}
@ -140,21 +140,21 @@ namespace ImageSharp
if (value.Type == IccFormulaCurveType.Type1 || value.Type == IccFormulaCurveType.Type2)
{
count += this.WriteSingle((float)value.Gamma);
count += this.WriteSingle(value.Gamma);
}
count += this.WriteSingle((float)value.A);
count += this.WriteSingle((float)value.B);
count += this.WriteSingle((float)value.C);
count += this.WriteSingle(value.A);
count += this.WriteSingle(value.B);
count += this.WriteSingle(value.C);
if (value.Type == IccFormulaCurveType.Type2 || value.Type == IccFormulaCurveType.Type3)
{
count += this.WriteSingle((float)value.D);
count += this.WriteSingle(value.D);
}
if (value.Type == IccFormulaCurveType.Type3)
{
count += this.WriteSingle((float)value.E);
count += this.WriteSingle(value.E);
}
return count;
@ -168,9 +168,9 @@ namespace ImageSharp
public int WriteSampledCurveElement(IccSampledCurveElement value)
{
int count = this.WriteUInt32((uint)value.CurveEntries.Length);
foreach (double entry in value.CurveEntries)
foreach (float entry in value.CurveEntries)
{
count += this.WriteSingle((float)entry);
count += this.WriteSingle(entry);
}
return count;

8
src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs

@ -5,9 +5,9 @@
namespace ImageSharp
{
/// <summary>
/// <content>
/// Provides methods to write ICC data types
/// </summary>
/// </content>
internal sealed partial class IccDataWriter
{
/// <summary>
@ -17,7 +17,7 @@ namespace ImageSharp
/// <returns>The number of bytes written</returns>
public int WriteLut8(IccLut value)
{
foreach (double item in value.Values)
foreach (float item in value.Values)
{
this.WriteByte((byte)((item * byte.MaxValue) + 0.5f).Clamp(0, byte.MaxValue));
}
@ -32,7 +32,7 @@ namespace ImageSharp
/// <returns>The number of bytes written</returns>
public int WriteLut16(IccLut value)
{
foreach (double item in value.Values)
foreach (float item in value.Values)
{
this.WriteUInt16((ushort)((item * ushort.MaxValue) + 0.5f).Clamp(0, ushort.MaxValue));
}

2
src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs

@ -38,6 +38,8 @@ namespace ImageSharp
int major = value.Major.Clamp(0, byte.MaxValue);
int minor = value.Minor.Clamp(0, 15);
int bugfix = value.Build.Clamp(0, 15);
// TODO: This is not used?
byte mb = (byte)((minor << 4) | bugfix);
int version = (major << 24) | (minor << 20) | (bugfix << 16);

24
src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs

@ -111,10 +111,10 @@ namespace ImageSharp
/// <returns>the number of bytes written</returns>
public int WriteFix16(double value)
{
const double max = short.MaxValue + (65535d / 65536d);
const double min = short.MinValue;
const double Max = short.MaxValue + (65535d / 65536d);
const double Min = short.MinValue;
value = value.Clamp(min, max);
value = value.Clamp(Min, Max);
value *= 65536d;
return this.WriteInt32((int)Math.Round(value, MidpointRounding.AwayFromZero));
@ -127,10 +127,10 @@ namespace ImageSharp
/// <returns>the number of bytes written</returns>
public int WriteUFix16(double value)
{
const double max = ushort.MaxValue + (65535d / 65536d);
const double min = ushort.MinValue;
const double Max = ushort.MaxValue + (65535d / 65536d);
const double Min = ushort.MinValue;
value = value.Clamp(min, max);
value = value.Clamp(Min, Max);
value *= 65536d;
return this.WriteUInt32((uint)Math.Round(value, MidpointRounding.AwayFromZero));
@ -143,10 +143,10 @@ namespace ImageSharp
/// <returns>the number of bytes written</returns>
public int WriteU1Fix15(double value)
{
const double max = 1 + (32767d / 32768d);
const double min = 0;
const double Max = 1 + (32767d / 32768d);
const double Min = 0;
value = value.Clamp(min, max);
value = value.Clamp(Min, Max);
value *= 32768d;
return this.WriteUInt16((ushort)Math.Round(value, MidpointRounding.AwayFromZero));
@ -159,10 +159,10 @@ namespace ImageSharp
/// <returns>the number of bytes written</returns>
public int WriteUFix8(double value)
{
const double max = byte.MaxValue + (255d / 256d);
const double min = byte.MinValue;
const double Max = byte.MaxValue + (255d / 256d);
const double Min = byte.MinValue;
value = value.Clamp(min, max);
value = value.Clamp(Min, Max);
value *= 256d;
return this.WriteUInt16((ushort)Math.Round(value, MidpointRounding.AwayFromZero));

8
src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs

@ -61,10 +61,10 @@ namespace ImageSharp
count += this.WriteLut8TagDataEntry(entry as IccLut8TagDataEntry);
break;
case IccTypeSignature.LutAToB:
count += this.WriteLutAToBTagDataEntry(entry as IccLutAToBTagDataEntry);
count += this.WriteLutAtoBTagDataEntry(entry as IccLutAToBTagDataEntry);
break;
case IccTypeSignature.LutBToA:
count += this.WriteLutBToATagDataEntry(entry as IccLutBToATagDataEntry);
count += this.WriteLutBtoATagDataEntry(entry as IccLutBToATagDataEntry);
break;
case IccTypeSignature.Measurement:
count += this.WriteMeasurementTagDataEntry(entry as IccMeasurementTagDataEntry);
@ -337,7 +337,7 @@ namespace ImageSharp
/// </summary>
/// <param name="value">The entry to write</param>
/// <returns>The number of bytes written</returns>
public int WriteLutAToBTagDataEntry(IccLutAToBTagDataEntry value)
public int WriteLutAtoBTagDataEntry(IccLutAToBTagDataEntry value)
{
long start = this.dataStream.Position - 8; // 8 is the tag header size
@ -435,7 +435,7 @@ namespace ImageSharp
/// </summary>
/// <param name="value">The entry to write</param>
/// <returns>The number of bytes written</returns>
public int WriteLutBToATagDataEntry(IccLutBToATagDataEntry value)
public int WriteLutBtoATagDataEntry(IccLutBToATagDataEntry value)
{
long start = this.dataStream.Position - 8; // 8 is the tag header size

7
src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs

@ -25,7 +25,7 @@ namespace ImageSharp
/// <summary>
/// To detect redundant calls
/// </summary>
private bool isDisposed = false;
private bool isDisposed;
/// <summary>
/// Initializes a new instance of the <see cref="IccDataWriter"/> class.
@ -38,10 +38,7 @@ namespace ImageSharp
/// <summary>
/// Gets the currently written length in bytes
/// </summary>
public uint Length
{
get { return (uint)this.dataStream.Length; }
}
public uint Length => (uint)this.dataStream.Length;
/// <summary>
/// Gets the written data bytes

6
src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs

@ -20,7 +20,7 @@ namespace ImageSharp
Guard.NotNull(data, nameof(data));
Guard.IsTrue(data.Length >= 128, nameof(data), "Data length must be at least 128 to be a valid ICC profile");
IccDataReader reader = new IccDataReader(data);
var reader = new IccDataReader(data);
IccProfileHeader header = this.ReadHeader(reader);
IccTagDataEntry[] tagData = this.ReadTagData(reader);
@ -37,7 +37,7 @@ namespace ImageSharp
Guard.NotNull(data, nameof(data));
Guard.IsTrue(data.Length >= 128, nameof(data), "Data length must be at least 128 to be a valid profile header");
IccDataReader reader = new IccDataReader(data);
var reader = new IccDataReader(data);
return this.ReadHeader(reader);
}
@ -51,7 +51,7 @@ namespace ImageSharp
Guard.NotNull(data, nameof(data));
Guard.IsTrue(data.Length >= 128, nameof(data), "Data length must be at least 128 to be a valid ICC profile");
IccDataReader reader = new IccDataReader(data);
var reader = new IccDataReader(data);
return this.ReadTagData(reader);
}

10
src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs

@ -12,8 +12,6 @@ namespace ImageSharp
/// </summary>
public abstract class IccTagDataEntry : IEquatable<IccTagDataEntry>
{
private IccProfileTag tagSignature = IccProfileTag.Unknown;
/// <summary>
/// Initializes a new instance of the <see cref="IccTagDataEntry"/> class.
/// TagSignature will be <see cref="IccProfileTag.Unknown"/>
@ -32,7 +30,7 @@ namespace ImageSharp
protected IccTagDataEntry(IccTypeSignature signature, IccProfileTag tagSignature)
{
this.Signature = signature;
this.tagSignature = tagSignature;
this.TagSignature = tagSignature;
}
/// <summary>
@ -43,11 +41,7 @@ namespace ImageSharp
/// <summary>
/// Gets or sets the tag Signature
/// </summary>
public IccProfileTag TagSignature
{
get => this.tagSignature;
set => this.tagSignature = value;
}
public IccProfileTag TagSignature { get; set; }
/// <inheritdoc/>
public virtual bool Equals(IccTagDataEntry other)

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

@ -22,7 +22,7 @@ namespace ImageSharp
{
Guard.NotNull(profile, nameof(profile));
using (IccDataWriter writer = new IccDataWriter())
using (var writer = new IccDataWriter())
{
IccTagTableEntry[] tagTable = this.WriteTagData(writer, profile.Entries);
this.WriteTagTable(writer, tagTable);
@ -76,8 +76,8 @@ namespace ImageSharp
private IccTagTableEntry[] WriteTagData(IccDataWriter writer, List<IccTagDataEntry> entries)
{
List<IccTagDataEntry> inData = new List<IccTagDataEntry>(entries);
List<IccTagDataEntry[]> dupData = new List<IccTagDataEntry[]>();
var inData = new List<IccTagDataEntry>(entries);
var dupData = new List<IccTagDataEntry[]>();
// Filter out duplicate entries. They only need to be defined once but can be used multiple times
while (inData.Count > 0)
@ -90,7 +90,7 @@ namespace ImageSharp
}
}
List<IccTagTableEntry> table = new List<IccTagTableEntry>();
var table = new List<IccTagTableEntry>();
// (Header size) + (entry count) + (nr of entries) * (size of table entry)
writer.SetIndex(128 + 4 + (entries.Count * 12));

4
tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntryTests.cs

@ -114,7 +114,7 @@ namespace ImageSharp.Tests.Icc
{
IccDataReader reader = CreateReader(data);
IccLutAToBTagDataEntry output = reader.ReadLutAToBTagDataEntry();
IccLutAToBTagDataEntry output = reader.ReadLutAtoBTagDataEntry();
Assert.Equal(expected, output);
}
@ -125,7 +125,7 @@ namespace ImageSharp.Tests.Icc
{
IccDataReader reader = CreateReader(data);
IccLutBToATagDataEntry output = reader.ReadLutBToATagDataEntry();
IccLutBToATagDataEntry output = reader.ReadLutBtoATagDataEntry();
Assert.Equal(expected, output);
}

4
tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntryTests.cs

@ -123,7 +123,7 @@ namespace ImageSharp.Tests.Icc
{
IccDataWriter writer = CreateWriter();
writer.WriteLutAToBTagDataEntry(data);
writer.WriteLutAtoBTagDataEntry(data);
byte[] output = writer.GetData();
Assert.Equal(expected, output);
@ -135,7 +135,7 @@ namespace ImageSharp.Tests.Icc
{
IccDataWriter writer = CreateWriter();
writer.WriteLutBToATagDataEntry(data);
writer.WriteLutBtoATagDataEntry(data);
byte[] output = writer.GetData();
Assert.Equal(expected, output);

Loading…
Cancel
Save