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 | 5 |
6 // Namespace object for the utilities. | 6 // Namespace object for the utilities. |
7 function ImageUtil() {} | 7 function ImageUtil() {} |
8 | 8 |
9 /** | 9 /** |
10 * Performance trace. | 10 * Performance trace. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 * @return {number} The closest to the |value| number in span [min, max]. | 60 * @return {number} The closest to the |value| number in span [min, max]. |
61 */ | 61 */ |
62 ImageUtil.clamp = function(min, value, max) { | 62 ImageUtil.clamp = function(min, value, max) { |
63 return Math.max(min, Math.min(max, value)); | 63 return Math.max(min, Math.min(max, value)); |
64 }; | 64 }; |
65 | 65 |
66 /** | 66 /** |
67 * @param {number} min Minimum value. | 67 * @param {number} min Minimum value. |
68 * @param {number} value Value to check. | 68 * @param {number} value Value to check. |
69 * @param {number} max Maximum value. | 69 * @param {number} max Maximum value. |
70 * @return {boolean} True if value is between | 70 * @return {boolean} True if value is between. |
71 */ | 71 */ |
72 ImageUtil.between = function(min, value, max) { | 72 ImageUtil.between = function(min, value, max) { |
73 return (value - min) * (value - max) <= 0; | 73 return (value - min) * (value - max) <= 0; |
74 }; | 74 }; |
75 | 75 |
76 /** | 76 /** |
77 * Rectangle class. | 77 * Rectangle class. |
78 */ | 78 */ |
79 | 79 |
80 /** | 80 /** |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 return x * x + y * y <= this.squaredR; | 351 return x * x + y * y <= this.squaredR; |
352 }; | 352 }; |
353 | 353 |
354 /** | 354 /** |
355 * Copy an image applying scaling and rotation. | 355 * Copy an image applying scaling and rotation. |
356 * | 356 * |
357 * @param {HTMLCanvasElement} dst Destination. | 357 * @param {HTMLCanvasElement} dst Destination. |
358 * @param {HTMLCanvasElement|HTMLImageElement} src Source. | 358 * @param {HTMLCanvasElement|HTMLImageElement} src Source. |
359 * @param {number} scaleX Y scale transformation. | 359 * @param {number} scaleX Y scale transformation. |
360 * @param {number} scaleY X scale transformation. | 360 * @param {number} scaleY X scale transformation. |
361 * @param {number} angle (in radians) | 361 * @param {number} angle (in radians). |
362 */ | 362 */ |
363 ImageUtil.drawImageTransformed = function(dst, src, scaleX, scaleY, angle) { | 363 ImageUtil.drawImageTransformed = function(dst, src, scaleX, scaleY, angle) { |
364 var context = dst.getContext('2d'); | 364 var context = dst.getContext('2d'); |
365 context.save(); | 365 context.save(); |
366 context.translate(context.canvas.width / 2, context.canvas.height / 2); | 366 context.translate(context.canvas.width / 2, context.canvas.height / 2); |
367 context.rotate(angle); | 367 context.rotate(angle); |
368 context.scale(scaleX, scaleY); | 368 context.scale(scaleX, scaleY); |
369 context.drawImage(src, -src.width / 2, -src.height / 2); | 369 context.drawImage(src, -src.width / 2, -src.height / 2); |
370 context.restore(); | 370 context.restore(); |
371 }; | 371 }; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 * metadata, should have |width| and |height| properties. | 430 * metadata, should have |width| and |height| properties. |
431 * @return {boolean} True if the image is too large to be loaded. | 431 * @return {boolean} True if the image is too large to be loaded. |
432 */ | 432 */ |
433 ImageUtil.ImageLoader.isTooLarge = function(image) { | 433 ImageUtil.ImageLoader.isTooLarge = function(image) { |
434 return image.width * image.height > ImageUtil.ImageLoader.IMAGE_SIZE_LIMIT; | 434 return image.width * image.height > ImageUtil.ImageLoader.IMAGE_SIZE_LIMIT; |
435 }; | 435 }; |
436 | 436 |
437 /** | 437 /** |
438 * @param {string} url Image URL. | 438 * @param {string} url Image URL. |
439 * @param {function(function(object))} transformFetcher function to get | 439 * @param {function(function(object))} transformFetcher function to get |
440 * the image transform (which we need for the image orientation) | 440 * the image transform (which we need for the image orientation). |
441 * @param {function(HTMLCanvasElement)} callback To be called when loaded. | 441 * @param {function(HTMLCanvasElement)} callback To be called when loaded. |
442 * @param {number} opt_delay Load delay in milliseconds, useful to let the | 442 * @param {number} opt_delay Load delay in milliseconds, useful to let the |
443 * animations play out before the computation heavy image loading starts. | 443 * animations play out before the computation heavy image loading starts. |
444 */ | 444 */ |
445 ImageUtil.ImageLoader.prototype.load = function( | 445 ImageUtil.ImageLoader.prototype.load = function( |
446 url, transformFetcher, callback, opt_delay) { | 446 url, transformFetcher, callback, opt_delay) { |
447 this.cancel(); | 447 this.cancel(); |
448 | 448 |
449 this.url_ = url; | 449 this.url_ = url; |
450 this.callback_ = callback; | 450 this.callback_ = callback; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 * @return {string} Full name. | 681 * @return {string} Full name. |
682 */ | 682 */ |
683 ImageUtil.getMetricName = function(name) { | 683 ImageUtil.getMetricName = function(name) { |
684 return 'PhotoEditor.' + name; | 684 return 'PhotoEditor.' + name; |
685 }; | 685 }; |
686 | 686 |
687 /** | 687 /** |
688 * Used for metrics reporting, keep in sync with the histogram description. | 688 * Used for metrics reporting, keep in sync with the histogram description. |
689 */ | 689 */ |
690 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; | 690 ImageUtil.FILE_TYPES = ['jpg', 'png', 'gif', 'bmp', 'webp']; |
OLD | NEW |