- Timestamp:
- 2011-06-01T12:33:42+12:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/greenstone2/perllib/cpan/Image/ExifTool/NikonCapture.pm
r16842 r24107 5 5 # 6 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 7 9 # 8 10 # References: 1) http://www.cybercom.net/~dcoffin/dcraw/ … … 16 18 use Image::ExifTool::Exif; 17 19 18 $VERSION = '1.02'; 20 $VERSION = '1.07'; 21 22 sub ProcessNikonCapture($$$); 19 23 20 24 # common print conversions … … 41 45 the maker notes of NEF images. 42 46 }, 47 # 0x007ddc9d contains contrast information 43 48 0x008ae85e => { 44 49 Name => 'LCHEditor', … … 50 55 Writable => 'int8u', 51 56 PrintConv => \%offOn, 57 }, 58 0x116fea21 => { 59 Name => 'HighlightData', 60 SubDirectory => { 61 TagTable => 'Image::ExifTool::NikonCapture::HighlightData', 62 }, 52 63 }, 53 64 0x2175eb78 => { … … 66 77 }, 67 78 }, 79 0x39c456ac => { 80 Name => 'PictureCtrl', 81 SubDirectory => { 82 TagTable => 'Image::ExifTool::NikonCapture::PictureCtrl', 83 }, 84 }, 68 85 0x3cfc73c6 => { 69 86 Name => 'RedEyeData', 70 87 SubDirectory => { 71 88 TagTable => 'Image::ExifTool::NikonCapture::RedEyeData', 89 }, 90 }, 91 0x3d136244 => { 92 Name => 'EditVersionName', 93 Writable => 'string', # (null terminated) 94 }, 95 # 0x3e726567 added when I rotated by 90 degrees 96 0x56a54260 => { 97 Name => 'Exposure', 98 SubDirectory => { 99 TagTable => 'Image::ExifTool::NikonCapture::Exposure', 72 100 }, 73 101 }, … … 126 154 Writable => 'int16u', 127 155 }, 156 0x083a1a25 => { 157 Name => 'HistogramXML', 158 Writable => 'undef', 159 Binary => 1, 160 AdjustSize => 4, # patch Nikon bug 161 }, 128 162 0x84589434 => { 129 163 Name => 'BrightnessData', … … 150 184 }, 151 185 }, 186 # 0xa7264a72, 0x88f55e48 and 0x416391c6 all change from 0 to 1 when QuickFix is turned on 152 187 0xab5eca5e => { 153 188 Name => 'PhotoEffects', … … 182 217 PrintConv => \%offOn, 183 218 }, 219 0xe2173c47 => { 220 Name => 'PictureControl', 221 Writable => 'int8u', 222 PrintConv => \%offOn, 223 }, 184 224 0xe37b4337 => { 185 225 Name => 'D-LightingHSData', … … 193 233 TagTable => 'Image::ExifTool::NikonCapture::UnsharpData', 194 234 }, 235 }, 236 0xe9651831 => { 237 Name => 'PhotoEffectHistoryXML', 238 Binary => 1, 239 Writable => 'undef', 240 }, 241 0xfe28a44f => { 242 Name => 'AutoRedEye', 243 Writable => 'int8u', 244 PrintConv => \%offOn, # (have seen a value of 28 here for older software?) 195 245 }, 196 246 0xfe443a45 => { … … 249 299 FIRST_ENTRY => 0, 250 300 GROUPS => { 0 => 'MakerNotes', 2 => 'Image' }, 251 0 => 'D-LightingH SShadow',252 1 => 'D-LightingH SHighlight',253 2 => 'D-LightingH SColorBoost',301 0 => 'D-LightingHQShadow', 302 1 => 'D-LightingHQHighlight', 303 2 => 'D-LightingHQColorBoost', 254 304 ); 255 305 … … 299 349 4 => 'Calculate Automatically' 300 350 }, 351 }, 352 0x14 => { 353 Name => 'WBAdjLightingSubtype', 354 # this varies for different lighting types 355 # (ie. for Daylight, this is 0 => 'Direct', 1 => 'Shade', 2 => 'Cloudy') 301 356 }, 302 357 0x15 => { … … 315 370 Format => 'int16u', 316 371 }, 372 0x25 => { 373 Name => 'WBAdjTint', 374 Format => 'int32s', 375 }, 317 376 ); 318 377 … … 376 435 FIRST_ENTRY => 0, 377 436 GROUPS => { 0 => 'MakerNotes', 2 => 'Image' }, 378 4 => {437 0x04 => { 379 438 Name => 'EdgeNoiseReduction', 380 439 PrintConv => \%offOn, 381 440 }, 382 5 => {383 Name => 'ColorMoireReduction ',441 0x05 => { 442 Name => 'ColorMoireReductionMode', 384 443 PrintConv => { 385 444 0 => 'Off', … … 389 448 }, 390 449 }, 391 9 => {450 0x09 => { 392 451 Name => 'NoiseReductionIntensity', 393 452 Format => 'int32u', 394 453 }, 395 13=> {454 0x0d => { 396 455 Name => 'NoiseReductionSharpness', 397 456 Format => 'int32u', 398 457 }, 399 17=> {458 0x11 => { 400 459 Name => 'NoiseReductionMethod', 401 460 Format => 'int16u', … … 405 464 }, 406 465 }, 466 0x15 => { 467 Name => 'ColorMoireReduction', 468 PrintConv => \%offOn, 469 }, 470 0x17 => { 471 Name => 'NoiseReduction', 472 PrintConv => \%offOn, 473 }, 474 0x18 => { 475 Name => 'ColorNoiseReductionIntensity', 476 Format => 'int32u', 477 }, 478 0x1c => { 479 Name => 'ColorNoiseReductionSharpness', 480 Format => 'int32u', 481 }, 407 482 ); 408 483 … … 440 515 }, 441 516 0x8e => { 442 Name => ' OutputWidthInches',517 Name => 'CropOutputWidthInches', 443 518 Format => 'double', 444 519 }, 445 520 0x96 => { 446 Name => ' OutputHeightInches',521 Name => 'CropOutputHeightInches', 447 522 Format => 'double', 448 523 }, 449 524 0x9e => { 450 Name => ' ScaledResolution',525 Name => 'CropScaledResolution', 451 526 Format => 'double', 452 527 }, 453 528 0xae => { 454 Name => ' SourceResolution',529 Name => 'CropSourceResolution', 455 530 Format => 'double', 456 531 ValueConv => '$val / 2', … … 458 533 }, 459 534 0xb6 => { 460 Name => ' OutputResolution',535 Name => 'CropOutputResolution', 461 536 Format => 'double', 462 537 }, … … 466 541 }, 467 542 0xc6 => { 468 Name => ' OutputWidth',543 Name => 'CropOutputWidth', 469 544 Format => 'double', 470 545 }, 471 546 0xce => { 472 Name => ' OutputHeight',547 Name => 'CropOutputHeight', 473 548 Format => 'double', 474 549 }, 475 550 0xd6 => { 476 Name => 'OutputPixels', 477 Format => 'double', 478 }, 551 Name => 'CropOutputPixels', 552 Format => 'double', 553 }, 554 ); 555 556 %Image::ExifTool::NikonCapture::PictureCtrl = ( 557 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData, 558 WRITE_PROC => \&Image::ExifTool::WriteBinaryData, 559 CHECK_PROC => \&Image::ExifTool::CheckBinaryData, 560 WRITABLE => 1, 561 FORMAT => 'int8u', 562 FIRST_ENTRY => 0, 563 GROUPS => { 0 => 'MakerNotes', 2 => 'Image' }, 564 0x00 => { 565 Name => 'PictureControlActive', 566 PrintConv => \%offOn, 567 }, 568 0x13 => { 569 Name => 'PictureControlMode', 570 Format => 'string[16]', 571 }, 572 # 0x29 changes with Hue and Sharpening 573 0x2a => { 574 Name => 'QuickAdjust', 575 ValueConv => '$val - 128', 576 ValueConvInv => '$val + 128', 577 }, 578 0x2b => { 579 Name => 'SharpeningAdj', 580 ValueConv => '$val ? $val - 128 : "Auto"', 581 ValueConvInv => '$val=~/\d/ ? $val + 128 : 0', 582 }, 583 0x2c => { 584 Name => 'ContrastAdj', 585 ValueConv => '$val ? $val - 128 : "Auto"', 586 ValueConvInv => '$val=~/\d/ ? $val + 128 : 0', 587 }, 588 0x2d => { 589 Name => 'BrightnessAdj', 590 ValueConv => '$val ? $val - 128 : "Auto"', # no "Auto" mode (yet) for this setting 591 ValueConvInv => '$val=~/\d/ ? $val + 128 : 0', 592 }, 593 0x2e => { 594 Name => 'SaturationAdj', 595 ValueConv => '$val ? $val - 128 : "Auto"', 596 ValueConvInv => '$val=~/\d/ ? $val + 128 : 0', 597 }, 598 0x2f => { 599 Name => 'HueAdj', 600 ValueConv => '$val - 128', 601 ValueConvInv => '$val + 128', 602 }, 603 # 0x37 changed from 0 to 2 when Picture Control is enabled (and no active DLighting) 479 604 ); 480 605 … … 495 620 }, 496 621 }, 622 ); 623 624 %Image::ExifTool::NikonCapture::Exposure = ( 625 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData, 626 WRITE_PROC => \&Image::ExifTool::WriteBinaryData, 627 CHECK_PROC => \&Image::ExifTool::CheckBinaryData, 628 WRITABLE => 1, 629 FORMAT => 'int8u', 630 FIRST_ENTRY => 0, 631 GROUPS => { 0 => 'MakerNotes', 2 => 'Image' }, 632 0x00 => { 633 Name => 'ExposureAdj', 634 Format => 'int16s', 635 ValueConv => '$val / 100', 636 ValueConvInv => '$val * 100', 637 }, 638 0x12 => { 639 Name => 'ExposureAdj2', 640 Format => 'double', 641 PrintConv => 'sprintf("%.4f", $val)', 642 PrintConvInvn => '$val', 643 }, 644 0x24 => { 645 Name => 'ActiveD-Lighting', 646 PrintConv => \%offOn, 647 }, 648 0x25 => { 649 Name => 'ActiveD-LightingMode', 650 PrintConv => { 651 0 => 'Unchanged', 652 1 => 'Off', 653 2 => 'Low', 654 3 => 'Normal', 655 4 => 'High', 656 6 => 'Extra High', 657 }, 658 }, 659 ); 660 661 %Image::ExifTool::NikonCapture::HighlightData = ( 662 PROCESS_PROC => \&Image::ExifTool::ProcessBinaryData, 663 WRITE_PROC => \&Image::ExifTool::WriteBinaryData, 664 CHECK_PROC => \&Image::ExifTool::CheckBinaryData, 665 WRITABLE => 1, 666 FORMAT => 'int8s', 667 FIRST_ENTRY => 0, 668 GROUPS => { 0 => 'MakerNotes', 2 => 'Image' }, 669 0 => 'ShadowProtection', 670 1 => 'SaturationAdj', 671 6 => 'HighlightProtection', 497 672 ); 498 673 … … 514 689 my $dirStart = $$dirInfo{DirStart}; 515 690 my $dirLen = $$dirInfo{DirLen}; 516 my $dirEnd = $dirStart + $dirLen;517 691 if ($dirLen < 22) { 518 692 $exifTool->Warn('Short Nikon Capture Data',1); … … 522 696 SetByteOrder('II'); 523 697 my $tagID = Get32u($dataPt, $dirStart); 698 # sometimes size includes 18 header bytes, and other times it doesn't (ie. ViewNX 2.1.1) 524 699 my $size = Get32u($dataPt, $dirStart + 18); 525 unless ($tagID == 0x7a86a940 and $size + 18 == $dirLen) { 700 my $pad = $dirLen - $size - 18; 701 unless ($tagID == 0x7a86a940 and ($pad >= 0 or $pad == -18)) { 526 702 $exifTool->Warn('Unrecognized Nikon Capture Data header'); 527 703 return undef; 704 } 705 # determine if there is any data after this block 706 if ($pad > 0) { 707 $pad = substr($$dataPt, $dirStart + 18 + $size, $pad); 708 $dirLen = $size + 18; 709 } else { 710 $pad = ''; 528 711 } 529 712 my $outBuff = ''; 530 713 my $pos; 531 714 my $newTags = $exifTool->GetNewTagInfoHash($tagTablePtr); 715 my $dirEnd = $dirStart + $dirLen; 532 716 533 717 # loop through all entries in the Nikon Capture data … … 558 742 my $format = $$tagInfo{Format} || $$tagInfo{Writable}; 559 743 my $oldVal = ReadValue($dataPt,$pos+22,$format,1,$size); 560 my $n ewValueHash = $exifTool->GetNewValueHash($tagInfo);561 if (Image::ExifTool::IsOverwriting($n ewValueHash, $oldVal)) {744 my $nvHash = $exifTool->GetNewValueHash($tagInfo); 745 if (Image::ExifTool::IsOverwriting($nvHash, $oldVal)) { 562 746 my $val = $exifTool->GetNewValues($tagInfo); 563 747 $newVal = WriteValue($val, $$tagInfo{Writable}) if defined $val; … … 583 767 } 584 768 unless ($pos == $dirEnd) { 585 $exifTool->Warn('Nikon Capture Data improperly terminated',1); 586 return undef; 769 if ($pos == $dirEnd - 4) { 770 # it seems that sometimes (NX2) the main block size is wrong by 4 bytes 771 # (did they forget to include the size word?) 772 $outBuff .= substr($$dataPt, $pos, 4); 773 } else { 774 $exifTool->Warn('Nikon Capture Data improperly terminated',1); 775 return undef; 776 } 587 777 } 588 778 # add the header and return the new directory 589 779 return substr($$dataPt, $dirStart, 18) . 590 780 Set32u(length($outBuff) + 4) . 591 $outBuff ;781 $outBuff . $pad; 592 782 } 593 783 594 784 #------------------------------------------------------------------------------ 595 785 # process Nikon Capture data (ref 1) 596 # Inputs: 0) ExifTool object reference, 1) reference to directory information 597 # 2) pointer to tag table 786 # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref 787 # Returns: 1 on success 788 sub ProcessNikonCaptureEditVersions($$$) 789 { 790 my ($exifTool, $dirInfo, $tagTablePtr) = @_; 791 my $dataPt = $$dirInfo{DataPt}; 792 my $dirStart = $$dirInfo{DirStart}; 793 my $dirLen = $$dirInfo{DirLen}; 794 my $dirEnd = $dirStart + $dirLen; 795 my $verbose = $exifTool->Options('Verbose'); 796 SetByteOrder('II'); 797 return 0 unless $dirLen > 4; 798 my $num = Get32u($dataPt, $dirStart); 799 my $pos = $dirStart + 4; 800 $verbose and $exifTool->VerboseDir('NikonCaptureEditVersions', $num); 801 while ($num) { 802 last if $pos + 4 > $dirEnd; 803 my $len = Get32u($dataPt, $pos); 804 last if $pos + $len + 4 > $dirEnd; 805 my %dirInfo = ( 806 DirName => 'NikonCapture', 807 Parent => 'NikonCaptureEditVersions', 808 DataPt => $dataPt, 809 DirStart => $pos + 4, 810 DirLen => $len, 811 ); 812 $$exifTool{DOC_NUM} = ++$$exifTool{DOC_COUNT}; 813 $exifTool->ProcessDirectory(\%dirInfo, $tagTablePtr); 814 --$num; 815 $pos += $len + 4; 816 } 817 delete $$exifTool{DOC_NUM}; 818 return 1; 819 } 820 821 #------------------------------------------------------------------------------ 822 # process Nikon Capture data (ref 1) 823 # Inputs: 0) ExifTool object ref, 1) dirInfo ref, 2) tag table ref 598 824 # Returns: 1 on success 599 825 sub ProcessNikonCapture($$$) … … 624 850 } 625 851 if ($format) { 626 $value = ReadValue($dataPt,$pos,$format,1,$size); 852 my $count = 1; 853 if ($format eq 'string' or $format eq 'undef') { 854 # patch Nikon bug in size of some values (HistogramXML) 855 $size += $$tagInfo{AdjustSize} if $tagInfo and $$tagInfo{AdjustSize}; 856 $count = $size; 857 } 858 $value = ReadValue($dataPt,$pos,$format,$count,$size); 627 859 } elsif ($size == 1) { 628 860 $value = substr($$dataPt, $pos, $size); … … 641 873 1; # end 642 874 875 __END__ 876 643 877 =head1 NAME 644 878 … … 656 890 =head1 AUTHOR 657 891 658 Copyright 2003-20 07, Phil Harvey (phil at owl.phy.queensu.ca)892 Copyright 2003-2011, Phil Harvey (phil at owl.phy.queensu.ca) 659 893 660 894 This library is free software; you can redistribute it and/or modify it
Note:
See TracChangeset
for help on using the changeset viewer.