2012.03.20 14:24 "[Tiff] Unable to read following tiff file", by Reg

2012.03.21 14:21 "Re: [Tiff] Unable to read following tiff file", by Reg

Thank you very much for your help

On 21/03/2012 09:37, Joris Van Damme (AWare Systems) wrote:

Frank wrote:

It doesn't
seem well behaved to me.

It is a weird file.

Here's a tag dump (best viewed as HTML).

> *Tag*         *Datatype*      *Count*         *Value*
> NewSubfileType 
> <http://www.awaresystems.be/imaging/tiff/tifftags/newsubfiletype.html>        Long 
>       1       0
> ImageWidth 
> <http://www.awaresystems.be/imaging/tiff/tifftags/imagewidth.html> 
> Long  1       2550
> ImageLength 
> <http://www.awaresystems.be/imaging/tiff/tifftags/imagelength.html>   Long 
>       1       3300
> BitsPerSample 
> <http://www.awaresystems.be/imaging/tiff/tifftags/bitspersample.html>         Short 
>       3       8, 8, 8
> Compression 
> <http://www.awaresystems.be/imaging/tiff/tifftags/compression.html> 
> Short         1       JPEG
> PhotometricInterpretation 
> <http://www.awaresystems.be/imaging/tiff/tifftags/photometricinterpretation.html> 
>       Short   1       YCbCr
> Orientation 
> <http://www.awaresystems.be/imaging/tiff/tifftags/orientation.html> 
> Short         1       TopLeft
> SamplesPerPixel 
> <http://www.awaresystems.be/imaging/tiff/tifftags/samplesperpixel.html> 
> Short         1       3
> XResolution 
> <http://www.awaresystems.be/imaging/tiff/tifftags/xresolution.html> 
> Rational      1       300
> YResolution 
> <http://www.awaresystems.be/imaging/tiff/tifftags/yresolution.html> 
> Rational      1       300
> PlanarConfiguration 
> <http://www.awaresystems.be/imaging/tiff/tifftags/planarconfiguration.html> 
>       Short   1       Chunky
> ResolutionUnit 
> <http://www.awaresystems.be/imaging/tiff/tifftags/resolutionunit.html>        Short 
>       1       Inch
> TileWidth 
> <http://www.awaresystems.be/imaging/tiff/tifftags/tilewidth.html> 
> Short         1       2550
> TileLength 
> <http://www.awaresystems.be/imaging/tiff/tifftags/tilelength.html> 
> Short         1       3300
> TileOffsets 
> <http://www.awaresystems.be/imaging/tiff/tifftags/tileoffsets.html>   Long 
>       1       1000
> TileByteCounts 
> <http://www.awaresystems.be/imaging/tiff/tifftags/tilebytecounts.html>        Long 
>       1       303600
> JPEGProc 
> <http://www.awaresystems.be/imaging/tiff/tifftags/jpegproc.html> 
> Short         1       Baseline
> JPEGInterchangeFormat 
> <http://www.awaresystems.be/imaging/tiff/tifftags/jpeginterchangeformat.html> 
>       Long    1       360
> JPEGInterchangeFormatLength 
> <http://www.awaresystems.be/imaging/tiff/tifftags/jpeginterchangeformatlength.html> 
>       Long    1       304240
> JPEGRestartInterval 
> <file:///C:/Users/Joris/Desktop/Nieuw%20tekstdocument.html>   Short   1       0
> Subsampling 
> <http://www.awaresystems.be/imaging/tiff/tifftags/ycbcrsubsampling.html> 
>       Short   2       2, 1
> SubsamplingPositioning 
> <http://www.awaresystems.be/imaging/tiff/tifftags/ycbcrpositioning.html> 
>       Short   1       Cosited
> ReferenceBlackWhite 
> <file:///C:/Users/Joris/Desktop/Nieuw%20tekstdocument.html> 
> Rational      6       0, 255, 128, 255, 128, 255

First thing you'll notice, apart from the odd tile sizes you mentioned already, is the presence of old-style JPEG tags combined with the new-style JPEG compression value of the Compression tag. And the uncommon value for SubsamplingPosition.

The strip data or in this case tile data is part of the JPEGInterchangeFormat stream, judging from the tag values, and that is not atypical of old-style JPEG. In such cases, the strip/tile data typically points to the compressed data portion of the JPEG stream, so, excluding all markers at the start and end of the JPEG stream. However, in this case they both end at the same position. Also, the actual TileOffset value, 1000, is suspicious, as such a nice round number seems to indicate the process of arriving at that number may have been somewhat arbitrary.

Investigating the JPEGInterchangeFormat stream, one does find a seemingly legit though truncates JPEG stream. Marker sequence is SOI, APP0, COM, DQT, DHT, SOF0, SOS, and this is followed by seemingly legit compressed image data. The presence of APP0 and COM markers is not at all correct, as these contain metadata that is useful in a JPEG file context but should not be there in a TIFF file context where all such metadata ought to be contained inside the TIFF IFD. But it is reasonably common nonetheless.

The markers furthermore indicate the presence of 3 channels in the stream, and subsampling values also consistent with what is indicated in the TIFF IFD.

The compressed image data starts at offset 640 in the stream. So, this is indeed offset 1000 in the TIFF file. Therefore, the TileOffsets value is not arbitrary after all, it does point to the start of the compressed image data, as is not uncommon for old-style JPEG, though of course not legit for new-style JPEG.

The compressed data in the stream is prematurely truncated. There are no usual trailing markers in the stream.

The premature truncation does not appear to have originated at TIFF level.

The file size is 304600 bytes, that is consistent with the values of the TIleOffsets, TileByteCounts, and JpegInterchangeFormat tags.

All this leads me to the conclusion that this file is probably a very bad attempt at encapsulating a truncated JPEG file. Done by people that don't read standards and ended up mixing old-style and new-style JPEG stuff in a very creative manner. The JPEG stream COM marker says "LEAD Technologies Inc. V1.01", and we're used to seeing garbadge from LEAD libraries trying to write JPEG-compressed TIFF files, so maybe that's some indication as to who is to blame for this junk.

It is also likely that LibTIFF (or LibTIFF RGBA interface) fails in these circumstances, either because it finds no required table markers at the position pointed to by TilfOffsets, or either because it fails to respond properly the LibJPEG erroring out at premature EOF. It could do better, by using the JPEGInterchangeFormat stream when it fails to find all required data in the Tile stream, and/or by responding more robustly to LibJPEG's error indication near the end of the image data, but it is absolutely not required to do better, as the file is far from legit.

Or maybe LibTIFF RGBA interface fails because it rightly thinks it cannot support the uncommon SubsamplingPosition value when it relies on LibJPEG to do the de-subsampling. In this case it could and should do better by not delegating de-subsampling to LibJPEG, as has always been my point of view because subsampling can actually be combined with any compression mode in TIFF.