Browse Source

Merge branch 'main' into js/webp-allocations

pull/2546/head
James Jackson-South 2 years ago
committed by GitHub
parent
commit
74a09bfcce
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
  2. 4
      src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs
  3. 14
      src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs
  4. 36
      src/ImageSharp/Formats/Pbm/PlainDecoder.cs

8
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;
}

4
src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs

@ -15,7 +15,7 @@ internal static class BufferedReadStreamExtensions
/// </summary>
/// <param name="stream">The buffered read stream.</param>
/// <returns><see langword="false"/> if EOF has been reached while reading the stream; see langword="true"/> otherwise.</returns>
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.
/// </remarks>
public static bool TryReadDecimal(this BufferedReadStream stream, out int value)
public static bool ReadDecimal(this BufferedReadStream stream, out int value)
{
value = 0;
while (true)

14
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
{

36
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;

Loading…
Cancel
Save