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/IPTC.pm

    r16842 r24107  
    44# Description:  Read IPTC meta information
    55#
    6 # Revisions:    Jan. 08/03 - P. Harvey Created
    7 #               Feb. 05/04 - P. Harvey Added support for records other than 2
     6# Revisions:    Jan. 08/2003 - P. Harvey Created
     7#               Feb. 05/2004 - P. Harvey Added support for records other than 2
    88#
    99# References:   1) http://www.iptc.org/IIM/
     
    1515use vars qw($VERSION $AUTOLOAD %iptcCharset);
    1616
    17 $VERSION = '1.23';
     17$VERSION = '1.42';
    1818
    1919%iptcCharset = (
    2020    "\x1b%G"  => 'UTF8',
    2121   # don't translate these (at least until we handle ISO 2022 shift codes)
    22    # because the sets are only designated and not invoked 
     22   # because the sets are only designated and not invoked
    2323   # "\x1b,A"  => 'Latin',  # G0 = ISO 8859-1 (similar to Latin1, but codes 0x80-0x9f are missing)
    2424   # "\x1b-A"  => 'Latin',  # G1     "
     
    105105    9 => {
    106106        Name => 'IPTCPostObjectData',
     107        Groups => { 1 => 'IPTC#' }, #(just so this shows up in group list)
    107108        SubDirectory => {
    108109            TagTable => 'Image::ExifTool::IPTC::PostObjectData',
     110        },
     111    },
     112    240 => {
     113        Name => 'IPTCFotoStation',
     114        SubDirectory => {
     115            TagTable => 'Image::ExifTool::IPTC::FotoStation',
    109116        },
    110117    },
     
    120127        Name => 'EnvelopeRecordVersion',
    121128        Format => 'int16u',
     129        Mandatory => 1,
    122130    },
    123131    5 => {
     
    154162        Name => 'EnvelopePriority',
    155163        Format => 'digits[1]',
     164        PrintConv => {
     165            0 => '0 (reserved)',
     166            1 => '1 (most urgent)',
     167            2 => 2,
     168            3 => 3,
     169            4 => 4,
     170            5 => '5 (normal urgency)',
     171            6 => 6,
     172            7 => 7,
     173            8 => '8 (least urgent)',
     174            9 => '9 (user-defined priority)',
     175        },
    156176    },
    157177    70 => {
     
    178198            convenience.  Either string may be used when writing.  The value of this tag
    179199            affects the decoding of string values in the Application and NewsPhoto
    180             records
    181         },
     200            records.  This tag is marked as "unsafe" to prevent it from being copied by
     201            default in a group operation because existing tags in the destination image
     202            may use a different encoding.  When creating a new IPTC record from scratch,
     203            it is suggested that this be set to "UTF8" if special characters are a
     204            possibility
     205        },
     206        Protected => 1,
    182207        Format => 'string[0,32]',
    183208        # convert ISO 2022 escape sequences to a more readable format
     
    208233        Name => 'ApplicationRecordVersion',
    209234        Format => 'int16u',
     235        Mandatory => 1,
    210236    },
    211237    3 => {
     
    229255        Name => 'EditorialUpdate',
    230256        Format => 'digits[2]',
     257        PrintConv => {
     258            '01' => 'Additional language',
     259        },
    231260    },
    232261    10 => {
    233262        Name => 'Urgency',
    234263        Format => 'digits[1]',
     264        PrintConv => {
     265            0 => '0 (reserved)',
     266            1 => '1 (most urgent)',
     267            2 => 2,
     268            3 => 3,
     269            4 => 4,
     270            5 => '5 (normal urgency)',
     271            6 => 6,
     272            7 => 7,
     273            8 => '8 (least urgent)',
     274            9 => '9 (user-defined priority)',
     275        },
    235276    },
    236277    12 => {
     
    454495        Format => 'string[0,2000]',
    455496    },
    456     121 => { # (format not certain)
     497    121 => {
    457498        Name => 'LocalCaption',
    458         Format => 'string[0,256]',
     499        Format => 'string[0,256]', # (guess)
    459500        Notes => q{
    460501            I haven't found a reference for the format of tags 121, 184-188 and
    461502            225-232, so I have just make them writable as strings with
    462503            reasonable length.  Beware that if this is wrong, other utilities
    463             won't be able to read these tags as written by ExifTool.
     504            won't be able to read these tags as written by ExifTool
    464505        },
    465506    },
     
    472513    125 => {
    473514        Name => 'RasterizedCaption',
    474         Format => 'string[7360]',
     515        Format => 'undef[7360]',
    475516        Binary => 1,
    476517    },
     
    533574        Format => 'string[0,64]',
    534575    },
    535     184 => { # (format not certain)
     576    184 => {
    536577        Name => 'JobID',
    537         Format => 'string[0,64]',
    538     },
    539     185 => { # (format not certain)
     578        Format => 'string[0,64]', # (guess)
     579    },
     580    185 => {
    540581        Name => 'MasterDocumentID',
    541         Format => 'string[0,256]',
    542     },
    543     186 => { # (format not certain)
     582        Format => 'string[0,256]', # (guess)
     583    },
     584    186 => {
    544585        Name => 'ShortDocumentID',
    545         Format => 'string[0,64]',
    546     },
    547     187 => { # (format not certain)
     586        Format => 'string[0,64]', # (guess)
     587    },
     588    187 => {
    548589        Name => 'UniqueDocumentID',
    549         Format => 'string[0,128]',
    550     },
    551     188 => { # (format not certain)
     590        Format => 'string[0,128]', # (guess)
     591    },
     592    188 => {
    552593        Name => 'OwnerID',
    553         Format => 'string[0,128]',
     594        Format => 'string[0,128]', # (guess)
    554595    },
    555596    200 => {
     
    567608        Name => 'ObjectPreviewData',
    568609        Groups => { 2 => 'Image' },
    569         Format => 'string[0,256000]',
     610        Format => 'undef[0,256000]',
    570611        Binary => 1,
    571612    },
     
    586627        },
    587628    },
    588     225 => { # (format not certain)
     629    225 => {
    589630        Name => 'ClassifyState',
    590         Format => 'string[0,64]',
    591     },
    592     228 => { # (format not certain)
     631        Format => 'string[0,64]', # (guess)
     632    },
     633    228 => {
    593634        Name => 'SimilarityIndex',
    594         Format => 'string[0,32]',
    595     },
    596     230 => { # (format not certain)
     635        Format => 'string[0,32]', # (guess)
     636    },
     637    230 => {
    597638        Name => 'DocumentNotes',
    598         Format => 'string[0,1024]',
    599     },
    600     231 => { # (format not certain)
     639        Format => 'string[0,1024]', # (guess)
     640    },
     641    231 => {
    601642        Name => 'DocumentHistory',
    602         Format => 'string[0,256]',
    603     },
    604     232 => { # (format not certain)
     643        Format => 'string[0,256]', # (guess)
     644    },
     645    232 => {
    605646        Name => 'ExifCameraInfo',
    606         Format => 'string[0,4096]',
     647        Format => 'string[0,4096]', # (guess)
     648    },
     649    255 => { #PH
     650        Name => 'CatalogSets',
     651        List => 1,
     652        Format => 'string[0,256]', # (guess)
     653        Notes => 'written by iView MediaPro',
    607654    },
    608655);
     
    617664        Name => 'NewsPhotoVersion',
    618665        Format => 'int16u',
     666        Mandatory => 1,
    619667    },
    620668    10 => {
     
    842890);
    843891
     892# Record 240 -- FotoStation proprietary data (ref PH)
     893%Image::ExifTool::IPTC::FotoStation = (
     894    GROUPS => { 2 => 'Other' },
     895    WRITE_PROC => \&WriteIPTC,
     896    CHECK_PROC => \&CheckIPTC,
     897    WRITABLE => 1,
     898);
     899
     900# IPTC Composite tags
     901%Image::ExifTool::IPTC::Composite = (
     902    GROUPS => { 2 => 'Image' },
     903    DateTimeCreated => {
     904        Description => 'Date/Time Created',
     905        Groups => { 2 => 'Time' },
     906        Require => {
     907            0 => 'IPTC:DateCreated',
     908            1 => 'IPTC:TimeCreated',
     909        },
     910        ValueConv => '"$val[0] $val[1]"',
     911        PrintConv => '$self->ConvertDateTime($val)',
     912    },
     913    DigitalCreationDateTime => {
     914        Description => 'Digital Creation Date/Time',
     915        Groups => { 2 => 'Time' },
     916        Require => {
     917            0 => 'IPTC:DigitalCreationDate',
     918            1 => 'IPTC:DigitalCreationTime',
     919        },
     920        ValueConv => '"$val[0] $val[1]"',
     921        PrintConv => '$self->ConvertDateTime($val)',
     922    },
     923);
     924
     925# add our composite tags
     926Image::ExifTool::AddCompositeTags('Image::ExifTool::IPTC');
     927
    844928
    845929#------------------------------------------------------------------------------
     
    863947    return $val;
    864948}
    865        
     949
    866950#------------------------------------------------------------------------------
    867951# Handle CodedCharacterSet
    868952# Inputs: 0) ExifTool ref, 1) CodedCharacterSet value
    869 # Returns: external character set if translation required (or 'bad' if unknown)
     953# Returns: IPTC character set if translation required (or 'bad' if unknown)
    870954sub HandleCodedCharset($$)
    871955{
    872956    my ($exifTool, $val) = @_;
    873     my $xlat = $exifTool->Options('Charset');
    874     if ($iptcCharset{$val}) {
    875         # no need to translate if destination is the same
    876         undef $xlat if $xlat eq $iptcCharset{$val};
    877     } elsif ($val =~ /^\x1b\x25/) {
    878         # some unknown character set involked
    879         $xlat = 'bad';  # flag unsupported coding
    880     } else {
    881         # translate all other codes as Latin
    882         undef $xlat if $xlat eq 'Latin';
     957    my $xlat = $iptcCharset{$val};
     958    unless ($xlat) {
     959        if ($val =~ /^\x1b\x25/) {
     960            # some unknown character set invoked
     961            $xlat = 'bad';  # flag unsupported coding
     962        } else {
     963            $xlat = $exifTool->Options('CharsetIPTC');
     964        }
    883965    }
     966    # no need to translate if Charset is the same
     967    undef $xlat if $xlat eq $exifTool->Options('Charset');
    884968    return $xlat;
    885969}
     
    887971#------------------------------------------------------------------------------
    888972# Encode or decode coded string
    889 # Inputs: 0) ExifTool ref, 1) value ptr, 2) destination charset ('Latin','UTF8' or 'bad')
     973# Inputs: 0) ExifTool ref, 1) value ptr, 2) IPTC charset (or 'bad') ref
    890974#         3) flag set to decode (read) value from IPTC
    891975# Updates value on return
     
    893977{
    894978    my ($exifTool, $valPtr, $xlatPtr, $read) = @_;
    895     my $escaped;
    896979    if ($$xlatPtr eq 'bad') {
    897980        $exifTool->Warn('Some IPTC characters not converted (unsupported CodedCharacterSet)');
    898981        undef $$xlatPtr;
    899     } elsif ($$xlatPtr eq 'Latin' xor $read) {
     982    } elsif (not $read) {
     983        $$valPtr = $exifTool->Decode($$valPtr, undef, undef, $$xlatPtr);
     984    } elsif ($$valPtr !~ /[\x14\x15\x1b]/) {
     985        $$valPtr = $exifTool->Decode($$valPtr, $$xlatPtr);
     986    } else {
    900987        # don't yet support reading ISO 2022 shifted character sets
    901         if (not $read or $$valPtr !~ /[\x14\x15\x1b]/) {
    902             # convert from Latin to UTF-8
    903             my $val = Image::ExifTool::Latin2Unicode($$valPtr,'n');
    904             $$valPtr = Image::ExifTool::Unicode2UTF8($val,'n');
    905         } elsif (not $$exifTool{WarnShift2022}) {
    906             $exifTool->Warn('Some IPTC characters not converted (ISO 2022 shifting not supported)');
    907             $$exifTool{WarnShift2022} = 1;
    908         }
    909     } else {
    910         # convert from UTF-8 to Latin
    911         my $val = Image::ExifTool::UTF82Unicode($$valPtr,'n',$exifTool);
    912         $$valPtr = Image::ExifTool::Unicode2Latin($val,'n',$exifTool);
     988        $exifTool->WarnOnce('Some IPTC characters not converted (ISO 2022 shifting not supported)');
    913989    }
     990}
     991
     992#------------------------------------------------------------------------------
     993# Is this IPTC in a standard location?
     994# Inputs: 0) Current metadata path string
     995# Returns: true if path is standard
     996sub IsStandardIPTC($)
     997{
     998    my $path = shift;
     999    return $path =~ /^(JPEG-APP13-Photoshop-IPTC|TIFF-IFD0-IPTC|PSD-IPTC|MIE-IPTC)$/
    9141000}
    9151001
     
    9281014    my $verbose = $exifTool->Options('Verbose');
    9291015    my $success = 0;
    930     my (%listTags, $lastRec, $recordPtr, $recordName);
    931 
    932     # begin by assuming IPTC is Latin (so no translation if Charset is Latin)
    933     my $xlat = $exifTool->Options('Charset');
    934     undef $xlat if $xlat eq 'Latin';
    935    
     1016    my ($lastRec, $recordPtr, $recordName);
     1017
    9361018    $verbose and $dirInfo and $exifTool->VerboseDir('IPTC', 0, $$dirInfo{DirLen});
     1019
    9371020    if ($tagTablePtr eq \%Image::ExifTool::IPTC::Main) {
     1021        # calculate MD5 if Digest::MD5 is available (for standard IPTC only)
     1022        my $path = $exifTool->MetadataPath();
     1023        if (IsStandardIPTC($path)) {
     1024            my $md5;
     1025            if (eval 'require Digest::MD5') {
     1026                if ($pos or $dirLen != length($$dataPt)) {
     1027                    $md5 = Digest::MD5::md5(substr $$dataPt, $pos, $dirLen);
     1028                } else {
     1029                    $md5 = Digest::MD5::md5($$dataPt);
     1030                }
     1031            } else {
     1032                # a zero digest indicates IPTC exists but we don't have Digest::MD5
     1033                $md5 = "\0" x 16;
     1034            }
     1035            $exifTool->FoundTag('CurrentIPTCDigest', $md5);
     1036        } elsif ($Image::ExifTool::MWG::strict and $$exifTool{FILE_TYPE} =~ /^(JPEG|TIFF|PSD)$/) {
     1037            # ignore non-standard IPTC while in strict MWG compatibility mode
     1038            $exifTool->Warn("Ignored non-standard IPTC at $path");
     1039            return 1;
     1040        }
     1041        # set family 1 group name if multiple IPTC directories
    9381042        my $dirCount = ($exifTool->{DIR_COUNT}->{IPTC} || 0) + 1;
    9391043        $exifTool->{DIR_COUNT}->{IPTC} = $dirCount;
    9401044        $exifTool->{SET_GROUP1} = '+' . $dirCount if $dirCount > 1;
    9411045    }
     1046    # begin by assuming default IPTC encoding
     1047    my $xlat = $exifTool->Options('CharsetIPTC');
     1048    undef $xlat if $xlat eq $exifTool->Options('Charset');
     1049
    9421050    # quick check for improperly byte-swapped IPTC
    9431051    if ($dirLen >= 4 and substr($$dataPt, $pos, 1) ne "\x1c" and
     
    9671075            my $tableInfo = $tagTablePtr->{$rec};
    9681076            unless ($tableInfo) {
    969                 $exifTool->Warn("Unrecognized IPTC record: $rec");
     1077                $exifTool->Warn("Unrecognized IPTC record $rec, subsequent records ignored");
    9701078                last;   # stop now because we're probably reading garbage
    9711079            }
     
    10101118        my $tagInfo = $exifTool->GetTagInfo($recordPtr, $tag);
    10111119        my $format;
     1120        # (could use $$recordPtr{FORMAT} if no Format below, but don't do this to
     1121        #  be backward compatible with improperly written PhotoMechanic tags)
    10121122        $format = $$tagInfo{Format} if $tagInfo;
    10131123        # use logic to determine format if not specified
     
    10251135                }
    10261136            } elsif ($format =~ /^string/) {
     1137                $val =~ s/\0+$//;   # some braindead softwares add null terminators
    10271138                if ($rec == 1) {
    10281139                    # handle CodedCharacterSet tag
     
    10331144                    TranslateCodedString($exifTool, \$val, \$xlat, 1);
    10341145                }
    1035             } elsif ($format !~ /^digits/) {
     1146            } elsif ($format =~ /^digits/) {
     1147                $val =~ s/\0+$//;
     1148            } elsif ($format !~ /^undef/) {
    10361149                warn("Invalid IPTC format: $format");
    10371150            }
     
    10451158            Start   => $pos,
    10461159            Extra   => ", $recordName record",
     1160            Format  => $format,
    10471161        );
    1048         # prevent adding tags to list from another IPTC directory
    1049         if ($tagInfo) {
    1050             if ($$tagInfo{List}) {
    1051                 $exifTool->{NO_LIST} = 1 unless $listTags{$tagInfo};
    1052                 $listTags{$tagInfo} = 1;    # list the next one we see
    1053             }
    1054             $exifTool->FoundTag($tagInfo, $val);
    1055         }
    1056         delete $exifTool->{NO_LIST};
     1162        $exifTool->FoundTag($tagInfo, $val) if $tagInfo;
    10571163        $success = 1;
    10581164
     
    10841190=head1 AUTHOR
    10851191
    1086 Copyright 2003-2007, Phil Harvey (phil at owl.phy.queensu.ca)
     1192Copyright 2003-2011, Phil Harvey (phil at owl.phy.queensu.ca)
    10871193
    10881194This library is free software; you can redistribute it and/or modify it
Note: See TracChangeset for help on using the changeset viewer.