PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Bug encoding CCITT bilevel images
https://forum.pdfsharp.net/viewtopic.php?f=3&t=2077
Page 1 of 1

Author:  BryceWagner [ Fri Jul 06, 2012 8:12 pm ]
Post subject:  Bug encoding CCITT bilevel images

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();
      }
    }

Author:  Thomas Hoevel [ Mon Jul 09, 2012 8:46 am ]
Post subject:  Re: Bug encoding CCITT bilevel images

Thank you for your feedback, bug will be fixed with the next release.

Author:  Modeus [ Thu Jun 05, 2014 8:38 am ]
Post subject:  Re: Bug encoding CCITT bilevel images

I see the above code fix has not been integrated into the source. And there hasn't been a release since this was posted, coming up on 2 years ago.

Is the above fix problematic? We've encountered the same issue and the fix appears to resolve, but if it has not been committed to the source I am wary of why.

Author:  Thomas Hoevel [ Thu Jun 05, 2014 3:52 pm ]
Post subject:  Re: Bug encoding CCITT bilevel images

Two years ago we thought we would publish a new release very dang soon.

We still want to publish a new release with improvements and bug fixes ASAP (I cannot give any EDA).

Nothing wrong with this correction in particular.

Author:  johnzered [ Fri Mar 20, 2015 1:07 pm ]
Post subject:  Re: Bug encoding CCITT bilevel images

Is this fixed in 1.50 Beta?

Author:  () => true [ Sat Mar 21, 2015 9:10 pm ]
Post subject:  Re: Bug encoding CCITT bilevel images

That bug should be fixed with 1.50 beta.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/