index.ts 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320
  1. // @ts-nocheck
  2. // 源于piexifjs
  3. import { cloneDeep } from '../cloneDeep'
  4. import { isString } from '../isString'
  5. const TAGS = {
  6. 'Image': {
  7. 11: {
  8. 'name': 'ProcessingSoftware',
  9. 'type': 'Ascii'
  10. },
  11. 254: {
  12. 'name': 'NewSubfileType',
  13. 'type': 'Long'
  14. },
  15. 255: {
  16. 'name': 'SubfileType',
  17. 'type': 'Short'
  18. },
  19. 256: {
  20. 'name': 'ImageWidth',
  21. 'type': 'Long'
  22. },
  23. 257: {
  24. 'name': 'ImageLength',
  25. 'type': 'Long'
  26. },
  27. 258: {
  28. 'name': 'BitsPerSample',
  29. 'type': 'Short'
  30. },
  31. 259: {
  32. 'name': 'Compression',
  33. 'type': 'Short'
  34. },
  35. 262: {
  36. 'name': 'PhotometricInterpretation',
  37. 'type': 'Short'
  38. },
  39. 263: {
  40. 'name': 'Threshholding',
  41. 'type': 'Short'
  42. },
  43. 264: {
  44. 'name': 'CellWidth',
  45. 'type': 'Short'
  46. },
  47. 265: {
  48. 'name': 'CellLength',
  49. 'type': 'Short'
  50. },
  51. 266: {
  52. 'name': 'FillOrder',
  53. 'type': 'Short'
  54. },
  55. 269: {
  56. 'name': 'DocumentName',
  57. 'type': 'Ascii'
  58. },
  59. 270: {
  60. 'name': 'ImageDescription',
  61. 'type': 'Ascii'
  62. },
  63. 271: {
  64. 'name': 'Make',
  65. 'type': 'Ascii'
  66. },
  67. 272: {
  68. 'name': 'Model',
  69. 'type': 'Ascii'
  70. },
  71. 273: {
  72. 'name': 'StripOffsets',
  73. 'type': 'Long'
  74. },
  75. 274: {
  76. 'name': 'Orientation',
  77. 'type': 'Short'
  78. },
  79. 277: {
  80. 'name': 'SamplesPerPixel',
  81. 'type': 'Short'
  82. },
  83. 278: {
  84. 'name': 'RowsPerStrip',
  85. 'type': 'Long'
  86. },
  87. 279: {
  88. 'name': 'StripByteCounts',
  89. 'type': 'Long'
  90. },
  91. 282: {
  92. 'name': 'XResolution',
  93. 'type': 'Rational'
  94. },
  95. 283: {
  96. 'name': 'YResolution',
  97. 'type': 'Rational'
  98. },
  99. 284: {
  100. 'name': 'PlanarConfiguration',
  101. 'type': 'Short'
  102. },
  103. 290: {
  104. 'name': 'GrayResponseUnit',
  105. 'type': 'Short'
  106. },
  107. 291: {
  108. 'name': 'GrayResponseCurve',
  109. 'type': 'Short'
  110. },
  111. 292: {
  112. 'name': 'T4Options',
  113. 'type': 'Long'
  114. },
  115. 293: {
  116. 'name': 'T6Options',
  117. 'type': 'Long'
  118. },
  119. 296: {
  120. 'name': 'ResolutionUnit',
  121. 'type': 'Short'
  122. },
  123. 301: {
  124. 'name': 'TransferFunction',
  125. 'type': 'Short'
  126. },
  127. 305: {
  128. 'name': 'Software',
  129. 'type': 'Ascii'
  130. },
  131. 306: {
  132. 'name': 'DateTime',
  133. 'type': 'Ascii'
  134. },
  135. 315: {
  136. 'name': 'Artist',
  137. 'type': 'Ascii'
  138. },
  139. 316: {
  140. 'name': 'HostComputer',
  141. 'type': 'Ascii'
  142. },
  143. 317: {
  144. 'name': 'Predictor',
  145. 'type': 'Short'
  146. },
  147. 318: {
  148. 'name': 'WhitePoint',
  149. 'type': 'Rational'
  150. },
  151. 319: {
  152. 'name': 'PrimaryChromaticities',
  153. 'type': 'Rational'
  154. },
  155. 320: {
  156. 'name': 'ColorMap',
  157. 'type': 'Short'
  158. },
  159. 321: {
  160. 'name': 'HalftoneHints',
  161. 'type': 'Short'
  162. },
  163. 322: {
  164. 'name': 'TileWidth',
  165. 'type': 'Short'
  166. },
  167. 323: {
  168. 'name': 'TileLength',
  169. 'type': 'Short'
  170. },
  171. 324: {
  172. 'name': 'TileOffsets',
  173. 'type': 'Short'
  174. },
  175. 325: {
  176. 'name': 'TileByteCounts',
  177. 'type': 'Short'
  178. },
  179. 330: {
  180. 'name': 'SubIFDs',
  181. 'type': 'Long'
  182. },
  183. 332: {
  184. 'name': 'InkSet',
  185. 'type': 'Short'
  186. },
  187. 333: {
  188. 'name': 'InkNames',
  189. 'type': 'Ascii'
  190. },
  191. 334: {
  192. 'name': 'NumberOfInks',
  193. 'type': 'Short'
  194. },
  195. 336: {
  196. 'name': 'DotRange',
  197. 'type': 'Byte'
  198. },
  199. 337: {
  200. 'name': 'TargetPrinter',
  201. 'type': 'Ascii'
  202. },
  203. 338: {
  204. 'name': 'ExtraSamples',
  205. 'type': 'Short'
  206. },
  207. 339: {
  208. 'name': 'SampleFormat',
  209. 'type': 'Short'
  210. },
  211. 340: {
  212. 'name': 'SMinSampleValue',
  213. 'type': 'Short'
  214. },
  215. 341: {
  216. 'name': 'SMaxSampleValue',
  217. 'type': 'Short'
  218. },
  219. 342: {
  220. 'name': 'TransferRange',
  221. 'type': 'Short'
  222. },
  223. 343: {
  224. 'name': 'ClipPath',
  225. 'type': 'Byte'
  226. },
  227. 344: {
  228. 'name': 'XClipPathUnits',
  229. 'type': 'Long'
  230. },
  231. 345: {
  232. 'name': 'YClipPathUnits',
  233. 'type': 'Long'
  234. },
  235. 346: {
  236. 'name': 'Indexed',
  237. 'type': 'Short'
  238. },
  239. 347: {
  240. 'name': 'JPEGTables',
  241. 'type': 'Undefined'
  242. },
  243. 351: {
  244. 'name': 'OPIProxy',
  245. 'type': 'Short'
  246. },
  247. 512: {
  248. 'name': 'JPEGProc',
  249. 'type': 'Long'
  250. },
  251. 513: {
  252. 'name': 'JPEGInterchangeFormat',
  253. 'type': 'Long'
  254. },
  255. 514: {
  256. 'name': 'JPEGInterchangeFormatLength',
  257. 'type': 'Long'
  258. },
  259. 515: {
  260. 'name': 'JPEGRestartInterval',
  261. 'type': 'Short'
  262. },
  263. 517: {
  264. 'name': 'JPEGLosslessPredictors',
  265. 'type': 'Short'
  266. },
  267. 518: {
  268. 'name': 'JPEGPointTransforms',
  269. 'type': 'Short'
  270. },
  271. 519: {
  272. 'name': 'JPEGQTables',
  273. 'type': 'Long'
  274. },
  275. 520: {
  276. 'name': 'JPEGDCTables',
  277. 'type': 'Long'
  278. },
  279. 521: {
  280. 'name': 'JPEGACTables',
  281. 'type': 'Long'
  282. },
  283. 529: {
  284. 'name': 'YCbCrCoefficients',
  285. 'type': 'Rational'
  286. },
  287. 530: {
  288. 'name': 'YCbCrSubSampling',
  289. 'type': 'Short'
  290. },
  291. 531: {
  292. 'name': 'YCbCrPositioning',
  293. 'type': 'Short'
  294. },
  295. 532: {
  296. 'name': 'ReferenceBlackWhite',
  297. 'type': 'Rational'
  298. },
  299. 700: {
  300. 'name': 'XMLPacket',
  301. 'type': 'Byte'
  302. },
  303. 18246: {
  304. 'name': 'Rating',
  305. 'type': 'Short'
  306. },
  307. 18249: {
  308. 'name': 'RatingPercent',
  309. 'type': 'Short'
  310. },
  311. 32781: {
  312. 'name': 'ImageID',
  313. 'type': 'Ascii'
  314. },
  315. 33421: {
  316. 'name': 'CFARepeatPatternDim',
  317. 'type': 'Short'
  318. },
  319. 33422: {
  320. 'name': 'CFAPattern',
  321. 'type': 'Byte'
  322. },
  323. 33423: {
  324. 'name': 'BatteryLevel',
  325. 'type': 'Rational'
  326. },
  327. 33432: {
  328. 'name': 'Copyright',
  329. 'type': 'Ascii'
  330. },
  331. 33434: {
  332. 'name': 'ExposureTime',
  333. 'type': 'Rational'
  334. },
  335. 34377: {
  336. 'name': 'ImageResources',
  337. 'type': 'Byte'
  338. },
  339. 34665: {
  340. 'name': 'ExifTag',
  341. 'type': 'Long'
  342. },
  343. 34675: {
  344. 'name': 'InterColorProfile',
  345. 'type': 'Undefined'
  346. },
  347. 34853: {
  348. 'name': 'GPSTag',
  349. 'type': 'Long'
  350. },
  351. 34857: {
  352. 'name': 'Interlace',
  353. 'type': 'Short'
  354. },
  355. 34858: {
  356. 'name': 'TimeZoneOffset',
  357. 'type': 'Long'
  358. },
  359. 34859: {
  360. 'name': 'SelfTimerMode',
  361. 'type': 'Short'
  362. },
  363. 37387: {
  364. 'name': 'FlashEnergy',
  365. 'type': 'Rational'
  366. },
  367. 37388: {
  368. 'name': 'SpatialFrequencyResponse',
  369. 'type': 'Undefined'
  370. },
  371. 37389: {
  372. 'name': 'Noise',
  373. 'type': 'Undefined'
  374. },
  375. 37390: {
  376. 'name': 'FocalPlaneXResolution',
  377. 'type': 'Rational'
  378. },
  379. 37391: {
  380. 'name': 'FocalPlaneYResolution',
  381. 'type': 'Rational'
  382. },
  383. 37392: {
  384. 'name': 'FocalPlaneResolutionUnit',
  385. 'type': 'Short'
  386. },
  387. 37393: {
  388. 'name': 'ImageNumber',
  389. 'type': 'Long'
  390. },
  391. 37394: {
  392. 'name': 'SecurityClassification',
  393. 'type': 'Ascii'
  394. },
  395. 37395: {
  396. 'name': 'ImageHistory',
  397. 'type': 'Ascii'
  398. },
  399. 37397: {
  400. 'name': 'ExposureIndex',
  401. 'type': 'Rational'
  402. },
  403. 37398: {
  404. 'name': 'TIFFEPStandardID',
  405. 'type': 'Byte'
  406. },
  407. 37399: {
  408. 'name': 'SensingMethod',
  409. 'type': 'Short'
  410. },
  411. 40091: {
  412. 'name': 'XPTitle',
  413. 'type': 'Byte'
  414. },
  415. 40092: {
  416. 'name': 'XPComment',
  417. 'type': 'Byte'
  418. },
  419. 40093: {
  420. 'name': 'XPAuthor',
  421. 'type': 'Byte'
  422. },
  423. 40094: {
  424. 'name': 'XPKeywords',
  425. 'type': 'Byte'
  426. },
  427. 40095: {
  428. 'name': 'XPSubject',
  429. 'type': 'Byte'
  430. },
  431. 50341: {
  432. 'name': 'PrintImageMatching',
  433. 'type': 'Undefined'
  434. },
  435. 50706: {
  436. 'name': 'DNGVersion',
  437. 'type': 'Byte'
  438. },
  439. 50707: {
  440. 'name': 'DNGBackwardVersion',
  441. 'type': 'Byte'
  442. },
  443. 50708: {
  444. 'name': 'UniqueCameraModel',
  445. 'type': 'Ascii'
  446. },
  447. 50709: {
  448. 'name': 'LocalizedCameraModel',
  449. 'type': 'Byte'
  450. },
  451. 50710: {
  452. 'name': 'CFAPlaneColor',
  453. 'type': 'Byte'
  454. },
  455. 50711: {
  456. 'name': 'CFALayout',
  457. 'type': 'Short'
  458. },
  459. 50712: {
  460. 'name': 'LinearizationTable',
  461. 'type': 'Short'
  462. },
  463. 50713: {
  464. 'name': 'BlackLevelRepeatDim',
  465. 'type': 'Short'
  466. },
  467. 50714: {
  468. 'name': 'BlackLevel',
  469. 'type': 'Rational'
  470. },
  471. 50715: {
  472. 'name': 'BlackLevelDeltaH',
  473. 'type': 'SRational'
  474. },
  475. 50716: {
  476. 'name': 'BlackLevelDeltaV',
  477. 'type': 'SRational'
  478. },
  479. 50717: {
  480. 'name': 'WhiteLevel',
  481. 'type': 'Short'
  482. },
  483. 50718: {
  484. 'name': 'DefaultScale',
  485. 'type': 'Rational'
  486. },
  487. 50719: {
  488. 'name': 'DefaultCropOrigin',
  489. 'type': 'Short'
  490. },
  491. 50720: {
  492. 'name': 'DefaultCropSize',
  493. 'type': 'Short'
  494. },
  495. 50721: {
  496. 'name': 'ColorMatrix1',
  497. 'type': 'SRational'
  498. },
  499. 50722: {
  500. 'name': 'ColorMatrix2',
  501. 'type': 'SRational'
  502. },
  503. 50723: {
  504. 'name': 'CameraCalibration1',
  505. 'type': 'SRational'
  506. },
  507. 50724: {
  508. 'name': 'CameraCalibration2',
  509. 'type': 'SRational'
  510. },
  511. 50725: {
  512. 'name': 'ReductionMatrix1',
  513. 'type': 'SRational'
  514. },
  515. 50726: {
  516. 'name': 'ReductionMatrix2',
  517. 'type': 'SRational'
  518. },
  519. 50727: {
  520. 'name': 'AnalogBalance',
  521. 'type': 'Rational'
  522. },
  523. 50728: {
  524. 'name': 'AsShotNeutral',
  525. 'type': 'Short'
  526. },
  527. 50729: {
  528. 'name': 'AsShotWhiteXY',
  529. 'type': 'Rational'
  530. },
  531. 50730: {
  532. 'name': 'BaselineExposure',
  533. 'type': 'SRational'
  534. },
  535. 50731: {
  536. 'name': 'BaselineNoise',
  537. 'type': 'Rational'
  538. },
  539. 50732: {
  540. 'name': 'BaselineSharpness',
  541. 'type': 'Rational'
  542. },
  543. 50733: {
  544. 'name': 'BayerGreenSplit',
  545. 'type': 'Long'
  546. },
  547. 50734: {
  548. 'name': 'LinearResponseLimit',
  549. 'type': 'Rational'
  550. },
  551. 50735: {
  552. 'name': 'CameraSerialNumber',
  553. 'type': 'Ascii'
  554. },
  555. 50736: {
  556. 'name': 'LensInfo',
  557. 'type': 'Rational'
  558. },
  559. 50737: {
  560. 'name': 'ChromaBlurRadius',
  561. 'type': 'Rational'
  562. },
  563. 50738: {
  564. 'name': 'AntiAliasStrength',
  565. 'type': 'Rational'
  566. },
  567. 50739: {
  568. 'name': 'ShadowScale',
  569. 'type': 'SRational'
  570. },
  571. 50740: {
  572. 'name': 'DNGPrivateData',
  573. 'type': 'Byte'
  574. },
  575. 50741: {
  576. 'name': 'MakerNoteSafety',
  577. 'type': 'Short'
  578. },
  579. 50778: {
  580. 'name': 'CalibrationIlluminant1',
  581. 'type': 'Short'
  582. },
  583. 50779: {
  584. 'name': 'CalibrationIlluminant2',
  585. 'type': 'Short'
  586. },
  587. 50780: {
  588. 'name': 'BestQualityScale',
  589. 'type': 'Rational'
  590. },
  591. 50781: {
  592. 'name': 'RawDataUniqueID',
  593. 'type': 'Byte'
  594. },
  595. 50827: {
  596. 'name': 'OriginalRawFileName',
  597. 'type': 'Byte'
  598. },
  599. 50828: {
  600. 'name': 'OriginalRawFileData',
  601. 'type': 'Undefined'
  602. },
  603. 50829: {
  604. 'name': 'ActiveArea',
  605. 'type': 'Short'
  606. },
  607. 50830: {
  608. 'name': 'MaskedAreas',
  609. 'type': 'Short'
  610. },
  611. 50831: {
  612. 'name': 'AsShotICCProfile',
  613. 'type': 'Undefined'
  614. },
  615. 50832: {
  616. 'name': 'AsShotPreProfileMatrix',
  617. 'type': 'SRational'
  618. },
  619. 50833: {
  620. 'name': 'CurrentICCProfile',
  621. 'type': 'Undefined'
  622. },
  623. 50834: {
  624. 'name': 'CurrentPreProfileMatrix',
  625. 'type': 'SRational'
  626. },
  627. 50879: {
  628. 'name': 'ColorimetricReference',
  629. 'type': 'Short'
  630. },
  631. 50931: {
  632. 'name': 'CameraCalibrationSignature',
  633. 'type': 'Byte'
  634. },
  635. 50932: {
  636. 'name': 'ProfileCalibrationSignature',
  637. 'type': 'Byte'
  638. },
  639. 50934: {
  640. 'name': 'AsShotProfileName',
  641. 'type': 'Byte'
  642. },
  643. 50935: {
  644. 'name': 'NoiseReductionApplied',
  645. 'type': 'Rational'
  646. },
  647. 50936: {
  648. 'name': 'ProfileName',
  649. 'type': 'Byte'
  650. },
  651. 50937: {
  652. 'name': 'ProfileHueSatMapDims',
  653. 'type': 'Long'
  654. },
  655. 50938: {
  656. 'name': 'ProfileHueSatMapData1',
  657. 'type': 'Float'
  658. },
  659. 50939: {
  660. 'name': 'ProfileHueSatMapData2',
  661. 'type': 'Float'
  662. },
  663. 50940: {
  664. 'name': 'ProfileToneCurve',
  665. 'type': 'Float'
  666. },
  667. 50941: {
  668. 'name': 'ProfileEmbedPolicy',
  669. 'type': 'Long'
  670. },
  671. 50942: {
  672. 'name': 'ProfileCopyright',
  673. 'type': 'Byte'
  674. },
  675. 50964: {
  676. 'name': 'ForwardMatrix1',
  677. 'type': 'SRational'
  678. },
  679. 50965: {
  680. 'name': 'ForwardMatrix2',
  681. 'type': 'SRational'
  682. },
  683. 50966: {
  684. 'name': 'PreviewApplicationName',
  685. 'type': 'Byte'
  686. },
  687. 50967: {
  688. 'name': 'PreviewApplicationVersion',
  689. 'type': 'Byte'
  690. },
  691. 50968: {
  692. 'name': 'PreviewSettingsName',
  693. 'type': 'Byte'
  694. },
  695. 50969: {
  696. 'name': 'PreviewSettingsDigest',
  697. 'type': 'Byte'
  698. },
  699. 50970: {
  700. 'name': 'PreviewColorSpace',
  701. 'type': 'Long'
  702. },
  703. 50971: {
  704. 'name': 'PreviewDateTime',
  705. 'type': 'Ascii'
  706. },
  707. 50972: {
  708. 'name': 'RawImageDigest',
  709. 'type': 'Undefined'
  710. },
  711. 50973: {
  712. 'name': 'OriginalRawFileDigest',
  713. 'type': 'Undefined'
  714. },
  715. 50974: {
  716. 'name': 'SubTileBlockSize',
  717. 'type': 'Long'
  718. },
  719. 50975: {
  720. 'name': 'RowInterleaveFactor',
  721. 'type': 'Long'
  722. },
  723. 50981: {
  724. 'name': 'ProfileLookTableDims',
  725. 'type': 'Long'
  726. },
  727. 50982: {
  728. 'name': 'ProfileLookTableData',
  729. 'type': 'Float'
  730. },
  731. 51008: {
  732. 'name': 'OpcodeList1',
  733. 'type': 'Undefined'
  734. },
  735. 51009: {
  736. 'name': 'OpcodeList2',
  737. 'type': 'Undefined'
  738. },
  739. 51022: {
  740. 'name': 'OpcodeList3',
  741. 'type': 'Undefined'
  742. }
  743. },
  744. 'Exif': {
  745. 33434: {
  746. 'name': 'ExposureTime',
  747. 'type': 'Rational'
  748. },
  749. 33437: {
  750. 'name': 'FNumber',
  751. 'type': 'Rational'
  752. },
  753. 34850: {
  754. 'name': 'ExposureProgram',
  755. 'type': 'Short'
  756. },
  757. 34852: {
  758. 'name': 'SpectralSensitivity',
  759. 'type': 'Ascii'
  760. },
  761. 34855: {
  762. 'name': 'ISOSpeedRatings',
  763. 'type': 'Short'
  764. },
  765. 34856: {
  766. 'name': 'OECF',
  767. 'type': 'Undefined'
  768. },
  769. 34864: {
  770. 'name': 'SensitivityType',
  771. 'type': 'Short'
  772. },
  773. 34865: {
  774. 'name': 'StandardOutputSensitivity',
  775. 'type': 'Long'
  776. },
  777. 34866: {
  778. 'name': 'RecommendedExposureIndex',
  779. 'type': 'Long'
  780. },
  781. 34867: {
  782. 'name': 'ISOSpeed',
  783. 'type': 'Long'
  784. },
  785. 34868: {
  786. 'name': 'ISOSpeedLatitudeyyy',
  787. 'type': 'Long'
  788. },
  789. 34869: {
  790. 'name': 'ISOSpeedLatitudezzz',
  791. 'type': 'Long'
  792. },
  793. 36864: {
  794. 'name': 'ExifVersion',
  795. 'type': 'Undefined'
  796. },
  797. 36867: {
  798. 'name': 'DateTimeOriginal',
  799. 'type': 'Ascii'
  800. },
  801. 36868: {
  802. 'name': 'DateTimeDigitized',
  803. 'type': 'Ascii'
  804. },
  805. 37121: {
  806. 'name': 'ComponentsConfiguration',
  807. 'type': 'Undefined'
  808. },
  809. 37122: {
  810. 'name': 'CompressedBitsPerPixel',
  811. 'type': 'Rational'
  812. },
  813. 37377: {
  814. 'name': 'ShutterSpeedValue',
  815. 'type': 'SRational'
  816. },
  817. 37378: {
  818. 'name': 'ApertureValue',
  819. 'type': 'Rational'
  820. },
  821. 37379: {
  822. 'name': 'BrightnessValue',
  823. 'type': 'SRational'
  824. },
  825. 37380: {
  826. 'name': 'ExposureBiasValue',
  827. 'type': 'SRational'
  828. },
  829. 37381: {
  830. 'name': 'MaxApertureValue',
  831. 'type': 'Rational'
  832. },
  833. 37382: {
  834. 'name': 'SubjectDistance',
  835. 'type': 'Rational'
  836. },
  837. 37383: {
  838. 'name': 'MeteringMode',
  839. 'type': 'Short'
  840. },
  841. 37384: {
  842. 'name': 'LightSource',
  843. 'type': 'Short'
  844. },
  845. 37385: {
  846. 'name': 'Flash',
  847. 'type': 'Short'
  848. },
  849. 37386: {
  850. 'name': 'FocalLength',
  851. 'type': 'Rational'
  852. },
  853. 37396: {
  854. 'name': 'SubjectArea',
  855. 'type': 'Short'
  856. },
  857. 37500: {
  858. 'name': 'MakerNote',
  859. 'type': 'Undefined'
  860. },
  861. 37510: {
  862. 'name': 'UserComment',
  863. 'type': 'Ascii'
  864. },
  865. 37520: {
  866. 'name': 'SubSecTime',
  867. 'type': 'Ascii'
  868. },
  869. 37521: {
  870. 'name': 'SubSecTimeOriginal',
  871. 'type': 'Ascii'
  872. },
  873. 37522: {
  874. 'name': 'SubSecTimeDigitized',
  875. 'type': 'Ascii'
  876. },
  877. 40960: {
  878. 'name': 'FlashpixVersion',
  879. 'type': 'Undefined'
  880. },
  881. 40961: {
  882. 'name': 'ColorSpace',
  883. 'type': 'Short'
  884. },
  885. 40962: {
  886. 'name': 'PixelXDimension',
  887. 'type': 'Long'
  888. },
  889. 40963: {
  890. 'name': 'PixelYDimension',
  891. 'type': 'Long'
  892. },
  893. 40964: {
  894. 'name': 'RelatedSoundFile',
  895. 'type': 'Ascii'
  896. },
  897. 40965: {
  898. 'name': 'InteroperabilityTag',
  899. 'type': 'Long'
  900. },
  901. 41483: {
  902. 'name': 'FlashEnergy',
  903. 'type': 'Rational'
  904. },
  905. 41484: {
  906. 'name': 'SpatialFrequencyResponse',
  907. 'type': 'Undefined'
  908. },
  909. 41486: {
  910. 'name': 'FocalPlaneXResolution',
  911. 'type': 'Rational'
  912. },
  913. 41487: {
  914. 'name': 'FocalPlaneYResolution',
  915. 'type': 'Rational'
  916. },
  917. 41488: {
  918. 'name': 'FocalPlaneResolutionUnit',
  919. 'type': 'Short'
  920. },
  921. 41492: {
  922. 'name': 'SubjectLocation',
  923. 'type': 'Short'
  924. },
  925. 41493: {
  926. 'name': 'ExposureIndex',
  927. 'type': 'Rational'
  928. },
  929. 41495: {
  930. 'name': 'SensingMethod',
  931. 'type': 'Short'
  932. },
  933. 41728: {
  934. 'name': 'FileSource',
  935. 'type': 'Undefined'
  936. },
  937. 41729: {
  938. 'name': 'SceneType',
  939. 'type': 'Undefined'
  940. },
  941. 41730: {
  942. 'name': 'CFAPattern',
  943. 'type': 'Undefined'
  944. },
  945. 41985: {
  946. 'name': 'CustomRendered',
  947. 'type': 'Short'
  948. },
  949. 41986: {
  950. 'name': 'ExposureMode',
  951. 'type': 'Short'
  952. },
  953. 41987: {
  954. 'name': 'WhiteBalance',
  955. 'type': 'Short'
  956. },
  957. 41988: {
  958. 'name': 'DigitalZoomRatio',
  959. 'type': 'Rational'
  960. },
  961. 41989: {
  962. 'name': 'FocalLengthIn35mmFilm',
  963. 'type': 'Short'
  964. },
  965. 41990: {
  966. 'name': 'SceneCaptureType',
  967. 'type': 'Short'
  968. },
  969. 41991: {
  970. 'name': 'GainControl',
  971. 'type': 'Short'
  972. },
  973. 41992: {
  974. 'name': 'Contrast',
  975. 'type': 'Short'
  976. },
  977. 41993: {
  978. 'name': 'Saturation',
  979. 'type': 'Short'
  980. },
  981. 41994: {
  982. 'name': 'Sharpness',
  983. 'type': 'Short'
  984. },
  985. 41995: {
  986. 'name': 'DeviceSettingDescription',
  987. 'type': 'Undefined'
  988. },
  989. 41996: {
  990. 'name': 'SubjectDistanceRange',
  991. 'type': 'Short'
  992. },
  993. 42016: {
  994. 'name': 'ImageUniqueID',
  995. 'type': 'Ascii'
  996. },
  997. 42032: {
  998. 'name': 'CameraOwnerName',
  999. 'type': 'Ascii'
  1000. },
  1001. 42033: {
  1002. 'name': 'BodySerialNumber',
  1003. 'type': 'Ascii'
  1004. },
  1005. 42034: {
  1006. 'name': 'LensSpecification',
  1007. 'type': 'Rational'
  1008. },
  1009. 42035: {
  1010. 'name': 'LensMake',
  1011. 'type': 'Ascii'
  1012. },
  1013. 42036: {
  1014. 'name': 'LensModel',
  1015. 'type': 'Ascii'
  1016. },
  1017. 42037: {
  1018. 'name': 'LensSerialNumber',
  1019. 'type': 'Ascii'
  1020. },
  1021. 42240: {
  1022. 'name': 'Gamma',
  1023. 'type': 'Rational'
  1024. }
  1025. },
  1026. 'GPS': {
  1027. 0: {
  1028. 'name': 'GPSVersionID',
  1029. 'type': 'Byte'
  1030. },
  1031. 1: {
  1032. 'name': 'GPSLatitudeRef',
  1033. 'type': 'Ascii'
  1034. },
  1035. 2: {
  1036. 'name': 'GPSLatitude',
  1037. 'type': 'Rational'
  1038. },
  1039. 3: {
  1040. 'name': 'GPSLongitudeRef',
  1041. 'type': 'Ascii'
  1042. },
  1043. 4: {
  1044. 'name': 'GPSLongitude',
  1045. 'type': 'Rational'
  1046. },
  1047. 5: {
  1048. 'name': 'GPSAltitudeRef',
  1049. 'type': 'Byte'
  1050. },
  1051. 6: {
  1052. 'name': 'GPSAltitude',
  1053. 'type': 'Rational'
  1054. },
  1055. 7: {
  1056. 'name': 'GPSTimeStamp',
  1057. 'type': 'Rational'
  1058. },
  1059. 8: {
  1060. 'name': 'GPSSatellites',
  1061. 'type': 'Ascii'
  1062. },
  1063. 9: {
  1064. 'name': 'GPSStatus',
  1065. 'type': 'Ascii'
  1066. },
  1067. 10: {
  1068. 'name': 'GPSMeasureMode',
  1069. 'type': 'Ascii'
  1070. },
  1071. 11: {
  1072. 'name': 'GPSDOP',
  1073. 'type': 'Rational'
  1074. },
  1075. 12: {
  1076. 'name': 'GPSSpeedRef',
  1077. 'type': 'Ascii'
  1078. },
  1079. 13: {
  1080. 'name': 'GPSSpeed',
  1081. 'type': 'Rational'
  1082. },
  1083. 14: {
  1084. 'name': 'GPSTrackRef',
  1085. 'type': 'Ascii'
  1086. },
  1087. 15: {
  1088. 'name': 'GPSTrack',
  1089. 'type': 'Rational'
  1090. },
  1091. 16: {
  1092. 'name': 'GPSImgDirectionRef',
  1093. 'type': 'Ascii'
  1094. },
  1095. 17: {
  1096. 'name': 'GPSImgDirection',
  1097. 'type': 'Rational'
  1098. },
  1099. 18: {
  1100. 'name': 'GPSMapDatum',
  1101. 'type': 'Ascii'
  1102. },
  1103. 19: {
  1104. 'name': 'GPSDestLatitudeRef',
  1105. 'type': 'Ascii'
  1106. },
  1107. 20: {
  1108. 'name': 'GPSDestLatitude',
  1109. 'type': 'Rational'
  1110. },
  1111. 21: {
  1112. 'name': 'GPSDestLongitudeRef',
  1113. 'type': 'Ascii'
  1114. },
  1115. 22: {
  1116. 'name': 'GPSDestLongitude',
  1117. 'type': 'Rational'
  1118. },
  1119. 23: {
  1120. 'name': 'GPSDestBearingRef',
  1121. 'type': 'Ascii'
  1122. },
  1123. 24: {
  1124. 'name': 'GPSDestBearing',
  1125. 'type': 'Rational'
  1126. },
  1127. 25: {
  1128. 'name': 'GPSDestDistanceRef',
  1129. 'type': 'Ascii'
  1130. },
  1131. 26: {
  1132. 'name': 'GPSDestDistance',
  1133. 'type': 'Rational'
  1134. },
  1135. 27: {
  1136. 'name': 'GPSProcessingMethod',
  1137. 'type': 'Undefined'
  1138. },
  1139. 28: {
  1140. 'name': 'GPSAreaInformation',
  1141. 'type': 'Undefined'
  1142. },
  1143. 29: {
  1144. 'name': 'GPSDateStamp',
  1145. 'type': 'Ascii'
  1146. },
  1147. 30: {
  1148. 'name': 'GPSDifferential',
  1149. 'type': 'Short'
  1150. },
  1151. 31: {
  1152. 'name': 'GPSHPositioningError',
  1153. 'type': 'Rational'
  1154. }
  1155. },
  1156. 'Interop': {
  1157. 1: {
  1158. 'name': 'InteroperabilityIndex',
  1159. 'type': 'Ascii'
  1160. }
  1161. },
  1162. };
  1163. const TYPES = {
  1164. "Byte": 1,
  1165. "Ascii": 2,
  1166. "Short": 3,
  1167. "Long": 4,
  1168. "Rational": 5,
  1169. "Undefined": 7,
  1170. "SLong": 9,
  1171. "SRational": 10
  1172. };
  1173. TAGS["0th"] = TAGS["Image"];
  1174. TAGS["1st"] = TAGS["Image"];
  1175. class Piexif {
  1176. version = "1.0.4"
  1177. TAGS = TAGS
  1178. ImageIFD = {
  1179. ProcessingSoftware: 11,
  1180. NewSubfileType: 254,
  1181. SubfileType: 255,
  1182. ImageWidth: 256,
  1183. ImageLength: 257,
  1184. BitsPerSample: 258,
  1185. Compression: 259,
  1186. PhotometricInterpretation: 262,
  1187. Threshholding: 263,
  1188. CellWidth: 264,
  1189. CellLength: 265,
  1190. FillOrder: 266,
  1191. DocumentName: 269,
  1192. ImageDescription: 270,
  1193. Make: 271,
  1194. Model: 272,
  1195. StripOffsets: 273,
  1196. Orientation: 274,
  1197. SamplesPerPixel: 277,
  1198. RowsPerStrip: 278,
  1199. StripByteCounts: 279,
  1200. XResolution: 282,
  1201. YResolution: 283,
  1202. PlanarConfiguration: 284,
  1203. GrayResponseUnit: 290,
  1204. GrayResponseCurve: 291,
  1205. T4Options: 292,
  1206. T6Options: 293,
  1207. ResolutionUnit: 296,
  1208. TransferFunction: 301,
  1209. Software: 305,
  1210. DateTime: 306,
  1211. Artist: 315,
  1212. HostComputer: 316,
  1213. Predictor: 317,
  1214. WhitePoint: 318,
  1215. PrimaryChromaticities: 319,
  1216. ColorMap: 320,
  1217. HalftoneHints: 321,
  1218. TileWidth: 322,
  1219. TileLength: 323,
  1220. TileOffsets: 324,
  1221. TileByteCounts: 325,
  1222. SubIFDs: 330,
  1223. InkSet: 332,
  1224. InkNames: 333,
  1225. NumberOfInks: 334,
  1226. DotRange: 336,
  1227. TargetPrinter: 337,
  1228. ExtraSamples: 338,
  1229. SampleFormat: 339,
  1230. SMinSampleValue: 340,
  1231. SMaxSampleValue: 341,
  1232. TransferRange: 342,
  1233. ClipPath: 343,
  1234. XClipPathUnits: 344,
  1235. YClipPathUnits: 345,
  1236. Indexed: 346,
  1237. JPEGTables: 347,
  1238. OPIProxy: 351,
  1239. JPEGProc: 512,
  1240. JPEGInterchangeFormat: 513,
  1241. JPEGInterchangeFormatLength: 514,
  1242. JPEGRestartInterval: 515,
  1243. JPEGLosslessPredictors: 517,
  1244. JPEGPointTransforms: 518,
  1245. JPEGQTables: 519,
  1246. JPEGDCTables: 520,
  1247. JPEGACTables: 521,
  1248. YCbCrCoefficients: 529,
  1249. YCbCrSubSampling: 530,
  1250. YCbCrPositioning: 531,
  1251. ReferenceBlackWhite: 532,
  1252. XMLPacket: 700,
  1253. Rating: 18246,
  1254. RatingPercent: 18249,
  1255. ImageID: 32781,
  1256. CFARepeatPatternDim: 33421,
  1257. CFAPattern: 33422,
  1258. BatteryLevel: 33423,
  1259. Copyright: 33432,
  1260. ExposureTime: 33434,
  1261. ImageResources: 34377,
  1262. ExifTag: 34665,
  1263. InterColorProfile: 34675,
  1264. GPSTag: 34853,
  1265. Interlace: 34857,
  1266. TimeZoneOffset: 34858,
  1267. SelfTimerMode: 34859,
  1268. FlashEnergy: 37387,
  1269. SpatialFrequencyResponse: 37388,
  1270. Noise: 37389,
  1271. FocalPlaneXResolution: 37390,
  1272. FocalPlaneYResolution: 37391,
  1273. FocalPlaneResolutionUnit: 37392,
  1274. ImageNumber: 37393,
  1275. SecurityClassification: 37394,
  1276. ImageHistory: 37395,
  1277. ExposureIndex: 37397,
  1278. TIFFEPStandardID: 37398,
  1279. SensingMethod: 37399,
  1280. XPTitle: 40091,
  1281. XPComment: 40092,
  1282. XPAuthor: 40093,
  1283. XPKeywords: 40094,
  1284. XPSubject: 40095,
  1285. PrintImageMatching: 50341,
  1286. DNGVersion: 50706,
  1287. DNGBackwardVersion: 50707,
  1288. UniqueCameraModel: 50708,
  1289. LocalizedCameraModel: 50709,
  1290. CFAPlaneColor: 50710,
  1291. CFALayout: 50711,
  1292. LinearizationTable: 50712,
  1293. BlackLevelRepeatDim: 50713,
  1294. BlackLevel: 50714,
  1295. BlackLevelDeltaH: 50715,
  1296. BlackLevelDeltaV: 50716,
  1297. WhiteLevel: 50717,
  1298. DefaultScale: 50718,
  1299. DefaultCropOrigin: 50719,
  1300. DefaultCropSize: 50720,
  1301. ColorMatrix1: 50721,
  1302. ColorMatrix2: 50722,
  1303. CameraCalibration1: 50723,
  1304. CameraCalibration2: 50724,
  1305. ReductionMatrix1: 50725,
  1306. ReductionMatrix2: 50726,
  1307. AnalogBalance: 50727,
  1308. AsShotNeutral: 50728,
  1309. AsShotWhiteXY: 50729,
  1310. BaselineExposure: 50730,
  1311. BaselineNoise: 50731,
  1312. BaselineSharpness: 50732,
  1313. BayerGreenSplit: 50733,
  1314. LinearResponseLimit: 50734,
  1315. CameraSerialNumber: 50735,
  1316. LensInfo: 50736,
  1317. ChromaBlurRadius: 50737,
  1318. AntiAliasStrength: 50738,
  1319. ShadowScale: 50739,
  1320. DNGPrivateData: 50740,
  1321. MakerNoteSafety: 50741,
  1322. CalibrationIlluminant1: 50778,
  1323. CalibrationIlluminant2: 50779,
  1324. BestQualityScale: 50780,
  1325. RawDataUniqueID: 50781,
  1326. OriginalRawFileName: 50827,
  1327. OriginalRawFileData: 50828,
  1328. ActiveArea: 50829,
  1329. MaskedAreas: 50830,
  1330. AsShotICCProfile: 50831,
  1331. AsShotPreProfileMatrix: 50832,
  1332. CurrentICCProfile: 50833,
  1333. CurrentPreProfileMatrix: 50834,
  1334. ColorimetricReference: 50879,
  1335. CameraCalibrationSignature: 50931,
  1336. ProfileCalibrationSignature: 50932,
  1337. AsShotProfileName: 50934,
  1338. NoiseReductionApplied: 50935,
  1339. ProfileName: 50936,
  1340. ProfileHueSatMapDims: 50937,
  1341. ProfileHueSatMapData1: 50938,
  1342. ProfileHueSatMapData2: 50939,
  1343. ProfileToneCurve: 50940,
  1344. ProfileEmbedPolicy: 50941,
  1345. ProfileCopyright: 50942,
  1346. ForwardMatrix1: 50964,
  1347. ForwardMatrix2: 50965,
  1348. PreviewApplicationName: 50966,
  1349. PreviewApplicationVersion: 50967,
  1350. PreviewSettingsName: 50968,
  1351. PreviewSettingsDigest: 50969,
  1352. PreviewColorSpace: 50970,
  1353. PreviewDateTime: 50971,
  1354. RawImageDigest: 50972,
  1355. OriginalRawFileDigest: 50973,
  1356. SubTileBlockSize: 50974,
  1357. RowInterleaveFactor: 50975,
  1358. ProfileLookTableDims: 50981,
  1359. ProfileLookTableData: 50982,
  1360. OpcodeList1: 51008,
  1361. OpcodeList2: 51009,
  1362. OpcodeList3: 51022,
  1363. NoiseProfile: 51041,
  1364. }
  1365. ExifIFD = {
  1366. ExposureTime: 33434,
  1367. FNumber: 33437,
  1368. ExposureProgram: 34850,
  1369. SpectralSensitivity: 34852,
  1370. ISOSpeedRatings: 34855,
  1371. OECF: 34856,
  1372. SensitivityType: 34864,
  1373. StandardOutputSensitivity: 34865,
  1374. RecommendedExposureIndex: 34866,
  1375. ISOSpeed: 34867,
  1376. ISOSpeedLatitudeyyy: 34868,
  1377. ISOSpeedLatitudezzz: 34869,
  1378. ExifVersion: 36864,
  1379. DateTimeOriginal: 36867,
  1380. DateTimeDigitized: 36868,
  1381. ComponentsConfiguration: 37121,
  1382. CompressedBitsPerPixel: 37122,
  1383. ShutterSpeedValue: 37377,
  1384. ApertureValue: 37378,
  1385. BrightnessValue: 37379,
  1386. ExposureBiasValue: 37380,
  1387. MaxApertureValue: 37381,
  1388. SubjectDistance: 37382,
  1389. MeteringMode: 37383,
  1390. LightSource: 37384,
  1391. Flash: 37385,
  1392. FocalLength: 37386,
  1393. SubjectArea: 37396,
  1394. MakerNote: 37500,
  1395. UserComment: 37510,
  1396. SubSecTime: 37520,
  1397. SubSecTimeOriginal: 37521,
  1398. SubSecTimeDigitized: 37522,
  1399. FlashpixVersion: 40960,
  1400. ColorSpace: 40961,
  1401. PixelXDimension: 40962,
  1402. PixelYDimension: 40963,
  1403. RelatedSoundFile: 40964,
  1404. InteroperabilityTag: 40965,
  1405. FlashEnergy: 41483,
  1406. SpatialFrequencyResponse: 41484,
  1407. FocalPlaneXResolution: 41486,
  1408. FocalPlaneYResolution: 41487,
  1409. FocalPlaneResolutionUnit: 41488,
  1410. SubjectLocation: 41492,
  1411. ExposureIndex: 41493,
  1412. SensingMethod: 41495,
  1413. FileSource: 41728,
  1414. SceneType: 41729,
  1415. CFAPattern: 41730,
  1416. CustomRendered: 41985,
  1417. ExposureMode: 41986,
  1418. WhiteBalance: 41987,
  1419. DigitalZoomRatio: 41988,
  1420. FocalLengthIn35mmFilm: 41989,
  1421. SceneCaptureType: 41990,
  1422. GainControl: 41991,
  1423. Contrast: 41992,
  1424. Saturation: 41993,
  1425. Sharpness: 41994,
  1426. DeviceSettingDescription: 41995,
  1427. SubjectDistanceRange: 41996,
  1428. ImageUniqueID: 42016,
  1429. CameraOwnerName: 42032,
  1430. BodySerialNumber: 42033,
  1431. LensSpecification: 42034,
  1432. LensMake: 42035,
  1433. LensModel: 42036,
  1434. LensSerialNumber: 42037,
  1435. Gamma: 42240,
  1436. }
  1437. GPSIFD = {
  1438. GPSVersionID: 0,
  1439. GPSLatitudeRef: 1,
  1440. GPSLatitude: 2,
  1441. GPSLongitudeRef: 3,
  1442. GPSLongitude: 4,
  1443. GPSAltitudeRef: 5,
  1444. GPSAltitude: 6,
  1445. GPSTimeStamp: 7,
  1446. GPSSatellites: 8,
  1447. GPSStatus: 9,
  1448. GPSMeasureMode: 10,
  1449. GPSDOP: 11,
  1450. GPSSpeedRef: 12,
  1451. GPSSpeed: 13,
  1452. GPSTrackRef: 14,
  1453. GPSTrack: 15,
  1454. GPSImgDirectionRef: 16,
  1455. GPSImgDirection: 17,
  1456. GPSMapDatum: 18,
  1457. GPSDestLatitudeRef: 19,
  1458. GPSDestLatitude: 20,
  1459. GPSDestLongitudeRef: 21,
  1460. GPSDestLongitude: 22,
  1461. GPSDestBearingRef: 23,
  1462. GPSDestBearing: 24,
  1463. GPSDestDistanceRef: 25,
  1464. GPSDestDistance: 26,
  1465. GPSProcessingMethod: 27,
  1466. GPSAreaInformation: 28,
  1467. GPSDateStamp: 29,
  1468. GPSDifferential: 30,
  1469. GPSHPositioningError: 31,
  1470. }
  1471. InteropIFD = {
  1472. InteroperabilityIndex: 1,
  1473. }
  1474. GPSHelper = {
  1475. degToDmsRational(degFloat : number) {
  1476. const degAbs = Math.abs(degFloat);
  1477. const minFloat = degAbs % 1 * 60;
  1478. const secFloat = minFloat % 1 * 60;
  1479. const deg = Math.floor(degAbs);
  1480. const min = Math.floor(minFloat);
  1481. const sec = Math.round(secFloat * 100);
  1482. return [
  1483. [deg, 1],
  1484. [min, 1],
  1485. [sec, 100]
  1486. ];
  1487. },
  1488. dmsRationalToDeg(dmsArray : number[][], ref : string) {
  1489. const sign = (ref === 'S' || ref === 'W') ? -1.0 : 1.0;
  1490. const deg = dmsArray[0][0] / dmsArray[0][1] +
  1491. dmsArray[1][0] / dmsArray[1][1] / 60.0 +
  1492. dmsArray[2][0] / dmsArray[2][1] / 3600.0;
  1493. return deg * sign;
  1494. },
  1495. }
  1496. remove(jpeg) {
  1497. let b64 = false;
  1498. if (jpeg.slice(0, 2) == "\xff\xd8") { } else if (jpeg.slice(0, 23) == "data:image/jpeg;base64," || jpeg
  1499. .slice(0, 22) == "data:image/jpg;base64,") {
  1500. jpeg = atob(jpeg.split(",")[1]);
  1501. b64 = true;
  1502. } else {
  1503. throw new Error("Given data is not jpeg.");
  1504. }
  1505. const segments = splitIntoSegments(jpeg);
  1506. const newSegments = segments.filter(function (seg) {
  1507. return !(seg.slice(0, 2) == "\xff\xe1" &&
  1508. seg.slice(4, 10) == "Exif\x00\x00");
  1509. });
  1510. let new_data = newSegments.join("");
  1511. if (b64) {
  1512. new_data = "data:image/jpeg;base64," + btoa(new_data);
  1513. }
  1514. return new_data;
  1515. }
  1516. insert(exif, jpeg) {
  1517. let b64 = false;
  1518. if (exif.slice(0, 6) != "\x45\x78\x69\x66\x00\x00") {
  1519. throw new Error("Given data is not exif.");
  1520. }
  1521. if (jpeg.slice(0, 2) == "\xff\xd8") { } else if (jpeg.slice(0, 23) == "data:image/jpeg;base64," || jpeg
  1522. .slice(0, 22) == "data:image/jpg;base64,") {
  1523. jpeg = atob(jpeg.split(",")[1]);
  1524. b64 = true;
  1525. } else {
  1526. throw new Error("Given data is not jpeg.");
  1527. }
  1528. const exifStr = "\xff\xe1" + pack(">H", [exif.length + 2]) + exif;
  1529. const segments = splitIntoSegments(jpeg);
  1530. let new_data = mergeSegments(segments, exifStr);
  1531. if (b64) {
  1532. new_data = "data:image/jpeg;base64," + btoa(new_data);
  1533. }
  1534. return new_data;
  1535. }
  1536. load(data) {
  1537. let input_data;
  1538. if (isString(data)) {
  1539. if (data.slice(0, 2) == "\xff\xd8") {
  1540. input_data = data;
  1541. } else if (data.slice(0, 23) == "data:image/jpeg;base64," || data.slice(0, 22) == "data:image/jpg;base64,") {
  1542. input_data = atob(data.split(",")[1]);
  1543. } else if (data.slice(0, 4) == "Exif") {
  1544. input_data = data.slice(6);
  1545. } else {
  1546. throw new Error("'load' gots invalid file data.");
  1547. }
  1548. } else {
  1549. throw new Error("'load' gots invalid type argument.");
  1550. }
  1551. let exifDict = {};
  1552. let exif_dict = {
  1553. "0th": {},
  1554. "Exif": {},
  1555. "GPS": {},
  1556. "Interop": {},
  1557. "1st": {},
  1558. "thumbnail": null
  1559. };
  1560. const exifReader = new ExifReader(input_data);
  1561. if (exifReader.tiftag === null) {
  1562. return exif_dict;
  1563. }
  1564. if (exifReader.tiftag.slice(0, 2) == "\x49\x49") {
  1565. exifReader.endian_mark = "<";
  1566. } else {
  1567. exifReader.endian_mark = ">";
  1568. }
  1569. let pointer = unpack(exifReader.endian_mark + "L",
  1570. exifReader.tiftag.slice(4, 8))[0];
  1571. exif_dict["0th"] = exifReader.get_ifd(pointer, "0th");
  1572. const first_ifd_pointer = exif_dict["0th"]["first_ifd_pointer"];
  1573. delete exif_dict["0th"]["first_ifd_pointer"];
  1574. if (34665 in exif_dict["0th"]) {
  1575. pointer = exif_dict["0th"][34665];
  1576. exif_dict["Exif"] = exifReader.get_ifd(pointer, "Exif");
  1577. }
  1578. if (34853 in exif_dict["0th"]) {
  1579. pointer = exif_dict["0th"][34853];
  1580. exif_dict["GPS"] = exifReader.get_ifd(pointer, "GPS");
  1581. }
  1582. if (40965 in exif_dict["Exif"]) {
  1583. pointer = exif_dict["Exif"][40965];
  1584. exif_dict["Interop"] = exifReader.get_ifd(pointer, "Interop");
  1585. }
  1586. if (first_ifd_pointer != "\x00\x00\x00\x00") {
  1587. pointer = unpack(exifReader.endian_mark + "L",
  1588. first_ifd_pointer)[0];
  1589. exif_dict["1st"] = exifReader.get_ifd(pointer, "1st");
  1590. if ((513 in exif_dict["1st"]) && (514 in exif_dict["1st"])) {
  1591. var end = exif_dict["1st"][513] + exif_dict["1st"][514];
  1592. var thumb = exifReader.tiftag.slice(exif_dict["1st"][513], end);
  1593. exif_dict["thumbnail"] = thumb;
  1594. }
  1595. }
  1596. return exif_dict;
  1597. }
  1598. dump(exif_dict_original) {
  1599. const TIFF_HEADER_LENGTH = 8;
  1600. const exif_dict : any = cloneDeep(exif_dict_original);
  1601. const header = "Exif\x00\x00\x4d\x4d\x00\x2a\x00\x00\x00\x08";
  1602. let exif_is = 0//false;
  1603. let gps_is = 0 //false;
  1604. let interop_is = 0//false;
  1605. let first_is = false;
  1606. let zeroth_ifd,
  1607. exif_ifd,
  1608. interop_ifd,
  1609. gps_ifd,
  1610. first_ifd;
  1611. if ("0th" in exif_dict) {
  1612. zeroth_ifd = exif_dict["0th"];
  1613. } else {
  1614. zeroth_ifd = {};
  1615. }
  1616. if ((("Exif" in exif_dict) && (Object.keys(exif_dict["Exif"]).length)) ||
  1617. (("Interop" in exif_dict) && (Object.keys(exif_dict["Interop"]).length))) {
  1618. zeroth_ifd[34665] = 1;
  1619. exif_is = 1//true;
  1620. exif_ifd = exif_dict["Exif"];
  1621. if (("Interop" in exif_dict) && Object.keys(exif_dict["Interop"]).length) {
  1622. exif_ifd[40965] = 1;
  1623. interop_is = 1//true;
  1624. interop_ifd = exif_dict["Interop"];
  1625. } else if (Object.keys(exif_ifd).indexOf(this.ExifIFD.InteroperabilityTag.toString()) > -1) {
  1626. delete exif_ifd[40965];
  1627. }
  1628. } else if (Object.keys(zeroth_ifd).indexOf(this.ImageIFD.ExifTag.toString()) > -1) {
  1629. delete zeroth_ifd[34665];
  1630. }
  1631. if (("GPS" in exif_dict) && (Object.keys(exif_dict["GPS"]).length)) {
  1632. zeroth_ifd[this.ImageIFD.GPSTag] = 1;
  1633. gps_is = 1 //true;
  1634. gps_ifd = exif_dict["GPS"];
  1635. } else if (Object.keys(zeroth_ifd).indexOf(this.ImageIFD.GPSTag.toString()) > -1) {
  1636. delete zeroth_ifd[this.ImageIFD.GPSTag];
  1637. }
  1638. if (("1st" in exif_dict) &&
  1639. ("thumbnail" in exif_dict) &&
  1640. (exif_dict["thumbnail"] != null)) {
  1641. first_is = true;
  1642. exif_dict["1st"][513] = 1;
  1643. exif_dict["1st"][514] = 1;
  1644. first_ifd = exif_dict["1st"];
  1645. }
  1646. const zeroth_set = _dict_to_bytes(zeroth_ifd, "0th", 0);
  1647. const zeroth_length = (zeroth_set[0].length + exif_is * 12 + gps_is * 12 + 4 +
  1648. zeroth_set[1].length);
  1649. let exif_set,
  1650. exif_bytes = "",
  1651. exif_length = 0,
  1652. gps_set,
  1653. gps_bytes = "",
  1654. gps_length = 0,
  1655. interop_set,
  1656. interop_bytes = "",
  1657. interop_length = 0,
  1658. first_set,
  1659. first_bytes = "",
  1660. thumbnail;
  1661. if (exif_is) {
  1662. exif_set = _dict_to_bytes(exif_ifd, "Exif", zeroth_length);
  1663. exif_length = exif_set[0].length + interop_is * 12 + exif_set[1].length;
  1664. }
  1665. if (gps_is) {
  1666. gps_set = _dict_to_bytes(gps_ifd, "GPS", zeroth_length + exif_length);
  1667. gps_bytes = gps_set.join("");
  1668. gps_length = gps_bytes.length;
  1669. }
  1670. if (interop_is) {
  1671. const offset = zeroth_length + exif_length + gps_length;
  1672. interop_set = _dict_to_bytes(interop_ifd, "Interop", offset);
  1673. interop_bytes = interop_set.join("");
  1674. interop_length = interop_bytes.length;
  1675. }
  1676. if (first_is) {
  1677. const offset = zeroth_length + exif_length + gps_length + interop_length;
  1678. first_set = _dict_to_bytes(first_ifd, "1st", offset);
  1679. thumbnail = _get_thumbnail(exif_dict["thumbnail"]);
  1680. if (thumbnail.length > 64000) {
  1681. throw new Error("Given thumbnail is too large. max 64kB");
  1682. }
  1683. }
  1684. let exif_pointer = "",
  1685. gps_pointer = "",
  1686. interop_pointer = "",
  1687. first_ifd_pointer = "\x00\x00\x00\x00";
  1688. if (exif_is) {
  1689. const pointer_value = TIFF_HEADER_LENGTH + zeroth_length;
  1690. const pointer_str = pack(">L", [pointer_value]);
  1691. const key = 34665;
  1692. const key_str = pack(">H", [key]);
  1693. const type_str = pack(">H", [TYPES["Long"]]);
  1694. const length_str = pack(">L", [1]);
  1695. exif_pointer = key_str + type_str + length_str + pointer_str;
  1696. }
  1697. if (gps_is) {
  1698. const pointer_value = TIFF_HEADER_LENGTH + zeroth_length + exif_length;
  1699. const pointer_str = pack(">L", [pointer_value]);
  1700. const key = 34853;
  1701. const key_str = pack(">H", [key]);
  1702. const type_str = pack(">H", [TYPES["Long"]]);
  1703. const length_str = pack(">L", [1]);
  1704. gps_pointer = key_str + type_str + length_str + pointer_str;
  1705. }
  1706. if (interop_is) {
  1707. const pointer_value = (TIFF_HEADER_LENGTH +
  1708. zeroth_length + exif_length + gps_length);
  1709. const pointer_str = pack(">L", [pointer_value]);
  1710. const key = 40965;
  1711. const key_str = pack(">H", [key]);
  1712. const type_str = pack(">H", [TYPES["Long"]]);
  1713. const length_str = pack(">L", [1]);
  1714. interop_pointer = key_str + type_str + length_str + pointer_str;
  1715. }
  1716. if (first_is) {
  1717. const pointer_value = (TIFF_HEADER_LENGTH + zeroth_length +
  1718. exif_length + gps_length + interop_length);
  1719. first_ifd_pointer = pack(">L", [pointer_value]);
  1720. const thumbnail_pointer = (pointer_value + first_set[0].length + 24 +
  1721. 4 + first_set[1].length);
  1722. const thumbnail_p_bytes = ("\x02\x01\x00\x04\x00\x00\x00\x01" +
  1723. pack(">L", [thumbnail_pointer]));
  1724. const thumbnail_length_bytes = ("\x02\x02\x00\x04\x00\x00\x00\x01" +
  1725. pack(">L", [thumbnail.length]));
  1726. first_bytes = (first_set[0] + thumbnail_p_bytes +
  1727. thumbnail_length_bytes + "\x00\x00\x00\x00" +
  1728. first_set[1] + thumbnail);
  1729. }
  1730. const zeroth_bytes = (zeroth_set[0] + exif_pointer + gps_pointer +
  1731. first_ifd_pointer + zeroth_set[1]);
  1732. if (exif_is) {
  1733. exif_bytes = exif_set[0] + interop_pointer + exif_set[1];
  1734. }
  1735. return (header + zeroth_bytes + exif_bytes + gps_bytes +
  1736. interop_bytes + first_bytes);
  1737. }
  1738. }
  1739. function _get_thumbnail(jpeg) {
  1740. let segments = splitIntoSegments(jpeg);
  1741. while (("\xff\xe0" <= segments[1].slice(0, 2)) && (segments[1].slice(0, 2) <= "\xff\xef")) {
  1742. segments = [segments[0]].concat(segments.slice(2));
  1743. }
  1744. return segments.join("");
  1745. }
  1746. function _pack_byte(array) {
  1747. return pack(">" + nStr("B", array.length), array);
  1748. }
  1749. function _pack_short(array) {
  1750. return pack(">" + nStr("H", array.length), array);
  1751. }
  1752. function _pack_long(array) {
  1753. return pack(">" + nStr("L", array.length), array);
  1754. }
  1755. function _value_to_bytes(raw_value, value_type, offset) {
  1756. let four_bytes_over = "";
  1757. let value_str = "";
  1758. let length,
  1759. new_value,
  1760. num,
  1761. den;
  1762. if (value_type == "Byte") {
  1763. length = raw_value.length;
  1764. if (length <= 4) {
  1765. value_str = (_pack_byte(raw_value) +
  1766. nStr("\x00", 4 - length));
  1767. } else {
  1768. value_str = pack(">L", [offset]);
  1769. four_bytes_over = _pack_byte(raw_value);
  1770. }
  1771. } else if (value_type == "Short") {
  1772. length = raw_value.length;
  1773. if (length <= 2) {
  1774. value_str = (_pack_short(raw_value) +
  1775. nStr("\x00\x00", 2 - length));
  1776. } else {
  1777. value_str = pack(">L", [offset]);
  1778. four_bytes_over = _pack_short(raw_value);
  1779. }
  1780. } else if (value_type == "Long") {
  1781. length = raw_value.length;
  1782. if (length <= 1) {
  1783. value_str = _pack_long(raw_value);
  1784. } else {
  1785. value_str = pack(">L", [offset]);
  1786. four_bytes_over = _pack_long(raw_value);
  1787. }
  1788. } else if (value_type == "Ascii") {
  1789. new_value = raw_value + "\x00";
  1790. length = new_value.length;
  1791. if (length > 4) {
  1792. value_str = pack(">L", [offset]);
  1793. four_bytes_over = new_value;
  1794. } else {
  1795. value_str = new_value + nStr("\x00", 4 - length);
  1796. }
  1797. } else if (value_type == "Rational") {
  1798. if (typeof (raw_value[0]) == "number") {
  1799. length = 1;
  1800. num = raw_value[0];
  1801. den = raw_value[1];
  1802. new_value = pack(">L", [num]) + pack(">L", [den]);
  1803. } else {
  1804. length = raw_value.length;
  1805. new_value = "";
  1806. for (var n = 0; n < length; n++) {
  1807. num = raw_value[n][0];
  1808. den = raw_value[n][1];
  1809. new_value += (pack(">L", [num]) +
  1810. pack(">L", [den]));
  1811. }
  1812. }
  1813. value_str = pack(">L", [offset]);
  1814. four_bytes_over = new_value;
  1815. } else if (value_type == "SRational") {
  1816. if (typeof (raw_value[0]) == "number") {
  1817. length = 1;
  1818. num = raw_value[0];
  1819. den = raw_value[1];
  1820. new_value = pack(">l", [num]) + pack(">l", [den]);
  1821. } else {
  1822. length = raw_value.length;
  1823. new_value = "";
  1824. for (var n = 0; n < length; n++) {
  1825. num = raw_value[n][0];
  1826. den = raw_value[n][1];
  1827. new_value += (pack(">l", [num]) +
  1828. pack(">l", [den]));
  1829. }
  1830. }
  1831. value_str = pack(">L", [offset]);
  1832. four_bytes_over = new_value;
  1833. } else if (value_type == "Undefined") {
  1834. length = raw_value.length;
  1835. if (length > 4) {
  1836. value_str = pack(">L", [offset]);
  1837. four_bytes_over = raw_value;
  1838. } else {
  1839. value_str = raw_value + nStr("\x00", 4 - length);
  1840. }
  1841. }
  1842. var length_str = pack(">L", [length]);
  1843. return [length_str, value_str, four_bytes_over];
  1844. }
  1845. function _dict_to_bytes(ifd_dict, ifd, ifd_offset) {
  1846. const TIFF_HEADER_LENGTH = 8;
  1847. const tag_count = Object.keys(ifd_dict).length;
  1848. const entry_header = pack(">H", [tag_count]);
  1849. let entries_length;
  1850. if (["0th", "1st"].indexOf(ifd) > -1) {
  1851. entries_length = 2 + tag_count * 12 + 4;
  1852. } else {
  1853. entries_length = 2 + tag_count * 12;
  1854. }
  1855. let entries = "";
  1856. let values = "";
  1857. let key;
  1858. for (key in ifd_dict) {
  1859. if (typeof (key) == "string") {
  1860. key = parseInt(key);
  1861. }
  1862. if ((ifd == "0th") && ([34665, 34853].indexOf(key) > -1)) {
  1863. continue;
  1864. } else if ((ifd == "Exif") && (key == 40965)) {
  1865. continue;
  1866. } else if ((ifd == "1st") && ([513, 514].indexOf(key) > -1)) {
  1867. continue;
  1868. }
  1869. var raw_value = ifd_dict[key];
  1870. var key_str = pack(">H", [key]);
  1871. var value_type = TAGS[ifd][key]["type"];
  1872. var type_str = pack(">H", [TYPES[value_type]]);
  1873. if (typeof (raw_value) == "number") {
  1874. raw_value = [raw_value];
  1875. }
  1876. var offset = TIFF_HEADER_LENGTH + entries_length + ifd_offset + values.length;
  1877. var b = _value_to_bytes(raw_value, value_type, offset);
  1878. var length_str = b[0];
  1879. var value_str = b[1];
  1880. var four_bytes_over = b[2];
  1881. entries += key_str + type_str + length_str + value_str;
  1882. values += four_bytes_over;
  1883. }
  1884. return [entry_header + entries, values];
  1885. }
  1886. class ExifReader {
  1887. tiftag = null
  1888. endian_mark = ''
  1889. constructor(data) {
  1890. let segments,
  1891. app1;
  1892. if (data.slice(0, 2) == "\xff\xd8") { // JPEG
  1893. segments = splitIntoSegments(data);
  1894. app1 = getExifSeg(segments);
  1895. if (app1) {
  1896. this.tiftag = app1.slice(10);
  1897. }
  1898. } else if (["\x49\x49", "\x4d\x4d"].indexOf(data.slice(0, 2)) > -1) { // TIFF
  1899. this.tiftag = data;
  1900. } else if (data.slice(0, 4) == "Exif") { // Exif
  1901. this.tiftag = data.slice(6);
  1902. } else {
  1903. throw new Error("Given file is neither JPEG nor TIFF.");
  1904. }
  1905. }
  1906. get_ifd(pointer, ifd_name) {
  1907. let ifd_dict = {};
  1908. let tag_count = unpack(this.endian_mark + "H",
  1909. this.tiftag.slice(pointer, pointer + 2))[0];
  1910. const offset = pointer + 2;
  1911. let t;
  1912. if (["0th", "1st"].indexOf(ifd_name) > -1) {
  1913. t = "Image";
  1914. } else {
  1915. t = ifd_name;
  1916. }
  1917. for (let x = 0; x < tag_count; x++) {
  1918. pointer = offset + 12 * x;
  1919. const tag = unpack(this.endian_mark + "H",
  1920. this.tiftag.slice(pointer, pointer + 2))[0];
  1921. const value_type = unpack(this.endian_mark + "H",
  1922. this.tiftag.slice(pointer + 2, pointer + 4))[0];
  1923. const value_num = unpack(this.endian_mark + "L",
  1924. this.tiftag.slice(pointer + 4, pointer + 8))[0];
  1925. const value = this.tiftag.slice(pointer + 8, pointer + 12);
  1926. const v_set = [value_type, value_num, value];
  1927. if (tag in TAGS[t]) {
  1928. ifd_dict[tag] = this.convert_value(v_set);
  1929. }
  1930. }
  1931. if (ifd_name == "0th") {
  1932. pointer = offset + 12 * tag_count;
  1933. ifd_dict["first_ifd_pointer"] = this.tiftag.slice(pointer, pointer + 4);
  1934. }
  1935. return ifd_dict;
  1936. }
  1937. convert_value(val) {
  1938. let data = null;
  1939. const t = val[0];
  1940. const length = val[1];
  1941. const value = val[2];
  1942. let pointer;
  1943. if (t == 1) { // BYTE
  1944. if (length > 4) {
  1945. pointer = unpack(this.endian_mark + "L", value)[0];
  1946. data = unpack(this.endian_mark + nStr("B", length),
  1947. this.tiftag.slice(pointer, pointer + length));
  1948. } else {
  1949. data = unpack(this.endian_mark + nStr("B", length), value.slice(0, length));
  1950. }
  1951. } else if (t == 2) { // ASCII
  1952. if (length > 4) {
  1953. pointer = unpack(this.endian_mark + "L", value)[0];
  1954. data = this.tiftag.slice(pointer, pointer + length - 1);
  1955. } else {
  1956. data = value.slice(0, length - 1);
  1957. }
  1958. } else if (t == 3) { // SHORT
  1959. if (length > 2) {
  1960. pointer = unpack(this.endian_mark + "L", value)[0];
  1961. data = unpack(this.endian_mark + nStr("H", length),
  1962. this.tiftag.slice(pointer, pointer + length * 2));
  1963. } else {
  1964. data = unpack(this.endian_mark + nStr("H", length),
  1965. value.slice(0, length * 2));
  1966. }
  1967. } else if (t == 4) { // LONG
  1968. if (length > 1) {
  1969. pointer = unpack(this.endian_mark + "L", value)[0];
  1970. data = unpack(this.endian_mark + nStr("L", length),
  1971. this.tiftag.slice(pointer, pointer + length * 4));
  1972. } else {
  1973. data = unpack(this.endian_mark + nStr("L", length),
  1974. value);
  1975. }
  1976. } else if (t == 5) { // RATIONAL
  1977. pointer = unpack(this.endian_mark + "L", value)[0];
  1978. if (length > 1) {
  1979. data = [];
  1980. for (let x = 0; x < length; x++) {
  1981. data.push([unpack(this.endian_mark + "L",
  1982. this.tiftag.slice(pointer + x * 8, pointer + 4 + x * 8))[0],
  1983. unpack(this.endian_mark + "L",
  1984. this.tiftag.slice(pointer + 4 + x * 8, pointer + 8 + x * 8))[0]
  1985. ]);
  1986. }
  1987. } else {
  1988. data = [unpack(this.endian_mark + "L",
  1989. this.tiftag.slice(pointer, pointer + 4))[0],
  1990. unpack(this.endian_mark + "L",
  1991. this.tiftag.slice(pointer + 4, pointer + 8))[0]
  1992. ];
  1993. }
  1994. } else if (t == 7) { // UNDEFINED BYTES
  1995. if (length > 4) {
  1996. pointer = unpack(this.endian_mark + "L", value)[0];
  1997. data = this.tiftag.slice(pointer, pointer + length);
  1998. } else {
  1999. data = value.slice(0, length);
  2000. }
  2001. } else if (t == 9) { // SLONG
  2002. if (length > 1) {
  2003. pointer = unpack(this.endian_mark + "L", value)[0];
  2004. data = unpack(this.endian_mark + nStr("l", length),
  2005. this.tiftag.slice(pointer, pointer + length * 4));
  2006. } else {
  2007. data = unpack(this.endian_mark + nStr("l", length),
  2008. value);
  2009. }
  2010. } else if (t == 10) { // SRATIONAL
  2011. pointer = unpack(this.endian_mark + "L", value)[0];
  2012. if (length > 1) {
  2013. data = [];
  2014. for (let x = 0; x < length; x++) {
  2015. data.push([unpack(this.endian_mark + "l",
  2016. this.tiftag.slice(pointer + x * 8, pointer + 4 + x * 8))[0],
  2017. unpack(this.endian_mark + "l",
  2018. this.tiftag.slice(pointer + 4 + x * 8, pointer + 8 + x * 8))[0]
  2019. ]);
  2020. }
  2021. } else {
  2022. data = [unpack(this.endian_mark + "l",
  2023. this.tiftag.slice(pointer, pointer + 4))[0],
  2024. unpack(this.endian_mark + "l",
  2025. this.tiftag.slice(pointer + 4, pointer + 8))[0]
  2026. ];
  2027. }
  2028. } else {
  2029. throw new Error("Exif might be wrong. Got incorrect value " +
  2030. "type to decode. type:" + t);
  2031. }
  2032. if ((data instanceof Array) && (data.length == 1)) {
  2033. return data[0];
  2034. } else {
  2035. return data;
  2036. }
  2037. }
  2038. }
  2039. function pack(mark, array) {
  2040. if (!(array instanceof Array)) {
  2041. throw new Error("'pack' error. Got invalid type argument.");
  2042. }
  2043. if ((mark.length - 1) != array.length) {
  2044. throw new Error("'pack' error. " + (mark.length - 1) + " marks, " + array.length + " elements.");
  2045. }
  2046. let littleEndian;
  2047. if (mark[0] == "<") {
  2048. littleEndian = true;
  2049. } else if (mark[0] == ">") {
  2050. littleEndian = false;
  2051. } else {
  2052. throw new Error("");
  2053. }
  2054. let packed = "";
  2055. let p = 1;
  2056. let val = null;
  2057. let c = null;
  2058. let valStr = null;
  2059. while (c = mark[p]) {
  2060. if (c.toLowerCase() == "b") {
  2061. val = array[p - 1];
  2062. if ((c == "b") && (val < 0)) {
  2063. val += 0x100;
  2064. }
  2065. if ((val > 0xff) || (val < 0)) {
  2066. throw new Error("'pack' error.");
  2067. } else {
  2068. valStr = String.fromCharCode(val);
  2069. }
  2070. } else if (c == "H") {
  2071. val = array[p - 1];
  2072. if ((val > 0xffff) || (val < 0)) {
  2073. throw new Error("'pack' error.");
  2074. } else {
  2075. valStr = String.fromCharCode(Math.floor((val % 0x10000) / 0x100)) +
  2076. String.fromCharCode(val % 0x100);
  2077. if (littleEndian) {
  2078. valStr = valStr.split("").reverse().join("");
  2079. }
  2080. }
  2081. } else if (c.toLowerCase() == "l") {
  2082. val = array[p - 1];
  2083. if ((c == "l") && (val < 0)) {
  2084. val += 0x100000000;
  2085. }
  2086. if ((val > 0xffffffff) || (val < 0)) {
  2087. throw new Error("'pack' error.");
  2088. } else {
  2089. valStr = String.fromCharCode(Math.floor(val / 0x1000000)) +
  2090. String.fromCharCode(Math.floor((val % 0x1000000) / 0x10000)) +
  2091. String.fromCharCode(Math.floor((val % 0x10000) / 0x100)) +
  2092. String.fromCharCode(val % 0x100);
  2093. if (littleEndian) {
  2094. valStr = valStr.split("").reverse().join("");
  2095. }
  2096. }
  2097. } else {
  2098. throw new Error("'pack' error.");
  2099. }
  2100. packed += valStr;
  2101. p += 1;
  2102. }
  2103. return packed;
  2104. }
  2105. function unpack(mark, str) {
  2106. if (typeof (str) != "string") {
  2107. throw new Error("'unpack' error. Got invalid type argument.");
  2108. }
  2109. let l = 0;
  2110. for (let markPointer = 1; markPointer < mark.length; markPointer++) {
  2111. if (mark[markPointer].toLowerCase() == "b") {
  2112. l += 1;
  2113. } else if (mark[markPointer].toLowerCase() == "h") {
  2114. l += 2;
  2115. } else if (mark[markPointer].toLowerCase() == "l") {
  2116. l += 4;
  2117. } else {
  2118. throw new Error("'unpack' error. Got invalid mark.");
  2119. }
  2120. }
  2121. if (l != str.length) {
  2122. throw new Error("'unpack' error. Mismatch between symbol and string length. " + l + ":" + str.length);
  2123. }
  2124. let littleEndian;
  2125. if (mark[0] == "<") {
  2126. littleEndian = true;
  2127. } else if (mark[0] == ">") {
  2128. littleEndian = false;
  2129. } else {
  2130. throw new Error("'unpack' error.");
  2131. }
  2132. let unpacked = [];
  2133. let strPointer = 0;
  2134. let p = 1;
  2135. let val = null;
  2136. let c = null;
  2137. let length = null;
  2138. let sliced = "";
  2139. while (c = mark[p]) {
  2140. if (c.toLowerCase() == "b") {
  2141. length = 1;
  2142. sliced = str.slice(strPointer, strPointer + length);
  2143. val = sliced.charCodeAt(0);
  2144. if ((c == "b") && (val >= 0x80)) {
  2145. val -= 0x100;
  2146. }
  2147. } else if (c == "H") {
  2148. length = 2;
  2149. sliced = str.slice(strPointer, strPointer + length);
  2150. if (littleEndian) {
  2151. sliced = sliced.split("").reverse().join("");
  2152. }
  2153. val = sliced.charCodeAt(0) * 0x100 +
  2154. sliced.charCodeAt(1);
  2155. } else if (c.toLowerCase() == "l") {
  2156. length = 4;
  2157. sliced = str.slice(strPointer, strPointer + length);
  2158. if (littleEndian) {
  2159. sliced = sliced.split("").reverse().join("");
  2160. }
  2161. val = sliced.charCodeAt(0) * 0x1000000 +
  2162. sliced.charCodeAt(1) * 0x10000 +
  2163. sliced.charCodeAt(2) * 0x100 +
  2164. sliced.charCodeAt(3);
  2165. if ((c == "l") && (val >= 0x80000000)) {
  2166. val -= 0x100000000;
  2167. }
  2168. } else {
  2169. throw new Error("'unpack' error. " + c);
  2170. }
  2171. unpacked.push(val);
  2172. strPointer += length;
  2173. p += 1;
  2174. }
  2175. return unpacked;
  2176. }
  2177. function nStr(ch, num) {
  2178. let str = "";
  2179. for (let i = 0; i < num; i++) {
  2180. str += ch;
  2181. }
  2182. return str;
  2183. }
  2184. function splitIntoSegments(data) {
  2185. if (data.slice(0, 2) != "\xff\xd8") {
  2186. throw new Error("Given data isn't JPEG.");
  2187. }
  2188. let head = 2;
  2189. const segments = ["\xff\xd8"];
  2190. while (true) {
  2191. if (data.slice(head, head + 2) == "\xff\xda") {
  2192. segments.push(data.slice(head));
  2193. break;
  2194. } else {
  2195. var length = unpack(">H", data.slice(head + 2, head + 4))[0];
  2196. var endPoint = head + length + 2;
  2197. segments.push(data.slice(head, endPoint));
  2198. head = endPoint;
  2199. }
  2200. if (head >= data.length) {
  2201. throw new Error("Wrong JPEG data.");
  2202. }
  2203. }
  2204. return segments;
  2205. }
  2206. function getExifSeg(segments) {
  2207. let seg;
  2208. for (let i = 0; i < segments.length; i++) {
  2209. seg = segments[i];
  2210. if (seg.slice(0, 2) == "\xff\xe1" &&
  2211. seg.slice(4, 10) == "Exif\x00\x00") {
  2212. return seg;
  2213. }
  2214. }
  2215. return null;
  2216. }
  2217. function mergeSegments(segments, exif) {
  2218. let hasExifSegment = false;
  2219. let additionalAPP1ExifSegments = [];
  2220. segments.forEach(function (segment, i) {
  2221. // Replace first occurence of APP1:Exif segment
  2222. if (segment.slice(0, 2) == "\xff\xe1" &&
  2223. segment.slice(4, 10) == "Exif\x00\x00"
  2224. ) {
  2225. if (!hasExifSegment) {
  2226. segments[i] = exif;
  2227. hasExifSegment = true;
  2228. } else {
  2229. additionalAPP1ExifSegments.unshift(i);
  2230. }
  2231. }
  2232. });
  2233. // Remove additional occurences of APP1:Exif segment
  2234. additionalAPP1ExifSegments.forEach(function (segmentIndex) {
  2235. segments.splice(segmentIndex, 1);
  2236. });
  2237. if (!hasExifSegment && exif) {
  2238. segments = [segments[0], exif].concat(segments.slice(1));
  2239. }
  2240. return segments.join("");
  2241. }