Skip to content

Commit 74a09bf

Browse files
Merge branch 'main' into js/webp-allocations
2 parents 83ced12 + d93bc6c commit 74a09bf

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

src/ImageSharp/Formats/Pbm/BinaryDecoder.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private static void ProcessGrayscale<TPixel>(Configuration configuration, Buffer
7171

7272
for (int y = 0; y < height; y++)
7373
{
74-
if (stream.Read(rowSpan) == 0)
74+
if (stream.Read(rowSpan) < rowSpan.Length)
7575
{
7676
return;
7777
}
@@ -97,7 +97,7 @@ private static void ProcessWideGrayscale<TPixel>(Configuration configuration, Bu
9797

9898
for (int y = 0; y < height; y++)
9999
{
100-
if (stream.Read(rowSpan) == 0)
100+
if (stream.Read(rowSpan) < rowSpan.Length)
101101
{
102102
return;
103103
}
@@ -123,7 +123,7 @@ private static void ProcessRgb<TPixel>(Configuration configuration, Buffer2D<TPi
123123

124124
for (int y = 0; y < height; y++)
125125
{
126-
if (stream.Read(rowSpan) == 0)
126+
if (stream.Read(rowSpan) < rowSpan.Length)
127127
{
128128
return;
129129
}
@@ -149,7 +149,7 @@ private static void ProcessWideRgb<TPixel>(Configuration configuration, Buffer2D
149149

150150
for (int y = 0; y < height; y++)
151151
{
152-
if (stream.Read(rowSpan) == 0)
152+
if (stream.Read(rowSpan) < rowSpan.Length)
153153
{
154154
return;
155155
}

src/ImageSharp/Formats/Pbm/BufferedReadStreamExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal static class BufferedReadStreamExtensions
1515
/// </summary>
1616
/// <param name="stream">The buffered read stream.</param>
1717
/// <returns><see langword="false"/> if EOF has been reached while reading the stream; see langword="true"/> otherwise.</returns>
18-
public static bool TrySkipWhitespaceAndComments(this BufferedReadStream stream)
18+
public static bool SkipWhitespaceAndComments(this BufferedReadStream stream)
1919
{
2020
bool isWhitespace;
2121
do
@@ -61,7 +61,7 @@ public static bool TrySkipWhitespaceAndComments(this BufferedReadStream stream)
6161
/// 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.
6262
/// It's up to the call site to handle such a situation.
6363
/// </remarks>
64-
public static bool TryReadDecimal(this BufferedReadStream stream, out int value)
64+
public static bool ReadDecimal(this BufferedReadStream stream, out int value)
6565
{
6666
value = 0;
6767
while (true)

src/ImageSharp/Formats/Pbm/PbmDecoderCore.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,18 @@ private void ProcessHeader(BufferedReadStream stream)
146146
throw new InvalidImageContentException("Unknown of not implemented image type encountered.");
147147
}
148148

149-
if (!stream.TrySkipWhitespaceAndComments() ||
150-
!stream.TryReadDecimal(out int width) ||
151-
!stream.TrySkipWhitespaceAndComments() ||
152-
!stream.TryReadDecimal(out int height) ||
153-
!stream.TrySkipWhitespaceAndComments())
149+
if (!stream.SkipWhitespaceAndComments() ||
150+
!stream.ReadDecimal(out int width) ||
151+
!stream.SkipWhitespaceAndComments() ||
152+
!stream.ReadDecimal(out int height) ||
153+
!stream.SkipWhitespaceAndComments())
154154
{
155155
ThrowPrematureEof();
156156
}
157157

158158
if (this.colorType != PbmColorType.BlackAndWhite)
159159
{
160-
if (!stream.TryReadDecimal(out this.maxPixelValue))
160+
if (!stream.ReadDecimal(out this.maxPixelValue))
161161
{
162162
ThrowPrematureEof();
163163
}
@@ -171,7 +171,7 @@ private void ProcessHeader(BufferedReadStream stream)
171171
this.componentType = PbmComponentType.Byte;
172172
}
173173

174-
stream.TrySkipWhitespaceAndComments();
174+
stream.SkipWhitespaceAndComments();
175175
}
176176
else
177177
{

src/ImageSharp/Formats/Pbm/PlainDecoder.cs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ private static void ProcessGrayscale<TPixel>(Configuration configuration, Buffer
7070
{
7171
for (int x = 0; x < width; x++)
7272
{
73-
stream.TryReadDecimal(out int value);
73+
stream.ReadDecimal(out int value);
7474
rowSpan[x] = new L8((byte)value);
75-
eofReached = !stream.TrySkipWhitespaceAndComments();
75+
eofReached = !stream.SkipWhitespaceAndComments();
7676
if (eofReached)
7777
{
7878
break;
@@ -106,9 +106,9 @@ private static void ProcessWideGrayscale<TPixel>(Configuration configuration, Bu
106106
{
107107
for (int x = 0; x < width; x++)
108108
{
109-
stream.TryReadDecimal(out int value);
109+
stream.ReadDecimal(out int value);
110110
rowSpan[x] = new L16((ushort)value);
111-
eofReached = !stream.TrySkipWhitespaceAndComments();
111+
eofReached = !stream.SkipWhitespaceAndComments();
112112
if (eofReached)
113113
{
114114
break;
@@ -142,20 +142,20 @@ private static void ProcessRgb<TPixel>(Configuration configuration, Buffer2D<TPi
142142
{
143143
for (int x = 0; x < width; x++)
144144
{
145-
if (!stream.TryReadDecimal(out int red) ||
146-
!stream.TrySkipWhitespaceAndComments() ||
147-
!stream.TryReadDecimal(out int green) ||
148-
!stream.TrySkipWhitespaceAndComments())
145+
if (!stream.ReadDecimal(out int red) ||
146+
!stream.SkipWhitespaceAndComments() ||
147+
!stream.ReadDecimal(out int green) ||
148+
!stream.SkipWhitespaceAndComments())
149149
{
150150
// Reached EOF before reading a full RGB value
151151
eofReached = true;
152152
break;
153153
}
154154

155-
stream.TryReadDecimal(out int blue);
155+
stream.ReadDecimal(out int blue);
156156

157157
rowSpan[x] = new Rgb24((byte)red, (byte)green, (byte)blue);
158-
eofReached = !stream.TrySkipWhitespaceAndComments();
158+
eofReached = !stream.SkipWhitespaceAndComments();
159159
if (eofReached)
160160
{
161161
break;
@@ -189,20 +189,20 @@ private static void ProcessWideRgb<TPixel>(Configuration configuration, Buffer2D
189189
{
190190
for (int x = 0; x < width; x++)
191191
{
192-
if (!stream.TryReadDecimal(out int red) ||
193-
!stream.TrySkipWhitespaceAndComments() ||
194-
!stream.TryReadDecimal(out int green) ||
195-
!stream.TrySkipWhitespaceAndComments())
192+
if (!stream.ReadDecimal(out int red) ||
193+
!stream.SkipWhitespaceAndComments() ||
194+
!stream.ReadDecimal(out int green) ||
195+
!stream.SkipWhitespaceAndComments())
196196
{
197197
// Reached EOF before reading a full RGB value
198198
eofReached = true;
199199
break;
200200
}
201201

202-
stream.TryReadDecimal(out int blue);
202+
stream.ReadDecimal(out int blue);
203203

204204
rowSpan[x] = new Rgb48((ushort)red, (ushort)green, (ushort)blue);
205-
eofReached = !stream.TrySkipWhitespaceAndComments();
205+
eofReached = !stream.SkipWhitespaceAndComments();
206206
if (eofReached)
207207
{
208208
break;
@@ -236,10 +236,10 @@ private static void ProcessBlackAndWhite<TPixel>(Configuration configuration, Bu
236236
{
237237
for (int x = 0; x < width; x++)
238238
{
239-
stream.TryReadDecimal(out int value);
239+
stream.ReadDecimal(out int value);
240240

241241
rowSpan[x] = value == 0 ? White : Black;
242-
eofReached = !stream.TrySkipWhitespaceAndComments();
242+
eofReached = !stream.SkipWhitespaceAndComments();
243243
if (eofReached)
244244
{
245245
break;

0 commit comments

Comments
 (0)