| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 /** | 5 /** |
| 6 * A namespace class for image encoding functions. All methods are static. | 6 * A namespace class for image encoding functions. All methods are static. |
| 7 */ | 7 */ |
| 8 function ImageEncoder() {} | 8 function ImageEncoder() {} |
| 9 | 9 |
| 10 ImageEncoder.MAX_THUMBNAIL_DIMENSION = 320; | 10 ImageEncoder.MAX_THUMBNAIL_DIMENSION = 320; |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 /** | 150 /** |
| 151 * A base class for a metadata encoder. | 151 * A base class for a metadata encoder. |
| 152 * | 152 * |
| 153 * Serves as a default metadata encoder for images that none of the metadata | 153 * Serves as a default metadata encoder for images that none of the metadata |
| 154 * parsers recognized. | 154 * parsers recognized. |
| 155 * | 155 * |
| 156 * @param {Object} original_metadata | 156 * @param {Object} original_metadata |
| 157 */ | 157 */ |
| 158 ImageEncoder.MetadataEncoder = function(original_metadata) { | 158 ImageEncoder.MetadataEncoder = function(original_metadata) { |
| 159 this.metadata_ = ImageUtil.deepCopy(original_metadata) || {}; | 159 this.metadata_ = ImageUtil.deepCopy(original_metadata) || {}; |
| 160 if (!this.metadata_.mimeType) { | 160 if (this.metadata_.mimeType != 'image/jpeg') { |
| 161 // For the purposes saving to a file and thumbnail generation we assume | 161 // Chrome can only encode JPEG and PNG. Force PNG mime type so that we |
| 162 // it is a png. | 162 // can save to file and generate a thumbnail. |
| 163 this.metadata_.mimeType = 'image/png'; | 163 this.metadata_.mimeType = 'image/png'; |
| 164 } | 164 } |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 ImageEncoder.MetadataEncoder.prototype.getMetadata = function() { | 167 ImageEncoder.MetadataEncoder.prototype.getMetadata = function() { |
| 168 return this.metadata_; | 168 return this.metadata_; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 /** | 171 /** |
| 172 * @param {HTMLCanvasElement|Object} canvas Canvas or or anything with | 172 * @param {HTMLCanvasElement|Object} canvas Canvas or or anything with |
| (...skipping 23 matching lines...) Expand all Loading... |
| 196 findInsertionRange = function(encodedImage) { return {from: 0, to: 0} }; | 196 findInsertionRange = function(encodedImage) { return {from: 0, to: 0} }; |
| 197 | 197 |
| 198 /** | 198 /** |
| 199 * Return serialized metadata ready to write to an image file. | 199 * Return serialized metadata ready to write to an image file. |
| 200 * The return type is optimized for passing to Blob.append. | 200 * The return type is optimized for passing to Blob.append. |
| 201 * @return {ArrayBuffer} | 201 * @return {ArrayBuffer} |
| 202 */ | 202 */ |
| 203 ImageEncoder.MetadataEncoder.prototype.encode = function() { | 203 ImageEncoder.MetadataEncoder.prototype.encode = function() { |
| 204 return new Uint8Array(0).buffer; | 204 return new Uint8Array(0).buffer; |
| 205 }; | 205 }; |
| OLD | NEW |