A request for help: TIFF writing

I also think both libtiff or exiv2 should handle this for you transparently…

E.g. TIFFTAG_XRESOLUTION is a RATIONAL, but TIFFSetField understands if (or even expects?) a float is passed as the argument.

1 Like

I think Exiv2 works alright, as long as I don’t try and copy allllll the EXIF data over.

For now I’m trying copying just the same 4, using Exiv2, and it seems to work, but I don’t have Photoshop to check for crashes…

I’d let L48-L58 be handled by exiv2 as well, you only need the libtiff lines above to define the image content/format before writing out the buffers.

As for what is “minimal” (and wether it goes into Exif.Image/IFD0 vs Exif.Photo/ExifIFD), just check Tables 17 and 18 in the Exif spec for what is mandatory.

Back from cabin-in-the-woods, where the internet proved to be another kind of dodgy…

  1. Inspecting my code brought forth recall of the original development journey. I remember now thinking, “nice, libtiff doesn’t require formatting a rational”, so I just let it save my internal float value thinking it would handle the dirty work. Bad assumption…

  2. Thinking about your original problem, based on my present understanding of exiv2 it now seems you were using the Exiv2 data structure you originally read from the input file, which for a raw would have contained the IFDs with the ancilliary renditions, thumbnails, embededd JPEGs, etc. Starting with a new Exiv2 instance and populating it for export should be alleviating that.

  3. Got me to re-consider using exiv2, but I’m coming back to the same conclusion: for renditions, I don’t want to pass on much past shutterspeed/aperture/ISO/date, and feel compelled to include orientation/photometricinterpretation for interoperability. Accordingly, I’m going to fix my present use of the libtiff/jpeg/png libraries (particularly exposuretime as a rational in TIFF) instead of using another library. If this doesn’t meet some ‘standard’ or other expectation, well, my first priority isn’t a customer base, anyway…

After investigation, it appears libtiff is writing a rational, exiftool -v confirms that.:

  | + [ExifIFD directory with 4 entries]
  | | 0)  ExposureTime = 0.001333329827 (5726608/4294967295)
  | | 1)  FNumber = 8 (8/1)
  | | 2)  ISO = 560
  | | 3)  FocalLength = 105 (105/1)

Not a pretty rational, but it is equivalent to 1/750sec…

Ah, so it’s just some applications not reading it correctly.

I did recall some people online mentioning that libtiff doesn’t do it very cleanly…