| 1 | #------------------------------------------------------------------------------ | ||
| 2 | # File: BuildTagLookup.pm | ||
| 3 | # | ||
| 4 | # Description: Utility to build tag lookup tables in Image::ExifTool::TagLookup.pm | ||
| 5 | # | ||
| 6 | # Revisions: 12/31/2004 - P. Harvey Created | ||
| 7 | # 02/15/2005 - PH Added ability to generate TagNames documentation | ||
| 8 | # | ||
| 9 | # Notes: Documentation for the tag tables may either be placed in the | ||
| 10 | # %docs hash below or in a NOTES entry in the table itself, and | ||
| 11 | # individual tags may have their own Notes entry. | ||
| 12 | #------------------------------------------------------------------------------ | ||
| 13 | |||
| 14 | package Image::ExifTool::BuildTagLookup; | ||
| 15 | |||
| 16 | use strict; | ||
| 17 | require Exporter; | ||
| 18 | |||
| 19 | BEGIN { | ||
| 20 | # prevent ExifTool from loading the user config file | ||
| 21 | $Image::ExifTool::configFile = ''; | ||
| 22 | $Image::ExifTool::debug = 1; # enabled debug messages | ||
| 23 | } | ||
| 24 | |||
| 25 | use vars qw($VERSION @ISA); | ||
| 26 | use Image::ExifTool qw(:Utils :Vars); | ||
| 27 | use Image::ExifTool::Exif; | ||
| 28 | use Image::ExifTool::Shortcuts; | ||
| 29 | use Image::ExifTool::HTML qw(EscapeHTML); | ||
| 30 | use Image::ExifTool::IPTC; | ||
| 31 | use Image::ExifTool::XMP; | ||
| 32 | use Image::ExifTool::Canon; | ||
| 33 | use Image::ExifTool::Nikon; | ||
| 34 | use Image::ExifTool::Sony; | ||
| 35 | use Image::ExifTool::Validate; | ||
| 36 | use Image::ExifTool::MacOS; | ||
| 37 | |||
| 38 | $VERSION = '3.67'; | ||
| 39 | @ISA = qw(Exporter); | ||
| 40 | |||
| 41 | sub NumbersFirst($$); | ||
| 42 | sub SortedTagTablekeys($); | ||
| 43 | |||
| 44 | my $createDate = 'Feb 15, 2005'; | ||
| 45 | |||
| 46 | # global variables to control sorting order of table entries | ||
| 47 | my $numbersFirst = 1; # set to -1 to sort numbers last, or 2 to put negative numbers last | ||
| 48 | my $caseInsensitive; # flag to ignore case when sorting tag names | ||
| 49 | |||
| 50 | # list of all tables in plug-in modules | ||
| 51 | my @pluginTables = ('Image::ExifTool::MWG::Composite'); | ||
| 52 | |||
| 53 | # colors for html pages | ||
| 54 | my $noteFont = "<span class=n>"; | ||
| 55 | my $noteFontSmall = "<span class='n s'>"; | ||
| 56 | |||
| 57 | my $docType = q{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" | ||
| 58 | "http://www.w3.org/TR/html4/loose.dtd"> | ||
| 59 | }; | ||
| 60 | |||
| 61 | my $homePage = 'https://exiftool.org'; | ||
| 62 | |||
| 63 | # tweak the ordering of tables in the documentation | ||
| 64 | my %tweakOrder = ( | ||
| 65 | # this => comes after this | ||
| 66 | # ------- ----------------- | ||
| 67 | JPEG => '-', # JPEG comes first | ||
| 68 | IPTC => 'Exif', # put IPTC after EXIF, | ||
| 69 | GPS => 'XMP', # etc... | ||
| 70 | Composite => 'Extra', | ||
| 71 | CBOR => 'JSON', | ||
| 72 | GeoTiff => 'GPS', | ||
| 73 | CanonVRD=> 'CanonCustom', | ||
| 74 | CaptureOne => 'CanonVRD', | ||
| 75 | DJI => 'Casio', | ||
| 76 | FLIR => 'DJI', | ||
| 77 | FujiFilm => 'FLIR', | ||
| 78 | Google => 'GE', | ||
| 79 | GoPro => 'Google', | ||
| 80 | Kodak => 'JVC', | ||
| 81 | Leaf => 'Kodak', | ||
| 82 | Lytro => 'Leaf', | ||
| 83 | Minolta => 'Lytro', | ||
| 84 | Motorola => 'Minolta', | ||
| 85 | Nikon => 'Motorola', | ||
| 86 | NikonCapture => 'Nikon', | ||
| 87 | NikonCustom => 'NikonCapture', | ||
| 88 | NikonSettings => 'NikonCustom', | ||
| 89 | Nintendo => 'NikonSettings', | ||
| 90 | Panasonic => 'Olympus', | ||
| 91 | Pentax => 'Panasonic', | ||
| 92 | Ricoh => 'Reconyx', | ||
| 93 | Samsung => 'Ricoh', | ||
| 94 | SonyIDC => 'Sony', | ||
| 95 | Unknown => 'SonyIDC', | ||
| 96 | DNG => 'Unknown', | ||
| 97 | PrintIM => 'ICC_Profile', | ||
| 98 | Vorbis => 'Ogg', | ||
| 99 | ID3 => 'PostScript', | ||
| 100 | MinoltaRaw => 'KyoceraRaw', | ||
| 101 | KyoceraRaw => 'CanonRaw', | ||
| 102 | MinoltaRaw => 'KyoceraRaw', | ||
| 103 | PanasonicRaw => 'MinoltaRaw', | ||
| 104 | SigmaRaw => 'PanasonicRaw', | ||
| 105 | PhotoMechanic => 'FotoStation', | ||
| 106 | Microsoft => 'PhotoMechanic', | ||
| 107 | GIMP => 'Microsoft', | ||
| 108 | DarwinCore => 'AFCP', | ||
| 109 | MWG => 'Shortcuts', | ||
| 110 | 'FujiFilm::RAF' => 'FujiFilm::RAFHeader', | ||
| 111 | 'FujiFilm::RAFData' => 'FujiFilm::RAF', | ||
| 112 | 'QuickTime::AudioKeys' => 'QuickTime::Keys', | ||
| 113 | 'QuickTime::VideoKeys' => 'QuickTime::AudioKeys', | ||
| 114 | ); | ||
| 115 | |||
| 116 | # list of all recognized Format strings | ||
| 117 | # (not a complete list, but this is all we use so far) | ||
| 118 | # (also, formats like "var_X[num]" are allowed for any valid X) | ||
| 119 | my %formatOK = ( | ||
| 120 | %Image::ExifTool::Exif::formatNumber, | ||
| 121 | 0 => 1, | ||
| 122 | 1 => 1, | ||
| 123 | 2 => 1, # (writable for docs only) | ||
| 124 | real => 1, | ||
| 125 | integer => 1, | ||
| 126 | date => 1, | ||
| 127 | boolean => 1, | ||
| 128 | rational => 1, | ||
| 129 | 'lang-alt' => 1, | ||
| 130 | fixed16u => 1, | ||
| 131 | fixed16s => 1, | ||
| 132 | fixed32u => 1, | ||
| 133 | fixed32s => 1, | ||
| 134 | extended => 1, | ||
| 135 | resize => 1, | ||
| 136 | digits => 1, | ||
| 137 | int16uRev => 1, | ||
| 138 | int32uRev => 1, | ||
| 139 | rational32u => 1, | ||
| 140 | rational32s => 1, | ||
| 141 | pstring => 1, | ||
| 142 | var_string => 1, | ||
| 143 | var_int16u => 1, | ||
| 144 | var_pstr32 => 1, | ||
| 145 | var_ustr32 => 1, | ||
| 146 | var_ue7 => 1, # (BPG) | ||
| 147 | # Matroska | ||
| 148 | signed => 1, | ||
| 149 | unsigned => 1, | ||
| 150 | utf8 => 1, | ||
| 151 | Unicode => 1, # (Microsoft Xtra) | ||
| 152 | GUID => 1, # (Microsoft Xtra) | ||
| 153 | vt_filetime => 1, # (Microsoft Xtra) | ||
| 154 | ); | ||
| 155 | |||
| 156 | # Descriptions for the TagNames documentation | ||
| 157 | # (descriptions may also be defined in tag table NOTES) | ||
| 158 | # Note: POD headers in these descriptions start with '~' instead of '=' to keep | ||
| 159 | # from confusing POD parsers which apparently parse inside quoted strings. | ||
| 160 | my %docs = ( | ||
| 161 | PodHeader => q{ | ||
| 162 | ~head1 NAME | ||
| 163 | |||
| 164 | Image::ExifTool::TagNames - ExifTool tag name documentation | ||
| 165 | |||
| 166 | ~head1 DESCRIPTION | ||
| 167 | |||
| 168 | This document contains a complete list of ExifTool tag names, organized into | ||
| 169 | tables based on information type. Tag names are used to reference specific | ||
| 170 | meta information extracted from or written to a file. | ||
| 171 | |||
| 172 | ~head1 TAG TABLES | ||
| 173 | }, | ||
| 174 | ExifTool => q{ | ||
| 175 | The tables listed below give the names of all tags recognized by ExifTool. | ||
| 176 | They contain a total of $$self{COUNT}{'total tags'} tags, with $$self{COUNT}{'unique tag names'} unique tag names. | ||
| 177 | }, | ||
| 178 | ExifTool2 => q{ | ||
| 179 | B<Tag ID>, B<Index#> or B<Sequence> is given in the first column of each | ||
| 180 | table. A B<Tag ID> is the computer-readable equivalent of a tag name, and | ||
| 181 | is the identifier that is actually stored in the file. B<Index#> refers to | ||
| 182 | the offset of a value when found at a fixed position within a data block | ||
| 183 | (B<#> is the multiplier for calculating a byte offset: B<1>, B<2>, B<4> or | ||
| 184 | B<8>). These offsets may have a decimal part which is used only to | ||
| 185 | differentiate tags with values stored at the same position. (Note that | ||
| 186 | writable tags within binary data blocks are not individually deletable, | ||
| 187 | and the usual alternative is to set them to a value of zero.) B<Sequence> | ||
| 188 | gives the order of values for a serial data stream. | ||
| 189 | |||
| 190 | A B<Tag Name> is the handle by which the information is accessed in | ||
| 191 | ExifTool. In some instances, more than one name may correspond to a single | ||
| 192 | tag ID. In these cases, the actual name used depends on the context in | ||
| 193 | which the information is found. Valid characters in a tag name are A-Z, | ||
| 194 | a-z, 0-9, hyphen (-) and underline (_). Case is not significant. A | ||
| 195 | question mark (C<?>) after a tag name indicates that the information is | ||
| 196 | either not understood, not verified, or not very useful -- these tags are | ||
| 197 | not extracted by ExifTool unless the L<Unknown|../ExifTool.html#Unknown> (-u) option is enabled. Be | ||
| 198 | aware that some tag names are different than the descriptions printed out by | ||
| 199 | default when extracting information with exiftool. To see the tag names | ||
| 200 | instead of the descriptions, use C<exiftool -s>. | ||
| 201 | |||
| 202 | The B<Writable> column indicates whether the tag is writable by ExifTool. | ||
| 203 | Anything but a C<no> in this column means the tag is writable. A C<yes> | ||
| 204 | indicates writable information that is either unformatted or written using | ||
| 205 | the existing format. Other expressions give details about the format of the | ||
| 206 | stored value, and vary depending on the general type of information. The | ||
| 207 | format name may be followed by a number in square brackets to indicate the | ||
| 208 | number of values written, or the number of characters in a fixed-length | ||
| 209 | string (including a null terminator which is added if required). | ||
| 210 | |||
| 211 | A plus sign (C<+>) after an entry in the B<Writable> column indicates a | ||
| 212 | I<List> tag which supports multiple values and allows individual values to | ||
| 213 | be added and deleted. A slash (C</>) indicates a tag that ExifTool will | ||
| 214 | I<Avoid> when writing. These will be edited but not created if another | ||
| 215 | same-named tag may be created instead. To create these tags, the group | ||
| 216 | should be specified. A tilde (C<~>) indicates a tag this is writable only | ||
| 217 | when the print conversion is disabled (by setting L<PrintConv|../ExifTool.html#PrintConv> to 0, using the | ||
| 218 | -n option, or suffixing the tag name with a C<#> character). An exclamation | ||
| 219 | point (C<!>) indicates a tag that is considered I<Unsafe> to write under | ||
| 220 | normal circumstances. These tags are not written unless specified | ||
| 221 | explicitly (ie. not when wildcards or "all" are used), and care should be | ||
| 222 | taken when editing them manually since they may affect the way an image is | ||
| 223 | rendered. An asterisk (C<*>) indicates a I<Protected> tag which is not | ||
| 224 | writable directly, but is written automatically by ExifTool (often when a | ||
| 225 | corresponding L<Composite|Image::ExifTool::TagNames/Composite Tags> or | ||
| 226 | L<Extra|Image::ExifTool::TagNames/Extra Tags> tag is written). A colon | ||
| 227 | (C<:>) indicates a I<Mandatory> tag which may be added automatically when | ||
| 228 | writing (use the API L<NoMandatory|../ExifTool.html#NoMandatory> option to avoid creating mandatory EXIF | ||
| 229 | tags). Normally MakerNotes tags may not be deleted individually, but a | ||
| 230 | caret (C<^>) indicates a I<Deletable> MakerNotes tag. | ||
| 231 | |||
| 232 | The HTML version of these tables also lists possible B<Values> for | ||
| 233 | discrete-valued tags, as well as B<Notes> for some tags. The B<Values> are | ||
| 234 | listed with the computer-readable values on the left of the equals sign | ||
| 235 | (C<=>), and the human-readable values on the right. The human-readable | ||
| 236 | values are used by default when reading and writing, but the | ||
| 237 | computer-readable values may be accessed by disabling the value conversion | ||
| 238 | with the -n option on the command line, by setting the L<PrintConv|../ExifTool.html#PrintConv> option to 0 | ||
| 239 | in the API, or or on a per-tag basis by adding a hash (C<#>) after the tag | ||
| 240 | name. | ||
| 241 | |||
| 242 | B<Note>: If you are familiar with common meta-information tag names, you may | ||
| 243 | find that some ExifTool tag names are different than expected. The usual | ||
| 244 | reason for this is to make the tag names more consistent across different | ||
| 245 | types of meta information. To determine a tag name, either consult this | ||
| 246 | documentation or run C<exiftool -s> on a file containing the information in | ||
| 247 | question. | ||
| 248 | |||
| 249 | I<(This documentation is the result of decades of research, testing and | ||
| 250 | reverse engineering, and is the most complete metadata tag list available | ||
| 251 | anywhere on the internet. It is provided not only for ExifTool users, but | ||
| 252 | more importantly as a public service to help augment the collective | ||
| 253 | knowledge, and is often used as a primary source of information in the | ||
| 254 | development of other metadata software. Please help keep this documentation | ||
| 255 | as accurate and complete as possible, and feed any new discoveries back to | ||
| 256 | ExifTool. A big thanks to everyone who has helped with this so far!)> | ||
| 257 | }, | ||
| 258 | EXIF => q{ | ||
| 259 | EXIF stands for "Exchangeable Image File Format". This type of information | ||
| 260 | is formatted according to the TIFF specification, and may be found in JPG, | ||
| 261 | TIFF, PNG, JP2, PGF, MIFF, HDP, PSP and XCF images, as well as many | ||
| 262 | TIFF-based RAW images, and even some AVI and MOV videos. | ||
| 263 | |||
| 264 | The EXIF meta information is organized into different Image File Directories | ||
| 265 | (IFD's) within an image. The names of these IFD's correspond to the | ||
| 266 | ExifTool family 1 group names. When writing EXIF information, the default | ||
| 267 | B<Group> listed below is used unless another group is specified. | ||
| 268 | |||
| 269 | Mandatory tags (indicated by a colon after the B<Writable> type) may be | ||
| 270 | added automatically with default values when creating a new IFD, and the IFD | ||
| 271 | is removed automatically when deleting tags if only default-valued mandatory | ||
| 272 | tags remain. | ||
| 273 | |||
| 274 | The table below lists all EXIF tags. Also listed are TIFF, DNG, HDP and | ||
| 275 | other tags which are not part of the EXIF specification, but may co-exist | ||
| 276 | with EXIF tags in some images. Tags which are part of the EXIF 3.0 | ||
| 277 | specification have an underlined B<Tag Name> in the HTML version of this | ||
| 278 | documentation. See | ||
| 279 | L<https://www.cipa.jp/std/documents/download_e.html?CIPA_DC-008-2024-E> | ||
| 280 | for the official EXIF 3.0 specification. | ||
| 281 | }, | ||
| 282 | GPS => q{ | ||
| 283 | These GPS tags are part of the EXIF standard, and are stored in a separate | ||
| 284 | IFD within the EXIF information. | ||
| 285 | |||
| 286 | ExifTool is very flexible about the input format when writing lat/long | ||
| 287 | coordinates, and will accept from 1 to 3 floating point numbers (for decimal | ||
| 288 | degrees, degrees and minutes, or degrees, minutes and seconds) separated by | ||
| 289 | just about anything, and will format them properly according to the EXIF | ||
| 290 | specification. | ||
| 291 | |||
| 292 | Some GPS tags have values which are fixed-length strings. For these, the | ||
| 293 | indicated string lengths include a null terminator which is added | ||
| 294 | automatically by ExifTool. Remember that the descriptive values are used | ||
| 295 | when writing (eg. 'Above Sea Level', not '0') unless the print conversion is | ||
| 296 | disabled (with '-n' on the command line or the L<PrintConv|../ExifTool.html#PrintConv> option in the API, | ||
| 297 | or by suffixing the tag name with a C<#> character). | ||
| 298 | |||
| 299 | When adding GPS information to an image, it is important to set all of the | ||
| 300 | following tags: GPSLatitude, GPSLatitudeRef, GPSLongitude, GPSLongitudeRef, | ||
| 301 | and GPSAltitude and GPSAltitudeRef if the altitude is known. ExifTool will | ||
| 302 | write the required GPSVersionID tag automatically if new a GPS IFD is added | ||
| 303 | to an image. | ||
| 304 | }, | ||
| 305 | XMP => q{ | ||
| 306 | XMP stands for "Extensible Metadata Platform", an XML/RDF-based metadata | ||
| 307 | format which is being pushed by Adobe. Information in this format can be | ||
| 308 | embedded in many different image file types including JPG, JP2, TIFF, GIF, | ||
| 309 | EPS, PDF, PSD, IND, INX, PNG, DJVU, SVG, PGF, MIFF, XCF, CRW, DNG and a | ||
| 310 | variety of proprietary TIFF-based RAW images, as well as MOV, AVI, ASF, WMV, | ||
| 311 | FLV, SWF and MP4 videos, and WMA and audio formats supporting ID3v2 | ||
| 312 | information. | ||
| 313 | |||
| 314 | The XMP B<Tag ID>'s aren't listed because in most cases they are identical | ||
| 315 | to the B<Tag Name> (aside from differences in case). Tags with different | ||
| 316 | ID's are mentioned in the B<Notes> column of the HTML version of this | ||
| 317 | document. | ||
| 318 | |||
| 319 | All XMP information is stored as character strings. The B<Writable> column | ||
| 320 | specifies the information format: C<string> is an unformatted string, | ||
| 321 | C<integer> is a string of digits (possibly beginning with a '+' or '-'), | ||
| 322 | C<real> is a floating point number, C<rational> is entered as a floating | ||
| 323 | point number but stored as two C<integer> strings separated by a '/' | ||
| 324 | character, C<date> is a date/time string entered in the format "YYYY:mm:dd | ||
| 325 | HH:MM:SS[.ss][+/-HH:MM]" but some partial date/time formats are also | ||
| 326 | accepted (see L<https://exiftool.org/faq.html#Q5>), C<boolean> is either | ||
| 327 | "True" or "False" (but "true" and "false" may be written as a ValueConv | ||
| 328 | value for compatibility with non-conforming applications), C<struct> | ||
| 329 | indicates a structured tag, and C<lang-alt> is a tag that supports alternate | ||
| 330 | languages. | ||
| 331 | |||
| 332 | When reading, C<struct> tags are extracted only if the L<Struct|../ExifTool.html#Struct> (-struct) | ||
| 333 | option is used. Otherwise the corresponding I<Flattened> tags, indicated by | ||
| 334 | an underline (C<_>) after the B<Writable> type, are extracted. When | ||
| 335 | copying, by default both structured and flattened tags are available, but | ||
| 336 | the flattened tags are considered "unsafe" so they aren't copied unless | ||
| 337 | specified explicitly. The L<Struct|../ExifTool.html#Struct> option may be disabled by setting Struct | ||
| 338 | to 0 via the API or with --struct on the command line to copy only flattened | ||
| 339 | tags, or enabled by setting Struct to 1 via the API or with -struct on the | ||
| 340 | command line to copy only as structures. When writing, the L<Struct|../ExifTool.html#Struct> option | ||
| 341 | has no effect, and both structured and flattened tags may be written. See | ||
| 342 | L<https://exiftool.org/struct.html> for more details. | ||
| 343 | |||
| 344 | Individual languages for C<lang-alt> tags are accessed by suffixing the tag | ||
| 345 | name with a '-', followed by an RFC 3066 language code (eg. "XMP:Title-fr", | ||
| 346 | or "Rights-en-US"). (See L<http://www.ietf.org/rfc/rfc3066.txt> for the RFC | ||
| 347 | 3066 specification.) A C<lang-alt> tag with no language code accesses the | ||
| 348 | "x-default" language, but causes other languages for this tag to be deleted | ||
| 349 | when writing. The "x-default" language code may be specified when writing | ||
| 350 | to preserve other existing languages (eg. "XMP-dc:Description-x-default"). | ||
| 351 | When reading, "x-default" is not specified. | ||
| 352 | |||
| 353 | The XMP tags are organized according to schema B<Namespace> in the following | ||
| 354 | tables. The ExifTool family 1 group names are derived from the namespace | ||
| 355 | prefixes by adding a leading "XMP-" (eg. "XMP-dc"). A few of the longer | ||
| 356 | prefixes have been shortened (as mentioned in the documentation below) to | ||
| 357 | avoid excessively long ExifTool group names. The tags of any namespace may | ||
| 358 | be deleted as a group by specifying the family 1 group name (eg. | ||
| 359 | "-XMP-dc:all=" on the command line). This includes namespaces which are not | ||
| 360 | pre-defined by ExifTool. | ||
| 361 | |||
| 362 | In cases where a tag name exists in more than one namespace, less common | ||
| 363 | namespaces are avoided when writing. However, a specific namespace may be | ||
| 364 | written by providing a family 1 group name for the tag (eg. XMP-crs:Contrast | ||
| 365 | or XMP-exif:Contrast). When deciding on which tags to add to an image, | ||
| 366 | using standard schemas such as L<dc|/XMP dc Tags>, L<xmp|/XMP xmp Tags>, | ||
| 367 | L<iptcCore|/XMP iptcCore Tags> and L<iptcExt|/XMP iptcExt Tags> is | ||
| 368 | recommended if possible. | ||
| 369 | |||
| 370 | For structures, the heading of the first column is B<Field Name>. Field | ||
| 371 | names are very similar to tag names, except they are used to identify fields | ||
| 372 | inside structures instead of stand-alone tags. See | ||
| 373 | L<the Field Name section of the Structured Information documentation|https://exiftool.org/struct.html#Fields> for more | ||
| 374 | details. | ||
| 375 | |||
| 376 | ExifTool will extract XMP information even if it is not listed in these | ||
| 377 | tables, but other tags are not writable unless added as user-defined tags in | ||
| 378 | the L<ExifTool config file|../config.html>. For example, the C<pdfx> namespace doesn't have a | ||
| 379 | predefined set of tag names because it is used to store application-defined | ||
| 380 | PDF information, so although this information will be extracted, it is only | ||
| 381 | writable if the corresponding user-defined tags have been created. | ||
| 382 | |||
| 383 | The tables below list tags from the official XMP specification (with an | ||
| 384 | underlined B<Namespace> in the HTML version of this documentation), as well | ||
| 385 | as extensions from various other sources. See | ||
| 386 | L<http://www.adobe.com/devnet/xmp/> for the official XMP specification. | ||
| 387 | }, | ||
| 388 | IPTC => q{ | ||
| 389 | The tags listed below are part of the International Press Telecommunications | ||
| 390 | Council (IPTC) and the Newspaper Association of America (NAA) Information | ||
| 391 | Interchange Model (IIM). This is an older meta information format, slowly | ||
| 392 | being phased out in favor of XMP -- the newer IPTCCore specification uses | ||
| 393 | XMP format. IPTC information may be found in JPG, TIFF, PNG, MIFF, PS, PDF, | ||
| 394 | PSD, XCF and DNG images. | ||
| 395 | |||
| 396 | IPTC information is separated into different records, each of which has its | ||
| 397 | own set of tags. See | ||
| 398 | L<http://www.iptc.org/std/IIM/4.1/specification/IIMV4.1.pdf> for the | ||
| 399 | official IPTC IIM specification. | ||
| 400 | |||
| 401 | This specification dictates a length for ASCII (C<string> or C<digits>) and | ||
| 402 | binary (C<undef>) values. These lengths are given in square brackets after | ||
| 403 | the B<Writable> format name. For tags where a range of lengths is allowed, | ||
| 404 | the minimum and maximum lengths are separated by a comma within the | ||
| 405 | brackets. When writing, ExifTool issues a minor warning and truncates the | ||
| 406 | value if it is longer than allowed by the IPTC specification. Minor errors | ||
| 407 | may be ignored with the L<IgnoreMinorErrors|../ExifTool.html#IgnoreMinorErrors> (-m) option, allowing longer | ||
| 408 | values to be written, but beware that values like this may cause problems | ||
| 409 | for some other IPTC readers. ExifTool will happily read IPTC values of any | ||
| 410 | length. | ||
| 411 | |||
| 412 | Separate IPTC date and time tags may be written with a combined date/time | ||
| 413 | value and ExifTool automagically takes the appropriate part of the date/time | ||
| 414 | string depending on whether a date or time tag is being written. This is | ||
| 415 | very useful when copying date/time values to IPTC from other metadata | ||
| 416 | formats. | ||
| 417 | |||
| 418 | IPTC time values include a timezone offset. If written with a value which | ||
| 419 | doesn't include a timezone then the current local timezone offset is used | ||
| 420 | (unless written with a combined date/time, in which case the local timezone | ||
| 421 | offset at the specified date/time is used, which may be different due to | ||
| 422 | changes in daylight savings time). | ||
| 423 | |||
| 424 | Note that it is not uncommon for IPTC to be found in non-standard locations | ||
| 425 | in JPEG and TIFF-based images. When reading, the family 1 group name has a | ||
| 426 | number added for non-standard IPTC ("IPTC2", "IPTC3", etc), but when writing | ||
| 427 | only "IPTC" may be specified as the group. To keep the IPTC consistent, | ||
| 428 | ExifTool updates tags in all existing IPTC locations, but will create a new | ||
| 429 | IPTC group only in the standard location. | ||
| 430 | }, | ||
| 431 | QuickTime => q{ | ||
| 432 | The QuickTime format is used for many different types of audio, video and | ||
| 433 | image files (most notably, MOV/MP4 videos and HEIC/CR3 images). ExifTool | ||
| 434 | extracts standard meta information and a variety of audio, video and image | ||
| 435 | parameters, as well as proprietary information written by many camera | ||
| 436 | models. Tags with a question mark after their name are not extracted unless | ||
| 437 | the L<Unknown|../ExifTool.html#Unknown> option is set. | ||
| 438 | |||
| 439 | When writing video files, ExifTool creates both QuickTime and XMP tags by | ||
| 440 | default, but the group may be specified to write one or the other | ||
| 441 | separately. If no location is specified, newly created QuickTime tags are | ||
| 442 | added in the L<ItemList|Image::ExifTool::TagNames/QuickTime ItemList Tags> | ||
| 443 | location if possible, otherwise in | ||
| 444 | L<UserData|Image::ExifTool::TagNames/QuickTime UserData Tags>, and | ||
| 445 | finally in L<Keys|Image::ExifTool::TagNames/QuickTime Keys Tags>, | ||
| 446 | but this order may be changed by setting the PREFERRED level of the | ||
| 447 | appropriate table in the config file (see | ||
| 448 | L<example.config|../config.html#PREF> in the full distribution for an | ||
| 449 | example). Note that some tags with the same name but different ID's may | ||
| 450 | exist in the same location, but the family 7 group names may be used to | ||
| 451 | differentiate these. | ||
| 452 | |||
| 453 | ExifTool currently writes | ||
| 454 | L<ItemList|Image::ExifTool::TagNames/QuickTime ItemList Tags> and | ||
| 455 | L<UserData|Image::ExifTool::TagNames/QuickTime UserData Tags> only as | ||
| 456 | top-level metadata, but select Keys tags are may be written to the audio or | ||
| 457 | video track. See the | ||
| 458 | L<AudioKeys|Image::ExifTool::TagNames/QuickTime AudioKeys Tags> and | ||
| 459 | L<VideoKeys|Image::ExifTool::TagNames/QuickTime VideoKeys Tags> tags for | ||
| 460 | more information. | ||
| 461 | |||
| 462 | Alternate language tags may be accessed for | ||
| 463 | L<ItemList|Image::ExifTool::TagNames/QuickTime ItemList Tags> and | ||
| 464 | L<Keys|Image::ExifTool::TagNames/QuickTime Keys Tags> tags by adding | ||
| 465 | a 3-character ISO 639-2 language code and an optional ISO 3166-1 alpha 2 | ||
| 466 | country code to the tag name (eg. "ItemList:Artist-deu" or | ||
| 467 | "ItemList::Artist-deu-DE"). Most | ||
| 468 | L<UserData|Image::ExifTool::TagNames/QuickTime UserData Tags> tags support a | ||
| 469 | language code, but without a country code. If no language code is specified | ||
| 470 | when writing, the default language is written and alternate languages for | ||
| 471 | the tag are deleted. Use the "und" language code to write the default | ||
| 472 | language without deleting alternate languages. Note that when reading, | ||
| 473 | "eng" is also treated as the default language if there is no country code. | ||
| 474 | |||
| 475 | According to the specification, integer-format QuickTime date/time tags | ||
| 476 | should be stored as UTC. Unfortunately, digital cameras often store local | ||
| 477 | time values instead (presumably because they don't know the time zone). For | ||
| 478 | this reason, by default ExifTool does not assume a time zone for these | ||
| 479 | values. However, if the API L<QuickTimeUTC|../ExifTool.html#QuickTimeUTC> option is set, then ExifTool will | ||
| 480 | assume these values are properly stored as UTC, and will convert them to | ||
| 481 | local time when extracting. | ||
| 482 | |||
| 483 | When writing string-based date/time tags, the system time zone is added if | ||
| 484 | the PrintConv option is enabled and no time zone is specified. This is | ||
| 485 | because Apple software may display crazy values if the time zone is missing | ||
| 486 | for some tags. | ||
| 487 | |||
| 488 | By default ExifTool will remove null padding from some QuickTime containers | ||
| 489 | in Canon CR3 files when writing, but the | ||
| 490 | L<QuickTimePad|../ExifTool.html#QuickTimePad> option may be used to preserve | ||
| 491 | the original size by padding with nulls if necessary. | ||
| 492 | |||
| 493 | See | ||
| 494 | L<https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/> | ||
| 495 | for the official QuickTime specification. | ||
| 496 | }, | ||
| 497 | Photoshop => q{ | ||
| 498 | Photoshop tags are found in PSD and PSB files, as well as inside embedded | ||
| 499 | Photoshop information in many other file types (JPEG, TIFF, PDF, PNG to name | ||
| 500 | a few). | ||
| 501 | |||
| 502 | Many Photoshop tags are marked as Unknown (indicated by a question mark | ||
| 503 | after the tag name) because the information they provide is not very useful | ||
| 504 | under normal circumstances. These unknown tags are not extracted unless the | ||
| 505 | L<Unknown|../ExifTool.html#Unknown> (-u) option is used. See | ||
| 506 | L<http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/> for the | ||
| 507 | official specification | ||
| 508 | |||
| 509 | Photoshop path tags (Tag ID's 0x7d0 to 0xbb5) are not defined by default, | ||
| 510 | but a config file included in the full ExifTool distribution | ||
| 511 | (config_files/photoshop_paths.config) contains the tag definitions to allow | ||
| 512 | access to this information. | ||
| 513 | }, | ||
| 514 | PrintIM => q{ | ||
| 515 | The format of the PrintIM information is known, however no PrintIM tags have | ||
| 516 | been decoded. Use the L<Unknown|../ExifTool.html#Unknown> (-u) option to extract PrintIM information. | ||
| 517 | }, | ||
| 518 | GeoTiff => q{ | ||
| 519 | ExifTool extracts the following tags from GeoTIFF images. See | ||
| 520 | L<https://web.archive.org/web/20070820121549/http://www.remotesensing.org/geotiff/spec/geotiffhome.html> | ||
| 521 | for the complete GeoTIFF specification. Also included in the table below | ||
| 522 | are ChartTIFF tags (see | ||
| 523 | L<https://web.archive.org/web/20020828193928/http://www.charttiff.com/whitepapers.shtml>). | ||
| 524 | GeoTIFF tags are not writable individually, but they may be copied en mass | ||
| 525 | via the block tags GeoTiffDirectory, GeoTiffDoubleParams and | ||
| 526 | GeoTiffAsciiParams. | ||
| 527 | }, | ||
| 528 | JFIF => q{ | ||
| 529 | The following information is extracted from the JPEG JFIF header. See | ||
| 530 | L<https://www.w3.org/Graphics/JPEG/jfif3.pdf> for the JFIF 1.02 | ||
| 531 | specification. | ||
| 532 | }, | ||
| 533 | Kodak => q{ | ||
| 534 | Many Kodak models don't store the maker notes in standard IFD format, and | ||
| 535 | these formats vary with different models. Some information has been | ||
| 536 | decoded, but much of the Kodak information remains unknown. | ||
| 537 | }, | ||
| 538 | 'Kodak SpecialEffects' => q{ | ||
| 539 | The Kodak SpecialEffects and Borders tags are found in sub-IFD's within the | ||
| 540 | Kodak JPEG APP3 "Meta" segment. | ||
| 541 | }, | ||
| 542 | Minolta => q{ | ||
| 543 | These tags are used by Minolta, Konica/Minolta as well as some Sony cameras. | ||
| 544 | Minolta doesn't make things easy for decoders because the meaning of some | ||
| 545 | tags and the location where some information is stored is different for | ||
| 546 | different camera models. (Take MinoltaQuality for example, which may be | ||
| 547 | located in 5 different places.) | ||
| 548 | }, | ||
| 549 | Olympus => q{ | ||
| 550 | Tags 0x0000 through 0x0103 are used by some older Olympus cameras, and are | ||
| 551 | the same as Konica/Minolta tags. These tags are also used for some models | ||
| 552 | from other brands such as Acer, BenQ, Epson, Hitachi, HP, Maginon, Minolta, | ||
| 553 | Pentax, Ricoh, Samsung, Sanyo, SeaLife, Sony, Supra and Vivitar. | ||
| 554 | }, | ||
| 555 | Panasonic => q{ | ||
| 556 | These tags are used in Panasonic/Leica cameras. | ||
| 557 | }, | ||
| 558 | Pentax => q{ | ||
| 559 | These tags are used in Pentax/Asahi/Ricoh cameras. | ||
| 560 | }, | ||
| 561 | CanonRaw => q{ | ||
| 562 | These tags apply to CRW-format Canon RAW files and information in the APP0 | ||
| 563 | "CIFF" segment of JPEG images. When writing CanonRaw/CIFF information, the | ||
| 564 | length of the information is preserved (and the new information is truncated | ||
| 565 | or padded as required) unless B<Writable> is C<resize>. Currently, only | ||
| 566 | JpgFromRaw and ThumbnailImage are allowed to change size. See | ||
| 567 | L<https://exiftool.org/canon_raw.html> for a description of the Canon CRW | ||
| 568 | format. | ||
| 569 | |||
| 570 | CRW images also support the addition of a CanonVRD trailer, which in turn | ||
| 571 | supports XMP. This trailer is created automatically if necessary when | ||
| 572 | ExifTool is used to write XMP to a CRW image. | ||
| 573 | }, | ||
| 574 | NikonCustom => q{ | ||
| 575 | Unfortunately, the NikonCustom settings are stored in a binary data block | ||
| 576 | which changes from model to model. This means that significant effort must | ||
| 577 | be spent in decoding these for each model, usually requiring hundreds of | ||
| 578 | test images from a dedicated Nikon owner. For this reason, the NikonCustom | ||
| 579 | settings have not been decoded for all models. The tables below list the | ||
| 580 | custom settings for the currently supported models. | ||
| 581 | }, | ||
| 582 | Unknown => q{ | ||
| 583 | The following tags are decoded in unsupported maker notes. Use the L<Unknown|../ExifTool.html#Unknown> | ||
| 584 | (-u) option to display other unknown tags. | ||
| 585 | }, | ||
| 586 | PDF => q{ | ||
| 587 | The tags listed in the PDF tables below are those which are used by ExifTool | ||
| 588 | to extract meta information, but they are only a small fraction of the total | ||
| 589 | number of available PDF tags. See | ||
| 590 | L<http://www.adobe.com/devnet/pdf/pdf_reference.html> for the official PDF | ||
| 591 | specification. | ||
| 592 | |||
| 593 | ExifTool supports reading and writing PDF documents up to version 2.0, | ||
| 594 | including support for RC4, AES-128 and AES-256 encryption. A | ||
| 595 | L<Password|../ExifTool.html#Password> option is provided to allow processing | ||
| 596 | of password-protected PDF files. | ||
| 597 | |||
| 598 | ExifTool may be used to write native PDF and XMP metadata to PDF files. It | ||
| 599 | uses an incremental update technique that has the advantages of being both | ||
| 600 | fast and reversible. If ExifTool was used to modify a PDF file, the | ||
| 601 | original may be recovered by deleting the C<PDF-update> pseudo-group (with | ||
| 602 | C<-PDF-update:all=> on the command line). However, there are two main | ||
| 603 | disadvantages to this technique: | ||
| 604 | |||
| 605 | 1) A linearized PDF file is no longer linearized after the update, so it | ||
| 606 | must be subsequently re-linearized if this is required. | ||
| 607 | |||
| 608 | 2) All metadata edits are reversible. While this would normally be | ||
| 609 | considered an advantage, it is a potential security problem because old | ||
| 610 | information is never actually deleted from the file. (However, after | ||
| 611 | running ExifTool the old information may be removed permanently using the | ||
| 612 | "qpdf" utility with this command: "qpdf --linearize in.pdf out.pdf".) | ||
| 613 | }, | ||
| 614 | DNG => q{ | ||
| 615 | The main DNG tags are found in the EXIF table. The tables below define only | ||
| 616 | information found within structures of these main DNG tag values. See | ||
| 617 | L<https://helpx.adobe.com/camera-raw/digital-negative.html> for the official | ||
| 618 | DNG specification. | ||
| 619 | }, | ||
| 620 | MPEG => q{ | ||
| 621 | The MPEG format doesn't specify any file-level meta information. In lieu of | ||
| 622 | this, information is extracted from the first audio and video frame headers | ||
| 623 | in the file. | ||
| 624 | }, | ||
| 625 | Real => q{ | ||
| 626 | ExifTool recognizes three basic types of Real audio/video files: 1) | ||
| 627 | RealMedia (RM, RV and RMVB), 2) RealAudio (RA), and 3) Real Metafile (RAM | ||
| 628 | and RPM). | ||
| 629 | }, | ||
| 630 | Extra => q{ | ||
| 631 | The extra tags provide extra features or extra information extracted or | ||
| 632 | generated by ExifTool that is not directly associated with another tag | ||
| 633 | group. The B<Group> column lists the family 1 group name when reading. | ||
| 634 | Tags with a "-" in this column are write-only. | ||
| 635 | |||
| 636 | Tags in the family 1 "System" group are referred to as "pseudo" tags because | ||
| 637 | they don't represent real metadata in the file. Instead, this information | ||
| 638 | is stored in the directory structure of the filesystem. The B<Writable> | ||
| 639 | System "pseudo" tags in this table may be written without modifying the file | ||
| 640 | itself. The TestName tag is used for dry-run testing before writing | ||
| 641 | FileName. | ||
| 642 | }, | ||
| 643 | Composite => q{ | ||
| 644 | The values of the composite tags are B<Derived From> the values of other | ||
| 645 | tags. These are convenience tags which are calculated after all other | ||
| 646 | information is extracted. Only a few of these tags are writable directly, | ||
| 647 | the others are changed by writing the corresponding B<Derived From> tags. | ||
| 648 | User-defined Composite tags, also useful for custom-formatting of tag | ||
| 649 | values, may created via the L<ExifTool configuration file|../config.html>. | ||
| 650 | }, | ||
| 651 | Shortcuts => q{ | ||
| 652 | Shortcut tags are convenience tags that represent one or more other tag | ||
| 653 | names. They are used like regular tags to read and write the information | ||
| 654 | for a specified set of tags. | ||
| 655 | |||
| 656 | The shortcut tags below have been pre-defined, but user-defined shortcuts | ||
| 657 | may be added via the %Image::ExifTool::UserDefined::Shortcuts lookup in the | ||
| 658 | ~/.ExifTool_config file. See the Image::ExifTool::Shortcuts documentation | ||
| 659 | for more details. | ||
| 660 | }, | ||
| 661 | MWG => q{ | ||
| 662 | The Metadata Working Group (MWG) recommends techniques to allow certain | ||
| 663 | overlapping EXIF, IPTC and XMP tags to be reconciled when reading, and | ||
| 664 | synchronized when writing. The MWG Composite tags below are designed to aid | ||
| 665 | in the implementation of these recommendations. As well, the MWG defines | ||
| 666 | new XMP tags which are listed in the subsequent tables below. See | ||
| 667 | L<https://web.archive.org/web/20180919181934/http://www.metadataworkinggroup.org/pdf/mwg_guidance.pdf> | ||
| 668 | for the official MWG specification. | ||
| 669 | }, | ||
| 670 | MacOS => q{ | ||
| 671 | On MacOS systems, the there are additional MDItem and XAttr Finder tags that | ||
| 672 | may be extracted. These tags are not extracted by default -- they must be | ||
| 673 | specifically requested or enabled via an API option. (Except when reading | ||
| 674 | MacOS "._" files directly, see below.) | ||
| 675 | |||
| 676 | The tables below list some of the tags that may be extracted, but ExifTool | ||
| 677 | will extract all available information even for tags not listed. | ||
| 678 | |||
| 679 | Tags in these tables are referred to as "pseudo" tags because their | ||
| 680 | information is not stored in the file itself. As such, B<Writable> tags in | ||
| 681 | these tables may be changed without having to rewrite the file. | ||
| 682 | }, | ||
| 683 | GM => q{ | ||
| 684 | These tags are extracted from GM/Cosworth PDR (Performance Data Recorder) | ||
| 685 | information found in videos from General Motors cars such as Corvette and | ||
| 686 | Camero. | ||
| 687 | |||
| 688 | Use the API L<PrintCSV|../ExifTool.html#PrintCSV> option to output all timed | ||
| 689 | PDR data in CSV format at greatly increased speed and with much lower memory | ||
| 690 | usage. This option prints the numerical values for each channel in CSV | ||
| 691 | format, suitable for import into RaceRender. In this output, the gear | ||
| 692 | numbers for Neutral and Reverse are changed to -1 and -100 respectively for | ||
| 693 | compatibility with RaceRender. | ||
| 694 | }, | ||
| 695 | PodTrailer => q{ | ||
| 696 | ~head1 NOTES | ||
| 697 | |||
| 698 | This document generated automatically by | ||
| 699 | L<Image::ExifTool::BuildTagLookup|Image::ExifTool::BuildTagLookup>. | ||
| 700 | |||
| 701 | ~head1 AUTHOR | ||
| 702 | |||
| 703 | Copyright 2003-2026, Phil Harvey (philharvey66 at gmail.com) | ||
| 704 | |||
| 705 | This library is free software; you can redistribute it and/or modify it | ||
| 706 | under the same terms as Perl itself. | ||
| 707 | |||
| 708 | ~head1 SEE ALSO | ||
| 709 | |||
| 710 | L<Image::ExifTool(3pm)|Image::ExifTool> | ||
| 711 | |||
| 712 | ~cut | ||
| 713 | }, | ||
| 714 | ); | ||
| 715 | |||
| 716 | # notes for Shortcuts tags | ||
| 717 | my %shortcutNotes = ( | ||
| 718 | AllDates => q{ | ||
| 719 | contrary to the shortcut name, this represents only the common EXIF | ||
| 720 | date/time tags. To access all date/time tags, use Time:All instead | ||
| 721 | }, | ||
| 722 | MakerNotes => q{ | ||
| 723 | useful when copying tags between files to either copy the maker notes as a | ||
| 724 | block or prevent it from being copied | ||
| 725 | }, | ||
| 726 | ColorSpaceTags => q{ | ||
| 727 | standard tags which carry color space information. Useful for preserving | ||
| 728 | color space when deleting all other metadata | ||
| 729 | }, | ||
| 730 | CommonIFD0 => q{ | ||
| 731 | common metadata tags found in IFD0 of TIFF-format images. Used to simplify | ||
| 732 | deletion of all metadata from these images. See | ||
| 733 | L<FAQ number 7|../faq.html#Q7> for details | ||
| 734 | }, | ||
| 735 | Unsafe => q{ | ||
| 736 | I<Unsafe> tags in JPEG images which are normally not copied. Defined here | ||
| 737 | as a shortcut to use when rebuilding JPEG EXIF from scratch. See | ||
| 738 | L<FAQ number 20|../faq.html#Q20> for more information | ||
| 739 | }, | ||
| 740 | LargeTags => q{ | ||
| 741 | large binary data tags which may be excluded to reduce memory usage if | ||
| 742 | memory limitations are a problem | ||
| 743 | }, | ||
| 744 | 'ls-l' => q{ | ||
| 745 | mimics columns shown by Unix "ls -l" command. Includes some tags which are | ||
| 746 | extracted only if the API L<SystemTags|../ExifTool.html#SystemTags> option | ||
| 747 | is enabled | ||
| 748 | }, | ||
| 749 | ); | ||
| 750 | |||
| 751 | # lookup for RIFF INFO tags which are found in the EXIF spec | ||
| 752 | my %riffSpec = ( | ||
| 753 | IARL => 1, ICRD => 1, IGNR => 1, IPLT => 1, ISRC => 1, | ||
| 754 | IART => 1, ICRP => 1, IKEY => 1, IPRD => 1, ISRF => 1, | ||
| 755 | ICMS => 1, IDIM => 1, ILGT => 1, ISBJ => 1, ITCH => 1, | ||
| 756 | ICMT => 1, IDPI => 1, IMED => 1, ISFT => 1, | ||
| 757 | ICOP => 1, IENG => 1, INAM => 1, ISHP => 1, | ||
| 758 | ); | ||
| 759 | # same thing for XMP namespaces | ||
| 760 | my %xmpSpec = ( | ||
| 761 | aux => 1, 'x' => 1, | ||
| 762 | crs => 1, xmp => 1, | ||
| 763 | dc => 1, xmpBJ => 1, | ||
| 764 | exif => 1, xmpDM => 1, | ||
| 765 | pdf => 1, xmpMM => 1, | ||
| 766 | pdfx => 1, xmpNote => 1, | ||
| 767 | photoshop => 1, xmpRights => 1, | ||
| 768 | tiff => 1, xmpTPg => 1, | ||
| 769 | ); | ||
| 770 | |||
| 771 | #------------------------------------------------------------------------------ | ||
| 772 | # New - create new BuildTagLookup object | ||
| 773 | # Inputs: 0) reference to BuildTagLookup object or BuildTagLookup class name | ||
| 774 | sub new | ||
| 775 | { | ||
| 776 | local $_; | ||
| 777 | my $that = shift; | ||
| 778 | my $class = ref($that) || $that || 'Image::ExifTool::BuildTagLookup'; | ||
| 779 | my $self = bless {}, $class; | ||
| 780 | my (%subdirs, %isShortcut); | ||
| 781 | my %count = ( | ||
| 782 | 'unique tag names' => 0, | ||
| 783 | 'total tags' => 0, | ||
| 784 | ); | ||
| 785 | # | ||
| 786 | # loop through all tables, accumulating TagLookup and TagName information | ||
| 787 | # | ||
| 788 | my (%tagNameInfo, %id, %longID, %longName, %shortName, %tableNum, | ||
| 789 | %tagLookup, %tagExists, %noLookup, %tableWritable, %sepTable, %case, | ||
| 790 | %structs, %compositeModules, %isPlugin, %flattened, %structLookup, | ||
| 791 | @writePseudo, %dupXmpTag); | ||
| 792 | $self->{TAG_NAME_INFO} = \%tagNameInfo; | ||
| 793 | $self->{ID_LOOKUP} = \%id; | ||
| 794 | $self->{LONG_ID} = \%longID; | ||
| 795 | $self->{LONG_NAME} = \%longName; | ||
| 796 | $self->{SHORT_NAME} = \%shortName; | ||
| 797 | $self->{TABLE_NUM} = \%tableNum; | ||
| 798 | $self->{TAG_LOOKUP} = \%tagLookup; | ||
| 799 | $self->{TAG_EXISTS} = \%tagExists; | ||
| 800 | $self->{FLATTENED} = \%flattened; | ||
| 801 | $self->{TABLE_WRITABLE} = \%tableWritable; | ||
| 802 | $self->{SEPARATE_TABLE} = \%sepTable; | ||
| 803 | $self->{STRUCTURES} = \%structs; | ||
| 804 | $self->{STRUCT_LOOKUP} = \%structLookup; # lookup for Struct hash ref based on Struct name | ||
| 805 | $self->{COMPOSITE_MODULES} = \%compositeModules; | ||
| 806 | $self->{COUNT} = \%count; | ||
| 807 | $self->{WRITE_PSEUDO} = \@writePseudo; | ||
| 808 | |||
| 809 | Image::ExifTool::LoadAllTables(); | ||
| 810 | my @tableNames = sort keys %allTables; | ||
| 811 | # add Shortcuts after other tables | ||
| 812 | push @tableNames, 'Image::ExifTool::Shortcuts::Main'; | ||
| 813 | # add plug-in modules last | ||
| 814 | foreach (@pluginTables) { | ||
| 815 | push @tableNames, $_; | ||
| 816 | $isPlugin{$_} = 1; | ||
| 817 | } | ||
| 818 | |||
| 819 | my $tableNum = 0; | ||
| 820 | my $et = Image::ExifTool->new; | ||
| 821 | my ($tableName, $tag); | ||
| 822 | # create lookup for short table names | ||
| 823 | foreach $tableName (@tableNames) { | ||
| 824 | my $short = $tableName; | ||
| 825 | $short =~ s/^Image::ExifTool:://; | ||
| 826 | $short =~ s/::Main$//; | ||
| 827 | $short =~ s/::/ /; | ||
| 828 | $short =~ s/^(.+)Tags$/\u$1/ unless $short eq 'Nikon AVITags'; | ||
| 829 | $short =~ s/^Exif\b/EXIF/; | ||
| 830 | # change underlines to dashes in XMP-mwg group names | ||
| 831 | # (we used underlines just because Perl variables can't contain dashes) | ||
| 832 | $short =~ s/^XMP mwg_/XMP mwg-/; | ||
| 833 | $shortName{$tableName} = $short; # remember short name | ||
| 834 | $tableNum{$tableName} = $tableNum++; | ||
| 835 | } | ||
| 836 | # validate DICOM UID values | ||
| 837 | foreach (values %Image::ExifTool::DICOM::uid) { | ||
| 838 | next unless /[\0-\x1f\x7f-\xff]/; | ||
| 839 | warn "Warning: Special characters in DICOM UID value ($_)\n"; | ||
| 840 | } | ||
| 841 | # make lookup table to check for shortcut tags | ||
| 842 | foreach $tag (keys %Image::ExifTool::Shortcuts::Main) { | ||
| 843 | my $entry = $Image::ExifTool::Shortcuts::Main{$tag}; | ||
| 844 | # ignore if shortcut tag name includes itself | ||
| 845 | next if ref $entry eq 'ARRAY' and grep /^$tag$/, @$entry; | ||
| 846 | $isShortcut{lc($tag)} = 1; | ||
| 847 | } | ||
| 848 | foreach $tableName (@tableNames) { | ||
| 849 | # create short table name | ||
| 850 | my $short = $shortName{$tableName}; | ||
| 851 | my $info = $tagNameInfo{$tableName} = [ ]; | ||
| 852 | my $isPlugin = $isPlugin{$tableName}; | ||
| 853 | my ($table, $shortcut, %isOffset, %datamember, %hasSubdir); | ||
| 854 | if ($short eq 'Shortcuts') { | ||
| 855 | # can't use GetTagTable() for Shortcuts (not a normal table) | ||
| 856 | $table = \%Image::ExifTool::Shortcuts::Main; | ||
| 857 | $shortcut = 1; | ||
| 858 | } elsif ($isPlugin) { | ||
| 859 | $table = GetTagTable($tableName); | ||
| 860 | # don't add to allTables list because this messes our table order | ||
| 861 | delete $allTables{$tableName}; | ||
| 862 | pop @tableOrder; | ||
| 863 | } else { | ||
| 864 | $table = GetTagTable($tableName); | ||
| 865 | } | ||
| 866 | my $tableNum = $tableNum{$tableName}; | ||
| 867 | my $writeProc = $$table{WRITE_PROC}; | ||
| 868 | my $vars = $$table{VARS} || { }; | ||
| 869 | $longID{$tableName} = 0; | ||
| 870 | $longName{$tableName} = 0; | ||
| 871 | # save all tag names | ||
| 872 | my ($tagID, $binaryTable, $noID, $prtID, $isIPTC, $isXMP); | ||
| 873 | $isIPTC = 1 if $writeProc and $writeProc eq \&Image::ExifTool::IPTC::WriteIPTC; | ||
| 874 | # generate flattened tag names for structure fields if this is an XMP table | ||
| 875 | if ($$table{GROUPS} and $$table{GROUPS}{0} eq 'XMP' or $$vars{ADD_FLATTENED}) { | ||
| 876 | Image::ExifTool::XMP::AddFlattenedTags($table); | ||
| 877 | $isXMP = 1; | ||
| 878 | } | ||
| 879 | $prtID = $$vars{ID_FMT}; | ||
| 880 | $noID = 1 if $isXMP or $short =~ /^(Shortcuts|ASF.*)$/ or $prtID and $prtID eq 'none'; | ||
| 881 | if ($$table{WRITE_PROC} and $$table{WRITE_PROC} eq \&Image::ExifTool::WriteBinaryData | ||
| 882 | and not $$table{CHECK_PROC}) | ||
| 883 | { | ||
| 884 | warn("Binary table $tableName doesn't have a CHECK_PROC\n"); | ||
| 885 | } | ||
| 886 | my $processBinaryData = ($$table{PROCESS_PROC} and ( | ||
| 887 | $$table{PROCESS_PROC} eq \&Image::ExifTool::ProcessBinaryData or | ||
| 888 | $$table{PROCESS_PROC} eq \&Image::ExifTool::Nikon::ProcessNikonEncrypted or | ||
| 889 | $$table{PROCESS_PROC} eq \&Image::ExifTool::Sony::ProcessEnciphered) or | ||
| 890 | $$table{VARS} and $$table{VARS}{IS_BINARY}); | ||
| 891 | if ($$vars{ID_LABEL} or $processBinaryData) { | ||
| 892 | my $s = $$table{FORMAT} ? Image::ExifTool::FormatSize($$table{FORMAT}) || 1 : 1; | ||
| 893 | $binaryTable = 1; | ||
| 894 | $id{$tableName} = $$vars{ID_LABEL} || "Index$s"; | ||
| 895 | } elsif ($isIPTC and $$table{PROCESS_PROC}) { #only the main IPTC table has a PROCESS_PROC | ||
| 896 | $id{$tableName} = 'Record'; | ||
| 897 | } elsif (not $noID) { | ||
| 898 | $id{$tableName} = 'Tag ID'; | ||
| 899 | } | ||
| 900 | $caseInsensitive = $isXMP; | ||
| 901 | $numbersFirst = 2; | ||
| 902 | $numbersFirst = -1 if $$table{VARS} and $$table{VARS}{ALPHA_FIRST}; | ||
| 903 | my @keys = SortedTagTableKeys($table); | ||
| 904 | $numbersFirst = 1; | ||
| 905 | my $defFormat = $table->{FORMAT}; | ||
| 906 | # use default format for binary data tables | ||
| 907 | $defFormat = 'int8u' if not $defFormat and $binaryTable; | ||
| 908 | |||
| 909 | TagID: foreach $tagID (@keys) { | ||
| 910 | my ($tagInfo, @tagNames, $subdir, @values); | ||
| 911 | my (@infoArray, @require, @writeGroup, @writable); | ||
| 912 | if ($shortcut) { | ||
| 913 | # must build a dummy tagInfo list since Shortcuts is not a normal table | ||
| 914 | $tagInfo = { | ||
| 915 | Name => $tagID, | ||
| 916 | Notes => $shortcutNotes{$tagID}, | ||
| 917 | Writable => 1, | ||
| 918 | Require => { }, | ||
| 919 | }; | ||
| 920 | my $i; | ||
| 921 | for ($i=0; $i<@{$$table{$tagID}}; ++$i) { | ||
| 922 | $tagInfo->{Require}->{$i} = $table->{$tagID}->[$i]; | ||
| 923 | } | ||
| 924 | @infoArray = ( $tagInfo ); | ||
| 925 | } else { | ||
| 926 | @infoArray = GetTagInfoList($table,$tagID); | ||
| 927 | } | ||
| 928 | foreach $tagInfo (@infoArray) { | ||
| 929 | if ($binaryTable and $$tagInfo{Writable} and $$tagInfo{Writable} ne '1') { | ||
| 930 | warn("$tableName $$tagInfo{Name} Writable should be 1, not $$tagInfo{Writable}\n"); | ||
| 931 | } | ||
| 932 | my $name = $$tagInfo{Name}; | ||
| 933 | if ($$tagInfo{WritePseudo}) { | ||
| 934 | push @writePseudo, $name; | ||
| 935 | warn "Writable pseudo tag $name is not protected!\n" unless $$tagInfo{Protected}; | ||
| 936 | } | ||
| 937 | unless ($$tagInfo{SubDirectory} or $$tagInfo{Struct}) { | ||
| 938 | my $lc = lc $name; | ||
| 939 | warn "Different case for $tableName $name $case{$lc}\n" if $case{$lc} and $case{$lc} ne $name; | ||
| 940 | $case{$lc} = $name; | ||
| 941 | } | ||
| 942 | my $format = $$tagInfo{Format}; | ||
| 943 | # check TagID's to make sure they don't start with 'ID-' | ||
| 944 | my @grps = $et->GetGroup($tagInfo); | ||
| 945 | foreach (@grps) { | ||
| 946 | warn "Group name starts with 'ID-' for $short $name\n" if /^ID-/i; | ||
| 947 | } | ||
| 948 | if ($isXMP and not $$tagInfo{Avoid} and not $$tagInfo{Struct} and | ||
| 949 | ($$tagInfo{Writable} or $$table{WRITABLE})) | ||
| 950 | { | ||
| 951 | $dupXmpTag{$name} and warn "Duplicate writable XMP tag $name\n"; | ||
| 952 | $dupXmpTag{$name} = 1; | ||
| 953 | } | ||
| 954 | # validate Name (must not start with a digit or else XML output will not be valid; | ||
| 955 | # must not start with a dash or exiftool command line may get confused) | ||
| 956 | if ($name !~ /^[_A-Za-z][-\w]+$/ and | ||
| 957 | # single-character subdirectory names are allowed | ||
| 958 | (not $$tagInfo{SubDirectory} or $name !~ /^[_A-Za-z]$/)) | ||
| 959 | { | ||
| 960 | warn "Warning: Invalid tag name $short '${name}'\n"; | ||
| 961 | } | ||
| 962 | # validate list type | ||
| 963 | if ($$tagInfo{List} and $$tagInfo{List} !~ /^(1|Alt|Bag|Seq|array|string)$/) { | ||
| 964 | warn "Warning: Unknown List type ($$tagInfo{List}) for $name in $tableName\n"; | ||
| 965 | } | ||
| 966 | if ($$tagInfo{Hook} and $$tagInfo{Unknown}) { | ||
| 967 | warn "Warning: Unknown tag with Hook - $short $name\n" | ||
| 968 | } | ||
| 969 | # accumulate information for consistency check of BinaryData tables | ||
| 970 | if ($processBinaryData and $$table{WRITABLE}) { | ||
| 971 | # can't currently write tag if Condition accesses $valPt | ||
| 972 | if ($$tagInfo{Condition} and not $$tagInfo{SubDirectory} and | ||
| 973 | $$tagInfo{Condition} =~ /\$valPt/ and | ||
| 974 | ($$tagInfo{Writable} or not defined $$tagInfo{Writable})) | ||
| 975 | { | ||
| 976 | warn "Warning: Tag not writable due to Condition - $short $name\n"; | ||
| 977 | } | ||
| 978 | $isOffset{$tagID} = $name if $$tagInfo{IsOffset}; | ||
| 979 | $hasSubdir{$tagID} = $name if $$tagInfo{SubDirectory}; | ||
| 980 | # require DATAMEMBER for writable var-format tags, Hook and DataMember tags | ||
| 981 | if ($format and $format =~ /^var_/) { | ||
| 982 | $datamember{$tagID} = $name; | ||
| 983 | unless (defined $$tagInfo{Writable} and not $$tagInfo{Writable}) { | ||
| 984 | warn "Warning: Var-format tag is writable - $short $name\n"; | ||
| 985 | } | ||
| 986 | # also need DATAMEMBER for tags used in length of var-sized value | ||
| 987 | while ($format =~ /\$val\{(.*?)\}/g) { | ||
| 988 | my $id = $1; | ||
| 989 | $id = hex($id) if $id =~ /^0x/; # convert from hex if necessary | ||
| 990 | $datamember{$id} = $$table{$id}{Name} if ref $$table{$id} eq 'HASH'; | ||
| 991 | unless ($datamember{$id}) { | ||
| 992 | warn "Warning: Unknown ID ($id) used in Format - $short $name\n"; | ||
| 993 | } | ||
| 994 | } | ||
| 995 | } elsif ($$tagInfo{Hook} or ($$tagInfo{RawConv} and | ||
| 996 | $$tagInfo{RawConv} =~ /\$self(->)?\{\w+\}\s*=(?!~)/)) | ||
| 997 | { | ||
| 998 | $datamember{$tagID} = $name; | ||
| 999 | } | ||
| 1000 | if ($format and $format =~ /\$val\{/ and | ||
| 1001 | ($$tagInfo{Writable} or not defined $$tagInfo{Writable})) | ||
| 1002 | { | ||
| 1003 | warn "Warning: \$val{} used in Format of writable tag - $short $name\n"; | ||
| 1004 | } | ||
| 1005 | } | ||
| 1006 | if ($$tagInfo{Hidden}) { | ||
| 1007 | if ($$tagInfo{Hidden} ne '2' and not $$tagInfo{Unknown} and | ||
| 1008 | (not $$tagInfo{RawConv} or $$tagInfo{RawConv} !~ /Unknown|undef/)) | ||
| 1009 | { | ||
| 1010 | warn "Warning: $short $name is Hidden contrary to guidelines\n"; | ||
| 1011 | } | ||
| 1012 | if ($tagInfo == $infoArray[0]) { | ||
| 1013 | next TagID; # hide all tags with this ID if first tag in list is hidden | ||
| 1014 | } else { | ||
| 1015 | next; # only hide this tag | ||
| 1016 | } | ||
| 1017 | } | ||
| 1018 | my $writable; | ||
| 1019 | if (defined $$tagInfo{Writable}) { | ||
| 1020 | $writable = $$tagInfo{Writable}; | ||
| 1021 | # validate Writable | ||
| 1022 | unless ($formatOK{$writable} or ($writable =~ /(.*)\[/ and $formatOK{$1})) { | ||
| 1023 | warn "Warning: Unknown Writable ($writable) - $short $name\n"; | ||
| 1024 | } | ||
| 1025 | } elsif (not $$tagInfo{SubDirectory}) { | ||
| 1026 | $writable = $$table{WRITABLE}; | ||
| 1027 | } | ||
| 1028 | # in general, we can't write unless we have a WRITE_PROC | ||
| 1029 | if ($writable and not ($$table{WRITE_PROC} or $tableName =~ /Shortcuts/ or $writable eq '2')) { | ||
| 1030 | undef $writable; | ||
| 1031 | } | ||
| 1032 | #if ($writable and $$tagInfo{Unknown} and $$table{GROUPS}{0} ne 'MakerNotes') { | ||
| 1033 | # warn "Warning: Writable Unknown tag - $short $name\n"; | ||
| 1034 | #} | ||
| 1035 | # validate some characteristics of obvious date/time tags | ||
| 1036 | my @g = $et->GetGroup($tagInfo); | ||
| 1037 | if ($$tagInfo{List} and $g[2] eq 'Time' and $writable and not $$tagInfo{Protected} and | ||
| 1038 | not $$tagInfo{PrintConvInv}) | ||
| 1039 | { | ||
| 1040 | # (this is a problem because shifting Time:All would create a new list entry) | ||
| 1041 | warn "Writable List-type Time tag $g[1]:$name has no PrintConvInv and is not Protected!\n"; | ||
| 1042 | } | ||
| 1043 | if ($$tagInfo{PrintConv} and $$tagInfo{PrintConv} eq '$self->ConvertDateTime($val)') { | ||
| 1044 | warn "$short $name should be in 'Time' group!\n" unless $g[2] eq 'Time'; | ||
| 1045 | if ($writable and not defined $$tagInfo{Shift} and $short ne 'PostScript') { | ||
| 1046 | warn "$short $name is not shiftable!\n"; | ||
| 1047 | } | ||
| 1048 | if ($writable and (not $$tagInfo{PrintConvInv} or | ||
| 1049 | $$tagInfo{PrintConvInv} !~ /InverseDateTime/)) | ||
| 1050 | { | ||
| 1051 | warn "$short $name missing InverseDateTime PrintConvInv\n"; | ||
| 1052 | } | ||
| 1053 | } elsif ($name =~ /DateTime(?!Stamp)/ and (not $$tagInfo{Groups}{2} or | ||
| 1054 | $$tagInfo{Groups}{2} ne 'Time') and $short ne 'DICOM') { | ||
| 1055 | warn "$short $name should be in 'Time' group!\n"; | ||
| 1056 | } | ||
| 1057 | if ($name eq 'DateTimeOriginal' and (not $$tagInfo{Description} or | ||
| 1058 | $$tagInfo{Description} ne 'Date/Time Original')) | ||
| 1059 | { | ||
| 1060 | warn "Need Description for $short DateTimeOriginal\n"; | ||
| 1061 | } | ||
| 1062 | # validate Description (can't contain special characters) | ||
| 1063 | if ($$tagInfo{Description} and | ||
| 1064 | $$tagInfo{Description} ne EscapeHTML($$tagInfo{Description})) | ||
| 1065 | { | ||
| 1066 | # this is a problem because the Escape option currently only | ||
| 1067 | # escapes descriptions if the default Lang option isn't default | ||
| 1068 | warn "$name description contains special characters!\n"; | ||
| 1069 | } | ||
| 1070 | # generate structure lookup | ||
| 1071 | my $struct = $$tagInfo{Struct}; | ||
| 1072 | my $strTable; | ||
| 1073 | if (ref $struct) { | ||
| 1074 | $strTable = $struct; | ||
| 1075 | $struct = $$strTable{STRUCT_NAME}; | ||
| 1076 | if ($struct) { | ||
| 1077 | my $oldTable = $structLookup{$struct}; | ||
| 1078 | if ($oldTable and $oldTable ne $strTable) { | ||
| 1079 | warn "Duplicate XMP structure with name $struct\n"; | ||
| 1080 | } else { | ||
| 1081 | $structLookup{$struct} = $strTable; | ||
| 1082 | } | ||
| 1083 | } else { | ||
| 1084 | warn "Missing STRUCT_NAME for structure in $$tagInfo{Name}\n"; | ||
| 1085 | undef $strTable; | ||
| 1086 | } | ||
| 1087 | } elsif ($struct) { | ||
| 1088 | $strTable = $structLookup{$struct}; | ||
| 1089 | unless ($strTable) { | ||
| 1090 | $struct = "XMP $struct" unless $struct =~ / /; | ||
| 1091 | warn "Missing $struct structure!\n"; | ||
| 1092 | undef $struct; | ||
| 1093 | } | ||
| 1094 | } | ||
| 1095 | # validate SubIFD flag | ||
| 1096 | my $subdir = $$tagInfo{SubDirectory}; | ||
| 1097 | my $isSub = ($subdir and $$subdir{Start} and $$subdir{Start} =~ /\$val\b/); | ||
| 1098 | if ($$tagInfo{SubIFD}) { | ||
| 1099 | warn "Warning: Wrong SubDirectory Start for SubIFD tag - $short $name\n" unless $isSub; | ||
| 1100 | } else { | ||
| 1101 | warn "Warning: SubIFD flag not set for $short $name\n" if $isSub and not $processBinaryData; | ||
| 1102 | } | ||
| 1103 | if ($$tagInfo{Notes}) { | ||
| 1104 | my $note = $$tagInfo{Notes}; | ||
| 1105 | # remove leading/trailing blank lines | ||
| 1106 | $note =~ s/^\s+//; $note =~ s/\s+$//; | ||
| 1107 | # remove leading/trailing spaces on each line | ||
| 1108 | $note =~ s/(^[ \t]+|[ \t]+$)//mg; | ||
| 1109 | push @values, "($note)"; | ||
| 1110 | } | ||
| 1111 | if ($isXMP and (lc $tagID ne lc $name or $$tagInfo{NotFlat})) { | ||
| 1112 | my $note; | ||
| 1113 | if ($$tagInfo{NotFlat}) { | ||
| 1114 | $note = 'NOT a flattened tag!'; | ||
| 1115 | } else { | ||
| 1116 | # add note about different XMP Tag ID | ||
| 1117 | $note = $$tagInfo{RootTagInfo} ? $tagID : "tag ID is '${tagID}'"; | ||
| 1118 | } | ||
| 1119 | if ($$tagInfo{Notes}) { | ||
| 1120 | $values[-1] =~ s/^\(/($note; /; | ||
| 1121 | } else { | ||
| 1122 | push @values, "($note)"; | ||
| 1123 | } | ||
| 1124 | } | ||
| 1125 | my $writeGroup; | ||
| 1126 | if ($short eq 'Extra') { | ||
| 1127 | $writeGroup = $$tagInfo{WriteOnly} ? '-' : $g[1]; | ||
| 1128 | } else { | ||
| 1129 | $writeGroup = $$tagInfo{WriteGroup}; | ||
| 1130 | } | ||
| 1131 | unless ($writeGroup) { | ||
| 1132 | $writeGroup = $$table{WRITE_GROUP} if $writable; | ||
| 1133 | $writeGroup = '-' unless $writeGroup; | ||
| 1134 | } | ||
| 1135 | if (defined $format) { | ||
| 1136 | # validate Format | ||
| 1137 | unless ($formatOK{$format} or $short eq 'PICT' or | ||
| 1138 | ($format =~ /^(var_)?(.*)\[/ and $formatOK{$2})) | ||
| 1139 | { | ||
| 1140 | warn "Warning: Unknown Format ($format) for $short $name\n"; | ||
| 1141 | } | ||
| 1142 | } else { | ||
| 1143 | $format = $defFormat; | ||
| 1144 | } | ||
| 1145 | if ($subdir) { | ||
| 1146 | my $subTable = $$subdir{TagTable} || $tableName; | ||
| 1147 | push @values, $shortName{$subTable} | ||
| 1148 | } elsif ($struct) { | ||
| 1149 | push @values, $struct; | ||
| 1150 | $structs{$struct} = 1; | ||
| 1151 | } | ||
| 1152 | my $type; | ||
| 1153 | foreach $type ('Require','Desire') { | ||
| 1154 | my $require = $$tagInfo{$type}; | ||
| 1155 | if (ref $require) { | ||
| 1156 | foreach (sort { $a <=> $b } keys %$require) { | ||
| 1157 | push @require, $$require{$_}; | ||
| 1158 | } | ||
| 1159 | } elsif ($require) { | ||
| 1160 | push @require, $require; | ||
| 1161 | } | ||
| 1162 | } | ||
| 1163 | my $printConv = $$tagInfo{PrintConv}; | ||
| 1164 | if ($$tagInfo{Mask}) { | ||
| 1165 | my $val = $$tagInfo{Mask}; | ||
| 1166 | my $bsh = $$tagInfo{BitShift}; | ||
| 1167 | if ($bsh) { | ||
| 1168 | push @values, sprintf('[val >> %d & 0x%x]',$bsh,$val>>$bsh); | ||
| 1169 | } else { | ||
| 1170 | push @values, sprintf('[val & 0x%x]',$val); | ||
| 1171 | } | ||
| 1172 | # verify that all values are within the mask | ||
| 1173 | if (ref $printConv eq 'HASH') { | ||
| 1174 | $val >>= $$tagInfo{BitShift}; | ||
| 1175 | foreach (keys %$printConv) { | ||
| 1176 | next if $_ !~ /^\d+$/ or ($_ & $val) == $_; | ||
| 1177 | my $hex = sprintf '0x%.2x', $_; | ||
| 1178 | warn "$short $name PrintConv value $hex is not in Mask!\n"; | ||
| 1179 | } | ||
| 1180 | } | ||
| 1181 | } | ||
| 1182 | if (ref($printConv) =~ /^(HASH|ARRAY)$/) { | ||
| 1183 | my (@printConvList, @indexList, $index, $valueConvHash); | ||
| 1184 | if (ref $printConv eq 'ARRAY') { | ||
| 1185 | for ($index=0; $index<@$printConv; ++$index) { | ||
| 1186 | if (ref $$printConv[$index] eq 'HASH') { | ||
| 1187 | next unless %{$$printConv[$index]}; | ||
| 1188 | push @printConvList, $$printConv[$index]; | ||
| 1189 | push @indexList, $index; | ||
| 1190 | } elsif ($$printConv[$index] and $$printConv[$index] eq 'REPEAT' and $index) { | ||
| 1191 | push @printConvList, $$printConv[$index-1]; | ||
| 1192 | push @indexList, 'N'; | ||
| 1193 | } else { | ||
| 1194 | next; | ||
| 1195 | } | ||
| 1196 | # collapse values with identical PrintConv's | ||
| 1197 | if (@printConvList >= 2 and $printConvList[-1] eq $printConvList[-2]) { | ||
| 1198 | if (ref $indexList[-2]) { | ||
| 1199 | push @{$indexList[-2]}, $indexList[-1]; | ||
| 1200 | } else { | ||
| 1201 | $indexList[-2] = [ $indexList[-2], $indexList[-1] ]; | ||
| 1202 | } | ||
| 1203 | pop @printConvList; | ||
| 1204 | pop @indexList; | ||
| 1205 | } | ||
| 1206 | } | ||
| 1207 | $printConv = shift @printConvList; | ||
| 1208 | $index = shift @indexList; | ||
| 1209 | } else { | ||
| 1210 | $valueConvHash = $$tagInfo{ValueConv} if ref $$tagInfo{ValueConv} eq 'HASH'; | ||
| 1211 | } | ||
| 1212 | while (defined $printConv) { | ||
| 1213 | if (defined $index) { | ||
| 1214 | # (print indices of original values if reorganized) | ||
| 1215 | my $s = ''; | ||
| 1216 | my $idx = $$tagInfo{Relist} ? $tagInfo->{Relist}->[$index] : $index; | ||
| 1217 | if (ref $idx) { | ||
| 1218 | $s = 's' if @$idx > 1; | ||
| 1219 | # collapse consecutive number ranges | ||
| 1220 | my ($i, @i, $rngStart); | ||
| 1221 | for ($i=0; $i<@$idx; ++$i) { | ||
| 1222 | if ($i < @$idx - 1 and ($$idx[$i+1] eq 'N' or $$idx[$i+1] == $$idx[$i] + 1)) { | ||
| 1223 | $rngStart = $$idx[$i] unless defined $rngStart; | ||
| 1224 | next; | ||
| 1225 | } | ||
| 1226 | push @i, (defined($rngStart) ? "$rngStart-" : '') . $$idx[$i]; | ||
| 1227 | } | ||
| 1228 | ($idx = join ', ', @i) =~ s/(.*),/$1 and/; | ||
| 1229 | } elsif (not $$tagInfo{Relist}) { | ||
| 1230 | while (@printConvList and $printConv eq $printConvList[0]) { | ||
| 1231 | shift @printConvList; | ||
| 1232 | $index = shift @indexList; | ||
| 1233 | } | ||
| 1234 | if ($idx != $index) { | ||
| 1235 | $idx = "$idx-$index"; | ||
| 1236 | $s = 's'; | ||
| 1237 | } | ||
| 1238 | } | ||
| 1239 | push @values, "[Value$s $idx]"; | ||
| 1240 | } | ||
| 1241 | if ($$tagInfo{SeparateTable}) { | ||
| 1242 | $subdir = 1; | ||
| 1243 | my $s = $$tagInfo{SeparateTable}; | ||
| 1244 | $s = $name if $s eq '1'; | ||
| 1245 | # add module name if not specified | ||
| 1246 | $s =~ / / or ($short =~ /^(\w+)/ and $s = "$1 $s"); | ||
| 1247 | push @values, $s; | ||
| 1248 | $sepTable{$s} = $printConv; | ||
| 1249 | # add PrintHex flag to PrintConv so we can check it later | ||
| 1250 | $$printConv{PrintHex} = 1 if $$tagInfo{PrintHex}; | ||
| 1251 | $$printConv{PrintInt} = 1 if $$tagInfo{PrintInt}; | ||
| 1252 | $$printConv{PrintString} = 1 if $$tagInfo{PrintString}; | ||
| 1253 | } else { | ||
| 1254 | $caseInsensitive = 0; | ||
| 1255 | my @pk; | ||
| 1256 | if ($$tagInfo{PrintSort}) { | ||
| 1257 | @pk = sort { NumbersFirst($$printConv{$a},$$printConv{$b}) } keys %$printConv; | ||
| 1258 | } else { | ||
| 1259 | @pk = sort { NumbersFirst($a,$b) } keys %$printConv; | ||
| 1260 | } | ||
| 1261 | my $n = scalar @values; | ||
| 1262 | my ($bits, $i, $v); | ||
| 1263 | foreach (@pk) { | ||
| 1264 | next if $_ eq '' and $$printConv{$_} eq ''; | ||
| 1265 | $_ eq 'BITMASK' and $bits = $$printConv{$_}, next; | ||
| 1266 | $_ eq 'OTHER' and next; | ||
| 1267 | my $index = $_; | ||
| 1268 | $index =~ s/\.\d+$// if $$tagInfo{PrintInt}; | ||
| 1269 | if (($$tagInfo{PrintHex} or $$printConv{BITMASK}) and $index =~ /^-?\d+$/) { | ||
| 1270 | my $dig = $$tagInfo{PrintHex} || 1; | ||
| 1271 | if ($index >= 0) { | ||
| 1272 | $index = sprintf('0x%.*x', $dig, $index); | ||
| 1273 | } elsif ($format and $format =~ /int(16|32)/) { | ||
| 1274 | # mask off unused bits of signed integer hex value | ||
| 1275 | my $mask = { 16 => 0xffff, 32 => 0xffffffff }->{$1}; | ||
| 1276 | $index = sprintf('0x%.*x', $dig, $index & $mask); | ||
| 1277 | } | ||
| 1278 | } elsif ($$tagInfo{PrintString} or not /^[+-]?(?=\d|\.\d)\d*(\.\d*)?$/) { | ||
| 1279 | # translate unprintable values | ||
| 1280 | if ($index =~ s/([\x00-\x1f\x7f-\xff])/sprintf("\\x%.2x",ord $1)/eg) { | ||
| 1281 | $index = qq{"$index"}; | ||
| 1282 | } else { | ||
| 1283 | $index = qq{'${index}'}; | ||
| 1284 | } | ||
| 1285 | } | ||
| 1286 | push @values, "$index = " . $$printConv{$_}; | ||
| 1287 | if ($valueConvHash) { | ||
| 1288 | foreach $v (keys %$valueConvHash) { | ||
| 1289 | next unless $$valueConvHash{$v} eq $_; | ||
| 1290 | $values[-1] = "$v => " . $values[-1]; | ||
| 1291 | last; | ||
| 1292 | } | ||
| 1293 | } | ||
| 1294 | # validate all PrintConv values | ||
| 1295 | if ($$printConv{$_} =~ /[\0-\x1f\x7f-\xff]/) { | ||
| 1296 | warn "Warning: Special characters in $short $name PrintConv ($$printConv{$_})\n"; | ||
| 1297 | } | ||
| 1298 | } | ||
| 1299 | if ($bits) { | ||
| 1300 | my @pk = sort { NumbersFirst($a,$b) } keys %$bits; | ||
| 1301 | foreach (@pk) { | ||
| 1302 | push @values, "Bit $_ = " . $$bits{$_}; | ||
| 1303 | } | ||
| 1304 | } | ||
| 1305 | # organize values into columns if specified | ||
| 1306 | my $cols = $$tagInfo{PrintConvColumns}; | ||
| 1307 | if (not $cols and scalar(@values) - $n >= 6) { | ||
| 1308 | # do columns if more than 6 short entries | ||
| 1309 | my $maxLen = 0; | ||
| 1310 | for ($i=$n; $i<@values; ++$i) { | ||
| 1311 | next unless $maxLen < length $values[$i]; | ||
| 1312 | $maxLen = length $values[$i]; | ||
| 1313 | } | ||
| 1314 | my $num = scalar(@values) - $n; | ||
| 1315 | $cols = int(50 / ($maxLen + 2)); # (50 chars max width) | ||
| 1316 | # have 3 rows minimum | ||
| 1317 | --$cols while $cols and $num / $cols < 3; | ||
| 1318 | } | ||
| 1319 | if ($cols) { | ||
| 1320 | my @new = splice @values, $n; | ||
| 1321 | my $v = '[!HTML]<table class=cols><tr>'; | ||
| 1322 | my $rows = int((scalar(@new) + $cols - 1) / $cols); | ||
| 1323 | for ($n=0; ;) { | ||
| 1324 | $v .= "\n <td>"; | ||
| 1325 | for ($i=0; $i<$rows and $n+$i<@new; ++$i) { | ||
| 1326 | $v .= "\n <br>" if $i; | ||
| 1327 | $v .= EscapeHTML($new[$n+$i]); | ||
| 1328 | } | ||
| 1329 | $v .= '</td>'; | ||
| 1330 | last if ($n += $rows) >= @new; | ||
| 1331 | $v .= '<td> </td>'; # add spaces between columns | ||
| 1332 | } | ||
| 1333 | push @values, $v . "</tr></table>\n"; | ||
| 1334 | } | ||
| 1335 | } | ||
| 1336 | last unless @printConvList; | ||
| 1337 | $printConv = shift @printConvList; | ||
| 1338 | $index = shift @indexList; | ||
| 1339 | } | ||
| 1340 | # look inside scalar PrintConv for a bit/byte conversion | ||
| 1341 | # (see Photoshop:PrintFlags for use of "$byte" decoding) | ||
| 1342 | } elsif ($printConv and $printConv =~ /DecodeBits\(\$(val|byte),\s*(\\\%[\w:]+|\{.*\})\s*\)/s) { | ||
| 1343 | my $type = $1 eq 'byte' ? 'Byte' : 'Bit'; | ||
| 1344 | $$self{Model} = ''; # needed for Nikon ShootingMode | ||
| 1345 | my $bits = eval $2; | ||
| 1346 | delete $$self{Model}; | ||
| 1347 | if ($@) { | ||
| 1348 | warn $@; | ||
| 1349 | } else { | ||
| 1350 | my @pk = sort { NumbersFirst($a,$b) } keys %$bits; | ||
| 1351 | foreach (@pk) { | ||
| 1352 | push @values, "$type $_ = " . $$bits{$_}; | ||
| 1353 | } | ||
| 1354 | } | ||
| 1355 | } | ||
| 1356 | if ($subdir and not $$tagInfo{SeparateTable}) { | ||
| 1357 | if ($writable) { | ||
| 1358 | # subdirectories are only writable if specified explicitly | ||
| 1359 | my $tw = $$tagInfo{Writable}; | ||
| 1360 | $writable = 'yes' if $tw and $writable eq '1' or $writable eq '2'; | ||
| 1361 | $writable = '-' . ($tw ? $writable : ''); | ||
| 1362 | $writable .= '!' if $tw and ($$tagInfo{Protected} || 0) & 0x01; | ||
| 1363 | $writable .= '+' if $$tagInfo{List} or $$tagInfo{IsList}; | ||
| 1364 | if (defined $$tagInfo{Permanent}) { | ||
| 1365 | $writable .= '^' unless $$tagInfo{Permanent}; | ||
| 1366 | } elsif (defined $$table{PERMANENT}) { | ||
| 1367 | $writable .= '^' unless $$table{PERMANENT}; | ||
| 1368 | } | ||
| 1369 | } else { | ||
| 1370 | $writable = '-'; | ||
| 1371 | } | ||
| 1372 | } else { | ||
| 1373 | # not writable if we can't do the inverse conversions | ||
| 1374 | my $noPrintConvInv; | ||
| 1375 | if ($writable) { | ||
| 1376 | foreach ('PrintConv','ValueConv') { | ||
| 1377 | next unless $$tagInfo{$_}; | ||
| 1378 | next if defined $$tagInfo{$_ . 'Inv'}; | ||
| 1379 | # (undefined inverse conversion overrides hash lookup) | ||
| 1380 | unless (exists $$tagInfo{$_ . 'Inv'}) { | ||
| 1381 | next if ref($$tagInfo{$_}) =~ /^(HASH|ARRAY)$/; | ||
| 1382 | next if $$tagInfo{WriteAlso}; | ||
| 1383 | } | ||
| 1384 | if ($_ eq 'ValueConv') { | ||
| 1385 | undef $writable; | ||
| 1386 | } else { | ||
| 1387 | $noPrintConvInv = 1; | ||
| 1388 | } | ||
| 1389 | } | ||
| 1390 | } | ||
| 1391 | if (not $writable) { | ||
| 1392 | $writable = 'no'; | ||
| 1393 | } else { | ||
| 1394 | $writable = $format ? $format : 'yes' if $writable eq '1' or $writable eq '2'; | ||
| 1395 | my $count = $$tagInfo{Count} || 1; | ||
| 1396 | # adjust count to Writable size if different than Format | ||
| 1397 | if ($writable and $format and $writable ne $format and | ||
| 1398 | $writable ne 'string' and $format ne 'string' and | ||
| 1399 | $Image::ExifTool::Exif::formatNumber{$writable} and | ||
| 1400 | $Image::ExifTool::Exif::formatNumber{$format}) | ||
| 1401 | { | ||
| 1402 | my $n1 = $Image::ExifTool::Exif::formatNumber{$format}; | ||
| 1403 | my $n2 = $Image::ExifTool::Exif::formatNumber{$writable}; | ||
| 1404 | $count *= $Image::ExifTool::Exif::formatSize[$n1] / | ||
| 1405 | $Image::ExifTool::Exif::formatSize[$n2]; | ||
| 1406 | } | ||
| 1407 | if ($count != 1) { | ||
| 1408 | $count = 'n' if $count < 0; | ||
| 1409 | $writable .= "[$count]"; | ||
| 1410 | } | ||
| 1411 | $writable .= '~' if $noPrintConvInv; | ||
| 1412 | # add a '*' if this tag is protected or a '!' for unsafe tags | ||
| 1413 | if ($$tagInfo{Protected}) { | ||
| 1414 | $writable .= '*' if $$tagInfo{Protected} & 0x02; | ||
| 1415 | $writable .= '!' if $$tagInfo{Protected} & 0x01; | ||
| 1416 | } | ||
| 1417 | $writable .= '/' if $$tagInfo{Avoid}; | ||
| 1418 | } | ||
| 1419 | $writable = "=struct" if $struct; | ||
| 1420 | $writable .= '_' if defined $$tagInfo{Flat}; | ||
| 1421 | $writable .= '+' if $$tagInfo{List} or $$tagInfo{IsList}; | ||
| 1422 | $writable .= ':' if $$tagInfo{Mandatory}; | ||
| 1423 | if (defined $$tagInfo{Permanent}) { | ||
| 1424 | $writable .= '^' unless $$tagInfo{Permanent}; | ||
| 1425 | } elsif (defined $$table{PERMANENT}) { | ||
| 1426 | $writable .= '^' unless $$table{PERMANENT}; | ||
| 1427 | } | ||
| 1428 | # separate tables link like subdirectories (flagged with leading '-') | ||
| 1429 | $writable = "-$writable" if $subdir; | ||
| 1430 | } | ||
| 1431 | # don't duplicate a tag name unless an entry is different | ||
| 1432 | my $lcName = lc($name); | ||
| 1433 | # check for conflicts with shortcut names | ||
| 1434 | if ($isShortcut{$lcName} and $short ne 'Shortcuts' and | ||
| 1435 | ($$tagInfo{Writable} or not $$tagInfo{SubDirectory})) | ||
| 1436 | { | ||
| 1437 | warn "WARNING: $short $name is a shortcut tag!\n"; | ||
| 1438 | } | ||
| 1439 | $name .= '?' if $$tagInfo{Unknown}; | ||
| 1440 | unless (@tagNames and $tagNames[-1] eq $name and | ||
| 1441 | $writeGroup[-1] eq $writeGroup and $writable[-1] eq $writable) | ||
| 1442 | { | ||
| 1443 | push @tagNames, $name; | ||
| 1444 | push @writeGroup, $writeGroup; | ||
| 1445 | push @writable, $writable; | ||
| 1446 | } | ||
| 1447 | # | ||
| 1448 | # add this tag to the tag lookup unless NO_LOOKUP is set or shortcut or plug-in tag | ||
| 1449 | # | ||
| 1450 | next if $shortcut or $isPlugin; | ||
| 1451 | # count tags | ||
| 1452 | if ($$tagInfo{SubDirectory}) { | ||
| 1453 | next if $$vars{NO_LOOKUP}; | ||
| 1454 | $subdirs{$lcName} or $subdirs{$lcName} = 0; | ||
| 1455 | ++$subdirs{$lcName}; | ||
| 1456 | } else { | ||
| 1457 | ++$count{'total tags'}; | ||
| 1458 | unless ($tagExists{$lcName} and | ||
| 1459 | (not $subdirs{$lcName} or $subdirs{$lcName} == $tagExists{$lcName})) | ||
| 1460 | { | ||
| 1461 | ++$count{'unique tag names'} unless $noLookup{$lcName}; | ||
| 1462 | } | ||
| 1463 | # don't add to tag lookup if specified | ||
| 1464 | $$vars{NO_LOOKUP} and $noLookup{$lcName} = 1, next; | ||
| 1465 | } | ||
| 1466 | $tagExists{$lcName} or $tagExists{$lcName} = 0; | ||
| 1467 | ++$tagExists{$lcName}; | ||
| 1468 | # only add writable tags to lookup table (for speed) | ||
| 1469 | my $wflag = $$tagInfo{Writable}; | ||
| 1470 | next unless $writeProc and ($wflag or ($$table{WRITABLE} and | ||
| 1471 | not defined $wflag and not $$tagInfo{SubDirectory})); | ||
| 1472 | $tagLookup{$lcName} or $tagLookup{$lcName} = { }; | ||
| 1473 | # add to lookup for flattened tags if necessary | ||
| 1474 | if ($$tagInfo{RootTagInfo}) { | ||
| 1475 | $flattened{$lcName} or $flattened{$lcName} = { }; | ||
| 1476 | $flattened{$lcName}{$tableNum} = $$tagInfo{RootTagInfo}{TagID}; | ||
| 1477 | } | ||
| 1478 | # remember number for this table | ||
| 1479 | my $tagIDs = $tagLookup{$lcName}->{$tableNum}; | ||
| 1480 | # must allow for duplicate tags with the same name in a single table! | ||
| 1481 | if ($tagIDs) { | ||
| 1482 | if (ref $tagIDs eq 'HASH') { | ||
| 1483 | $$tagIDs{$tagID} = 1; | ||
| 1484 | next; | ||
| 1485 | } elsif ($tagID eq $tagIDs) { | ||
| 1486 | next; | ||
| 1487 | } else { | ||
| 1488 | $tagIDs = { $tagIDs => 1, $tagID => 1 }; | ||
| 1489 | } | ||
| 1490 | } else { | ||
| 1491 | $tagIDs = $tagID; | ||
| 1492 | } | ||
| 1493 | $tableWritable{$tableName} = 1; | ||
| 1494 | $tagLookup{$lcName}->{$tableNum} = $tagIDs; | ||
| 1495 | # keep track of extra modules needed for Composite tags | ||
| 1496 | $compositeModules{$lcName} = $$tagInfo{Module} if $$tagInfo{Module}; | ||
| 1497 | } | ||
| 1498 | # | ||
| 1499 | # save TagName information | ||
| 1500 | # | ||
| 1501 | my $tagIDstr; | ||
| 1502 | if ($tagID =~ /^(-)?\d+(\.\d+)?$/) { | ||
| 1503 | if ($1) { | ||
| 1504 | $tagIDstr = $tagID; | ||
| 1505 | } elsif (defined $prtID) { | ||
| 1506 | if ($prtID eq 'hex') { | ||
| 1507 | $tagIDstr = sprintf('0x%.4x',$tagID); | ||
| 1508 | } elsif ($prtID eq 'str') { | ||
| 1509 | $tagIDstr = "'${tagID}'"; | ||
| 1510 | } else { | ||
| 1511 | $tagIDstr = $tagID; | ||
| 1512 | } | ||
| 1513 | } elsif (not $2 and not $binaryTable and not $isIPTC and | ||
| 1514 | not ($short =~ /^CanonCustom/ and $tagID < 256)) | ||
| 1515 | { | ||
| 1516 | $tagIDstr = sprintf('0x%.4x',$tagID); | ||
| 1517 | } elsif ($tagID < 0x10000) { | ||
| 1518 | $tagIDstr = $tagID; | ||
| 1519 | } else { | ||
| 1520 | $tagIDstr = sprintf('0x%.8x',$tagID); | ||
| 1521 | } | ||
| 1522 | } elsif ($short eq 'DICOM') { | ||
| 1523 | ($tagIDstr = $tagID) =~ s/_/,/; | ||
| 1524 | } elsif ($tagID =~ /^0x([0-9a-f]+)\.(\d+)$/) { # DR4 tags like '0x20500.0' | ||
| 1525 | $tagIDstr = $tagID; | ||
| 1526 | } else { | ||
| 1527 | # convert non-printable characters to hex escape sequences | ||
| 1528 | if ($tagID =~ s/([\x00-\x1f\x7f-\xff])/'\x'.unpack('H*',$1)/eg) { | ||
| 1529 | $tagID =~ s/\\x00/\\0/g; | ||
| 1530 | next if $tagID eq 'jP\x1a\x1a'; # ignore abnormal JP2 signature tag | ||
| 1531 | $tagIDstr = qq{"$tagID"}; | ||
| 1532 | } else { | ||
| 1533 | $tagIDstr = "'${tagID}'"; | ||
| 1534 | } | ||
| 1535 | } | ||
| 1536 | my $len = length $tagIDstr; | ||
| 1537 | $longID{$tableName} = $len if $longID{$tableName} < $len; | ||
| 1538 | foreach (@tagNames) { | ||
| 1539 | $len = length $_; | ||
| 1540 | $longName{$tableName} = $len if $longName{$tableName} < $len; | ||
| 1541 | } | ||
| 1542 | push @$info, [ $tagIDstr, \@tagNames, \@writable, \@values, \@require, \@writeGroup ]; | ||
| 1543 | } | ||
| 1544 | # do consistency check of writable BinaryData tables | ||
| 1545 | if ($processBinaryData and $$table{WRITABLE}) { | ||
| 1546 | my %lookup = ( | ||
| 1547 | IS_OFFSET => \%isOffset, | ||
| 1548 | IS_SUBDIR => \%hasSubdir, | ||
| 1549 | DATAMEMBER => \%datamember, | ||
| 1550 | ); | ||
| 1551 | my ($var, $tagID); | ||
| 1552 | foreach $var (sort keys %lookup) { | ||
| 1553 | my $hash = $lookup{$var}; | ||
| 1554 | if ($$table{$var}) { | ||
| 1555 | foreach $tagID (@{$$table{$var}}) { | ||
| 1556 | $$hash{$tagID} and delete($$hash{$tagID}), next; | ||
| 1557 | warn sprintf("Warning: Extra %s for %s tag %d (0x%.4x)\n", | ||
| 1558 | $var, $short, $tagID, $tagID); | ||
| 1559 | } | ||
| 1560 | } | ||
| 1561 | foreach $tagID (sort keys %$hash) { | ||
| 1562 | warn sprintf("Warning: Missing %s for %s %s, tag %s (0x%.4x)\n", | ||
| 1563 | $var, $short, $$hash{$tagID}, $tagID, $tagID); | ||
| 1564 | } | ||
| 1565 | } | ||
| 1566 | } | ||
| 1567 | } | ||
| 1568 | # save information about structures | ||
| 1569 | my $strName; | ||
| 1570 | foreach $strName (keys %structs) { | ||
| 1571 | my $struct = $structLookup{$strName}; | ||
| 1572 | my $fullName = ($strName =~ / / ? '' : 'XMP ') . "$strName Struct"; | ||
| 1573 | my $info = $tagNameInfo{$fullName} = [ ]; | ||
| 1574 | my $tag; | ||
| 1575 | my $order = $$struct{SORT_ORDER} || [ sort keys %$struct ]; | ||
| 1576 | foreach $tag (@$order) { | ||
| 1577 | my $tagInfo = $$struct{$tag}; | ||
| 1578 | next unless ref $tagInfo eq 'HASH' and $tag ne 'NAMESPACE' and $tag ne 'GROUPS'; | ||
| 1579 | warn "WARNING: $strName Struct containes $tag\n" if $Image::ExifTool::specialTags{$tag}; | ||
| 1580 | my $writable = $$tagInfo{Writable}; | ||
| 1581 | my @vals; | ||
| 1582 | unless ($writable) { | ||
| 1583 | $writable = $$tagInfo{Struct}; | ||
| 1584 | ref $writable and $writable = $$writable{STRUCT_NAME}; | ||
| 1585 | if ($writable) { | ||
| 1586 | push @vals, $writable; | ||
| 1587 | $structs{$writable} = 1; | ||
| 1588 | $writable = "=$writable"; | ||
| 1589 | } elsif (defined $$tagInfo{Writable}) { | ||
| 1590 | $writable = 'no'; | ||
| 1591 | } else { | ||
| 1592 | $writable = 'string'; | ||
| 1593 | } | ||
| 1594 | } | ||
| 1595 | $writable .= '+' if $$tagInfo{List} or $$tagInfo{IsList}; | ||
| 1596 | push @vals, "($$tagInfo{Notes})" if $$tagInfo{Notes}; | ||
| 1597 | # handle PrintConv lookups in Structure elements | ||
| 1598 | my $printConv = $$tagInfo{PrintConv}; | ||
| 1599 | if (ref $printConv eq 'HASH') { | ||
| 1600 | foreach (sort { NumbersFirst($a,$b) } keys %$printConv) { | ||
| 1601 | next if /^(OTHER|BITMASK)$/; | ||
| 1602 | push @vals, "$_ = $$printConv{$_}"; | ||
| 1603 | } | ||
| 1604 | } | ||
| 1605 | push @$info, [ | ||
| 1606 | $tag, | ||
| 1607 | [ $$tagInfo{Name} || ucfirst($tag) ], | ||
| 1608 | [ $writable ], | ||
| 1609 | \@vals, | ||
| 1610 | [], [] | ||
| 1611 | ]; | ||
| 1612 | } | ||
| 1613 | } | ||
| 1614 | return $self; | ||
| 1615 | } | ||
| 1616 | |||
| 1617 | #------------------------------------------------------------------------------ | ||
| 1618 | # Rewrite this file to build the lookup tables | ||
| 1619 | # Inputs: 0) BuildTagLookup object reference | ||
| 1620 | # 1) output tag lookup module name (eg. 'lib/Image/ExifTool/TagLookup.pm') | ||
| 1621 | # Returns: true on success | ||
| 1622 | sub WriteTagLookup($$) | ||
| 1623 | { | ||
| 1624 | local ($_, *INFILE, *OUTFILE); | ||
| 1625 | my ($self, $file) = @_; | ||
| 1626 | my $tagLookup = $self->{TAG_LOOKUP}; | ||
| 1627 | my $tagExists = $self->{TAG_EXISTS}; | ||
| 1628 | my $flattened = $self->{FLATTENED}; | ||
| 1629 | my $tableWritable = $self->{TABLE_WRITABLE}; | ||
| 1630 | # | ||
| 1631 | # open/create necessary files and transfer file headers | ||
| 1632 | # | ||
| 1633 | my $tmpFile = "${file}_tmp"; | ||
| 1634 | open(INFILE, $file) or warn("Can't open $file\n"), return 0; | ||
| 1635 | unless (open(OUTFILE, ">$tmpFile")) { | ||
| 1636 | warn "Can't create temporary file $tmpFile\n"; | ||
| 1637 | close(INFILE); | ||
| 1638 | return 0; | ||
| 1639 | } | ||
| 1640 | my $success; | ||
| 1641 | while (<INFILE>) { | ||
| 1642 | print OUTFILE $_ or last; | ||
| 1643 | if (/^#\+{4} Begin/) { | ||
| 1644 | $success = 1; | ||
| 1645 | last; | ||
| 1646 | } | ||
| 1647 | } | ||
| 1648 | print OUTFILE "\n# list of tables containing writable tags\n"; | ||
| 1649 | print OUTFILE "my \@tableList = (\n"; | ||
| 1650 | |||
| 1651 | # | ||
| 1652 | # write table list | ||
| 1653 | # | ||
| 1654 | my @tableNames = sort keys %allTables; | ||
| 1655 | my $tableName; | ||
| 1656 | my %wrNum; # translate from allTables index to writable tables index | ||
| 1657 | my $count = 0; | ||
| 1658 | my $num = 0; | ||
| 1659 | foreach $tableName (@tableNames) { | ||
| 1660 | if ($$tableWritable{$tableName}) { | ||
| 1661 | print OUTFILE "\t'${tableName}',\n"; | ||
| 1662 | $wrNum{$count} = $num++; | ||
| 1663 | } | ||
| 1664 | $count++; | ||
| 1665 | } | ||
| 1666 | # | ||
| 1667 | # write the tag lookup table | ||
| 1668 | # | ||
| 1669 | my $tag; | ||
| 1670 | # verify that certain critical tag names aren't duplicated | ||
| 1671 | foreach $tag (qw{filename directory}) { | ||
| 1672 | next unless $$tagLookup{$tag}; | ||
| 1673 | my $n = scalar keys %{$$tagLookup{$tag}}; | ||
| 1674 | warn "Warning: $n writable '${tag}' tags!\n" if $n > 1; | ||
| 1675 | } | ||
| 1676 | print OUTFILE ");\n\n# lookup for all writable tags\nmy \%tagLookup = (\n"; | ||
| 1677 | foreach $tag (sort keys %$tagLookup) { | ||
| 1678 | print OUTFILE "\t'${tag}' => { "; | ||
| 1679 | my @tableNums = sort { $a <=> $b } keys %{$$tagLookup{$tag}}; | ||
| 1680 | my (@entries, $tableNum); | ||
| 1681 | foreach $tableNum (@tableNums) { | ||
| 1682 | my $tagID = $$tagLookup{$tag}{$tableNum}; | ||
| 1683 | my $rootID = $$flattened{$tag}{$tableNum}; | ||
| 1684 | my $entry; | ||
| 1685 | if (ref $tagID eq 'HASH' or $rootID) { | ||
| 1686 | $tagID = { $tagID => 1 } unless ref $tagID eq 'HASH'; | ||
| 1687 | my @tagIDs = sort keys %$tagID; | ||
| 1688 | foreach (@tagIDs) { | ||
| 1689 | if (/^\d+$/) { | ||
| 1690 | $_ = sprintf('0x%x',$_); | ||
| 1691 | } else { | ||
| 1692 | my $quot = "'"; | ||
| 1693 | # escape non-printable characters in tag ID if necessary | ||
| 1694 | $quot = '"' if s/([\x00-\x1f,\x7f-\xff])/sprintf('\\x%.2x',ord($1))/ge; | ||
| 1695 | $_ = $quot . $_ . $quot; | ||
| 1696 | } | ||
| 1697 | } | ||
| 1698 | # reference to root structure ID must come first in lookup | ||
| 1699 | # (so we can generate the flattened tags just before we need them) | ||
| 1700 | unshift @tagIDs, "\\'${rootID}'" if $rootID; | ||
| 1701 | $entry = '[' . join(',', @tagIDs) . ']'; | ||
| 1702 | } elsif ($tagID =~ /^\d+$/) { | ||
| 1703 | $entry = sprintf('0x%x',$tagID); | ||
| 1704 | } else { | ||
| 1705 | my $quot = "'"; | ||
| 1706 | # escape non-printable characters in tag ID if necessary | ||
| 1707 | $quot = '"' if $tagID =~ s/([\x00-\x1f,\x7f-\xff])/sprintf('\\x%.2x',ord($1))/ge; | ||
| 1708 | $entry = "$quot${tagID}$quot"; | ||
| 1709 | } | ||
| 1710 | my $wrNum = $wrNum{$tableNum}; | ||
| 1711 | push @entries, "$wrNum => $entry"; | ||
| 1712 | } | ||
| 1713 | print OUTFILE join(', ', @entries); | ||
| 1714 | print OUTFILE " },\n"; | ||
| 1715 | } | ||
| 1716 | # | ||
| 1717 | # write tag exists lookup | ||
| 1718 | # | ||
| 1719 | print OUTFILE ");\n\n# lookup for non-writable tags to check if the name exists\n"; | ||
| 1720 | print OUTFILE "my \%tagExists = (\n"; | ||
| 1721 | foreach $tag (sort keys %$tagExists) { | ||
| 1722 | next if $$tagLookup{$tag}; | ||
| 1723 | print OUTFILE "\t'${tag}' => 1,\n"; | ||
| 1724 | } | ||
| 1725 | # | ||
| 1726 | # write module lookup for writable composite tags | ||
| 1727 | # | ||
| 1728 | my $compositeModules = $self->{COMPOSITE_MODULES}; | ||
| 1729 | print OUTFILE ");\n\n# module names for writable Composite tags\n"; | ||
| 1730 | print OUTFILE "my \%compositeModules = (\n"; | ||
| 1731 | foreach (sort keys %$compositeModules) { | ||
| 1732 | print OUTFILE "\t'${_}' => '$$compositeModules{$_}',\n"; | ||
| 1733 | } | ||
| 1734 | print OUTFILE ");\n\n"; | ||
| 1735 | # | ||
| 1736 | # finish writing TagLookup.pm and clean up | ||
| 1737 | # | ||
| 1738 | if ($success) { | ||
| 1739 | $success = 0; | ||
| 1740 | while (<INFILE>) { | ||
| 1741 | $success or /^#\+{4} End/ or next; | ||
| 1742 | print OUTFILE $_; | ||
| 1743 | $success = 1; | ||
| 1744 | } | ||
| 1745 | } | ||
| 1746 | close(INFILE); | ||
| 1747 | close(OUTFILE) or $success = 0; | ||
| 1748 | # | ||
| 1749 | # return success code | ||
| 1750 | # | ||
| 1751 | if ($success) { | ||
| 1752 | local (*ORG, *TMP); | ||
| 1753 | # only rename the file if something changed | ||
| 1754 | open ORG, $file or return 0; | ||
| 1755 | open TMP, $tmpFile or return 0; | ||
| 1756 | my ($buff, $buf2, $changed); | ||
| 1757 | for (;;) { | ||
| 1758 | my $n1 = read ORG, $buff, 65536; | ||
| 1759 | my $n2 = read TMP, $buf2, 65536; | ||
| 1760 | $n1 eq $n2 or $changed = 1, last; | ||
| 1761 | last unless $n1; | ||
| 1762 | $buff eq $buf2 or $changed = 1, last; | ||
| 1763 | } | ||
| 1764 | close ORG; | ||
| 1765 | close TMP; | ||
| 1766 | if ($changed) { | ||
| 1767 | rename($tmpFile, $file) or warn("Error renaming $tmpFile\n"), $success = 0; | ||
| 1768 | } else { | ||
| 1769 | unlink($tmpFile); | ||
| 1770 | } | ||
| 1771 | } else { | ||
| 1772 | unlink($tmpFile); | ||
| 1773 | warn "Error rewriting file\n"; | ||
| 1774 | } | ||
| 1775 | return $success; | ||
| 1776 | } | ||
| 1777 | |||
| 1778 | #------------------------------------------------------------------------------ | ||
| 1779 | # Sort numbers first numerically, then strings alphabetically | ||
| 1780 | # - case-insensitive sorting set by global variable $caseInsensitive | ||
| 1781 | # - two global variables are used to change the sort algorithm: | ||
| 1782 | # $numbersFirst: -1 = put numbers after other strings | ||
| 1783 | # 1 = put numbers before other strings | ||
| 1784 | # 2 = put numbers first, but negative numbers last | ||
| 1785 | sub NumbersFirst($$) | ||
| 1786 | { | ||
| 1787 | my ($a, $b) = @_; | ||
| 1788 | my $rtnVal; | ||
| 1789 | my ($bNum, $bDec); | ||
| 1790 | ($bNum, $bDec) = ($1, $3) if $b =~ /^(-?[0-9]+)(\.(\d*))?$/; | ||
| 1791 | if ($a =~ /^(-?[0-9]+)(\.(\d*))?$/) { | ||
| 1792 | if (defined $bNum) { | ||
| 1793 | $bNum += 1e9 if $numbersFirst == 2 and $bNum < 0; | ||
| 1794 | my $aInt = $1; | ||
| 1795 | $aInt += 1e9 if $numbersFirst == 2 and $aInt < 0; | ||
| 1796 | # compare integer part as a number | ||
| 1797 | $rtnVal = $aInt <=> $bNum; | ||
| 1798 | unless ($rtnVal) { | ||
| 1799 | my $aDec = $3 || 0; | ||
| 1800 | $bDec or $bDec = 0; | ||
| 1801 | # compare decimal part as an integer too | ||
| 1802 | # (so that "1.10" comes after "1.9") | ||
| 1803 | $rtnVal = $aDec <=> $bDec; | ||
| 1804 | } | ||
| 1805 | } else { | ||
| 1806 | $rtnVal = -$numbersFirst; | ||
| 1807 | } | ||
| 1808 | } elsif (defined $bNum) { | ||
| 1809 | $rtnVal = $numbersFirst; | ||
| 1810 | } else { | ||
| 1811 | my ($a2, $b2) = ($a, $b); | ||
| 1812 | # expand numbers to 3 digits (with restrictions to avoid messing up | ||
| 1813 | # ascii-hex tags -- Nikon LensID's are 23 characters long) | ||
| 1814 | $a2 =~ s/(\d+)/sprintf("%.3d",$1)/eg if $a2 =~ /^(APP|DMC-\w+ |dvtm_.*|(IDB|SHB)-)?[.0-9 ]*$/ and length($a2)<23; | ||
| 1815 | $b2 =~ s/(\d+)/sprintf("%.3d",$1)/eg if $b2 =~ /^(APP|DMC-\w+ |dvtm_.*|(IDB|SHB)-)?[.0-9 ]*$/ and length($b2)<23; | ||
| 1816 | $caseInsensitive and $rtnVal = (lc($a2) cmp lc($b2)); | ||
| 1817 | $rtnVal or $rtnVal = ($a2 cmp $b2); | ||
| 1818 | } | ||
| 1819 | return $rtnVal; | ||
| 1820 | } | ||
| 1821 | |||
| 1822 | #------------------------------------------------------------------------------ | ||
| 1823 | # Convert our pod-like documentation to pod | ||
| 1824 | # (funny, I know, but the pod headings must be hidden to prevent confusing | ||
| 1825 | # the pod parser) | ||
| 1826 | # Inputs: 0-N) documentation strings | ||
| 1827 | sub Doc2Pod($;@) | ||
| 1828 | { | ||
| 1829 | my $doc = shift; | ||
| 1830 | local $_; | ||
| 1831 | $doc .= shift while @_; | ||
| 1832 | $doc =~ s/\n~/\n=/g; | ||
| 1833 | $doc =~ s/L<[^>]+?\|(http[^>]+)>/L<$1>/g; # POD doesn't support text for http links | ||
| 1834 | $doc =~ s/L<([^>]+?)\|[^>]+\.html(#\w+)?>/$1/g; # remove relative HTML links | ||
| 1835 | return $doc; | ||
| 1836 | } | ||
| 1837 | |||
| 1838 | #------------------------------------------------------------------------------ | ||
| 1839 | # Convert our pod-like documentation to html | ||
| 1840 | # Inputs: 0) string | ||
| 1841 | sub Doc2Html($) | ||
| 1842 | { | ||
| 1843 | my $doc = EscapeHTML(shift); | ||
| 1844 | $doc =~ s/\n\n/<\/p>\n\n<p>/g; | ||
| 1845 | $doc =~ s/B<(.*?)>/<b>$1<\/b>/sg; | ||
| 1846 | $doc =~ s/C<(.*?)>/<code>$1<\/code>/sg; | ||
| 1847 | $doc =~ s/I<(.*?)>/<i>$1<\/i>/sg; | ||
| 1848 | # L<some text|https://exiftool.org/struct.html#Fields> --> <a href="../struct.html#Fields">some text</a> | ||
| 1849 | $doc =~ s{L<([^&]+?)\|\Q$homePage\E/(.*?)>}{<a href="../$2">$1<\/a>}sg; | ||
| 1850 | # L<https://exiftool.org/struct.html> --> <a href="https://exiftool.org/struct.html">https://exiftool.org/struct.html</a> | ||
| 1851 | $doc =~ s{L<\Q$homePage\E/(.*?)>}{<a href="../$1">$1<\/a>}sg; | ||
| 1852 | # L<XMP DICOM Tags|Image::ExifTool::TagNames/XMP DICOM Tags> --> <a href="XMP.html#DICOM">XMP DICOM Tags</a> | ||
| 1853 | # (specify "Image::ExifTool::TagNames" to link to another html file) | ||
| 1854 | $doc =~ s{L<([^&]+?)\|Image::ExifTool::TagNames/(\w+) ([^/&|]+) Tags>}{<a href="$2.html#$3">$1</a>}sg; | ||
| 1855 | # L<DICOM Tags|Image::ExifTool::TagNames/DICOM Tags> --> <a href="DICOM.html">DICOM Tags</a> | ||
| 1856 | $doc =~ s{L<([^&]+?)\|Image::ExifTool::TagNames/(\w+) Tags>}{<a href="$2.html">$1</a>}sg; | ||
| 1857 | # L<dc|/XMP dc Tags> --> <a href="#dc">dc</a> | ||
| 1858 | # (a relative POD link turns into a relative HTML link) | ||
| 1859 | $doc =~ s{L<([^&]+?)\|/\w+ ([^/&|]+) Tags>}{<a href="#$2">$1</a>}sg; | ||
| 1860 | # L<sample config file|../config.html> --> <a href="../config.html">sample config file</a> | ||
| 1861 | $doc =~ s/L<([^&]+?)\|(.+?)>/<a href="$2">$1<\/a>/sg; | ||
| 1862 | # L<http://some.web.site/> --> <a href="http://some.web.site">http://some.web.site</a> | ||
| 1863 | $doc =~ s/L<(http.*?)>/<a href="$1">$1<\/a>/sg; | ||
| 1864 | return $doc; | ||
| 1865 | } | ||
| 1866 | |||
| 1867 | #------------------------------------------------------------------------------ | ||
| 1868 | # Tweak order of tables | ||
| 1869 | # Inputs: 0) table list ref, 1) reference to tweak hash | ||
| 1870 | sub TweakOrder($$) | ||
| 1871 | { | ||
| 1872 | local $_; | ||
| 1873 | my ($sortedTables, $tweakOrder) = @_; | ||
| 1874 | my @tweak = sort keys %$tweakOrder; | ||
| 1875 | my (@sorted, %hasMain, %module, $entry); | ||
| 1876 | # apply manual tweaks | ||
| 1877 | while (@tweak) { | ||
| 1878 | my $table = shift @tweak; | ||
| 1879 | my $first = $$tweakOrder{$table}; | ||
| 1880 | if ($$tweakOrder{$first}) { | ||
| 1881 | push @tweak, $table; # must defer this till later | ||
| 1882 | next; | ||
| 1883 | } | ||
| 1884 | delete $$tweakOrder{$table}; # because the table won't move again | ||
| 1885 | my @moving = grep /^Image::ExifTool::$table\b/, @$sortedTables; | ||
| 1886 | my @notMoving = grep !/^Image::ExifTool::$table\b/, @$sortedTables; | ||
| 1887 | my @after; | ||
| 1888 | while (@notMoving) { | ||
| 1889 | last if $notMoving[-1] =~ /^Image::ExifTool::$first\b/; | ||
| 1890 | unshift @after, pop @notMoving; | ||
| 1891 | } | ||
| 1892 | @$sortedTables = (@notMoving, @moving, @after); | ||
| 1893 | } | ||
| 1894 | # flag modules which have a "Main" table, and organize tables by module name | ||
| 1895 | foreach (@$sortedTables) { | ||
| 1896 | if (not /^Image::ExifTool::(\w+)::(\w+)/) { | ||
| 1897 | push @sorted, $_; | ||
| 1898 | } else { | ||
| 1899 | $hasMain{$1} = 1 if $2 eq 'Main'; | ||
| 1900 | push @sorted, $module{$1} = [ ] unless $module{$1}; | ||
| 1901 | push @{$module{$1}}, $_; | ||
| 1902 | } | ||
| 1903 | } | ||
| 1904 | # force MWG::Composite table first | ||
| 1905 | my @mwg = ( 'Image::ExifTool::MWG::Composite' ); | ||
| 1906 | /Composite/ or push @mwg, $_ foreach @{$module{MWG}}; | ||
| 1907 | @{$module{MWG}} = @mwg; | ||
| 1908 | # make sure that the main table always comes first in each file | ||
| 1909 | # and that all other tables from this group follow | ||
| 1910 | @$sortedTables = ( ); | ||
| 1911 | foreach $entry (@sorted) { | ||
| 1912 | ref $entry or push(@$sortedTables, $entry), next; | ||
| 1913 | $$entry[0] =~ /^Image::ExifTool::(\w+)::(\w+)/ or die 'Internal error'; | ||
| 1914 | my $main = "Image::ExifTool::$1::Main"; | ||
| 1915 | # main table must come first (even if it doesn't exist) | ||
| 1916 | push @$sortedTables, $main if $hasMain{$1}; | ||
| 1917 | $_ eq $main or push(@$sortedTables, $_) foreach @$entry; | ||
| 1918 | } | ||
| 1919 | } | ||
| 1920 | |||
| 1921 | #------------------------------------------------------------------------------ | ||
| 1922 | # Get a list of sorted tag ID's from a table | ||
| 1923 | # Inputs: 0) tag table ref | ||
| 1924 | # Returns: list of sorted keys | ||
| 1925 | sub SortedTagTableKeys($) | ||
| 1926 | { | ||
| 1927 | my $table = shift; | ||
| 1928 | my $vars = $$table{VARS} || { }; | ||
| 1929 | my @keys = TagTableKeys($table); | ||
| 1930 | if ($$vars{ID_FMT} and $$vars{ID_FMT} eq 'none') { | ||
| 1931 | # sort by tag name if ID not shown | ||
| 1932 | my ($key, %name); | ||
| 1933 | foreach $key (@keys) { | ||
| 1934 | my ($tagInfo) = GetTagInfoList($table, $key); | ||
| 1935 | $name{$key} = $$tagInfo{Name}; | ||
| 1936 | } | ||
| 1937 | return sort { $name{$a} cmp $name{$b} or $a cmp $b } @keys; | ||
| 1938 | } else { | ||
| 1939 | my $sortProc = $$vars{SORT_PROC} || \&NumbersFirst; | ||
| 1940 | return sort { &$sortProc($a,$b) } @keys; | ||
| 1941 | } | ||
| 1942 | } | ||
| 1943 | |||
| 1944 | #------------------------------------------------------------------------------ | ||
| 1945 | # Get the order that we want to print the tables in the documentation | ||
| 1946 | # Inputs: 0-N) Extra tables to add at end | ||
| 1947 | # Returns: tables in the order we want | ||
| 1948 | sub GetTableOrder(@) | ||
| 1949 | { | ||
| 1950 | my %gotTable; | ||
| 1951 | my @tableNames = @tableOrder; | ||
| 1952 | my (@orderedTables, %mainTables, @outOfOrder); | ||
| 1953 | my $lastTable = ''; | ||
| 1954 | |||
| 1955 | while (@tableNames) { | ||
| 1956 | my $tableName = shift @tableNames; | ||
| 1957 | next if $gotTable{$tableName}; | ||
| 1958 | if ($tableName =~ /^Image::ExifTool::(\w+)::Main/) { | ||
| 1959 | $mainTables{$1} = 1; | ||
| 1960 | } elsif ($lastTable and not $tableName =~ /^${lastTable}::/) { | ||
| 1961 | push @outOfOrder, $tableName; | ||
| 1962 | } | ||
| 1963 | ($lastTable) = ($tableName =~ /^(Image::ExifTool::\w+)/); | ||
| 1964 | push @orderedTables, $tableName; | ||
| 1965 | $gotTable{$tableName} = 1; | ||
| 1966 | my $table = GetTagTable($tableName); | ||
| 1967 | # recursively scan through tables in subdirectories | ||
| 1968 | my @moreTables; | ||
| 1969 | $caseInsensitive = ($$table{GROUPS} and $$table{GROUPS}{0} eq 'XMP'); | ||
| 1970 | $numbersFirst = -1 if $$table{VARS} and $$table{VARS}{ALPHA_FIRST}; | ||
| 1971 | my @keys = SortedTagTableKeys($table); | ||
| 1972 | $numbersFirst = 1; | ||
| 1973 | foreach (@keys) { | ||
| 1974 | my @infoArray = GetTagInfoList($table,$_); | ||
| 1975 | my $tagInfo; | ||
| 1976 | foreach $tagInfo (@infoArray) { | ||
| 1977 | my $subdir = $$tagInfo{SubDirectory} or next; | ||
| 1978 | $tableName = $$subdir{TagTable} or next; | ||
| 1979 | next if $gotTable{$tableName}; # next if table already loaded | ||
| 1980 | push @moreTables, $tableName; # must scan this one too | ||
| 1981 | } | ||
| 1982 | } | ||
| 1983 | unshift @tableNames, @moreTables; | ||
| 1984 | } | ||
| 1985 | # clean up the order for tables which are out of order | ||
| 1986 | # (groups all Canon and Kodak tables together) | ||
| 1987 | my %fixOrder; | ||
| 1988 | foreach (@outOfOrder) { | ||
| 1989 | next unless /^Image::ExifTool::(\w+)/; | ||
| 1990 | # only re-order tables which have a corresponding main table | ||
| 1991 | next unless $mainTables{$1}; | ||
| 1992 | $fixOrder{$1} = []; # fix the order of these tables | ||
| 1993 | } | ||
| 1994 | my (@sortedTables, %fixPos, $pos); | ||
| 1995 | foreach (@orderedTables) { | ||
| 1996 | if (/^Image::ExifTool::(\w+)/ and $fixOrder{$1}) { | ||
| 1997 | my $fix = $fixOrder{$1}; | ||
| 1998 | unless (@$fix) { | ||
| 1999 | $pos = @sortedTables; | ||
| 2000 | $fixPos{$pos} or $fixPos{$pos} = []; | ||
| 2001 | push @{$fixPos{$pos}}, $1; | ||
| 2002 | } | ||
| 2003 | push @{$fix}, $_; | ||
| 2004 | } else { | ||
| 2005 | push @sortedTables, $_; | ||
| 2006 | } | ||
| 2007 | } | ||
| 2008 | # insert back in better order | ||
| 2009 | foreach $pos (sort { $b <=> $a } keys %fixPos) { # (reverse sort) | ||
| 2010 | my $fix = $fixPos{$pos}; | ||
| 2011 | foreach (@$fix) { | ||
| 2012 | splice(@sortedTables, $pos, 0, @{$fixOrder{$_}}); | ||
| 2013 | } | ||
| 2014 | } | ||
| 2015 | # add the extra tables | ||
| 2016 | push @sortedTables, @_; | ||
| 2017 | # tweak the table order | ||
| 2018 | TweakOrder(\@sortedTables, \%tweakOrder); | ||
| 2019 | |||
| 2020 | return @sortedTables; | ||
| 2021 | } | ||
| 2022 | |||
| 2023 | #------------------------------------------------------------------------------ | ||
| 2024 | # Open HTMLFILE and print header and description | ||
| 2025 | # Inputs: 0) Filename, 1) optional category | ||
| 2026 | # Returns: True on success | ||
| 2027 | my %createdFiles; | ||
| 2028 | sub OpenHtmlFile($;$$) | ||
| 2029 | { | ||
| 2030 | my ($htmldir, $category, $sepTable) = @_; | ||
| 2031 | my ($htmlFile, $head, $title, $url, $class); | ||
| 2032 | my $top = ''; | ||
| 2033 | |||
| 2034 | if ($category) { | ||
| 2035 | my @names = split ' ', $category; | ||
| 2036 | $class = shift @names; | ||
| 2037 | $htmlFile = "$htmldir/TagNames/$class.html"; | ||
| 2038 | $head = $category; | ||
| 2039 | if ($head =~ /^\S+ .+ Struct$/) { | ||
| 2040 | pop @names; | ||
| 2041 | } else { | ||
| 2042 | $head .= ($sepTable ? ' Values' : ' Tags'); | ||
| 2043 | } | ||
| 2044 | ($title = $head) =~ s/ .* / /; | ||
| 2045 | @names and $url = join '_', @names; | ||
| 2046 | } else { | ||
| 2047 | $htmlFile = "$htmldir/TagNames/index.html"; | ||
| 2048 | $category = $class = 'ExifTool'; | ||
| 2049 | $head = $title = 'ExifTool Tag Names'; | ||
| 2050 | } | ||
| 2051 | if ($createdFiles{$htmlFile}) { | ||
| 2052 | open(HTMLFILE, ">>${htmlFile}_tmp") or return 0; | ||
| 2053 | } else { | ||
| 2054 | open(HTMLFILE, ">${htmlFile}_tmp") or return 0; | ||
| 2055 | print HTMLFILE "$docType<html>\n"; | ||
| 2056 | print HTMLFILE "<!-- (this file generated automatically by Image::ExifTool::BuildTagLookup) -->\n"; | ||
| 2057 | print HTMLFILE "<head>\n<title>$title</title>\n"; | ||
| 2058 | print HTMLFILE "<link rel=stylesheet type='text/css' href='style.css' title='Style'>\n"; | ||
| 2059 | print HTMLFILE "</head>\n<body>\n"; | ||
| 2060 | if ($category ne $class and $docs{$class}) { | ||
| 2061 | print HTMLFILE "<h2 class=top>$class Tags</h2>\n" or return 0; | ||
| 2062 | print HTMLFILE '<p>',Doc2Html($docs{$class}),"</p>\n" or return 0; | ||
| 2063 | } else { | ||
| 2064 | $top = " class=top"; | ||
| 2065 | } | ||
| 2066 | } | ||
| 2067 | $head = "<a name='${url}'>$head</a>" if $url; | ||
| 2068 | print HTMLFILE "<h2$top>$head</h2>\n" or return 0; | ||
| 2069 | print HTMLFILE '<p>',Doc2Html($docs{$category}),"</p>\n" if $docs{$category}; | ||
| 2070 | $createdFiles{$htmlFile} = 1; | ||
| 2071 | return 1; | ||
| 2072 | } | ||
| 2073 | |||
| 2074 | #------------------------------------------------------------------------------ | ||
| 2075 | # Close all html files and write trailers | ||
| 2076 | # Returns: true on success | ||
| 2077 | # Inputs: 0) BuildTagLookup object reference | ||
| 2078 | sub CloseHtmlFiles($) | ||
| 2079 | { | ||
| 2080 | my $self = shift; | ||
| 2081 | my $preserveDate = $$self{PRESERVE_DATE}; | ||
| 2082 | my $success = 1; | ||
| 2083 | # get the date | ||
| 2084 | my ($sec,$min,$hr,$day,$mon,$yr) = localtime; | ||
| 2085 | my @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); | ||
| 2086 | $yr += 1900; | ||
| 2087 | my $date = "$month[$mon] $day, $yr"; | ||
| 2088 | my $htmlFile; | ||
| 2089 | my $countNewFiles = 0; | ||
| 2090 | my $countSameFiles = 0; | ||
| 2091 | foreach $htmlFile (keys %createdFiles) { | ||
| 2092 | my $tmpFile = $htmlFile . '_tmp'; | ||
| 2093 | my $fileDate = $date; | ||
| 2094 | if ($preserveDate) { | ||
| 2095 | my @lines = `grep '<i>Last revised' $htmlFile`; | ||
| 2096 | $fileDate = $1 if @lines and $lines[-1] =~ m{<i>Last revised (.*)</i>}; | ||
| 2097 | } | ||
| 2098 | open(HTMLFILE, ">>$tmpFile") or $success = 0, next; | ||
| 2099 | # write the trailers | ||
| 2100 | print HTMLFILE "<hr>\n"; | ||
| 2101 | print HTMLFILE "(This document generated automatically by Image::ExifTool::BuildTagLookup)\n"; | ||
| 2102 | print HTMLFILE "<br><i>Created $createDate</i>\n" if $htmlFile eq 'html/TagNames/index.html'; | ||
| 2103 | print HTMLFILE "<br><i>Last revised $fileDate</i>\n"; | ||
| 2104 | print HTMLFILE "<p class=lf><a href="; | ||
| 2105 | if ($htmlFile =~ /index\.html$/) { | ||
| 2106 | print HTMLFILE "'../index.html'><-- Back to ExifTool home page</a></p>\n"; | ||
| 2107 | } else { | ||
| 2108 | print HTMLFILE "'index.html'><-- ExifTool Tag Names</a></p>\n"; | ||
| 2109 | } | ||
| 2110 | print HTMLFILE "</body>\n</html>\n" or $success = 0; | ||
| 2111 | close HTMLFILE or $success = 0; | ||
| 2112 | # check for differences and only use new file if it was changed | ||
| 2113 | # (so the date only gets updated if changes were really made) | ||
| 2114 | my $useNewFile; | ||
| 2115 | if ($success) { | ||
| 2116 | open (TEMPFILE, $tmpFile) or $success = 0, last; | ||
| 2117 | if (open (HTMLFILE, $htmlFile)) { | ||
| 2118 | while (<HTMLFILE>) { | ||
| 2119 | my $newLine = <TEMPFILE>; | ||
| 2120 | if (defined $newLine) { | ||
| 2121 | next if /^<br><i>Last revised/; | ||
| 2122 | next if $_ eq $newLine; | ||
| 2123 | } | ||
| 2124 | # files are different -- use the new file | ||
| 2125 | $useNewFile = 1; | ||
| 2126 | last; | ||
| 2127 | } | ||
| 2128 | $useNewFile = 1 if <TEMPFILE>; | ||
| 2129 | close HTMLFILE; | ||
| 2130 | } else { | ||
| 2131 | $useNewFile = 1; | ||
| 2132 | } | ||
| 2133 | close TEMPFILE; | ||
| 2134 | if ($useNewFile) { | ||
| 2135 | ++$countNewFiles; | ||
| 2136 | rename $tmpFile, $htmlFile or warn("Error renaming temporary file\n"), $success = 0; | ||
| 2137 | } else { | ||
| 2138 | ++$countSameFiles; | ||
| 2139 | unlink $tmpFile; # erase new file and use existing file | ||
| 2140 | } | ||
| 2141 | } | ||
| 2142 | last unless $success; | ||
| 2143 | } | ||
| 2144 | # save number of files processed so we can check the results later | ||
| 2145 | $self->{COUNT}->{'HTML files changed'} = $countNewFiles; | ||
| 2146 | $self->{COUNT}->{'HTML files unchanged'} = $countSameFiles; | ||
| 2147 | return $success; | ||
| 2148 | } | ||
| 2149 | |||
| 2150 | #------------------------------------------------------------------------------ | ||
| 2151 | # Get bitmask for POD documentation | ||
| 2152 | # Inputs: mask string from HTML docs | ||
| 2153 | # Returns: mask string for POD, or '' | ||
| 2154 | sub PodMask($) | ||
| 2155 | { | ||
| 2156 | my $mask = shift; | ||
| 2157 | return '' unless $mask =~ /^\[val( >> (\d+))? \& (0x[\da-f]+)\]/; | ||
| 2158 | return sprintf(' & 0x%.2x', hex($3) << ($2 || 0)); | ||
| 2159 | } | ||
| 2160 | |||
| 2161 | #------------------------------------------------------------------------------ | ||
| 2162 | # Write the TagName HTML and POD documentation | ||
| 2163 | # Inputs: 0) BuildTagLookup object reference | ||
| 2164 | # 1) output pod file (eg. 'lib/Image/ExifTool/TagNames.pod') | ||
| 2165 | # 2) output html directory (eg. 'html') | ||
| 2166 | # Returns: true on success | ||
| 2167 | # Notes: My apologies for the patchwork code, but this is only used to generate the docs. | ||
| 2168 | sub WriteTagNames($$) | ||
| 2169 | { | ||
| 2170 | my ($self, $podFile, $htmldir) = @_; | ||
| 2171 | my ($tableName, $short, $url, @sepTables, @structs); | ||
| 2172 | my $tagNameInfo = $self->{TAG_NAME_INFO} or return 0; | ||
| 2173 | my $idLabel = $self->{ID_LOOKUP}; | ||
| 2174 | my $shortName = $self->{SHORT_NAME}; | ||
| 2175 | my $sepTable = $self->{SEPARATE_TABLE}; | ||
| 2176 | my $structs = $self->{STRUCTURES}; | ||
| 2177 | my $structLookup = $self->{STRUCT_LOOKUP}; | ||
| 2178 | my $success = 1; | ||
| 2179 | my $columns = 6; # number of columns in html index | ||
| 2180 | my $percent = int(100 / $columns); | ||
| 2181 | |||
| 2182 | # open the file and write the header | ||
| 2183 | open(PODFILE, ">$podFile") or return 0; | ||
| 2184 | $docs{ExifTool} = eval qq{"$docs{ExifTool}"}; | ||
| 2185 | print PODFILE Doc2Pod($docs{PodHeader}, $docs{ExifTool}, $docs{ExifTool2}); | ||
| 2186 | mkdir "$htmldir/TagNames", 0777; | ||
| 2187 | OpenHtmlFile($htmldir) or return 0; | ||
| 2188 | print HTMLFILE "<blockquote>\n"; | ||
| 2189 | print HTMLFILE "<table width='100%' class=frame><tr><td>\n"; | ||
| 2190 | print HTMLFILE "<table width='100%' class=inner cellspacing=1><tr class=h>\n"; | ||
| 2191 | print HTMLFILE "<th colspan=$columns><span class=l>Tag Table Index</span></th></tr>\n"; | ||
| 2192 | print HTMLFILE "<tr class=b><td width='$percent%'>\n"; | ||
| 2193 | |||
| 2194 | # get the full table list, adding shortcuts and plug-in tables to the end | ||
| 2195 | my @tableNames = GetTableOrder('Image::ExifTool::Shortcuts::Main', @pluginTables); | ||
| 2196 | |||
| 2197 | # get list of headings and add any missing ones | ||
| 2198 | my $heading = 'xxx'; | ||
| 2199 | my (@tableIndexNames, @headings); | ||
| 2200 | foreach $tableName (@tableNames) { | ||
| 2201 | $short = $$shortName{$tableName}; | ||
| 2202 | my @names = split ' ', $short; | ||
| 2203 | my $class = shift @names; | ||
| 2204 | if (@names and $class ne 'Other') { | ||
| 2205 | # add heading for tables without a Main | ||
| 2206 | unless ($heading eq $class) { | ||
| 2207 | $heading = $class; | ||
| 2208 | push @tableIndexNames, $heading; | ||
| 2209 | push @headings, $heading; | ||
| 2210 | } | ||
| 2211 | } else { | ||
| 2212 | $heading = $short; | ||
| 2213 | push @headings, $heading; | ||
| 2214 | } | ||
| 2215 | push @tableIndexNames, $tableName; | ||
| 2216 | } | ||
| 2217 | @tableNames = @tableIndexNames; | ||
| 2218 | # print html index of headings only | ||
| 2219 | my $count = 0; | ||
| 2220 | my $lines = int((scalar(@headings) + $columns - 1) / $columns); | ||
| 2221 | foreach $tableName (@headings) { | ||
| 2222 | if ($count) { | ||
| 2223 | if ($count % $lines) { | ||
| 2224 | print HTMLFILE "<br>\n"; | ||
| 2225 | } else { | ||
| 2226 | print HTMLFILE "</td><td width='$percent%'>\n"; | ||
| 2227 | } | ||
| 2228 | } | ||
| 2229 | $short = $$shortName{$tableName}; | ||
| 2230 | $short = $tableName unless $short; | ||
| 2231 | $url = "$short.html"; | ||
| 2232 | # handle various tables in "Other.pm" | ||
| 2233 | if ($short =~ /^Other (.*)/) { | ||
| 2234 | $short = $1; | ||
| 2235 | $url = 'Other.html#' . $1; | ||
| 2236 | } else { | ||
| 2237 | $url = "$short.html"; | ||
| 2238 | } | ||
| 2239 | print HTMLFILE "<a href='${url}'>$short</a>"; | ||
| 2240 | ++$count; | ||
| 2241 | } | ||
| 2242 | print HTMLFILE "\n</td></tr></table></td></tr></table></blockquote>\n"; | ||
| 2243 | print HTMLFILE '<p>',Doc2Html($docs{ExifTool2}),"</p>\n"; | ||
| 2244 | |||
| 2245 | # write all the tag tables | ||
| 2246 | while (@tableNames or @sepTables or @structs) { | ||
| 2247 | while (@sepTables) { | ||
| 2248 | $tableName = shift @sepTables; | ||
| 2249 | my $printConv = $$sepTable{$tableName}; | ||
| 2250 | next unless ref $printConv eq 'HASH'; | ||
| 2251 | $$sepTable{$tableName} = 1; | ||
| 2252 | my $notes = $$printConv{Notes}; | ||
| 2253 | if ($notes) { | ||
| 2254 | # remove unnecessary whitespace | ||
| 2255 | $notes =~ s/^\s+//; $notes =~ s/\s+$//; | ||
| 2256 | $notes =~ s/(^[ \t]+|[ \t]+$)//mg; | ||
| 2257 | } | ||
| 2258 | my $head = $tableName; | ||
| 2259 | $head =~ s/^.* //s; | ||
| 2260 | close HTMLFILE; | ||
| 2261 | if (OpenHtmlFile($htmldir, $tableName, 1)) { | ||
| 2262 | print HTMLFILE '<p>', Doc2Html($notes), "</p>\n" if $notes; | ||
| 2263 | print HTMLFILE "<blockquote>\n"; | ||
| 2264 | print HTMLFILE "<table class=frame><tr><td>\n"; | ||
| 2265 | print HTMLFILE "<table class='inner sep' cellspacing=1>\n"; | ||
| 2266 | my $align = ' class=r'; | ||
| 2267 | my $wid = 0; | ||
| 2268 | my (@keys, @bits); | ||
| 2269 | foreach (sort { NumbersFirst($a,$b) } keys %$printConv) { | ||
| 2270 | next if /^(Notes|PrintHex|PrintInt|PrintString|OTHER|BITMASK)$/; | ||
| 2271 | $align = '' if $align and /[^\d]/; | ||
| 2272 | my $w = length($_) + length($$printConv{$_}); | ||
| 2273 | $wid = $w if $wid < $w; | ||
| 2274 | push @keys, $_; | ||
| 2275 | next unless $$printConv{$_} =~ /[\0-\x1f\x7f-\xff]/; | ||
| 2276 | warn "Warning: Special characters in $tableName PrintConv ($$printConv{$_})\n"; | ||
| 2277 | } | ||
| 2278 | my $bits = $$printConv{BITMASK}; | ||
| 2279 | if ($bits) { | ||
| 2280 | $align = ''; | ||
| 2281 | foreach (sort { NumbersFirst($a,$b) } keys %$bits) { | ||
| 2282 | my $w = length($_) + length($$bits{$_}) + 4; | ||
| 2283 | $wid = $w if $wid < $w; | ||
| 2284 | push @bits, $_; | ||
| 2285 | next unless $$bits{$_} =~ /[\0-\x1f\x7f-\xff]/; | ||
| 2286 | warn "Warning: Special characters in $tableName PrintConv BITMASK ($$bits{$_})\n"; | ||
| 2287 | } | ||
| 2288 | } | ||
| 2289 | $wid = length($tableName)+7 if $wid < length($tableName)+7; | ||
| 2290 | # print in multiple columns if there is room | ||
| 2291 | my $cols = int(110 / ($wid + 4)); | ||
| 2292 | my $items = @keys + @bits; | ||
| 2293 | $cols = 1 if $cols < 1 or $cols > $items or $items < 4; | ||
| 2294 | my $rows = int(($items + $cols - 1) / $cols); | ||
| 2295 | my ($r, $c); | ||
| 2296 | print HTMLFILE '<tr class=h>'; | ||
| 2297 | for ($c=0; $c<$cols; ++$c) { | ||
| 2298 | print HTMLFILE "<th>Value</th><th>$head</th>"; | ||
| 2299 | } | ||
| 2300 | print HTMLFILE "</tr>\n"; | ||
| 2301 | for ($r=0; $r<$rows; ++$r) { | ||
| 2302 | print HTMLFILE '<tr>'; | ||
| 2303 | for ($c=0; $c<$cols; ++$c) { | ||
| 2304 | my ($key, $val, $index, $prt); | ||
| 2305 | my $n = $r + $c * $rows; | ||
| 2306 | if ($n < @keys) { | ||
| 2307 | $key = $keys[$n]; | ||
| 2308 | $val = $$printConv{$key}; | ||
| 2309 | } elsif ($n < $items) { | ||
| 2310 | $key = 'Bit ' . $bits[$n - @keys]; | ||
| 2311 | $val = $$bits{$bits[$n - @keys]}; | ||
| 2312 | } | ||
| 2313 | if (defined $key) { | ||
| 2314 | $index = $key; | ||
| 2315 | $prt = '= ' . EscapeHTML($val); | ||
| 2316 | $index =~ s/\.\d+$// if $$printConv{PrintInt}; | ||
| 2317 | if ($$printConv{PrintHex}) { | ||
| 2318 | $index =~ s/(\.\d+)$//; # remove decimal | ||
| 2319 | $index = sprintf('0x%x',$index); | ||
| 2320 | $index .= $1 if $1; # add back decimal | ||
| 2321 | } elsif ($$printConv{PrintString} or | ||
| 2322 | $index !~ /^[+-]?(?=\d|\.\d)\d*(\.\d*)?$/) | ||
| 2323 | { | ||
| 2324 | $index = "'" . EscapeHTML($index) . "'"; | ||
| 2325 | } | ||
| 2326 | } else { | ||
| 2327 | $index = $prt = ' '; | ||
| 2328 | } | ||
| 2329 | my ($ic, $pc); | ||
| 2330 | if ($c & 0x01) { | ||
| 2331 | $pc = ' class=b'; | ||
| 2332 | $ic = $align ? " class='r b'" : $pc; | ||
| 2333 | } else { | ||
| 2334 | $ic = $align; | ||
| 2335 | $pc = ''; | ||
| 2336 | } | ||
| 2337 | print HTMLFILE "<td$ic>$index</td><td$pc>$prt</td>\n"; | ||
| 2338 | } | ||
| 2339 | print HTMLFILE '</tr>'; | ||
| 2340 | } | ||
| 2341 | print HTMLFILE "</table></td></tr></table></blockquote>\n\n"; | ||
| 2342 | } | ||
| 2343 | } | ||
| 2344 | last unless @tableNames or @structs; | ||
| 2345 | my $isStruct; | ||
| 2346 | if (@structs) { | ||
| 2347 | $tableName = shift @structs; | ||
| 2348 | next if $$structs{$tableName} == 2; # only list each structure once | ||
| 2349 | $$structs{$tableName} = 2; | ||
| 2350 | $isStruct = $$structLookup{$tableName}; | ||
| 2351 | $isStruct or warn("Missing structure $tableName\n"), next; | ||
| 2352 | $tableName = "XMP $tableName" unless $tableName =~ / /; | ||
| 2353 | $short = $tableName = "$tableName Struct"; | ||
| 2354 | my $maxLen = 0; | ||
| 2355 | $maxLen < length and $maxLen = length foreach keys %$isStruct; | ||
| 2356 | $$self{LONG_ID}{$tableName} = $maxLen; | ||
| 2357 | } else { | ||
| 2358 | $tableName = shift @tableNames; | ||
| 2359 | $short = $$shortName{$tableName}; | ||
| 2360 | unless ($short) { | ||
| 2361 | # this is just an index heading | ||
| 2362 | print PODFILE "\n=head2 $tableName Tags\n"; | ||
| 2363 | print PODFILE Doc2Pod($docs{$tableName}) if $docs{$tableName}; | ||
| 2364 | next; | ||
| 2365 | } | ||
| 2366 | } | ||
| 2367 | my $isExif = ($tableName eq 'Image::ExifTool::Exif::Main'); | ||
| 2368 | my $isRiff = ($tableName eq 'Image::ExifTool::RIFF::Info'); | ||
| 2369 | my $isXmpMain = ($tableName eq 'Image::ExifTool::XMP::Main'); | ||
| 2370 | my $info = $$tagNameInfo{$tableName}; | ||
| 2371 | my $id = $$idLabel{$tableName}; | ||
| 2372 | my ($hid, $showGrp); | ||
| 2373 | # widths of the different columns in the POD documentation | ||
| 2374 | my ($wID,$wTag,$wReq,$wGrp) = (8,36,24,10); | ||
| 2375 | my ($composite, $derived, $notes, $longTags, $prefix); | ||
| 2376 | my $wasLong = 0; | ||
| 2377 | if ($short eq 'Shortcuts') { | ||
| 2378 | $derived = '<th>Refers To</th>'; | ||
| 2379 | $composite = 2; | ||
| 2380 | } elsif ($isStruct) { | ||
| 2381 | $derived = ''; | ||
| 2382 | $notes = $$isStruct{NOTES}; | ||
| 2383 | } else { | ||
| 2384 | my $table = GetTagTable($tableName); | ||
| 2385 | $notes = $$table{NOTES}; | ||
| 2386 | if ($$table{NAMESPACE}) { | ||
| 2387 | my $ns = $Image::ExifTool::XMP::stdXlatNS{$$table{NAMESPACE}} || $$table{NAMESPACE}; | ||
| 2388 | my $msg = "These tags belong to the ExifTool XMP-$ns family 1 group."; | ||
| 2389 | if ($notes) { | ||
| 2390 | $notes =~ s/\s+$//; | ||
| 2391 | $notes .= "\n\n" . $msg; | ||
| 2392 | } else { | ||
| 2393 | $notes = $msg; | ||
| 2394 | } | ||
| 2395 | } | ||
| 2396 | $longTags = $$table{VARS}{LONG_TAGS} if $$table{VARS}; | ||
| 2397 | if ($$table{GROUPS}{0} eq 'Composite') { | ||
| 2398 | $composite = 1; | ||
| 2399 | $derived = '<th>Derived From</th>'; | ||
| 2400 | } else { | ||
| 2401 | $composite = 0; | ||
| 2402 | $derived = ''; | ||
| 2403 | } | ||
| 2404 | } | ||
| 2405 | my $podIdLen = $self->{LONG_ID}->{$tableName}; | ||
| 2406 | if ($notes) { | ||
| 2407 | # remove unnecessary whitespace | ||
| 2408 | $notes =~ s/^\s+//; $notes =~ s/\s+$//; | ||
| 2409 | $notes =~ s/(^[ \t]+|[ \t]+$)//mg; | ||
| 2410 | if ($notes =~ /leading '(.*?_)' which/) { | ||
| 2411 | $prefix = $1; | ||
| 2412 | $podIdLen -= length $prefix; | ||
| 2413 | } | ||
| 2414 | } | ||
| 2415 | if ($podIdLen <= $wID) { | ||
| 2416 | $podIdLen = $wID; | ||
| 2417 | } elsif ($short eq 'DICOM') { | ||
| 2418 | $podIdLen = 10; | ||
| 2419 | } else { | ||
| 2420 | # align tag names in secondary columns if possible | ||
| 2421 | my $col = ($podIdLen <= 10) ? 12 : 20; | ||
| 2422 | $podIdLen = $col if $podIdLen < $col; | ||
| 2423 | } | ||
| 2424 | if ($id) { | ||
| 2425 | ($hid = "<th>$id</th>") =~ s/ / /g; | ||
| 2426 | $wTag -= $podIdLen - $wID; | ||
| 2427 | $wID = $podIdLen; | ||
| 2428 | my $longTag = $self->{LONG_NAME}->{$tableName}; | ||
| 2429 | if ($wTag < $longTag) { | ||
| 2430 | if ($wID - $longTag + $wTag >= 6) { # don't let ID column get too narrow | ||
| 2431 | $wID -= $longTag - $wTag; | ||
| 2432 | $wTag = $longTag; | ||
| 2433 | } | ||
| 2434 | ++$wasLong if $wID <= $self->{LONG_ID}->{$tableName}; | ||
| 2435 | } | ||
| 2436 | } elsif ($composite) { | ||
| 2437 | $wTag += $wID - $wReq; | ||
| 2438 | $hid = ''; | ||
| 2439 | } else { | ||
| 2440 | $wTag += 9; | ||
| 2441 | $hid = ''; | ||
| 2442 | } | ||
| 2443 | if ($short eq 'EXIF' or $short eq 'Extra') { | ||
| 2444 | $derived = '<th>Group</th>'; | ||
| 2445 | $showGrp = 1; | ||
| 2446 | $wGrp += 8 if $short eq 'Extra'; # tweak Group column width for "Extra" tags | ||
| 2447 | $wTag -= $wGrp + 1; | ||
| 2448 | } | ||
| 2449 | my $head = ($short =~ / /) ? 'head3' : 'head2'; | ||
| 2450 | my $str = $isStruct ? '' : ' Tags'; | ||
| 2451 | print PODFILE "\n=$head $short$str\n"; | ||
| 2452 | print PODFILE Doc2Pod($docs{$short}) if $docs{$short}; | ||
| 2453 | print PODFILE "\n", Doc2Pod($notes), "\n" if $notes; | ||
| 2454 | my $line = "\n"; | ||
| 2455 | if ($id) { | ||
| 2456 | # shift over 'Index' heading by one character for a bit more balance | ||
| 2457 | $id = " $id" if $id eq 'Index'; | ||
| 2458 | $line .= sprintf " %-${wID}s", $id; | ||
| 2459 | } else { | ||
| 2460 | $line .= ' '; | ||
| 2461 | } | ||
| 2462 | my $tagNameHeading = ($short eq 'XMP') ? 'Namespace' : ($isStruct?'Field':'Tag').' Name'; | ||
| 2463 | $line .= sprintf " %-${wTag}s", $tagNameHeading; | ||
| 2464 | $line .= sprintf " %-${wReq}s", $composite == 2 ? 'Refers To' : 'Derived From' if $composite; | ||
| 2465 | $line .= sprintf " %-${wGrp}s", 'Group' if $showGrp; | ||
| 2466 | $line .= ' Writable'; | ||
| 2467 | print PODFILE $line; | ||
| 2468 | $line =~ s/^(\s*\w.{6}\w) /$1\t/; # change space to tab after long ID label (eg. "Sequence") | ||
| 2469 | $line =~ s/\S/-/g; | ||
| 2470 | $line =~ s/- -/---/g; | ||
| 2471 | $line =~ tr/\t/ /; # change tab back to space | ||
| 2472 | print PODFILE $line,"\n"; | ||
| 2473 | close HTMLFILE; | ||
| 2474 | OpenHtmlFile($htmldir, $short) or $success = 0; | ||
| 2475 | print HTMLFILE '<p>',Doc2Html($notes), "</p>\n" if $notes; | ||
| 2476 | print HTMLFILE "<blockquote>\n"; | ||
| 2477 | print HTMLFILE "<table class=frame><tr><td>\n"; | ||
| 2478 | print HTMLFILE "<table class=inner cellspacing=1>\n"; | ||
| 2479 | print HTMLFILE "<tr class=h>$hid<th>$tagNameHeading</th>\n"; | ||
| 2480 | print HTMLFILE "<th>Writable</th>$derived<th>Values / ${noteFont}Notes</span></th></tr>\n"; | ||
| 2481 | my $rowClass = 1; | ||
| 2482 | my $infoCount = 0; | ||
| 2483 | my $infoList; | ||
| 2484 | foreach $infoList (@$info) { | ||
| 2485 | ++$infoCount; | ||
| 2486 | my ($tagIDstr, $tagNames, $writable, $values, $require, $writeGroup) = @$infoList; | ||
| 2487 | my ($align, $idStr, $w, $tip); | ||
| 2488 | my $wTag2 = $wTag; | ||
| 2489 | if (not $id) { | ||
| 2490 | $idStr = ' '; | ||
| 2491 | } elsif ($tagIDstr =~ /^-?\d+(\.\d+)?$/) { | ||
| 2492 | $w = $wID - 3; | ||
| 2493 | $idStr = sprintf " %${w}g ", $tagIDstr; | ||
| 2494 | my $tooLong = length($idStr) - 6 - $w; | ||
| 2495 | if ($tooLong) { | ||
| 2496 | $tooLong = 3 if $tooLong > 3; | ||
| 2497 | $idStr = substr($idStr, 0, -$tooLong); | ||
| 2498 | } | ||
| 2499 | $align = " class=r"; | ||
| 2500 | } else { | ||
| 2501 | $tagIDstr =~ s/^'$prefix/'/ if $prefix; | ||
| 2502 | $w = $wID; | ||
| 2503 | my $over = length($tagIDstr) - $w; | ||
| 2504 | if ($over > 0) { | ||
| 2505 | # shift over tag name if there is room | ||
| 2506 | if ($over <= $wTag - length($$tagNames[0])) { | ||
| 2507 | $wTag2 -= $over; | ||
| 2508 | $w += $over; | ||
| 2509 | --$wasLong; | ||
| 2510 | } else { | ||
| 2511 | # put tag name on next line if ID is too long | ||
| 2512 | $idStr = " $tagIDstr\n " . (' ' x $w); | ||
| 2513 | if ($longTags) { | ||
| 2514 | --$longTags; | ||
| 2515 | } else { | ||
| 2516 | warn "Notice: Split $$tagNames[0] line\n"; | ||
| 2517 | } | ||
| 2518 | } | ||
| 2519 | } | ||
| 2520 | $idStr = sprintf " %-${w}s ", $tagIDstr unless defined $idStr; | ||
| 2521 | $align = ''; | ||
| 2522 | } | ||
| 2523 | my @reqs; | ||
| 2524 | my @tags = @$tagNames; | ||
| 2525 | my @wGrp = @$writeGroup; | ||
| 2526 | my @vals = @$writable; | ||
| 2527 | my $wrStr = shift @vals; | ||
| 2528 | my $subdir; | ||
| 2529 | my @masks = grep /^\[val( >> \d+)? \& 0x[\da-f]+\]/, @$values; | ||
| 2530 | my $tag = shift @tags; | ||
| 2531 | # if this is a subdirectory or structure, print subdir name (from values) instead of writable | ||
| 2532 | if ($wrStr =~ /^[-=]/) { | ||
| 2533 | $subdir = 1; | ||
| 2534 | if (@masks) { | ||
| 2535 | # combine any mask into the format string | ||
| 2536 | $wrStr .= PodMask($masks[0]); | ||
| 2537 | shift @masks; | ||
| 2538 | @vals = grep !/^\[val( >> \d+)? \& 0x[\da-f]+\]/, @$values; | ||
| 2539 | } else { | ||
| 2540 | @vals = @$values; | ||
| 2541 | } | ||
| 2542 | # remove Notes if subdir has Notes as well | ||
| 2543 | shift @vals if $vals[0] =~ /^\(/ and @vals >= @$writable; | ||
| 2544 | foreach (@vals) { /^\(/ and $_ = '-' } | ||
| 2545 | my $i; # fill in any missing entries from non-directory tags | ||
| 2546 | for ($i=0; $i<@$writable; ++$i) { | ||
| 2547 | $vals[$i] = $$writable[$i] unless defined $vals[$i]; | ||
| 2548 | if (@masks) { | ||
| 2549 | $vals[$i] .= PodMask($masks[0]); | ||
| 2550 | shift @masks; | ||
| 2551 | } | ||
| 2552 | } | ||
| 2553 | if ($$sepTable{$vals[0]}) { | ||
| 2554 | $wrStr =~ s/^[-=]//; | ||
| 2555 | $wrStr = 'no' unless $wrStr; | ||
| 2556 | } elsif ($$structs{$vals[0]}) { | ||
| 2557 | my $flags = $wrStr =~ /([+_]+)$/ ? $1 : ''; | ||
| 2558 | $wrStr = "$vals[0] Struct$flags"; | ||
| 2559 | } else { | ||
| 2560 | $wrStr = $vals[0]; | ||
| 2561 | } | ||
| 2562 | shift @vals; | ||
| 2563 | } elsif ($wrStr and $wrStr ne 'no' and @masks) { | ||
| 2564 | # fill in missing entries if masks are different | ||
| 2565 | my $mask = shift @masks; | ||
| 2566 | while (@masks > @vals) { | ||
| 2567 | last if $masks[@vals] eq $mask; | ||
| 2568 | push @vals, $wrStr; | ||
| 2569 | push @tags, $tag if @tags < @vals; | ||
| 2570 | } | ||
| 2571 | # add Mask to Writable column in POD doc | ||
| 2572 | $wrStr .= PodMask($mask); | ||
| 2573 | } | ||
| 2574 | my $pod = sprintf "%s%-${wTag2}s", $idStr, $tag; | ||
| 2575 | my $tGrp = $wGrp; | ||
| 2576 | if ($id and length($tag) > $wTag2) { | ||
| 2577 | my $madeRoom; | ||
| 2578 | if ($showGrp) { | ||
| 2579 | my $wGrp0 = length($wGrp[0] || '-'); | ||
| 2580 | if (not $composite and $wGrp > $wGrp0) { | ||
| 2581 | $tGrp = $wGrp - (length($tag) - $wTag2); | ||
| 2582 | if ($tGrp < length $wGrp0) { | ||
| 2583 | $tGrp = length $wGrp0; | ||
| 2584 | } else { | ||
| 2585 | $madeRoom = 1; | ||
| 2586 | } | ||
| 2587 | } | ||
| 2588 | } | ||
| 2589 | warn "Warning: Pushed $tag\n" unless $madeRoom; | ||
| 2590 | } | ||
| 2591 | $pod .= sprintf " %-${tGrp}s", shift(@wGrp) || '-' if $showGrp; | ||
| 2592 | if ($composite) { | ||
| 2593 | @reqs = @$require; | ||
| 2594 | $w = $wReq; # Keep writable column in line | ||
| 2595 | length($tag) > $wTag2 and $w -= length($tag) - $wTag2; | ||
| 2596 | $pod .= sprintf " %-${w}s", shift(@reqs) || ''; | ||
| 2597 | } | ||
| 2598 | $pod .= " $wrStr"; | ||
| 2599 | # limit line length to 82 characters (even if it means messing up column alignment) | ||
| 2600 | if (length $pod > 82 and $pod !~ /\n/) { | ||
| 2601 | my $remove = length($pod) - 82; | ||
| 2602 | $pod =~ s/(\w)\s{$remove}/$1/; | ||
| 2603 | } | ||
| 2604 | print PODFILE $pod, "\n"; | ||
| 2605 | my $numTags = scalar @$tagNames; | ||
| 2606 | my $n = 0; | ||
| 2607 | while (@tags or @reqs or @vals) { | ||
| 2608 | my $more = (@tags or @reqs); | ||
| 2609 | $line = ' '; | ||
| 2610 | $line .= ' 'x($wID+1) if $id; | ||
| 2611 | $line .= sprintf("%-${wTag2}s", shift(@tags) || ''); | ||
| 2612 | $line .= sprintf(" %-${wReq}s", shift(@reqs) || '') if $composite; | ||
| 2613 | $line .= sprintf(" %-${wGrp}s", shift(@wGrp) || '-') if $showGrp; | ||
| 2614 | ++$n; | ||
| 2615 | if (@vals) { | ||
| 2616 | my $val = shift @vals; | ||
| 2617 | # use writable if this is a note | ||
| 2618 | my $wrStr = $$writable[$n]; | ||
| 2619 | if ($subdir and ($val =~ /^\(/ or $val =~ /=/ or ($wrStr and $wrStr !~ /^[-=]/))) { | ||
| 2620 | $val = $wrStr; | ||
| 2621 | if (defined $val) { | ||
| 2622 | $val =~ s/^[-=]//; | ||
| 2623 | } else { | ||
| 2624 | # done with tag if nothing else to print | ||
| 2625 | last unless $more; | ||
| 2626 | } | ||
| 2627 | } | ||
| 2628 | if (defined $val) { | ||
| 2629 | $line .= " $val"; | ||
| 2630 | if (@masks) { | ||
| 2631 | $line .= PodMask($masks[0]); | ||
| 2632 | shift @masks; | ||
| 2633 | } | ||
| 2634 | } | ||
| 2635 | } | ||
| 2636 | $line =~ s/\s+$//; # trim trailing white space | ||
| 2637 | print PODFILE "$line\n"; | ||
| 2638 | } | ||
| 2639 | my @htmlTags; | ||
| 2640 | foreach (@$tagNames) { | ||
| 2641 | push @htmlTags, EscapeHTML($_); | ||
| 2642 | } | ||
| 2643 | if (($isExif and $Image::ExifTool::Validate::exifSpec{hex $tagIDstr}) or | ||
| 2644 | ($isRiff and $tagIDstr=~/(\w+)/ and $riffSpec{$1}) or | ||
| 2645 | ($isXmpMain and $tagIDstr=~/([-\w]+)/ and $xmpSpec{$1})) | ||
| 2646 | { | ||
| 2647 | # underline "unknown" makernote tags only | ||
| 2648 | my $n = $tagIDstr eq '0x927c' ? -1 : 0; | ||
| 2649 | $htmlTags[$n] = "<u>$htmlTags[$n]</u>"; | ||
| 2650 | } | ||
| 2651 | $rowClass = $rowClass ? '' : " class=b"; | ||
| 2652 | my $isSubdir; | ||
| 2653 | if ($$writable[0] =~ /^[-=]/) { | ||
| 2654 | $isSubdir = 1; | ||
| 2655 | s/^[-=](.+)/$1/ foreach @$writable; | ||
| 2656 | } | ||
| 2657 | # add tooltip for hex conversion of Tag ID | ||
| 2658 | if ($tagIDstr =~ /^(0x[0-9a-f]+)(\.\d+)?$/i) { | ||
| 2659 | $tip = sprintf(" title='$tagIDstr = %u%s'", hex($1), $2||''); | ||
| 2660 | } elsif ($tagIDstr =~ /^(\d+)(\.\d*)?$/) { | ||
| 2661 | $tip = sprintf(" title='%u = 0x%x'", $1, $1); | ||
| 2662 | } else { | ||
| 2663 | $tip = ''; | ||
| 2664 | # use copyright symbol in QuickTime UserData tags | ||
| 2665 | $tagIDstr =~ s/^"\\xa9/"©/; | ||
| 2666 | # escape necessary characters in html | ||
| 2667 | $tagIDstr =~ s/>/>/g; | ||
| 2668 | $tagIDstr =~ s/</</g; | ||
| 2669 | } | ||
| 2670 | # add tooltip for special writable attributes | ||
| 2671 | my $wtip = ''; | ||
| 2672 | my %wattr = ( | ||
| 2673 | '_' => 'Flattened', | ||
| 2674 | '+' => 'List', | ||
| 2675 | '/' => 'Avoid', | ||
| 2676 | '~' => 'Writable only with -n', | ||
| 2677 | '!' => 'Unsafe', | ||
| 2678 | '*' => 'Protected', | ||
| 2679 | ':' => 'Mandatory', | ||
| 2680 | '^' => 'Deletable', | ||
| 2681 | ); | ||
| 2682 | my ($wstr, %hasAttr, @hasAttr); | ||
| 2683 | foreach $wstr (@$writable) { | ||
| 2684 | next unless $wstr =~ m{([+/~!*:_^]+)$}; | ||
| 2685 | my @a = split //, $1; | ||
| 2686 | foreach (@a) { | ||
| 2687 | next if $hasAttr{$_}; | ||
| 2688 | push @hasAttr, $_; | ||
| 2689 | $hasAttr{$_} = 1; | ||
| 2690 | } | ||
| 2691 | } | ||
| 2692 | if (@hasAttr) { | ||
| 2693 | $wtip = " title='"; | ||
| 2694 | my $n = 0; | ||
| 2695 | foreach (@hasAttr) { | ||
| 2696 | $wtip .= "\n" if $n; | ||
| 2697 | $wtip .= " $_ = $wattr{$_}"; | ||
| 2698 | ++$n; | ||
| 2699 | } | ||
| 2700 | $wtip .= "'"; | ||
| 2701 | } | ||
| 2702 | # print this row in the tag table | ||
| 2703 | print HTMLFILE "<tr$rowClass>\n"; | ||
| 2704 | print HTMLFILE "<td$align$tip>$tagIDstr</td>\n" if $id; | ||
| 2705 | print HTMLFILE "<td>", join("\n <br>",@htmlTags), "</td>\n"; | ||
| 2706 | print HTMLFILE "<td class=c$wtip>",join('<br>',@$writable),"</td>\n"; | ||
| 2707 | print HTMLFILE '<td class=n>',join("\n <br>",@$require),"</td>\n" if $composite; | ||
| 2708 | print HTMLFILE "<td class=c>",join('<br>',@$writeGroup),"</td>\n" if $showGrp; | ||
| 2709 | print HTMLFILE "<td>"; | ||
| 2710 | if (@$values) { | ||
| 2711 | if ($isSubdir) { | ||
| 2712 | my ($smallNote, @values); | ||
| 2713 | foreach (@$values) { | ||
| 2714 | if (/^\(/) { | ||
| 2715 | $_ = Doc2Html($_); | ||
| 2716 | # set the note font | ||
| 2717 | $smallNote = 1 if $numTags < 2; | ||
| 2718 | push @values, ($smallNote ? $noteFontSmall : $noteFont) . "$_</span>"; | ||
| 2719 | next; | ||
| 2720 | } | ||
| 2721 | # make text in square brackets small | ||
| 2722 | if (/^\[/) { | ||
| 2723 | if (s/^\[!HTML\]//) { | ||
| 2724 | push @values, $_; | ||
| 2725 | } else { | ||
| 2726 | $_ = Doc2Html($_); | ||
| 2727 | push @values, "<span class=s>$_</span>"; | ||
| 2728 | } | ||
| 2729 | next; | ||
| 2730 | } | ||
| 2731 | /=/ and push(@values, $_), next; | ||
| 2732 | my @names = split; | ||
| 2733 | my $suffix = ' Tags'; | ||
| 2734 | if ($$sepTable{$_}) { | ||
| 2735 | push @sepTables, $_; | ||
| 2736 | $suffix = ' Values'; | ||
| 2737 | } | ||
| 2738 | # handle structures specially | ||
| 2739 | if ($$structs{$_}) { | ||
| 2740 | # assume XMP module for this struct unless otherwise specified | ||
| 2741 | unshift @names, 'XMP' unless / /; | ||
| 2742 | push @structs, $_; # list this later | ||
| 2743 | # hack to put Area Struct in with XMP tags, | ||
| 2744 | # even though it is only used by the MWG module | ||
| 2745 | push @structs, 'Area' if $_ eq 'Dimensions'; | ||
| 2746 | $suffix = ' Struct'; | ||
| 2747 | } | ||
| 2748 | $url = (shift @names) . '.html'; | ||
| 2749 | @names and $url .= '#' . join '_', @names; | ||
| 2750 | push @values, "--> <a href='${url}'>$_$suffix</a>"; | ||
| 2751 | } | ||
| 2752 | # put small note last | ||
| 2753 | $smallNote and push @values, shift @values; | ||
| 2754 | print HTMLFILE join("\n <br>",@values); | ||
| 2755 | } else { | ||
| 2756 | my ($close, $br) = ('', ''); | ||
| 2757 | foreach (@$values) { | ||
| 2758 | if (s/^\[!HTML\]//) { | ||
| 2759 | print HTMLFILE $close if $close; | ||
| 2760 | print HTMLFILE $_; | ||
| 2761 | $close = $br = ''; | ||
| 2762 | } else { | ||
| 2763 | if (/^\(/) { | ||
| 2764 | # notes can use POD syntax | ||
| 2765 | $_ = $noteFont . Doc2Html($_) . "</span>"; | ||
| 2766 | } else { | ||
| 2767 | $_ = EscapeHTML($_); | ||
| 2768 | } | ||
| 2769 | $close or $_ = "<span class=s>$_", $close = '</span>'; | ||
| 2770 | print HTMLFILE $br, $_; | ||
| 2771 | $br = "\n <br>"; | ||
| 2772 | } | ||
| 2773 | } | ||
| 2774 | print HTMLFILE $close if $close; | ||
| 2775 | } | ||
| 2776 | } else { | ||
| 2777 | print HTMLFILE ' '; | ||
| 2778 | } | ||
| 2779 | print HTMLFILE "</td></tr>\n"; | ||
| 2780 | } | ||
| 2781 | warn "$longTags unaccounted-for long tags in $tableName\n" if $longTags; | ||
| 2782 | if ($wasLong and not defined $longTags) { | ||
| 2783 | warn "Notice: Long tags in $tableName table\n"; | ||
| 2784 | } | ||
| 2785 | unless ($infoCount) { | ||
| 2786 | print PODFILE " [no tags known]\n"; | ||
| 2787 | my $cols = 3; | ||
| 2788 | ++$cols if $hid; | ||
| 2789 | ++$cols if $derived; | ||
| 2790 | print HTMLFILE "<tr><td colspan=$cols class=c><i>[no tags known]</i></td></tr>\n"; | ||
| 2791 | } | ||
| 2792 | print HTMLFILE "</table></td></tr></table></blockquote>\n\n"; | ||
| 2793 | } | ||
| 2794 | close(HTMLFILE) or $success = 0; | ||
| 2795 | CloseHtmlFiles($self) or $success = 0; | ||
| 2796 | print PODFILE Doc2Pod($docs{PodTrailer}) or $success = 0; | ||
| 2797 | close(PODFILE) or $success = 0; | ||
| 2798 | return $success; | ||
| 2799 | } | ||
| 2800 | |||
| 2801 | 1; # end | ||
| 2802 | |||
| 2803 | |||
| 2804 | __END__ |