| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 // TODO:(kaznacheev) Share the EXIF constants with exif_parser.js | 7 // TODO:(kaznacheev) Share the EXIF constants with exif_parser.js |
| 8 var EXIF_MARK_SOS = 0xffda; // Start of "stream" (the actual image data). | 8 var EXIF_MARK_SOS = 0xffda; // Start of "stream" (the actual image data). |
| 9 var EXIF_MARK_SOI = 0xffd8; // Start of image data. | 9 var EXIF_MARK_SOI = 0xffd8; // Start of image data. |
| 10 var EXIF_MARK_EOI = 0xffd9; // End of image data. | 10 var EXIF_MARK_EOI = 0xffd9; // End of image data. |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 canvas.height; | 113 canvas.height; |
| 114 | 114 |
| 115 // The values for these tags will be set in ExifWriter.encode. | 115 // The values for these tags will be set in ExifWriter.encode. |
| 116 ExifEncoder.findOrCreateTag(thumbnail, EXIF_TAG_JPG_THUMB_OFFSET); | 116 ExifEncoder.findOrCreateTag(thumbnail, EXIF_TAG_JPG_THUMB_OFFSET); |
| 117 ExifEncoder.findOrCreateTag(thumbnail, EXIF_TAG_JPG_THUMB_LENGTH); | 117 ExifEncoder.findOrCreateTag(thumbnail, EXIF_TAG_JPG_THUMB_LENGTH); |
| 118 | 118 |
| 119 // Always save in default orientation. | 119 // Always save in default orientation. |
| 120 ExifEncoder.findOrCreateTag(thumbnail, EXIF_TAG_ORIENTATION).value = 1; | 120 ExifEncoder.findOrCreateTag(thumbnail, EXIF_TAG_ORIENTATION).value = 1; |
| 121 } else { | 121 } else { |
| 122 console.warn( | 122 console.warn( |
| 123 'Thumbnail URL too long: ' + this.metadata_.thumbnailURL.length); | 123 'Thumbnail URL too long: ' + this.metadata_.thumbnailURL.length); |
| 124 // Delete thumbnail ifd so that it is not written out to a file, but | 124 // Delete thumbnail ifd so that it is not written out to a file, but |
| 125 // keep thumbnailURL for display purposes. | 125 // keep thumbnailURL for display purposes. |
| 126 if (this.ifd_.thumbnail) { | 126 if (this.ifd_.thumbnail) { |
| 127 delete this.ifd_.thumbnail; | 127 delete this.ifd_.thumbnail; |
| 128 } | 128 } |
| 129 } | 129 } |
| 130 delete this.metadata_.thumbnailTransform; | 130 delete this.metadata_.thumbnailTransform; |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 /** | 133 /** |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 if (width == 8) { | 372 if (width == 8) { |
| 373 bw.writeScalar(value[0], 4, signed); | 373 bw.writeScalar(value[0], 4, signed); |
| 374 bw.writeScalar(value[1], 4, signed); | 374 bw.writeScalar(value[1], 4, signed); |
| 375 } else { | 375 } else { |
| 376 bw.writeScalar(value, width, signed); | 376 bw.writeScalar(value, width, signed); |
| 377 } | 377 } |
| 378 }; | 378 }; |
| 379 | 379 |
| 380 var signed = (tag.format == 9 || tag.format == 10); | 380 var signed = (tag.format == 9 || tag.format == 10); |
| 381 if (tag.componentCount == 1) { | 381 if (tag.componentCount == 1) { |
| 382 writeComponent(tag.value, signed); | 382 writeComponent(tag.value, signed); |
| 383 } else { | 383 } else { |
| 384 for (var i = 0; i != tag.componentCount; i++) { | 384 for (var i = 0; i != tag.componentCount; i++) { |
| 385 writeComponent(tag.value[i], signed); | 385 writeComponent(tag.value[i], signed); |
| 386 } | 386 } |
| 387 } | 387 } |
| 388 } | 388 } |
| 389 }; | 389 }; |
| 390 | 390 |
| 391 /** | 391 /** |
| 392 * @param {{Object.<number,Object>}} directory EXIF directory. | 392 * @param {{Object.<number,Object>}} directory EXIF directory. |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 }; | 470 }; |
| 471 | 471 |
| 472 /** | 472 /** |
| 473 * Writes scalar value to output stream. | 473 * Writes scalar value to output stream. |
| 474 * @param {number} value Value to write. | 474 * @param {number} value Value to write. |
| 475 * @param {number} width Desired width of written value. | 475 * @param {number} width Desired width of written value. |
| 476 * @param {boolean=} opt_signed True if value represents signed number. | 476 * @param {boolean=} opt_signed True if value represents signed number. |
| 477 */ | 477 */ |
| 478 ByteWriter.prototype.writeScalar = function(value, width, opt_signed) { | 478 ByteWriter.prototype.writeScalar = function(value, width, opt_signed) { |
| 479 var method; | 479 var method; |
| 480 // The below switch is so verbose for two reasons: | 480 // The below switch is so verbose for two reasons: |
| 481 // 1. V8 is faster on method names which are 'symbols'. | 481 // 1. V8 is faster on method names which are 'symbols'. |
| 482 // 2. Method names are discoverable by full text search. | 482 // 2. Method names are discoverable by full text search. |
| 483 switch (width) { | 483 switch (width) { |
| 484 case 1: | 484 case 1: |
| 485 method = opt_signed ? 'setInt8' : 'setUint8'; | 485 method = opt_signed ? 'setInt8' : 'setUint8'; |
| 486 break; | 486 break; |
| 487 | 487 |
| 488 case 2: | 488 case 2: |
| 489 method = opt_signed ? 'setInt16' : 'setUint16'; | 489 method = opt_signed ? 'setInt16' : 'setUint16'; |
| 490 break; | 490 break; |
| 491 | 491 |
| 492 case 4: | 492 case 4: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 }; | 560 }; |
| 561 | 561 |
| 562 /** | 562 /** |
| 563 * Check if every forward has been resolved, throw and error if not. | 563 * Check if every forward has been resolved, throw and error if not. |
| 564 */ | 564 */ |
| 565 ByteWriter.prototype.checkResolved = function() { | 565 ByteWriter.prototype.checkResolved = function() { |
| 566 for (var key in this.forwards_) { | 566 for (var key in this.forwards_) { |
| 567 throw new Error('Unresolved forward pointer ' + key.toString(16)); | 567 throw new Error('Unresolved forward pointer ' + key.toString(16)); |
| 568 } | 568 } |
| 569 }; | 569 }; |
| OLD | NEW |