- 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/IPTC.pm
r16842 r24107 4 4 # Description: Read IPTC meta information 5 5 # 6 # Revisions: Jan. 08/ 03 - P. Harvey Created7 # Feb. 05/ 04 - P. Harvey Added support for records other than 26 # Revisions: Jan. 08/2003 - P. Harvey Created 7 # Feb. 05/2004 - P. Harvey Added support for records other than 2 8 8 # 9 9 # References: 1) http://www.iptc.org/IIM/ … … 15 15 use vars qw($VERSION $AUTOLOAD %iptcCharset); 16 16 17 $VERSION = '1. 23';17 $VERSION = '1.42'; 18 18 19 19 %iptcCharset = ( 20 20 "\x1b%G" => 'UTF8', 21 21 # 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 23 23 # "\x1b,A" => 'Latin', # G0 = ISO 8859-1 (similar to Latin1, but codes 0x80-0x9f are missing) 24 24 # "\x1b-A" => 'Latin', # G1 " … … 105 105 9 => { 106 106 Name => 'IPTCPostObjectData', 107 Groups => { 1 => 'IPTC#' }, #(just so this shows up in group list) 107 108 SubDirectory => { 108 109 TagTable => 'Image::ExifTool::IPTC::PostObjectData', 110 }, 111 }, 112 240 => { 113 Name => 'IPTCFotoStation', 114 SubDirectory => { 115 TagTable => 'Image::ExifTool::IPTC::FotoStation', 109 116 }, 110 117 }, … … 120 127 Name => 'EnvelopeRecordVersion', 121 128 Format => 'int16u', 129 Mandatory => 1, 122 130 }, 123 131 5 => { … … 154 162 Name => 'EnvelopePriority', 155 163 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 }, 156 176 }, 157 177 70 => { … … 178 198 convenience. Either string may be used when writing. The value of this tag 179 199 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, 182 207 Format => 'string[0,32]', 183 208 # convert ISO 2022 escape sequences to a more readable format … … 208 233 Name => 'ApplicationRecordVersion', 209 234 Format => 'int16u', 235 Mandatory => 1, 210 236 }, 211 237 3 => { … … 229 255 Name => 'EditorialUpdate', 230 256 Format => 'digits[2]', 257 PrintConv => { 258 '01' => 'Additional language', 259 }, 231 260 }, 232 261 10 => { 233 262 Name => 'Urgency', 234 263 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 }, 235 276 }, 236 277 12 => { … … 454 495 Format => 'string[0,2000]', 455 496 }, 456 121 => { # (format not certain)497 121 => { 457 498 Name => 'LocalCaption', 458 Format => 'string[0,256]', 499 Format => 'string[0,256]', # (guess) 459 500 Notes => q{ 460 501 I haven't found a reference for the format of tags 121, 184-188 and 461 502 225-232, so I have just make them writable as strings with 462 503 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 464 505 }, 465 506 }, … … 472 513 125 => { 473 514 Name => 'RasterizedCaption', 474 Format => ' string[7360]',515 Format => 'undef[7360]', 475 516 Binary => 1, 476 517 }, … … 533 574 Format => 'string[0,64]', 534 575 }, 535 184 => { # (format not certain)576 184 => { 536 577 Name => 'JobID', 537 Format => 'string[0,64]', 538 }, 539 185 => { # (format not certain)578 Format => 'string[0,64]', # (guess) 579 }, 580 185 => { 540 581 Name => 'MasterDocumentID', 541 Format => 'string[0,256]', 542 }, 543 186 => { # (format not certain)582 Format => 'string[0,256]', # (guess) 583 }, 584 186 => { 544 585 Name => 'ShortDocumentID', 545 Format => 'string[0,64]', 546 }, 547 187 => { # (format not certain)586 Format => 'string[0,64]', # (guess) 587 }, 588 187 => { 548 589 Name => 'UniqueDocumentID', 549 Format => 'string[0,128]', 550 }, 551 188 => { # (format not certain)590 Format => 'string[0,128]', # (guess) 591 }, 592 188 => { 552 593 Name => 'OwnerID', 553 Format => 'string[0,128]', 594 Format => 'string[0,128]', # (guess) 554 595 }, 555 596 200 => { … … 567 608 Name => 'ObjectPreviewData', 568 609 Groups => { 2 => 'Image' }, 569 Format => ' string[0,256000]',610 Format => 'undef[0,256000]', 570 611 Binary => 1, 571 612 }, … … 586 627 }, 587 628 }, 588 225 => { # (format not certain)629 225 => { 589 630 Name => 'ClassifyState', 590 Format => 'string[0,64]', 591 }, 592 228 => { # (format not certain)631 Format => 'string[0,64]', # (guess) 632 }, 633 228 => { 593 634 Name => 'SimilarityIndex', 594 Format => 'string[0,32]', 595 }, 596 230 => { # (format not certain)635 Format => 'string[0,32]', # (guess) 636 }, 637 230 => { 597 638 Name => 'DocumentNotes', 598 Format => 'string[0,1024]', 599 }, 600 231 => { # (format not certain)639 Format => 'string[0,1024]', # (guess) 640 }, 641 231 => { 601 642 Name => 'DocumentHistory', 602 Format => 'string[0,256]', 603 }, 604 232 => { # (format not certain)643 Format => 'string[0,256]', # (guess) 644 }, 645 232 => { 605 646 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', 607 654 }, 608 655 ); … … 617 664 Name => 'NewsPhotoVersion', 618 665 Format => 'int16u', 666 Mandatory => 1, 619 667 }, 620 668 10 => { … … 842 890 ); 843 891 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 926 Image::ExifTool::AddCompositeTags('Image::ExifTool::IPTC'); 927 844 928 845 929 #------------------------------------------------------------------------------ … … 863 947 return $val; 864 948 } 865 949 866 950 #------------------------------------------------------------------------------ 867 951 # Handle CodedCharacterSet 868 952 # Inputs: 0) ExifTool ref, 1) CodedCharacterSet value 869 # Returns: externalcharacter set if translation required (or 'bad' if unknown)953 # Returns: IPTC character set if translation required (or 'bad' if unknown) 870 954 sub HandleCodedCharset($$) 871 955 { 872 956 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 } 883 965 } 966 # no need to translate if Charset is the same 967 undef $xlat if $xlat eq $exifTool->Options('Charset'); 884 968 return $xlat; 885 969 } … … 887 971 #------------------------------------------------------------------------------ 888 972 # 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 890 974 # 3) flag set to decode (read) value from IPTC 891 975 # Updates value on return … … 893 977 { 894 978 my ($exifTool, $valPtr, $xlatPtr, $read) = @_; 895 my $escaped;896 979 if ($$xlatPtr eq 'bad') { 897 980 $exifTool->Warn('Some IPTC characters not converted (unsupported CodedCharacterSet)'); 898 981 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 { 900 987 # 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)'); 913 989 } 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 996 sub IsStandardIPTC($) 997 { 998 my $path = shift; 999 return $path =~ /^(JPEG-APP13-Photoshop-IPTC|TIFF-IFD0-IPTC|PSD-IPTC|MIE-IPTC)$/ 914 1000 } 915 1001 … … 928 1014 my $verbose = $exifTool->Options('Verbose'); 929 1015 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 936 1018 $verbose and $dirInfo and $exifTool->VerboseDir('IPTC', 0, $$dirInfo{DirLen}); 1019 937 1020 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 938 1042 my $dirCount = ($exifTool->{DIR_COUNT}->{IPTC} || 0) + 1; 939 1043 $exifTool->{DIR_COUNT}->{IPTC} = $dirCount; 940 1044 $exifTool->{SET_GROUP1} = '+' . $dirCount if $dirCount > 1; 941 1045 } 1046 # begin by assuming default IPTC encoding 1047 my $xlat = $exifTool->Options('CharsetIPTC'); 1048 undef $xlat if $xlat eq $exifTool->Options('Charset'); 1049 942 1050 # quick check for improperly byte-swapped IPTC 943 1051 if ($dirLen >= 4 and substr($$dataPt, $pos, 1) ne "\x1c" and … … 967 1075 my $tableInfo = $tagTablePtr->{$rec}; 968 1076 unless ($tableInfo) { 969 $exifTool->Warn("Unrecognized IPTC record : $rec");1077 $exifTool->Warn("Unrecognized IPTC record $rec, subsequent records ignored"); 970 1078 last; # stop now because we're probably reading garbage 971 1079 } … … 1010 1118 my $tagInfo = $exifTool->GetTagInfo($recordPtr, $tag); 1011 1119 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) 1012 1122 $format = $$tagInfo{Format} if $tagInfo; 1013 1123 # use logic to determine format if not specified … … 1025 1135 } 1026 1136 } elsif ($format =~ /^string/) { 1137 $val =~ s/\0+$//; # some braindead softwares add null terminators 1027 1138 if ($rec == 1) { 1028 1139 # handle CodedCharacterSet tag … … 1033 1144 TranslateCodedString($exifTool, \$val, \$xlat, 1); 1034 1145 } 1035 } elsif ($format !~ /^digits/) { 1146 } elsif ($format =~ /^digits/) { 1147 $val =~ s/\0+$//; 1148 } elsif ($format !~ /^undef/) { 1036 1149 warn("Invalid IPTC format: $format"); 1037 1150 } … … 1045 1158 Start => $pos, 1046 1159 Extra => ", $recordName record", 1160 Format => $format, 1047 1161 ); 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; 1057 1163 $success = 1; 1058 1164 … … 1084 1190 =head1 AUTHOR 1085 1191 1086 Copyright 2003-20 07, Phil Harvey (phil at owl.phy.queensu.ca)1192 Copyright 2003-2011, Phil Harvey (phil at owl.phy.queensu.ca) 1087 1193 1088 1194 This library is free software; you can redistribute it and/or modify it
Note:
See TracChangeset
for help on using the changeset viewer.