From 4e5dec9f4f75f779456d43134729b73f2213acee Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Thu, 5 Aug 2021 12:47:03 +0200 Subject: [PATCH] Introduce variable for buffer.AsSpan(bufferStartIdx) --- .../BlackIsZero24TiffColor{TPixel}.cs | 5 +++-- .../Rgb242424TiffColor{TPixel}.cs | 13 +++++++------ .../Rgb24PlanarTiffColor{TPixel}.cs | 13 +++++++------ .../WhiteIsZero24TiffColor{TPixel}.cs | 5 +++-- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero24TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero24TiffColor{TPixel}.cs index 813d7beb5..ec07abd5c 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero24TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero24TiffColor{TPixel}.cs @@ -32,6 +32,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation byte[] buffer = new byte[4]; int bufferStartIdx = this.isBigEndian ? 1 : 0; + Span bufferSpan = buffer.AsSpan(bufferStartIdx); int offset = 0; for (int y = top; y < top + height; y++) { @@ -40,7 +41,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { for (int x = 0; x < pixelRow.Length; x++) { - data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + data.Slice(offset, 3).CopyTo(bufferSpan); ulong intensity = TiffUtils.ConvertToUIntBigEndian(buffer); offset += 3; @@ -51,7 +52,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { for (int x = 0; x < pixelRow.Length; x++) { - data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + data.Slice(offset, 3).CopyTo(bufferSpan); ulong intensity = TiffUtils.ConvertToUIntLittleEndian(buffer); offset += 3; diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb242424TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb242424TiffColor{TPixel}.cs index abc3a82a9..3be0540a0 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb242424TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb242424TiffColor{TPixel}.cs @@ -33,6 +33,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation byte[] buffer = new byte[4]; int bufferStartIdx = this.isBigEndian ? 1 : 0; + Span bufferSpan = buffer.AsSpan(bufferStartIdx); for (int y = top; y < top + height; y++) { Span pixelRow = pixels.GetRowSpan(y).Slice(left, width); @@ -41,15 +42,15 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { for (int x = 0; x < pixelRow.Length; x++) { - data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + data.Slice(offset, 3).CopyTo(bufferSpan); ulong r = TiffUtils.ConvertToUIntBigEndian(buffer); offset += 3; - data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + data.Slice(offset, 3).CopyTo(bufferSpan); ulong g = TiffUtils.ConvertToUIntBigEndian(buffer); offset += 3; - data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + data.Slice(offset, 3).CopyTo(bufferSpan); ulong b = TiffUtils.ConvertToUIntBigEndian(buffer); offset += 3; @@ -60,15 +61,15 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { for (int x = 0; x < pixelRow.Length; x++) { - data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + data.Slice(offset, 3).CopyTo(bufferSpan); ulong r = TiffUtils.ConvertToUIntLittleEndian(buffer); offset += 3; - data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + data.Slice(offset, 3).CopyTo(bufferSpan); ulong g = TiffUtils.ConvertToUIntLittleEndian(buffer); offset += 3; - data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + data.Slice(offset, 3).CopyTo(bufferSpan); ulong b = TiffUtils.ConvertToUIntLittleEndian(buffer); offset += 3; diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb24PlanarTiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb24PlanarTiffColor{TPixel}.cs index cd94f8e81..9c3e57e2a 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb24PlanarTiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb24PlanarTiffColor{TPixel}.cs @@ -36,6 +36,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation Span redData = data[0].GetSpan(); Span greenData = data[1].GetSpan(); Span blueData = data[2].GetSpan(); + Span bufferSpan = buffer.AsSpan(bufferStartIdx); int offset = 0; for (int y = top; y < top + height; y++) @@ -45,11 +46,11 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { for (int x = 0; x < pixelRow.Length; x++) { - redData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + redData.Slice(offset, 3).CopyTo(bufferSpan); ulong r = TiffUtils.ConvertToUIntBigEndian(buffer); - greenData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + greenData.Slice(offset, 3).CopyTo(bufferSpan); ulong g = TiffUtils.ConvertToUIntBigEndian(buffer); - blueData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + blueData.Slice(offset, 3).CopyTo(bufferSpan); ulong b = TiffUtils.ConvertToUIntBigEndian(buffer); offset += 3; @@ -61,11 +62,11 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { for (int x = 0; x < pixelRow.Length; x++) { - redData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + redData.Slice(offset, 3).CopyTo(bufferSpan); ulong r = TiffUtils.ConvertToUIntLittleEndian(buffer); - greenData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + greenData.Slice(offset, 3).CopyTo(bufferSpan); ulong g = TiffUtils.ConvertToUIntLittleEndian(buffer); - blueData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + blueData.Slice(offset, 3).CopyTo(bufferSpan); ulong b = TiffUtils.ConvertToUIntLittleEndian(buffer); offset += 3; diff --git a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero24TiffColor{TPixel}.cs b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero24TiffColor{TPixel}.cs index 143a684c2..b1088732b 100644 --- a/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero24TiffColor{TPixel}.cs +++ b/src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero24TiffColor{TPixel}.cs @@ -32,6 +32,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation byte[] buffer = new byte[4]; int bufferStartIdx = this.isBigEndian ? 1 : 0; + Span bufferSpan = buffer.AsSpan(bufferStartIdx); int offset = 0; for (int y = top; y < top + height; y++) { @@ -40,7 +41,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { for (int x = 0; x < pixelRow.Length; x++) { - data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + data.Slice(offset, 3).CopyTo(bufferSpan); ulong intensity = TiffUtils.ConvertToUIntBigEndian(buffer); offset += 3; @@ -51,7 +52,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation { for (int x = 0; x < pixelRow.Length; x++) { - data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx)); + data.Slice(offset, 3).CopyTo(bufferSpan); ulong intensity = TiffUtils.ConvertToUIntLittleEndian(buffer); offset += 3;