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 var mimeType = metadata.mediaMimeType || metadata.contentMimeType; |
223 return metadata.mediaMimeType; | 223 return assert(mimeType); |
Dan Beam
2015/10/16 07:20:47
return assert(metadata.mediaMimeType || metadata.c
fukino
2015/10/19 09:55:14
Done.
| |
224 else if (metadata.contentMimeType) | |
225 return metadata.contentMimeType; | |
226 | |
227 assertNotReached(); | |
228 }; | 224 }; |
229 | 225 |
230 /** | 226 /** |
231 * Sets an image data. | 227 * Sets an image data. |
232 * @param {!HTMLCanvasElement} canvas Canvas or anything with width and height | 228 * @param {!HTMLCanvasElement} canvas Canvas or anything with width and height |
233 * properties. | 229 * properties. |
234 */ | 230 */ |
235 ImageEncoder.MetadataEncoder.prototype.setImageData = function(canvas) { | 231 ImageEncoder.MetadataEncoder.prototype.setImageData = function(canvas) { |
236 this.imageWidth = canvas.width; | 232 this.imageWidth = canvas.width; |
237 this.imageHeight = canvas.height; | 233 this.imageHeight = canvas.height; |
(...skipping 19 matching lines...) Expand all Loading... | |
257 findInsertionRange = function(encodedImage) { return {from: 0, to: 0}; }; | 253 findInsertionRange = function(encodedImage) { return {from: 0, to: 0}; }; |
258 | 254 |
259 /** | 255 /** |
260 * Returns serialized metadata ready to write to an image file. | 256 * Returns serialized metadata ready to write to an image file. |
261 * The return type is optimized for passing to Blob.append. | 257 * The return type is optimized for passing to Blob.append. |
262 * @return {!ArrayBuffer} Serialized metadata. | 258 * @return {!ArrayBuffer} Serialized metadata. |
263 */ | 259 */ |
264 ImageEncoder.MetadataEncoder.prototype.encode = function() { | 260 ImageEncoder.MetadataEncoder.prototype.encode = function() { |
265 return new Uint8Array(0).buffer; | 261 return new Uint8Array(0).buffer; |
266 }; | 262 }; |
OLD | NEW |