CCTIFFReader.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. /****************************************************************************
  2. Copyright (c) 2011 Gordon P. Hemsley
  3. http://gphemsley.org/
  4. Copyright (c) 2008-2010 Ricardo Quesada
  5. Copyright (c) 2011-2012 cocos2d-x.org
  6. Copyright (c) 2013-2014 Chukong Technologies Inc.
  7. http://www.cocos2d-x.org
  8. Permission is hereby granted, free of charge, to any person obtaining a copy
  9. of this software and associated documentation files (the "Software"), to deal
  10. in the Software without restriction, including without limitation the rights
  11. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. copies of the Software, and to permit persons to whom the Software is
  13. furnished to do so, subject to the following conditions:
  14. The above copyright notice and this permission notice shall be included in
  15. all copies or substantial portions of the Software.
  16. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22. THE SOFTWARE.
  23. ****************************************************************************/
  24. /**
  25. * cc.tiffReader is a singleton object, it's a tiff file reader, it can parse byte array to draw into a canvas
  26. * @class
  27. * @name cc.tiffReader
  28. */
  29. cc.tiffReader = /** @lends cc.tiffReader# */{
  30. _littleEndian: false,
  31. _tiffData: null,
  32. _fileDirectories: [],
  33. getUint8: function (offset) {
  34. return this._tiffData[offset];
  35. },
  36. getUint16: function (offset) {
  37. if (this._littleEndian)
  38. return (this._tiffData[offset + 1] << 8) | (this._tiffData[offset]);
  39. else
  40. return (this._tiffData[offset] << 8) | (this._tiffData[offset + 1]);
  41. },
  42. getUint32: function (offset) {
  43. var a = this._tiffData;
  44. if (this._littleEndian)
  45. return (a[offset + 3] << 24) | (a[offset + 2] << 16) | (a[offset + 1] << 8) | (a[offset]);
  46. else
  47. return (a[offset] << 24) | (a[offset + 1] << 16) | (a[offset + 2] << 8) | (a[offset + 3]);
  48. },
  49. checkLittleEndian: function () {
  50. var BOM = this.getUint16(0);
  51. if (BOM === 0x4949) {
  52. this.littleEndian = true;
  53. } else if (BOM === 0x4D4D) {
  54. this.littleEndian = false;
  55. } else {
  56. console.log(BOM);
  57. throw TypeError("Invalid byte order value.");
  58. }
  59. return this.littleEndian;
  60. },
  61. hasTowel: function () {
  62. // Check for towel.
  63. if (this.getUint16(2) !== 42) {
  64. throw RangeError("You forgot your towel!");
  65. return false;
  66. }
  67. return true;
  68. },
  69. getFieldTypeName: function (fieldType) {
  70. var typeNames = this.fieldTypeNames;
  71. if (fieldType in typeNames) {
  72. return typeNames[fieldType];
  73. }
  74. return null;
  75. },
  76. getFieldTagName: function (fieldTag) {
  77. var tagNames = this.fieldTagNames;
  78. if (fieldTag in tagNames) {
  79. return tagNames[fieldTag];
  80. } else {
  81. console.log("Unknown Field Tag:", fieldTag);
  82. return "Tag" + fieldTag;
  83. }
  84. },
  85. getFieldTypeLength: function (fieldTypeName) {
  86. if (['BYTE', 'ASCII', 'SBYTE', 'UNDEFINED'].indexOf(fieldTypeName) !== -1) {
  87. return 1;
  88. } else if (['SHORT', 'SSHORT'].indexOf(fieldTypeName) !== -1) {
  89. return 2;
  90. } else if (['LONG', 'SLONG', 'FLOAT'].indexOf(fieldTypeName) !== -1) {
  91. return 4;
  92. } else if (['RATIONAL', 'SRATIONAL', 'DOUBLE'].indexOf(fieldTypeName) !== -1) {
  93. return 8;
  94. }
  95. return null;
  96. },
  97. getFieldValues: function (fieldTagName, fieldTypeName, typeCount, valueOffset) {
  98. var fieldValues = [];
  99. var fieldTypeLength = this.getFieldTypeLength(fieldTypeName);
  100. var fieldValueSize = fieldTypeLength * typeCount;
  101. if (fieldValueSize <= 4) {
  102. // The value is stored at the big end of the valueOffset.
  103. if (this.littleEndian === false)
  104. fieldValues.push(valueOffset >>> ((4 - fieldTypeLength) * 8));
  105. else
  106. fieldValues.push(valueOffset);
  107. } else {
  108. for (var i = 0; i < typeCount; i++) {
  109. var indexOffset = fieldTypeLength * i;
  110. if (fieldTypeLength >= 8) {
  111. if (['RATIONAL', 'SRATIONAL'].indexOf(fieldTypeName) !== -1) {
  112. // Numerator
  113. fieldValues.push(this.getUint32(valueOffset + indexOffset));
  114. // Denominator
  115. fieldValues.push(this.getUint32(valueOffset + indexOffset + 4));
  116. } else {
  117. cc.log("Can't handle this field type or size");
  118. }
  119. } else {
  120. fieldValues.push(this.getBytes(fieldTypeLength, valueOffset + indexOffset));
  121. }
  122. }
  123. }
  124. if (fieldTypeName === 'ASCII') {
  125. fieldValues.forEach(function (e, i, a) {
  126. a[i] = String.fromCharCode(e);
  127. });
  128. }
  129. return fieldValues;
  130. },
  131. getBytes: function (numBytes, offset) {
  132. if (numBytes <= 0) {
  133. cc.log("No bytes requested");
  134. } else if (numBytes <= 1) {
  135. return this.getUint8(offset);
  136. } else if (numBytes <= 2) {
  137. return this.getUint16(offset);
  138. } else if (numBytes <= 3) {
  139. return this.getUint32(offset) >>> 8;
  140. } else if (numBytes <= 4) {
  141. return this.getUint32(offset);
  142. } else {
  143. cc.log("Too many bytes requested");
  144. }
  145. },
  146. getBits: function (numBits, byteOffset, bitOffset) {
  147. bitOffset = bitOffset || 0;
  148. var extraBytes = Math.floor(bitOffset / 8);
  149. var newByteOffset = byteOffset + extraBytes;
  150. var totalBits = bitOffset + numBits;
  151. var shiftRight = 32 - numBits;
  152. var shiftLeft,rawBits;
  153. if (totalBits <= 0) {
  154. console.log("No bits requested");
  155. } else if (totalBits <= 8) {
  156. shiftLeft = 24 + bitOffset;
  157. rawBits = this.getUint8(newByteOffset);
  158. } else if (totalBits <= 16) {
  159. shiftLeft = 16 + bitOffset;
  160. rawBits = this.getUint16(newByteOffset);
  161. } else if (totalBits <= 32) {
  162. shiftLeft = bitOffset;
  163. rawBits = this.getUint32(newByteOffset);
  164. } else {
  165. console.log( "Too many bits requested" );
  166. }
  167. return {
  168. 'bits': ((rawBits << shiftLeft) >>> shiftRight),
  169. 'byteOffset': newByteOffset + Math.floor(totalBits / 8),
  170. 'bitOffset': totalBits % 8
  171. };
  172. },
  173. parseFileDirectory: function (byteOffset) {
  174. var numDirEntries = this.getUint16(byteOffset);
  175. var tiffFields = [];
  176. for (var i = byteOffset + 2, entryCount = 0; entryCount < numDirEntries; i += 12, entryCount++) {
  177. var fieldTag = this.getUint16(i);
  178. var fieldType = this.getUint16(i + 2);
  179. var typeCount = this.getUint32(i + 4);
  180. var valueOffset = this.getUint32(i + 8);
  181. var fieldTagName = this.getFieldTagName(fieldTag);
  182. var fieldTypeName = this.getFieldTypeName(fieldType);
  183. var fieldValues = this.getFieldValues(fieldTagName, fieldTypeName, typeCount, valueOffset);
  184. tiffFields[fieldTagName] = { type: fieldTypeName, values: fieldValues };
  185. }
  186. this._fileDirectories.push(tiffFields);
  187. var nextIFDByteOffset = this.getUint32(i);
  188. if (nextIFDByteOffset !== 0x00000000) {
  189. this.parseFileDirectory(nextIFDByteOffset);
  190. }
  191. },
  192. clampColorSample: function(colorSample, bitsPerSample) {
  193. var multiplier = Math.pow(2, 8 - bitsPerSample);
  194. return Math.floor((colorSample * multiplier) + (multiplier - 1));
  195. },
  196. /**
  197. * @function
  198. * @param {Array} tiffData
  199. * @param {HTMLCanvasElement} canvas
  200. * @returns {*}
  201. */
  202. parseTIFF: function (tiffData, canvas) {
  203. canvas = canvas || cc.newElement('canvas');
  204. this._tiffData = tiffData;
  205. this.canvas = canvas;
  206. this.checkLittleEndian();
  207. if (!this.hasTowel()) {
  208. return;
  209. }
  210. var firstIFDByteOffset = this.getUint32(4);
  211. this._fileDirectories.length = 0;
  212. this.parseFileDirectory(firstIFDByteOffset);
  213. var fileDirectory = this._fileDirectories[0];
  214. var imageWidth = fileDirectory['ImageWidth'].values[0];
  215. var imageLength = fileDirectory['ImageLength'].values[0];
  216. this.canvas.width = imageWidth;
  217. this.canvas.height = imageLength;
  218. var strips = [];
  219. var compression = (fileDirectory['Compression']) ? fileDirectory['Compression'].values[0] : 1;
  220. var samplesPerPixel = fileDirectory['SamplesPerPixel'].values[0];
  221. var sampleProperties = [];
  222. var bitsPerPixel = 0;
  223. var hasBytesPerPixel = false;
  224. fileDirectory['BitsPerSample'].values.forEach(function (bitsPerSample, i, bitsPerSampleValues) {
  225. sampleProperties[i] = {
  226. bitsPerSample: bitsPerSample,
  227. hasBytesPerSample: false,
  228. bytesPerSample: undefined
  229. };
  230. if ((bitsPerSample % 8) === 0) {
  231. sampleProperties[i].hasBytesPerSample = true;
  232. sampleProperties[i].bytesPerSample = bitsPerSample / 8;
  233. }
  234. bitsPerPixel += bitsPerSample;
  235. }, this);
  236. if ((bitsPerPixel % 8) === 0) {
  237. hasBytesPerPixel = true;
  238. var bytesPerPixel = bitsPerPixel / 8;
  239. }
  240. var stripOffsetValues = fileDirectory['StripOffsets'].values;
  241. var numStripOffsetValues = stripOffsetValues.length;
  242. // StripByteCounts is supposed to be required, but see if we can recover anyway.
  243. if (fileDirectory['StripByteCounts']) {
  244. var stripByteCountValues = fileDirectory['StripByteCounts'].values;
  245. } else {
  246. cc.log("Missing StripByteCounts!");
  247. // Infer StripByteCounts, if possible.
  248. if (numStripOffsetValues === 1) {
  249. var stripByteCountValues = [Math.ceil((imageWidth * imageLength * bitsPerPixel) / 8)];
  250. } else {
  251. throw Error("Cannot recover from missing StripByteCounts");
  252. }
  253. }
  254. // Loop through strips and decompress as necessary.
  255. for (var i = 0; i < numStripOffsetValues; i++) {
  256. var stripOffset = stripOffsetValues[i];
  257. strips[i] = [];
  258. var stripByteCount = stripByteCountValues[i];
  259. // Loop through pixels.
  260. for (var byteOffset = 0, bitOffset = 0, jIncrement = 1, getHeader = true, pixel = [], numBytes = 0, sample = 0, currentSample = 0;
  261. byteOffset < stripByteCount; byteOffset += jIncrement) {
  262. // Decompress strip.
  263. switch (compression) {
  264. // Uncompressed
  265. case 1:
  266. // Loop through samples (sub-pixels).
  267. for (var m = 0, pixel = []; m < samplesPerPixel; m++) {
  268. if (sampleProperties[m].hasBytesPerSample) {
  269. // XXX: This is wrong!
  270. var sampleOffset = sampleProperties[m].bytesPerSample * m;
  271. pixel.push(this.getBytes(sampleProperties[m].bytesPerSample, stripOffset + byteOffset + sampleOffset));
  272. } else {
  273. var sampleInfo = this.getBits(sampleProperties[m].bitsPerSample, stripOffset + byteOffset, bitOffset);
  274. pixel.push(sampleInfo.bits);
  275. byteOffset = sampleInfo.byteOffset - stripOffset;
  276. bitOffset = sampleInfo.bitOffset;
  277. throw RangeError("Cannot handle sub-byte bits per sample");
  278. }
  279. }
  280. strips[i].push(pixel);
  281. if (hasBytesPerPixel) {
  282. jIncrement = bytesPerPixel;
  283. } else {
  284. jIncrement = 0;
  285. throw RangeError("Cannot handle sub-byte bits per pixel");
  286. }
  287. break;
  288. // CITT Group 3 1-Dimensional Modified Huffman run-length encoding
  289. case 2:
  290. // XXX: Use PDF.js code?
  291. break;
  292. // Group 3 Fax
  293. case 3:
  294. // XXX: Use PDF.js code?
  295. break;
  296. // Group 4 Fax
  297. case 4:
  298. // XXX: Use PDF.js code?
  299. break;
  300. // LZW
  301. case 5:
  302. // XXX: Use PDF.js code?
  303. break;
  304. // Old-style JPEG (TIFF 6.0)
  305. case 6:
  306. // XXX: Use PDF.js code?
  307. break;
  308. // New-style JPEG (TIFF Specification Supplement 2)
  309. case 7:
  310. // XXX: Use PDF.js code?
  311. break;
  312. // PackBits
  313. case 32773:
  314. // Are we ready for a new block?
  315. if (getHeader) {
  316. getHeader = false;
  317. var blockLength = 1;
  318. var iterations = 1;
  319. // The header byte is signed.
  320. var header = this.getInt8(stripOffset + byteOffset);
  321. if ((header >= 0) && (header <= 127)) { // Normal pixels.
  322. blockLength = header + 1;
  323. } else if ((header >= -127) && (header <= -1)) { // Collapsed pixels.
  324. iterations = -header + 1;
  325. } else /*if (header === -128)*/ { // Placeholder byte?
  326. getHeader = true;
  327. }
  328. } else {
  329. var currentByte = this.getUint8(stripOffset + byteOffset);
  330. // Duplicate bytes, if necessary.
  331. for (var m = 0; m < iterations; m++) {
  332. if (sampleProperties[sample].hasBytesPerSample) {
  333. // We're reading one byte at a time, so we need to handle multi-byte samples.
  334. currentSample = (currentSample << (8 * numBytes)) | currentByte;
  335. numBytes++;
  336. // Is our sample complete?
  337. if (numBytes === sampleProperties[sample].bytesPerSample) {
  338. pixel.push(currentSample);
  339. currentSample = numBytes = 0;
  340. sample++;
  341. }
  342. } else {
  343. throw RangeError("Cannot handle sub-byte bits per sample");
  344. }
  345. // Is our pixel complete?
  346. if (sample === samplesPerPixel) {
  347. strips[i].push(pixel);
  348. pixel = [];
  349. sample = 0;
  350. }
  351. }
  352. blockLength--;
  353. // Is our block complete?
  354. if (blockLength === 0) {
  355. getHeader = true;
  356. }
  357. }
  358. jIncrement = 1;
  359. break;
  360. // Unknown compression algorithm
  361. default:
  362. // Do not attempt to parse the image data.
  363. break;
  364. }
  365. }
  366. }
  367. if (canvas.getContext) {
  368. var ctx = this.canvas.getContext("2d");
  369. // Set a default fill style.
  370. ctx.fillStyle = "rgba(255, 255, 255, 0)";
  371. // If RowsPerStrip is missing, the whole image is in one strip.
  372. var rowsPerStrip = fileDirectory['RowsPerStrip'] ? fileDirectory['RowsPerStrip'].values[0] : imageLength;
  373. var numStrips = strips.length;
  374. var imageLengthModRowsPerStrip = imageLength % rowsPerStrip;
  375. var rowsInLastStrip = (imageLengthModRowsPerStrip === 0) ? rowsPerStrip : imageLengthModRowsPerStrip;
  376. var numRowsInStrip = rowsPerStrip;
  377. var numRowsInPreviousStrip = 0;
  378. var photometricInterpretation = fileDirectory['PhotometricInterpretation'].values[0];
  379. var extraSamplesValues = [];
  380. var numExtraSamples = 0;
  381. if (fileDirectory['ExtraSamples']) {
  382. extraSamplesValues = fileDirectory['ExtraSamples'].values;
  383. numExtraSamples = extraSamplesValues.length;
  384. }
  385. if (fileDirectory['ColorMap']) {
  386. var colorMapValues = fileDirectory['ColorMap'].values;
  387. var colorMapSampleSize = Math.pow(2, sampleProperties[0].bitsPerSample);
  388. }
  389. // Loop through the strips in the image.
  390. for (var i = 0; i < numStrips; i++) {
  391. // The last strip may be short.
  392. if ((i + 1) === numStrips) {
  393. numRowsInStrip = rowsInLastStrip;
  394. }
  395. var numPixels = strips[i].length;
  396. var yPadding = numRowsInPreviousStrip * i;
  397. // Loop through the rows in the strip.
  398. for (var y = 0, j = 0; y < numRowsInStrip, j < numPixels; y++) {
  399. // Loop through the pixels in the row.
  400. for (var x = 0; x < imageWidth; x++, j++) {
  401. var pixelSamples = strips[i][j];
  402. var red = 0;
  403. var green = 0;
  404. var blue = 0;
  405. var opacity = 1.0;
  406. if (numExtraSamples > 0) {
  407. for (var k = 0; k < numExtraSamples; k++) {
  408. if (extraSamplesValues[k] === 1 || extraSamplesValues[k] === 2) {
  409. // Clamp opacity to the range [0,1].
  410. opacity = pixelSamples[3 + k] / 256;
  411. break;
  412. }
  413. }
  414. }
  415. switch (photometricInterpretation) {
  416. // Bilevel or Grayscale
  417. // WhiteIsZero
  418. case 0:
  419. if (sampleProperties[0].hasBytesPerSample) {
  420. var invertValue = Math.pow(0x10, sampleProperties[0].bytesPerSample * 2);
  421. }
  422. // Invert samples.
  423. pixelSamples.forEach(function (sample, index, samples) {
  424. samples[index] = invertValue - sample;
  425. });
  426. // Bilevel or Grayscale
  427. // BlackIsZero
  428. case 1:
  429. red = green = blue = this.clampColorSample(pixelSamples[0], sampleProperties[0].bitsPerSample);
  430. break;
  431. // RGB Full Color
  432. case 2:
  433. red = this.clampColorSample(pixelSamples[0], sampleProperties[0].bitsPerSample);
  434. green = this.clampColorSample(pixelSamples[1], sampleProperties[1].bitsPerSample);
  435. blue = this.clampColorSample(pixelSamples[2], sampleProperties[2].bitsPerSample);
  436. break;
  437. // RGB Color Palette
  438. case 3:
  439. if (colorMapValues === undefined) {
  440. throw Error("Palette image missing color map");
  441. }
  442. var colorMapIndex = pixelSamples[0];
  443. red = this.clampColorSample(colorMapValues[colorMapIndex], 16);
  444. green = this.clampColorSample(colorMapValues[colorMapSampleSize + colorMapIndex], 16);
  445. blue = this.clampColorSample(colorMapValues[(2 * colorMapSampleSize) + colorMapIndex], 16);
  446. break;
  447. // Unknown Photometric Interpretation
  448. default:
  449. throw RangeError('Unknown Photometric Interpretation:', photometricInterpretation);
  450. break;
  451. }
  452. ctx.fillStyle = "rgba(" + red + ", " + green + ", " + blue + ", " + opacity + ")";
  453. ctx.fillRect(x, yPadding + y, 1, 1);
  454. }
  455. }
  456. numRowsInPreviousStrip = numRowsInStrip;
  457. }
  458. }
  459. return this.canvas;
  460. },
  461. // See: http://www.digitizationguidelines.gov/guidelines/TIFF_Metadata_Final.pdf
  462. // See: http://www.digitalpreservation.gov/formats/content/tiff_tags.shtml
  463. fieldTagNames: {
  464. // TIFF Baseline
  465. 0x013B: 'Artist',
  466. 0x0102: 'BitsPerSample',
  467. 0x0109: 'CellLength',
  468. 0x0108: 'CellWidth',
  469. 0x0140: 'ColorMap',
  470. 0x0103: 'Compression',
  471. 0x8298: 'Copyright',
  472. 0x0132: 'DateTime',
  473. 0x0152: 'ExtraSamples',
  474. 0x010A: 'FillOrder',
  475. 0x0121: 'FreeByteCounts',
  476. 0x0120: 'FreeOffsets',
  477. 0x0123: 'GrayResponseCurve',
  478. 0x0122: 'GrayResponseUnit',
  479. 0x013C: 'HostComputer',
  480. 0x010E: 'ImageDescription',
  481. 0x0101: 'ImageLength',
  482. 0x0100: 'ImageWidth',
  483. 0x010F: 'Make',
  484. 0x0119: 'MaxSampleValue',
  485. 0x0118: 'MinSampleValue',
  486. 0x0110: 'Model',
  487. 0x00FE: 'NewSubfileType',
  488. 0x0112: 'Orientation',
  489. 0x0106: 'PhotometricInterpretation',
  490. 0x011C: 'PlanarConfiguration',
  491. 0x0128: 'ResolutionUnit',
  492. 0x0116: 'RowsPerStrip',
  493. 0x0115: 'SamplesPerPixel',
  494. 0x0131: 'Software',
  495. 0x0117: 'StripByteCounts',
  496. 0x0111: 'StripOffsets',
  497. 0x00FF: 'SubfileType',
  498. 0x0107: 'Threshholding',
  499. 0x011A: 'XResolution',
  500. 0x011B: 'YResolution',
  501. // TIFF Extended
  502. 0x0146: 'BadFaxLines',
  503. 0x0147: 'CleanFaxData',
  504. 0x0157: 'ClipPath',
  505. 0x0148: 'ConsecutiveBadFaxLines',
  506. 0x01B1: 'Decode',
  507. 0x01B2: 'DefaultImageColor',
  508. 0x010D: 'DocumentName',
  509. 0x0150: 'DotRange',
  510. 0x0141: 'HalftoneHints',
  511. 0x015A: 'Indexed',
  512. 0x015B: 'JPEGTables',
  513. 0x011D: 'PageName',
  514. 0x0129: 'PageNumber',
  515. 0x013D: 'Predictor',
  516. 0x013F: 'PrimaryChromaticities',
  517. 0x0214: 'ReferenceBlackWhite',
  518. 0x0153: 'SampleFormat',
  519. 0x022F: 'StripRowCounts',
  520. 0x014A: 'SubIFDs',
  521. 0x0124: 'T4Options',
  522. 0x0125: 'T6Options',
  523. 0x0145: 'TileByteCounts',
  524. 0x0143: 'TileLength',
  525. 0x0144: 'TileOffsets',
  526. 0x0142: 'TileWidth',
  527. 0x012D: 'TransferFunction',
  528. 0x013E: 'WhitePoint',
  529. 0x0158: 'XClipPathUnits',
  530. 0x011E: 'XPosition',
  531. 0x0211: 'YCbCrCoefficients',
  532. 0x0213: 'YCbCrPositioning',
  533. 0x0212: 'YCbCrSubSampling',
  534. 0x0159: 'YClipPathUnits',
  535. 0x011F: 'YPosition',
  536. // EXIF
  537. 0x9202: 'ApertureValue',
  538. 0xA001: 'ColorSpace',
  539. 0x9004: 'DateTimeDigitized',
  540. 0x9003: 'DateTimeOriginal',
  541. 0x8769: 'Exif IFD',
  542. 0x9000: 'ExifVersion',
  543. 0x829A: 'ExposureTime',
  544. 0xA300: 'FileSource',
  545. 0x9209: 'Flash',
  546. 0xA000: 'FlashpixVersion',
  547. 0x829D: 'FNumber',
  548. 0xA420: 'ImageUniqueID',
  549. 0x9208: 'LightSource',
  550. 0x927C: 'MakerNote',
  551. 0x9201: 'ShutterSpeedValue',
  552. 0x9286: 'UserComment',
  553. // IPTC
  554. 0x83BB: 'IPTC',
  555. // ICC
  556. 0x8773: 'ICC Profile',
  557. // XMP
  558. 0x02BC: 'XMP',
  559. // GDAL
  560. 0xA480: 'GDAL_METADATA',
  561. 0xA481: 'GDAL_NODATA',
  562. // Photoshop
  563. 0x8649: 'Photoshop'
  564. },
  565. fieldTypeNames: {
  566. 0x0001: 'BYTE',
  567. 0x0002: 'ASCII',
  568. 0x0003: 'SHORT',
  569. 0x0004: 'LONG',
  570. 0x0005: 'RATIONAL',
  571. 0x0006: 'SBYTE',
  572. 0x0007: 'UNDEFINED',
  573. 0x0008: 'SSHORT',
  574. 0x0009: 'SLONG',
  575. 0x000A: 'SRATIONAL',
  576. 0x000B: 'FLOAT',
  577. 0x000C: 'DOUBLE'
  578. }
  579. };