Ignore:
Timestamp:
2011-06-01T12:33:42+12:00 (13 years ago)
Author:
sjm84
Message:

Updating the ExifTool perl modules

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/cpan/Image/ExifTool/NikonCapture.pm

    r16842 r24107  
    55#
    66# 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
    79#
    810# References:   1) http://www.cybercom.net/~dcoffin/dcraw/
     
    1618use Image::ExifTool::Exif;
    1719
    18 $VERSION = '1.02';
     20$VERSION = '1.07';
     21
     22sub ProcessNikonCapture($$$);
    1923
    2024# common print conversions
     
    4145        the maker notes of NEF images.
    4246    },
     47    # 0x007ddc9d contains contrast information
    4348    0x008ae85e => {
    4449        Name => 'LCHEditor',
     
    5055        Writable => 'int8u',
    5156        PrintConv => \%offOn,
     57    },
     58    0x116fea21 => {
     59        Name => 'HighlightData',
     60        SubDirectory => {
     61            TagTable => 'Image::ExifTool::NikonCapture::HighlightData',
     62        },
    5263    },
    5364    0x2175eb78 => {
     
    6677        },
    6778    },
     79    0x39c456ac => {
     80        Name => 'PictureCtrl',
     81        SubDirectory => {
     82            TagTable => 'Image::ExifTool::NikonCapture::PictureCtrl',
     83        },
     84    },
    6885    0x3cfc73c6 => {
    6986        Name => 'RedEyeData',
    7087        SubDirectory => {
    7188            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',
    72100        },
    73101    },
     
    126154        Writable => 'int16u',
    127155    },
     156    0x083a1a25 => {
     157        Name => 'HistogramXML',
     158        Writable => 'undef',
     159        Binary => 1,
     160        AdjustSize => 4,    # patch Nikon bug
     161    },
    128162    0x84589434 => {
    129163        Name => 'BrightnessData',
     
    150184        },
    151185    },
     186  # 0xa7264a72, 0x88f55e48 and 0x416391c6 all change from 0 to 1 when QuickFix is turned on
    152187    0xab5eca5e => {
    153188        Name => 'PhotoEffects',
     
    182217        PrintConv => \%offOn,
    183218    },
     219    0xe2173c47 => {
     220        Name => 'PictureControl',
     221        Writable => 'int8u',
     222        PrintConv => \%offOn,
     223    },
    184224    0xe37b4337 => {
    185225        Name => 'D-LightingHSData',
     
    193233            TagTable => 'Image::ExifTool::NikonCapture::UnsharpData',
    194234        },
     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?)
    195245    },
    196246    0xfe443a45 => {
     
    249299    FIRST_ENTRY => 0,
    250300    GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
    251     0 => 'D-LightingHSShadow',
    252     1 => 'D-LightingHSHighlight',
    253     2 => 'D-LightingHSColorBoost',
     301    0 => 'D-LightingHQShadow',
     302    1 => 'D-LightingHQHighlight',
     303    2 => 'D-LightingHQColorBoost',
    254304);
    255305
     
    299349            4 => 'Calculate Automatically'
    300350        },
     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')
    301356    },
    302357    0x15 => {
     
    315370        Format => 'int16u',
    316371    },
     372    0x25 => {
     373        Name => 'WBAdjTint',
     374        Format => 'int32s',
     375    },
    317376);
    318377
     
    376435    FIRST_ENTRY => 0,
    377436    GROUPS => { 0 => 'MakerNotes', 2 => 'Image' },
    378     4 => {
     437    0x04 => {
    379438        Name => 'EdgeNoiseReduction',
    380439        PrintConv => \%offOn,
    381440    },
    382     5 => {
    383         Name => 'ColorMoireReduction',
     441    0x05 => {
     442        Name => 'ColorMoireReductionMode',
    384443        PrintConv => {
    385444            0 => 'Off',
     
    389448        },
    390449    },
    391     9 => {
     450    0x09 => {
    392451        Name => 'NoiseReductionIntensity',
    393452        Format => 'int32u',
    394453    },
    395     13 => {
     454    0x0d => {
    396455        Name => 'NoiseReductionSharpness',
    397456        Format => 'int32u',
    398457    },
    399     17 => {
     458    0x11 => {
    400459        Name => 'NoiseReductionMethod',
    401460        Format => 'int16u',
     
    405464        },
    406465    },
     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    },
    407482);
    408483
     
    440515    },
    441516    0x8e => {
    442         Name => 'OutputWidthInches',
     517        Name => 'CropOutputWidthInches',
    443518        Format => 'double',
    444519    },
    445520    0x96 => {
    446         Name => 'OutputHeightInches',
     521        Name => 'CropOutputHeightInches',
    447522        Format => 'double',
    448523    },
    449524    0x9e => {
    450         Name => 'ScaledResolution',
     525        Name => 'CropScaledResolution',
    451526        Format => 'double',
    452527    },
    453528    0xae => {
    454         Name => 'SourceResolution',
     529        Name => 'CropSourceResolution',
    455530        Format => 'double',
    456531        ValueConv => '$val / 2',
     
    458533    },
    459534    0xb6 => {
    460         Name => 'OutputResolution',
     535        Name => 'CropOutputResolution',
    461536        Format => 'double',
    462537    },
     
    466541    },
    467542    0xc6 => {
    468         Name => 'OutputWidth',
     543        Name => 'CropOutputWidth',
    469544        Format => 'double',
    470545    },
    471546    0xce => {
    472         Name => 'OutputHeight',
     547        Name => 'CropOutputHeight',
    473548        Format => 'double',
    474549    },
    475550    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)
    479604);
    480605
     
    495620        },
    496621    },
     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',
    497672);
    498673
     
    514689    my $dirStart = $$dirInfo{DirStart};
    515690    my $dirLen = $$dirInfo{DirLen};
    516     my $dirEnd = $dirStart + $dirLen;
    517691    if ($dirLen < 22) {
    518692        $exifTool->Warn('Short Nikon Capture Data',1);
     
    522696    SetByteOrder('II');
    523697    my $tagID = Get32u($dataPt, $dirStart);
     698    # sometimes size includes 18 header bytes, and other times it doesn't (ie. ViewNX 2.1.1)
    524699    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)) {
    526702        $exifTool->Warn('Unrecognized Nikon Capture Data header');
    527703        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 = '';
    528711    }
    529712    my $outBuff = '';
    530713    my $pos;
    531714    my $newTags = $exifTool->GetNewTagInfoHash($tagTablePtr);
     715    my $dirEnd = $dirStart + $dirLen;
    532716
    533717    # loop through all entries in the Nikon Capture data
     
    558742                my $format = $$tagInfo{Format} || $$tagInfo{Writable};
    559743                my $oldVal = ReadValue($dataPt,$pos+22,$format,1,$size);
    560                 my $newValueHash = $exifTool->GetNewValueHash($tagInfo);
    561                 if (Image::ExifTool::IsOverwriting($newValueHash, $oldVal)) {
     744                my $nvHash = $exifTool->GetNewValueHash($tagInfo);
     745                if (Image::ExifTool::IsOverwriting($nvHash, $oldVal)) {
    562746                    my $val = $exifTool->GetNewValues($tagInfo);
    563747                    $newVal = WriteValue($val, $$tagInfo{Writable}) if defined $val;
     
    583767    }
    584768    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        }
    587777    }
    588778    # add the header and return the new directory
    589779    return substr($$dataPt, $dirStart, 18) .
    590780           Set32u(length($outBuff) + 4) .
    591            $outBuff;
     781           $outBuff . $pad;
    592782}
    593783
    594784#------------------------------------------------------------------------------
    595785# 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
     788sub 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
    598824# Returns: 1 on success
    599825sub ProcessNikonCapture($$$)
     
    624850            }
    625851            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);
    627859            } elsif ($size == 1) {
    628860                $value = substr($$dataPt, $pos, $size);
     
    6418731;  # end
    642874
     875__END__
     876
    643877=head1 NAME
    644878
     
    656890=head1 AUTHOR
    657891
    658 Copyright 2003-2007, Phil Harvey (phil at owl.phy.queensu.ca)
     892Copyright 2003-2011, Phil Harvey (phil at owl.phy.queensu.ca)
    659893
    660894This library is free software; you can redistribute it and/or modify it
Note: See TracChangeset for help on using the changeset viewer.