OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // TODO:(kaznacheev) Share the EXIF constants with exif_parser.js | 5 // TODO:(kaznacheev) Share the EXIF constants with exif_parser.js |
6 var EXIF_MARK_SOS = 0xffda; // Start of "stream" (the actual image data). | 6 var EXIF_MARK_SOS = 0xffda; // Start of "stream" (the actual image data). |
7 var EXIF_MARK_SOI = 0xffd8; // Start of image data. | 7 var EXIF_MARK_SOI = 0xffd8; // Start of image data. |
8 var EXIF_MARK_EOI = 0xffd9; // End of image data. | 8 var EXIF_MARK_EOI = 0xffd9; // End of image data. |
9 | 9 |
10 var EXIF_MARK_APP0 = 0xffe0; // APP0 block, most commonly JFIF data. | 10 var EXIF_MARK_APP0 = 0xffe0; // APP0 block, most commonly JFIF data. |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 } | 314 } |
315 | 315 |
316 // Write out the long values and resolve pointers. | 316 // Write out the long values and resolve pointers. |
317 for (var i = 0; i != longValues.length; i++) { | 317 for (var i = 0; i != longValues.length; i++) { |
318 var longValue = longValues[i]; | 318 var longValue = longValues[i]; |
319 bw.resolveOffset(longValue.id); | 319 bw.resolveOffset(longValue.id); |
320 ExifEncoder.writeValue(bw, longValue); | 320 ExifEncoder.writeValue(bw, longValue); |
321 } | 321 } |
322 }; | 322 }; |
323 | 323 |
324 // TODO(kaznacheev): Share with ExifParser? | 324 /** |
325 // TODO(JSDOC) | 325 * @param {{format:number, id:number}} tag EXIF tag object. |
| 326 * @return {number} Width in bytes of the data unit associated with this tag. |
| 327 * TODO(kaznacheev): Share with ExifParser? |
| 328 */ |
326 ExifEncoder.getComponentWidth = function(tag) { | 329 ExifEncoder.getComponentWidth = function(tag) { |
327 switch (tag.format) { | 330 switch (tag.format) { |
328 case 1: // Byte | 331 case 1: // Byte |
329 case 2: // String | 332 case 2: // String |
330 case 7: // Undefined | 333 case 7: // Undefined |
331 return 1; | 334 return 1; |
332 | 335 |
333 case 3: // Short | 336 case 3: // Short |
334 return 2; | 337 return 2; |
335 | 338 |
336 case 4: // Long | 339 case 4: // Long |
337 case 9: // Signed Long | 340 case 9: // Signed Long |
338 return 4; | 341 return 4; |
339 | 342 |
340 case 5: // Rational | 343 case 5: // Rational |
341 case 10: // Signed Rational | 344 case 10: // Signed Rational |
342 return 8; | 345 return 8; |
343 | 346 |
344 default: // ??? | 347 default: // ??? |
345 throw new Error('Unknown tag format 0x' + | 348 console.warn('Unknown tag format 0x' + |
346 Number(tag.id).toString(16) + ': ' + tag.format); | 349 Number(tag.id).toString(16) + ': ' + tag.format); |
347 return 4; | 350 return 4; |
348 } | 351 } |
349 }; | 352 }; |
350 | 353 |
351 /** | 354 /** |
352 * Writes out the tag value. | 355 * Writes out the tag value. |
353 * @param {ByteWriter} bw Writer to use. | 356 * @param {ByteWriter} bw Writer to use. |
354 * @param {Object} tag Tag, which value to write. | 357 * @param {Object} tag Tag, which value to write. |
355 */ | 358 */ |
(...skipping 20 matching lines...) Expand all Loading... |
376 if (tag.componentCount == 1) { | 379 if (tag.componentCount == 1) { |
377 writeComponent(tag.value, signed); | 380 writeComponent(tag.value, signed); |
378 } else { | 381 } else { |
379 for (var i = 0; i != tag.componentCount; i++) { | 382 for (var i = 0; i != tag.componentCount; i++) { |
380 writeComponent(tag.value[i], signed); | 383 writeComponent(tag.value[i], signed); |
381 } | 384 } |
382 } | 385 } |
383 } | 386 } |
384 }; | 387 }; |
385 | 388 |
386 //TODO(JSDOC) | 389 /** |
| 390 * @param {{Object.<number,Object>}} directory EXIF directory. |
| 391 * @param {number} id Tag id. |
| 392 * @param {number} format Tag format |
| 393 * (used in {@link ExifEncoder#getComponentWidth}). |
| 394 * @param {number} componentCount Number of components in this tag. |
| 395 * @return {{id:number, format:number, componentCount:number}} |
| 396 * Tag found or created. |
| 397 */ |
387 ExifEncoder.findOrCreateTag = function(directory, id, format, componentCount) { | 398 ExifEncoder.findOrCreateTag = function(directory, id, format, componentCount) { |
388 if (!(id in directory)) { | 399 if (!(id in directory)) { |
389 directory[id] = { | 400 directory[id] = { |
390 id: id, | 401 id: id, |
391 format: format || 3, // Short | 402 format: format || 3, // Short |
392 componentCount: componentCount || 1 | 403 componentCount: componentCount || 1 |
393 }; | 404 }; |
394 } | 405 } |
395 return directory[id]; | 406 return directory[id]; |
396 }; | 407 }; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 }; | 558 }; |
548 | 559 |
549 /** | 560 /** |
550 * Check if every forward has been resolved, throw and error if not. | 561 * Check if every forward has been resolved, throw and error if not. |
551 */ | 562 */ |
552 ByteWriter.prototype.checkResolved = function() { | 563 ByteWriter.prototype.checkResolved = function() { |
553 for (var key in this.forwards_) { | 564 for (var key in this.forwards_) { |
554 throw new Error('Unresolved forward pointer ' + key.toString(16)); | 565 throw new Error('Unresolved forward pointer ' + key.toString(16)); |
555 } | 566 } |
556 }; | 567 }; |
OLD | NEW |