Skip to content

Commit 4e5dec9

Browse files
committed
Introduce variable for buffer.AsSpan(bufferStartIdx)
1 parent c61ce85 commit 4e5dec9

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero24TiffColor{TPixel}.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
3232
byte[] buffer = new byte[4];
3333
int bufferStartIdx = this.isBigEndian ? 1 : 0;
3434

35+
Span<byte> bufferSpan = buffer.AsSpan(bufferStartIdx);
3536
int offset = 0;
3637
for (int y = top; y < top + height; y++)
3738
{
@@ -40,7 +41,7 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
4041
{
4142
for (int x = 0; x < pixelRow.Length; x++)
4243
{
43-
data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
44+
data.Slice(offset, 3).CopyTo(bufferSpan);
4445
ulong intensity = TiffUtils.ConvertToUIntBigEndian(buffer);
4546
offset += 3;
4647

@@ -51,7 +52,7 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
5152
{
5253
for (int x = 0; x < pixelRow.Length; x++)
5354
{
54-
data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
55+
data.Slice(offset, 3).CopyTo(bufferSpan);
5556
ulong intensity = TiffUtils.ConvertToUIntLittleEndian(buffer);
5657
offset += 3;
5758

src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb242424TiffColor{TPixel}.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
3333
byte[] buffer = new byte[4];
3434
int bufferStartIdx = this.isBigEndian ? 1 : 0;
3535

36+
Span<byte> bufferSpan = buffer.AsSpan(bufferStartIdx);
3637
for (int y = top; y < top + height; y++)
3738
{
3839
Span<TPixel> pixelRow = pixels.GetRowSpan(y).Slice(left, width);
@@ -41,15 +42,15 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
4142
{
4243
for (int x = 0; x < pixelRow.Length; x++)
4344
{
44-
data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
45+
data.Slice(offset, 3).CopyTo(bufferSpan);
4546
ulong r = TiffUtils.ConvertToUIntBigEndian(buffer);
4647
offset += 3;
4748

48-
data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
49+
data.Slice(offset, 3).CopyTo(bufferSpan);
4950
ulong g = TiffUtils.ConvertToUIntBigEndian(buffer);
5051
offset += 3;
5152

52-
data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
53+
data.Slice(offset, 3).CopyTo(bufferSpan);
5354
ulong b = TiffUtils.ConvertToUIntBigEndian(buffer);
5455
offset += 3;
5556

@@ -60,15 +61,15 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
6061
{
6162
for (int x = 0; x < pixelRow.Length; x++)
6263
{
63-
data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
64+
data.Slice(offset, 3).CopyTo(bufferSpan);
6465
ulong r = TiffUtils.ConvertToUIntLittleEndian(buffer);
6566
offset += 3;
6667

67-
data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
68+
data.Slice(offset, 3).CopyTo(bufferSpan);
6869
ulong g = TiffUtils.ConvertToUIntLittleEndian(buffer);
6970
offset += 3;
7071

71-
data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
72+
data.Slice(offset, 3).CopyTo(bufferSpan);
7273
ulong b = TiffUtils.ConvertToUIntLittleEndian(buffer);
7374
offset += 3;
7475

src/ImageSharp/Formats/Tiff/PhotometricInterpretation/Rgb24PlanarTiffColor{TPixel}.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public override void Decode(IMemoryOwner<byte>[] data, Buffer2D<TPixel> pixels,
3636
Span<byte> redData = data[0].GetSpan();
3737
Span<byte> greenData = data[1].GetSpan();
3838
Span<byte> blueData = data[2].GetSpan();
39+
Span<byte> bufferSpan = buffer.AsSpan(bufferStartIdx);
3940

4041
int offset = 0;
4142
for (int y = top; y < top + height; y++)
@@ -45,11 +46,11 @@ public override void Decode(IMemoryOwner<byte>[] data, Buffer2D<TPixel> pixels,
4546
{
4647
for (int x = 0; x < pixelRow.Length; x++)
4748
{
48-
redData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
49+
redData.Slice(offset, 3).CopyTo(bufferSpan);
4950
ulong r = TiffUtils.ConvertToUIntBigEndian(buffer);
50-
greenData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
51+
greenData.Slice(offset, 3).CopyTo(bufferSpan);
5152
ulong g = TiffUtils.ConvertToUIntBigEndian(buffer);
52-
blueData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
53+
blueData.Slice(offset, 3).CopyTo(bufferSpan);
5354
ulong b = TiffUtils.ConvertToUIntBigEndian(buffer);
5455

5556
offset += 3;
@@ -61,11 +62,11 @@ public override void Decode(IMemoryOwner<byte>[] data, Buffer2D<TPixel> pixels,
6162
{
6263
for (int x = 0; x < pixelRow.Length; x++)
6364
{
64-
redData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
65+
redData.Slice(offset, 3).CopyTo(bufferSpan);
6566
ulong r = TiffUtils.ConvertToUIntLittleEndian(buffer);
66-
greenData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
67+
greenData.Slice(offset, 3).CopyTo(bufferSpan);
6768
ulong g = TiffUtils.ConvertToUIntLittleEndian(buffer);
68-
blueData.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
69+
blueData.Slice(offset, 3).CopyTo(bufferSpan);
6970
ulong b = TiffUtils.ConvertToUIntLittleEndian(buffer);
7071

7172
offset += 3;

src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero24TiffColor{TPixel}.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
3232
byte[] buffer = new byte[4];
3333
int bufferStartIdx = this.isBigEndian ? 1 : 0;
3434

35+
Span<byte> bufferSpan = buffer.AsSpan(bufferStartIdx);
3536
int offset = 0;
3637
for (int y = top; y < top + height; y++)
3738
{
@@ -40,7 +41,7 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
4041
{
4142
for (int x = 0; x < pixelRow.Length; x++)
4243
{
43-
data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
44+
data.Slice(offset, 3).CopyTo(bufferSpan);
4445
ulong intensity = TiffUtils.ConvertToUIntBigEndian(buffer);
4546
offset += 3;
4647

@@ -51,7 +52,7 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
5152
{
5253
for (int x = 0; x < pixelRow.Length; x++)
5354
{
54-
data.Slice(offset, 3).CopyTo(buffer.AsSpan(bufferStartIdx));
55+
data.Slice(offset, 3).CopyTo(bufferSpan);
5556
ulong intensity = TiffUtils.ConvertToUIntLittleEndian(buffer);
5657
offset += 3;
5758

0 commit comments

Comments
 (0)