Skip to content

Commit 0ae95f1

Browse files
committed
Use pixel row span to access pixels
1 parent 6b538f8 commit 0ae95f1

11 files changed

+35
-23
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
3232
var l16 = default(L16);
3333
for (int y = top; y < top + height; y++)
3434
{
35+
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
3536
if (this.isBigEndian)
3637
{
3738
for (int x = left; x < left + width; x++)
3839
{
3940
ushort intensity = TiffUtils.ConvertToShortBigEndian(data.Slice(offset, 2));
4041
offset += 2;
4142

42-
pixels[x, y] = TiffUtils.ColorFromL16(l16, intensity, color);
43+
pixelRow[x] = TiffUtils.ColorFromL16(l16, intensity, color);
4344
}
4445
}
4546
else
@@ -49,7 +50,7 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
4950
ushort intensity = TiffUtils.ConvertToShortLittleEndian(data.Slice(offset, 2));
5051
offset += 2;
5152

52-
pixels[x, y] = TiffUtils.ColorFromL16(l16, intensity, color);
53+
pixelRow[x] = TiffUtils.ColorFromL16(l16, intensity, color);
5354
}
5455
}
5556
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5-
5+
using SixLabors.ImageSharp.Formats.Tiff.Utils;
66
using SixLabors.ImageSharp.Memory;
77
using SixLabors.ImageSharp.PixelFormats;
88

@@ -24,14 +24,11 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
2424
var l8 = default(L8);
2525
for (int y = top; y < top + height; y++)
2626
{
27+
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
2728
for (int x = left; x < left + width; x++)
2829
{
2930
byte intensity = data[offset++];
30-
31-
l8.PackedValue = intensity;
32-
color.FromL8(l8);
33-
34-
pixels[x, y] = color;
31+
pixelRow[x] = TiffUtils.ColorFromL8(l8, intensity, color);
3532
}
3633
}
3734
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
3434

