diff --git a/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs b/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
index 8b6df295b2..2a171456ad 100644
--- a/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
+++ b/src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
@@ -14,6 +14,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
///
internal class BinaryDecoder
{
+ private static L8 white = new L8(255);
+ private static L8 black = new L8(0);
+
///
/// Decode the specified pixels.
///
@@ -60,9 +63,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void ProcessGrayscale(Configuration configuration, Buffer2D pixels, BufferedReadStream stream)
where TPixel : unmanaged, IPixel
{
+ const int bytesPerPixel = 1;
int width = pixels.Width;
int height = pixels.Height;
- int bytesPerPixel = 1;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner row = allocator.Allocate(width * bytesPerPixel);
Span rowSpan = row.GetSpan();
@@ -82,9 +85,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void ProcessWideGrayscale(Configuration configuration, Buffer2D pixels, BufferedReadStream stream)
where TPixel : unmanaged, IPixel
{
+ const int bytesPerPixel = 2;
int width = pixels.Width;
int height = pixels.Height;
- int bytesPerPixel = 2;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner row = allocator.Allocate(width * bytesPerPixel);
Span rowSpan = row.GetSpan();
@@ -104,9 +107,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void ProcessRgb(Configuration configuration, Buffer2D pixels, BufferedReadStream stream)
where TPixel : unmanaged, IPixel
{
+ const int bytesPerPixel = 3;
int width = pixels.Width;
int height = pixels.Height;
- int bytesPerPixel = 3;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner row = allocator.Allocate(width * bytesPerPixel);
Span rowSpan = row.GetSpan();
@@ -126,9 +129,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void ProcessWideRgb(Configuration configuration, Buffer2D pixels, BufferedReadStream stream)
where TPixel : unmanaged, IPixel
{
+ const int bytesPerPixel = 6;
int width = pixels.Width;
int height = pixels.Height;
- int bytesPerPixel = 6;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner row = allocator.Allocate(width * bytesPerPixel);
Span rowSpan = row.GetSpan();
@@ -154,8 +157,6 @@ namespace SixLabors.ImageSharp.Formats.Pbm
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner row = allocator.Allocate(width);
Span rowSpan = row.GetSpan();
- var white = new L8(255);
- var black = new L8(0);
for (int y = 0; y < height; y++)
{
diff --git a/src/ImageSharp/Formats/Pbm/BinaryEncoder.cs b/src/ImageSharp/Formats/Pbm/BinaryEncoder.cs
index 2bcbaeef7c..626026726b 100644
--- a/src/ImageSharp/Formats/Pbm/BinaryEncoder.cs
+++ b/src/ImageSharp/Formats/Pbm/BinaryEncoder.cs
@@ -83,9 +83,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void WriteWideGrayscale(Configuration configuration, Stream stream, ImageFrame image)
where TPixel : unmanaged, IPixel
{
+ const int bytesPerPixel = 2;
int width = image.Width;
int height = image.Height;
- int bytesPerPixel = 2;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner row = allocator.Allocate(width * bytesPerPixel);
Span rowSpan = row.GetSpan();
@@ -107,9 +107,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void WriteRgb(Configuration configuration, Stream stream, ImageFrame image)
where TPixel : unmanaged, IPixel
{
+ const int bytesPerPixel = 3;
int width = image.Width;
int height = image.Height;
- int bytesPerPixel = 3;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner row = allocator.Allocate(width * bytesPerPixel);
Span rowSpan = row.GetSpan();
@@ -131,9 +131,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void WriteWideRgb(Configuration configuration, Stream stream, ImageFrame image)
where TPixel : unmanaged, IPixel
{
+ const int bytesPerPixel = 6;
int width = image.Width;
int height = image.Height;
- int bytesPerPixel = 6;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner row = allocator.Allocate(width * bytesPerPixel);
Span rowSpan = row.GetSpan();
diff --git a/src/ImageSharp/Formats/Pbm/PlainDecoder.cs b/src/ImageSharp/Formats/Pbm/PlainDecoder.cs
index 9fa8e513e0..dc5350bdd9 100644
--- a/src/ImageSharp/Formats/Pbm/PlainDecoder.cs
+++ b/src/ImageSharp/Formats/Pbm/PlainDecoder.cs
@@ -14,6 +14,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
///
internal class PlainDecoder
{
+ private static L8 white = new L8(255);
+ private static L8 black = new L8(0);
+
///
/// Decode the specified pixels.
///
@@ -174,8 +177,6 @@ namespace SixLabors.ImageSharp.Formats.Pbm
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner row = allocator.Allocate(width);
Span rowSpan = row.GetSpan();
- var white = new L8(255);
- var black = new L8(0);
for (int y = 0; y < height; y++)
{