Browse Source

Use nint, determine what's white only once

pull/2134/head
Brian Popow 4 years ago
parent
commit
2876f2f44d
  1. 2
      src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittReferenceScanline.cs
  2. 8
      src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6TiffCompression.cs

2
src/ImageSharp/Formats/Tiff/Compression/Decompressors/CcittReferenceScanline.cs

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Runtime.CompilerServices;
namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
{ {
@ -130,6 +131,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
return index + offset; return index + offset;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private int FindB2ForImaginaryWhiteLine() => this.width; private int FindB2ForImaginaryWhiteLine() => this.width;
private int FindB2ForNormalLine(int b1) private int FindB2ForNormalLine(int b1)

8
src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6TiffCompression.cs

@ -19,6 +19,8 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
private readonly int width; private readonly int width;
private readonly byte white;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="T6TiffCompression" /> class. /// Initializes a new instance of the <see cref="T6TiffCompression" /> class.
/// </summary> /// </summary>
@ -38,6 +40,7 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
this.FillOrder = fillOrder; this.FillOrder = fillOrder;
this.width = width; this.width = width;
this.isWhiteZero = photometricInterpretation == TiffPhotometricInterpretation.WhiteIsZero; this.isWhiteZero = photometricInterpretation == TiffPhotometricInterpretation.WhiteIsZero;
this.white = (byte)(this.isWhiteZero ? 0 : 255);
} }
/// <summary> /// <summary>
@ -72,12 +75,11 @@ namespace SixLabors.ImageSharp.Formats.Tiff.Compression.Decompressors
private uint WriteScanLine(Span<byte> buffer, Span<byte> scanLine, uint bitsWritten) private uint WriteScanLine(Span<byte> buffer, Span<byte> scanLine, uint bitsWritten)
{ {
byte white = (byte)(this.isWhiteZero ? 0 : 255);
int bitPos = (int)(bitsWritten % 8); int bitPos = (int)(bitsWritten % 8);
int bufferPos = (int)(bitsWritten / 8); int bufferPos = (int)(bitsWritten / 8);
for (int i = 0; i < scanLine.Length; i++) for (nint i = 0; i < scanLine.Length; i++)
{ {
if (Unsafe.Add(ref MemoryMarshal.GetReference(scanLine), i) != white) if (Unsafe.Add(ref MemoryMarshal.GetReference(scanLine), i) != this.white)
{ {
BitWriterUtils.WriteBit(buffer, bufferPos, bitPos); BitWriterUtils.WriteBit(buffer, bufferPos, bitPos);
} }

Loading…
Cancel
Save