Byte order in Canon Maker note section

Started by mvadu, September 25, 2010, 11:47:31 AM

Previous topic - Next topic

mvadu

Hi, is the Byte Order given in Exif header applicable to Maker Note section as well?

I am writing GUI application using C++ to catalog images. I could read all standard tags defined in Exif spec. (Thank you so much for -h -v switch Phil, it helped me a lot to compare my results.) Now I am trying to read/decode makernote section, and facing issues with byte order.

I have Canon T1i, and the image is imported via standard import wizard in Windows 7. The byte order in Exif header is Motorola(Big-endian), and all the exif tags follow that endianness. Suddenly inside makernote section starting from No of Entries tag it switches to Intel(little-endian) format. Is it common in Canon? or Windows import screwed my image?

Also is there any way to definitely determine Byte Order for the makernote section?

Phil Harvey

Straight out of the camera, the makernote byte order is likely to be the same as the main EXIF.  But I have seen some image editors that change the order of the EXIF but not the maker notes, so ExifTool makes no assumptions.  I use a heuristic to determine the byte ordering, and the algorithm I use gives very good results, but it isn't definitive.

I have always said that it is insanely stupid for any software to change the byte ordering because of the high risk of corrupting some data, but it seems there are still some really dumb programmers out there who just don't get the message. :(

The T1i EXIF byte order should be little-endian (II), so it looks like the import wizard in Windows 7 is being very stupid.  (Unfortunately this is par for the course for Microsoft, which has a very bad record for producing software which corrupts metadata.)

Also, it maybe be worthwhile to note that some maker notes which use different byte orders for different values, so you can't always assume that the entire maker notes are the same byte order.  Nice, huh?

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mvadu

Thanks Phil.. Every day I am working with this spec, reading about makernote format of different camera makers in different websites I am finding new respect for Exiftool and for you.. How on earth you could complete Exiftool ::).

Can I reuse/implement your algorithm in my code too?

One more thing, have you noticed GainControl (41991 or 0xA407)  tag in spec, even with Exif spec 2.3 has its type as Rational in the grid, and Short in the actual explanation of the tag. Actual data is Short!!

mvadu

#3
Phil, at the minute I have below work around,

lTotalEntries=ReadWord(pFile,sByteOrder);
       //with current byte order if we get too large a value swap Byte order
if(lTotalEntries>0xFF)
{
sByteOrder=(ByteOrder==Motorola?Intel:Motorola);
lTotalEntries=ReadWord(pFile,sByteOrder);
}


So i am depending on total maker note tags being less than 255, will this be sufficient logic?

On the side note where can I access source code of ExifTool? I can see only two distributions on your site, and windows one just has an exe file.

Phil Harvey

QuoteHow on earth you could complete Exiftool

Good question.  And you've just touched the tip of the iceberg with your questions!

QuoteCan I reuse/implement your algorithm in my code too?

Sure.

QuoteSo i am depending on total maker note tags being less than 255, will this be sufficient logic?

Yes, this is what I do once I know where the start of the IFD is.

QuoteOn the side note where can I access source code of ExifTool? I can see only two distributions on your site, and windows one just has an exe file.

I think you missed the first link for the full perl version (one link inside each box at the top of the exiftool home page).  All versions actually contain the source code, but it is the easist to find in the full Perl version (plus this version has all the documentation too).

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mvadu

#5
Thank you so much Phil.. You are really helpful (than I would ever imagined).
I just downloaded your full version (I look so dumb when I look back now!!, I should have seen that before asking you) I will go through it whenever I have questions.

Quote from: Phil Harvey on September 26, 2010, 01:54:29 PM
QuoteSo i am depending on total maker note tags being less than 255, will this be sufficient logic?

Yes, this is what I do once I know where the start of the IFD is.
- Phil
So as of now none of the camera's have more than 255 entries in maker note tag?


Phil Harvey

Take a look at the LocateIFD() subroutine in lib/Image/ExifTool/MakerNotes.pm.  This module contains most of the maker note logic.

Quote from: mvadu on September 26, 2010, 08:56:12 PM
So as of now none of the camera's have more than 255 entries in maker note tag?

Correct.

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

mvadu

Thanks Phil, I did take a look, and your code re-assured my logic. But understanding your code is very difficult, as I am very new (in fact this is my first day) to Perl. For most of the lines I have to look at http://perldoc.perl.org  >:(

mvadu

Phil,
after the knowledge I gained from other post, I am now reached a place to read Canon MakerNotes footer tag. Looks like footer has a ByteOrder section, can we rely on that?

49 49 2a 00 2a 0b 00 00
This is the footer from the image where it was originally II (Intel) and Microsoft Import wizard changed it to MM except for makernote section.

Phil Harvey

I have seen some software that swaps the byte order of the makernotes (can you believe it??!!), so I don't rely on anything.  But for any other cases I would imagine that the byte order indicated in the footer is reliable.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).