Skip to content

Commit 37033cd

Browse files
brianpopowgfoidl
andauthored
Apply suggestions from code review
Co-authored-by: Günther Foidl <[email protected]>
1 parent c6e0171 commit 37033cd

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

src/ImageSharp/Formats/Tiff/Compression/Decompressors/ModifiedHuffmanBitReader.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public ModifiedHuffmanBitReader(Stream input, TiffFillOrder fillOrder, int bytes
2626
}
2727

2828
/// <inheritdoc/>
29-
public override bool HasMoreData => this.Position < (ulong)this.DataLength - 1 || (this.BitsRead > 0 && this.BitsRead < 7);
29+
public override bool HasMoreData => this.Position < (ulong)this.DataLength - 1 || ((uint)(this.BitsRead - 1) < (7 - 1));
3030

3131
/// <inheritdoc/>
3232
public override bool IsEndOfScanLine
@@ -53,8 +53,8 @@ public override void StartNewRow()
5353
{
5454
base.StartNewRow();
5555

56-
int pad = 8 - (this.BitsRead % 8);
57-
if (pad != 8)
56+
int remainder = this.BitsRead & 7; // bit-hack for % 8
57+
if (remainder != 0)
5858
{
5959
// Skip padding bits, move to next byte.
6060
this.Position++;

src/ImageSharp/Formats/Tiff/Compression/Decompressors/T6BitReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public T6BitReader(Stream input, TiffFillOrder fillOrder, int bytesToRead, Memor
6363
}
6464

6565
/// <inheritdoc/>
66-
public override bool HasMoreData => this.Position < (ulong)this.DataLength - 1 || (this.BitsRead > 0 && this.BitsRead < 7);
66+
public override bool HasMoreData => this.Position < (ulong)this.DataLength - 1 || ((uint)(this.BitsRead - 1) < (7 - 1));
6767

6868
/// <summary>
6969
/// Gets or sets the two dimensional code.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ private uint WriteScanLine(Span<byte> buffer, Span<byte> scanLine, uint bitsWrit
8484
}
8585

8686
// Write padding bytes, if necessary.
87-
uint pad = 8 - (bitsWritten % 8);
88-
if (pad != 8)
87+
uint remainder = bitsWritten % 8;
88+
if (remainder != 0)
8989
{
9090
BitWriterUtils.WriteBits(buffer, (int)bitsWritten, pad, 0);
9191
bitsWritten += pad;

0 commit comments

Comments
 (0)