Skip to content

TIFF not recognized in newer versions of xdocreport #696

@alexanderveit

Description

@alexanderveit

It seems that at some time after version 1.0.3 support for TIFF images has been gone away.

In 1.0.3 it has been handled by fr.opensagres.xdocreport.document.images.SimpleImageInfo.processStream(InputStream)

private void processStream( InputStream is )
    throws IOException
{
    int c1 = is.read();
    int c2 = is.read();
    int c3 = is.read();

    mimeType = null;
    width = height = -1;

    if ( c1 == 'G' && c2 == 'I' && c3 == 'F' )
    { // GIF...
    }
    // ...
    else
    {
        int c4 = is.read();
        if ( ( c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42 ) || ( c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0 ) )
        { // TIFF
            boolean bigEndian = c1 == 'M';
            int ifd = 0;
            int entries;
            ifd = readInt( is, 4, bigEndian );
            is.skip( ifd - 8 );
            entries = readInt( is, 2, bigEndian );
            for ( int i = 1; i <= entries; i++ )
            {
                int tag = readInt( is, 2, bigEndian );
                int fieldType = readInt( is, 2, bigEndian );
                long count = readInt( is, 4, bigEndian );
                int valOffset;
                if ( ( fieldType == 3 || fieldType == 8 ) )
                {
                    valOffset = readInt( is, 2, bigEndian );
                    is.skip( 2 );
                }
                else
                {
                    valOffset = readInt( is, 4, bigEndian );
                }
                if ( tag == 256 )
                {
                    width = valOffset;
                }
                else if ( tag == 257 )
                {
                    height = valOffset;
                }
                if ( width != -1 && height != -1 )
                {
                    mimeType = ImageFormat.tiff;
                    break;
                }
            }
        }
    }
    if ( mimeType == null )
    {
        throw new IOException( "Unsupported image type" );
    }
}

In the current version of SimpleImageInfo there is no sign for TIFF support anymore.
https://github.com/opensagres/xdocreport/blob/02ca6b545f1867c29162ec4096bb1fa05ebb98ac/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/images/SimpleImageInfo.java

After updating to a newer version (1.0.6) this leads to the following exception when processing TIFF images.

java.io.IOException: Unable to read image info.
 at fr.opensagres.xdocreport.document.images.AbstractInputStreamImageProvider.loadImageInfo(AbstractInputStreamImageProvider.java:89) ~[fr.opensagres.xdocreport.document-1.0.6.jar:1.0.6]
 at fr.opensagres.xdocreport.document.images.AbstractImageProvider.getImageInfo(AbstractImageProvider.java:186) ~[fr.opensagres.xdocreport.document-1.0.6.jar:1.0.6]
 at fr.opensagres.xdocreport.document.images.AbstractImageProvider.getHeight(AbstractImageProvider.java:142) ~[fr.opensagres.xdocreport.document-1.0.6.jar:1.0.6]
 at fr.opensagres.xdocreport.document.images.AbstractImageRegistry.getHeight(AbstractImageRegistry.java:282) ~[fr.opensagres.xdocreport.document-1.0.6.jar:1.0.6]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions