NikonCapture.pm 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940
  1. #------------------------------------------------------------------------------
  2. # File: NikonCapture.pm
  3. #
  4. # Description: Read/write Nikon Capture information
  5. #
  6. # Revisions: 11/08/2005 - P. Harvey Created
  7. # 10/10/2008 - P. Harvey Updated for Capture NX 2
  8. # 16/04/2011 - P. Harvey Decode NikonCaptureEditVersions
  9. #
  10. # References: 1) http://www.cybercom.net/~dcoffin/dcraw/
  11. # 2) Iliah Borg private communication (LibRaw)
  12. #------------------------------------------------------------------------------
  13. package Image::ExifTool::NikonCapture;
  14. use strict;
  15. use vars qw($VERSION);
  16. use Image::ExifTool qw(:DataAccess :Utils);
  17. use Image::ExifTool::Exif;
  18. $VERSION = '1.14';
  19. sub ProcessNikonCapture($$$);
  20. # common print conversions
  21. my %offOn = ( 0 => 'Off', 1 => 'On' );
  22. my %noYes = ( 0 => 'No', 1 => 'Yes' );
  23. my %unsharpColor = (
  24. 0 => 'RGB',
  25. 1 => 'Red',
  26. 2 => 'Green',
  27. 3 => 'Blue',
  28. 4 => 'Yellow',
  29. 5 => 'Magenta',
  30. 6 => 'Cyan',
  31. );
  32. # Nikon Capture data (ref PH)
  33. %Image::ExifTool::NikonCapture::Main = (
  34. PROCESS_PROC => \&ProcessNikonCapture,
  35. WRITE_PROC => \&WriteNikonCapture,
  36. CHECK_PROC => \&Image::ExifTool::Exif::CheckExif,
  37. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  38. NOTES => q{
  39. This information is written by the Nikon Capture software in tag 0x0e01 of
  40. the maker notes of NEF images.
  41. },
  42. # 0x007ddc9d contains contrast information
  43. 0x008ae85e => {
  44. Name => 'LCHEditor',
  45. Writable => 'int8u',
  46. PrintConv => \%offOn,
  47. },
  48. 0x0c89224b => {
  49. Name => 'ColorAberrationControl',
  50. Writable => 'int8u',
  51. PrintConv => \%offOn,
  52. },
  53. 0x116fea21 => {
  54. Name => 'HighlightData',
  55. SubDirectory => {
  56. TagTable => 'Image::ExifTool::NikonCapture::HighlightData',
  57. },
  58. },
  59. 0x2175eb78 => {
  60. Name => 'D-LightingHQ',
  61. Writable => 'int8u',
  62. PrintConv => \%offOn,
  63. },
  64. 0x2fc08431 => {
  65. Name => 'StraightenAngle',
  66. Writable => 'double',
  67. },
  68. 0x374233e0 => {
  69. Name => 'CropData',
  70. SubDirectory => {
  71. TagTable => 'Image::ExifTool::NikonCapture::CropData',
  72. },
  73. },
  74. 0x39c456ac => {
  75. Name => 'PictureCtrl',
  76. SubDirectory => {
  77. TagTable => 'Image::ExifTool::NikonCapture::PictureCtrl',
  78. },
  79. },
  80. 0x3cfc73c6 => {
  81. Name => 'RedEyeData',
  82. SubDirectory => {
  83. TagTable => 'Image::ExifTool::NikonCapture::RedEyeData',
  84. },
  85. },
  86. 0x3d136244 => {
  87. Name => 'EditVersionName',
  88. Writable => 'string', # (null terminated)
  89. },
  90. # 0x3e726567 added when I rotated by 90 degrees
  91. 0x416391c6 => {
  92. Name => 'QuickFix',
  93. Writable => 'int8u',
  94. PrintConv => \%offOn,
  95. },
  96. 0x56a54260 => {
  97. Name => 'Exposure',
  98. SubDirectory => {
  99. TagTable => 'Image::ExifTool::NikonCapture::Exposure',
  100. },
  101. },
  102. 0x5f0e7d23 => {
  103. Name => 'ColorBooster',
  104. Writable => 'int8u',
  105. PrintConv => \%offOn,
  106. },
  107. 0x6a6e36b6 => {
  108. Name => 'D-LightingHQSelected',
  109. Writable => 'int8u',
  110. PrintConv => \%noYes,
  111. },
  112. 0x753dcbc0 => {
  113. Name => 'NoiseReduction',
  114. Writable => 'int8u',
  115. PrintConv => \%offOn,
  116. },
  117. 0x76a43200 => {
  118. Name => 'UnsharpMask',
  119. Writable => 'int8u',
  120. PrintConv => \%offOn,
  121. },
  122. 0x76a43201 => {
  123. Name => 'Curves',
  124. Writable => 'int8u',
  125. PrintConv => \%offOn,
  126. },
  127. 0x76a43202 => {
  128. Name => 'ColorBalanceAdj',
  129. Writable => 'int8u',
  130. PrintConv => \%offOn,
  131. },
  132. 0x76a43203 => {
  133. Name => 'AdvancedRaw',
  134. Writable => 'int8u',
  135. PrintConv => \%offOn,
  136. },
  137. 0x76a43204 => {
  138. Name => 'WhiteBalanceAdj',
  139. Writable => 'int8u',
  140. PrintConv => \%offOn,
  141. },
  142. 0x76a43205 => {
  143. Name => 'VignetteControl',
  144. Writable => 'int8u',
  145. PrintConv => \%offOn,
  146. },
  147. 0x76a43206 => {
  148. Name => 'FlipHorizontal',
  149. Writable => 'int8u',
  150. PrintConv => \%noYes,
  151. },
  152. 0x76a43207 => { # rotation angle in degrees
  153. Name => 'Rotation',
  154. Writable => 'int16u',
  155. },
  156. 0x083a1a25 => {
  157. Name => 'HistogramXML',
  158. Writable => 'undef',
  159. Binary => 1,
  160. AdjustSize => 4, # patch Nikon bug
  161. },
  162. 0x84589434 => {
  163. Name => 'BrightnessData',
  164. SubDirectory => {
  165. TagTable => 'Image::ExifTool::NikonCapture::Brightness',
  166. },
  167. },
  168. # 0x88f55e48 - related to QuickFix
  169. 0x890ff591 => {
  170. Name => 'D-LightingHQData',
  171. SubDirectory => {
  172. TagTable => 'Image::ExifTool::NikonCapture::DLightingHQ',
  173. },
  174. },
  175. 0x926f13e0 => {
  176. Name => 'NoiseReductionData',
  177. SubDirectory => {
  178. TagTable => 'Image::ExifTool::NikonCapture::NoiseReduction',
  179. },
  180. },
  181. 0x9ef5f6e0 => {
  182. Name => 'IPTCData',
  183. SubDirectory => {
  184. TagTable => 'Image::ExifTool::IPTC::Main',
  185. },
  186. },
  187. # 0xa7264a72 - related to QuickFix
  188. 0xab5eca5e => {
  189. Name => 'PhotoEffects',
  190. Writable => 'int8u',
  191. PrintConv => \%offOn,
  192. },
  193. 0xac6bd5c0 => {
  194. Name => 'VignetteControlIntensity',
  195. Writable => 'int16s',
  196. },
  197. 0xb0384e1e => {
  198. Name => 'PhotoEffectsData',
  199. SubDirectory => {
  200. TagTable => 'Image::ExifTool::NikonCapture::PhotoEffects',
  201. },
  202. },
  203. 0xb999a36f => {
  204. Name => 'ColorBoostData',
  205. SubDirectory => {
  206. TagTable => 'Image::ExifTool::NikonCapture::ColorBoost',
  207. },
  208. },
  209. 0xbf3c6c20 => {
  210. Name => 'WBAdjData',
  211. SubDirectory => {
  212. TagTable => 'Image::ExifTool::NikonCapture::WBAdjData',
  213. },
  214. },
  215. 0xce5554aa => {
  216. Name => 'D-LightingHS',
  217. Writable => 'int8u',
  218. PrintConv => \%offOn,
  219. },
  220. 0xe2173c47 => {
  221. Name => 'PictureControl',
  222. Writable => 'int8u',
  223. PrintConv => \%offOn,
  224. },
  225. 0xe37b4337 => {
  226. Name => 'D-LightingHSData',
  227. SubDirectory => {
  228. TagTable => 'Image::ExifTool::NikonCapture::DLightingHS',
  229. },
  230. },
  231. 0xe42b5161 => {
  232. Name => 'UnsharpData',
  233. SubDirectory => {
  234. TagTable => 'Image::ExifTool::NikonCapture::UnsharpData',
  235. },
  236. },
  237. 0xe9651831 => {
  238. Name => 'PhotoEffectHistoryXML',
  239. Binary => 1,
  240. Writable => 'undef',
  241. },
  242. 0xfe28a44f => {
  243. Name => 'AutoRedEye',
  244. Writable => 'int8u',
  245. PrintConv => \%offOn, # (have seen a value of 28 here for older software?)
  246. },
  247. 0xfe443a45 => {
  248. Name => 'ImageDustOff',
  249. Writable => 'int8u',
  250. PrintConv => \%offOn,
  251. },
  252. );
  253. %Image::ExifTool::NikonCapture::UnsharpData = (
  254. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  255. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  256. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  257. WRITABLE => 1,
  258. FORMAT => 'int8u',
  259. FIRST_ENTRY => 0,
  260. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  261. 0 => 'UnsharpCount',
  262. 19 => { Name => 'Unsharp1Color', Format => 'int16u', PrintConv => \%unsharpColor },
  263. 23 => { Name => 'Unsharp1Intensity', Format => 'int16u' },
  264. 25 => { Name => 'Unsharp1HaloWidth', Format => 'int16u' },
  265. 27 => 'Unsharp1Threshold',
  266. 46 => { Name => 'Unsharp2Color', Format => 'int16u', PrintConv => \%unsharpColor },
  267. 50 => { Name => 'Unsharp2Intensity', Format => 'int16u' },
  268. 52 => { Name => 'Unsharp2HaloWidth', Format => 'int16u' },
  269. 54 => 'Unsharp2Threshold',
  270. 73 => { Name => 'Unsharp3Color', Format => 'int16u', PrintConv => \%unsharpColor },
  271. 77 => { Name => 'Unsharp3Intensity', Format => 'int16u' },
  272. 79 => { Name => 'Unsharp3HaloWidth', Format => 'int16u' },
  273. 81 => 'Unsharp3Threshold',
  274. 100 => { Name => 'Unsharp4Color', Format => 'int16u', PrintConv => \%unsharpColor },
  275. 104 => { Name => 'Unsharp4Intensity', Format => 'int16u' },
  276. 106 => { Name => 'Unsharp4HaloWidth', Format => 'int16u' },
  277. 108 => 'Unsharp4Threshold',
  278. # there could be more, but I grow bored of this... :P
  279. );
  280. %Image::ExifTool::NikonCapture::DLightingHS = (
  281. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  282. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  283. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  284. WRITABLE => 1,
  285. FORMAT => 'int32u',
  286. FIRST_ENTRY => 0,
  287. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  288. 0 => 'D-LightingHSAdjustment',
  289. 1 => 'D-LightingHSColorBoost',
  290. );
  291. %Image::ExifTool::NikonCapture::DLightingHQ = (
  292. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  293. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  294. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  295. WRITABLE => 1,
  296. FORMAT => 'int32u',
  297. FIRST_ENTRY => 0,
  298. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  299. 0 => 'D-LightingHQShadow',
  300. 1 => 'D-LightingHQHighlight',
  301. 2 => 'D-LightingHQColorBoost',
  302. );
  303. %Image::ExifTool::NikonCapture::ColorBoost = (
  304. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  305. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  306. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  307. WRITABLE => 1,
  308. FORMAT => 'int8u',
  309. FIRST_ENTRY => 0,
  310. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  311. 0 => {
  312. Name => 'ColorBoostType',
  313. PrintConv => {
  314. 0 => 'Nature',
  315. 1 => 'People',
  316. },
  317. },
  318. 1 => {
  319. Name => 'ColorBoostLevel',
  320. Format => 'int32u',
  321. },
  322. );
  323. %Image::ExifTool::NikonCapture::WBAdjData = (
  324. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  325. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  326. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  327. WRITABLE => 1,
  328. FORMAT => 'int8u',
  329. FIRST_ENTRY => 0,
  330. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  331. 0x00 => {
  332. Name => 'WBAdjRedBalance',
  333. Format => 'double',
  334. },
  335. 0x08 => {
  336. Name => 'WBAdjBlueBalance',
  337. Format => 'double',
  338. },
  339. 0x10 => {
  340. Name => 'WBAdjMode',
  341. PrintConv => {
  342. 1 => 'Use Gray Point',
  343. 2 => 'Recorded Value',
  344. 3 => 'Use Temperature',
  345. 4 => 'Calculate Automatically',
  346. 5 => 'Auto2', #2
  347. 6 => 'Underwater', #2
  348. 7 => 'Auto1',
  349. },
  350. },
  351. 0x14 => { #2
  352. Name => 'WBAdjLighting',
  353. Format => 'int16u',
  354. PrintHex => 1,
  355. PrintConv => {
  356. 0x000 => 'None',
  357. 0x100 => 'Incandescent',
  358. 0x200 => 'Daylight (direct sunlight)',
  359. 0x201 => 'Daylight (shade)',
  360. 0x202 => 'Daylight (cloudy)',
  361. 0x300 => 'Standard Fluorescent (warm white)',
  362. 0x301 => 'Standard Fluorescent (3700K)',
  363. 0x302 => 'Standard Fluorescent (cool white)',
  364. 0x303 => 'Standard Fluorescent (5000K)',
  365. 0x304 => 'Standard Fluorescent (daylight)',
  366. 0x305 => 'Standard Fluorescent (high temperature mercury vapor)',
  367. 0x400 => 'High Color Rendering Fluorescent (warm white)',
  368. 0x401 => 'High Color Rendering Fluorescent (3700K)',
  369. 0x402 => 'High Color Rendering Fluorescent (cool white)',
  370. 0x403 => 'High Color Rendering Fluorescent (5000K)',
  371. 0x404 => 'High Color Rendering Fluorescent (daylight)',
  372. 0x500 => 'Flash',
  373. 0x501 => 'Flash (FL-G1 filter)',
  374. 0x502 => 'Flash (FL-G2 filter)',
  375. 0x503 => 'Flash (TN-A1 filter)',
  376. 0x504 => 'Flash (TN-A2 filter)',
  377. 0x600 => 'Sodium Vapor Lamps',
  378. # 0x1002 => seen for WBAdjMode modes of Underwater and Calculate Automatically
  379. },
  380. },
  381. 0x18 => {
  382. Name => 'WBAdjTemperature',
  383. Format => 'int16u',
  384. },
  385. 0x25 => {
  386. Name => 'WBAdjTint',
  387. Format => 'int32s',
  388. },
  389. );
  390. %Image::ExifTool::NikonCapture::PhotoEffects = (
  391. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  392. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  393. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  394. WRITABLE => 1,
  395. FORMAT => 'int8u',
  396. FIRST_ENTRY => 0,
  397. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  398. 0 => {
  399. Name => 'PhotoEffectsType',
  400. PrintConv => {
  401. 0 => 'None',
  402. 1 => 'B&W',
  403. 2 => 'Sepia',
  404. 3 => 'Tinted',
  405. },
  406. },
  407. 4 => {
  408. Name => 'PhotoEffectsRed',
  409. Format => 'int16s',
  410. },
  411. 6 => {
  412. Name => 'PhotoEffectsGreen',
  413. Format => 'int16s',
  414. },
  415. 8 => {
  416. Name => 'PhotoEffectsBlue',
  417. Format => 'int16s',
  418. },
  419. );
  420. %Image::ExifTool::NikonCapture::Brightness = (
  421. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  422. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  423. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  424. WRITABLE => 1,
  425. FORMAT => 'int8u',
  426. FIRST_ENTRY => 0,
  427. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  428. 0 => {
  429. Name => 'BrightnessAdj',
  430. Format => 'double',
  431. ValueConv => '$val * 50',
  432. ValueConvInv => '$val / 50',
  433. },
  434. 8 => {
  435. Name => 'EnhanceDarkTones',
  436. PrintConv => \%offOn,
  437. },
  438. );
  439. %Image::ExifTool::NikonCapture::NoiseReduction = (
  440. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  441. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  442. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  443. WRITABLE => 1,
  444. FORMAT => 'int8u',
  445. FIRST_ENTRY => 0,
  446. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  447. 0x04 => {
  448. Name => 'EdgeNoiseReduction',
  449. PrintConv => \%offOn,
  450. },
  451. 0x05 => {
  452. Name => 'ColorMoireReductionMode',
  453. PrintConv => {
  454. 0 => 'Off',
  455. 1 => 'Low',
  456. 2 => 'Medium',
  457. 3 => 'High',
  458. },
  459. },
  460. 0x09 => {
  461. Name => 'NoiseReductionIntensity',
  462. Format => 'int32u',
  463. },
  464. 0x0d => {
  465. Name => 'NoiseReductionSharpness',
  466. Format => 'int32u',
  467. },
  468. 0x11 => {
  469. Name => 'NoiseReductionMethod',
  470. Format => 'int16u',
  471. PrintConv => {
  472. 0 => 'Faster',
  473. 1 => 'Better Quality',
  474. 2 => 'Better Quality 2013',
  475. },
  476. },
  477. 0x15 => {
  478. Name => 'ColorMoireReduction',
  479. PrintConv => \%offOn,
  480. },
  481. 0x17 => {
  482. Name => 'NoiseReduction',
  483. PrintConv => \%offOn,
  484. },
  485. 0x18 => {
  486. Name => 'ColorNoiseReductionIntensity',
  487. Format => 'int32u',
  488. },
  489. 0x1c => {
  490. Name => 'ColorNoiseReductionSharpness',
  491. Format => 'int32u',
  492. },
  493. );
  494. %Image::ExifTool::NikonCapture::CropData = (
  495. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  496. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  497. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  498. WRITABLE => 1,
  499. FORMAT => 'int8u',
  500. FIRST_ENTRY => 0,
  501. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  502. 0x1e => {
  503. Name => 'CropLeft',
  504. Format => 'double',
  505. ValueConv => '$val / 2',
  506. ValueConvInv => '$val * 2',
  507. },
  508. 0x26 => {
  509. Name => 'CropTop',
  510. Format => 'double',
  511. ValueConv => '$val / 2',
  512. ValueConvInv => '$val * 2',
  513. },
  514. 0x2e => {
  515. Name => 'CropRight',
  516. Format => 'double',
  517. ValueConv => '$val / 2',
  518. ValueConvInv => '$val * 2',
  519. },
  520. 0x36 => {
  521. Name => 'CropBottom',
  522. Format => 'double',
  523. ValueConv => '$val / 2',
  524. ValueConvInv => '$val * 2',
  525. },
  526. 0x8e => {
  527. Name => 'CropOutputWidthInches',
  528. Format => 'double',
  529. },
  530. 0x96 => {
  531. Name => 'CropOutputHeightInches',
  532. Format => 'double',
  533. },
  534. 0x9e => {
  535. Name => 'CropScaledResolution',
  536. Format => 'double',
  537. },
  538. 0xae => {
  539. Name => 'CropSourceResolution',
  540. Format => 'double',
  541. ValueConv => '$val / 2',
  542. ValueConvInv => '$val * 2',
  543. },
  544. 0xb6 => {
  545. Name => 'CropOutputResolution',
  546. Format => 'double',
  547. },
  548. 0xbe => {
  549. Name => 'CropOutputScale',
  550. Format => 'double',
  551. },
  552. 0xc6 => {
  553. Name => 'CropOutputWidth',
  554. Format => 'double',
  555. },
  556. 0xce => {
  557. Name => 'CropOutputHeight',
  558. Format => 'double',
  559. },
  560. 0xd6 => {
  561. Name => 'CropOutputPixels',
  562. Format => 'double',
  563. },
  564. );
  565. %Image::ExifTool::NikonCapture::PictureCtrl = (
  566. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  567. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  568. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  569. WRITABLE => 1,
  570. FORMAT => 'int8u',
  571. FIRST_ENTRY => 0,
  572. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  573. 0x00 => {
  574. Name => 'PictureControlActive',
  575. PrintConv => \%offOn,
  576. },
  577. 0x13 => {
  578. Name => 'PictureControlMode',
  579. Format => 'string[16]',
  580. },
  581. # 0x29 changes with Hue and Sharpening
  582. 0x2a => {
  583. Name => 'QuickAdjust',
  584. ValueConv => '$val - 128',
  585. ValueConvInv => '$val + 128',
  586. },
  587. 0x2b => {
  588. Name => 'SharpeningAdj',
  589. ValueConv => '$val ? $val - 128 : "Auto"',
  590. ValueConvInv => '$val=~/\d/ ? $val + 128 : 0',
  591. },
  592. 0x2c => {
  593. Name => 'ContrastAdj',
  594. ValueConv => '$val ? $val - 128 : "Auto"',
  595. ValueConvInv => '$val=~/\d/ ? $val + 128 : 0',
  596. },
  597. 0x2d => {
  598. Name => 'BrightnessAdj',
  599. ValueConv => '$val ? $val - 128 : "Auto"', # no "Auto" mode (yet) for this setting
  600. ValueConvInv => '$val=~/\d/ ? $val + 128 : 0',
  601. },
  602. 0x2e => {
  603. Name => 'SaturationAdj',
  604. ValueConv => '$val ? $val - 128 : "Auto"',
  605. ValueConvInv => '$val=~/\d/ ? $val + 128 : 0',
  606. },
  607. 0x2f => {
  608. Name => 'HueAdj',
  609. ValueConv => '$val - 128',
  610. ValueConvInv => '$val + 128',
  611. },
  612. # 0x37 changed from 0 to 2 when Picture Control is enabled (and no active DLighting)
  613. );
  614. %Image::ExifTool::NikonCapture::RedEyeData = (
  615. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  616. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  617. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  618. WRITABLE => 1,
  619. FORMAT => 'int8u',
  620. FIRST_ENTRY => 0,
  621. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  622. 0 => {
  623. Name => 'RedEyeCorrection',
  624. PrintConv => {
  625. 0 => 'Off',
  626. 1 => 'Automatic',
  627. 2 => 'Click on Eyes',
  628. },
  629. },
  630. );
  631. %Image::ExifTool::NikonCapture::Exposure = (
  632. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  633. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  634. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  635. WRITABLE => 1,
  636. FORMAT => 'int8u',
  637. FIRST_ENTRY => 0,
  638. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  639. 0x00 => {
  640. Name => 'ExposureAdj',
  641. Format => 'int16s',
  642. ValueConv => '$val / 100',
  643. ValueConvInv => '$val * 100',
  644. },
  645. 0x12 => {
  646. Name => 'ExposureAdj2',
  647. Format => 'double',
  648. PrintConv => 'sprintf("%.4f", $val)',
  649. PrintConvInv => '$val',
  650. },
  651. 0x24 => {
  652. Name => 'ActiveD-Lighting',
  653. PrintConv => \%offOn,
  654. },
  655. 0x25 => {
  656. Name => 'ActiveD-LightingMode',
  657. PrintConv => {
  658. 0 => 'Unchanged',
  659. 1 => 'Off',
  660. 2 => 'Low',
  661. 3 => 'Normal',
  662. 4 => 'High',
  663. 6 => 'Extra High',
  664. 7 => 'Extra High 1',
  665. 8 => 'Extra High 2',
  666. },
  667. },
  668. );
  669. %Image::ExifTool::NikonCapture::HighlightData = (
  670. PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData,
  671. WRITE_PROC => \&Image::ExifTool::WriteBinaryData,
  672. CHECK_PROC => \&Image::ExifTool::CheckBinaryData,
  673. WRITABLE => 1,
  674. FORMAT => 'int8s',
  675. FIRST_ENTRY => 0,
  676. GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
  677. 0 => 'ShadowProtection',
  678. 1 => 'SaturationAdj',
  679. 6 => 'HighlightProtection',
  680. );
  681. #------------------------------------------------------------------------------
  682. # write Nikon Capture data (ref 1)
  683. # Inputs: 0) ExifTool object reference, 1) reference to directory information
  684. # 2) pointer to tag table
  685. # Returns: 1 on success
  686. sub WriteNikonCapture($$$)
  687. {
  688. my ($et, $dirInfo, $tagTablePtr) = @_;
  689. $et or return 1; # allow dummy access to autoload this package
  690. # no need to edit this information unless necessary
  691. unless ($$et{EDIT_DIRS}{MakerNotes} or $$et{EDIT_DIRS}{IPTC}) {
  692. return undef;
  693. }
  694. my $dataPt = $$dirInfo{DataPt};
  695. my $dirStart = $$dirInfo{DirStart};
  696. my $dirLen = $$dirInfo{DirLen};
  697. if ($dirLen < 22) {
  698. $et->Warn('Short Nikon Capture Data',1);
  699. return undef;
  700. }
  701. # make sure the capture data is properly contained
  702. SetByteOrder('II');
  703. my $tagID = Get32u($dataPt, $dirStart);
  704. # sometimes size includes 18 header bytes, and other times it doesn't (eg. ViewNX 2.1.1)
  705. my $size = Get32u($dataPt, $dirStart + 18);
  706. my $pad = $dirLen - $size - 18;
  707. unless ($tagID == 0x7a86a940 and ($pad >= 0 or $pad == -18)) {
  708. $et->Warn('Unrecognized Nikon Capture Data header');
  709. return undef;
  710. }
  711. # determine if there is any data after this block
  712. if ($pad > 0) {
  713. $pad = substr($$dataPt, $dirStart + 18 + $size, $pad);
  714. $dirLen = $size + 18;
  715. } else {
  716. $pad = '';
  717. }
  718. my $outBuff = '';
  719. my $pos;
  720. my $newTags = $et->GetNewTagInfoHash($tagTablePtr);
  721. my $dirEnd = $dirStart + $dirLen;
  722. # loop through all entries in the Nikon Capture data
  723. for ($pos=$dirStart+22; $pos+22<$dirEnd; $pos+=22+$size) {
  724. $tagID = Get32u($dataPt, $pos);
  725. $size = Get32u($dataPt, $pos + 18) - 4;
  726. last if $size < 0 or $pos + 22 + $size > $dirEnd;
  727. my $tagInfo = $et->GetTagInfo($tagTablePtr, $tagID);
  728. if ($tagInfo) {
  729. my $newVal;
  730. if ($$tagInfo{SubDirectory}) {
  731. # rewrite the subdirectory
  732. my %subdirInfo = (
  733. DataPt => $dataPt,
  734. DirStart => $pos + 22,
  735. DirLen => $size,
  736. );
  737. my $subTable = GetTagTable($tagInfo->{SubDirectory}->{TagTable});
  738. # ignore minor errors in IPTC since there is typically trailing garbage
  739. my $oldSetting = $et->Options('IgnoreMinorErrors');
  740. $$tagInfo{Name} =~ /IPTC/ and $et->Options(IgnoreMinorErrors => 1);
  741. # rewrite the directory
  742. $newVal = $et->WriteDirectory(\%subdirInfo, $subTable);
  743. # restore our original options
  744. $et->Options(IgnoreMinorErrors => $oldSetting);
  745. } elsif ($$newTags{$tagID}) {
  746. # get new value for this tag if we are writing it
  747. my $format = $$tagInfo{Format} || $$tagInfo{Writable};
  748. my $oldVal = ReadValue($dataPt,$pos+22,$format,1,$size);
  749. my $nvHash = $et->GetNewValueHash($tagInfo);
  750. if ($et->IsOverwriting($nvHash, $oldVal)) {
  751. my $val = $et->GetNewValue($tagInfo);
  752. $newVal = WriteValue($val, $$tagInfo{Writable}) if defined $val;
  753. if (defined $newVal and length $newVal) {
  754. ++$$et{CHANGED};
  755. } else {
  756. undef $newVal;
  757. $et->Warn("Can't delete $$tagInfo{Name}");
  758. }
  759. }
  760. }
  761. if (defined $newVal) {
  762. next unless length $newVal; # don't write zero length information
  763. # write the new value
  764. $outBuff .= substr($$dataPt, $pos, 18);
  765. $outBuff .= Set32u(length($newVal) + 4);
  766. $outBuff .= $newVal;
  767. next;
  768. }
  769. }
  770. # rewrite the existing information
  771. $outBuff .= substr($$dataPt, $pos, 22 + $size);
  772. }
  773. unless ($pos == $dirEnd) {
  774. if ($pos == $dirEnd - 4) {
  775. # it seems that sometimes (NX2) the main block size is wrong by 4 bytes
  776. # (did they forget to include the size word?)
  777. $outBuff .= substr($$dataPt, $pos, 4);
  778. } else {
  779. $et->Warn('Nikon Capture Data improperly terminated',1);
  780. return undef;
  781. }
  782. }
  783. # add the header and return the new directory
  784. return substr($$dataPt, $dirStart, 18) .
  785. Set32u(length($outBuff) + 4) .
  786. $outBuff . $pad;
  787. }
  788. #------------------------------------------------------------------------------
  789. # process Nikon Capture data (ref 1)
  790. # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
  791. # Returns: 1 on success
  792. sub ProcessNikonCaptureEditVersions($$$)
  793. {
  794. my ($et, $dirInfo, $tagTablePtr) = @_;
  795. my $dataPt = $$dirInfo{DataPt};
  796. my $dirStart = $$dirInfo{DirStart};
  797. my $dirLen = $$dirInfo{DirLen};
  798. my $dirEnd = $dirStart + $dirLen;
  799. my $verbose = $et->Options('Verbose');
  800. SetByteOrder('II');
  801. return 0 unless $dirLen > 4;
  802. my $num = Get32u($dataPt, $dirStart);
  803. my $pos = $dirStart + 4;
  804. $verbose and $et->VerboseDir('NikonCaptureEditVersions', $num);
  805. while ($num) {
  806. last if $pos + 4 > $dirEnd;
  807. my $len = Get32u($dataPt, $pos);
  808. last if $pos + $len + 4 > $dirEnd;
  809. my %dirInfo = (
  810. DirName => 'NikonCapture',
  811. Parent => 'NikonCaptureEditVersions',
  812. DataPt => $dataPt,
  813. DirStart => $pos + 4,
  814. DirLen => $len,
  815. );
  816. $$et{DOC_NUM} = ++$$et{DOC_COUNT};
  817. $et->ProcessDirectory(\%dirInfo, $tagTablePtr);
  818. --$num;
  819. $pos += $len + 4;
  820. }
  821. delete $$et{DOC_NUM};
  822. return 1;
  823. }
  824. #------------------------------------------------------------------------------
  825. # process Nikon Capture data (ref 1)
  826. # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref
  827. # Returns: 1 on success
  828. sub ProcessNikonCapture($$$)
  829. {
  830. my ($et, $dirInfo, $tagTablePtr) = @_;
  831. my $dataPt = $$dirInfo{DataPt};
  832. my $dirStart = $$dirInfo{DirStart};
  833. my $dirLen = $$dirInfo{DirLen};
  834. my $dirEnd = $dirStart + $dirLen;
  835. my $verbose = $et->Options('Verbose');
  836. my $success = 0;
  837. SetByteOrder('II');
  838. $verbose and $et->VerboseDir('NikonCapture', 0, $dirLen);
  839. my $pos;
  840. for ($pos=$dirStart+22; $pos+22<$dirEnd; ) {
  841. my $tagID = Get32u($dataPt, $pos);
  842. my $size = Get32u($dataPt, $pos + 18) - 4;
  843. $pos += 22;
  844. last if $size < 0 or $pos + $size > $dirEnd;
  845. my $tagInfo = $et->GetTagInfo($tagTablePtr, $tagID);
  846. if ($tagInfo or $verbose) {
  847. my ($format, $value);
  848. # (note that Writable will be 0 for Unknown tags)
  849. $tagInfo and $format = ($$tagInfo{Format} || $$tagInfo{Writable});
  850. # generate a reasonable default format type for short values
  851. if (not $format and ($size == 1 or $size == 2 or $size == 4)) {
  852. $format = 'int' . ($size * 8) . 'u';
  853. }
  854. if ($format) {
  855. my $count = 1;
  856. if ($format eq 'string' or $format eq 'undef') {
  857. # patch Nikon bug in size of some values (HistogramXML)
  858. $size += $$tagInfo{AdjustSize} if $tagInfo and $$tagInfo{AdjustSize};
  859. $count = $size;
  860. }
  861. $value = ReadValue($dataPt,$pos,$format,$count,$size);
  862. } elsif ($size == 1) {
  863. $value = substr($$dataPt, $pos, $size);
  864. }
  865. $et->HandleTag($tagTablePtr, $tagID, $value,
  866. DataPt => $dataPt,
  867. DataPos => $$dirInfo{DataPos},
  868. Base => $$dirInfo{Base},
  869. Start => $pos,
  870. Size => $size,
  871. ) and $success = 1;
  872. }
  873. $pos += $size;
  874. }
  875. return $success;
  876. }
  877. 1; # end
  878. __END__
  879. =head1 NAME
  880. Image::ExifTool::NikonCapture - Read/write Nikon Capture information
  881. =head1 SYNOPSIS
  882. This module is loaded automatically by Image::ExifTool when required.
  883. =head1 DESCRIPTION
  884. This module contains routines to read and write Nikon Capture information in
  885. the maker notes of NEF images.
  886. =head1 AUTHOR
  887. Copyright 2003-2016, Phil Harvey (phil at owl.phy.queensu.ca)
  888. This library is free software; you can redistribute it and/or modify it
  889. under the same terms as Perl itself.
  890. =head1 REFERENCES
  891. =over 4
  892. =item L<http://www.cybercom.net/~dcoffin/dcraw/>
  893. =back
  894. =head1 SEE ALSO
  895. L<Image::ExifTool::TagNames/NikonCapture Tags>,
  896. L<Image::ExifTool::TagNames/Nikon Tags>,
  897. L<Image::ExifTool(3pm)|Image::ExifTool>
  898. =cut