Browse Source

Row boundary on decode

pull/2481/head
Ynse Hoornenborg 3 years ago
parent
commit
bbc14f4ff5
  1. 15
      src/ImageSharp/Formats/Pbm/BinaryDecoder.cs

15
src/ImageSharp/Formats/Pbm/BinaryDecoder.cs

@ -152,7 +152,6 @@ internal class BinaryDecoder
{ {
int width = pixels.Width; int width = pixels.Width;
int height = pixels.Height; int height = pixels.Height;
int startBit = 0;
MemoryAllocator allocator = configuration.MemoryAllocator; MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner<L8> row = allocator.Allocate<L8>(width); using IMemoryOwner<L8> row = allocator.Allocate<L8>(width);
Span<L8> rowSpan = row.GetSpan(); Span<L8> rowSpan = row.GetSpan();
@ -162,23 +161,11 @@ internal class BinaryDecoder
for (int x = 0; x < width;) for (int x = 0; x < width;)
{ {
int raw = stream.ReadByte(); int raw = stream.ReadByte();
int bit = startBit; for (int bit = 0; bit < 8; bit++)
startBit = 0;
for (; bit < 8; bit++)
{ {
bool bitValue = (raw & (0x80 >> bit)) != 0; bool bitValue = (raw & (0x80 >> bit)) != 0;
rowSpan[x] = bitValue ? black : white; rowSpan[x] = bitValue ? black : white;
x++; x++;
if (x == width)
{
startBit = (bit + 1) & 7; // Round off to below 8.
if (startBit != 0)
{
stream.Seek(-1, System.IO.SeekOrigin.Current);
}
break;
}
} }
} }

Loading…
Cancel
Save