Browse Source

Use GetRowSpan to access pixel data

pull/2134/head
Brian Popow 4 years ago
parent
commit
8459828aad
  1. 13
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs
  2. 13
      src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs

13
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/BlackIsZero1TiffColor{TPixel}.cs

@ -17,14 +17,15 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
/// <inheritdoc/> /// <inheritdoc/>
public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height) public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height)
{ {
var color = default(TPixel);
int offset = 0; int offset = 0;
var colorBlack = default(TPixel);
var colorWhite = default(TPixel);
Color black = Color.Black; colorBlack.FromRgba32(Color.Black);
Color white = Color.White; colorWhite.FromRgba32(Color.White);
for (int y = top; y < top + height; y++) for (int y = top; y < top + height; y++)
{ {
Span<TPixel> pixelRowSpan = pixels.DangerousGetRowSpan(y);
for (int x = left; x < left + width; x += 8) for (int x = left; x < left + width; x += 8)
{ {
byte b = data[offset++]; byte b = data[offset++];
@ -34,9 +35,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
{ {
int bit = (b >> (7 - shift)) & 1; int bit = (b >> (7 - shift)) & 1;
color.FromRgba32(bit == 0 ? black : white); pixelRowSpan[x + shift] = bit == 0 ? colorBlack : colorWhite;
pixels[x + shift, y] = color;
} }
} }
} }

13
src/ImageSharp/Formats/Tiff/PhotometricInterpretation/WhiteIsZero1TiffColor{TPixel}.cs

@ -16,14 +16,15 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
/// <inheritdoc/> /// <inheritdoc/>
public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height) public override void Decode(ReadOnlySpan<byte> data, Buffer2D<TPixel> pixels, int left, int top, int width, int height)
{ {
var color = default(TPixel);
int offset = 0; int offset = 0;
var colorBlack = default(TPixel);
var colorWhite = default(TPixel);
Color black = Color.Black; colorBlack.FromRgba32(Color.Black);
Color white = Color.White; colorWhite.FromRgba32(Color.White);
for (int y = top; y < top + height; y++) for (int y = top; y < top + height; y++)
{ {
Span<TPixel> pixelRowSpan = pixels.DangerousGetRowSpan(y);
for (int x = left; x < left + width; x += 8) for (int x = left; x < left + width; x += 8)
{ {
byte b = data[offset++]; byte b = data[offset++];
@ -33,9 +34,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.PhotometricInterpretation
{ {
int bit = (b >> (7 - shift)) & 1; int bit = (b >> (7 - shift)) & 1;
color.FromRgba32(bit == 0 ? white : black); pixelRowSpan[x + shift] = bit == 0 ? colorWhite : colorBlack;
pixels[x + shift, y] = color;
} }
} }
} }

Loading…
Cancel
Save