It appears there is a bug in PdfImage.FaxEncode.cs. The "CountZeroBits" and "CountOneBits" does not properly detect the right edge in certain circumstances where the width is not divisible by 8. Basically it confuses the encoder so it thinks the current line is different length from the previous line.
I fixed it by replacing "return found + hits;" with the following code:
Code:
found += hits;
if (found >= bitsLeft)
return bitsLeft;
return found;
Code:
private static uint CountOneBits(BitReader reader, uint bitsLeft)
{
uint found = 0;
for (; ; )
{
uint bits;
int @byte = reader.PeekByte(out bits);
uint hits = OneRuns[@byte];
if (hits < bits)
{
if (hits > 0)
reader.SkipBits(hits);
found += hits;
if (found >= bitsLeft)
return bitsLeft;
return found;
}
found += bits;
if (found >= bitsLeft)
return bitsLeft;
reader.NextByte();
}
}
Code:
private static uint CountZeroBits(BitReader reader, uint bitsLeft)
{
uint found = 0;
for (; ; )
{
uint bits;
int @byte = reader.PeekByte(out bits);
uint hits = ZeroRuns[@byte];
if (hits < bits)
{
if (hits > 0)
reader.SkipBits(hits);
found += hits;
if (found >= bitsLeft)
return bitsLeft;
return found;
}
found += bits;
if (found >= bitsLeft)
return bitsLeft;
reader.NextByte();
}
}