Use libexiv2 to parse TIFF-file and extract IFD?
Added by Anonymous Poster over 6 years ago
Hi,
I'm working on a DNG-converter for Sony's ARW raw files. I'm already using libexiv2 to read the ARW's EXIF/XMP data. How (if at all) can I use libexiv2 to extract a single IFD from the ARW (Tiff-format) as a binary stream/buffer?
Background: I would like to preserve Sony's proprietary information in a DNGPrivate data field. Sony cameras write their prop information in 2 places
- their MakerNote
- a special "SR2"-IFD in the raw-file (with multiple sub-IFDs) with about 56 kb of data
The former, I can read fine through Exiv2::ExifData and the "Exif.Photo.MakerNote" (plus Exif.MakerNote.Offset, Exif.MakerNote.ByteOrder) tags. I'm struggling with the latter. I've been reading through the API docs and the TIFF-classes but am a bit confused. Ideally, I would construct the TIFF-structure "tree" and then extract one IFD as a binary stream.
Is this possible with libexiv2? Would appreciate any pointers.
Many thanks!
Replies (11)
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Gilles Caulier over 6 years ago
Hi,
Do you will write an open source DNG conveter or a closed source ?
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Anonymous Poster over 6 years ago
I'm not starting from scratch but am building on https://github.com/jmue/dngconvert, which I believe is based on your Digikam work.
My goal is just to optimise the code base for my Sony A7's raw files and bring it as close to Adobe's DNG-converter as possible (e.g., decoding the embedded lens profiles, etc). Had only my own use in mind but happy to publish back if anybody is interested.
Thanks for your work btw - wouldn't have been able to start this from scratch! Your old blog-entries were also helpful to get into the topic.
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Gilles Caulier over 6 years ago
Absolutely. Jens has work on digiKam DNGConverter.
The last code is in kipi tool. Why not to help us to improve this code instead to work on a forked implementation. As I use Sony Camera, i'm interested by this topic...
Gilles Caulier
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Gilles Caulier over 6 years ago
And to respond to you original question i think yes it's possible. I remember to have played with private TIFF tag in DNGConverter.
Gilles Caulier
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Anonymous Poster over 6 years ago
Sure. If you're interested in the Sony-format, I have documented my findings on the embedded lens-correction data in 3 postings here: https://variousphotography.wordpress.com/
If anybody could point me to the right entry class to parse the Tiff-file and extract the IFD, would be really helpful. Thanks!
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Gilles Caulier over 6 years ago
Look in DNG converter core code. It's a low level implementation. You have also a CLI tool to not use GUI :
In extra sub folder you will found DNG sdk and XMP sdk from Adobe. You can forget these parts. The main class is DNGWriter, and especially here :
...where Sony markernotes must be migrated from ARW to DNG.
Look also here :
...where private markernotes TIFF tag is copied from original RAW.
In this code we use KPMetadata class, which is based on libkexiv2, which is a C++ wrapper for Exiv2 library :
https://projects.kde.org/projects/kde/kdegraphics/libs/libkexiv2/repository
All patches are welcome for DNGWriter
Gilles Caulier
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Anonymous Poster over 6 years ago
Thanks, I'm reusing that code. My problem is that Sony has proprietary information in 2 places (the MakerNote and another 'SR2'-IFD in the file). Your code copies the MakerNote fine (into the Adobe 'MakN' blob), Adobe's DNG-converter also copies the additional IFD (into an Adobe "SR2 " blob - can also be seen in the DNG SDK - dng_info.cpp). Since, I want to stay close to Adobe's version, I'm trying to add that (you can argue what's the 'right' behaviour, since the DNG-specification doesn't anything about it - but Adobe's process is "standard" when it comes to DNGs).
However, after re-reading the Exiftool (which can read this IFD) code/docs and spending some more time in a hex-editor, I realised that Sony stores the IFD-offset in a non-standard way under the DNGPrivateData tag. To my understanding, Exiv2 can currently not decode that, so will try to develop my own parsing.
Thanks for your help so far!
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Gilles Caulier over 6 years ago
Thanks, I'm reusing that code. My problem is that Sony has proprietary information in 2 places (the MakerNote and another 'SR2'-IFD in the file). Your code copies the MakerNote fine (into the Adobe 'MakN' blob), Adobe's DNG-converter also copies the >additional IFD (into an Adobe "SR2 " blob - can also be seen in the DNG SDK - dng_info.cpp). Since, I want to stay close to Adobe's version, I'm trying to add that (you can argue what's the 'right' behaviour, since the DNG-specification doesn't anything about it >- but Adobe's process is "standard" when it comes to DNGs).
well, it's a too specifc task for a simple RAW to DNG converter. It out of my mind when i designed this tool.
However, after re-reading the Exiftool (which can read this IFD) code/docs and spending some more time in a hex-editor, I realised that Sony stores the IFD-offset in a non-standard way under the DNGPrivateData tag. To my understanding, Exiv2 can currently >not decode that, so will try to develop my own parsing.
Well, this issue is a specific feature for Exiv2. Or perhaps somebody as Andreas who know better than me Exiv2 code arcane can give some pointer about this problem.
Thanks for your help so far!
In all cases, if you have patch for DNGConverter to improve it, i will be happy to review and include in repository.
Best
Gilles Caulier
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Alan Pater over 6 years ago
Anonymous Poster wrote:
To my understanding, Exiv2 can currently not decode that, so will try to develop my own parsing.
Please contribute your changes back to exiv2 so that everyone can benefit rather then having to re-invent the wheel.
The wiki has details on getting and building the source code: http://dev.exiv2.org/projects/exiv2/wiki
To get started:
$ svn checkout svn://dev.exiv2.org/svn/trunk
You are probably best running the latest code from trunk for the type of project you are working on anyway.
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Alan Pater over 6 years ago
Anonymous, how is the parsing going?
Also wondering if you have seen the documentation on TIFF files on the exiv2 wiki?
[[http://dev.exiv2.org/projects/exiv2/wiki/The_Metadata_in_TIFF_files]]
RE: Use libexiv2 to parse TIFF-file and extract IFD? - Added by Anonymous Poster over 6 years ago
Thanks. Hadn't seen it but I have solved my problem by now with some workarounds.
Basically in Sony ARWs, the DNGPrivateDataTag points to a "SR2"-IFD, containing (amongst other things) offset, length and encryption tags for a SubIFD, which contains the proprietary data I'm after.
I'm reading the SR2-IFD through BasicIO, then create a 'fake' TIFF-header and ending around it, feed the whole thing into TiffParser::decode, extract the relevant tags through ExifData.findKey() and read the final SubIFD again through BasicIO.
Bit complex but works. :-)