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 /** | 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 /** | 10 /** |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 /** | 212 /** |
213 * Gets mime type from metadata. It reads media.mimeType at first, and if it | 213 * Gets mime type from metadata. It reads media.mimeType at first, and if it |
214 * fails, it falls back to external.contentMimeType. If both fields are | 214 * fails, it falls back to external.contentMimeType. If both fields are |
215 * undefined, it means that metadata is broken. Then it throws an exception. | 215 * undefined, it means that metadata is broken. Then it throws an exception. |
216 * | 216 * |
217 * @param {!MetadataItem} metadata Metadata. | 217 * @param {!MetadataItem} metadata Metadata. |
218 * @return {string} Mime type. | 218 * @return {string} Mime type. |
219 * @private | 219 * @private |
220 */ | 220 */ |
221 ImageEncoder.MetadataEncoder.getMimeType_ = function(metadata) { | 221 ImageEncoder.MetadataEncoder.getMimeType_ = function(metadata) { |
222 if (metadata.mediaMimeType) | 222 return assert(metadata.mediaMimeType || metadata.contentMimeType); |
223 return metadata.mediaMimeType; | |
224 else if (metadata.contentMimeType) | |
225 return metadata.contentMimeType; | |
226 | |
227 assertNotReached(); | |
228 }; | 223 }; |
229 | 224 |
230 /** | 225 /** |
231 * Sets an image data. | 226 * Sets an image data. |
232 * @param {!HTMLCanvasElement} canvas Canvas or anything with width and height | 227 * @param {!HTMLCanvasElement} canvas Canvas or anything with width and height |
233 * properties. | 228 * properties. |
234 */ | 229 */ |
235 ImageEncoder.MetadataEncoder.prototype.setImageData = function(canvas) { | 230 ImageEncoder.MetadataEncoder.prototype.setImageData = function(canvas) { |
236 this.imageWidth = canvas.width; | 231 this.imageWidth = canvas.width; |
237 this.imageHeight = canvas.height; | 232 this.imageHeight = canvas.height; |
(...skipping 19 matching lines...) Expand all Loading... |
257 findInsertionRange = function(encodedImage) { return {from: 0, to: 0}; }; | 252 findInsertionRange = function(encodedImage) { return {from: 0, to: 0}; }; |
258 | 253 |
259 /** | 254 /** |
260 * Returns serialized metadata ready to write to an image file. | 255 * Returns serialized metadata ready to write to an image file. |
261 * The return type is optimized for passing to Blob.append. | 256 * The return type is optimized for passing to Blob.append. |
262 * @return {!ArrayBuffer} Serialized metadata. | 257 * @return {!ArrayBuffer} Serialized metadata. |
263 */ | 258 */ |
264 ImageEncoder.MetadataEncoder.prototype.encode = function() { | 259 ImageEncoder.MetadataEncoder.prototype.encode = function() { |
265 return new Uint8Array(0).buffer; | 260 return new Uint8Array(0).buffer; |
266 }; | 261 }; |
OLD | NEW |