diff --git a/src/ImageSharp/IO/EndianBinaryReader.cs b/src/ImageSharp/IO/EndianBinaryReader.cs index 0d660c68d..2b2a79c7e 100644 --- a/src/ImageSharp/IO/EndianBinaryReader.cs +++ b/src/ImageSharp/IO/EndianBinaryReader.cs @@ -38,6 +38,11 @@ namespace SixLabors.ImageSharp.IO /// private bool disposed; + /// + /// The endianness used to read data + /// + private Endianness endianness; + /// /// Initializes a new instance of the class. /// Equivalent of , but with either endianness, depending on @@ -72,6 +77,7 @@ namespace SixLabors.ImageSharp.IO this.BitConverter = EndianBitConverter.GetConverter(endianness); this.Encoding = encoding; this.decoder = encoding.GetDecoder(); + this.endianness = endianness; this.minBytesPerChar = 1; if (encoding is UnicodeEncoding) @@ -141,7 +147,9 @@ namespace SixLabors.ImageSharp.IO public bool ReadBoolean() { this.ReadInternal(this.storageBuffer, 1); - return this.BitConverter.ToBoolean(this.storageBuffer, 0); + + return this.storageBuffer[0] != 0; + } /// diff --git a/src/ImageSharp/IO/EndianBitConverter.ToType.cs b/src/ImageSharp/IO/EndianBitConverter.ToType.cs index 0c0e49911..ee14ef33e 100644 --- a/src/ImageSharp/IO/EndianBitConverter.ToType.cs +++ b/src/ImageSharp/IO/EndianBitConverter.ToType.cs @@ -67,18 +67,6 @@ namespace SixLabors.ImageSharp.IO return unchecked((ulong)this.ToInt64(value, startIndex)); } - /// - /// Returns a Boolean value converted from one byte at a specified position in a byte array. - /// - /// An array of bytes. - /// The starting position within value. - /// true if the byte at startIndex in value is nonzero; otherwise, false. - public bool ToBoolean(byte[] value, int startIndex) - { - CheckByteArgument(value, startIndex, 1); - return value[startIndex] != 0; - } - /// /// Returns a Unicode character converted from two bytes at a specified position in a byte array. /// diff --git a/tests/ImageSharp.Tests/IO/BigEndianBitConverter.ToTypeTests.cs b/tests/ImageSharp.Tests/IO/BigEndianBitConverter.ToTypeTests.cs index 19ef24c79..67fb7e2cc 100644 --- a/tests/ImageSharp.Tests/IO/BigEndianBitConverter.ToTypeTests.cs +++ b/tests/ImageSharp.Tests/IO/BigEndianBitConverter.ToTypeTests.cs @@ -15,7 +15,6 @@ namespace SixLabors.ImageSharp.Tests.IO [Fact] public void CopyToWithNullBufferThrowsException() { - Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToBoolean(null, 0)); Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToInt16(null, 0)); Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToUInt16(null, 0)); Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToInt32(null, 0)); @@ -27,7 +26,6 @@ namespace SixLabors.ImageSharp.Tests.IO [Fact] public void CopyToWithIndexTooBigThrowsException() { - Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToBoolean(new byte[1], 1)); Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToInt16(new byte[2], 1)); Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToUInt16(new byte[2], 1)); Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToInt32(new byte[4], 1)); @@ -39,7 +37,6 @@ namespace SixLabors.ImageSharp.Tests.IO [Fact] public void CopyToWithBufferTooSmallThrowsException() { - Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToBoolean(new byte[0], 0)); Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToInt16(new byte[1], 0)); Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToUInt16(new byte[1], 0)); Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToInt32(new byte[3], 0)); @@ -48,21 +45,6 @@ namespace SixLabors.ImageSharp.Tests.IO Assert.Throws(() => EndianBitConverter.BigEndianConverter.ToUInt64(new byte[7], 0)); } - /// - /// Tests that passing a returns the correct bytes. - /// - [Fact] - public void ToBoolean() - { - Assert.False(EndianBitConverter.BigEndianConverter.ToBoolean(new byte[] { 0 }, 0)); - Assert.True(EndianBitConverter.BigEndianConverter.ToBoolean(new byte[] { 1 }, 0)); - Assert.True(EndianBitConverter.BigEndianConverter.ToBoolean(new byte[] { 42 }, 0)); - - Assert.False(EndianBitConverter.BigEndianConverter.ToBoolean(new byte[] { 1, 0 }, 1)); - Assert.True(EndianBitConverter.BigEndianConverter.ToBoolean(new byte[] { 0, 1 }, 1)); - Assert.True(EndianBitConverter.BigEndianConverter.ToBoolean(new byte[] { 0, 42 }, 1)); - } - /// /// Tests that passing a returns the correct bytes. /// diff --git a/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.ToTypeTests.cs b/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.ToTypeTests.cs index 0e09d1d07..4c890b367 100644 --- a/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.ToTypeTests.cs +++ b/tests/ImageSharp.Tests/IO/LittleEndianBitConverter.ToTypeTests.cs @@ -15,7 +15,6 @@ namespace SixLabors.ImageSharp.Tests.IO [Fact] public void CopyToWithNullBufferThrowsException() { - Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToBoolean(null, 0)); Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToInt16(null, 0)); Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToUInt16(null, 0)); Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToInt32(null, 0)); @@ -27,7 +26,6 @@ namespace SixLabors.ImageSharp.Tests.IO [Fact] public void CopyToWithIndexTooBigThrowsException() { - Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToBoolean(new byte[1], 1)); Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToInt16(new byte[2], 1)); Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToUInt16(new byte[2], 1)); Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToInt32(new byte[4], 1)); @@ -39,7 +37,6 @@ namespace SixLabors.ImageSharp.Tests.IO [Fact] public void CopyToWithBufferTooSmallThrowsException() { - Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToBoolean(new byte[0], 0)); Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToInt16(new byte[1], 0)); Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToUInt16(new byte[1], 0)); Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToInt32(new byte[3], 0)); @@ -48,19 +45,6 @@ namespace SixLabors.ImageSharp.Tests.IO Assert.Throws(() => EndianBitConverter.LittleEndianConverter.ToUInt64(new byte[7], 0)); } - /// - /// Tests that passing a returns the correct bytes. - /// - [Fact] - public void ToBoolean() - { - Assert.False(EndianBitConverter.LittleEndianConverter.ToBoolean(new byte[] { 0 }, 0)); - Assert.True(EndianBitConverter.LittleEndianConverter.ToBoolean(new byte[] { 1 }, 0)); - - Assert.False(EndianBitConverter.LittleEndianConverter.ToBoolean(new byte[] { 1, 0 }, 1)); - Assert.True(EndianBitConverter.LittleEndianConverter.ToBoolean(new byte[] { 0, 1 }, 1)); - } - /// /// Tests that passing a returns the correct bytes. ///