/usr/share/perl5/Image/ExifTool/MWG.pm is in libimage-exiftool-perl 10.40-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | #------------------------------------------------------------------------------
# File: MWG.pm
#
# Description: Metadata Working Group support
#
# Revisions: 2009/10/21 - P. Harvey Created
#
# References: 1) http://www.metadataworkinggroup.org/
#------------------------------------------------------------------------------
package Image::ExifTool::MWG;
use strict;
use vars qw($VERSION);
use Image::ExifTool qw(:DataAccess :Utils);
use Image::ExifTool::Exif;
use Image::ExifTool::XMP;
$VERSION = '1.19';
sub RecoverTruncatedIPTC($$$);
sub ListToString($);
sub StringToList($$);
sub OverwriteStringList($$$$);
my $mwgLoaded; # flag set if we alreaded Load()ed the MWG tags
# MWG Composite tags
%Image::ExifTool::MWG::Composite = (
GROUPS => { 0 => 'Composite', 1 => 'MWG', 2 => 'Image' },
VARS => { NO_ID => 1 },
NOTES => q{
The table below lists special Composite tags which are used to access other
tags based on the MWG 2.0 recommendations. These tags are only accessible
when explicitly loaded, but this is done automatically by the exiftool
application if MWG is specified as a group for any tag on the command line,
or manually with the C<-use MWG> option. Via the API, the MWG Composite
tags are loaded by calling "C<Image::ExifTool::MWG::Load()>".
When reading, the value of each MWG tag is B<Derived From> the specified
tags based on the MWG guidelines. When writing, the appropriate associated
tags are written. The value of the IPTCDigest tag is updated automatically
when the IPTC is changed if either the IPTCDigest tag didn't exist
beforehand or its value agreed with the original IPTC digest (indicating
that the XMP is synchronized with the IPTC). IPTC information is written
only if the original file contained IPTC.
Loading the MWG module activates "strict MWG conformance mode", which has
the effect of causing EXIF, IPTC and XMP in non-standard locations to be
ignored when reading, as per the MWG recommendations. Instead, a "Warning"
tag is generated when non-standard metadata is encountered. This feature
may be disabled by setting C<$Image::ExifTool::MWG::strict = 0> in the
L<ExifTool config file|../config.html> (or from your Perl script when using the API). Note
that the behaviour when writing is not changed: ExifTool always creates new
records only in the standard location, but writes new tags to any
EXIF/IPTC/XMP records that exist.
Contrary to the EXIF specification, the MWG recommends that EXIF "ASCII"
string values be stored as UTF-8. To honour this, the exiftool application
sets the default internal EXIF string encoding to "UTF8" when the MWG module
is loaded, but via the API this must be done manually by setting the
CharsetEXIF option.
A complication of the MWG specification is that although the MWG:Creator
property may consist of multiple values, the associated EXIF tag
(EXIF:Artist) is only a simple string. To resolve this discrepancy the MWG
recommends a technique which allows a list of values to be stored in a
string by using a semicolon-space separator (with quotes around values if
necessary). When the MWG module is loaded, ExifTool automatically
implements this policy and changes EXIF:Artist to a list-type tag.
},
Keywords => {
Flags => ['Writable','List'],
Desire => {
0 => 'IPTC:Keywords', # (64-character limit)
1 => 'XMP-dc:Subject',
2 => 'CurrentIPTCDigest',
3 => 'IPTCDigest',
},
RawConv => q{
return $val[1] if not defined $val[2] or (defined $val[1] and
(not defined $val[3] or $val[2] eq $val[3]));
return Image::ExifTool::MWG::RecoverTruncatedIPTC($val[0], $val[1], 64);
},
DelCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteAlso => {
# only write Keywords if IPTC exists (eg. set EditGroup option)
'IPTC:Keywords' => '$opts{EditGroup} = 1; $val',
'XMP-dc:Subject' => '$val',
},
},
Description => {
Writable => 1,
Desire => {
0 => 'EXIF:ImageDescription',
1 => 'IPTC:Caption-Abstract', # (2000-character limit)
2 => 'XMP-dc:Description',
3 => 'CurrentIPTCDigest',
4 => 'IPTCDigest',
},
RawConv => q{
return $val[0] if defined $val[0] and $val[0] !~ /^ *$/;
return $val[2] if not defined $val[3] or (defined $val[2] and
(not defined $val[4] or $val[3] eq $val[4]));
return Image::ExifTool::MWG::RecoverTruncatedIPTC($val[1], $val[2], 2000);
},
DelCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteAlso => {
'EXIF:ImageDescription' => '$val',
'IPTC:Caption-Abstract' => '$opts{EditGroup} = 1; $val',
'XMP-dc:Description' => '$val',
},
},
DateTimeOriginal => {
Description => 'Date/Time Original',
Groups => { 2 => 'Time' },
Notes => '"creation date of the intellectual content being shown" - MWG',
Writable => 1,
Shift => 0, # don't shift this tag
Desire => {
0 => 'Composite:SubSecDateTimeOriginal',
1 => 'EXIF:DateTimeOriginal',
2 => 'IPTC:DateCreated',
3 => 'IPTC:TimeCreated',
4 => 'XMP-photoshop:DateCreated',
5 => 'CurrentIPTCDigest',
6 => 'IPTCDigest',
},
# must check for validity in RawConv to avoid hiding a same-named tag,
# but IPTC dates use a ValueConv so we need to derive the value there
RawConv => '(defined $val[0] or defined $val[1] or defined $val[3]) ? $val : undef',
ValueConv => q{
return $val[0] if defined $val[0] and $val[0] !~ /^[: ]*$/;
return $val[1] if defined $val[1] and $val[1] !~ /^[: ]*$/;
return $val[4] if not defined $val[5] or (defined $val[4] and
(not defined $val[6] or $val[5] eq $val[6]));
return $val[3] ? "$val[2] $val[3]" : $val[2] if $val[2];
return undef;
},
PrintConv => '$self->ConvertDateTime($val)',
PrintConvInv => '$self->InverseDateTime($val,undef,1)',
DelCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteAlso => {
# set EXIF date/time values according to PrintConv option instead
# of defaulting to Type=ValueConv to allow reformatting to be applied
'Composite:SubSecDateTimeOriginal' => 'delete $opts{Type}; $val',
'IPTC:DateCreated' => '$opts{EditGroup} = 1; $val',
'IPTC:TimeCreated' => '$opts{EditGroup} = 1; $val',
'XMP-photoshop:DateCreated' => '$val',
},
},
CreateDate => {
Groups => { 2 => 'Time' },
Notes => '"creation date of the digital representation" - MWG',
Writable => 1,
Shift => 0, # don't shift this tag
Desire => {
0 => 'Composite:SubSecCreateDate',
1 => 'EXIF:CreateDate',
2 => 'IPTC:DigitalCreationDate',
3 => 'IPTC:DigitalCreationTime',
4 => 'XMP-xmp:CreateDate',
5 => 'CurrentIPTCDigest',
6 => 'IPTCDigest',
},
RawConv => '(defined $val[0] or defined $val[1] or defined $val[3]) ? $val : undef',
ValueConv => q{
return $val[0] if defined $val[0] and $val[0] !~ /^[: ]*$/;
return $val[1] if defined $val[1] and $val[1] !~ /^[: ]*$/;
return $val[4] if not defined $val[5] or (defined $val[4] and
(not defined $val[6] or $val[5] eq $val[6]));
return $val[3] ? "$val[2] $val[3]" : $val[2] if $val[2];
return undef;
},
PrintConv => '$self->ConvertDateTime($val)',
PrintConvInv => '$self->InverseDateTime($val,undef,1)',
DelCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteAlso => {
'Composite:SubSecCreateDate' => 'delete $opts{Type}; $val',
'IPTC:DigitalCreationDate' => '$opts{EditGroup} = 1; $val',
'IPTC:DigitalCreationTime' => '$opts{EditGroup} = 1; $val',
'XMP-xmp:CreateDate' => '$val',
},
},
ModifyDate => {
Groups => { 2 => 'Time' },
Notes => '"modification date of the digital image file" - MWG',
Writable => 1,
Shift => 0, # don't shift this tag
Desire => {
0 => 'Composite:SubSecModifyDate',
1 => 'EXIF:ModifyDate',
2 => 'XMP-xmp:ModifyDate',
3 => 'CurrentIPTCDigest',
4 => 'IPTCDigest',
},
RawConv => q{
return $val[0] if defined $val[0] and $val[0] !~ /^[: ]*$/;
return $val[1] if defined $val[1] and $val[1] !~ /^[: ]*$/;
return $val[2] if not defined $val[3] or not defined $val[4] or $val[3] eq $val[4];
return undef;
},
PrintConv => '$self->ConvertDateTime($val)',
PrintConvInv => '$self->InverseDateTime($val,undef,1)',
# return empty string from check routines so this tag will never be set
# (only WriteAlso tags are written), the only difference is a -v2 message
DelCheck => '""',
WriteCheck => '""',
WriteAlso => {
'Composite:SubSecModifyDate' => 'delete $opts{Type}; $val',
'XMP-xmp:ModifyDate' => '$val',
},
},
Orientation => {
Writable => 1,
Require => 'EXIF:Orientation',
ValueConv => '$val',
PrintConv => \%Image::ExifTool::Exif::orientation,
DelCheck => '""',
WriteCheck => '""',
WriteAlso => {
'EXIF:Orientation' => '$val',
},
},
Rating => {
Writable => 1,
Require => 'XMP-xmp:Rating',
ValueConv => '$val',
DelCheck => '""',
WriteCheck => '""',
WriteAlso => {
'XMP-xmp:Rating' => '$val',
},
},
Copyright => {
Groups => { 2 => 'Author' },
Writable => 1,
Desire => {
0 => 'EXIF:Copyright',
1 => 'IPTC:CopyrightNotice', # (128-character limit)
2 => 'XMP-dc:Rights',
3 => 'CurrentIPTCDigest',
4 => 'IPTCDigest',
},
RawConv => q{
return $val[0] if defined $val[0] and $val[0] !~ /^ *$/;
return $val[2] if not defined $val[3] or (defined $val[2] and
(not defined $val[4] or $val[3] eq $val[4]));
return Image::ExifTool::MWG::RecoverTruncatedIPTC($val[1], $val[2], 128);
},
DelCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteAlso => {
'EXIF:Copyright' => q{
# encode if necessary (not automatic because Format is 'undef')
my $enc = $self->Options('CharsetEXIF');
if ($enc) {
my $v = $val;
$self->Encode($v,$enc);
return $v;
}
return $val;
},
'IPTC:CopyrightNotice' => '$opts{EditGroup} = 1; $val',
'XMP-dc:Rights' => '$val',
},
},
Creator => {
Groups => { 2 => 'Author' },
Flags => ['Writable','List'],
Desire => {
0 => 'EXIF:Artist',
1 => 'IPTC:By-line', # (32-character limit)
2 => 'XMP-dc:Creator',
3 => 'CurrentIPTCDigest',
4 => 'IPTCDigest',
},
RawConv => q{
return $val[0] if defined $val[0] and $val[0] !~ /^ *$/;
return $val[2] if not defined $val[3] or (defined $val[2] and
(not defined $val[4] or $val[3] eq $val[4]));
return Image::ExifTool::MWG::RecoverTruncatedIPTC($val[1], $val[2], 32);
},
DelCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteAlso => {
'EXIF:Artist' => '$val',
'IPTC:By-line' => '$opts{EditGroup} = 1; $val',
'XMP-dc:Creator' => '$val',
},
},
Country => {
Groups => { 2 => 'Location' },
Writable => 1,
Desire => {
0 => 'IPTC:Country-PrimaryLocationName', # (64-character limit)
1 => 'XMP-photoshop:Country',
2 => 'XMP-iptcExt:LocationShownCountryName',
3 => 'CurrentIPTCDigest',
4 => 'IPTCDigest',
},
RawConv => q{
my $xmpVal = $val[2] || $val[1];
return $xmpVal if not defined $val[3] or (defined $xmpVal and
(not defined $val[4] or $val[3] eq $val[4]));
return Image::ExifTool::MWG::RecoverTruncatedIPTC($val[0], $xmpVal, 64);
},
DelCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteAlso => {
'IPTC:Country-PrimaryLocationName' => '$opts{EditGroup} = 1; $val',
'XMP-photoshop:Country' => '$val', # (legacy)
'XMP-iptcExt:LocationShownCountryName' => '$val',
},
},
State => {
Groups => { 2 => 'Location' },
Writable => 1,
Desire => {
0 => 'IPTC:Province-State', # (32-character limit)
1 => 'XMP-photoshop:State',
2 => 'XMP-iptcExt:LocationShownProvinceState',
3 => 'CurrentIPTCDigest',
4 => 'IPTCDigest',
},
RawConv => q{
my $xmpVal = $val[2] || $val[1];
return $xmpVal if not defined $val[3] or (defined $xmpVal and
(not defined $val[4] or $val[3] eq $val[4]));
return Image::ExifTool::MWG::RecoverTruncatedIPTC($val[0], $xmpVal, 32);
},
DelCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteAlso => {
'IPTC:Province-State' => '$opts{EditGroup} = 1; $val',
'XMP-photoshop:State' => '$val', # (legacy)
'XMP-iptcExt:LocationShownProvinceState' => '$val',
},
},
City => {
Groups => { 2 => 'Location' },
Writable => 1,
Desire => {
0 => 'IPTC:City', # (32-character limit)
1 => 'XMP-photoshop:City',
2 => 'XMP-iptcExt:LocationShownCity',
3 => 'CurrentIPTCDigest',
4 => 'IPTCDigest',
},
RawConv => q{
my $xmpVal = $val[2] || $val[1];
return $xmpVal if not defined $val[3] or (defined $xmpVal and
(not defined $val[4] or $val[3] eq $val[4]));
return Image::ExifTool::MWG::RecoverTruncatedIPTC($val[0], $xmpVal, 32);
},
DelCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteAlso => {
'IPTC:City' => '$opts{EditGroup} = 1; $val',
'XMP-photoshop:City' => '$val', # (legacy)
'XMP-iptcExt:LocationShownCity' => '$val',
},
},
Location => {
Groups => { 2 => 'Location' },
Writable => 1,
Desire => {
0 => 'IPTC:Sub-location', # (32-character limit)
1 => 'XMP-iptcCore:Location',
2 => 'XMP-iptcExt:LocationShownSublocation',
3 => 'CurrentIPTCDigest',
4 => 'IPTCDigest',
},
RawConv => q{
my $xmpVal = $val[2] || $val[1];
return $xmpVal if not defined $val[3] or (defined $xmpVal and
(not defined $val[4] or $val[3] eq $val[4]));
return Image::ExifTool::MWG::RecoverTruncatedIPTC($val[0], $xmpVal, 32);
},
DelCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteCheck => 'Image::ExifTool::MWG::ReconcileIPTCDigest($self)',
WriteAlso => {
'IPTC:Sub-location' => '$opts{EditGroup} = 1; $val',
'XMP-iptcCore:Location' => '$val', # (legacy)
'XMP-iptcExt:LocationShownSublocation' => '$val',
},
},
);
# MWG XMP structures
my %sExtensions = (
STRUCT_NAME => 'MWG Extensions',
NAMESPACE => undef, # variable namespace
NOTES => q{
This structure may contain any top-level XMP tags, but none have been
pre-defined in ExifTool. Since no flattened tags have been pre-defined,
RegionExtensions is writable only as a structure (eg.
C<{xmp-dc:creator=me,rating=5}>). Fields for this structure are identified
using the standard ExifTool tag name (with optional leading group name,
and/or trailing language code, and/or trailing C<#> symbol to disable print
conversion).
},
);
my %sRegionStruct = (
STRUCT_NAME => 'MWG RegionStruct',
NAMESPACE => 'mwg-rs',
Area => { Struct => \%Image::ExifTool::XMP::sArea },
Type => {
PrintConv => {
Face => 'Face',
Pet => 'Pet',
Focus => 'Focus',
BarCode => 'BarCode',
},
},
Name => { },
Description => { },
FocusUsage => {
PrintConv => {
EvaluatedUsed => 'Evaluated, Used',
EvaluatedNotUsed => 'Evaluated, Not Used',
NotEvaluatedNotUsed => 'Not Evaluated, Not Used',
},
},
BarCodeValue=> { },
Extensions => { Struct => \%sExtensions },
Rotation => { # (observed in LR6 XMP)
Writable => 'real',
Notes => 'RegionsRegionListRotation, not part of MWG 2.0 spec',
},
seeAlso => { Namespace => 'rdfs', Resource => 1 },
);
my %sKeywordStruct;
%sKeywordStruct = (
STRUCT_NAME => 'MWG KeywordStruct',
NAMESPACE => 'mwg-kw',
Keyword => { },
Applied => { Writable => 'boolean' },
Children => { Struct => \%sKeywordStruct, List => 'Bag' },
);
# MWG 2.0 XMP region namespace tags
%Image::ExifTool::MWG::Regions = (
%Image::ExifTool::XMP::xmpTableDefaults,
GROUPS => { 0 => 'XMP', 1 => 'XMP-mwg-rs', 2 => 'Image' },
NAMESPACE => 'mwg-rs',
NOTES => q{
Image region metadata defined by the MWG 2.0 specification. These tags
may be accessed without the need to load the MWG Composite tags above. See
L<http://www.metadataworkinggroup.org/> for the official specification.
},
Regions => {
Name => 'RegionInfo',
FlatName => 'Region',
Struct => {
STRUCT_NAME => 'MWG RegionInfo',
NAMESPACE => 'mwg-rs',
RegionList => {
FlatName => 'Region',
Struct => \%sRegionStruct,
List => 'Bag',
},
AppliedToDimensions => { Struct => \%Image::ExifTool::XMP::sDimensions },
},
},
RegionsRegionList => { Flat => 1, Name => 'RegionList' },
);
# MWG 2.0 XMP hierarchical keyword namespace tags
%Image::ExifTool::MWG::Keywords = (
%Image::ExifTool::XMP::xmpTableDefaults,
GROUPS => { 0 => 'XMP', 1 => 'XMP-mwg-kw', 2 => 'Image' },
NAMESPACE => 'mwg-kw',
NOTES => q{
Hierarchical keywords metadata defined by the MWG 2.0 specification.
ExifTool unrolls keyword structures to an arbitrary depth of 6 to allow
individual levels to be accessed with different tag names, and to avoid
infinite recursion. See L<http://www.metadataworkinggroup.org/> for the
official specification.
},
# arbitrarily define only the first 6 levels of the keyword hierarchy
Keywords => {
Name => 'KeywordInfo',
Struct => {
STRUCT_NAME => 'MWG KeywordInfo',
NAMESPACE => 'mwg-kw',
Hierarchy => { Struct => \%sKeywordStruct, List => 'Bag' },
},
},
KeywordsHierarchy => { Name => 'HierarchicalKeywords', Flat => 1 },
KeywordsHierarchyKeyword => { Name => 'HierarchicalKeywords1', Flat => 1 },
KeywordsHierarchyApplied => { Name => 'HierarchicalKeywords1Applied', Flat => 1 },
KeywordsHierarchyChildren => { Name => 'HierarchicalKeywords1Children', Flat => 1 },
KeywordsHierarchyChildrenKeyword => { Name => 'HierarchicalKeywords2', Flat => 1 },
KeywordsHierarchyChildrenApplied => { Name => 'HierarchicalKeywords2Applied', Flat => 1 },
KeywordsHierarchyChildrenChildren => { Name => 'HierarchicalKeywords2Children', Flat => 1 },
KeywordsHierarchyChildrenChildrenKeyword => { Name => 'HierarchicalKeywords3', Flat => 1 },
KeywordsHierarchyChildrenChildrenApplied => { Name => 'HierarchicalKeywords3Applied', Flat => 1 },
KeywordsHierarchyChildrenChildrenChildren => { Name => 'HierarchicalKeywords3Children', Flat => 1 },
KeywordsHierarchyChildrenChildrenChildrenKeyword => { Name => 'HierarchicalKeywords4', Flat => 1 },
KeywordsHierarchyChildrenChildrenChildrenApplied => { Name => 'HierarchicalKeywords4Applied', Flat => 1 },
KeywordsHierarchyChildrenChildrenChildrenChildren => { Name => 'HierarchicalKeywords4Children', Flat => 1 },
KeywordsHierarchyChildrenChildrenChildrenChildrenKeyword => { Name => 'HierarchicalKeywords5', Flat => 1 },
KeywordsHierarchyChildrenChildrenChildrenChildrenApplied => { Name => 'HierarchicalKeywords5Applied', Flat => 1 },
KeywordsHierarchyChildrenChildrenChildrenChildrenChildren => { Name => 'HierarchicalKeywords5Children', Flat => 1, NoSubStruct => 1 }, # break infinite recursion
KeywordsHierarchyChildrenChildrenChildrenChildrenChildrenKeyword => { Name => 'HierarchicalKeywords6', Flat => 1 },
KeywordsHierarchyChildrenChildrenChildrenChildrenChildrenApplied => { Name => 'HierarchicalKeywords6Applied', Flat => 1 },
);
# MWG 2.0 XMP collections namespace tags
%Image::ExifTool::MWG::Collections = (
%Image::ExifTool::XMP::xmpTableDefaults,
GROUPS => { 0 => 'XMP', 1 => 'XMP-mwg-coll', 2 => 'Image' },
NAMESPACE => 'mwg-coll',
NOTES => q{
Collections metadata defined by the MWG 2.0 specification. See
L<http://www.metadataworkinggroup.org/> for the official specification.
},
Collections => {
FlatName => '',
List => 'Bag',
Struct => {
STRUCT_NAME => 'MWG CollectionInfo',
NAMESPACE => 'mwg-coll',
CollectionName => { },
CollectionURI => { },
},
},
);
#------------------------------------------------------------------------------
# Load the MWG Composite tags
sub Load()
{
return if $mwgLoaded;
# add our composite tags
Image::ExifTool::AddCompositeTags('Image::ExifTool::MWG');
# must also add to lookup so we can write them
# (since MWG tags aren't in the tag lookup by default)
Image::ExifTool::AddTagsToLookup(\%Image::ExifTool::MWG::Composite,
'Image::ExifTool::Composite');
# modify EXIF:Artist to behave as a list-type tag
my $artist = $Image::ExifTool::Exif::Main{0x13b};
$$artist{List} = 1;
$$artist{IsOverwriting} = \&OverwriteStringList;
$$artist{RawConv} = \&StringToList;
# enable MWG strict mode if not set already
# (causes non-standard EXIF, IPTC and XMP to be ignored)
$Image::ExifTool::MWG::strict = 1 unless defined $Image::ExifTool::MWG::strict;
$mwgLoaded = 1;
}
#------------------------------------------------------------------------------
# Change a list of values to a string using MWG rules
# Inputs: 0)reference to list of values
# Returns: string of values (and may reformat list entries)
sub ListToString($)
{
my $vals = shift;
foreach (@$vals) {
# double all quotes in value and quote the value if it begins
# with a quote or contains a semicolon-space separator
if (/^"/ or /; /) {
s/"/""/g; # double all quotes
$_ = qq{"$_"}; # quote the value
}
}
return join('; ', @$vals);
}
#------------------------------------------------------------------------------
# Change a string value to a list of values using MWG rules
# Inputs: 0) string of values, 1) ExifTool ref
# Returns: value or list reference if more than one value
# Notes: Sets Warning tag on error
sub StringToList($$)
{
my ($str, $et) = @_;
my (@vals, $inQuotes);
my @t = split '; ', $str, -1;
foreach (@t) {
my $wasQuotes = $inQuotes;
$inQuotes = 1 if not $inQuotes and s/^"//;
if ($inQuotes) {
# remove the last quote and reset the inQuotes flag if
# the value ended in an odd number of quotes
$inQuotes = 0 if s/((^|[^"])("")*)"$/$1/;
s/""/"/g; # un-double the contained quotes
}
if ($wasQuotes) {
# previous separator was quoted, so concatinate with previous value
$vals[-1] .= '; ' . $_;
} else {
push @vals, $_;
}
}
$et->Warn('Incorrectly quoted MWG string-list value') if $inQuotes;
return @vals > 1 ? \@vals : $vals[0];
}
#------------------------------------------------------------------------------
# Handle logic for overwriting EXIF string-type list tag
# Inputs: 0) ExifTool ref, 1) new value hash ref,
# 2) old string value (or undef if it didn't exist), 3) new value ref
# Returns: 1 and sets the new value for the tag
sub OverwriteStringList($$$$)
{
local $_;
my ($et, $nvHash, $val, $newValuePt) = @_;
my (@new, $delIndex);
if ($$nvHash{DelValue} and defined $val) {
# preserve specified old values
my $old = StringToList($val, $et);
my @old = ref $old eq 'ARRAY' ? @$old : $old;
if (@{$$nvHash{DelValue}}) {
my %del;
$del{$_} = 1 foreach @{$$nvHash{DelValue}};
foreach (@old) {
$del{$_} or push(@new, $_), next;
$delIndex or $delIndex = scalar @new;
}
} else {
push @new, @old;
}
}
# add new values (at location of deleted values, if any)
if ($$nvHash{Value}) {
if (defined $delIndex) {
splice @new, $delIndex, 0, @{$$nvHash{Value}};
} else {
push @new, @{$$nvHash{Value}};
}
}
if (@new) {
# convert back to string format
$$newValuePt = ListToString(\@new);
} else {
$$newValuePt = undef; # delete the tag
}
return 1;
}
#------------------------------------------------------------------------------
# Reconcile IPTC digest after writing an MWG tag
# Inputs: 0) ExifTool object ref
# Returns: empty string
sub ReconcileIPTCDigest($)
{
my $et = shift;
# set new value for IPTCDigest if not done already
unless ($Image::ExifTool::Photoshop::iptcDigestInfo and
$$et{NEW_VALUE}{$Image::ExifTool::Photoshop::iptcDigestInfo})
{
# write new IPTCDigest only if it doesn't exist or
# is the same as the digest of the original IPTC
my @a; # (capture warning messages)
@a = $et->SetNewValue('Photoshop:IPTCDigest', 'old', Protected => 1, DelValue => 1);
@a = $et->SetNewValue('Photoshop:IPTCDigest', 'new', Protected => 1);
}
return '';
}
#------------------------------------------------------------------------------
# Recover strings which were truncated by IPTC dataset length limit
# Inputs: 0) IPTC value, 1) XMP value, 2) length limit
# Notes: handles the case where IPTC and/or XMP values are lists
sub RecoverTruncatedIPTC($$$)
{
my ($iptc, $xmp, $limit) = @_;
return $iptc unless defined $xmp;
if (ref $iptc) {
$xmp = [ $xmp ] unless ref $xmp;
my ($i, @vals);
for ($i=0; $i<@$iptc; ++$i) {
push @vals, RecoverTruncatedIPTC($$iptc[$i], $$xmp[$i], $limit);
}
return \@vals;
} elsif (defined $iptc and length $iptc == $limit) {
$xmp = $$xmp[0] if ref $xmp; # take first element of list
return $xmp if length $xmp > $limit and $iptc eq substr($xmp, 0, $limit);
}
return $iptc;
}
1; # end
__END__
=head1 NAME
Image::ExifTool::MWG - Metadata Working Group support
=head1 SYNOPSIS
# enable MWG Composite tags
use Image::ExifTool::MWG;
Image::ExifTool::MWG::Load();
# enable MWG strict mode
$Image::ExifTool::MWG::strict = 1;
# disable MWG strict mode
$Image::ExifTool::MWG::strict = 0;
=head1 DESCRIPTION
The MWG module contains Composite tag definitions which are designed to
simplify implementation of the Metadata Working Group guidelines. These
special MWG Composite tags are enabled by calling the Load() method:
use Image::ExifTool::MWG;
Image::ExifTool::MWG::Load();
By default, loading the MWG Composite tags enables "strict MWG conformance"
unless previously enabled or disabled by the user. In this mode, ExifTool
will generate a Warning instead of extracting EXIF, IPTC and XMP from
non-standard locations. The strict mode may be disabled or enabled at any
time by setting the MWG "strict" flag to 0 or 1. eg)
$Image::ExifTool::MWG::strict = 0;
This module also contains the MWG XMP tags which are loaded automatically by
ExifTool as required, and are independent of the MWG Composite tags which
must be loaded explicitly as described above.
=head1 AUTHOR
Copyright 2003-2017, Phil Harvey (phil at owl.phy.queensu.ca)
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=head1 REFERENCES
=over 4
=item L<http://www.metadataworkinggroup.org/>
=back
=head1 SEE ALSO
L<Image::ExifTool::TagNames/MWG Tags>,
L<Image::ExifTool(3pm)|Image::ExifTool>
=cut
|