From 450ad2eb224be679f4fd0e7b88d4969bbe5f0ff9 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 16 May 2017 00:20:46 +1000 Subject: [PATCH] Clean up code a little --- .../ICC/DataReader/IccDataReader.Curves.cs | 10 +-- .../ICC/DataReader/IccDataReader.Lut.cs | 37 ++++----- .../DataReader/IccDataReader.NonPrimitives.cs | 6 +- .../DataReader/IccDataReader.TagDataEntry.cs | 80 ++++++++++--------- .../Profiles/ICC/DataReader/IccDataReader.cs | 27 ++++--- .../ICC/DataWriter/IccDataWriter.Curves.cs | 26 +++--- .../ICC/DataWriter/IccDataWriter.Lut.cs | 8 +- .../DataWriter/IccDataWriter.NonPrimitives.cs | 2 + .../DataWriter/IccDataWriter.Primitives.cs | 24 +++--- .../DataWriter/IccDataWriter.TagDataEntry.cs | 8 +- .../Profiles/ICC/DataWriter/IccDataWriter.cs | 7 +- .../MetaData/Profiles/ICC/IccReader.cs | 6 +- .../MetaData/Profiles/ICC/IccTagDataEntry.cs | 10 +-- .../MetaData/Profiles/ICC/IccWriter.cs | 8 +- .../IccDataReader.TagDataEntryTests.cs | 4 +- .../IccDataWriter.TagDataEntryTests.cs | 4 +- 16 files changed, 131 insertions(+), 136 deletions(-) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs index b8daeaac00..ba32586fea 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Curves.cs @@ -42,7 +42,7 @@ namespace ImageSharp /// The read curve 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 /// The read segment 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 /// The read segment 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) { diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs index d37dccb72c..a34ee42fce 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.Lut.cs +++ b/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); } /// @@ -82,7 +79,7 @@ namespace ImageSharp /// The read CLUT8 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 /// The read CLUT16 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 /// The read CLUTf32 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); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs index fa823b9b06..44a892084c 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.NonPrimitives.cs +++ b/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(); diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs index d7842bece9..1c130b54d0 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntry.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// the tag data entry 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 /// The read signature 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 /// /// The read entry - 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 /// /// The read entry - 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 /// The read entry 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 /// The read entry 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 /// The read entry 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 /// The read entry 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 /// The read entry 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 /// The read entry 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++) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs index 8a1dab81b3..cb1fe5b55e 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataReader/IccDataReader.cs @@ -23,11 +23,14 @@ namespace ImageSharp private readonly byte[] data; /// - /// The current reading position + /// The bit converter /// - private int index; + private readonly EndianBitConverter converter = new BigEndianBitConverter(); - private EndianBitConverter converter = new BigEndianBitConverter(); + /// + /// The current reading position + /// + private int currentIndex; /// /// Initializes a new instance of the class. @@ -45,27 +48,27 @@ namespace ImageSharp /// The new index position public void SetIndex(int index) { - this.index = index.Clamp(0, this.data.Length); + this.currentIndex = index.Clamp(0, this.data.Length); } /// - /// Returns the current without increment and adds the given increment + /// Returns the current without increment and adds the given increment /// - /// The value to increment - /// The current without the increment + /// The value to increment + /// The current without the increment private int AddIndex(int increment) { - int tmp = this.index; - this.index += increment; + int tmp = this.currentIndex; + this.currentIndex += increment; return tmp; } /// - /// Calculates the 4 byte padding and adds it to the variable + /// Calculates the 4 byte padding and adds it to the variable /// private void AddPadding() { - this.index += this.CalcPadding(); + this.currentIndex += this.CalcPadding(); } /// @@ -74,7 +77,7 @@ namespace ImageSharp /// the number of bytes to pad private int CalcPadding() { - int p = 4 - (this.index % 4); + int p = 4 - (this.currentIndex % 4); return p >= 4 ? 0 : p; } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs index 660d6f4271..4b6e454a1d 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Curves.cs @@ -7,9 +7,9 @@ namespace ImageSharp { using System.Numerics; - /// + /// /// Provides methods to write ICC data types - /// + /// internal sealed partial class IccDataWriter { /// @@ -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; diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs index 01360da640..f85d59714f 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Lut.cs @@ -5,9 +5,9 @@ namespace ImageSharp { - /// + /// /// Provides methods to write ICC data types - /// + /// internal sealed partial class IccDataWriter { /// @@ -17,7 +17,7 @@ namespace ImageSharp /// The number of bytes written 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 /// The number of bytes written 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)); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs index 544baa9506..d90c1ff549 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.NonPrimitives.cs +++ b/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); diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs index 041cb4c234..fbb7065e6b 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.Primitives.cs @@ -111,10 +111,10 @@ namespace ImageSharp /// the number of bytes written 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 /// the number of bytes written 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 /// the number of bytes written 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 /// the number of bytes written 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)); diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs index 717a80f6b4..8e8065cee8 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntry.cs +++ b/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 /// /// The entry to write /// The number of bytes written - 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 /// /// The entry to write /// The number of bytes written - public int WriteLutBToATagDataEntry(IccLutBToATagDataEntry value) + public int WriteLutBtoATagDataEntry(IccLutBToATagDataEntry value) { long start = this.dataStream.Position - 8; // 8 is the tag header size diff --git a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs index d515ee7263..a9a65b80be 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/DataWriter/IccDataWriter.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// /// To detect redundant calls /// - private bool isDisposed = false; + private bool isDisposed; /// /// Initializes a new instance of the class. @@ -38,10 +38,7 @@ namespace ImageSharp /// /// Gets the currently written length in bytes /// - public uint Length - { - get { return (uint)this.dataStream.Length; } - } + public uint Length => (uint)this.dataStream.Length; /// /// Gets the written data bytes diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs index efc27a78c4..d7f556a814 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccReader.cs +++ b/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); } diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs index 440ef14495..753eb894b6 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs +++ b/src/ImageSharp/MetaData/Profiles/ICC/IccTagDataEntry.cs @@ -12,8 +12,6 @@ namespace ImageSharp /// public abstract class IccTagDataEntry : IEquatable { - private IccProfileTag tagSignature = IccProfileTag.Unknown; - /// /// Initializes a new instance of the class. /// TagSignature will be @@ -32,7 +30,7 @@ namespace ImageSharp protected IccTagDataEntry(IccTypeSignature signature, IccProfileTag tagSignature) { this.Signature = signature; - this.tagSignature = tagSignature; + this.TagSignature = tagSignature; } /// @@ -43,11 +41,7 @@ namespace ImageSharp /// /// Gets or sets the tag Signature /// - public IccProfileTag TagSignature - { - get => this.tagSignature; - set => this.tagSignature = value; - } + public IccProfileTag TagSignature { get; set; } /// public virtual bool Equals(IccTagDataEntry other) diff --git a/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs b/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs index dcf2f056fe..de28233874 100644 --- a/src/ImageSharp/MetaData/Profiles/ICC/IccWriter.cs +++ b/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 entries) { - List inData = new List(entries); - List dupData = new List(); + var inData = new List(entries); + var dupData = new List(); // 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 table = new List(); + var table = new List(); // (Header size) + (entry count) + (nr of entries) * (size of table entry) writer.SetIndex(128 + 4 + (entries.Count * 12)); diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntryTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntryTests.cs index 35920139bd..9a2455f0e8 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataReader/IccDataReader.TagDataEntryTests.cs +++ b/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); } diff --git a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntryTests.cs b/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntryTests.cs index b00235682b..affe9835e9 100644 --- a/tests/ImageSharp.Tests/MetaData/Profiles/ICC/DataWriter/IccDataWriter.TagDataEntryTests.cs +++ b/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);