TagInfo: How to determine the array length of an Exif item?
Added by Matthias Baas over 11 years ago
Hi,
I'm using the TagInfo structs provided by the exiv2 library to get information about Exif keys (to validate user input). I can get the data type that is expected by the Exif standard but the TagInfo struct doesn't contain the number of values required. Shouldn't that "count" value be part of the TagInfo as well so that the type information is complete?
For example, the ReferenceBlackWhite value is an array of 6 rational values but from the TagInfo struct I can only determine that its base type is rational but I haven't seen a way of finding out that this is actually an array of 6 elements.
So would it make sense to add a "count" member to the TagInfo struct?
Cheers,
- Matthias -
Replies (6)
RE: TagInfo: How to determine the array length of an Exif item? - Added by Andreas Huggel over 11 years ago
Well, yes, that information is not recorded in the taglists and it would make the tag reference more complete. It would be a lot of work to add that information as it would need to be researched for makernote tags.
Andreas
RE: TagInfo: How to determine the array length of an Exif item? - Added by Matthias Baas over 11 years ago
Hm, the makernotes aren't standardized anyway, are they? So it might be a bit difficult getting this information for all tags.
But at least in my case, it would be enough if I have that information only for the standard tags. After all, the makernote tags are written by the camera and once they are in the file, I can get the information from the file.
So maybe that "count" field could contain -1 in the case when the correct number is not known and in all other cases it specifies the value from any known standard.
I had a look at the code and it seems quite straightforward adding such a field (it's just a bit tedious changing all the tables). So as this is Open Source, would you accept a patch that adds such a field even though the makernote tags will only be set to -1? If so, I'll give it a go myself and post the patch once I'm done.
Cheers,
- Matthias -
RE: TagInfo: How to determine the array length of an Exif item? - Added by Matthias Baas about 11 years ago
I had a bit of time this weekend and added that count field I was talking about to the TagInfo struct. I have attached the patch (against rev2327) to this message. Please let me know if you are going to accept the patch. If not, I'll just add that information directly to my application.
I set the count member to -1 if no value is known (all makernote tags currently have this value). In this case, an application is in the same situation as it has been before this change. If the count value is 0, then it means the value can take any number of items (it's mostly strings that use this value). A positive count value means the item takes exactly this number of elements.
I took the information from various specs (Exif, DNG, TIFF, ...) and refrained from guessing values, so some non-makernote tags are also set to -1 (for example, those Windows XP* tags. I didn't find any definitive information about them).
There are also some values whose count value is not just a constant value but derived from other properties or it can take one of several values. For example, some of the TIFF fields have a count value which is the number of samples per pixel, the DNG tags have a similar thing or the Exif "SubjectArea" value takes either 2, 3 or 4 values. So in all these cases, I set the count member to -1 as well.
- Matthias -
| count_patch.diff.zip (55.7 KB) count_patch.diff.zip |
RE: TagInfo: How to determine the array length of an Exif item? - Added by Andreas Huggel about 11 years ago
Hi Matthias,
Thanks for your patch and apologis for the late reply. What you write sounds good, I'm interested in this patch, just haven't had time to look into it in detail.
I should be able to do this over the next few days. Are you willing to assign the copyright of the change to me? That is what I require for all contributions so that I can continue to dual-license the library.
Thanks,
Andreas
RE: TagInfo: How to determine the array length of an Exif item? - Added by Matthias Baas about 11 years ago
Andreas Huggel wrote:
Thanks for your patch and apologis for the late reply. What you write sounds good, I'm interested in this patch, just haven't had time to look into it in detail.
No worries. I know, the patch is fairly large as I had to change all those TagInfo instantiations. Apart from that, the only real code change is adding the data member and changing the constructor.
Are you willing to assign the copyright of the change to me? That is what I require for all contributions so that I can continue to dual-license the library.
Sure, no problem.
Thanks,
- Matthias -
RE: TagInfo: How to determine the array length of an Exif item? - Added by Andreas Huggel about 11 years ago
Done with r2332.
Andreas