How to parse Nikon ColorBalance2 values

Started by yetithefoot, May 08, 2014, 06:18:40 AM

Previous topic - Next topic

yetithefoot

Hi. Im trying to get ColorBalance data for my Nikon D50. Im using exiftool as an etalon.

According to this http://www.exiftool.org/TagNames/Nikon.html#ColorBalance2
I should read four 16bit usigned integer values from offset 0.
But I got strange values: [12338, 12341, 19676, 23495]
This is not the same what exiftool returns.

I read bytes: [48, 50, 48, 53, 76, 220, 91, 199]

Here I read that I should read from offset 5 http://www.exiv2.org/tags-nikon.html

Also there is phrases: This information is encrypted for most camera models.

This is my file https://dl.dropboxusercontent.com/u/3157153/nikon_d50.NEF.
Global offset for this tag in my file is 7812.
What im doing wrong?  :'(


Phil Harvey

To figure this out you need to look at lib/Image/ExifTool/Nikon.pm in the ExifTool source code.  Either download the full distribution, or find it on cpan.

See the ColorBalance0205 tag for the constants used in parsing this information for the D50:

                DecryptStart => 4,
                DecryptLen => 22, # 284 bytes encrypted, but don't need to decrypt it all
                DirOffset => 14,


The index in the tag table documentation is relative to DecryptStart + DirOffset.  So you must decrypt from byte 4 onwards, and you will find your color balance information starting at byte 14 in the decrypted data.

Use the exiftool -v3 option to see everything that is going on here in your file:

  | | | 33) ColorBalance0205 (SubDirectory) -->
  | | |     - Tag 0x0097 (284 bytes, undef[284]):
  | | |         1e84: 30 32 30 35 4c dc 5b c7 22 6e a9 d1 e9 f0 e6 cb [0205L.[."n......]
  | | |         1e94: 9f 62 16 d3 44 c4 33 8f da 41 43 5a 61 59 3e 13 [.b..D.3..ACZaY>.]
  | | |         1ea4: d7 8a 2c bd 3c ac 09 48 91 a1 dc fd dd c3 92 5f [..,.<..H......._]
  | | |         1eb4: 0d 80 40 eb 35 98 e6 2a 49 4f 70 25 51 bf ee be [..@.5..*IOp%Q...]
  | | |         1ec4: 45 f7 5e b1 2d d5 ba 75 01 7f 0a d0 88 d2 02 a9 [E.^.-..u........]
  | | |         [snip 204 bytes]
  | | | + [Decrypted ColorBalance0205 directory]
  | | | |       1e84: 30 32 30 35 01 00 01 00 01 00 01 00 00 00 00 00 [0205............]
  | | | |       1e94: 00 00 02 66 01 00 01 00 01 57 03 03 00 01 00 00 [...f.....W......]
  | | | |       1ea4: 00 00 00 00 01 00 03 1f 02 1f 04 1c 04 03 04 04 [................]
  | | | |       1eb4: 02 32 04 2e 00 0c 04 35 02 29 00 4c 00 97 00 1d [.2.....5.).L....]
  | | | |       1ec4: 02 2d 02 7c 00 a9 00 92 02 71 02 21 41 42 44 42 [.-.|.....q.!ABDB]
  | | | |       [snip 204 bytes]
  | | | + [BinaryData directory, 266 bytes]
  | | | | WB_RGGBLevels = 614 256 256 343
  | | | | - Tag 0x0000 (8 bytes, int16u[4]):
  | | | |     1e96: 02 66 01 00 01 00 01 57                         [.f.....W]


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