[ome-users] Reading XResolution TiffTag rational

Paul van Schayck paul at vanschayck.nl
Thu Jan 28 15:21:07 GMT 2016


Dear bioformat developers,

I've been trying to read the XResolution Tiff tag. However the
returned value seems to be incorrect. Attached you can find the file
I've been testing with.

The tags have been set using Matlab (using the wrapper functions
around libtiff-5) or using tiffset (libtiff-4). For example like this:

     $ tiffset -s XResolution 42.42 myfile.tif

Reading this file with BioFormats will not show any XResolution set.
Checking with tiffdump will show the 42.42 value. Something is wrong.

Diving deeper into the problem, I discovered that the Rational value
may not be read correctly.

    TiffRational xResolution = ifd.getIFDRationalValue(X_RESOLUTION);
    xResolution.toString();

This would return -1/101248644

There seems to be something wrong with the parsing of Rational value.
Possibly around this line:

https://github.com/openmicroscopy/bioformats/blob/develop/components/formats-bsd/src/loci/formats/tiff/TiffParser.java#L574


So I looked into the writing of the tiff tag in libtiff. I've attached
the code below. But I'm stuck here. I cannot figure out how change the
parsing of the rational value to match what is being done in libtiff.
Maybe I'm on completely the wrong path though.

Thanks,

Paul





static int
TIFFWriteDirectoryTagCheckedRational(TIFF* tif, uint32* ndir,
TIFFDirEntry* dir, uint16 tag, double value)
{
        uint32 m[2];
        assert(value>=0.0);
        assert(sizeof(uint32)==4);
        if (value<=0.0)
        {
                m[0]=0;
                m[1]=1;
        }
        else if (value==(double)(uint32)value)
        {
                m[0]=(uint32)value;
                m[1]=1;
        }
        else if (value<1.0)
        {
                m[0]=(uint32)(value*0xFFFFFFFF);
                m[1]=0xFFFFFFFF;
        }
        else
        {
                m[0]=0xFFFFFFFF;
                m[1]=(uint32)(0xFFFFFFFF/value);
        }
        if (tif->tif_flags&TIFF_SWAB)
        {
                TIFFSwabLong(&m[0]);
                TIFFSwabLong(&m[1]);
        }
        return(TIFFWriteDirectoryTagData(tif,ndir,dir,tag,TIFF_RATIONAL,1,8,&m[0]));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: myfile.tif
Type: image/tiff
Size: 254196 bytes
Desc: not available
URL: <http://lists.openmicroscopy.org.uk/pipermail/ome-users/attachments/20160128/4ad34570/attachment.tif>


More information about the ome-users mailing list