CCTIFFReader.js 25 KB

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