XMP.pm 161 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043
  1. #------------------------------------------------------------------------------
  2. # File: XMP.pm
  3. #
  4. # Description: Read XMP meta information
  5. #
  6. # Revisions: 11/25/2003 - P. Harvey Created
  7. # 10/28/2004 - P. Harvey Major overhaul to conform with XMP spec
  8. # 02/27/2005 - P. Harvey Also read UTF-16 and UTF-32 XMP
  9. # 08/30/2005 - P. Harvey Split tag tables into separate namespaces
  10. # 10/24/2005 - P. Harvey Added ability to parse .XMP files
  11. # 08/25/2006 - P. Harvey Added ability to handle blank nodes
  12. # 08/22/2007 - P. Harvey Added ability to handle alternate language tags
  13. # 09/26/2008 - P. Harvey Added Iptc4xmpExt tags (version 1.0 rev 2)
  14. #
  15. # References: 1) http://www.adobe.com/products/xmp/pdfs/xmpspec.pdf
  16. # 2) http://www.w3.org/TR/rdf-syntax-grammar/ (20040210)
  17. # 3) http://www.portfoliofaq.com/pfaq/v7mappings.htm
  18. # 4) http://www.iptc.org/IPTC4XMP/
  19. # 5) http://creativecommons.org/technology/xmp
  20. # --> changed to http://wiki.creativecommons.org/Companion_File_metadata_specification (2007/12/21)
  21. # 6) http://www.optimasc.com/products/fileid/xmp-extensions.pdf
  22. # 7) Lou Salkind private communication
  23. # 8) http://partners.adobe.com/public/developer/en/xmp/sdk/XMPspecification.pdf
  24. # 9) http://www.w3.org/TR/SVG11/
  25. # 10) http://www.adobe.com/devnet/xmp/pdfs/XMPSpecificationPart2.pdf (Oct 2008)
  26. # 11) http://www.extensis.com/en/support/kb_article.jsp?articleNumber=6102211
  27. # 12) http://www.cipa.jp/std/documents/e/DC-010-2012_E.pdf
  28. #
  29. # Notes: - Property qualifiers are handled as if they were separate
  30. # properties (with no associated namespace).
  31. #
  32. # - Currently, there is no special treatment of the following
  33. # properties which could potentially affect the extracted
  34. # information: xml:base, rdf:parseType (note that parseType
  35. # Literal isn't allowed by the XMP spec).
  36. #
  37. # - The family 2 group names will be set to 'Unknown' for any XMP
  38. # tags not found in the XMP or Exif tag tables.
  39. #------------------------------------------------------------------------------
  40. package Image::ExifTool::XMP;
  41. use strict;
  42. use vars qw($VERSION $AUTOLOAD @ISA @EXPORT_OK %stdXlatNS %nsURI %dateTimeInfo
  43. %xmpTableDefaults %specialStruct %sDimensions %sArea %sColorant);
  44. use Image::ExifTool qw(:Utils);
  45. use Image::ExifTool::Exif;
  46. require Exporter;
  47. $VERSION = '2.90';
  48. @ISA = qw(Exporter);
  49. @EXPORT_OK = qw(EscapeXML UnescapeXML);
  50. sub ProcessXMP($$;$);
  51. sub WriteXMP($$;$);
  52. sub CheckXMP($$$);
  53. sub ParseXMPElement($$$;$$$$);
  54. sub DecodeBase64($);
  55. sub EncodeBase64($;$);
  56. sub SaveBlankInfo($$$;$);
  57. sub ProcessBlankInfo($$$;$);
  58. sub ValidateXMP($;$);
  59. sub UnescapeChar($$);
  60. sub AddFlattenedTags($;$$);
  61. sub FormatXMPDate($);
  62. sub ConvertRational($);
  63. sub ConvertRationalList($);
  64. # lookup for translating to ExifTool namespaces
  65. %stdXlatNS = (
  66. # shorten ugly namespace prefixes
  67. 'Iptc4xmpCore' => 'iptcCore',
  68. 'Iptc4xmpExt' => 'iptcExt',
  69. 'photomechanic'=> 'photomech',
  70. 'MicrosoftPhoto' => 'microsoft',
  71. 'prismusagerights' => 'pur',
  72. 'GettyImagesGIFT' => 'getty',
  73. );
  74. # translate ExifTool XMP family 1 group names to standard XMP namespace prefixes
  75. my %xmpNS = (
  76. # shorten ugly namespace prefixes
  77. 'iptcCore' => 'Iptc4xmpCore',
  78. 'iptcExt' => 'Iptc4xmpExt',
  79. 'photomechanic'=> 'photomech',
  80. 'microsoft' => 'MicrosoftPhoto',
  81. 'gettyImages' => 'GettyImagesGIFT',
  82. # (prism changed their spec to now use 'pur')
  83. # 'pur' => 'prismusagerights',
  84. );
  85. # Lookup to translate standard XMP namespace prefixes into URI's. This list
  86. # need not be complete, but it must contain an entry for each namespace prefix
  87. # (NAMESPACE) for writable tags in the XMP tables or in structures that doesn't
  88. # define a URI. Also, the namespace must be defined here for non-standard
  89. # namespace prefixes to be recognized.
  90. %nsURI = (
  91. aux => 'http://ns.adobe.com/exif/1.0/aux/',
  92. album => 'http://ns.adobe.com/album/1.0/',
  93. cc => 'http://creativecommons.org/ns#', # changed 2007/12/21 - PH
  94. crs => 'http://ns.adobe.com/camera-raw-settings/1.0/',
  95. crss => 'http://ns.adobe.com/camera-raw-saved-settings/1.0/',
  96. dc => 'http://purl.org/dc/elements/1.1/',
  97. exif => 'http://ns.adobe.com/exif/1.0/',
  98. exifEX => 'http://cipa.jp/exif/1.0/',
  99. iX => 'http://ns.adobe.com/iX/1.0/',
  100. pdf => 'http://ns.adobe.com/pdf/1.3/',
  101. pdfx => 'http://ns.adobe.com/pdfx/1.3/',
  102. photoshop => 'http://ns.adobe.com/photoshop/1.0/',
  103. rdf => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
  104. rdfs => 'http://www.w3.org/2000/01/rdf-schema#',
  105. stDim => 'http://ns.adobe.com/xap/1.0/sType/Dimensions#',
  106. stEvt => 'http://ns.adobe.com/xap/1.0/sType/ResourceEvent#',
  107. stFnt => 'http://ns.adobe.com/xap/1.0/sType/Font#',
  108. stJob => 'http://ns.adobe.com/xap/1.0/sType/Job#',
  109. stRef => 'http://ns.adobe.com/xap/1.0/sType/ResourceRef#',
  110. stVer => 'http://ns.adobe.com/xap/1.0/sType/Version#',
  111. stMfs => 'http://ns.adobe.com/xap/1.0/sType/ManifestItem#',
  112. tiff => 'http://ns.adobe.com/tiff/1.0/',
  113. 'x' => 'adobe:ns:meta/',
  114. xmpG => 'http://ns.adobe.com/xap/1.0/g/',
  115. xmpGImg => 'http://ns.adobe.com/xap/1.0/g/img/',
  116. xmp => 'http://ns.adobe.com/xap/1.0/',
  117. xmpBJ => 'http://ns.adobe.com/xap/1.0/bj/',
  118. xmpDM => 'http://ns.adobe.com/xmp/1.0/DynamicMedia/',
  119. xmpMM => 'http://ns.adobe.com/xap/1.0/mm/',
  120. xmpRights => 'http://ns.adobe.com/xap/1.0/rights/',
  121. xmpNote => 'http://ns.adobe.com/xmp/note/',
  122. xmpTPg => 'http://ns.adobe.com/xap/1.0/t/pg/',
  123. xmpidq => 'http://ns.adobe.com/xmp/Identifier/qual/1.0/',
  124. xmpPLUS => 'http://ns.adobe.com/xap/1.0/PLUS/',
  125. dex => 'http://ns.optimasc.com/dex/1.0/',
  126. mediapro => 'http://ns.iview-multimedia.com/mediapro/1.0/',
  127. expressionmedia => 'http://ns.microsoft.com/expressionmedia/1.0/',
  128. Iptc4xmpCore => 'http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/',
  129. Iptc4xmpExt => 'http://iptc.org/std/Iptc4xmpExt/2008-02-29/',
  130. MicrosoftPhoto => 'http://ns.microsoft.com/photo/1.0',
  131. MP1 => 'http://ns.microsoft.com/photo/1.1', #PH (MP1 is fabricated)
  132. MP => 'http://ns.microsoft.com/photo/1.2/',
  133. MPRI => 'http://ns.microsoft.com/photo/1.2/t/RegionInfo#',
  134. MPReg => 'http://ns.microsoft.com/photo/1.2/t/Region#',
  135. lr => 'http://ns.adobe.com/lightroom/1.0/',
  136. DICOM => 'http://ns.adobe.com/DICOM/',
  137. svg => 'http://www.w3.org/2000/svg',
  138. et => 'http://ns.exiftool.ca/1.0/',
  139. #
  140. # namespaces defined in XMP2.pl:
  141. #
  142. plus => 'http://ns.useplus.org/ldf/xmp/1.0/',
  143. # (prism recommendations from http://www.prismstandard.org/specifications/3.0/Image_Guide_3.0.htm)
  144. prism => 'http://prismstandard.org/namespaces/basic/2.0/',
  145. prl => 'http://prismstandard.org/namespaces/prl/2.1/',
  146. pur => 'http://prismstandard.org/namespaces/prismusagerights/2.1/',
  147. pmi => 'http://prismstandard.org/namespaces/pmi/2.2/',
  148. prm => 'http://prismstandard.org/namespaces/prm/3.0/',
  149. acdsee => 'http://ns.acdsee.com/iptc/1.0/',
  150. digiKam => 'http://www.digikam.org/ns/1.0/',
  151. swf => 'http://ns.adobe.com/swf/1.0',
  152. cell => 'http://developer.sonyericsson.com/cell/1.0/',
  153. aas => 'http://ns.apple.com/adjustment-settings/1.0/',
  154. 'mwg-rs' => 'http://www.metadataworkinggroup.com/schemas/regions/',
  155. 'mwg-kw' => 'http://www.metadataworkinggroup.com/schemas/keywords/',
  156. 'mwg-coll' => 'http://www.metadataworkinggroup.com/schemas/collections/',
  157. stArea => 'http://ns.adobe.com/xmp/sType/Area#',
  158. extensis => 'http://ns.extensis.com/extensis/1.0/',
  159. ics => 'http://ns.idimager.com/ics/1.0/',
  160. fpv => 'http://ns.fastpictureviewer.com/fpv/1.0/',
  161. creatorAtom=>'http://ns.adobe.com/creatorAtom/1.0/',
  162. 'apple-fi' => 'http://ns.apple.com/faceinfo/1.0/',
  163. GPano => 'http://ns.google.com/photos/1.0/panorama/',
  164. dwc => 'http://rs.tdwg.org/dwc/index.htm',
  165. GettyImagesGIFT => 'http://xmp.gettyimages.com/gift/1.0/',
  166. );
  167. # build reverse namespace lookup
  168. my %uri2ns;
  169. {
  170. my $ns;
  171. foreach $ns (keys %nsURI) {
  172. $uri2ns{$nsURI{$ns}} = $ns;
  173. }
  174. }
  175. # conversions for GPS coordinates
  176. sub ToDegrees
  177. {
  178. require Image::ExifTool::GPS;
  179. Image::ExifTool::GPS::ToDegrees($_[0], 1);
  180. }
  181. my %latConv = (
  182. ValueConv => \&ToDegrees,
  183. RawConv => 'require Image::ExifTool::GPS; $val', # to load Composite tags and routines
  184. ValueConvInv => q{
  185. require Image::ExifTool::GPS;
  186. Image::ExifTool::GPS::ToDMS($self, $val, 2, "N");
  187. },
  188. PrintConv => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "N")',
  189. PrintConvInv => \&ToDegrees,
  190. );
  191. my %longConv = (
  192. ValueConv => \&ToDegrees,
  193. RawConv => 'require Image::ExifTool::GPS; $val',
  194. ValueConvInv => q{
  195. require Image::ExifTool::GPS;
  196. Image::ExifTool::GPS::ToDMS($self, $val, 2, "E");
  197. },
  198. PrintConv => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "E")',
  199. PrintConvInv => \&ToDegrees,
  200. );
  201. %dateTimeInfo = (
  202. # NOTE: Do NOT put "Groups" here because Groups hash must not be common!
  203. Writable => 'date',
  204. Shift => 'Time',
  205. PrintConv => '$self->ConvertDateTime($val)',
  206. PrintConvInv => '$self->InverseDateTime($val,undef,1)',
  207. );
  208. # this conversion allows alternate language support for designated boolean tags
  209. my %boolConv = (
  210. PrintConv => {
  211. OTHER => sub { # (inverse conversion is the same)
  212. my $val = shift;
  213. return 'False' if lc $val eq 'false';
  214. return 'True' if lc $val eq 'true';
  215. return $val;
  216. },
  217. True => 'True',
  218. False => 'False',
  219. },
  220. );
  221. # XMP namespaces which we don't want to contribute to generated EXIF tag names
  222. # (Note: namespaces with non-standard prefixes aren't currently ignored)
  223. my %ignoreNamespace = ( 'x'=>1, rdf=>1, xmlns=>1, xml=>1, svg=>1, et=>1, office=>1 );
  224. # XMP properties to ignore (set dynamically via dirInfo IgnoreProp)
  225. my %ignoreProp;
  226. # these are the attributes that we handle for properties that contain
  227. # sub-properties. Attributes for simple properties are easy, and we
  228. # just copy them over. These are harder since we don't store attributes
  229. # for properties without simple values. (maybe this will change...)
  230. # (special attributes are indicated by a list reference of tag information)
  231. my %recognizedAttrs = (
  232. 'rdf:about' => [ 'Image::ExifTool::XMP::rdf', 'about', 'About' ],
  233. 'x:xmptk' => [ 'Image::ExifTool::XMP::x', 'xmptk', 'XMPToolkit' ],
  234. 'x:xaptk' => [ 'Image::ExifTool::XMP::x', 'xmptk', 'XMPToolkit' ],
  235. 'rdf:parseType' => 1,
  236. 'rdf:nodeID' => 1,
  237. 'et:toolkit' => 1,
  238. 'rdf:xmlns' => 1, # this is presumably the default namespace, which we currently ignore
  239. 'lastUpdate' => [ 'Image::ExifTool::XMP::XML', 'lastUpdate', 'LastUpdate' ], # found in XML from Sony ILCE-7S MP4
  240. );
  241. # special tags in structures below
  242. # NOTE: this lookup is duplicated in TagLookup.pm!!
  243. %specialStruct = (
  244. STRUCT_NAME => 1, # [optional] name of structure
  245. NAMESPACE => 1, # [mandatory] namespace prefix used for fields of this structure
  246. NOTES => 1, # [optional] notes for documentation about this structure
  247. TYPE => 1, # [optional] rdf:type resource for struct (if used, the StructType flag
  248. # will be set automatically for all derived flattened tags when writing)
  249. );
  250. # XMP structures (each structure is similar to a tag table so we can
  251. # recurse through them in SetPropertyPath() as if they were tag tables)
  252. # The main differences between structure field information and tagInfo hashes are:
  253. # 1) Field information hashes do not contain Name, Groups or Table entries, and
  254. # 2) The TagID entry is optional, and is used only if the key in the structure hash
  255. # is different from the TagID (currently only true for alternate language fields)
  256. # 3) Field information hashes support a additional "Namespace" property.
  257. my %sResourceRef = (
  258. STRUCT_NAME => 'ResourceRef',
  259. NAMESPACE => 'stRef',
  260. documentID => { },
  261. instanceID => { },
  262. manager => { },
  263. managerVariant => { },
  264. manageTo => { },
  265. manageUI => { },
  266. renditionClass => { },
  267. renditionParams => { },
  268. versionID => { },
  269. # added Oct 2008
  270. alternatePaths => { List => 'Seq' },
  271. filePath => { },
  272. fromPart => { },
  273. lastModifyDate => { %dateTimeInfo, Groups => { 2 => 'Time' } },
  274. maskMarkers => { PrintConv => { All => 'All', None => 'None' } },
  275. partMapping => { },
  276. toPart => { },
  277. # added May 2010
  278. originalDocumentID => { }, # (undocumented property written by Adobe InDesign)
  279. );
  280. my %sResourceEvent = (
  281. STRUCT_NAME => 'ResourceEvent',
  282. NAMESPACE => 'stEvt',
  283. action => { },
  284. instanceID => { },
  285. parameters => { },
  286. softwareAgent => { },
  287. when => { %dateTimeInfo, Groups => { 2 => 'Time' } },
  288. # added Oct 2008
  289. changed => { },
  290. );
  291. my %sJobRef = (
  292. STRUCT_NAME => 'JobRef',
  293. NAMESPACE => 'stJob',
  294. id => { },
  295. name => { },
  296. url => { },
  297. );
  298. my %sVersion = (
  299. STRUCT_NAME => 'Version',
  300. NAMESPACE => 'stVer',
  301. comments => { },
  302. event => { Struct => \%sResourceEvent },
  303. modifier => { },
  304. modifyDate => { %dateTimeInfo, Groups => { 2 => 'Time' } },
  305. version => { },
  306. );
  307. my %sThumbnail = (
  308. STRUCT_NAME => 'Thumbnail',
  309. NAMESPACE => 'xmpGImg',
  310. height => { Writable => 'integer' },
  311. width => { Writable => 'integer' },
  312. 'format' => { },
  313. image => {
  314. Avoid => 1,
  315. Groups => { 2 => 'Preview' },
  316. ValueConv => 'Image::ExifTool::XMP::DecodeBase64($val)',
  317. ValueConvInv => 'Image::ExifTool::XMP::EncodeBase64($val)',
  318. },
  319. );
  320. my %sPageInfo = (
  321. STRUCT_NAME => 'PageInfo',
  322. NAMESPACE => 'xmpGImg',
  323. PageNumber => { Writable => 'integer', Namespace => 'xmpTPg' }, # override default namespace
  324. height => { Writable => 'integer' },
  325. width => { Writable => 'integer' },
  326. 'format' => { },
  327. image => {
  328. Groups => { 2 => 'Preview' },
  329. ValueConv => 'Image::ExifTool::XMP::DecodeBase64($val)',
  330. ValueConvInv => 'Image::ExifTool::XMP::EncodeBase64($val)',
  331. },
  332. );
  333. #my %sIdentifierScheme = (
  334. # NAMESPACE => 'xmpidq',
  335. # Scheme => { }, # qualifier for xmp:Identifier only
  336. #);
  337. %sDimensions = (
  338. STRUCT_NAME => 'Dimensions',
  339. NAMESPACE => 'stDim',
  340. w => { Writable => 'real' },
  341. h => { Writable => 'real' },
  342. unit => { },
  343. );
  344. %sArea = (
  345. STRUCT_NAME => 'Area',
  346. NAMESPACE => 'stArea',
  347. 'x' => { Writable => 'real' },
  348. 'y' => { Writable => 'real' },
  349. w => { Writable => 'real' },
  350. h => { Writable => 'real' },
  351. d => { Writable => 'real' },
  352. unit => { },
  353. );
  354. %sColorant = (
  355. STRUCT_NAME => 'Colorant',
  356. NAMESPACE => 'xmpG',
  357. swatchName => { },
  358. mode => { PrintConv => { CMYK=>'CMYK', RGB=>'RGB', LAB=>'Lab' } },
  359. # note: do not implement closed choice for "type" because Adobe can't
  360. # get the case right: spec. says "PROCESS" but Indesign writes "Process"
  361. type => { },
  362. cyan => { Writable => 'real' },
  363. magenta => { Writable => 'real' },
  364. yellow => { Writable => 'real' },
  365. black => { Writable => 'real' },
  366. red => { Writable => 'integer' },
  367. green => { Writable => 'integer' },
  368. blue => { Writable => 'integer' },
  369. L => { Writable => 'real' },
  370. A => { Writable => 'integer' },
  371. B => { Writable => 'integer' },
  372. # 'tint' observed in INDD sample - PH
  373. tint => { Writable => 'integer', Notes => 'not part of 2010 XMP specification' },
  374. );
  375. my %sFont = (
  376. STRUCT_NAME => 'Font',
  377. NAMESPACE => 'stFnt',
  378. fontName => { },
  379. fontFamily => { },
  380. fontFace => { },
  381. fontType => { },
  382. versionString => { },
  383. composite => { Writable => 'boolean' },
  384. fontFileName=> { },
  385. childFontFiles => { List => 'Seq' },
  386. );
  387. my %sOECF = (
  388. STRUCT_NAME => 'OECF',
  389. NAMESPACE => 'exif',
  390. Columns => { Writable => 'integer' },
  391. Rows => { Writable => 'integer' },
  392. Names => { List => 'Seq' },
  393. Values => { List => 'Seq', Writable => 'rational' },
  394. );
  395. # new LR2 crs structures (PH)
  396. my %sCorrectionMask = (
  397. STRUCT_NAME => 'CorrectionMask',
  398. NAMESPACE => 'crs',
  399. # disable List behaviour of flattened Gradient/PaintBasedCorrections
  400. # because these are nested in lists and the flattened tags can't
  401. # do justice to this complex structure
  402. What => { List => 0 },
  403. MaskValue => { Writable => 'real', List => 0, FlatName => 'Value' },
  404. Radius => { Writable => 'real', List => 0 },
  405. Flow => { Writable => 'real', List => 0 },
  406. CenterWeight => { Writable => 'real', List => 0 },
  407. Dabs => { List => 'Seq' },
  408. ZeroX => { Writable => 'real', List => 0 },
  409. ZeroY => { Writable => 'real', List => 0 },
  410. FullX => { Writable => 'real', List => 0 },
  411. FullY => { Writable => 'real', List => 0 },
  412. # new elements used in CircularGradientBasedCorrections CorrectionMasks
  413. # and RetouchAreas Masks
  414. Top => { Writable => 'real', List => 0 },
  415. Left => { Writable => 'real', List => 0 },
  416. Bottom => { Writable => 'real', List => 0 },
  417. Right => { Writable => 'real', List => 0 },
  418. Angle => { Writable => 'real', List => 0 },
  419. Midpoint => { Writable => 'real', List => 0 },
  420. Roundness => { Writable => 'real', List => 0 },
  421. Feather => { Writable => 'real', List => 0 },
  422. Flipped => { Writable => 'boolean', List => 0 },
  423. Version => { Writable => 'integer', List => 0 },
  424. SizeX => { Writable => 'real', List => 0 },
  425. SizeY => { Writable => 'real', List => 0 },
  426. X => { Writable => 'real', List => 0 },
  427. Y => { Writable => 'real', List => 0 },
  428. Alpha => { Writable => 'real', List => 0 },
  429. CenterValue => { Writable => 'real', List => 0 },
  430. PerimeterValue=>{ Writable => 'real', List => 0 },
  431. );
  432. my %sCorrection = (
  433. STRUCT_NAME => 'Correction',
  434. NAMESPACE => 'crs',
  435. What => { List => 0 },
  436. CorrectionAmount => { FlatName => 'Amount', Writable => 'real', List => 0 },
  437. CorrectionActive => { FlatName => 'Active', Writable => 'boolean', List => 0 },
  438. LocalExposure => { FlatName => 'Exposure', Writable => 'real', List => 0 },
  439. LocalSaturation => { FlatName => 'Saturation', Writable => 'real', List => 0 },
  440. LocalContrast => { FlatName => 'Contrast', Writable => 'real', List => 0 },
  441. LocalClarity => { FlatName => 'Clarity', Writable => 'real', List => 0 },
  442. LocalSharpness => { FlatName => 'Sharpness', Writable => 'real', List => 0 },
  443. LocalBrightness => { FlatName => 'Brightness', Writable => 'real', List => 0 },
  444. LocalToningHue => { FlatName => 'Hue', Writable => 'real', List => 0 },
  445. LocalToningSaturation => { FlatName => 'Saturation', Writable => 'real', List => 0 },
  446. LocalExposure2012 => { FlatName => 'Exposure2012', Writable => 'real', List => 0 },
  447. LocalContrast2012 => { FlatName => 'Contrast2012', Writable => 'real', List => 0 },
  448. LocalHighlights2012 => { FlatName => 'Highlights2012', Writable => 'real', List => 0 },
  449. LocalShadows2012 => { FlatName => 'Shadows2012', Writable => 'real', List => 0 },
  450. LocalClarity2012 => { FlatName => 'Clarity2012', Writable => 'real', List => 0 },
  451. LocalLuminanceNoise => { FlatName => 'LuminanceNoise', Writable => 'real', List => 0 },
  452. LocalMoire => { FlatName => 'Moire', Writable => 'real', List => 0 },
  453. LocalDefringe => { FlatName => 'Defringe', Writable => 'real', List => 0 },
  454. LocalTemperature => { FlatName => 'Temperature',Writable => 'real', List => 0 },
  455. LocalTint => { FlatName => 'Tint', Writable => 'real', List => 0 },
  456. CorrectionMasks => {
  457. FlatName => 'Mask',
  458. Struct => \%sCorrectionMask,
  459. List => 'Seq',
  460. },
  461. );
  462. my %sRetouchArea = (
  463. STRUCT_NAME => 'RetouchArea',
  464. NAMESPACE => 'crs',
  465. SpotType => { List => 0 },
  466. SourceState => { List => 0 },
  467. Method => { List => 0 },
  468. SourceX => { Writable => 'real', List => 0 },
  469. OffsetY => { Writable => 'real', List => 0 },
  470. Opacity => { Writable => 'real', List => 0 },
  471. Feather => { Writable => 'real', List => 0 },
  472. Seed => { Writable => 'integer', List => 0 },
  473. Masks => {
  474. FlatName => 'Mask',
  475. Struct => \%sCorrectionMask,
  476. List => 'Seq',
  477. },
  478. );
  479. # IPTC Extension 1.0 structures
  480. my %sLocationDetails = (
  481. STRUCT_NAME => 'LocationDetails',
  482. NAMESPACE => 'Iptc4xmpExt',
  483. City => { },
  484. CountryCode => { },
  485. CountryName => { },
  486. ProvinceState=> { },
  487. Sublocation => { },
  488. WorldRegion => { },
  489. LocationId => { List => 'Bag' },
  490. );
  491. my %sCVTermDetails = (
  492. STRUCT_NAME => 'CVTermDetails',
  493. NAMESPACE => 'Iptc4xmpExt',
  494. CvTermId => { },
  495. CvTermName => { Writable => 'lang-alt' },
  496. CvId => { },
  497. CvTermRefinedAbout => { },
  498. );
  499. # main XMP tag table (tag ID's are used for the family 1 group names)
  500. %Image::ExifTool::XMP::Main = (
  501. GROUPS => { 2 => 'Unknown' },
  502. PROCESS_PROC => \&ProcessXMP,
  503. WRITE_PROC => \&WriteXMP,
  504. dc => {
  505. Name => 'dc', # (otherwise generated name would be 'Dc')
  506. SubDirectory => { TagTable => 'Image::ExifTool::XMP::dc' },
  507. },
  508. xmp => {
  509. Name => 'xmp',
  510. SubDirectory => { TagTable => 'Image::ExifTool::XMP::xmp' },
  511. },
  512. xmpDM => {
  513. Name => 'xmpDM',
  514. SubDirectory => { TagTable => 'Image::ExifTool::XMP::xmpDM' },
  515. },
  516. xmpRights => {
  517. Name => 'xmpRights',
  518. SubDirectory => { TagTable => 'Image::ExifTool::XMP::xmpRights' },
  519. },
  520. xmpNote => {
  521. Name => 'xmpNote',
  522. SubDirectory => { TagTable => 'Image::ExifTool::XMP::xmpNote' },
  523. },
  524. xmpMM => {
  525. Name => 'xmpMM',
  526. SubDirectory => { TagTable => 'Image::ExifTool::XMP::xmpMM' },
  527. },
  528. xmpBJ => {
  529. Name => 'xmpBJ',
  530. SubDirectory => { TagTable => 'Image::ExifTool::XMP::xmpBJ' },
  531. },
  532. xmpTPg => {
  533. Name => 'xmpTPg',
  534. SubDirectory => { TagTable => 'Image::ExifTool::XMP::xmpTPg' },
  535. },
  536. pdf => {
  537. Name => 'pdf',
  538. SubDirectory => { TagTable => 'Image::ExifTool::XMP::pdf' },
  539. },
  540. pdfx => {
  541. Name => 'pdfx',
  542. SubDirectory => { TagTable => 'Image::ExifTool::XMP::pdfx' },
  543. },
  544. photoshop => {
  545. Name => 'photoshop',
  546. SubDirectory => { TagTable => 'Image::ExifTool::XMP::photoshop' },
  547. },
  548. crs => {
  549. Name => 'crs',
  550. SubDirectory => { TagTable => 'Image::ExifTool::XMP::crs' },
  551. },
  552. # crss - it would be tedious to add the ability to write this
  553. aux => {
  554. Name => 'aux',
  555. SubDirectory => { TagTable => 'Image::ExifTool::XMP::aux' },
  556. },
  557. tiff => {
  558. Name => 'tiff',
  559. SubDirectory => { TagTable => 'Image::ExifTool::XMP::tiff' },
  560. },
  561. exif => {
  562. Name => 'exif',
  563. SubDirectory => { TagTable => 'Image::ExifTool::XMP::exif' },
  564. },
  565. exifEX => {
  566. Name => 'exifEX',
  567. SubDirectory => { TagTable => 'Image::ExifTool::XMP::exifEX' },
  568. },
  569. iptcCore => {
  570. Name => 'iptcCore',
  571. SubDirectory => { TagTable => 'Image::ExifTool::XMP::iptcCore' },
  572. },
  573. iptcExt => {
  574. Name => 'iptcExt',
  575. SubDirectory => { TagTable => 'Image::ExifTool::XMP::iptcExt' },
  576. },
  577. PixelLive => {
  578. SubDirectory => { TagTable => 'Image::ExifTool::XMP::PixelLive' },
  579. },
  580. xmpPLUS => {
  581. Name => 'xmpPLUS',
  582. SubDirectory => { TagTable => 'Image::ExifTool::XMP::xmpPLUS' },
  583. },
  584. plus => {
  585. Name => 'plus',
  586. SubDirectory => { TagTable => 'Image::ExifTool::XMP::plus' },
  587. },
  588. cc => {
  589. Name => 'cc',
  590. SubDirectory => { TagTable => 'Image::ExifTool::XMP::cc' },
  591. },
  592. dex => {
  593. Name => 'dex',
  594. SubDirectory => { TagTable => 'Image::ExifTool::XMP::dex' },
  595. },
  596. photomech => {
  597. Name => 'photomech',
  598. SubDirectory => { TagTable => 'Image::ExifTool::PhotoMechanic::XMP' },
  599. },
  600. mediapro => {
  601. Name => 'mediapro',
  602. SubDirectory => { TagTable => 'Image::ExifTool::XMP::MediaPro' },
  603. },
  604. expressionmedia => {
  605. Name => 'expressionmedia',
  606. SubDirectory => { TagTable => 'Image::ExifTool::XMP::ExpressionMedia' },
  607. },
  608. microsoft => {
  609. Name => 'microsoft',
  610. SubDirectory => { TagTable => 'Image::ExifTool::Microsoft::XMP' },
  611. },
  612. MP => {
  613. Name => 'MP',
  614. SubDirectory => { TagTable => 'Image::ExifTool::Microsoft::MP' },
  615. },
  616. MP1 => {
  617. Name => 'MP1',
  618. SubDirectory => { TagTable => 'Image::ExifTool::Microsoft::MP1' },
  619. },
  620. lr => {
  621. Name => 'lr',
  622. SubDirectory => { TagTable => 'Image::ExifTool::XMP::Lightroom' },
  623. },
  624. DICOM => {
  625. Name => 'DICOM',
  626. SubDirectory => { TagTable => 'Image::ExifTool::XMP::DICOM' },
  627. },
  628. album => {
  629. Name => 'album',
  630. SubDirectory => { TagTable => 'Image::ExifTool::XMP::Album' },
  631. },
  632. prism => {
  633. Name => 'prism',
  634. SubDirectory => { TagTable => 'Image::ExifTool::XMP::prism' },
  635. },
  636. prl => {
  637. Name => 'prl',
  638. SubDirectory => { TagTable => 'Image::ExifTool::XMP::prl' },
  639. },
  640. pur => {
  641. Name => 'pur',
  642. SubDirectory => { TagTable => 'Image::ExifTool::XMP::pur' },
  643. },
  644. pmi => {
  645. Name => 'pmi',
  646. SubDirectory => { TagTable => 'Image::ExifTool::XMP::pmi' },
  647. },
  648. prm => {
  649. Name => 'prm',
  650. SubDirectory => { TagTable => 'Image::ExifTool::XMP::prm' },
  651. },
  652. rdf => {
  653. Name => 'rdf',
  654. SubDirectory => { TagTable => 'Image::ExifTool::XMP::rdf' },
  655. },
  656. 'x' => {
  657. Name => 'x',
  658. SubDirectory => { TagTable => 'Image::ExifTool::XMP::x' },
  659. },
  660. acdsee => {
  661. Name => 'acdsee',
  662. SubDirectory => { TagTable => 'Image::ExifTool::XMP::acdsee' },
  663. },
  664. digiKam => {
  665. Name => 'digiKam',
  666. SubDirectory => { TagTable => 'Image::ExifTool::XMP::digiKam' },
  667. },
  668. swf => {
  669. Name => 'swf',
  670. SubDirectory => { TagTable => 'Image::ExifTool::XMP::swf' },
  671. },
  672. cell => {
  673. Name => 'cell',
  674. SubDirectory => { TagTable => 'Image::ExifTool::XMP::cell' },
  675. },
  676. aas => {
  677. Name => 'aas',
  678. SubDirectory => { TagTable => 'Image::ExifTool::XMP::aas' },
  679. },
  680. 'mwg-rs' => {
  681. Name => 'mwg-rs',
  682. SubDirectory => { TagTable => 'Image::ExifTool::MWG::Regions' },
  683. },
  684. 'mwg-kw' => {
  685. Name => 'mwg-kw',
  686. SubDirectory => { TagTable => 'Image::ExifTool::MWG::Keywords' },
  687. },
  688. 'mwg-coll' => {
  689. Name => 'mwg-coll',
  690. SubDirectory => { TagTable => 'Image::ExifTool::MWG::Collections' },
  691. },
  692. extensis => {
  693. Name => 'extensis',
  694. SubDirectory => { TagTable => 'Image::ExifTool::XMP::extensis' },
  695. },
  696. ics => {
  697. Name => 'ics',
  698. SubDirectory => { TagTable => 'Image::ExifTool::XMP::ics' },
  699. },
  700. fpv => {
  701. Name => 'fpv',
  702. SubDirectory => { TagTable => 'Image::ExifTool::XMP::fpv' },
  703. },
  704. creatorAtom => {
  705. Name => 'creatorAtom',
  706. SubDirectory => { TagTable => 'Image::ExifTool::XMP::creatorAtom' },
  707. },
  708. 'apple-fi' => {
  709. Name => 'apple-fi',
  710. SubDirectory => { TagTable => 'Image::ExifTool::XMP::apple_fi' },
  711. },
  712. GPano => {
  713. Name => 'GPano',
  714. SubDirectory => { TagTable => 'Image::ExifTool::XMP::GPano' },
  715. },
  716. dwc => {
  717. Name => 'dwc',
  718. SubDirectory => { TagTable => 'Image::ExifTool::DarwinCore::Main' },
  719. },
  720. getty => {
  721. Name => 'getty',
  722. SubDirectory => { TagTable => 'Image::ExifTool::XMP::GettyImages' },
  723. },
  724. );
  725. # hack to allow XML containing Dublin Core metadata to be handled like XMP (eg. EPUB - see ZIP.pm)
  726. %Image::ExifTool::XMP::XML = (
  727. GROUPS => { 0 => 'XML', 1 => 'XML', 2 => 'Unknown' },
  728. PROCESS_PROC => \&ProcessXMP,
  729. dc => {
  730. Name => 'dc',
  731. SubDirectory => { TagTable => 'Image::ExifTool::XMP::dc' },
  732. },
  733. lastUpdate => {
  734. Groups => { 2 => 'Time' },
  735. ValueConv => 'Image::ExifTool::XMP::ConvertXMPDate($val)',
  736. PrintConv => '$self->ConvertDateTime($val)',
  737. },
  738. );
  739. #
  740. # Tag tables for all XMP namespaces:
  741. #
  742. # Writable - only need to define this for writable tags if not plain text
  743. # (boolean, integer, rational, real, date or lang-alt)
  744. # List - XMP list type (Bag, Seq or Alt, or set to 1 for elements in Struct lists --
  745. # this is necessary to obtain proper list behaviour when reading/writing)
  746. #
  747. # (Note that family 1 group names are generated from the property namespace, not
  748. # the group1 names below which exist so the groups will appear in the list.)
  749. #
  750. %xmpTableDefaults = (
  751. WRITE_PROC => \&WriteXMP,
  752. CHECK_PROC => \&CheckXMP,
  753. WRITABLE => 'string',
  754. LANG_INFO => \&GetLangInfo,
  755. );
  756. # rdf attributes extracted
  757. %Image::ExifTool::XMP::rdf = (
  758. %xmpTableDefaults,
  759. GROUPS => { 1 => 'XMP-rdf', 2 => 'Document' },
  760. NAMESPACE => 'rdf',
  761. NOTES => q{
  762. Most RDF attributes are handled internally, but the "about" attribute is
  763. treated specially to allow it to be set to a specific value if required.
  764. },
  765. about => { Protected => 1 },
  766. );
  767. # x attributes extracted
  768. %Image::ExifTool::XMP::x = (
  769. %xmpTableDefaults,
  770. GROUPS => { 1 => 'XMP-x', 2 => 'Document' },
  771. NAMESPACE => 'x',
  772. NOTES => qq{
  773. The "x" namespace is used for the "xmpmeta" wrapper, and may contain an
  774. "xmptk" attribute that is extracted as the XMPToolkit tag. When writing,
  775. the XMPToolkit tag is generated automatically by ExifTool unless
  776. specifically set to another value.
  777. },
  778. xmptk => { Name => 'XMPToolkit', Protected => 1 },
  779. );
  780. # Dublin Core namespace properties (dc)
  781. %Image::ExifTool::XMP::dc = (
  782. %xmpTableDefaults,
  783. GROUPS => { 1 => 'XMP-dc', 2 => 'Other' },
  784. NAMESPACE => 'dc',
  785. TABLE_DESC => 'XMP Dublin Core',
  786. NOTES => 'Dublin Core namespace tags.',
  787. contributor => { Groups => { 2 => 'Author' }, List => 'Bag' },
  788. coverage => { },
  789. creator => { Groups => { 2 => 'Author' }, List => 'Seq' },
  790. date => { Groups => { 2 => 'Time' }, List => 'Seq', %dateTimeInfo },
  791. description => { Groups => { 2 => 'Image' }, Writable => 'lang-alt' },
  792. 'format' => { Groups => { 2 => 'Image' } },
  793. identifier => { Groups => { 2 => 'Image' } },
  794. language => { List => 'Bag' },
  795. publisher => { Groups => { 2 => 'Author' }, List => 'Bag' },
  796. relation => { List => 'Bag' },
  797. rights => { Groups => { 2 => 'Author' }, Writable => 'lang-alt' },
  798. source => { Groups => { 2 => 'Author' }, Avoid => 1 },
  799. subject => { Groups => { 2 => 'Image' }, List => 'Bag' },
  800. title => { Groups => { 2 => 'Image' }, Writable => 'lang-alt' },
  801. type => { Groups => { 2 => 'Image' }, List => 'Bag' },
  802. );
  803. # XMP namespace properties (xmp, xap)
  804. %Image::ExifTool::XMP::xmp = (
  805. %xmpTableDefaults,
  806. GROUPS => { 1 => 'XMP-xmp', 2 => 'Image' },
  807. NAMESPACE => 'xmp',
  808. NOTES => q{
  809. XMP namespace tags. If the older "xap", "xapBJ", "xapMM" or "xapRights"
  810. namespace prefixes are found, they are translated to the newer "xmp",
  811. "xmpBJ", "xmpMM" and "xmpRights" prefixes for use in family 1 group names.
  812. },
  813. Advisory => { List => 'Bag', Notes => 'deprecated' },
  814. BaseURL => { },
  815. # (date/time tags not as reliable as EXIF)
  816. CreateDate => { Groups => { 2 => 'Time' }, %dateTimeInfo, Priority => 0 },
  817. CreatorTool => { },
  818. Identifier => { Avoid => 1, List => 'Bag' },
  819. Label => { },
  820. MetadataDate=> { Groups => { 2 => 'Time' }, %dateTimeInfo },
  821. ModifyDate => { Groups => { 2 => 'Time' }, %dateTimeInfo, Priority => 0 },
  822. Nickname => { },
  823. Rating => { Writable => 'real', Notes => 'a value from 0 to 5, or -1 for "rejected"' },
  824. Thumbnails => {
  825. FlatName => 'Thumbnail',
  826. Struct => \%sThumbnail,
  827. List => 'Alt',
  828. },
  829. # the following written by Adobe InDesign, not part of XMP spec:
  830. PageInfo => {
  831. FlatName => 'PageImage',
  832. Struct => \%sPageInfo,
  833. List => 'Seq',
  834. },
  835. PageInfoImage => { Name => 'PageImage', Flat => 1 },
  836. Title => { Avoid => 1, Notes => 'non-standard', Writable => 'lang-alt' }, #11
  837. Author => { Avoid => 1, Notes => 'non-standard', Groups => { 2 => 'Author' } }, #11
  838. Keywords => { Avoid => 1, Notes => 'non-standard' }, #11
  839. Description => { Avoid => 1, Notes => 'non-standard', Writable => 'lang-alt' }, #11
  840. Format => { Avoid => 1, Notes => 'non-standard' }, #11
  841. );
  842. # XMP Rights Management namespace properties (xmpRights, xapRights)
  843. %Image::ExifTool::XMP::xmpRights = (
  844. %xmpTableDefaults,
  845. GROUPS => { 1 => 'XMP-xmpRights', 2 => 'Author' },
  846. NAMESPACE => 'xmpRights',
  847. NOTES => 'XMP Rights Management namespace tags.',
  848. Certificate => { },
  849. Marked => { Writable => 'boolean' },
  850. Owner => { List => 'Bag' },
  851. UsageTerms => { Writable => 'lang-alt' },
  852. WebStatement => { },
  853. );
  854. # XMP Note namespace properties (xmpNote)
  855. %Image::ExifTool::XMP::xmpNote = (
  856. %xmpTableDefaults,
  857. GROUPS => { 1 => 'XMP-xmpNote' },
  858. NAMESPACE => 'xmpNote',
  859. NOTES => 'XMP Note namespace tags.',
  860. HasExtendedXMP => {
  861. Notes => q{
  862. this tag is protected so it is not writable directly. Instead, it is set
  863. automatically to the GUID of the extended XMP when writing extended XMP to a
  864. JPEG image
  865. },
  866. Protected => 2,
  867. },
  868. );
  869. # XMP xmpMM ManifestItem struct (ref PH, written by Adobe PDF library 8.0)
  870. my %sManifestItem = (
  871. STRUCT_NAME => 'ManifestItem',
  872. NAMESPACE => 'stMfs',
  873. linkForm => { },
  874. placedXResolution => { Namespace => 'xmpMM', Writable => 'real' },
  875. placedYResolution => { Namespace => 'xmpMM', Writable => 'real' },
  876. placedResolutionUnit=> { Namespace => 'xmpMM' },
  877. reference => { Struct => \%sResourceRef },
  878. );
  879. # the xmpMM Pantry
  880. my %sPantryItem = (
  881. STRUCT_NAME => 'PantryItem',
  882. NAMESPACE => undef, # stores any top-level XMP tags
  883. NOTES => q{
  884. This structure must have an InstanceID field, but may also contain any other
  885. XMP properties.
  886. },
  887. InstanceID => { Namespace => 'xmpMM' },
  888. );
  889. # XMP Media Management namespace properties (xmpMM, xapMM)
  890. %Image::ExifTool::XMP::xmpMM = (
  891. %xmpTableDefaults,
  892. GROUPS => { 1 => 'XMP-xmpMM', 2 => 'Other' },
  893. NAMESPACE => 'xmpMM',
  894. TABLE_DESC => 'XMP Media Management',
  895. NOTES => 'XMP Media Management namespace tags.',
  896. DerivedFrom => { Struct => \%sResourceRef },
  897. DocumentID => { },
  898. History => { Struct => \%sResourceEvent, List => 'Seq' },
  899. # we treat these like list items since History is a list
  900. Ingredients => { Struct => \%sResourceRef, List => 'Bag' },
  901. InstanceID => { }, #PH (CS3)
  902. ManagedFrom => { Struct => \%sResourceRef },
  903. Manager => { Groups => { 2 => 'Author' } },
  904. ManageTo => { Groups => { 2 => 'Author' } },
  905. ManageUI => { },
  906. ManagerVariant => { },
  907. Manifest => { Struct => \%sManifestItem, List => 'Bag' },
  908. OriginalDocumentID=> { },
  909. Pantry => { Struct => \%sPantryItem, List => 'Bag' },
  910. PreservedFileName => { }, # undocumented
  911. RenditionClass => { },
  912. RenditionParams => { },
  913. VersionID => { },
  914. Versions => { Struct => \%sVersion, List => 'Seq' },
  915. LastURL => { }, # (deprecated)
  916. RenditionOf => { Struct => \%sResourceRef }, # (deprecated)
  917. SaveID => { Writable => 'integer' }, # (deprecated)
  918. subject => { List => 'Seq', Avoid => 1, Notes => 'undocumented' },
  919. );
  920. # XMP Basic Job Ticket namespace properties (xmpBJ, xapBJ)
  921. %Image::ExifTool::XMP::xmpBJ = (
  922. %xmpTableDefaults,
  923. GROUPS => { 1 => 'XMP-xmpBJ', 2 => 'Other' },
  924. NAMESPACE => 'xmpBJ',
  925. TABLE_DESC => 'XMP Basic Job Ticket',
  926. NOTES => 'XMP Basic Job Ticket namespace tags.',
  927. # Note: JobRef is a List of structures. To accomplish this, we set the XMP
  928. # List=>'Bag', but since SubDirectory is defined, this tag isn't writable
  929. # directly. Then we need to set List=>1 for the members so the Writer logic
  930. # will allow us to add list items.
  931. JobRef => { Struct => \%sJobRef, List => 'Bag' },
  932. );
  933. # XMP Paged-Text namespace properties (xmpTPg)
  934. %Image::ExifTool::XMP::xmpTPg = (
  935. %xmpTableDefaults,
  936. GROUPS => { 1 => 'XMP-xmpTPg', 2 => 'Image' },
  937. NAMESPACE => 'xmpTPg',
  938. TABLE_DESC => 'XMP Paged-Text',
  939. NOTES => 'XMP Paged-Text namespace tags.',
  940. MaxPageSize => { Struct => \%sDimensions },
  941. NPages => { Writable => 'integer' },
  942. Fonts => {
  943. FlatName => '',
  944. Struct => \%sFont,
  945. List => 'Bag',
  946. },
  947. FontsVersionString => { Name => 'FontVersion', Flat => 1 },
  948. FontsComposite => { Name => 'FontComposite', Flat => 1 },
  949. Colorants => {
  950. FlatName => 'Colorant',
  951. Struct => \%sColorant,
  952. List => 'Seq',
  953. },
  954. PlateNames => { List => 'Seq' },
  955. );
  956. # PDF namespace properties (pdf)
  957. %Image::ExifTool::XMP::pdf = (
  958. %xmpTableDefaults,
  959. GROUPS => { 1 => 'XMP-pdf', 2 => 'Image' },
  960. NAMESPACE => 'pdf',
  961. TABLE_DESC => 'XMP PDF',
  962. NOTES => q{
  963. Adobe PDF namespace tags. The official XMP specification defines only
  964. Keywords, PDFVersion, Producer and Trapped. The other tags are included
  965. because they have been observed in PDF files, but some are avoided when
  966. writing due to name conflicts with other XMP namespaces.
  967. },
  968. Author => { Groups => { 2 => 'Author' } }, #PH
  969. ModDate => { Groups => { 2 => 'Time' }, %dateTimeInfo }, #PH
  970. CreationDate=> { Groups => { 2 => 'Time' }, %dateTimeInfo }, #PH
  971. Creator => { Groups => { 2 => 'Author' }, Avoid => 1 },
  972. Copyright => { Groups => { 2 => 'Author' }, Avoid => 1 }, #PH
  973. Marked => { Avoid => 1, Writable => 'boolean' }, #PH
  974. Subject => { Avoid => 1 },
  975. Title => { Avoid => 1 },
  976. Trapped => { #PH
  977. # remove leading '/' from '/True' or '/False'
  978. ValueConv => '$val=~s{^/}{}; $val',
  979. ValueConvInv => '"/$val"',
  980. PrintConv => { True => 'True', False => 'False', Unknown => 'Unknown' },
  981. },
  982. Keywords => { Priority => 0 },
  983. PDFVersion => { },
  984. Producer => { Groups => { 2 => 'Author' } },
  985. );
  986. # PDF extension namespace properties (pdfx)
  987. %Image::ExifTool::XMP::pdfx = (
  988. %xmpTableDefaults,
  989. GROUPS => { 1 => 'XMP-pdfx', 2 => 'Document' },
  990. NAMESPACE => 'pdfx',
  991. NOTES => q{
  992. PDF extension tags. This namespace is used to store application-defined PDF
  993. information, so there are no pre-defined tags. User-defined tags must be
  994. created to enable writing of XMP-pdfx information.
  995. },
  996. );
  997. # Photoshop namespace properties (photoshop)
  998. %Image::ExifTool::XMP::photoshop = (
  999. %xmpTableDefaults,
  1000. GROUPS => { 1 => 'XMP-photoshop', 2 => 'Image' },
  1001. NAMESPACE => 'photoshop',
  1002. TABLE_DESC => 'XMP Photoshop',
  1003. NOTES => 'Adobe Photoshop namespace tags.',
  1004. AuthorsPosition => { Groups => { 2 => 'Author' } },
  1005. CaptionWriter => { Groups => { 2 => 'Author' } },
  1006. Category => { },
  1007. City => { Groups => { 2 => 'Location' } },
  1008. ColorMode => {
  1009. Writable => 'integer', # (as of July 2010 spec, courtesy of yours truly)
  1010. PrintConvColumns => 2,
  1011. PrintConv => {
  1012. 0 => 'Bitmap',
  1013. 1 => 'Grayscale',
  1014. 2 => 'Indexed',
  1015. 3 => 'RGB',
  1016. 4 => 'CMYK',
  1017. 7 => 'Multichannel',
  1018. 8 => 'Duotone',
  1019. 9 => 'Lab',
  1020. },
  1021. },
  1022. Country => { Groups => { 2 => 'Location' } },
  1023. Credit => { Groups => { 2 => 'Author' } },
  1024. DateCreated => { Groups => { 2 => 'Time' }, %dateTimeInfo },
  1025. DocumentAncestors => {
  1026. List => 'Bag',
  1027. # Contrary to their own XMP specification, Adobe writes this as a simple Bag
  1028. # of strings instead of structures, so comment out the structure definition...
  1029. # FlatName => 'Document',
  1030. # Struct => {
  1031. # STRUCT_NAME => 'Ancestor',
  1032. # NAMESPACE => 'photoshop',
  1033. # AncestorID => { },
  1034. # },
  1035. },
  1036. Headline => { },
  1037. History => { }, #PH (CS3)
  1038. ICCProfile => { Name => 'ICCProfileName' }, #PH
  1039. Instructions => { },
  1040. LegacyIPTCDigest=> { }, #PH
  1041. SidecarForExtension => { }, #PH (CS3)
  1042. Source => { Groups => { 2 => 'Author' } },
  1043. State => { Groups => { 2 => 'Location' } },
  1044. # the XMP spec doesn't show SupplementalCategories as a 'Bag', but
  1045. # that's the way Photoshop writes it [fixed in the June 2005 XMP spec].
  1046. # Also, it is incorrectly listed as "SupplementalCategory" in the
  1047. # IPTC Standard Photo Metadata docs (2008rev2 and July 2009rev1) - PH
  1048. SupplementalCategories => { List => 'Bag' },
  1049. TextLayers => {
  1050. FlatName => 'Text',
  1051. List => 'Seq',
  1052. Struct => {
  1053. STRUCT_NAME => 'Layer',
  1054. NAMESPACE => 'photoshop',
  1055. LayerName => { },
  1056. LayerText => { },
  1057. },
  1058. },
  1059. TransmissionReference => { },
  1060. Urgency => {
  1061. Writable => 'integer',
  1062. Notes => 'should be in the range 1-8 to conform with the XMP spec',
  1063. PrintConv => { # (same values as IPTC:Urgency)
  1064. 0 => '0 (reserved)', # (not standard XMP)
  1065. 1 => '1 (most urgent)',
  1066. 2 => 2,
  1067. 3 => 3,
  1068. 4 => 4,
  1069. 5 => '5 (normal urgency)',
  1070. 6 => 6,
  1071. 7 => 7,
  1072. 8 => '8 (least urgent)',
  1073. 9 => '9 (user-defined priority)', # (not standard XMP)
  1074. },
  1075. },
  1076. EmbeddedXMPDigest => { }, #PH (LR5)
  1077. );
  1078. # Photoshop Camera Raw namespace properties (crs) - (ref 8,PH)
  1079. %Image::ExifTool::XMP::crs = (
  1080. %xmpTableDefaults,
  1081. GROUPS => { 1 => 'XMP-crs', 2 => 'Image' },
  1082. NAMESPACE => 'crs',
  1083. TABLE_DESC => 'Photoshop Camera Raw namespace',
  1084. NOTES => q{
  1085. Photoshop Camera Raw namespace tags. It is a shame that Adobe pollutes the
  1086. metadata space with these incredibly bulky image editing parameters.
  1087. },
  1088. AlreadyApplied => { Writable => 'boolean' }, #PH (written by LightRoom beta 4.1)
  1089. AutoBrightness => { Writable => 'boolean' },
  1090. AutoContrast => { Writable => 'boolean' },
  1091. AutoExposure => { Writable => 'boolean' },
  1092. AutoShadows => { Writable => 'boolean' },
  1093. BlueHue => { Writable => 'integer' },
  1094. BlueSaturation => { Writable => 'integer' },
  1095. Brightness => { Writable => 'integer' },
  1096. CameraProfile => { },
  1097. ChromaticAberrationB=> { Writable => 'integer' },
  1098. ChromaticAberrationR=> { Writable => 'integer' },
  1099. ColorNoiseReduction => { Writable => 'integer' },
  1100. Contrast => { Writable => 'integer', Avoid => 1 },
  1101. Converter => { }, #PH guess (found in EXIF)
  1102. CropTop => { Writable => 'real' },
  1103. CropLeft => { Writable => 'real' },
  1104. CropBottom => { Writable => 'real' },
  1105. CropRight => { Writable => 'real' },
  1106. CropAngle => { Writable => 'real' },
  1107. CropWidth => { Writable => 'real' },
  1108. CropHeight => { Writable => 'real' },
  1109. CropUnits => {
  1110. Writable => 'integer',
  1111. PrintConv => {
  1112. 0 => 'pixels',
  1113. 1 => 'inches',
  1114. 2 => 'cm',
  1115. },
  1116. },
  1117. Exposure => { Writable => 'real' },
  1118. GreenHue => { Writable => 'integer' },
  1119. GreenSaturation => { Writable => 'integer' },
  1120. HasCrop => { Writable => 'boolean' },
  1121. HasSettings => { Writable => 'boolean' },
  1122. LuminanceSmoothing => { Writable => 'integer' },
  1123. MoireFilter => { PrintConv => { Off=>'Off', On=>'On' } },
  1124. RawFileName => { },
  1125. RedHue => { Writable => 'integer' },
  1126. RedSaturation => { Writable => 'integer' },
  1127. Saturation => { Writable => 'integer', Avoid => 1 },
  1128. Shadows => { Writable => 'integer' },
  1129. ShadowTint => { Writable => 'integer' },
  1130. Sharpness => { Writable => 'integer', Avoid => 1 },
  1131. Smoothness => { Writable => 'integer' },
  1132. Temperature => { Writable => 'integer', Avoid => 1, Name => 'ColorTemperature' },
  1133. Tint => { Writable => 'integer' },
  1134. ToneCurve => { List => 'Seq' },
  1135. ToneCurveName => {
  1136. PrintConv => {
  1137. Linear => 'Linear',
  1138. 'Medium Contrast' => 'Medium Contrast',
  1139. 'Strong Contrast' => 'Strong Contrast',
  1140. Custom => 'Custom',
  1141. },
  1142. },
  1143. Version => { },
  1144. VignetteAmount => { Writable => 'integer' },
  1145. VignetteMidpoint=> { Writable => 'integer' },
  1146. WhiteBalance => {
  1147. Avoid => 1,
  1148. PrintConv => {
  1149. 'As Shot' => 'As Shot',
  1150. Auto => 'Auto',
  1151. Daylight => 'Daylight',
  1152. Cloudy => 'Cloudy',
  1153. Shade => 'Shade',
  1154. Tungsten => 'Tungsten',
  1155. Fluorescent => 'Fluorescent',
  1156. Flash => 'Flash',
  1157. Custom => 'Custom',
  1158. },
  1159. },
  1160. # new tags observed in Adobe Lightroom output - PH
  1161. CameraProfileDigest => { },
  1162. Clarity => { Writable => 'integer' },
  1163. ConvertToGrayscale => { Writable => 'boolean' },
  1164. Defringe => { Writable => 'integer' },
  1165. FillLight => { Writable => 'integer' },
  1166. HighlightRecovery => { Writable => 'integer' },
  1167. HueAdjustmentAqua => { Writable => 'integer' },
  1168. HueAdjustmentBlue => { Writable => 'integer' },
  1169. HueAdjustmentGreen => { Writable => 'integer' },
  1170. HueAdjustmentMagenta => { Writable => 'integer' },
  1171. HueAdjustmentOrange => { Writable => 'integer' },
  1172. HueAdjustmentPurple => { Writable => 'integer' },
  1173. HueAdjustmentRed => { Writable => 'integer' },
  1174. HueAdjustmentYellow => { Writable => 'integer' },
  1175. IncrementalTemperature => { Writable => 'integer' },
  1176. IncrementalTint => { Writable => 'integer' },
  1177. LuminanceAdjustmentAqua => { Writable => 'integer' },
  1178. LuminanceAdjustmentBlue => { Writable => 'integer' },
  1179. LuminanceAdjustmentGreen => { Writable => 'integer' },
  1180. LuminanceAdjustmentMagenta => { Writable => 'integer' },
  1181. LuminanceAdjustmentOrange => { Writable => 'integer' },
  1182. LuminanceAdjustmentPurple => { Writable => 'integer' },
  1183. LuminanceAdjustmentRed => { Writable => 'integer' },
  1184. LuminanceAdjustmentYellow => { Writable => 'integer' },
  1185. ParametricDarks => { Writable => 'integer' },
  1186. ParametricHighlights => { Writable => 'integer' },
  1187. ParametricHighlightSplit => { Writable => 'integer' },
  1188. ParametricLights => { Writable => 'integer' },
  1189. ParametricMidtoneSplit => { Writable => 'integer' },
  1190. ParametricShadows => { Writable => 'integer' },
  1191. ParametricShadowSplit => { Writable => 'integer' },
  1192. SaturationAdjustmentAqua => { Writable => 'integer' },
  1193. SaturationAdjustmentBlue => { Writable => 'integer' },
  1194. SaturationAdjustmentGreen => { Writable => 'integer' },
  1195. SaturationAdjustmentMagenta => { Writable => 'integer' },
  1196. SaturationAdjustmentOrange => { Writable => 'integer' },
  1197. SaturationAdjustmentPurple => { Writable => 'integer' },
  1198. SaturationAdjustmentRed => { Writable => 'integer' },
  1199. SaturationAdjustmentYellow => { Writable => 'integer' },
  1200. SharpenDetail => { Writable => 'integer' },
  1201. SharpenEdgeMasking => { Writable => 'integer' },
  1202. SharpenRadius => { Writable => 'real' },
  1203. SplitToningBalance => { Writable => 'integer' },
  1204. SplitToningHighlightHue => { Writable => 'integer' },
  1205. SplitToningHighlightSaturation => { Writable => 'integer' },
  1206. SplitToningShadowHue => { Writable => 'integer' },
  1207. SplitToningShadowSaturation => { Writable => 'integer' },
  1208. Vibrance => { Writable => 'integer' },
  1209. # new tags written by LR 1.4 (not sure in what version they first appeared)
  1210. GrayMixerRed => { Writable => 'integer' },
  1211. GrayMixerOrange => { Writable => 'integer' },
  1212. GrayMixerYellow => { Writable => 'integer' },
  1213. GrayMixerGreen => { Writable => 'integer' },
  1214. GrayMixerAqua => { Writable => 'integer' },
  1215. GrayMixerBlue => { Writable => 'integer' },
  1216. GrayMixerPurple => { Writable => 'integer' },
  1217. GrayMixerMagenta => { Writable => 'integer' },
  1218. RetouchInfo => { List => 'Seq' },
  1219. RedEyeInfo => { List => 'Seq' },
  1220. # new tags written by LR 2.0 (ref PH)
  1221. CropUnit => { # was the XMP documentation wrong with "CropUnits"??
  1222. Writable => 'integer',
  1223. PrintConv => {
  1224. 0 => 'pixels',
  1225. 1 => 'inches',
  1226. 2 => 'cm',
  1227. # have seen a value of 3 here! - PH
  1228. },
  1229. },
  1230. PostCropVignetteAmount => { Writable => 'integer' },
  1231. PostCropVignetteMidpoint => { Writable => 'integer' },
  1232. PostCropVignetteFeather => { Writable => 'integer' },
  1233. PostCropVignetteRoundness => { Writable => 'integer' },
  1234. PostCropVignetteStyle => { Writable => 'integer' },
  1235. # disable List behaviour of flattened Gradient/PaintBasedCorrections
  1236. # because these are nested in lists and the flattened tags can't
  1237. # do justice to this complex structure
  1238. GradientBasedCorrections => {
  1239. FlatName => 'GradientBasedCorr',
  1240. Struct => \%sCorrection,
  1241. List => 'Seq',
  1242. },
  1243. GradientBasedCorrectionsCorrectionMasks => {
  1244. Name => 'GradientBasedCorrMasks',
  1245. FlatName => 'GradientBasedCorrMask',
  1246. Flat => 1
  1247. },
  1248. GradientBasedCorrectionsCorrectionMasksDabs => {
  1249. Name => 'GradientBasedCorrMaskDabs',
  1250. Flat => 1, List => 0,
  1251. },
  1252. PaintBasedCorrections => {
  1253. FlatName => 'PaintCorrection',
  1254. Struct => \%sCorrection,
  1255. List => 'Seq',
  1256. },
  1257. PaintBasedCorrectionsCorrectionMasks => {
  1258. Name => 'PaintBasedCorrectionMasks',
  1259. FlatName => 'PaintCorrectionMask',
  1260. Flat => 1,
  1261. },
  1262. PaintBasedCorrectionsCorrectionMasksDabs => {
  1263. Name => 'PaintCorrectionMaskDabs',
  1264. Flat => 1, List => 0,
  1265. },
  1266. # new tags written by LR 3 (thanks Wolfgang Guelcker)
  1267. ProcessVersion => { },
  1268. LensProfileEnable => { Writable => 'integer' },
  1269. LensProfileSetup => { },
  1270. LensProfileName => { },
  1271. LensProfileFilename => { },
  1272. LensProfileDigest => { },
  1273. LensProfileDistortionScale => { Writable => 'integer' },
  1274. LensProfileChromaticAberrationScale => { Writable => 'integer' },
  1275. LensProfileVignettingScale => { Writable => 'integer' },
  1276. LensManualDistortionAmount => { Writable => 'integer' },
  1277. PerspectiveVertical => { Writable => 'integer' },
  1278. PerspectiveHorizontal => { Writable => 'integer' },
  1279. PerspectiveRotate => { Writable => 'real' },
  1280. PerspectiveScale => { Writable => 'integer' },
  1281. CropConstrainToWarp => { Writable => 'integer' },
  1282. LuminanceNoiseReductionDetail => { Writable => 'integer' },
  1283. LuminanceNoiseReductionContrast => { Writable => 'integer' },
  1284. ColorNoiseReductionDetail => { Writable => 'integer' },
  1285. GrainAmount => { Writable => 'integer' },
  1286. GrainSize => { Writable => 'integer' },
  1287. GrainFrequency => { Writable => 'integer' },
  1288. # new tags written by LR4
  1289. AutoLateralCA => { Writable => 'integer' },
  1290. Exposure2012 => { Writable => 'real' },
  1291. Contrast2012 => { Writable => 'integer' },
  1292. Highlights2012 => { Writable => 'integer' },
  1293. Shadows2012 => { Writable => 'integer' },
  1294. Whites2012 => { Writable => 'integer' },
  1295. Blacks2012 => { Writable => 'integer' },
  1296. Clarity2012 => { Writable => 'integer' },
  1297. PostCropVignetteHighlightContrast => { Writable => 'integer' },
  1298. ToneCurveName2012 => { },
  1299. ToneCurveRed => { List => 'Seq' },
  1300. ToneCurveGreen => { List => 'Seq' },
  1301. ToneCurveBlue => { List => 'Seq' },
  1302. ToneCurvePV2012 => { List => 'Seq' },
  1303. ToneCurvePV2012Red => { List => 'Seq' },
  1304. ToneCurvePV2012Green => { List => 'Seq' },
  1305. ToneCurvePV2012Blue => { List => 'Seq' },
  1306. DefringePurpleAmount => { Writable => 'integer' },
  1307. DefringePurpleHueLo => { Writable => 'integer' },
  1308. DefringePurpleHueHi => { Writable => 'integer' },
  1309. DefringeGreenAmount => { Writable => 'integer' },
  1310. DefringeGreenHueLo => { Writable => 'integer' },
  1311. DefringeGreenHueHi => { Writable => 'integer' },
  1312. # new tags written by LR5
  1313. AutoWhiteVersion => { Writable => 'integer' },
  1314. CircularGradientBasedCorrections => {
  1315. FlatName => 'CircGradBasedCorr',
  1316. Struct => \%sCorrection,
  1317. List => 'Seq',
  1318. },
  1319. CircularGradientBasedCorrectionsCorrectionMasks => {
  1320. Name => 'CircGradBasedCorrMasks',
  1321. FlatName => 'CircGradBasedCorrMask',
  1322. Flat => 1
  1323. },
  1324. CircularGradientBasedCorrectionsCorrectionMasksDabs => {
  1325. Name => 'CircGradBasedCorrMaskDabs',
  1326. Flat => 1, List => 0,
  1327. },
  1328. ColorNoiseReductionSmoothness => { Writable => 'integer' },
  1329. PerspectiveAspect => { Writable => 'integer' },
  1330. PerspectiveUpright => { Writable => 'integer' },
  1331. RetouchAreas => {
  1332. FlatName => 'RetouchArea',
  1333. Struct => \%sRetouchArea,
  1334. List => 'Seq',
  1335. },
  1336. RetouchAreasMasks => {
  1337. Name => 'RetouchAreaMasks',
  1338. FlatName => 'RetouchAreaMask',
  1339. Flat => 1
  1340. },
  1341. RetouchAreasMasksDabs => {
  1342. Name => 'RetouchAreaMaskDabs',
  1343. Flat => 1, List => 0,
  1344. },
  1345. UprightVersion => { Writable => 'integer' },
  1346. UprightCenterMode => { Writable => 'integer' },
  1347. UprightCenterNormX => { Writable => 'real' },
  1348. UprightCenterNormY => { Writable => 'real' },
  1349. UprightFocalMode => { Writable => 'integer' },
  1350. UprightFocalLength35mm => { Writable => 'real' },
  1351. UprightPreview => { Writable => 'boolean' },
  1352. UprightTransformCount => { Writable => 'integer' },
  1353. UprightDependentDigest => { },
  1354. UprightTransform_0 => { },
  1355. UprightTransform_1 => { },
  1356. UprightTransform_2 => { },
  1357. UprightTransform_3 => { },
  1358. UprightTransform_4 => { },
  1359. # more stuff seen in lens profile file (unknown source)
  1360. What => { }, # (with value "LensProfileDefaultSettings")
  1361. LensProfileMatchKeyExifMake => { },
  1362. LensProfileMatchKeyExifModel => { },
  1363. LensProfileMatchKeyCameraModelName => { },
  1364. LensProfileMatchKeyLensInfo => { },
  1365. LensProfileMatchKeyLensID => { },
  1366. LensProfileMatchKeyLensName => { },
  1367. LensProfileMatchKeyIsRaw => { Writable => 'boolean' },
  1368. LensProfileMatchKeySensorFormatFactor=>{ Writable => 'real' },
  1369. );
  1370. # Tiff namespace properties (tiff)
  1371. %Image::ExifTool::XMP::tiff = (
  1372. %xmpTableDefaults,
  1373. GROUPS => { 1 => 'XMP-tiff', 2 => 'Image' },
  1374. NAMESPACE => 'tiff',
  1375. PRIORITY => 0, # not as reliable as actual TIFF tags
  1376. TABLE_DESC => 'XMP TIFF',
  1377. NOTES => q{
  1378. EXIF namespace for TIFF tags. See
  1379. L<http://www.cipa.jp/std/documents/e/DC-010-2012_E.pdf> for the
  1380. specification.
  1381. },
  1382. ImageWidth => { Writable => 'integer' },
  1383. ImageLength => { Writable => 'integer', Name => 'ImageHeight' },
  1384. BitsPerSample => { Writable => 'integer', List => 'Seq', AutoSplit => 1 },
  1385. Compression => {
  1386. Writable => 'integer',
  1387. SeparateTable => 'EXIF Compression',
  1388. PrintConv => \%Image::ExifTool::Exif::compression,
  1389. },
  1390. PhotometricInterpretation => {
  1391. Writable => 'integer',
  1392. PrintConv => \%Image::ExifTool::Exif::photometricInterpretation,
  1393. },
  1394. Orientation => {
  1395. Writable => 'integer',
  1396. PrintConv => \%Image::ExifTool::Exif::orientation,
  1397. },
  1398. SamplesPerPixel => { Writable => 'integer' },
  1399. PlanarConfiguration => {
  1400. Writable => 'integer',
  1401. PrintConv => {
  1402. 1 => 'Chunky',
  1403. 2 => 'Planar',
  1404. },
  1405. },
  1406. YCbCrSubSampling => {
  1407. Writable => 'integer',
  1408. List => 'Seq',
  1409. # join the raw values before conversion to allow PrintConv to operate on
  1410. # the combined string as it does for the corresponding EXIF tag
  1411. RawJoin => 1,
  1412. Notes => q{
  1413. while technically this is a list-type tag, for compatibility with its EXIF
  1414. counterpart it is written and read as a simple string
  1415. },
  1416. PrintConv => \%Image::ExifTool::JPEG::yCbCrSubSampling,
  1417. },
  1418. YCbCrPositioning => {
  1419. Writable => 'integer',
  1420. PrintConv => {
  1421. 1 => 'Centered',
  1422. 2 => 'Co-sited',
  1423. },
  1424. },
  1425. XResolution => { Writable => 'rational' },
  1426. YResolution => { Writable => 'rational' },
  1427. ResolutionUnit => {
  1428. Writable => 'integer',
  1429. Notes => 'the value 1 is not standard EXIF',
  1430. PrintConv => {
  1431. 1 => 'None',
  1432. 2 => 'inches',
  1433. 3 => 'cm',
  1434. },
  1435. },
  1436. TransferFunction => { Writable => 'integer', List => 'Seq', AutoSplit => 1 },
  1437. WhitePoint => { Writable => 'rational', List => 'Seq', AutoSplit => 1 },
  1438. PrimaryChromaticities => { Writable => 'rational', List => 'Seq', AutoSplit => 1 },
  1439. YCbCrCoefficients => { Writable => 'rational', List => 'Seq', AutoSplit => 1 },
  1440. ReferenceBlackWhite => { Writable => 'rational', List => 'Seq', AutoSplit => 1 },
  1441. DateTime => { # (EXIF tag named ModifyDate, but this exists in XMP-xmp)
  1442. Description => 'Date/Time Modified',
  1443. Groups => { 2 => 'Time' },
  1444. %dateTimeInfo,
  1445. },
  1446. ImageDescription => { Writable => 'lang-alt' },
  1447. Make => {
  1448. Groups => { 2 => 'Camera' },
  1449. RawConv => '$$self{Make} ? $val : $$self{Make} = $val',
  1450. },
  1451. Model => {
  1452. Groups => { 2 => 'Camera' },
  1453. Description => 'Camera Model Name',
  1454. RawConv => '$$self{Model} ? $val : $$self{Model} = $val',
  1455. },
  1456. Software => { },
  1457. Artist => { Groups => { 2 => 'Author' } },
  1458. Copyright => { Groups => { 2 => 'Author' }, Writable => 'lang-alt' },
  1459. NativeDigest => { }, #PH
  1460. );
  1461. # Exif namespace properties (exif)
  1462. %Image::ExifTool::XMP::exif = (
  1463. %xmpTableDefaults,
  1464. GROUPS => { 1 => 'XMP-exif', 2 => 'Image' },
  1465. NAMESPACE => 'exif',
  1466. PRIORITY => 0, # not as reliable as actual EXIF tags
  1467. NOTES => q{
  1468. EXIF namespace for EXIF tags. See
  1469. L<http://www.cipa.jp/std/documents/e/DC-010-2012_E.pdf> for the
  1470. specification.
  1471. },
  1472. ExifVersion => { },
  1473. FlashpixVersion => { },
  1474. ColorSpace => {
  1475. Writable => 'integer',
  1476. # (some applications incorrectly write -1 as a long integer)
  1477. ValueConv => '$val == 0xffffffff ? 0xffff : $val',
  1478. ValueConvInv => '$val',
  1479. PrintConv => {
  1480. 1 => 'sRGB',
  1481. 2 => 'Adobe RGB',
  1482. 0xffff => 'Uncalibrated',
  1483. },
  1484. },
  1485. ComponentsConfiguration => {
  1486. Writable => 'integer',
  1487. List => 'Seq',
  1488. AutoSplit => 1,
  1489. PrintConvColumns => 2,
  1490. PrintConv => {
  1491. 0 => '-',
  1492. 1 => 'Y',
  1493. 2 => 'Cb',
  1494. 3 => 'Cr',
  1495. 4 => 'R',
  1496. 5 => 'G',
  1497. 6 => 'B',
  1498. },
  1499. },
  1500. CompressedBitsPerPixel => { Writable => 'rational' },
  1501. PixelXDimension => { Name => 'ExifImageWidth', Writable => 'integer' },
  1502. PixelYDimension => { Name => 'ExifImageHeight', Writable => 'integer' },
  1503. MakerNote => { },
  1504. UserComment => { Writable => 'lang-alt' },
  1505. RelatedSoundFile => { },
  1506. DateTimeOriginal => {
  1507. Description => 'Date/Time Original',
  1508. Groups => { 2 => 'Time' },
  1509. %dateTimeInfo,
  1510. },
  1511. DateTimeDigitized => { # (EXIF tag named CreateDate, but this exists in XMP-xmp)
  1512. Description => 'Date/Time Digitized',
  1513. Groups => { 2 => 'Time' },
  1514. %dateTimeInfo,
  1515. },
  1516. ExposureTime => {
  1517. Writable => 'rational',
  1518. PrintConv => 'Image::ExifTool::Exif::PrintExposureTime($val)',
  1519. PrintConvInv => 'Image::ExifTool::Exif::ConvertFraction($val)',
  1520. },
  1521. FNumber => {
  1522. Writable => 'rational',
  1523. PrintConv => 'Image::ExifTool::Exif::PrintFNumber($val)',
  1524. PrintConvInv => '$val',
  1525. },
  1526. ExposureProgram => {
  1527. Groups => { 2 => 'Camera' },
  1528. Writable => 'integer',
  1529. PrintConv => {
  1530. 0 => 'Not Defined',
  1531. 1 => 'Manual',
  1532. 2 => 'Program AE',
  1533. 3 => 'Aperture-priority AE',
  1534. 4 => 'Shutter speed priority AE',
  1535. 5 => 'Creative (Slow speed)',
  1536. 6 => 'Action (High speed)',
  1537. 7 => 'Portrait',
  1538. 8 => 'Landscape',
  1539. },
  1540. },
  1541. SpectralSensitivity => { Groups => { 2 => 'Camera' } },
  1542. ISOSpeedRatings => {
  1543. Name => 'ISO',
  1544. Writable => 'integer',
  1545. List => 'Seq',
  1546. AutoSplit => 1,
  1547. },
  1548. OECF => {
  1549. Name => 'Opto-ElectricConvFactor',
  1550. FlatName => 'OECF',
  1551. Groups => { 2 => 'Camera' },
  1552. Struct => \%sOECF,
  1553. },
  1554. ShutterSpeedValue => {
  1555. Writable => 'rational',
  1556. ValueConv => 'abs($val)<100 ? 1/(2**$val) : 0',
  1557. PrintConv => 'Image::ExifTool::Exif::PrintExposureTime($val)',
  1558. ValueConvInv => '$val>0 ? -log($val)/log(2) : 0',
  1559. PrintConvInv => 'Image::ExifTool::Exif::ConvertFraction($val)',
  1560. },
  1561. ApertureValue => {
  1562. Writable => 'rational',
  1563. ValueConv => 'sqrt(2) ** $val',
  1564. PrintConv => 'sprintf("%.1f",$val)',
  1565. ValueConvInv => '$val>0 ? 2*log($val)/log(2) : 0',
  1566. PrintConvInv => '$val',
  1567. },
  1568. BrightnessValue => { Writable => 'rational' },
  1569. ExposureBiasValue => {
  1570. Name => 'ExposureCompensation',
  1571. Writable => 'rational',
  1572. PrintConv => 'Image::ExifTool::Exif::PrintFraction($val)',
  1573. PrintConvInv => 'Image::ExifTool::Exif::ConvertFraction($val)',
  1574. },
  1575. MaxApertureValue => {
  1576. Groups => { 2 => 'Camera' },
  1577. Writable => 'rational',
  1578. ValueConv => 'sqrt(2) ** $val',
  1579. PrintConv => 'sprintf("%.1f",$val)',
  1580. ValueConvInv => '$val>0 ? 2*log($val)/log(2) : 0',
  1581. PrintConvInv => '$val',
  1582. },
  1583. SubjectDistance => {
  1584. Groups => { 2 => 'Camera' },
  1585. Writable => 'rational',
  1586. PrintConv => '$val =~ /^(inf|undef)$/ ? $val : "$val m"',
  1587. PrintConvInv => '$val=~s/\s*m$//;$val',
  1588. },
  1589. MeteringMode => {
  1590. Groups => { 2 => 'Camera' },
  1591. Writable => 'integer',
  1592. PrintConv => {
  1593. 1 => 'Average',
  1594. 2 => 'Center-weighted average',
  1595. 3 => 'Spot',
  1596. 4 => 'Multi-spot',
  1597. 5 => 'Multi-segment',
  1598. 6 => 'Partial',
  1599. 255 => 'Other',
  1600. },
  1601. },
  1602. LightSource => {
  1603. Groups => { 2 => 'Camera' },
  1604. SeparateTable => 'EXIF LightSource',
  1605. PrintConv => \%Image::ExifTool::Exif::lightSource,
  1606. },
  1607. Flash => {
  1608. Groups => { 2 => 'Camera' },
  1609. Struct => {
  1610. STRUCT_NAME => 'Flash',
  1611. NAMESPACE => 'exif',
  1612. Fired => { Writable => 'boolean', %boolConv },
  1613. Return => {
  1614. Writable => 'integer',
  1615. PrintConv => {
  1616. 0 => 'No return detection',
  1617. 2 => 'Return not detected',
  1618. 3 => 'Return detected',
  1619. },
  1620. },
  1621. Mode => {
  1622. Writable => 'integer',
  1623. PrintConv => {
  1624. 0 => 'Unknown',
  1625. 1 => 'On',
  1626. 2 => 'Off',
  1627. 3 => 'Auto',
  1628. },
  1629. },
  1630. Function => { Writable => 'boolean', %boolConv },
  1631. RedEyeMode => { Writable => 'boolean', %boolConv },
  1632. },
  1633. },
  1634. FocalLength=> {
  1635. Groups => { 2 => 'Camera' },
  1636. Writable => 'rational',
  1637. PrintConv => 'sprintf("%.1f mm",$val)',
  1638. PrintConvInv => '$val=~s/\s*mm$//;$val',
  1639. },
  1640. SubjectArea => { Writable => 'integer', List => 'Seq', AutoSplit => 1 },
  1641. FlashEnergy => { Groups => { 2 => 'Camera' }, Writable => 'rational' },
  1642. SpatialFrequencyResponse => {
  1643. Groups => { 2 => 'Camera' },
  1644. Struct => \%sOECF,
  1645. },
  1646. FocalPlaneXResolution => { Groups => { 2 => 'Camera' }, Writable => 'rational' },
  1647. FocalPlaneYResolution => { Groups => { 2 => 'Camera' }, Writable => 'rational' },
  1648. FocalPlaneResolutionUnit => {
  1649. Groups => { 2 => 'Camera' },
  1650. Writable => 'integer',
  1651. Notes => 'values 1, 4 and 5 are not standard EXIF',
  1652. PrintConv => {
  1653. 1 => 'None', # (not standard EXIF)
  1654. 2 => 'inches',
  1655. 3 => 'cm',
  1656. 4 => 'mm', # (not standard EXIF)
  1657. 5 => 'um', # (not standard EXIF)
  1658. },
  1659. },
  1660. SubjectLocation => { Writable => 'integer', List => 'Seq', AutoSplit => 1 },
  1661. ExposureIndex => { Writable => 'rational' },
  1662. SensingMethod => {
  1663. Groups => { 2 => 'Camera' },
  1664. Writable => 'integer',
  1665. Notes => 'values 1 and 6 are not standard EXIF',
  1666. PrintConv => {
  1667. 1 => 'Monochrome area', # (not standard EXIF)
  1668. 2 => 'One-chip color area',
  1669. 3 => 'Two-chip color area',
  1670. 4 => 'Three-chip color area',
  1671. 5 => 'Color sequential area',
  1672. 6 => 'Monochrome linear', # (not standard EXIF)
  1673. 7 => 'Trilinear',
  1674. 8 => 'Color sequential linear',
  1675. },
  1676. },
  1677. FileSource => {
  1678. Writable => 'integer',
  1679. PrintConv => {
  1680. 1 => 'Film Scanner',
  1681. 2 => 'Reflection Print Scanner',
  1682. 3 => 'Digital Camera',
  1683. }
  1684. },
  1685. SceneType => { Writable => 'integer', PrintConv => { 1 => 'Directly photographed' } },
  1686. CFAPattern => {
  1687. Struct => {
  1688. STRUCT_NAME => 'CFAPattern',
  1689. NAMESPACE => 'exif',
  1690. Columns => { Writable => 'integer' },
  1691. Rows => { Writable => 'integer' },
  1692. Values => { Writable => 'integer', List => 'Seq' },
  1693. },
  1694. },
  1695. CustomRendered => {
  1696. Writable => 'integer',
  1697. PrintConv => {
  1698. 0 => 'Normal',
  1699. 1 => 'Custom',
  1700. },
  1701. },
  1702. ExposureMode => {
  1703. Groups => { 2 => 'Camera' },
  1704. Writable => 'integer',
  1705. PrintConv => {
  1706. 0 => 'Auto',
  1707. 1 => 'Manual',
  1708. 2 => 'Auto bracket',
  1709. },
  1710. },
  1711. WhiteBalance => {
  1712. Groups => { 2 => 'Camera' },
  1713. Writable => 'integer',
  1714. PrintConv => {
  1715. 0 => 'Auto',
  1716. 1 => 'Manual',
  1717. },
  1718. },
  1719. DigitalZoomRatio => { Writable => 'rational' },
  1720. FocalLengthIn35mmFilm => {
  1721. Name => 'FocalLengthIn35mmFormat',
  1722. Writable => 'integer',
  1723. Groups => { 2 => 'Camera' },
  1724. PrintConv => '"$val mm"',
  1725. PrintConvInv => '$val=~s/\s*mm$//;$val',
  1726. },
  1727. SceneCaptureType => {
  1728. Groups => { 2 => 'Camera' },
  1729. Writable => 'integer',
  1730. PrintConv => {
  1731. 0 => 'Standard',
  1732. 1 => 'Landscape',
  1733. 2 => 'Portrait',
  1734. 3 => 'Night',
  1735. },
  1736. },
  1737. GainControl => {
  1738. Groups => { 2 => 'Camera' },
  1739. Writable => 'integer',
  1740. PrintConv => {
  1741. 0 => 'None',
  1742. 1 => 'Low gain up',
  1743. 2 => 'High gain up',
  1744. 3 => 'Low gain down',
  1745. 4 => 'High gain down',
  1746. },
  1747. },
  1748. Contrast => {
  1749. Groups => { 2 => 'Camera' },
  1750. Writable => 'integer',
  1751. PrintConv => {
  1752. 0 => 'Normal',
  1753. 1 => 'Low',
  1754. 2 => 'High',
  1755. },
  1756. PrintConvInv => 'Image::ExifTool::Exif::ConvertParameter($val)',
  1757. },
  1758. Saturation => {
  1759. Groups => { 2 => 'Camera' },
  1760. Writable => 'integer',
  1761. PrintConv => {
  1762. 0 => 'Normal',
  1763. 1 => 'Low',
  1764. 2 => 'High',
  1765. },
  1766. PrintConvInv => 'Image::ExifTool::Exif::ConvertParameter($val)',
  1767. },
  1768. Sharpness => {
  1769. Groups => { 2 => 'Camera' },
  1770. Writable => 'integer',
  1771. PrintConv => {
  1772. 0 => 'Normal',
  1773. 1 => 'Soft',
  1774. 2 => 'Hard',
  1775. },
  1776. PrintConvInv => 'Image::ExifTool::Exif::ConvertParameter($val)',
  1777. },
  1778. DeviceSettingDescription => {
  1779. Groups => { 2 => 'Camera' },
  1780. Struct => {
  1781. STRUCT_NAME => 'DeviceSettings',
  1782. NAMESPACE => 'exif',
  1783. Columns => { Writable => 'integer' },
  1784. Rows => { Writable => 'integer' },
  1785. Settings => { List => 'Seq' },
  1786. },
  1787. },
  1788. SubjectDistanceRange => {
  1789. Groups => { 2 => 'Camera' },
  1790. Writable => 'integer',
  1791. PrintConv => {
  1792. 0 => 'Unknown',
  1793. 1 => 'Macro',
  1794. 2 => 'Close',
  1795. 3 => 'Distant',
  1796. },
  1797. },
  1798. ImageUniqueID => { },
  1799. GPSVersionID => { Groups => { 2 => 'Location' } },
  1800. GPSLatitude => { Groups => { 2 => 'Location' }, %latConv },
  1801. GPSLongitude => { Groups => { 2 => 'Location' }, %longConv },
  1802. GPSAltitudeRef => {
  1803. Groups => { 2 => 'Location' },
  1804. Writable => 'integer',
  1805. PrintConv => {
  1806. 0 => 'Above Sea Level',
  1807. 1 => 'Below Sea Level',
  1808. },
  1809. },
  1810. GPSAltitude => {
  1811. Groups => { 2 => 'Location' },
  1812. Writable => 'rational',
  1813. RawConv => 'require Image::ExifTool::GPS; $val', # to load Composite tags and routines
  1814. # extricate unsigned decimal number from string
  1815. ValueConvInv => '$val=~/((?=\d|\.\d)\d*(?:\.\d*)?)/ ? $1 : undef',
  1816. PrintConv => '$val =~ /^(inf|undef)$/ ? $val : "$val m"',
  1817. PrintConvInv => '$val=~s/\s*m$//;$val',
  1818. },
  1819. GPSTimeStamp => {
  1820. Name => 'GPSDateTime',
  1821. Description => 'GPS Date/Time',
  1822. Groups => { 2 => 'Time' },
  1823. Notes => q{
  1824. a date/time tag called GPSTimeStamp by the XMP specification. This tag is
  1825. renamed here to prevent direct copy from EXIF:GPSTimeStamp which is a
  1826. time-only tag. Instead, the value of this tag should be taken from
  1827. Composite:GPSDateTime when copying from EXIF
  1828. },
  1829. %dateTimeInfo,
  1830. },
  1831. GPSSatellites => { Groups => { 2 => 'Location' } },
  1832. GPSStatus => {
  1833. Groups => { 2 => 'Location' },
  1834. PrintConv => {
  1835. A => 'Measurement Active',
  1836. V => 'Measurement Void',
  1837. },
  1838. },
  1839. GPSMeasureMode => {
  1840. Groups => { 2 => 'Location' },
  1841. Writable => 'integer',
  1842. PrintConv => {
  1843. 2 => '2-Dimensional',
  1844. 3 => '3-Dimensional',
  1845. },
  1846. },
  1847. GPSDOP => { Groups => { 2 => 'Location' }, Writable => 'rational' },
  1848. GPSSpeedRef => {
  1849. Groups => { 2 => 'Location' },
  1850. PrintConv => {
  1851. K => 'km/h',
  1852. M => 'mph',
  1853. N => 'knots',
  1854. },
  1855. },
  1856. GPSSpeed => { Groups => { 2 => 'Location' }, Writable => 'rational' },
  1857. GPSTrackRef => {
  1858. Groups => { 2 => 'Location' },
  1859. PrintConv => {
  1860. M => 'Magnetic North',
  1861. T => 'True North',
  1862. },
  1863. },
  1864. GPSTrack => { Groups => { 2 => 'Location' }, Writable => 'rational' },
  1865. GPSImgDirectionRef => {
  1866. Groups => { 2 => 'Location' },
  1867. PrintConv => {
  1868. M => 'Magnetic North',
  1869. T => 'True North',
  1870. },
  1871. },
  1872. GPSImgDirection => { Groups => { 2 => 'Location' }, Writable => 'rational' },
  1873. GPSMapDatum => { Groups => { 2 => 'Location' } },
  1874. GPSDestLatitude => { Groups => { 2 => 'Location' }, %latConv },
  1875. GPSDestLongitude=> { Groups => { 2 => 'Location' }, %longConv },
  1876. GPSDestBearingRef => {
  1877. Groups => { 2 => 'Location' },
  1878. PrintConv => {
  1879. M => 'Magnetic North',
  1880. T => 'True North',
  1881. },
  1882. },
  1883. GPSDestBearing => { Groups => { 2 => 'Location' }, Writable => 'rational' },
  1884. GPSDestDistanceRef => {
  1885. Groups => { 2 => 'Location' },
  1886. PrintConv => {
  1887. K => 'Kilometers',
  1888. M => 'Miles',
  1889. N => 'Nautical Miles',
  1890. },
  1891. },
  1892. GPSDestDistance => {
  1893. Groups => { 2 => 'Location' },
  1894. Writable => 'rational',
  1895. },
  1896. GPSProcessingMethod => { Groups => { 2 => 'Location' } },
  1897. GPSAreaInformation => { Groups => { 2 => 'Location' } },
  1898. GPSDifferential => {
  1899. Groups => { 2 => 'Location' },
  1900. Writable => 'integer',
  1901. PrintConv => {
  1902. 0 => 'No Correction',
  1903. 1 => 'Differential Corrected',
  1904. },
  1905. },
  1906. GPSHPositioningError => { #12
  1907. Description => 'GPS Horizontal Positioning Error',
  1908. Groups => { 2 => 'Location' },
  1909. Writable => 'rational',
  1910. PrintConv => '"$val m"',
  1911. PrintConvInv => '$val=~s/\s*m$//; $val',
  1912. },
  1913. NativeDigest => { }, #PH
  1914. );
  1915. # Exif extended properties (exifEX, ref 12)
  1916. %Image::ExifTool::XMP::exifEX = (
  1917. %xmpTableDefaults,
  1918. GROUPS => { 1 => 'XMP-exifEX', 2 => 'Image' },
  1919. NAMESPACE => 'exifEX',
  1920. PRIORITY => 0, # not as reliable as actual EXIF tags
  1921. NOTES => q{
  1922. EXIF tags added by the EXIF 2.3 for XMP specification (see
  1923. L<http://www.cipa.jp/std/documents/e/DC-010-2012_E.pdf>).
  1924. },
  1925. Gamma => { Writable => 'rational' },
  1926. PhotographicSensitivity => { Writable => 'integer' },
  1927. SensitivityType => {
  1928. Writable => 'integer',
  1929. PrintConv => {
  1930. 0 => 'Unknown',
  1931. 1 => 'Standard Output Sensitivity',
  1932. 2 => 'Recommended Exposure Index',
  1933. 3 => 'ISO Speed',
  1934. 4 => 'Standard Output Sensitivity and Recommended Exposure Index',
  1935. 5 => 'Standard Output Sensitivity and ISO Speed',
  1936. 6 => 'Recommended Exposure Index and ISO Speed',
  1937. 7 => 'Standard Output Sensitivity, Recommended Exposure Index and ISO Speed',
  1938. },
  1939. },
  1940. StandardOutputSensitivity => { Writable => 'integer' },
  1941. RecommendedExposureIndex => { Writable => 'integer' },
  1942. ISOSpeed => { Writable => 'integer' },
  1943. ISOSpeedLatitudeyyy => {
  1944. Description => 'ISO Speed Latitude yyy',
  1945. Writable => 'integer',
  1946. },
  1947. ISOSpeedLatitudezzz => {
  1948. Description => 'ISO Speed Latitude zzz',
  1949. Writable => 'integer',
  1950. },
  1951. CameraOwnerName => { Name => 'OwnerName' },
  1952. BodySerialNumber => { Name => 'SerialNumber' },
  1953. LensSpecification => {
  1954. Name => 'LensInfo',
  1955. Writable => 'rational',
  1956. List => 'Seq',
  1957. RawJoin => 1, # join list into a string before ValueConv
  1958. ValueConv => \&ConvertRationalList,
  1959. ValueConvInv => sub {
  1960. my $val = shift;
  1961. my @vals = split ' ', $val;
  1962. return $val unless @vals == 4;
  1963. foreach (@vals) {
  1964. $_ eq 'inf' and $_ = '1/0', next;
  1965. $_ eq 'undef' and $_ = '0/0', next;
  1966. Image::ExifTool::IsFloat($_) or return $val;
  1967. my @a = Image::ExifTool::Rationalize($_);
  1968. $_ = join '/', @a;
  1969. }
  1970. return \@vals; # return list reference (List-type tag)
  1971. },
  1972. PrintConv => \&Image::ExifTool::Exif::PrintLensInfo,
  1973. PrintConvInv => \&Image::ExifTool::Exif::ConvertLensInfo,
  1974. Notes => q{
  1975. called LensSpecification by the spec. Unfortunately the EXIF 2.3 for XMP
  1976. specification defined this new tag instead of using the existing
  1977. XMP-aux:LensInfo
  1978. },
  1979. },
  1980. LensMake => { },
  1981. LensModel => { },
  1982. LensSerialNumber => { },
  1983. InteroperabilityIndex => {
  1984. Name => 'InteropIndex',
  1985. Description => 'Interoperability Index',
  1986. PrintConv => {
  1987. R98 => 'R98 - DCF basic file (sRGB)',
  1988. R03 => 'R03 - DCF option file (Adobe RGB)',
  1989. THM => 'THM - DCF thumbnail file',
  1990. },
  1991. },
  1992. );
  1993. # Auxiliary namespace properties (aux) - not fully documented (ref PH)
  1994. %Image::ExifTool::XMP::aux = (
  1995. %xmpTableDefaults,
  1996. GROUPS => { 1 => 'XMP-aux', 2 => 'Camera' },
  1997. NAMESPACE => 'aux',
  1998. NOTES => q{
  1999. Adobe-defined auxiliary EXIF tags. This namespace existed in the XMP
  2000. specification until it was dropped in 2012, presumably due to the
  2001. introduction of the EXIF 2.3 for XMP specification and the exifEX namespace
  2002. at this time. For this reason, tags below with equivalents in the
  2003. L<exifEX namespace|/XMP exifEX Tags> are avoided when writing.
  2004. },
  2005. Firmware => { }, #7
  2006. FlashCompensation => { Writable => 'rational' }, #7
  2007. ImageNumber => { }, #7
  2008. LensInfo => { #7
  2009. Notes => '4 rational values giving focal and aperture ranges',
  2010. Avoid => 1,
  2011. # convert to floating point values (or 'inf' or 'undef')
  2012. ValueConv => \&ConvertRationalList,
  2013. ValueConvInv => sub {
  2014. my $val = shift;
  2015. my @vals = split ' ', $val;
  2016. return $val unless @vals == 4;
  2017. foreach (@vals) {
  2018. $_ eq 'inf' and $_ = '1/0', next;
  2019. $_ eq 'undef' and $_ = '0/0', next;
  2020. Image::ExifTool::IsFloat($_) or return $val;
  2021. my @a = Image::ExifTool::Rationalize($_);
  2022. $_ = join '/', @a;
  2023. }
  2024. return join ' ', @vals; # return string (string tag)
  2025. },
  2026. # convert to the form "12-20mm f/3.8-4.5" or "50mm f/1.4"
  2027. PrintConv => \&Image::ExifTool::Exif::PrintLensInfo,
  2028. PrintConvInv => \&Image::ExifTool::Exif::ConvertLensInfo,
  2029. },
  2030. Lens => { },
  2031. OwnerName => { Avoid => 1 }, #7
  2032. SerialNumber => { Avoid => 1 },
  2033. LensSerialNumber=> { Avoid => 1 },
  2034. LensID => {
  2035. Priority => 0,
  2036. # prevent this from getting set from a LensID that has been converted
  2037. ValueConvInv => q{
  2038. warn "Expected one or more integer values" if $val =~ /[^\d ]/;
  2039. return $val;
  2040. },
  2041. },
  2042. ApproximateFocusDistance => { Writable => 'rational' }, #PH (LR3)
  2043. # the following new in LR6 (ref forum6497)
  2044. IsMergedPanorama => { Writable => 'boolean' },
  2045. IsMergedHDR => { Writable => 'boolean' },
  2046. DistortionCorrectionAlreadyApplied => { Writable => 'boolean' },
  2047. VignetteCorrectionAlreadyApplied => { Writable => 'boolean' },
  2048. LateralChromaticAberrationCorrectionAlreadyApplied => { Writable => 'boolean' },
  2049. );
  2050. # IPTC Core namespace properties (Iptc4xmpCore) (ref 4)
  2051. %Image::ExifTool::XMP::iptcCore = (
  2052. %xmpTableDefaults,
  2053. GROUPS => { 1 => 'XMP-iptcCore', 2 => 'Author' },
  2054. NAMESPACE => 'Iptc4xmpCore',
  2055. TABLE_DESC => 'XMP IPTC Core',
  2056. NOTES => q{
  2057. IPTC Core namespace tags. The actual IPTC Core namespace prefix is
  2058. "Iptc4xmpCore", which is the prefix recorded in the file, but ExifTool
  2059. shortens this for the "XMP-iptcCore" family 1 group name. (see
  2060. L<http://www.iptc.org/IPTC4XMP/>)
  2061. },
  2062. CountryCode => { Groups => { 2 => 'Location' } },
  2063. CreatorContactInfo => {
  2064. Struct => {
  2065. STRUCT_NAME => 'ContactInfo',
  2066. NAMESPACE => 'Iptc4xmpCore',
  2067. CiAdrCity => { },
  2068. CiAdrCtry => { },
  2069. CiAdrExtadr => { },
  2070. CiAdrPcode => { },
  2071. CiAdrRegion => { },
  2072. CiEmailWork => { },
  2073. CiTelWork => { },
  2074. CiUrlWork => { },
  2075. },
  2076. },
  2077. CreatorContactInfoCiAdrCity => { Flat => 1, Name => 'CreatorCity' },
  2078. CreatorContactInfoCiAdrCtry => { Flat => 1, Name => 'CreatorCountry' },
  2079. CreatorContactInfoCiAdrExtadr => { Flat => 1, Name => 'CreatorAddress' },
  2080. CreatorContactInfoCiAdrPcode => { Flat => 1, Name => 'CreatorPostalCode' },
  2081. CreatorContactInfoCiAdrRegion => { Flat => 1, Name => 'CreatorRegion' },
  2082. CreatorContactInfoCiEmailWork => { Flat => 1, Name => 'CreatorWorkEmail' },
  2083. CreatorContactInfoCiTelWork => { Flat => 1, Name => 'CreatorWorkTelephone' },
  2084. CreatorContactInfoCiUrlWork => { Flat => 1, Name => 'CreatorWorkURL' },
  2085. IntellectualGenre => { Groups => { 2 => 'Other' } },
  2086. Location => { Groups => { 2 => 'Location' } },
  2087. Scene => { Groups => { 2 => 'Other' }, List => 'Bag' },
  2088. SubjectCode => { Groups => { 2 => 'Other' }, List => 'Bag' },
  2089. );
  2090. # IPTC Extension namespace properties (Iptc4xmpExt) (ref 4)
  2091. %Image::ExifTool::XMP::iptcExt = (
  2092. %xmpTableDefaults,
  2093. GROUPS => { 1 => 'XMP-iptcExt', 2 => 'Author' },
  2094. NAMESPACE => 'Iptc4xmpExt',
  2095. TABLE_DESC => 'XMP IPTC Extension',
  2096. NOTES => q{
  2097. IPTC Extension namespace tags. The actual namespace prefix is
  2098. "Iptc4xmpExt", but ExifTool shortens this for the "XMP-iptcExt" family 1
  2099. group name. (see L<http://www.iptc.org/IPTC4XMP/>)
  2100. },
  2101. AboutCvTerm => {
  2102. Struct => \%sCVTermDetails,
  2103. List => 'Bag',
  2104. },
  2105. AboutCvTermCvId => { Flat => 1, Name => 'AboutCvTermCvId' },
  2106. AboutCvTermCvTermId => { Flat => 1, Name => 'AboutCvTermId' },
  2107. AboutCvTermCvTermName => { Flat => 1, Name => 'AboutCvTermName' },
  2108. AboutCvTermCvTermRefinedAbout => { Flat => 1, Name => 'AboutCvTermRefinedAbout' },
  2109. AddlModelInfo => { Name => 'AdditionalModelInformation' },
  2110. ArtworkOrObject => {
  2111. Struct => {
  2112. STRUCT_NAME => 'ArtworkOrObjectDetails',
  2113. NAMESPACE => 'Iptc4xmpExt',
  2114. AOCopyrightNotice => { },
  2115. AOCreator => { List => 'Seq' },
  2116. AODateCreated=> { Groups => { 2 => 'Time' }, %dateTimeInfo },
  2117. AOSource => { },
  2118. AOSourceInvNo=> { },
  2119. AOTitle => { Writable => 'lang-alt' },
  2120. AOCurrentCopyrightOwnerName => { },
  2121. AOCurrentCopyrightOwnerId => { },
  2122. AOCurrentLicensorName => { },
  2123. AOCurrentLicensorId => { },
  2124. AOCreatorId => { List => 'Seq' },
  2125. AOCircaDateCreated => { },
  2126. AOStylePeriod => { List => 'Bag' },
  2127. AOSourceInvURL => { },
  2128. AOContentDescription => { Writable => 'lang-alt' },
  2129. AOContributionDescription => { Writable => 'lang-alt' },
  2130. AOPhysicalDescription => { Writable => 'lang-alt' },
  2131. },
  2132. List => 'Bag',
  2133. },
  2134. ArtworkOrObjectAOCopyrightNotice => { Flat => 1, Name => 'ArtworkCopyrightNotice' },
  2135. ArtworkOrObjectAOCreator => { Flat => 1, Name => 'ArtworkCreator' },
  2136. ArtworkOrObjectAODateCreated => { Flat => 1, Name => 'ArtworkDateCreated' },
  2137. ArtworkOrObjectAOSource => { Flat => 1, Name => 'ArtworkSource' },
  2138. ArtworkOrObjectAOSourceInvNo => { Flat => 1, Name => 'ArtworkSourceInventoryNo' },
  2139. ArtworkOrObjectAOTitle => { Flat => 1, Name => 'ArtworkTitle' },
  2140. ArtworkOrObjectAOCurrentCopyrightOwnerName => { Flat => 1, Name => 'ArtworkCopyrightOwnerName' },
  2141. ArtworkOrObjectAOCurrentCopyrightOwnerId => { Flat => 1, Name => 'ArtworkCopyrightOwnerID' },
  2142. ArtworkOrObjectAOCurrentLicensorName => { Flat => 1, Name => 'ArtworkLicensorName' },
  2143. ArtworkOrObjectAOCurrentLicensorId => { Flat => 1, Name => 'ArtworkLicensorID' },
  2144. ArtworkOrObjectAOCreatorId => { Flat => 1, Name => 'ArtworkCreatorID' },
  2145. ArtworkOrObjectAOCircaDateCreated => { Flat => 1, Name => 'ArtworkCircaDateCreated' },
  2146. ArtworkOrObjectAOStylePeriod => { Flat => 1, Name => 'ArtworkStylePeriod' },
  2147. ArtworkOrObjectAOSourceInvURL => { Flat => 1, Name => 'ArtworkSourceInvURL' },
  2148. ArtworkOrObjectAOContentDescription => { Flat => 1, Name => 'ArtworkSContentDescription' },
  2149. ArtworkOrObjectAOContributionDescription => { Flat => 1, Name => 'ArtworkContributionDescription' },
  2150. ArtworkOrObjectAOPhysicalDescription => { Flat => 1, Name => 'ArtworkPhysicalDescription' },
  2151. CVterm => {
  2152. Name => 'ControlledVocabularyTerm',
  2153. List => 'Bag',
  2154. Notes => 'deprecated by version 1.2',
  2155. },
  2156. DigImageGUID => { Name => 'DigitalImageGUID' },
  2157. DigitalSourcefileType => {
  2158. Name => 'DigitalSourceFileType',
  2159. Notes => 'now deprecated -- replaced by DigitalSourceType',
  2160. },
  2161. DigitalSourceType => { Name => 'DigitalSourceType' },
  2162. EmbdEncRightsExpr => {
  2163. Struct => {
  2164. STRUCT_NAME => 'EEREDetails',
  2165. NAMESPACE => 'Iptc4xmpExt',
  2166. EncRightsExpr => { },
  2167. RightsExprEncType => { },
  2168. RightsExprLangId => { },
  2169. },
  2170. List => 'Bag',
  2171. },
  2172. EmbdEncRightsExprEncRightsExpr => { Flat => 1, Name => 'EmbeddedEncodedRightsExpr' },
  2173. EmbdEncRightsExprRightsExprEncType => { Flat => 1, Name => 'EmbeddedEncodedRightsExprType' },
  2174. EmbdEncRightsExprRightsExprLangId => { Flat => 1, Name => 'EmbeddedEncodedRightsExprLangID' },
  2175. Event => { Writable => 'lang-alt' },
  2176. IptcLastEdited => {
  2177. Name => 'IPTCLastEdited',
  2178. Groups => { 2 => 'Time' },
  2179. %dateTimeInfo,
  2180. },
  2181. LinkedEncRightsExpr => {
  2182. Struct => {
  2183. STRUCT_NAME => 'LEREDetails',
  2184. NAMESPACE => 'Iptc4xmpExt',
  2185. LinkedRightsExpr => { },
  2186. RightsExprEncType => { },
  2187. RightsExprLangId => { },
  2188. },
  2189. List => 'Bag',
  2190. },
  2191. LinkedEncRightsExprLinkedRightsExpr => { Flat => 1, Name => 'LinkedEncodedRightsExpr' },
  2192. LinkedEncRightsExprRightsExprEncType => { Flat => 1, Name => 'LinkedEncodedRightsExprType' },
  2193. LinkedEncRightsExprRightsExprLangId => { Flat => 1, Name => 'LinkedEncodedRightsExprLangID' },
  2194. LocationCreated => {
  2195. Struct => \%sLocationDetails,
  2196. Groups => { 2 => 'Location' },
  2197. List => 'Bag',
  2198. },
  2199. LocationShown => {
  2200. Struct => \%sLocationDetails,
  2201. Groups => { 2 => 'Location' },
  2202. List => 'Bag',
  2203. },
  2204. MaxAvailHeight => { Writable => 'integer' },
  2205. MaxAvailWidth => { Writable => 'integer' },
  2206. ModelAge => { List => 'Bag', Writable => 'integer' },
  2207. OrganisationInImageCode => { List => 'Bag' },
  2208. OrganisationInImageName => { List => 'Bag' },
  2209. PersonInImage => { List => 'Bag' },
  2210. PersonInImageWDetails => {
  2211. Struct => {
  2212. STRUCT_NAME => 'PersonDetails',
  2213. NAMESPACE => 'Iptc4xmpExt',
  2214. PersonId => { List => 'Bag' },
  2215. PersonName => { Writable => 'lang-alt' },
  2216. PersonCharacteristic => {
  2217. Struct => \%sCVTermDetails,
  2218. List => 'Bag',
  2219. },
  2220. PersonDescription => { Writable => 'lang-alt' },
  2221. },
  2222. List => 'Bag',
  2223. },
  2224. PersonInImageWDetailsPersonId => { Flat => 1, Name => 'PersonInImageId' },
  2225. PersonInImageWDetailsPersonName => { Flat => 1, Name => 'PersonInImageName' },
  2226. PersonInImageWDetailsPersonCharacteristic => { Flat => 1, Name => 'PersonInImageCharacteristic' },
  2227. PersonInImageWDetailsPersonCharacteristicCvId => { Flat => 1, Name => 'PersonInImageCvTermCvId' },
  2228. PersonInImageWDetailsPersonCharacteristicCvTermId => { Flat => 1, Name => 'PersonInImageCvTermId' },
  2229. PersonInImageWDetailsPersonCharacteristicCvTermName => { Flat => 1, Name => 'PersonInImageCvTermName' },
  2230. PersonInImageWDetailsPersonCharacteristicCvTermRefinedAbout => { Flat => 1, Name => 'PersonInImageCvTermRefinedAbout' },
  2231. PersonInImageWDetailsPersonDescription => { Flat => 1, Name => 'PersonInImageDescription' },
  2232. ProductInImage => {
  2233. Struct => {
  2234. STRUCT_NAME => 'ProductDetails',
  2235. NAMESPACE => 'Iptc4xmpExt',
  2236. ProductName => { Writable => 'lang-alt' },
  2237. ProductGTIN => { },
  2238. ProductDescription => { Writable => 'lang-alt' },
  2239. },
  2240. List => 'Bag',
  2241. },
  2242. ProductInImageProductName => { Flat => 1, Name => 'ProductInImageName' },
  2243. ProductInImageProductGTIN => { Flat => 1, Name => 'ProductInImageGTIN' },
  2244. ProductInImageProductDescription => { Flat => 1, Name => 'ProductInImageDescription' },
  2245. RegistryId => {
  2246. Name => 'RegistryID',
  2247. Struct => {
  2248. STRUCT_NAME => 'RegistryEntryDetails',
  2249. NAMESPACE => 'Iptc4xmpExt',
  2250. RegItemId => { },
  2251. RegOrgId => { },
  2252. },
  2253. List => 'Bag',
  2254. },
  2255. RegistryIdRegItemId => { Flat => 1, Name => 'RegistryItemID' },
  2256. RegistryIdRegOrgId => { Flat => 1, Name => 'RegistryOrganisationID' },
  2257. );
  2258. # Adobe Lightroom namespace properties (lr) (ref PH)
  2259. %Image::ExifTool::XMP::Lightroom = (
  2260. %xmpTableDefaults,
  2261. GROUPS => { 1 => 'XMP-lr', 2 => 'Image' },
  2262. NAMESPACE => 'lr',
  2263. TABLE_DESC => 'XMP Adobe Lightroom',
  2264. NOTES => 'Adobe Lightroom "lr" namespace tags.',
  2265. privateRTKInfo => { },
  2266. hierarchicalSubject => { List => 'Bag' },
  2267. );
  2268. # Adobe Album namespace properties (album) (ref PH)
  2269. %Image::ExifTool::XMP::Album = (
  2270. %xmpTableDefaults,
  2271. GROUPS => { 1 => 'XMP-album', 2 => 'Image' },
  2272. NAMESPACE => 'album',
  2273. TABLE_DESC => 'XMP Adobe Album',
  2274. NOTES => 'Adobe Album namespace tags.',
  2275. Notes => { },
  2276. );
  2277. # table to add tags in other namespaces
  2278. %Image::ExifTool::XMP::other = (
  2279. GROUPS => { 2 => 'Unknown' },
  2280. LANG_INFO => \&GetLangInfo,
  2281. );
  2282. # Composite XMP tags
  2283. %Image::ExifTool::XMP::Composite = (
  2284. # get latitude/logitude reference from XMP lat/long tags
  2285. # (used to set EXIF GPS position from XMP tags)
  2286. GPSLatitudeRef => {
  2287. Require => 'XMP:GPSLatitude',
  2288. ValueConv => q{
  2289. IsFloat($val[0]) and return $val[0] < 0 ? "S" : "N";
  2290. $val[0] =~ /^.*([NS])/;
  2291. return $1;
  2292. },
  2293. PrintConv => {
  2294. N => 'North',
  2295. S => 'South',
  2296. },
  2297. },
  2298. GPSLongitudeRef => {
  2299. Require => 'XMP:GPSLongitude',
  2300. ValueConv => q{
  2301. IsFloat($val[0]) and return $val[0] < 0 ? "W" : "E";
  2302. $val[0] =~ /^.*([EW])/;
  2303. return $1;
  2304. },
  2305. PrintConv => {
  2306. E => 'East',
  2307. W => 'West',
  2308. },
  2309. },
  2310. LensID => {
  2311. Notes => 'attempt to convert numerical XMP-aux:LensID stored by Adobe applications',
  2312. Require => {
  2313. 0 => 'XMP-aux:LensID',
  2314. 1 => 'Make',
  2315. },
  2316. Desire => {
  2317. 2 => 'LensInfo',
  2318. 3 => 'FocalLength',
  2319. 4 => 'LensModel',
  2320. 5 => 'MaxApertureValue',
  2321. },
  2322. Inhibit => {
  2323. 6 => 'Composite:LensID', # don't override existing Composite:LensID
  2324. },
  2325. ValueConv => '$val',
  2326. PrintConv => 'Image::ExifTool::XMP::PrintLensID($self, @val)',
  2327. },
  2328. Flash => {
  2329. Notes => 'facilitates copying camera flash information between XMP and EXIF',
  2330. Desire => {
  2331. 0 => 'XMP:FlashFired',
  2332. 1 => 'XMP:FlashReturn',
  2333. 2 => 'XMP:FlashMode',
  2334. 3 => 'XMP:FlashFunction',
  2335. 4 => 'XMP:FlashRedEyeMode',
  2336. 5 => 'XMP:Flash', # handle structured flash information too
  2337. },
  2338. Writable => 1,
  2339. PrintHex => 1,
  2340. SeparateTable => 'EXIF Flash',
  2341. ValueConv => q{
  2342. if (ref $val[5] eq 'HASH') {
  2343. # copy structure fields into value array
  2344. my $i = 0;
  2345. $val[$i++] = $val[5]{$_} foreach qw(Fired Return Mode Function RedEyeMode);
  2346. }
  2347. return (($val[0] and lc($val[0]) eq 'true') ? 0x01 : 0) |
  2348. (($val[1] || 0) << 1) |
  2349. (($val[2] || 0) << 3) |
  2350. (($val[3] and lc($val[3]) eq 'true') ? 0x20 : 0) |
  2351. (($val[4] and lc($val[4]) eq 'true') ? 0x40 : 0);
  2352. },
  2353. PrintConv => \%Image::ExifTool::Exif::flash,
  2354. WriteAlso => {
  2355. 'XMP:FlashFired' => '$val & 0x01 ? "True" : "False"',
  2356. 'XMP:FlashReturn' => '($val & 0x06) >> 1',
  2357. 'XMP:FlashMode' => '($val & 0x18) >> 3',
  2358. 'XMP:FlashFunction' => '$val & 0x20 ? "True" : "False"',
  2359. 'XMP:FlashRedEyeMode' => '$val & 0x40 ? "True" : "False"',
  2360. },
  2361. },
  2362. );
  2363. # add our composite tags
  2364. Image::ExifTool::AddCompositeTags('Image::ExifTool::XMP');
  2365. #------------------------------------------------------------------------------
  2366. # AutoLoad our writer routines when necessary
  2367. #
  2368. sub AUTOLOAD
  2369. {
  2370. return Image::ExifTool::DoAutoLoad($AUTOLOAD, @_);
  2371. }
  2372. #------------------------------------------------------------------------------
  2373. # Escape necessary XML characters in UTF-8 string
  2374. # Inputs: 0) string to be escaped
  2375. # Returns: escaped string
  2376. my %charName = ('"'=>'quot', '&'=>'amp', "'"=>'#39', '<'=>'lt', '>'=>'gt');
  2377. sub EscapeXML($)
  2378. {
  2379. my $str = shift;
  2380. $str =~ s/([&><'"])/&$charName{$1};/sg; # escape necessary XML characters
  2381. return $str;
  2382. }
  2383. #------------------------------------------------------------------------------
  2384. # Unescape XML character references (entities and numerical)
  2385. # Inputs: 0) string to be unescaped
  2386. # 1) optional hash reference to convert entity names to numbers
  2387. # Returns: unescaped string
  2388. my %charNum = ('quot'=>34, 'amp'=>38, 'apos'=>39, 'lt'=>60, 'gt'=>62);
  2389. sub UnescapeXML($;$)
  2390. {
  2391. my ($str, $conv) = @_;
  2392. $conv = \%charNum unless $conv;
  2393. $str =~ s/&(#?\w+);/UnescapeChar($1,$conv)/sge;
  2394. return $str;
  2395. }
  2396. #------------------------------------------------------------------------------
  2397. # Escape string for XML, ensuring valid XML and UTF-8
  2398. # Inputs: 0) string
  2399. # Returns: escaped string
  2400. sub FullEscapeXML($)
  2401. {
  2402. my $str = shift;
  2403. $str =~ s/([&><'"])/&$charName{$1};/sg; # escape necessary XML characters
  2404. $str =~ s/\\/&#92;/sg; # escape backslashes too
  2405. # then use C-escape sequences for invalid characters
  2406. if ($str =~ /[\0-\x1f]/ or IsUTF8(\$str) < 0) {
  2407. $str =~ s/([\0-\x1f\x80-\xff])/sprintf("\\x%.2x",ord $1)/sge;
  2408. }
  2409. return $str;
  2410. }
  2411. #------------------------------------------------------------------------------
  2412. # Unescape XML/C escaped string
  2413. # Inputs: 0) string
  2414. # Returns: unescaped string
  2415. sub FullUnescapeXML($)
  2416. {
  2417. my $str = shift;
  2418. # unescape C escape sequences first
  2419. $str =~ s/\\x([\da-f]{2})/chr(hex($1))/sge;
  2420. my $conv = \%charNum;
  2421. $str =~ s/&(#?\w+);/UnescapeChar($1,$conv)/sge;
  2422. return $str;
  2423. }
  2424. #------------------------------------------------------------------------------
  2425. # Convert XML character reference to UTF-8
  2426. # Inputs: 0) XML character reference stripped of the '&' and ';' (eg. 'quot', '#34', '#x22')
  2427. # 1) hash reference for looking up character numbers by name
  2428. # Returns: UTF-8 equivalent (or original character on conversion error)
  2429. sub UnescapeChar($$)
  2430. {
  2431. my ($ch, $conv) = @_;
  2432. my $val = $$conv{$ch};
  2433. unless (defined $val) {
  2434. if ($ch =~ /^#x([0-9a-fA-F]+)$/) {
  2435. $val = hex($1);
  2436. } elsif ($ch =~ /^#(\d+)$/) {
  2437. $val = $1;
  2438. } else {
  2439. return "&$ch;"; # should issue a warning here? [no]
  2440. }
  2441. }
  2442. return chr($val) if $val < 0x80; # simple ASCII
  2443. return pack('C0U', $val) if $] >= 5.006001;
  2444. return Image::ExifTool::PackUTF8($val);
  2445. }
  2446. #------------------------------------------------------------------------------
  2447. # Does a string contain valid UTF-8 characters?
  2448. # Inputs: 0) string reference
  2449. # Returns: 0=regular ASCII, -1=invalid UTF-8, 1=valid UTF-8 with maximum 16-bit
  2450. # wide characters, 2=valid UTF-8 requiring 32-bit wide characters
  2451. # Notes: Changes current string position
  2452. # (see http://www.fileformat.info/info/unicode/utf8.htm for help understanding this)
  2453. sub IsUTF8($)
  2454. {
  2455. my $strPt = shift;
  2456. pos($$strPt) = 0; # start at beginning of string
  2457. return 0 unless $$strPt =~ /([\x80-\xff])/g;
  2458. my $rtnVal = 1;
  2459. for (;;) {
  2460. my $ch = ord($1);
  2461. # minimum lead byte for 2-byte sequence is 0xc2 (overlong sequences
  2462. # not allowed), 0xf8-0xfd are restricted by RFC 3629 (no 5 or 6 byte
  2463. # sequences), and 0xfe and 0xff are not valid in UTF-8 strings
  2464. return -1 if $ch < 0xc2 or $ch >= 0xf8;
  2465. # determine number of bytes remaining in sequence
  2466. my $n;
  2467. if ($ch < 0xe0) {
  2468. $n = 1;
  2469. } elsif ($ch < 0xf0) {
  2470. $n = 2;
  2471. } else {
  2472. $n = 3;
  2473. # character code is greater than 0xffff if more than 2 extra bytes
  2474. # were required in the UTF-8 character
  2475. $rtnVal = 2;
  2476. }
  2477. return -1 unless $$strPt =~ /\G[\x80-\xbf]{$n}/g;
  2478. last unless $$strPt =~ /([\x80-\xff])/g;
  2479. }
  2480. return $rtnVal;
  2481. }
  2482. #------------------------------------------------------------------------------
  2483. # Fix malformed UTF8 (by replacing bad bytes with '?')
  2484. # Inputs: 0) string reference
  2485. # Returns: true if string was fixed, and updates string
  2486. sub FixUTF8($)
  2487. {
  2488. my $strPt = shift;
  2489. my $fixed;
  2490. pos($$strPt) = 0; # start at beginning of string
  2491. for (;;) {
  2492. last unless $$strPt =~ /([\x80-\xff])/g;
  2493. my $ch = ord($1);
  2494. my $pos = pos($$strPt);
  2495. # (see comments in IsUTF8() above)
  2496. if ($ch >= 0xc2 and $ch < 0xf8) {
  2497. my $n = $ch < 0xe0 ? 1 : ($ch < 0xf0 ? 2 : 3);
  2498. next if $$strPt =~ /\G[\x80-\xbf]{$n}/g;
  2499. }
  2500. # replace bad character with '?'
  2501. substr($$strPt, $pos-1, 1) = '?';
  2502. pos($$strPt) = $fixed = $pos;
  2503. }
  2504. return $fixed;
  2505. }
  2506. #------------------------------------------------------------------------------
  2507. # Utility routine to decode a base64 string
  2508. # Inputs: 0) base64 string
  2509. # Returns: reference to decoded data
  2510. sub DecodeBase64($)
  2511. {
  2512. local($^W) = 0; # unpack('u',...) gives bogus warning in 5.00[123]
  2513. my $str = shift;
  2514. # truncate at first unrecognized character (base 64 data
  2515. # may only contain A-Z, a-z, 0-9, +, /, =, or white space)
  2516. $str =~ s/[^A-Za-z0-9+\/= \t\n\r\f].*//s;
  2517. # translate to uucoded and remove padding and white space
  2518. $str =~ tr/A-Za-z0-9+\/= \t\n\r\f/ -_/d;
  2519. # convert the data to binary in chunks
  2520. my $chunkSize = 60;
  2521. my $uuLen = pack('c', 32 + $chunkSize * 3 / 4); # calculate length byte
  2522. my $dat = '';
  2523. my ($i, $substr);
  2524. # loop through the whole chunks
  2525. my $len = length($str) - $chunkSize;
  2526. for ($i=0; $i<=$len; $i+=$chunkSize) {
  2527. $substr = substr($str, $i, $chunkSize); # get a chunk of the data
  2528. $dat .= unpack('u', $uuLen . $substr); # decode it
  2529. }
  2530. $len += $chunkSize;
  2531. # handle last partial chunk if necessary
  2532. if ($i < $len) {
  2533. $uuLen = pack('c', 32 + ($len-$i) * 3 / 4); # recalculate length
  2534. $substr = substr($str, $i, $len-$i); # get the last partial chunk
  2535. $dat .= unpack('u', $uuLen . $substr); # decode it
  2536. }
  2537. return \$dat;
  2538. }
  2539. #------------------------------------------------------------------------------
  2540. # Generate a tag ID for this XMP tag
  2541. # Inputs: 0) tag property name list ref, 1) array ref for receiving structure property list
  2542. # 2) array for receiving namespace list
  2543. # Returns: tagID and outtermost interesting namespace (or '' if no namespace)
  2544. sub GetXMPTagID($;$$)
  2545. {
  2546. my ($props, $structProps, $nsList) = @_;
  2547. my ($tag, $prop, $namespace);
  2548. foreach $prop (@$props) {
  2549. # split name into namespace and property name
  2550. # (Note: namespace can be '' for property qualifiers)
  2551. my ($ns, $nm) = ($prop =~ /(.*?):(.*)/) ? ($1, $2) : ('', $prop);
  2552. if ($ignoreNamespace{$ns} or $ignoreProp{$prop}) {
  2553. # special case: don't ignore rdf numbered items
  2554. unless ($prop =~ /^rdf:(_\d+)$/) {
  2555. # save list index if necessary for structures
  2556. if ($structProps and @$structProps and $prop =~ /^rdf:li (\d+)$/) {
  2557. push @{$$structProps[-1]}, $1;
  2558. }
  2559. next;
  2560. }
  2561. $tag .= $1 if defined $tag;
  2562. } else {
  2563. $nm =~ s/ .*//; # remove nodeID if it exists
  2564. # all uppercase is ugly, so convert it
  2565. if ($nm !~ /[a-z]/) {
  2566. my $xlat = $stdXlatNS{$ns} || $ns;
  2567. my $info = $Image::ExifTool::XMP::Main{$xlat};
  2568. my $table;
  2569. if (ref $info eq 'HASH' and $$info{SubDirectory}) {
  2570. $table = GetTagTable($$info{SubDirectory}{TagTable});
  2571. }
  2572. unless ($table and $$table{$nm}) {
  2573. $nm = lc($nm);
  2574. $nm =~ s/_([a-z])/\u$1/g;
  2575. }
  2576. }
  2577. if (defined $tag) {
  2578. $tag .= ucfirst($nm); # add to tag name
  2579. } else {
  2580. $tag = $nm;
  2581. }
  2582. # save structure information if necessary
  2583. if ($structProps) {
  2584. push @$structProps, [ $nm ];
  2585. push @$nsList, $ns if $nsList;
  2586. }
  2587. }
  2588. # save namespace of first property to contribute to tag name
  2589. $namespace = $ns unless $namespace;
  2590. }
  2591. if (wantarray) {
  2592. return ($tag, $namespace || '');
  2593. } else {
  2594. return $tag;
  2595. }
  2596. }
  2597. #------------------------------------------------------------------------------
  2598. # Register namespace for specified user-defined table
  2599. # Inputs: 0) tag/structure table ref
  2600. # Returns: namespace prefix
  2601. sub RegisterNamespace($)
  2602. {
  2603. my $table = shift;
  2604. return $$table{NAMESPACE} unless ref $$table{NAMESPACE};
  2605. my $nsRef = $$table{NAMESPACE};
  2606. # recognize as either a list or hash
  2607. my $ns;
  2608. if (ref $nsRef eq 'ARRAY') {
  2609. $ns = $$nsRef[0];
  2610. $nsURI{$ns} = $$nsRef[1];
  2611. $uri2ns{$$nsRef[1]} = $ns;
  2612. } else { # must be a hash
  2613. my @ns = sort keys %$nsRef; # allow multiple namespace definitions
  2614. while (@ns) {
  2615. $ns = pop @ns;
  2616. if ($nsURI{$ns} and $nsURI{$ns} ne $$nsRef{$ns}) {
  2617. warn "User-defined namespace prefix '$ns' conflicts with existing namespace\n";
  2618. }
  2619. $nsURI{$ns} = $$nsRef{$ns};
  2620. $uri2ns{$$nsRef{$ns}} = $ns;
  2621. }
  2622. }
  2623. return $$table{NAMESPACE} = $ns;
  2624. }
  2625. #------------------------------------------------------------------------------
  2626. # Generate flattened tags and add to table
  2627. # Inputs: 0) tag table ref, 1) tag ID for Struct tag (if not defined, whole table is done),
  2628. # 2) flag to not expand sub-structures
  2629. # Returns: number of tags added (not counting those just initialized)
  2630. # Notes: Must have verified that $$tagTablePtr{$tagID}{Struct} exists before calling this routine
  2631. # - makes sure that the tagInfo Struct is a HASH reference
  2632. sub AddFlattenedTags($;$$)
  2633. {
  2634. local $_;
  2635. my ($tagTablePtr, $tagID, $noSubStruct) = @_;
  2636. my $count = 0;
  2637. my @tagIDs;
  2638. if (defined $tagID) {
  2639. push @tagIDs, $tagID;
  2640. } else {
  2641. foreach $tagID (TagTableKeys($tagTablePtr)) {
  2642. my $tagInfo = $$tagTablePtr{$tagID};
  2643. next unless ref $tagInfo eq 'HASH' and $$tagInfo{Struct};
  2644. push @tagIDs, $tagID;
  2645. }
  2646. }
  2647. # loop through specified tags
  2648. foreach $tagID (@tagIDs) {
  2649. my $tagInfo = $$tagTablePtr{$tagID};
  2650. $$tagInfo{Flattened} and next; # only generate flattened tags once
  2651. $$tagInfo{Flattened} = 1;
  2652. my $strTable = $$tagInfo{Struct};
  2653. unless (ref $strTable) { # (allow a structure name for backward compatibility only)
  2654. my $strName = $strTable;
  2655. $strTable = $Image::ExifTool::UserDefined::xmpStruct{$strTable} or next;
  2656. $$strTable{STRUCT_NAME} or $$strTable{STRUCT_NAME} = "XMP $strName";
  2657. $$tagInfo{Struct} = $strTable; # replace old-style name with HASH ref
  2658. delete $$tagInfo{SubDirectory}; # deprecated use of SubDirectory in Struct tags
  2659. }
  2660. # do not add flattened tags to variable-namespace structures
  2661. next if exists $$strTable{NAMESPACE} and not defined $$strTable{NAMESPACE};
  2662. # get prefix for flattened tag names
  2663. my $flat = (defined $$tagInfo{FlatName} ? $$tagInfo{FlatName} : $$tagInfo{Name});
  2664. # get family 2 group name for this structure tag
  2665. my ($tagG2, $field);
  2666. $tagG2 = $$tagInfo{Groups}{2} if $$tagInfo{Groups};
  2667. $tagG2 or $tagG2 = $$tagTablePtr{GROUPS}{2};
  2668. foreach $field (keys %$strTable) {
  2669. next if $specialStruct{$field};
  2670. my $fieldInfo = $$strTable{$field};
  2671. next if $$fieldInfo{LangCode}; # don't flatten lang-alt tags
  2672. next if $$fieldInfo{Struct} and $noSubStruct; # don't expand sub-structures if specified
  2673. # build a tag ID for the corresponding flattened tag
  2674. my $fieldName = ucfirst($field);
  2675. my $flatField = $$fieldInfo{FlatName} || $fieldName;
  2676. my $flatID = $tagID . $fieldName;
  2677. my $flatInfo = $$tagTablePtr{$flatID};
  2678. if ($flatInfo) {
  2679. ref $flatInfo eq 'HASH' or warn("$flatInfo is not a HASH!\n"), next; # (to be safe)
  2680. # pre-defined flattened tags should have Flat flag set
  2681. if (not defined $$flatInfo{Flat} and $Image::ExifTool::debug) {
  2682. warn "Missing Flat flag for $$flatInfo{Name}\n";
  2683. }
  2684. $$flatInfo{Flat} = 0;
  2685. # copy all missing entries from field information
  2686. foreach (keys %$fieldInfo) {
  2687. # must not copy PropertyPath (but can't delete it afterwards
  2688. # because the flat tag may already have this set)
  2689. next if $_ eq 'PropertyPath' or defined $$flatInfo{$_};
  2690. # copy the property (making a copy of the Groups hash)
  2691. $$flatInfo{$_} = $_ eq 'Groups' ? { %{$$fieldInfo{$_}} } : $$fieldInfo{$_};
  2692. }
  2693. # (NOTE: Can NOT delete Groups because we need them if GotGroups was done)
  2694. # re-generate List flag unless it is set to 0
  2695. delete $$flatInfo{List} if $$flatInfo{List};
  2696. } else {
  2697. # generate new flattened tag information based on structure field
  2698. my $flatName = $flat . $flatField;
  2699. $flatInfo = { %$fieldInfo, Name => $flatName, Flat => 0 };
  2700. # make a copy of the Groups hash if necessary
  2701. $$flatInfo{Groups} = { %{$$fieldInfo{Groups}} } if $$fieldInfo{Groups};
  2702. # add new flattened tag to table
  2703. AddTagToTable($tagTablePtr, $flatID, $flatInfo);
  2704. ++$count;
  2705. }
  2706. # propagate List flag (unless set to 0 in pre-defined flattened tag)
  2707. unless (defined $$flatInfo{List}) {
  2708. $$flatInfo{List} = $$fieldInfo{List} || 1 if $$fieldInfo{List} or $$tagInfo{List};
  2709. }
  2710. # set group 2 name from the first existing family 2 group in the:
  2711. # 1) structure field Groups, 2) structure table GROUPS, 3) structure tag Groups
  2712. if ($$fieldInfo{Groups} and $$fieldInfo{Groups}{2}) {
  2713. $$flatInfo{Groups}{2} = $$fieldInfo{Groups}{2};
  2714. } elsif ($$strTable{GROUPS} and $$strTable{GROUPS}{2}) {
  2715. $$flatInfo{Groups}{2} = $$strTable{GROUPS}{2};
  2716. } else {
  2717. $$flatInfo{Groups}{2} = $tagG2;
  2718. }
  2719. # save reference to top-level structure
  2720. $$flatInfo{RootTagInfo} = $$tagInfo{RootTagInfo} || $tagInfo;
  2721. # recursively generate flattened tags for sub-structures
  2722. next unless $$flatInfo{Struct};
  2723. length($flatID) > 250 and warn("Possible deep recursion for tag $flatID\n"), last;
  2724. # reset flattened tag just in case we flattened hierarchy in the wrong order
  2725. # because we must start from the outtermost structure to get the List flags right
  2726. # (this should only happen when building tag tables)
  2727. delete $$flatInfo{Flattened};
  2728. $count += AddFlattenedTags($tagTablePtr, $flatID, $$flatInfo{NoSubStruct});
  2729. }
  2730. }
  2731. return $count;
  2732. }
  2733. #------------------------------------------------------------------------------
  2734. # Get localized version of tagInfo hash
  2735. # Inputs: 0) tagInfo hash ref, 1) language code (eg. "x-default")
  2736. # Returns: new tagInfo hash ref, or undef if invalid
  2737. sub GetLangInfo($$)
  2738. {
  2739. my ($tagInfo, $langCode) = @_;
  2740. # only allow alternate language tags in lang-alt lists
  2741. return undef unless $$tagInfo{Writable} and $$tagInfo{Writable} eq 'lang-alt';
  2742. $langCode =~ tr/_/-/; # RFC 3066 specifies '-' as a separator
  2743. my $langInfo = Image::ExifTool::GetLangInfo($tagInfo, $langCode);
  2744. return $langInfo;
  2745. }
  2746. #------------------------------------------------------------------------------
  2747. # Get standard case for language code
  2748. # Inputs: 0) Language code
  2749. # Returns: Language code in standard case
  2750. sub StandardLangCase($)
  2751. {
  2752. my $lang = shift;
  2753. # make 2nd subtag uppercase only if it is 2 letters
  2754. return lc($1) . uc($2) . lc($3) if $lang =~ /^([a-z]{2,3}|[xi])(-[a-z]{2})\b(.*)/i;
  2755. return lc($lang);
  2756. }
  2757. #------------------------------------------------------------------------------
  2758. # Scan for XMP in a file
  2759. # Inputs: 0) ExifTool object ref, 1) RAF reference
  2760. # Returns: 1 if xmp was found, 0 otherwise
  2761. # Notes: Currently only recognizes UTF8-encoded XMP
  2762. sub ScanForXMP($$)
  2763. {
  2764. my ($et, $raf) = @_;
  2765. my ($buff, $xmp);
  2766. my $lastBuff = '';
  2767. $et->VPrint(0,"Scanning for XMP\n");
  2768. for (;;) {
  2769. defined $buff or $raf->Read($buff, 65536) or return 0;
  2770. unless (defined $xmp) {
  2771. $lastBuff .= $buff;
  2772. unless ($lastBuff =~ /(<\?xpacket begin=)/g) {
  2773. # must keep last 15 bytes to match 16-byte "xpacket begin" string
  2774. $lastBuff = length($buff) <= 15 ? $buff : substr($buff, -15);
  2775. undef $buff;
  2776. next;
  2777. }
  2778. $xmp = $1;
  2779. $buff = substr($lastBuff, pos($lastBuff));
  2780. }
  2781. my $pos = length($xmp) - 18; # (18 = length("<?xpacket end...") - 1)
  2782. $xmp .= $buff; # add new data to our XMP
  2783. pos($xmp) = $pos if $pos > 0; # set start for "xpacket end" scan
  2784. if ($xmp =~ /<\?xpacket end=['"][wr]['"]\?>/g) {
  2785. $buff = substr($xmp, pos($xmp)); # save data after end of XMP
  2786. $xmp = substr($xmp, 0, pos($xmp)); # isolate XMP
  2787. # check XMP for validity (not valid if it contains null bytes)
  2788. $pos = rindex($xmp, "\0") + 1 or last;
  2789. $lastBuff = substr($xmp, $pos); # re-parse beginning after last null byte
  2790. undef $xmp;
  2791. } else {
  2792. undef $buff;
  2793. }
  2794. }
  2795. unless ($$et{VALUE}{FileType}) {
  2796. $$et{FILE_TYPE} = $$et{FILE_EXT};
  2797. $et->SetFileType('<unknown file containing XMP>', undef, '');
  2798. }
  2799. my %dirInfo = (
  2800. DataPt => \$xmp,
  2801. DirLen => length $xmp,
  2802. DataLen => length $xmp,
  2803. );
  2804. ProcessXMP($et, \%dirInfo);
  2805. return 1;
  2806. }
  2807. #------------------------------------------------------------------------------
  2808. # Print conversion for XMP-aux:LensID
  2809. # Inputs: 0) ExifTool ref, 1) LensID, 2) Make, 3) LensInfo, 4) FocalLength,
  2810. # 5) LensModel, 6) MaxApertureValue
  2811. # (yes, this is ugly -- blame Adobe)
  2812. sub PrintLensID(@)
  2813. {
  2814. local $_;
  2815. my ($et, $id, $make, $info, $focalLength, $lensModel, $maxAv) = @_;
  2816. my ($mk, $printConv);
  2817. my %alt = ( Pentax => 'Ricoh' ); # Pentax changed its name to Ricoh
  2818. # missing: Olympus (no XMP:LensID written by Adobe)
  2819. foreach $mk (qw(Canon Nikon Pentax Sony Sigma Samsung Leica)) {
  2820. next unless $make =~ /$mk/i or ($alt{$mk} and $make =~ /$alt{$mk}/i);
  2821. # get name of module containing the lens lookup (default "Make.pm")
  2822. my $mod = { Sigma => 'SigmaRaw', Leica => 'Panasonic' }->{$mk} || $mk;
  2823. require "Image/ExifTool/$mod.pm";
  2824. # get the name of the lens name lookup (default "makeLensTypes")
  2825. # (canonLensTypes, pentaxLensTypes, nikonLensIDs, etc)
  2826. my $convName = "Image::ExifTool::${mod}::" .
  2827. ({ Nikon => 'nikonLensIDs' }->{$mk} || lc($mk) . 'LensTypes');
  2828. no strict 'refs';
  2829. %$convName or last;
  2830. my $printConv = \%$convName;
  2831. use strict 'refs';
  2832. # sf = short focal
  2833. # lf = long focal
  2834. # sa = max aperture at short focal
  2835. # la = max aperture at long focal
  2836. my ($sf, $lf, $sa, $la);
  2837. if ($info) {
  2838. my @a = split ' ', $info;
  2839. $_ eq 'undef' and $_ = undef foreach @a;
  2840. ($sf, $lf, $sa, $la) = @a;
  2841. # for Sony and ambiguous LensID, $info data may be incorrect:
  2842. # use only if it agrees with $focalLength and $maxAv (ref JR)
  2843. if ($mk eq 'Sony' and
  2844. (($focalLength and (($sf and $focalLength < $sf - 0.5) or
  2845. ($lf and $focalLength > $lf + 0.5))) or
  2846. ($maxAv and (($sa and $maxAv < $sa - 0.15) or
  2847. ($la and $maxAv > $la + 0.15)))))
  2848. {
  2849. undef $sf;
  2850. undef $lf;
  2851. undef $sa;
  2852. undef $la;
  2853. } elsif ($maxAv) {
  2854. # (using the short-focal-length max aperture in place of MaxAperture
  2855. # is a bad approximation, so don't do this if MaxApertureValue exists)
  2856. undef $sa;
  2857. }
  2858. }
  2859. if ($mk eq 'Pentax' and $id =~ /^\d+$/) {
  2860. # for Pentax, CS4 stores an int16u, but we use 2 x int8u
  2861. $id = join(' ', unpack('C*', pack('n', $id)));
  2862. }
  2863. my $str = $$printConv{$id} || "Unknown ($id)";
  2864. # Nikon is a special case because Adobe doesn't store the full LensID
  2865. if ($mk eq 'Nikon') {
  2866. my $hex = sprintf("%.2X", $id);
  2867. my (%newConv, %used);
  2868. my $i = 0;
  2869. foreach (grep /^$hex /, keys %$printConv) {
  2870. my $lens = $$printConv{$_};
  2871. next if $used{$lens}; # avoid duplicates
  2872. $used{$lens} = 1;
  2873. $newConv{$i ? "$id.$i" : $id} = $lens;
  2874. ++$i;
  2875. }
  2876. $printConv = \%newConv;
  2877. }
  2878. return Image::ExifTool::Exif::PrintLensID($et, $str, $printConv,
  2879. undef, $id, $focalLength, $sa, $maxAv, $sf, $lf, $lensModel);
  2880. }
  2881. return "Unknown ($id)";
  2882. }
  2883. #------------------------------------------------------------------------------
  2884. # Convert XMP date/time to EXIF format
  2885. # Inputs: 0) XMP date/time string, 1) set if we aren't sure this is a date
  2886. # Returns: EXIF date/time
  2887. sub ConvertXMPDate($;$)
  2888. {
  2889. my ($val, $unsure) = @_;
  2890. if ($val =~ /^(\d{4})-(\d{2})-(\d{2})[T ](\d{2}:\d{2})(:\d{2})?\s*(\S*)$/) {
  2891. my $s = $5 || ''; # seconds may be missing
  2892. $val = "$1:$2:$3 $4$s$6"; # convert back to EXIF time format
  2893. } elsif (not $unsure and $val =~ /^(\d{4})(-\d{2}){0,2}/) {
  2894. $val =~ tr/-/:/;
  2895. }
  2896. return $val;
  2897. }
  2898. #------------------------------------------------------------------------------
  2899. # Convert rational string value
  2900. # Inputs: 0) string (converted to number, 'inf' or 'undef' on return if rational)
  2901. # Returns: true if value was converted
  2902. sub ConvertRational($)
  2903. {
  2904. my $val = $_[0];
  2905. $val =~ m{^(-?\d+)/(-?\d+)$} or return undef;
  2906. if ($2 != 0) {
  2907. $_[0] = $1 / $2; # calculate quotient
  2908. } elsif ($1) {
  2909. $_[0] = 'inf';
  2910. } else {
  2911. $_[0] = 'undef';
  2912. }
  2913. return 1;
  2914. }
  2915. #------------------------------------------------------------------------------
  2916. # Convert a string of floating point values to rationals
  2917. # Inputs: 0) string of floating point numbers separated by spaces
  2918. # Returns: string of rational numbers separated by spaces
  2919. sub ConvertRationalList($)
  2920. {
  2921. my $val = shift;
  2922. my @vals = split ' ', $val;
  2923. return $val unless @vals == 4;
  2924. foreach (@vals) {
  2925. ConvertRational($_) or return $val;
  2926. }
  2927. return join ' ', @vals;
  2928. }
  2929. #------------------------------------------------------------------------------
  2930. # We found an XMP property name/value
  2931. # Inputs: 0) ExifTool object ref, 1) Pointer to tag table
  2932. # 2) reference to array of XMP property names (last is current property)
  2933. # 3) property value, 4) attribute hash ref (for 'xml:lang' or 'rdf:datatype')
  2934. # Returns: 1 if valid tag was found
  2935. sub FoundXMP($$$$;$)
  2936. {
  2937. local $_;
  2938. my ($et, $tagTablePtr, $props, $val, $attrs) = @_;
  2939. my ($lang, @structProps, $rawVal, $rational);
  2940. my ($tag, $ns) = GetXMPTagID($props, $$et{OPTIONS}{Struct} ? \@structProps : undef);
  2941. return 0 unless $tag; # ignore things that aren't valid tags
  2942. # translate namespace if necessary
  2943. $ns = $stdXlatNS{$ns} if $stdXlatNS{$ns};
  2944. my $info = $$tagTablePtr{$ns};
  2945. my ($table, $added, $xns, $tagID);
  2946. if ($info) {
  2947. $table = $$info{SubDirectory}{TagTable} or warn "Missing TagTable for $tag!\n";
  2948. } elsif ($$props[0] eq 'svg:svg') {
  2949. if (not $ns) {
  2950. # disambiguate MetadataID by adding back the 'metadata' we ignored
  2951. $tag = 'metadataId' if $tag eq 'id' and $$props[1] eq 'svg:metadata';
  2952. # use SVG namespace in SVG files if nothing better to use
  2953. $table = 'Image::ExifTool::XMP::SVG';
  2954. } elsif (not grep /^rdf:/, @$props) {
  2955. # only other SVG information if not inside RDF (call it XMP if in RDF)
  2956. $table = 'Image::ExifTool::XMP::otherSVG';
  2957. }
  2958. }
  2959. if (not $ns and $$tagTablePtr{GROUPS}{0} ne 'XMP') {
  2960. # this is a simple XML table (no namespaces)
  2961. $tagID = $tag;
  2962. } else {
  2963. # look up this tag in the appropriate table
  2964. $table or $table = 'Image::ExifTool::XMP::other';
  2965. $tagTablePtr = GetTagTable($table);
  2966. if ($$tagTablePtr{NAMESPACE}) {
  2967. $tagID = $tag;
  2968. } else {
  2969. # add XMP namespace prefix to avoid collisions in variable-namespace tables
  2970. $xns = $xmpNS{$ns} || $ns;
  2971. $tagID = "$xns:$tag";
  2972. # add namespace to top-level structure property
  2973. $structProps[0][0] = "$xns:" . $structProps[0][0] if @structProps;
  2974. }
  2975. }
  2976. my $tagInfo = $et->GetTagInfo($tagTablePtr, $tagID);
  2977. $lang = $$attrs{'xml:lang'} if $attrs;
  2978. # must add a new tag table entry if this tag isn't pre-defined
  2979. # (or initialize from structure field if this is a pre-defined flattened tag)
  2980. NoLoop:
  2981. while (not $tagInfo or $$tagInfo{Flat}) {
  2982. my (@tagList, @nsList);
  2983. GetXMPTagID($props, \@tagList, \@nsList);
  2984. my ($ta, $t, $ti, $addedFlat, $i, $j);
  2985. # build tag ID strings for each level in the property path
  2986. foreach $ta (@tagList) {
  2987. # insert tag ID in index 1 of tagList list
  2988. $t = $$ta[1] = $t ? $t . ucfirst($$ta[0]) : $$ta[0];
  2989. # generate flattened tags for top-level structure if necessary
  2990. next if defined $addedFlat;
  2991. $ti = $$tagTablePtr{$t} or next;
  2992. next unless ref $ti eq 'HASH' and $$ti{Struct};
  2993. $addedFlat = AddFlattenedTags($tagTablePtr, $t);
  2994. if ($tagInfo) {
  2995. # all done if we just wanted to initialize the flattened tag
  2996. if ($$tagInfo{Flat}) {
  2997. warn "Orphan tagInfo with Flat flag set: $$tagInfo{Name}\n";
  2998. delete $$tagInfo{Flat};
  2999. }
  3000. last NoLoop;
  3001. }
  3002. # all done if we generated the tag we are looking for
  3003. $tagInfo = $$tagTablePtr{$tagID} and last NoLoop if $addedFlat;
  3004. }
  3005. my $name = ucfirst($tag);
  3006. # search for the innermost containing structure
  3007. # (in case tag is an unknown field in a known structure)
  3008. # (only necessary if we found a structure above)
  3009. if (defined $addedFlat) {
  3010. my $t2 = '';
  3011. for ($i=$#tagList-1; $i>=0; --$i) {
  3012. $t = $tagList[$i][1];
  3013. $t2 = $tagList[$i+1][0] . ucfirst($t2); # build relative tag id
  3014. $ti = $$tagTablePtr{$t} or next;
  3015. next unless ref $ti eq 'HASH';
  3016. my $strTable = $$ti{Struct} or next;
  3017. my $flat = (defined $$ti{FlatName} ? $$ti{FlatName} : $$ti{Name});
  3018. $name = $flat . ucfirst($t2);
  3019. # don't continue if structure is known but field is not
  3020. last if $$strTable{NAMESPACE} or not exists $$strTable{NAMESPACE};
  3021. # this is a variable-namespace structure, so we must:
  3022. # 1) get tagInfo from corresponding top-level XMP tag if it exists
  3023. # 2) add new entry in this tag table, but with namespace prefix on tag ID
  3024. my $n = $nsList[$i+1]; # namespace of structure field
  3025. # translate to standard ExifTool namespace
  3026. $n = $stdXlatNS{$n} if $stdXlatNS{$n};
  3027. my $xn = $xmpNS{$n} || $n; # standard XMP namespace
  3028. # no need to continue with variable-namespace logic if
  3029. # we are in our own namespace (right?)
  3030. last if $xn eq ($$tagTablePtr{NAMESPACE} || '');
  3031. $tagID = "$xn:$tag"; # add namespace to avoid collisions
  3032. # change structure properties to add the standard XMP namespace
  3033. # prefix for this field (needed for variable-namespace fields)
  3034. if (@structProps) {
  3035. $structProps[$i+1][0] = "$xn:" . $structProps[$i+1][0];
  3036. }
  3037. # copy tagInfo entries from the existing top-level XMP tag
  3038. my $tg = $Image::ExifTool::XMP::Main{$n};
  3039. last unless ref $tg eq 'HASH' and $$tg{SubDirectory};
  3040. my $tbl = GetTagTable($$tg{SubDirectory}{TagTable}) or last;
  3041. my $sti = $et->GetTagInfo($tbl, $t2);
  3042. if (not $sti or $$sti{Flat}) {
  3043. # again, we must initialize flattened tags if necessary
  3044. # (but don't bother to recursively apply full logic to
  3045. # allow nested variable-namespace strucures until someone
  3046. # actually wants to do such a silly thing)
  3047. my $t3 = '';
  3048. for ($j=$i+1; $j<@tagList; ++$j) {
  3049. $t3 = $tagList[$j][0] . ucfirst($t3);
  3050. my $ti3 = $$tbl{$t3} or next;
  3051. next unless ref $ti3 eq 'HASH' and $$ti3{Struct};
  3052. last unless AddFlattenedTags($tbl, $t3);
  3053. $sti = $$tbl{$t2};
  3054. last;
  3055. }
  3056. last unless $sti;
  3057. }
  3058. $tagInfo = {
  3059. %$sti,
  3060. Name => $flat . $$sti{Name},
  3061. WasAdded => 1,
  3062. };
  3063. # be careful not to copy elements we shouldn't...
  3064. delete $$tagInfo{Description}; # Description will be different
  3065. # can't copy group hash because group 1 will be different and
  3066. # we need to check this when writing tag to a specific group
  3067. delete $$tagInfo{Groups};
  3068. $$tagInfo{Groups}{2} = $$sti{Groups}{2} if $$sti{Groups};
  3069. last;
  3070. }
  3071. }
  3072. $tagInfo or $tagInfo = { Name => $name, WasAdded => 1 };
  3073. # add tag Namespace entry for tags in variable-namespace tables
  3074. $$tagInfo{Namespace} = $xns if $xns;
  3075. if ($$et{curURI}{$ns} and $$et{curURI}{$ns} =~ m{^http://ns.exiftool.ca/(.*?)/(.*?)/}) {
  3076. my %grps = ( 0 => $1, 1 => $2 );
  3077. # apply a little magic to recover original group names
  3078. # from this exiftool-written RDF/XML file
  3079. if ($grps{1} =~ /^\d/) {
  3080. # URI's with only family 0 are internal tags from the source file,
  3081. # so change the group name to avoid confusion with tags from this file
  3082. $grps{1} = "XML-$grps{0}";
  3083. $grps{0} = 'XML';
  3084. }
  3085. $$tagInfo{Groups} = \%grps;
  3086. # flag to avoid setting group 1 later
  3087. $$tagInfo{StaticGroup1} = 1;
  3088. }
  3089. # construct tag information for this unknown tag
  3090. # -> make this a List or lang-alt tag if necessary
  3091. if (@$props > 2 and $$props[-1] =~ /^rdf:li \d+$/ and
  3092. $$props[-2] =~ /^rdf:(Bag|Seq|Alt)$/)
  3093. {
  3094. if ($lang and $1 eq 'Alt') {
  3095. $$tagInfo{Writable} = 'lang-alt';
  3096. } else {
  3097. $$tagInfo{List} = $1;
  3098. }
  3099. # tried this, but maybe not a good idea for complex structures:
  3100. #} elsif (grep / /, @$props) {
  3101. # $$tagInfo{List} = 1;
  3102. }
  3103. AddTagToTable($tagTablePtr, $tagID, $tagInfo);
  3104. $added = 1;
  3105. last;
  3106. }
  3107. # decode value if necessary (et:encoding was used before exiftool 7.71)
  3108. if ($attrs) {
  3109. my $enc = $$attrs{'rdf:datatype'} || $$attrs{'et:encoding'};
  3110. if ($enc and $enc =~ /base64/) {
  3111. $val = DecodeBase64($val); # (now a value ref)
  3112. $val = $$val unless length $$val > 100 or $$val =~ /[\0-\x08\x0b\0x0c\x0e-\x1f]/;
  3113. }
  3114. }
  3115. if (defined $lang and lc($lang) ne 'x-default') {
  3116. $lang = StandardLangCase($lang);
  3117. my $langInfo = GetLangInfo($tagInfo, $lang);
  3118. $tagInfo = $langInfo if $langInfo;
  3119. }
  3120. # un-escape XML character entities (handling CDATA)
  3121. pos($val) = 0;
  3122. if ($val =~ /<!\[CDATA\[(.*?)\]\]>/sg) {
  3123. my $p = pos $val;
  3124. # unescape everything up to the start of the CDATA section
  3125. # (the length of "<[[CDATA[]]>" is 12 characters)
  3126. my $v = UnescapeXML(substr($val, 0, $p - length($1) - 12)) . $1;
  3127. while ($val =~ /<!\[CDATA\[(.*?)\]\]>/sg) {
  3128. my $p1 = pos $val;
  3129. $v .= UnescapeXML(substr($val, $p, $p1 - length($1) - 12)) . $1;
  3130. $p = $p1;
  3131. }
  3132. $val = $v . UnescapeXML(substr($val, $p));
  3133. } else {
  3134. $val = UnescapeXML($val);
  3135. }
  3136. # decode from UTF8
  3137. $val = $et->Decode($val, 'UTF8');
  3138. # convert rational and date values to a more sensible format
  3139. my $fmt = $$tagInfo{Writable};
  3140. my $new = $$tagInfo{WasAdded} && $$et{OPTIONS}{XMPAutoConv};
  3141. if ($fmt or $new) {
  3142. $rawVal = $val; # save raw value for verbose output
  3143. if (($new or $fmt eq 'rational') and ConvertRational($val)) {
  3144. $rational = $rawVal;
  3145. } else {
  3146. $val = ConvertXMPDate($val, $new) if $new or $fmt eq 'date';
  3147. }
  3148. # protect against large binary data in unknown tags
  3149. $$tagInfo{Binary} = 1 if $new and length($val) > 65536;
  3150. }
  3151. # store the value for this tag
  3152. my $key = $et->FoundTag($tagInfo, $val) or return 0;
  3153. # save original components of rational numbers (used when copying)
  3154. $$et{RATIONAL}{$key} = $rational if defined $rational;
  3155. # save structure/list information if necessary
  3156. if (@structProps and (@structProps > 1 or defined $structProps[0][1]) and
  3157. not $$et{NO_STRUCT})
  3158. {
  3159. $$et{TAG_EXTRA}{$key}{Struct} = \@structProps;
  3160. $$et{IsStruct} = 1;
  3161. }
  3162. if ($ns and not $$tagInfo{StaticGroup1}) {
  3163. # set group1 dynamically according to the namespace
  3164. $et->SetGroup($key, "$$tagTablePtr{GROUPS}{0}-$ns");
  3165. }
  3166. if ($$et{OPTIONS}{Verbose}) {
  3167. if ($added) {
  3168. my $g1 = $et->GetGroup($key, 1);
  3169. $et->VPrint(0, $$et{INDENT}, "[adding $g1:$tag]\n");
  3170. }
  3171. my $tagID = join('/',@$props);
  3172. $et->VerboseInfo($tagID, $tagInfo, Value => $rawVal || $val);
  3173. }
  3174. return 1;
  3175. }
  3176. #------------------------------------------------------------------------------
  3177. # Recursively parse nested XMP data element
  3178. # Inputs: 0) ExifTool ref, 1) tag table ref, 2) XMP data ref
  3179. # 3) offset to start of XMP element, 4) offset to end of XMP element
  3180. # 5) reference to array of enclosing XMP property names (undef if none)
  3181. # 6) reference to blank node information hash
  3182. # Returns: Number of contained XMP elements
  3183. sub ParseXMPElement($$$;$$$$)
  3184. {
  3185. my ($et, $tagTablePtr, $dataPt, $start, $end, $propListPt, $blankInfo) = @_;
  3186. my ($count, $nItems) = (0, 0);
  3187. my $isWriting = $$et{XMP_CAPTURE};
  3188. my $isSVG = $$et{XMP_IS_SVG};
  3189. my $saveNS; # save xlatNS lookup if changed for the scope of this element
  3190. # get our parse procs
  3191. my ($attrProc, $foundProc);
  3192. if ($$et{XMPParseOpts}) {
  3193. $attrProc = $$et{XMPParseOpts}{AttrProc};
  3194. $foundProc = $$et{XMPParseOpts}{FoundProc} || \&FoundXMP;
  3195. } else {
  3196. $foundProc = \&FoundXMP;
  3197. }
  3198. $start or $start = 0;
  3199. $end or $end = length $$dataPt;
  3200. $propListPt or $propListPt = [ ];
  3201. my $processBlankInfo;
  3202. # create empty blank node information hash if necessary
  3203. $blankInfo or $blankInfo = $processBlankInfo = { Prop => { } };
  3204. # keep track of current nodeID at this nesting level
  3205. my $oldNodeID = $$blankInfo{NodeID};
  3206. pos($$dataPt) = $start;
  3207. # lookup for translating namespace prefixes
  3208. my $xlatNS = $$et{xlatNS};
  3209. Element: for (;;) {
  3210. # all done if there isn't enough data for another element
  3211. # (the smallest possible element is 4 bytes, eg. "<a/>")
  3212. last if pos($$dataPt) > $end - 4;
  3213. # reset nodeID before processing each element
  3214. my $nodeID = $$blankInfo{NodeID} = $oldNodeID;
  3215. # get next element
  3216. last if $$dataPt !~ m{<([?/]?)([-\w:.\x80-\xff]+)([^>]*)>}sg or pos($$dataPt) > $end;
  3217. # (the only reason we match '<[?/]' is to keep from scanning past the
  3218. # "<?xpacket end..." terminator or other closing token, so
  3219. next if $1;
  3220. my ($prop, $attrs) = ($2, $3);
  3221. my $valStart = pos($$dataPt);
  3222. my $valEnd;
  3223. # only look for closing token if this is not an empty element
  3224. # (empty elements end with '/', eg. <a:b/>)
  3225. if ($attrs !~ s/\/$//) {
  3226. my $nesting = 1;
  3227. my $tok;
  3228. for (;;) {
  3229. # this match fails with perl 5.6.2 (perl bug!), but it works without
  3230. # the '(.*?)', so we must do it differently...
  3231. # $$dataPt =~ m/(.*?)<\/$prop>/sg or last Element;
  3232. # my $val2 = $1;
  3233. # find next matching closing token, or the next opening token
  3234. # of a nested same-named element
  3235. if ($$dataPt !~ m{<(/?)$prop([-\w:.\x80-\xff]*)(.*?(/?))>}sg or
  3236. pos($$dataPt) > $end)
  3237. {
  3238. $et->Warn("XMP format error (no closing tag for $prop)");
  3239. last Element;
  3240. }
  3241. next if $2; # ignore opening properties with different names
  3242. if ($1) {
  3243. next if --$nesting;
  3244. $valEnd = pos($$dataPt) - length($prop) - length($3) - 3;
  3245. last; # this element is complete
  3246. }
  3247. # this is a nested opening token (or empty element)
  3248. ++$nesting unless $4;
  3249. }
  3250. } else {
  3251. $valEnd = $valStart;
  3252. }
  3253. $start = pos($$dataPt); # start from here the next time around
  3254. # extract property attributes
  3255. my ($parseResource, %attrs, @attrs);
  3256. while ($attrs =~ m/(\S+?)\s*=\s*(['"])(.*?)\2/sg) {
  3257. my ($attr, $val) = ($1, $3);
  3258. # handle namespace prefixes (defined by xmlns:PREFIX, or used with PREFIX:tag)
  3259. if ($attr =~ /(.*?):/) {
  3260. if ($1 eq 'xmlns') {
  3261. my $ns = substr($attr, 6);
  3262. my $stdNS = $uri2ns{$val};
  3263. unless ($stdNS) {
  3264. my $try = $val;
  3265. # patch for Nikon NX2 URI bug for Microsoft PhotoInfo namespace
  3266. $try =~ s{/$}{} or $try .= '/';
  3267. $stdNS = $uri2ns{$try};
  3268. if ($stdNS) {
  3269. $val = $try;
  3270. $et->WarnOnce("Fixed incorrect URI for xmlns:$ns", 1);
  3271. } else {
  3272. # look for same namespace with different version number
  3273. $try = quotemeta $val; # (note: escapes slashes too)
  3274. $try =~ s{\\/\d+\\\.\d+(\\/|$)}{\\/\\d+\\\.\\d+$1};
  3275. my ($good) = grep /^$try$/, keys %uri2ns;
  3276. if ($good) {
  3277. $stdNS = $uri2ns{$good};
  3278. $et->VPrint(0, $$et{INDENT}, "[different $stdNS version: $val]\n");
  3279. }
  3280. }
  3281. }
  3282. # tame wild namespace prefixes (patches Microsoft stupidity)
  3283. my $newNS;
  3284. if ($stdNS) {
  3285. # use standard namespace prefix if pre-defined
  3286. if ($stdNS ne $ns) {
  3287. $newNS = $stdNS;
  3288. } elsif ($$xlatNS{$ns}) {
  3289. # this prefix is re-defined to the standard prefix in this scope
  3290. $newNS = '';
  3291. }
  3292. } elsif ($$et{curNS}{$val}) {
  3293. # use a consistent prefix over the entire XMP for a given namespace URI
  3294. $newNS = $$et{curNS}{$val} if $$et{curNS}{$val} ne $ns;
  3295. } else {
  3296. my $curURI = $$et{curURI};
  3297. my $curNS = $$et{curNS};
  3298. my $usedNS = $ns;
  3299. # use unique prefixes for all namespaces across the entire XMP
  3300. if ($$curURI{$ns} or $nsURI{$ns}) {
  3301. # generate a temporary namespace prefix to resolve any conflict
  3302. my $i = 0;
  3303. ++$i while $$curURI{"tmp$i"};
  3304. $newNS = $usedNS = "tmp$i";
  3305. }
  3306. # keep track of the namespace prefixes and URI's used in this XMP
  3307. $$curNS{$val} = $usedNS;
  3308. $$curURI{$usedNS} = $val;
  3309. }
  3310. if (defined $newNS) {
  3311. # save translation used in containing scope if necessary
  3312. # create new namespace translation for the scope of this element
  3313. $saveNS or $saveNS = $xlatNS, $xlatNS = $$et{xlatNS} = { %$xlatNS };
  3314. if (length $newNS) {
  3315. # use the new namespace prefix
  3316. $$xlatNS{$ns} = $newNS;
  3317. $attr = 'xmlns:' . $newNS;
  3318. } else {
  3319. delete $$xlatNS{$ns};
  3320. }
  3321. }
  3322. } elsif ($$xlatNS{$1}) {
  3323. $attr = $$xlatNS{$1} . substr($attr, length($1));
  3324. }
  3325. }
  3326. push @attrs, $attr; # preserve order
  3327. $attrs{$attr} = $val;
  3328. }
  3329. # tame wild namespace prefixes (patch for Microsoft stupidity)
  3330. if ($prop =~ /(.*?):/ and $$xlatNS{$1}) {
  3331. $prop = $$xlatNS{$1} . substr($prop, length($1));
  3332. }
  3333. if ($prop eq 'rdf:li') {
  3334. # impose a reasonable maximum on the number of items in a list
  3335. if ($nItems == 1000) {
  3336. my ($tg,$ns) = GetXMPTagID($propListPt);
  3337. if ($isWriting) {
  3338. $et->Warn("Excessive number of items for $ns:$tg. Processing may be slow", 1);
  3339. } elsif (not $$et{OPTIONS}{IgnoreMinorErrors}) {
  3340. $et->Warn("Extracted only 1000 $ns:$tg items. Ignore minor errors to extract all", 2);
  3341. last;
  3342. }
  3343. }
  3344. # add index to list items so we can keep them in order
  3345. # (this also enables us to keep structure elements grouped properly
  3346. # for lists of structures, like JobRef)
  3347. # Note: the list index is prefixed by the number of digits so sorting
  3348. # alphabetically gives the correct order while still allowing a flexible
  3349. # number of digits -- this scheme allows up to 9 digits in the index,
  3350. # with index numbers ranging from 0 to 999999999. The sequence is:
  3351. # 10,11,12-19,210,211-299,3100,3101-3999,41000...9999999999.
  3352. $prop .= ' ' . length($nItems) . $nItems;
  3353. # reset LIST_TAGS at the start of the outtermost list
  3354. # (avoids accumulating incorrectly-written elements in a correctly-written list)
  3355. if (not $nItems and not grep /^rdf:li /, @$propListPt) {
  3356. $$et{LIST_TAGS} = { };
  3357. }
  3358. ++$nItems;
  3359. } elsif ($prop eq 'rdf:Description') {
  3360. # remove unnecessary rdf:Description elements since parseType='Resource'
  3361. # is more efficient (also necessary to make property path consistent)
  3362. $parseResource = 1 if grep /^rdf:Description$/, @$propListPt;
  3363. } elsif ($prop eq 'xmp:xmpmeta') {
  3364. # patch MicrosoftPhoto unconformity
  3365. $prop = 'x:xmpmeta';
  3366. }
  3367. # hook for special parsing of attributes
  3368. my $val;
  3369. if ($attrProc) {
  3370. $val = substr($$dataPt, $valStart, $valEnd - $valStart);
  3371. if (&$attrProc(\@attrs, \%attrs, \$prop, \$val)) {
  3372. # the value was changed, so reset $valStart/$valEnd to use $val instead
  3373. $valStart = $valEnd;
  3374. }
  3375. }
  3376. # add nodeID to property path (with leading ' #') if it exists
  3377. if (defined $attrs{'rdf:nodeID'}) {
  3378. $nodeID = $$blankInfo{NodeID} = $attrs{'rdf:nodeID'};
  3379. delete $attrs{'rdf:nodeID'};
  3380. $prop .= ' #' . $nodeID;
  3381. undef $parseResource; # can't ignore if this is a node
  3382. }
  3383. # push this property name onto our hierarchy list
  3384. push @$propListPt, $prop unless $parseResource;
  3385. if ($isSVG) {
  3386. # ignore everything but top level SVG tags and metadata unless Unknown set
  3387. unless ($$et{OPTIONS}{Unknown} > 1 or $$et{OPTIONS}{Verbose}) {
  3388. if (@$propListPt > 1 and $$propListPt[1] !~ /\b(metadata|desc|title)$/) {
  3389. pop @$propListPt;
  3390. next;
  3391. }
  3392. }
  3393. if ($prop eq 'svg' or $prop eq 'metadata') {
  3394. # add svg namespace prefix if missing to ignore these entries in the tag name
  3395. $$propListPt[-1] = "svg:$prop";
  3396. }
  3397. }
  3398. # handle properties inside element attributes (RDF shorthand format):
  3399. # (attributes take the form a:b='c' or a:b="c")
  3400. my ($shortName, $shorthand, $ignored);
  3401. foreach $shortName (@attrs) {
  3402. next unless defined $attrs{$shortName};
  3403. my $propName = $shortName;
  3404. my ($ns, $name);
  3405. if ($propName =~ /(.*?):(.*)/) {
  3406. $ns = $1; # specified namespace
  3407. $name = $2;
  3408. } elsif ($prop =~ /(\S*?):/) {
  3409. $ns = $1; # assume same namespace as parent
  3410. $name = $propName;
  3411. $propName = "$ns:$name"; # generate full property name
  3412. } else {
  3413. # a property qualifier is the only property name that may not
  3414. # have a namespace, and a qualifier shouldn't have attributes,
  3415. # but what the heck, let's allow this anyway
  3416. $ns = '';
  3417. $name = $propName;
  3418. }
  3419. if ($isWriting) {
  3420. # keep track of our namespaces when writing
  3421. if ($ns eq 'xmlns') {
  3422. my $stdNS = $uri2ns{$attrs{$shortName}};
  3423. unless ($stdNS and ($stdNS eq 'x' or $stdNS eq 'iX')) {
  3424. my $nsUsed = $$et{XMP_NS};
  3425. $$nsUsed{$name} = $attrs{$shortName} unless defined $$nsUsed{$name};
  3426. }
  3427. delete $attrs{$shortName}; # (handled by namespace logic)
  3428. next;
  3429. } elsif ($recognizedAttrs{$propName}) {
  3430. # save UUID to use same ID when writing
  3431. if ($propName eq 'rdf:about') {
  3432. if (not $$et{XMP_ABOUT}) {
  3433. $$et{XMP_ABOUT} = $attrs{$shortName};
  3434. } elsif ($$et{XMP_ABOUT} ne $attrs{$shortName}) {
  3435. $et->Error("Different 'rdf:about' attributes not handled", 1);
  3436. }
  3437. }
  3438. next;
  3439. }
  3440. }
  3441. my $shortVal = $attrs{$shortName};
  3442. if ($ignoreNamespace{$ns} or $ignoreProp{$prop}) {
  3443. $ignored = $propName;
  3444. # handle special attributes (extract as tags only once if not empty)
  3445. if (ref $recognizedAttrs{$propName} and $shortVal) {
  3446. my ($tbl, $id, $name) = @{$recognizedAttrs{$propName}};
  3447. my $tval = UnescapeXML($shortVal);
  3448. unless (defined $$et{VALUE}{$name} and $$et{VALUE}{$name} eq $tval) {
  3449. $et->HandleTag(GetTagTable($tbl), $id, $tval);
  3450. }
  3451. }
  3452. next;
  3453. }
  3454. delete $attrs{$shortName}; # don't re-use this attribute
  3455. push @$propListPt, $propName;
  3456. # save this shorthand XMP property
  3457. if (defined $nodeID) {
  3458. SaveBlankInfo($blankInfo, $propListPt, $shortVal);
  3459. } elsif ($isWriting) {
  3460. CaptureXMP($et, $propListPt, $shortVal);
  3461. } else {
  3462. &$foundProc($et, $tagTablePtr, $propListPt, $shortVal);
  3463. }
  3464. pop @$propListPt;
  3465. $shorthand = 1;
  3466. }
  3467. if ($isWriting) {
  3468. if (ParseXMPElement($et, $tagTablePtr, $dataPt, $valStart, $valEnd,
  3469. $propListPt, $blankInfo))
  3470. {
  3471. # (no value since we found more properties within this one)
  3472. # set an error on any ignored attributes here, because they will be lost
  3473. $$et{XMP_ERROR} = "Can't handle XMP attribute '$ignored'" if $ignored;
  3474. } elsif (not $shorthand or $valEnd != $valStart) {
  3475. $val = substr($$dataPt, $valStart, $valEnd - $valStart);
  3476. # remove comments and whitespace from rdf:Description only
  3477. if ($prop eq 'rdf:Description') {
  3478. $val =~ s/<!--.*?-->//g; $val =~ s/^\s+//; $val =~ s/\s+$//;
  3479. }
  3480. if (defined $nodeID) {
  3481. SaveBlankInfo($blankInfo, $propListPt, $val, \%attrs);
  3482. } else {
  3483. CaptureXMP($et, $propListPt, $val, \%attrs);
  3484. }
  3485. }
  3486. } else {
  3487. # look for additional elements contained within this one
  3488. if ($valStart == $valEnd or
  3489. !ParseXMPElement($et, $tagTablePtr, $dataPt, $valStart, $valEnd,
  3490. $propListPt, $blankInfo))
  3491. {
  3492. my $wasEmpty;
  3493. unless (defined $val) {
  3494. $val = substr($$dataPt, $valStart, $valEnd - $valStart);
  3495. # remove comments and whitespace from rdf:Description only
  3496. if ($prop eq 'rdf:Description' and $val) {
  3497. $val =~ s/<!--.*?-->//g; $val =~ s/^\s+//; $val =~ s/\s+$//;
  3498. }
  3499. # if element value is empty, take value from 'resource' attribute
  3500. # (preferentially) or 'about' attribute (if no 'resource')
  3501. if ($val eq '' and ($attrs =~ /\bresource=(['"])(.*?)\1/ or
  3502. $attrs =~ /\babout=(['"])(.*?)\1/))
  3503. {
  3504. $val = $2;
  3505. $wasEmpty = 1;
  3506. }
  3507. }
  3508. # there are no contained elements, so this must be a simple property value
  3509. # (unless we already extracted shorthand values from this element)
  3510. if (length $val or not $shorthand) {
  3511. my $lastProp = $$propListPt[-1];
  3512. if (defined $nodeID) {
  3513. SaveBlankInfo($blankInfo, $propListPt, $val);
  3514. } elsif ($lastProp eq 'rdf:type' and $wasEmpty) {
  3515. # do not extract empty structure types (for now)
  3516. } elsif ($lastProp =~ /^et:(desc|prt|val)$/ and ($count or $1 eq 'desc')) {
  3517. # ignore et:desc, and et:val if preceded by et:prt
  3518. --$count;
  3519. } else {
  3520. &$foundProc($et, $tagTablePtr, $propListPt, $val, \%attrs);
  3521. }
  3522. }
  3523. }
  3524. }
  3525. pop @$propListPt unless $parseResource;
  3526. ++$count;
  3527. last if $start >= $end;
  3528. pos($$dataPt) = $start;
  3529. $$dataPt =~ /\G\s+/gc; # skip white space after closing token
  3530. }
  3531. #
  3532. # process resources referenced by blank nodeID's
  3533. #
  3534. if ($processBlankInfo and %{$$blankInfo{Prop}}) {
  3535. ProcessBlankInfo($et, $tagTablePtr, $blankInfo, $isWriting);
  3536. %$blankInfo = (); # free some memory
  3537. }
  3538. # restore namespace lookup from the containing scope
  3539. $$et{xlatNS} = $saveNS if $saveNS;
  3540. return $count; # return the number of elements found at this level
  3541. }
  3542. #------------------------------------------------------------------------------
  3543. # Process XMP data
  3544. # Inputs: 0) ExifTool object reference, 1) DirInfo reference, 2) Pointer to tag table
  3545. # Returns: 1 on success
  3546. # Notes: The following flavours of XMP files are currently recognized:
  3547. # - standard XMP with xpacket, x:xmpmeta and rdf:RDF elements
  3548. # - XMP that is missing the xpacket and/or x:xmpmeta elements
  3549. # - mutant Microsoft XMP with xmp:xmpmeta element
  3550. # - XML files beginning with "<xml"
  3551. # - SVG files that begin with "<svg" or "<!DOCTYPE svg"
  3552. # - XMP and XML files beginning with a UTF-8 byte order mark
  3553. # - UTF-8, UTF-16 and UTF-32 encoded XMP
  3554. # - erroneously double-UTF8 encoded XMP
  3555. # - otherwise valid files with leading XML comment
  3556. sub ProcessXMP($$;$)
  3557. {
  3558. my ($et, $dirInfo, $tagTablePtr) = @_;
  3559. my $dataPt = $$dirInfo{DataPt};
  3560. my ($dirStart, $dirLen, $dataLen, $double);
  3561. my ($buff, $fmt, $hasXMP, $isXML, $isRDF, $isSVG);
  3562. my $rtnVal = 0;
  3563. my $bom = 0;
  3564. # namespaces and prefixes currently in effect while parsing the file,
  3565. # and lookup to translate brain-dead-Microsoft-Photo-software prefixes
  3566. $$et{curURI} = { };
  3567. $$et{curNS} = { };
  3568. $$et{xlatNS} = { };
  3569. # ignore non-standard XMP while in strict MWG compatibility mode
  3570. if ($Image::ExifTool::MWG::strict and not $$et{XMP_CAPTURE} and
  3571. $$et{FILE_TYPE} =~ /^(JPEG|TIFF|PSD)$/)
  3572. {
  3573. my $path = $et->MetadataPath();
  3574. unless ($path =~ /^(JPEG-APP1-XMP|TIFF-IFD0-XMP|PSD-XMP)$/) {
  3575. $et->Warn("Ignored non-standard XMP at $path");
  3576. return 1;
  3577. }
  3578. }
  3579. if ($dataPt) {
  3580. $dirStart = $$dirInfo{DirStart} || 0;
  3581. $dirLen = $$dirInfo{DirLen} || (length($$dataPt) - $dirStart);
  3582. $dataLen = $$dirInfo{DataLen} || length($$dataPt);
  3583. # check leading BOM (may indicate double-encoded UTF)
  3584. pos($$dataPt) = $dirStart;
  3585. $double = $1 if $$dataPt =~ /\G((\0\0)?\xfe\xff|\xff\xfe(\0\0)?|\xef\xbb\xbf)\0*<\0*\?\0*x\0*p\0*a\0*c\0*k\0*e\0*t/g;
  3586. } else {
  3587. my ($type, $buf2, $buf3);
  3588. # read information from XMP file
  3589. my $raf = $$dirInfo{RAF} or return 0;
  3590. $raf->Read($buff, 256) or return 0;
  3591. ($buf2 = $buff) =~ tr/\0//d; # cheap conversion to UTF-8
  3592. # remove leading comments if they exist (eg. ImageIngester)
  3593. while ($buf2 =~ /^\s*<!--/) {
  3594. # remove the comment if it is complete
  3595. if ($buf2 =~ s/^\s*<!--.*?-->\s+//s) {
  3596. # continue with parsing if we have more than 128 bytes remaining
  3597. next if length $buf2 > 128;
  3598. } else {
  3599. # don't read more than 10k when looking for the end of comment
  3600. return 0 if length($buf2) > 10000;
  3601. }
  3602. $raf->Read($buf3, 256) or last; # read more data if available
  3603. $buff .= $buf3;
  3604. $buf3 =~ tr/\0//d;
  3605. $buf2 .= $buf3;
  3606. }
  3607. # check to see if this is XMP format
  3608. # (CS2 writes .XMP files without the "xpacket begin")
  3609. if ($buf2 =~ /^\s*(<\?xpacket begin=|<x(mp)?:x[ma]pmeta)/) {
  3610. $hasXMP = 1;
  3611. } else {
  3612. # also recognize XML files and .XMP files with BOM and without x:xmpmeta
  3613. if ($buf2 =~ /^(\xfe\xff)(<\?xml|<rdf:RDF|<x(mp)?:x[ma]pmeta)/g) {
  3614. $fmt = 'n'; # UTF-16 or 32 MM with BOM
  3615. } elsif ($buf2 =~ /^(\xff\xfe)(<\?xml|<rdf:RDF|<x(mp)?:x[ma]pmeta)/g) {
  3616. $fmt = 'v'; # UTF-16 or 32 II with BOM
  3617. } elsif ($buf2 =~ /^(\xef\xbb\xbf)?(<\?xml|<rdf:RDF|<x(mp)?:x[ma]pmeta)/g) {
  3618. $fmt = 0; # UTF-8 with BOM or unknown encoding without BOM
  3619. } elsif ($buf2 =~ /^(\xfe\xff|\xff\xfe|\xef\xbb\xbf)(<\?xpacket begin=)/g) {
  3620. $double = $1; # double-encoded UTF
  3621. } else {
  3622. return 0; # not recognized XMP or XML
  3623. }
  3624. $bom = 1 if $1;
  3625. if ($2 eq '<?xml') {
  3626. if (defined $fmt and not $fmt and $buf2 =~ /^[^\n\r]*[\n\r]+<\?aid /s) {
  3627. if ($$et{XMP_CAPTURE}) {
  3628. $et->Error("ExifTool does not yet support writing of INX files");
  3629. return 0;
  3630. }
  3631. $type = 'INX';
  3632. } elsif ($buf2 =~ /<x(mp)?:x[ma]pmeta/) {
  3633. $hasXMP = 1;
  3634. } else {
  3635. # identify SVG images and PLIST files by DOCTYPE if available
  3636. if ($buf2 =~ /<!DOCTYPE\s+(\w+)/) {
  3637. if ($1 eq 'svg') {
  3638. $isSVG = 1;
  3639. } elsif ($1 eq 'plist') {
  3640. $type = 'PLIST';
  3641. } else {
  3642. return 0;
  3643. }
  3644. } elsif ($buf2 =~ /<svg[\s>]/) {
  3645. $isSVG = 1;
  3646. } elsif ($buf2 =~ /<rdf:RDF/) {
  3647. $isRDF = 1;
  3648. } elsif ($buf2 =~ /<plist[\s>]/) {
  3649. $type = 'PLIST';
  3650. }
  3651. if ($isSVG and $$et{XMP_CAPTURE}) {
  3652. $et->Error("ExifTool does not yet support writing of SVG images");
  3653. return 0;
  3654. }
  3655. }
  3656. $isXML = 1;
  3657. } elsif ($2 eq '<rdf:RDF') {
  3658. $isRDF = 1; # recognize XMP without x:xmpmeta element
  3659. }
  3660. if ($buff =~ /^\0\0/) {
  3661. $fmt = 'N'; # UTF-32 MM with or without BOM
  3662. } elsif ($buff =~ /^..\0\0/s) {
  3663. $fmt = 'V'; # UTF-32 II with or without BOM
  3664. } elsif (not $fmt) {
  3665. if ($buff =~ /^\0/) {
  3666. $fmt = 'n'; # UTF-16 MM without BOM
  3667. } elsif ($buff =~ /^.\0/s) {
  3668. $fmt = 'v'; # UTF-16 II without BOM
  3669. }
  3670. }
  3671. }
  3672. my $size;
  3673. if ($type) {
  3674. if ($type eq 'PLIST') {
  3675. my $ext = $$et{FILE_EXT};
  3676. $type = $ext if $ext and $ext eq 'MODD';
  3677. $tagTablePtr = GetTagTable('Image::ExifTool::PLIST::Main');
  3678. $$dirInfo{XMPParseOpts}{FoundProc} = \&Image::ExifTool::PLIST::FoundTag;
  3679. }
  3680. } else {
  3681. if ($isSVG) {
  3682. $type = 'SVG';
  3683. } elsif ($isXML and not $hasXMP and not $isRDF) {
  3684. $type = 'XML';
  3685. my $ext = $$et{FILE_EXT};
  3686. $type = $ext if $ext and $ext eq 'COS'; # recognize COS by extension
  3687. }
  3688. }
  3689. $et->SetFileType($type);
  3690. my $fast = $et->Options('FastScan');
  3691. return 1 if $fast and $fast == 3;
  3692. if ($type and $type eq 'INX') {
  3693. # brute force search for first XMP packet in INX file
  3694. # start: '<![CDATA[<?xpacket begin' (24 bytes)
  3695. # end: '<?xpacket end="r"?>]]>' (22 bytes)
  3696. $raf->Seek(0, 0) or return 0;
  3697. $raf->Read($buff, 65536) or return 1;
  3698. for (;;) {
  3699. last if $buff =~ /<!\[CDATA\[<\?xpacket begin/g;
  3700. $raf->Read($buf2, 65536) or return 1;
  3701. $buff = substr($buff, -24) . $buf2;
  3702. }
  3703. $buff = substr($buff, pos($buff) - 15); # (discard '<![CDATA[' and before)
  3704. for (;;) {
  3705. last if $buff =~ /<\?xpacket end="[rw]"\?>\]\]>/g;
  3706. my $n = length $buff;
  3707. $raf->Read($buf2, 65536) or $et->Warn('Missing xpacket end'), return 1;
  3708. $buff .= $buf2;
  3709. pos($buff) = $n - 22; # don't miss end pattern if it was split
  3710. }
  3711. $size = pos($buff) - 3; # (discard ']]>' and after)
  3712. $buff = substr($buff, 0, $size);
  3713. } else {
  3714. # read the entire file
  3715. $raf->Seek(0, 2) or return 0;
  3716. $size = $raf->Tell() or return 0;
  3717. $raf->Seek(0, 0) or return 0;
  3718. $raf->Read($buff, $size) == $size or return 0;
  3719. }
  3720. $dataPt = \$buff;
  3721. $dirStart = 0;
  3722. $dirLen = $dataLen = $size;
  3723. }
  3724. # decode the first layer of double-encoded UTF text (if necessary)
  3725. if ($double) {
  3726. my ($buf2, $fmt);
  3727. $buff = substr($$dataPt, $dirStart + length $double); # remove leading BOM
  3728. Image::ExifTool::SetWarning(undef); # clear old warning
  3729. local $SIG{'__WARN__'} = \&Image::ExifTool::SetWarning;
  3730. # assume that character data has been re-encoded in UTF, so re-pack
  3731. # as characters and look for warnings indicating a false assumption
  3732. if ($double eq "\xef\xbb\xbf") {
  3733. require Image::ExifTool::Charset;
  3734. my $uni = Image::ExifTool::Charset::Decompose(undef,$buff,'UTF8');
  3735. $buf2 = pack('C*', @$uni);
  3736. } else {
  3737. if (length($double) == 2) {
  3738. $fmt = ($double eq "\xfe\xff") ? 'n' : 'v';
  3739. } else {
  3740. $fmt = ($double eq "\0\0\xfe\xff") ? 'N' : 'V';
  3741. }
  3742. $buf2 = pack('C*', unpack("$fmt*",$buff));
  3743. }
  3744. if (Image::ExifTool::GetWarning()) {
  3745. $et->Warn('Superfluous BOM at start of XMP');
  3746. $dataPt = \$buff; # use XMP with the BOM removed
  3747. } else {
  3748. $et->Warn('XMP is double UTF-encoded');
  3749. $dataPt = \$buf2; # use the decoded XMP
  3750. }
  3751. $dirStart = 0;
  3752. $dirLen = $dataLen = length $$dataPt;
  3753. }
  3754. # extract XMP as a block if specified
  3755. my $blockName = $$dirInfo{BlockInfo} ? $$dirInfo{BlockInfo}{Name} : 'XMP';
  3756. if (($$et{REQ_TAG_LOOKUP}{lc $blockName} or ($$et{TAGS_FROM_FILE} and
  3757. not $$et{EXCL_TAG_LOOKUP}{lc $blockName})) and not $isSVG)
  3758. {
  3759. $et->FoundTag($$dirInfo{BlockInfo} || 'XMP', substr($$dataPt, $dirStart, $dirLen));
  3760. }
  3761. $tagTablePtr or $tagTablePtr = GetTagTable('Image::ExifTool::XMP::Main');
  3762. if ($et->Options('Verbose') and not $$et{XMP_CAPTURE}) {
  3763. my $dirType = $isSVG ? 'SVG' : $$tagTablePtr{GROUPS}{1};
  3764. $et->VerboseDir($dirType, 0, $dirLen);
  3765. }
  3766. #
  3767. # convert UTF-16 or UTF-32 encoded XMP to UTF-8 if necessary
  3768. #
  3769. my $begin = '<?xpacket begin=';
  3770. my $dirEnd = $dirStart + $dirLen;
  3771. pos($$dataPt) = $dirStart;
  3772. delete $$et{XMP_IS_XML};
  3773. delete $$et{XMP_IS_SVG};
  3774. if ($isXML or $isRDF) {
  3775. $$et{XMP_IS_XML} = $isXML;
  3776. $$et{XMP_IS_SVG} = $isSVG;
  3777. $$et{XMP_NO_XPACKET} = 1 + $bom;
  3778. } elsif ($$dataPt =~ /\G\Q$begin\E/gc) {
  3779. delete $$et{XMP_NO_XPACKET};
  3780. } elsif ($$dataPt =~ /<x(mp)?:x[ma]pmeta/gc and
  3781. pos($$dataPt) > $dirStart and pos($$dataPt) < $dirEnd)
  3782. {
  3783. $$et{XMP_NO_XPACKET} = 1 + $bom;
  3784. } else {
  3785. delete $$et{XMP_NO_XPACKET};
  3786. # check for UTF-16 encoding (insert one \0 between characters)
  3787. $begin = join "\0", split //, $begin;
  3788. # must reset pos because it was killed by previous unsuccessful //g match
  3789. pos($$dataPt) = $dirStart;
  3790. if ($$dataPt =~ /\G(\0)?\Q$begin\E\0./sg) {
  3791. # validate byte ordering by checking for U+FEFF character
  3792. if ($1) {
  3793. # should be big-endian since we had a leading \0
  3794. $fmt = 'n' if $$dataPt =~ /\G\xfe\xff/g;
  3795. } else {
  3796. $fmt = 'v' if $$dataPt =~ /\G\0\xff\xfe/g;
  3797. }
  3798. } else {
  3799. # check for UTF-32 encoding (with three \0's between characters)
  3800. $begin =~ s/\0/\0\0\0/g;
  3801. pos($$dataPt) = $dirStart;
  3802. if ($$dataPt !~ /\G(\0\0\0)?\Q$begin\E\0\0\0./sg) {
  3803. $fmt = 0; # set format to zero as indication we didn't find encoded XMP
  3804. } elsif ($1) {
  3805. # should be big-endian
  3806. $fmt = 'N' if $$dataPt =~ /\G\0\0\xfe\xff/g;
  3807. } else {
  3808. $fmt = 'V' if $$dataPt =~ /\G\0\0\0\xff\xfe\0\0/g;
  3809. }
  3810. }
  3811. defined $fmt or $et->Warn('XMP character encoding error');
  3812. }
  3813. if ($fmt) {
  3814. # trim if necessary to avoid converting non-UTF data
  3815. if ($dirStart or $dirEnd != length($$dataPt)) {
  3816. $buff = substr($$dataPt, $dirStart, $dirLen);
  3817. $dataPt = \$buff;
  3818. }
  3819. # convert into UTF-8
  3820. if ($] >= 5.006001) {
  3821. $buff = pack('C0U*', unpack("$fmt*",$$dataPt));
  3822. } else {
  3823. $buff = Image::ExifTool::PackUTF8(unpack("$fmt*",$$dataPt));
  3824. }
  3825. $dataPt = \$buff;
  3826. $dirStart = 0;
  3827. $dirLen = length $$dataPt;
  3828. $dirEnd = $dirStart + $dirLen;
  3829. }
  3830. # avoid scanning for XMP later in case ScanForXMP is set
  3831. $$et{FoundXMP} = 1 if $tagTablePtr eq \%Image::ExifTool::XMP::Main;
  3832. # set XMP parsing options
  3833. $$et{XMPParseOpts} = $$dirInfo{XMPParseOpts};
  3834. # ignore any specified properties (XML hack)
  3835. if ($$dirInfo{IgnoreProp}) {
  3836. %ignoreProp = %{$$dirInfo{IgnoreProp}};
  3837. } else {
  3838. undef %ignoreProp;
  3839. }
  3840. # need to preserve list indices to be able to handle multi-dimensional lists
  3841. my $keepFlat;
  3842. if ($$et{OPTIONS}{Struct}) {
  3843. if ($$et{OPTIONS}{Struct} eq '2') {
  3844. $keepFlat = 1; # preserve flattened tags
  3845. # setting NO_LIST to 0 combines list items in a TAG_EXTRA "NoList" element
  3846. # to allow them to be re-listed later if necessary. A "NoListDel" element
  3847. # is also created for tags that wouldn't have existed.
  3848. $$et{NO_LIST} = 0;
  3849. } else {
  3850. $$et{NO_LIST} = 1;
  3851. }
  3852. }
  3853. # don't generate structures if this isn't real XMP
  3854. $$et{NO_STRUCT} = 1 if $$dirInfo{BlockInfo} or $$dirInfo{NoStruct};
  3855. # parse the XMP
  3856. if (ParseXMPElement($et, $tagTablePtr, $dataPt, $dirStart, $dirEnd)) {
  3857. $rtnVal = 1;
  3858. } elsif ($$dirInfo{DirName} and $$dirInfo{DirName} eq 'XMP') {
  3859. # if DirName was 'XMP' we expect well-formed XMP, so set Warning since it wasn't
  3860. # (but allow empty XMP as written by some PhaseOne cameras)
  3861. my $xmp = substr($$dataPt, $dirStart, $dirLen);
  3862. if ($xmp =~ /^ *\0*$/) {
  3863. $et->Warn('Invalid XMP');
  3864. } else {
  3865. $et->Warn('Empty XMP',1);
  3866. $rtnVal = 1;
  3867. }
  3868. }
  3869. delete $$et{NO_STRUCT};
  3870. # return DataPt if successful in case we want it for writing
  3871. $$dirInfo{DataPt} = $dataPt if $rtnVal and $$dirInfo{RAF};
  3872. # restore structures if necessary
  3873. if ($$et{IsStruct}) {
  3874. require 'Image/ExifTool/XMPStruct.pl';
  3875. RestoreStruct($et, $keepFlat);
  3876. delete $$et{IsStruct};
  3877. }
  3878. # reset NO_LIST flag (must do this _after_ RestoreStruct() above)
  3879. delete $$et{NO_LIST};
  3880. delete $$et{XMPParseOpts};
  3881. delete $$et{curURI};
  3882. delete $$et{curNS};
  3883. delete $$et{xlatNS};
  3884. return $rtnVal;
  3885. }
  3886. 1; #end
  3887. __END__
  3888. =head1 NAME
  3889. Image::ExifTool::XMP - Read XMP meta information
  3890. =head1 SYNOPSIS
  3891. This module is loaded automatically by Image::ExifTool when required.
  3892. =head1 DESCRIPTION
  3893. XMP stands for Extensible Metadata Platform. It is a format based on XML
  3894. that Adobe developed for embedding metadata information in image files.
  3895. This module contains the definitions required by Image::ExifTool to read XMP
  3896. information.
  3897. =head1 AUTHOR
  3898. Copyright 2003-2016, Phil Harvey (phil at owl.phy.queensu.ca)
  3899. This library is free software; you can redistribute it and/or modify it
  3900. under the same terms as Perl itself.
  3901. =head1 REFERENCES
  3902. =over 4
  3903. =item L<http://www.adobe.com/devnet/xmp/>
  3904. =item L<http://www.w3.org/TR/rdf-syntax-grammar/>
  3905. =item L<http://www.iptc.org/IPTC4XMP/>
  3906. =back
  3907. =head1 SEE ALSO
  3908. L<Image::ExifTool::TagNames/XMP Tags>,
  3909. L<Image::ExifTool(3pm)|Image::ExifTool>
  3910. =cut