[ome-users] Reading XResolution TiffTag rational

Melissa Linkert melissa at glencoesoftware.com
Thu Jan 28 18:37:07 GMT 2016


Hi Paul,

> 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

Thanks for reporting this, and for investigating.  That line is indeed
the problem - the file exposes an edge case where the TiffRational
numerator is large enough to overflow.  We're testing a fix now:

https://github.com/openmicroscopy/bioformats/pull/2221

Regards,
-Melissa

On Thu, Jan 28, 2016 at 04:21:07PM +0100, Paul van Schayck wrote:
> 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]));
> }


> _______________________________________________
> ome-users mailing list
> ome-users at lists.openmicroscopy.org.uk
> http://lists.openmicroscopy.org.uk/mailman/listinfo/ome-users



More information about the ome-users mailing list