Need help with Canon makernote offsets.

Started by Astral, September 18, 2014, 11:47:10 AM

Previous topic - Next topic

Astral

Hi, I want my program to extract data from canon jpg's that have been through Canon's DPP, and now the offsets inside makernotes are invalid. How to get the value that modifies the offsets inside makernotes so that they point to the correct address?

Also in the canon makernotes-> CanonCameraSettings array elements 26 and 27 should represent the max and min apertures , but my program reads as them having 96 and 288, did my program read something incorrectly or is there a formula to convert these numbers into apertures? The lens is sigma 70-200 f2.8 macro.

Some output from my program. It gets the focal lengths correctly (23 & 24):

CanonCameraSettings[23] = 200
CanonCameraSettings[24] = 70
CanonCameraSettings[25] = 1
CanonCameraSettings[26] = 96
CanonCameraSettings[27] = 288

Phil Harvey

Canon's DPP should not invalidate the offsets.  Only 3rd party software should have this problem.

ExifTool automatically fixes Canon offsets unless scrambled particularly deviously (ie. Picasa).

- Phil

Edit:  Ah. I see you are talking about writing your own software to do this.  Look at the last 8 bytes in the Canon makernote for the original makernote offset, and adjust all offsets by the difference between this and the current offset. (Use the exiftool -htmlDump feature and look for the "Canon makernotes footer".) But like I said, DPP shouldn't mess this up.
...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 ($).

Astral

My program reads IFD0 , finds offset to subIFD , finds offset to makernotes, gets values and offsets(invalid if not straight from camera). -htmldump shows that after the makernote directory entries to which subIFD linked to, there is another IFD where more Canon data is stored (probably the data to which I need to know the correct offsets) then after that Canon data ends. Who would've thunk? How do I get from the Canon makernote directories to which subIFD linked to, to the real Canon makernote data end?

Phil Harvey

As I said, you just need to adjust the offsets in the canon makernote directory for the difference between the current makernote start and the address given in the 8-byte footer.  Once you have done this, you read it just like any other IFD.  But for older cameras the footer may not exist, in which case things get more complicated.

- 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 ($).

Astral

Okay so I solved the problem by searching for 4bytes containing byte order that precede the original offset value (starting from last makernote entry till its found or end of exif data is reached). the -htmldump function in exiftool is great for understanding the file structure!

now i need to figure Canon CameraSettings Tag 26 conversion formula. I don't know perl, what happens with these two formulas? is there a mathematical equation somewhere on how to convert the tag 26 value?

from: Canon.pm

    26 => { #9
        Name => 'MaxAperture',
        RawConv => '$val > 0 ? $val : undef',
        ValueConv => 'exp(Image::ExifTool::Canon::CanonEv($val)*log(2)/2)',
        ValueConvInv => 'Image::ExifTool::Canon::CanonEvInv(log($val)*2/log(2))',
        PrintConv => 'sprintf("%.2g",$val)',
        PrintConvInv => '$val',
    },

Phil Harvey

exp and log are the standard natural exponent and log functions.  You will find CanonEV in Canon.pm.  Except for handling rounding off of the 1/3 EV settings, this function essentially returns the value divided by 32.

- 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 ($).

Astral

Thanks, solved! Will bother again if I run into further problems ;)