3535
for (int y = top; y < top + height; y++)
3636
{
37+
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
3738
for (int x = left; x < left + width; x++)
3839
{
3940
int value = bitReader.ReadBits(this.bitsPerSample0);
4041
float intensity = value / this.factor;
4142

4243
color.FromVector4(new Vector4(intensity, intensity, intensity, 1.0f));
43-
pixels[x, y] = color;
44+
pixelRow[x] = color;
4445
}
4546

4647
bitReader.NextRow();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
3535

3636
for (int y = top; y < top + height; y++)
3737
{
38+
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
3839
for (int x = left; x < left + width; x++)
3940
{
4041
int index = bitReader.ReadBits(this.bitsPerSample0);
41-
pixels[x, y] = this.palette[index];
42+
pixelRow[x] = this.palette[index];
4243
}
4344

4445
bitReader.NextRow();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public override void Decode(IMemoryOwner<byte>[] data, Buffer2D<TPixel> pixels,
3535
var rgba = default(Rgba64);
3636
for (int y = top; y < top + height; y++)
3737
{
38+
System.Span<TPixel> pixelRow = pixels.GetRowSpan(y);
3839
if (this.isBigEndian)
3940
{
4041
for (int x = left; x < left + width; x++)
@@ -45,7 +46,7 @@ public override void Decode(IMemoryOwner<byte>[] data, Buffer2D<TPixel> pixels,
4546

4647
offset += 2;
4748

48-
pixels[x, y] = TiffUtils.ColorFromRgba64(rgba, r, g, b, color);
49+
pixelRow[x] = TiffUtils.ColorFromRgba64(rgba, r, g, b, color);
4950
}
5051
}
5152
else
@@ -58,7 +59,7 @@ public override void Decode(IMemoryOwner<byte>[] data, Buffer2D<TPixel> pixels,
5859

5960
offset += 2;
6061

61-
pixels[x, y] = TiffUtils.ColorFromRgba64(rgba, r, g, b, color);
62+
pixelRow[x] = TiffUtils.ColorFromRgba64(rgba, r, g, b, color);
6263
}
6364
}
6465
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4+
using System;
45
using System.Buffers;
56
using System.Numerics;
67
using SixLabors.ImageSharp.Formats.Tiff.Utils;
@@ -57,14 +58,15 @@ public override void Decode(IMemoryOwner<byte>[] data, Buffer2D<TPixel> pixels,
5758

5859
for (int y = top; y < top + height; y++)
5960
{
61+
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
6062
for (int x = left; x < left + width; x++)
6163
{
6264
float r = rBitReader.ReadBits(this.bitsPerSampleR) / this.rFactor;
6365
float g = gBitReader.ReadBits(this.bitsPerSampleG) / this.gFactor;
6466
float b = bBitReader.ReadBits(this.bitsPerSampleB) / this.bFactor;
6567

6668
color.FromVector4(new Vector4(r, g, b, 1.0f));
67-
pixels[x, y] = color;
69+
pixelRow[x] = color;
6870
}
6971

7072
rBitReader.NextRow();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
4747

4848
for (int y = top; y < top + height; y++)
4949
{
50+
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
5051
for (int x = left; x < left + width; x++)
5152
{
5253
float r = bitReader.ReadBits(this.bitsPerSampleR) / this.rFactor;
5354
float g = bitReader.ReadBits(this.bitsPerSampleG) / this.gFactor;
5455
float b = bitReader.ReadBits(this.bitsPerSampleB) / this.bFactor;
5556

5657
color.FromVector4(new Vector4(r, g, b, 1.0f));
57-
pixels[x, y] = color;
58+
pixelRow[x] = color;
5859
}
5960

6061
bitReader.NextRow();

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
3232
var l16 = default(L16);
3333
for (int y = top; y < top + height; y++)
3434
{
35+
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
3536
if (this.isBigEndian)
3637
{
3738
for (int x = left; x < left + width; x++)
3839
{
3940
ushort intensity = (ushort)(ushort.MaxValue - TiffUtils.ConvertToShortBigEndian(data.Slice(offset, 2)));
4041
offset += 2;
4142

42-
pixels[x, y] = TiffUtils.ColorFromL16(l16, intensity, color);
43+
pixelRow[x] = TiffUtils.ColorFromL16(l16, intensity, color);
4344
}
4445
}
4546
else
@@ -49,7 +50,7 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
4950
ushort intensity = (ushort)(ushort.MaxValue - TiffUtils.ConvertToShortLittleEndian(data.Slice(offset, 2)));
5051
offset += 2;
5152

52-
pixels[x, y] = TiffUtils.ColorFromL16(l16, intensity, color);
53+
pixelRow[x] = TiffUtils.ColorFromL16(l16, intensity, color);
5354
}
5455
}
5556
}

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
using System;
5-
5+
using SixLabors.ImageSharp.Formats.Tiff.Utils;
66
using SixLabors.ImageSharp.Memory;
77
using SixLabors.ImageSharp.PixelFormats;
88

@@ -24,14 +24,11 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
2424
var l8 = default(L8);
2525
for (int y = top; y < top + height; y++)
2626
{
27+
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
2728
for (int x = left; x < left + width; x++)
2829
{
2930
byte intensity = (byte)(255 - data[offset++]);
30-
31-
l8.PackedValue = intensity;
32-
color.FromL8(l8);
33-
34-
pixels[x, y] = color;
31+
pixelRow[x] = TiffUtils.ColorFromL8(l8, intensity, color);
3532
}
3633
}
3734
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, in
3434

3535
for (int y = top; y < top + height; y++)
3636
{
37+
Span<TPixel> pixelRow = pixels.GetRowSpan(y);
3738
for (int x = left; x < left + width; x++)
3839
{
3940
int value = bitReader.ReadBits(this.bitsPerSample0);
4041
float intensity = 1.0f - (value / this.factor);
4142

4243
color.FromVector4(new Vector4(intensity, intensity, intensity, 1.0f));
43-
pixels[x, y] = color;
44+
pixelRow[x] = color;
4445
}
4546

4647
bitReader.NextRow();

0 commit comments

Comments
 (0)