Browse Source

Make variables as const if possible

pull/1851/head
Ynse Hoornenborg 5 years ago
parent
commit
61cfa66bdb
  1. 13
      src/ImageSharp/Formats/Pbm/BinaryDecoder.cs
  2. 6
      src/ImageSharp/Formats/Pbm/BinaryEncoder.cs
  3. 5
      src/ImageSharp/Formats/Pbm/PlainDecoder.cs

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

@ -14,6 +14,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
/// </summary>
internal class BinaryDecoder
{
private static L8 white = new L8(255);
private static L8 black = new L8(0);
/// <summary>
/// Decode the specified pixels.
/// </summary>
@ -60,9 +63,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void ProcessGrayscale<TPixel>(Configuration configuration, Buffer2D<TPixel> pixels, BufferedReadStream stream)
where TPixel : unmanaged, IPixel<TPixel>
{
const int bytesPerPixel = 1;
int width = pixels.Width;
int height = pixels.Height;
int bytesPerPixel = 1;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner<byte> row = allocator.Allocate<byte>(width * bytesPerPixel);
Span<byte> rowSpan = row.GetSpan();
@ -82,9 +85,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void ProcessWideGrayscale<TPixel>(Configuration configuration, Buffer2D<TPixel> pixels, BufferedReadStream stream)
where TPixel : unmanaged, IPixel<TPixel>
{
const int bytesPerPixel = 2;
int width = pixels.Width;
int height = pixels.Height;
int bytesPerPixel = 2;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner<byte> row = allocator.Allocate<byte>(width * bytesPerPixel);
Span<byte> rowSpan = row.GetSpan();
@ -104,9 +107,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void ProcessRgb<TPixel>(Configuration configuration, Buffer2D<TPixel> pixels, BufferedReadStream stream)
where TPixel : unmanaged, IPixel<TPixel>
{
const int bytesPerPixel = 3;
int width = pixels.Width;
int height = pixels.Height;
int bytesPerPixel = 3;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner<byte> row = allocator.Allocate<byte>(width * bytesPerPixel);
Span<byte> rowSpan = row.GetSpan();
@ -126,9 +129,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void ProcessWideRgb<TPixel>(Configuration configuration, Buffer2D<TPixel> pixels, BufferedReadStream stream)
where TPixel : unmanaged, IPixel<TPixel>
{
const int bytesPerPixel = 6;
int width = pixels.Width;
int height = pixels.Height;
int bytesPerPixel = 6;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner<byte> row = allocator.Allocate<byte>(width * bytesPerPixel);
Span<byte> rowSpan = row.GetSpan();
@ -154,8 +157,6 @@ namespace SixLabors.ImageSharp.Formats.Pbm
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner<L8> row = allocator.Allocate<L8>(width);
Span<L8> rowSpan = row.GetSpan();
var white = new L8(255);
var black = new L8(0);
for (int y = 0; y < height; y++)
{

6
src/ImageSharp/Formats/Pbm/BinaryEncoder.cs

@ -83,9 +83,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void WriteWideGrayscale<TPixel>(Configuration configuration, Stream stream, ImageFrame<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel>
{
const int bytesPerPixel = 2;
int width = image.Width;
int height = image.Height;
int bytesPerPixel = 2;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner<byte> row = allocator.Allocate<byte>(width * bytesPerPixel);
Span<byte> rowSpan = row.GetSpan();
@ -107,9 +107,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void WriteRgb<TPixel>(Configuration configuration, Stream stream, ImageFrame<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel>
{
const int bytesPerPixel = 3;
int width = image.Width;
int height = image.Height;
int bytesPerPixel = 3;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner<byte> row = allocator.Allocate<byte>(width * bytesPerPixel);
Span<byte> rowSpan = row.GetSpan();
@ -131,9 +131,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
private static void WriteWideRgb<TPixel>(Configuration configuration, Stream stream, ImageFrame<TPixel> image)
where TPixel : unmanaged, IPixel<TPixel>
{
const int bytesPerPixel = 6;
int width = image.Width;
int height = image.Height;
int bytesPerPixel = 6;
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner<byte> row = allocator.Allocate<byte>(width * bytesPerPixel);
Span<byte> rowSpan = row.GetSpan();

5
src/ImageSharp/Formats/Pbm/PlainDecoder.cs

@ -14,6 +14,9 @@ namespace SixLabors.ImageSharp.Formats.Pbm
/// </summary>
internal class PlainDecoder
{
private static L8 white = new L8(255);
private static L8 black = new L8(0);
/// <summary>
/// Decode the specified pixels.
/// </summary>
@ -174,8 +177,6 @@ namespace SixLabors.ImageSharp.Formats.Pbm
MemoryAllocator allocator = configuration.MemoryAllocator;
using IMemoryOwner<L8> row = allocator.Allocate<L8>(width);
Span<L8> rowSpan = row.GetSpan();
var white = new L8(255);
var black = new L8(0);
for (int y = 0; y < height; y++)
{

Loading…
Cancel
Save