diff --git a/src/ImageSharp/Formats/Gif/PackedField.cs b/src/ImageSharp/Formats/Gif/PackedField.cs deleted file mode 100644 index e3c1ef0e7..000000000 --- a/src/ImageSharp/Formats/Gif/PackedField.cs +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright (c) Six Labors and contributors. -// Licensed under the Apache License, Version 2.0. - -using System; -using System.Diagnostics; -using System.Runtime.CompilerServices; - -namespace SixLabors.ImageSharp.Formats.Gif -{ - /// - /// Represents a byte of data in a GIF data stream which contains a number - /// of data items. - /// - internal readonly struct PackedField - { - /// - /// The individual bits representing the packed byte. - /// - private static readonly bool[] Bits = new bool[8]; - - /// - /// Gets the byte which represents the data items held in this instance. - /// - public byte Byte - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - int returnValue = 0; - int bitShift = 7; - foreach (bool bit in Bits) - { - int bitValue; - if (bit) - { - bitValue = 1 << bitShift; - } - else - { - bitValue = 0; - } - - returnValue |= bitValue; - bitShift--; - } - - return Convert.ToByte(returnValue & 0xFF); - } - } - - /// - /// Sets the specified bit within the packed fields to the supplied - /// value. - /// - /// - /// The zero-based index within the packed fields of the bit to set. - /// - /// - /// The value to set the bit to. - /// - public void SetBit(int index, bool valueToSet) - { - DebugGuard.MustBeBetweenOrEqualTo(index, 0, 7, nameof(index)); - Bits[index] = valueToSet; - } - - /// - /// Sets the specified bits within the packed fields to the supplied - /// value. - /// - /// The zero-based index within the packed fields of the first bit to set. - /// The number of bits to set. - /// The value to set the bits to. - public void SetBits(int startIndex, int length, int valueToSet) - { - DebugGuard.MustBeBetweenOrEqualTo(startIndex, 0, 7, nameof(startIndex)); - DebugCheckLength(startIndex, length); - - int bitShift = length - 1; - for (int i = startIndex; i < startIndex + length; i++) - { - int bitValueIfSet = 1 << bitShift; - int bitValue = valueToSet & bitValueIfSet; - int bitIsSet = bitValue >> bitShift; - Bits[i] = bitIsSet == 1; - bitShift--; - } - } - - /// - /// Gets the value of the specified bit within the byte. - /// - /// The zero-based index of the bit to get. - /// - /// The value of the specified bit within the byte. - /// - public bool GetBit(int index) - { - DebugGuard.MustBeBetweenOrEqualTo(index, 0, 7, nameof(index)); - return Bits[index]; - } - - [Conditional("DEBUG")] - private static void DebugCheckLength(int startIndex, int length) - { - if (length < 1 || startIndex + length > 8) - { - string message = "Length must be greater than zero and the sum of length and start index must be less than 8. " - + $"Supplied length: {length}. Supplied start index: {startIndex}"; - - throw new ArgumentOutOfRangeException(nameof(length), message); - } - } - } -} \ No newline at end of file