Question

I've got a multipage tiff using jpeg compression.

When opening the file via libtiff.net I get following error message:

JPEGPreDecode: 
JPEG strip/tile size exceeds expected dimensions, expected 1164x1, got 1164x826.

The image processing fails. The file/directory has this tags:

OldSubFileType (1 Short): 1
ImageWidth (1 Long): 1164
ImageLength (1 Long): 826
BitsPerSample (3 Short): 8, 8, 8
Compression (1 Short): JPEG Technote #2
Photometric (1 Short): YCbCr
FillOrder (1 Short): Msb2Lsb
StripOffsets (1 Long): 224
SamplesPerPixel (1 Short): 3
StripByteCounts (1 Long): 109294
XResolution (1 Rational): 200
YResolution (1 Rational): 200
PlanarConfig (1 Short): Contig

With other jpeg compressed files I've no problems. Any ideas why I get the error? Why does it expect 1164x1?

Was it helpful?

Solution

Please make sure your files have ROWSPERSTRIP tag set.

Without this tag set, JPEG decoder might assume that height of strips in your image is incorrect.

Other option is to download source code of LibTiff.Net, set breakpoint at the beginning of JPEGPreDecode method in JpgeCodec.cs and see what goes wrong. Most probably, the following part of the method is causing the warnings and misbehaving of the codec:

if (segment_height > td.td_rowsperstrip)
    segment_height = td.td_rowsperstrip;

You might change this part of the method but it might be better to fix the files instead.

You might also try to add the tag yourselves (please note that you will need to set tag for each directory). Open the image, check the presence of the tag and try setting the correct value for the tag using 'SetField' method.

using (Tiff image = Tiff.Open(existingTiffName, "a"))
{
    for (int i = 0; i < image.NumberOfDirectories(); i++)
    {
        image.SetDirectory(i);
        ...

        FieldValue[] value = image.GetField(TiffTag.ROWSPERSTRIP);
        if (value == null)
        {
            // ROWSPERSTRIP is not set
            image.SetField(TiffTag.ROWSPERSTRIP, heightOfTheImage);
        }
        ...
    }
}

Please note that you should open image in append more (use "a" parameter for this).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top