diff --git a/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs b/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
index 96564df0f..ce7e379fc 100644
--- a/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
+++ b/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
@@ -71,7 +71,7 @@ internal class BinaryDecoder
for (int y = 0; y < height; y++)
{
- if (stream.Read(rowSpan) == 0)
+ if (stream.Read(rowSpan) < rowSpan.Length)
{
return;
}
@@ -97,7 +97,7 @@ internal class BinaryDecoder
for (int y = 0; y < height; y++)
{
- if (stream.Read(rowSpan) == 0)
+ if (stream.Read(rowSpan) < rowSpan.Length)
{
return;
}
@@ -123,7 +123,7 @@ internal class BinaryDecoder
for (int y = 0; y < height; y++)
{
- if (stream.Read(rowSpan) == 0)
+ if (stream.Read(rowSpan) < rowSpan.Length)
{
return;
}
@@ -149,7 +149,7 @@ internal class BinaryDecoder
for (int y = 0; y < height; y++)
{
- if (stream.Read(rowSpan) == 0)
+ if (stream.Read(rowSpan) < rowSpan.Length)
{
return;
}
diff --git a/src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs b/src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs
index 8fd1d797d..3b0e41a02 100644
--- a/src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs
+++ b/src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs
@@ -15,7 +15,7 @@ internal static class BufferedReadStreamExtensions
///
/// The buffered read stream.
/// if EOF has been reached while reading the stream; see langword="true"/> otherwise.
- public static bool TrySkipWhitespaceAndComments(this BufferedReadStream stream)
+ public static bool SkipWhitespaceAndComments(this BufferedReadStream stream)
{
bool isWhitespace;
do
@@ -61,7 +61,7 @@ internal static class BufferedReadStreamExtensions
/// A 'false' return value doesn't mean that the parsing has been failed, since it's possible to reach EOF while reading the last decimal in the file.
/// It's up to the call site to handle such a situation.
///
- public static bool TryReadDecimal(this BufferedReadStream stream, out int value)
+ public static bool ReadDecimal(this BufferedReadStream stream, out int value)
{
value = 0;
while (true)
diff --git a/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs b/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs
index 84d0acb1b..3fe339865 100644
--- a/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs
+++ b/src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs
@@ -146,18 +146,18 @@ internal sealed class PbmDecoderCore : IImageDecoderInternals
throw new InvalidImageContentException("Unknown of not implemented image type encountered.");
}
- if (!stream.TrySkipWhitespaceAndComments() ||
- !stream.TryReadDecimal(out int width) ||
- !stream.TrySkipWhitespaceAndComments() ||
- !stream.TryReadDecimal(out int height) ||
- !stream.TrySkipWhitespaceAndComments())
+ if (!stream.SkipWhitespaceAndComments() ||
+ !stream.ReadDecimal(out int width) ||
+ !stream.SkipWhitespaceAndComments() ||
+ !stream.ReadDecimal(out int height) ||
+ !stream.SkipWhitespaceAndComments())
{
ThrowPrematureEof();
}
if (this.colorType != PbmColorType.BlackAndWhite)
{
- if (!stream.TryReadDecimal(out this.maxPixelValue))
+ if (!stream.ReadDecimal(out this.maxPixelValue))
{
ThrowPrematureEof();
}
@@ -171,7 +171,7 @@ internal sealed class PbmDecoderCore : IImageDecoderInternals
this.componentType = PbmComponentType.Byte;
}
- stream.TrySkipWhitespaceAndComments();
+ stream.SkipWhitespaceAndComments();
}
else
{
diff --git a/src/ImageSharp/Formats/Pbm/PlainDecoder.cs b/src/ImageSharp/Formats/Pbm/PlainDecoder.cs
index 5a01c9a8a..8748d90fa 100644
--- a/src/ImageSharp/Formats/Pbm/PlainDecoder.cs
+++ b/src/ImageSharp/Formats/Pbm/PlainDecoder.cs
@@ -70,9 +70,9 @@ internal class PlainDecoder
{
for (int x = 0; x < width; x++)
{
- stream.TryReadDecimal(out int value);
+ stream.ReadDecimal(out int value);
rowSpan[x] = new L8((byte)value);
- eofReached = !stream.TrySkipWhitespaceAndComments();
+ eofReached = !stream.SkipWhitespaceAndComments();
if (eofReached)
{
break;
@@ -106,9 +106,9 @@ internal class PlainDecoder
{
for (int x = 0; x < width; x++)
{
- stream.TryReadDecimal(out int value);
+ stream.ReadDecimal(out int value);
rowSpan[x] = new L16((ushort)value);
- eofReached = !stream.TrySkipWhitespaceAndComments();
+ eofReached = !stream.SkipWhitespaceAndComments();
if (eofReached)
{
break;
@@ -142,20 +142,20 @@ internal class PlainDecoder
{
for (int x = 0; x < width; x++)
{
- if (!stream.TryReadDecimal(out int red) ||
- !stream.TrySkipWhitespaceAndComments() ||
- !stream.TryReadDecimal(out int green) ||
- !stream.TrySkipWhitespaceAndComments())
+ if (!stream.ReadDecimal(out int red) ||
+ !stream.SkipWhitespaceAndComments() ||
+ !stream.ReadDecimal(out int green) ||
+ !stream.SkipWhitespaceAndComments())
{
// Reached EOF before reading a full RGB value
eofReached = true;
break;
}
- stream.TryReadDecimal(out int blue);
+ stream.ReadDecimal(out int blue);
rowSpan[x] = new Rgb24((byte)red, (byte)green, (byte)blue);
- eofReached = !stream.TrySkipWhitespaceAndComments();
+ eofReached = !stream.SkipWhitespaceAndComments();
if (eofReached)
{
break;
@@ -189,20 +189,20 @@ internal class PlainDecoder
{
for (int x = 0; x < width; x++)
{
- if (!stream.TryReadDecimal(out int red) ||
- !stream.TrySkipWhitespaceAndComments() ||
- !stream.TryReadDecimal(out int green) ||
- !stream.TrySkipWhitespaceAndComments())
+ if (!stream.ReadDecimal(out int red) ||
+ !stream.SkipWhitespaceAndComments() ||
+ !stream.ReadDecimal(out int green) ||
+ !stream.SkipWhitespaceAndComments())
{
// Reached EOF before reading a full RGB value
eofReached = true;
break;
}
- stream.TryReadDecimal(out int blue);
+ stream.ReadDecimal(out int blue);
rowSpan[x] = new Rgb48((ushort)red, (ushort)green, (ushort)blue);
- eofReached = !stream.TrySkipWhitespaceAndComments();
+ eofReached = !stream.SkipWhitespaceAndComments();
if (eofReached)
{
break;
@@ -236,10 +236,10 @@ internal class PlainDecoder
{
for (int x = 0; x < width; x++)
{
- stream.TryReadDecimal(out int value);
+ stream.ReadDecimal(out int value);
rowSpan[x] = value == 0 ? White : Black;
- eofReached = !stream.TrySkipWhitespaceAndComments();
+ eofReached = !stream.SkipWhitespaceAndComments();
if (eofReached)
{
break;