Opened 17 years ago

Closed 17 years ago

#1483 closed defect (invalid)

Bug in TIFF reading (with EXIF JPEG preview)

Reported by: seth@… Owned by: warmerdam
Priority: normal Milestone:
Component: GDAL_Raster Version: 1.4.0
Severity: normal Keywords:
Cc:

Description (last modified by warmerdam)

I have an error with some large (geo)tiffs that I'm working with. I've generated them with georeferenced info via the GDAL utilities, then I want to add an overview image (like a preview) using the gdaladdo utility. If I use exiftool to add a preview first, gdaladdo reports an error in the file format. See the commands below:

"
Pine06:~ sage$ cp orig.tif exif_tooled.tif
Pine06:~ sage$ cp orig.tif no_exiftool.tif
Pine06:~ sage$ ./gdaladdo -r average no_exiftool.tif 16 32
0...10...20...30...40...50...60...70...80...90...100 - done.
Pine06:~ sage$ ./exiftool '-ThumbnailImage<=thumb.jpg' exif_tooled.tif
Pine06:~ sage$ ./gdaladdo -r average exif_tooled.tif 16 32
ERROR 1: MissingRequired:exif_tooled.tif: TIFF directory is missing required "ImageLength" field
0ERROR 1: MissingRequired:exif_tooled.tif: TIFF directory is missing required "ImageLength" field
...10...20...30...40...50...60...70...80...90...100 - done.
"

At first I thought that it was a bug in exiftool, so I emailed the author. It looks like it's actually a bug with GDAL (or libtiff) expecting tags that aren't required for an EXIF image preview. Here is his full reply:

" Unfortunately the EXIF specification defines a number of mandatory tags. ExifTool fills in all of the ones that it can (as you can see from the output), but some it must leave to hte user. Noteably, the ExifImageWidth and ExifImageHeight in the ExifIFD are not written automatically. (But I have never seen an application that will complain if these are missing.)

In your case, however, ExifTool is adding IFD1, not the ExifIFD. According to the specification, ImageWidth and ImageLength are only required in IFD1 for uncompressed images. For compressed thumbnails (ie. JPEG), the only mandatory tags are:

And these are exactly what is written.

So in this case, I think the fault is in gdaladdo, and you should send a bug report to them along with a sample image.

You can try this to see if my deduction is correct: Write IFD1:ImageWidth and IFD1:ImageHeight to see if the gdaladdo warning disappears. If it does, it is a gdaladdo bug. "

I followed his recommendation with setting the height and width, and GDAL threw a new error:

Pine06:~ sage$ ./exiftool -v5 '-ThumbnailImage<=thumb.jpg' -IFD1:ImageWidth=512 -IFD1:ImageHeight=512 exif_tooled.tif
Pine06:~ sage$ ./gdaladdo -r average exif_tooled.tif 16 32
ERROR 1: MissingRequired:exif_tooled.tif: TIFF directory is missing required "StripOffsets" field
0ERROR 1: MissingRequired:exif_tooled.tif: TIFF directory is missing required "StripOffsets" field
...10...20...30...40...50...60...70...80...90...100 - done.

Change History (1)

comment:2 by warmerdam, 17 years ago

Component: defaultGDAL_Raster
Description: modified (diff)
Priority: highestnormal
Resolution: invalid
Status: newclosed

Seth,

The message you are seeing is produced by libtiff.

I haven't dug into it in detail, but to the best of my understanding the TIFF specification requires every image directory to have the image width and height tags. If you are producing an EXIF directory in the "main directory chain" of the TIFF file you are required to adhere to the TIFF specification regardless of what the EXIF specification may say (IMHO).

So, I'm inclined to bounce this back to the exif tool author.

In any event, it isn't a GDAL issue. The closest it gets to GDAL is libtiff.

Tentatively closing this, but feel free to re-open it if there is reason to believe there is a GDAL issue.

Note: See TracTickets for help on using tickets.