1

I am reading a particular TIF file that reports a zero scanline size. The read operation returns null.

tiff = Tiff.ClientOpen("image", Stream.Length == 0 ? "w" : "ra", Stream, new TIFFTruncStream());

tiff == null, and the log contains a Zero scanline size trace message.

The .NET framework and some other viewers cannot open the file, We have managed to open the file(s) in some older IBM viewers. Is this definitely a corrupt file or just a scenario unsupported by LibTiff.NET?

Thanks

Jim
  • 14,952
  • 15
  • 80
  • 167
  • Most probably it's a corrupt file. But: is there any modern viewer available online that can open the file? – Bobrovsky Jul 03 '14 at 15:26
  • None that I have tried. What I really need to know is what zero scan line means, and if that's typically a sign of a corrupt file. – Jim Jul 09 '14 at 05:06
  • Zero scanline size is definitely not supported by libtiff/LibTiff.Net. It might be a corrupt file (some of the directories aka pages are broken) or there might be an error in the code that reads/computes the scanline size. Given that you are able to open this file in at least one viewer, I think the library can be adapted to read such files. You are welcome to send your file (with any additional screenshots etc.) to support@bitmiracle.com for further review. Without the file there is nothing more I can do, sorry. – Bobrovsky Jul 09 '14 at 10:16
  • @Babrovsky, don't you want to answer this question with a response indicating that the zero scan line is a corrupt image. I sent through the sample images, and you guys have confirmed its' corrupt. – Jim Aug 05 '14 at 11:08
  • Sure, it's just I wasn't able to find this questions until today :-) – Bobrovsky Aug 05 '14 at 15:54

1 Answers1

0

Zero scanline size is definitely not supported by libtiff/LibTiff.Net. I do not know about any other viewer that supports images with scanlines of zero length.

Jim sent us couple of such files and it turned out that the files are corrupt/broken. They specify zero width for their first page.

I tried to open these files in some other image viewers and only Preview utility in Mac OS X Mavericks could open them. The utility opens both files but silently skips the fist broken page. It shows not errors and acts like there is one less page in the files.

To achieve the same (silently skip first page), you can use the following workaround:

  1. Open the TIFF in append mode
  2. Set current page to be first page
  3. In a loop check the size of each page
  4. Skip any page with zero width or height

Below is a sample code for the workaround.

// "a" is for append
using (Tiff inImage = Tiff.Open(put-file-name-here, "a"))
{
    if (inImage == null)
        return;

    // move to the first page
    inImage.SetDirectory(0);

    do
    {
        FieldValue[] width = inImage.GetField(TiffTag.IMAGEWIDTH);
        FieldValue[] height = inImage.GetField(TiffTag.IMAGEWIDTH);
        if (width[0].ToInt() != 0 && height[0].ToInt() != 0)
        {
            // the page appears correct, do something with it
        }
    } while (inImage.ReadDirectory());
}
Bobrovsky
  • 13,789
  • 19
  • 80
  • 130