|
|
|
@ -9,16 +9,16 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression |
|
|
|
{ |
|
|
|
internal static class BitWriterUtils |
|
|
|
{ |
|
|
|
public static void WriteBits(Span<byte> buffer, int pos, int count, byte value) |
|
|
|
public static void WriteBits(Span<byte> buffer, nint pos, nint count, byte value) |
|
|
|
{ |
|
|
|
int bitPos = Numerics.Modulo8(pos); |
|
|
|
int bufferPos = pos / 8; |
|
|
|
int startIdx = bufferPos + bitPos; |
|
|
|
int endIdx = startIdx + count; |
|
|
|
nint bitPos = Numerics.Modulo8(pos); |
|
|
|
nint bufferPos = pos / 8; |
|
|
|
nint startIdx = bufferPos + bitPos; |
|
|
|
nint endIdx = startIdx + count; |
|
|
|
|
|
|
|
if (value == 1) |
|
|
|
{ |
|
|
|
for (int i = startIdx; i < endIdx; i++) |
|
|
|
for (nint i = startIdx; i < endIdx; i++) |
|
|
|
{ |
|
|
|
WriteBit(buffer, bufferPos, bitPos); |
|
|
|
|
|
|
|
@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
for (int i = startIdx; i < endIdx; i++) |
|
|
|
for (nint i = startIdx; i < endIdx; i++) |
|
|
|
{ |
|
|
|
WriteZeroBit(buffer, bufferPos, bitPos); |
|
|
|
|
|
|
|
@ -47,17 +47,17 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(InliningOptions.ShortMethod)] |
|
|
|
public static void WriteBit(Span<byte> buffer, int bufferPos, int bitPos) |
|
|
|
public static void WriteBit(Span<byte> buffer, nint bufferPos, nint bitPos) |
|
|
|
{ |
|
|
|
ref byte b = ref Unsafe.Add(ref MemoryMarshal.GetReference(buffer), bufferPos); |
|
|
|
b |= (byte)(1 << (7 - bitPos)); |
|
|
|
b |= (byte)(1 << (int)(7 - bitPos)); |
|
|
|
} |
|
|
|
|
|
|
|
[MethodImpl(InliningOptions.ShortMethod)] |
|
|
|
public static void WriteZeroBit(Span<byte> buffer, int bufferPos, int bitPos) |
|
|
|
public static void WriteZeroBit(Span<byte> buffer, nint bufferPos, nint bitPos) |
|
|
|
{ |
|
|
|
ref byte b = ref Unsafe.Add(ref MemoryMarshal.GetReference(buffer), bufferPos); |
|
|
|
b = (byte)(b & ~(1 << (7 - bitPos))); |
|
|
|
b = (byte)(b & ~(1 << (int)(7 - bitPos))); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|