| 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 * The base class for simple filters that only modify the image content | 6 * The base class for simple filters that only modify the image content |
| 7 * but do not modify the image dimensions. | 7 * but do not modify the image dimensions. |
| 8 * @constructor | 8 * @constructor |
| 9 * @extends ImageEditor.Mode | 9 * @extends ImageEditor.Mode |
| 10 */ | 10 */ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 return new Command.Filter(this.name, this.filter_, this.doneMessage_); | 24 return new Command.Filter(this.name, this.filter_, this.doneMessage_); |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 /** @override */ | 27 /** @override */ |
| 28 ImageEditor.Mode.Adjust.prototype.cleanUpUI = function() { | 28 ImageEditor.Mode.Adjust.prototype.cleanUpUI = function() { |
| 29 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); | 29 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); |
| 30 this.hidePreview(); | 30 this.hidePreview(); |
| 31 }; | 31 }; |
| 32 | 32 |
| 33 //TODO(JSDOC) | 33 /** |
| 34 * TODO(JSDOC) |
| 35 */ |
| 34 ImageEditor.Mode.Adjust.prototype.hidePreview = function() { | 36 ImageEditor.Mode.Adjust.prototype.hidePreview = function() { |
| 35 if (this.canvas_) { | 37 if (this.canvas_) { |
| 36 this.canvas_.parentNode.removeChild(this.canvas_); | 38 this.canvas_.parentNode.removeChild(this.canvas_); |
| 37 this.canvas_ = null; | 39 this.canvas_ = null; |
| 38 } | 40 } |
| 39 }; | 41 }; |
| 40 | 42 |
| 41 //TODO(JSDOC) | 43 /** |
| 44 * TODO(JSDOC) |
| 45 */ |
| 42 ImageEditor.Mode.Adjust.prototype.cleanUpCaches = function() { | 46 ImageEditor.Mode.Adjust.prototype.cleanUpCaches = function() { |
| 43 this.filter_ = null; | 47 this.filter_ = null; |
| 44 this.previewImageData_ = null; | 48 this.previewImageData_ = null; |
| 45 }; | 49 }; |
| 46 | 50 |
| 47 //TODO(JSDOC) | 51 /** |
| 52 * TODO(JSDOC) |
| 53 */ |
| 48 ImageEditor.Mode.Adjust.prototype.reset = function() { | 54 ImageEditor.Mode.Adjust.prototype.reset = function() { |
| 49 ImageEditor.Mode.prototype.reset.call(this); | 55 ImageEditor.Mode.prototype.reset.call(this); |
| 50 this.hidePreview(); | 56 this.hidePreview(); |
| 51 this.cleanUpCaches(); | 57 this.cleanUpCaches(); |
| 52 }; | 58 }; |
| 53 | 59 |
| 54 //TODO(JSDOC) | 60 /** |
| 61 * TODO(JSDOC) |
| 62 * @param {Object} options //TODO(JSDOC). |
| 63 */ |
| 55 ImageEditor.Mode.Adjust.prototype.update = function(options) { | 64 ImageEditor.Mode.Adjust.prototype.update = function(options) { |
| 56 ImageEditor.Mode.prototype.update.apply(this, arguments); | 65 ImageEditor.Mode.prototype.update.apply(this, arguments); |
| 57 | 66 |
| 58 // We assume filter names are used in the UI directly. | 67 // We assume filter names are used in the UI directly. |
| 59 // This will have to change with i18n. | 68 // This will have to change with i18n. |
| 60 this.filter_ = this.createFilter(options); | 69 this.filter_ = this.createFilter(options); |
| 61 this.updatePreviewImage(); | 70 this.updatePreviewImage(); |
| 62 ImageUtil.trace.resetTimer('preview'); | 71 ImageUtil.trace.resetTimer('preview'); |
| 63 this.filter_(this.previewImageData_, this.originalImageData, 0, 0); | 72 this.filter_(this.previewImageData_, this.originalImageData, 0, 0); |
| 64 ImageUtil.trace.reportTimer('preview'); | 73 ImageUtil.trace.reportTimer('preview'); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 83 | 92 |
| 84 this.originalImageData = this.getImageView().copyScreenImageData(); | 93 this.originalImageData = this.getImageView().copyScreenImageData(); |
| 85 this.previewImageData_ = this.getImageView().copyScreenImageData(); | 94 this.previewImageData_ = this.getImageView().copyScreenImageData(); |
| 86 } | 95 } |
| 87 }; | 96 }; |
| 88 | 97 |
| 89 /* | 98 /* |
| 90 * Own methods | 99 * Own methods |
| 91 */ | 100 */ |
| 92 | 101 |
| 93 //TODO(JSDOC) | 102 /** |
| 103 * TODO(JSDOC) |
| 104 * @param {Object} options //TODO(JSDOC). |
| 105 * @return {function(ImageData,ImageData,number,number)} Created function. |
| 106 */ |
| 94 ImageEditor.Mode.Adjust.prototype.createFilter = function(options) { | 107 ImageEditor.Mode.Adjust.prototype.createFilter = function(options) { |
| 95 return filter.create(this.name, options); | 108 return filter.create(this.name, options); |
| 96 }; | 109 }; |
| 97 | 110 |
| 98 /** | 111 /** |
| 99 * A base class for color filters that are scale independent. | 112 * A base class for color filters that are scale independent. |
| 100 * @constructor | 113 * @constructor |
| 101 */ | 114 */ |
| 102 ImageEditor.Mode.ColorFilter = function() { | 115 ImageEditor.Mode.ColorFilter = function() { |
| 103 ImageEditor.Mode.Adjust.apply(this, arguments); | 116 ImageEditor.Mode.Adjust.apply(this, arguments); |
| 104 }; | 117 }; |
| 105 | 118 |
| 106 ImageEditor.Mode.ColorFilter.prototype = | 119 ImageEditor.Mode.ColorFilter.prototype = |
| 107 {__proto__: ImageEditor.Mode.Adjust.prototype}; | 120 {__proto__: ImageEditor.Mode.Adjust.prototype}; |
| 108 | 121 |
| 122 /** |
| 123 * TODO(JSDOC) |
| 124 * @return {{r: Array.<number>, g: Array.<number>, b: Array.<number>}} |
| 125 * histogram. |
| 126 */ |
| 109 ImageEditor.Mode.ColorFilter.prototype.getHistogram = function() { | 127 ImageEditor.Mode.ColorFilter.prototype.getHistogram = function() { |
| 110 return filter.getHistogram(this.getImageView().getThumbnail()); | 128 return filter.getHistogram(this.getImageView().getThumbnail()); |
| 111 }; | 129 }; |
| 112 | 130 |
| 113 /** | 131 /** |
| 114 * Exposure/contrast filter. | 132 * Exposure/contrast filter. |
| 115 * @constructor | 133 * @constructor |
| 116 */ | 134 */ |
| 117 ImageEditor.Mode.Exposure = function() { | 135 ImageEditor.Mode.Exposure = function() { |
| 118 ImageEditor.Mode.ColorFilter.call(this, 'exposure'); | 136 ImageEditor.Mode.ColorFilter.call(this, 'exposure'); |
| 119 }; | 137 }; |
| 120 | 138 |
| 121 ImageEditor.Mode.Exposure.prototype = | 139 ImageEditor.Mode.Exposure.prototype = |
| 122 {__proto__: ImageEditor.Mode.ColorFilter.prototype}; | 140 {__proto__: ImageEditor.Mode.ColorFilter.prototype}; |
| 123 | 141 |
| 142 /** |
| 143 * TODO(JSDOC) |
| 144 * @param {ImageEditor.Toolbar} toolbar The toolbar to populate. |
| 145 */ |
| 124 ImageEditor.Mode.Exposure.prototype.createTools = function(toolbar) { | 146 ImageEditor.Mode.Exposure.prototype.createTools = function(toolbar) { |
| 125 toolbar.addRange('brightness', -1, 0, 1, 100); | 147 toolbar.addRange('brightness', -1, 0, 1, 100); |
| 126 toolbar.addRange('contrast', -1, 0, 1, 100); | 148 toolbar.addRange('contrast', -1, 0, 1, 100); |
| 127 }; | 149 }; |
| 128 | 150 |
| 129 /** | 151 /** |
| 130 * Autofix. | 152 * Autofix. |
| 131 * @constructor | 153 * @constructor |
| 132 */ | 154 */ |
| 133 ImageEditor.Mode.Autofix = function() { | 155 ImageEditor.Mode.Autofix = function() { |
| 134 ImageEditor.Mode.ColorFilter.call(this, 'autofix'); | 156 ImageEditor.Mode.ColorFilter.call(this, 'autofix'); |
| 135 this.doneMessage_ = 'fixed'; | 157 this.doneMessage_ = 'fixed'; |
| 136 }; | 158 }; |
| 137 | 159 |
| 138 ImageEditor.Mode.Autofix.prototype = | 160 ImageEditor.Mode.Autofix.prototype = |
| 139 {__proto__: ImageEditor.Mode.ColorFilter.prototype}; | 161 {__proto__: ImageEditor.Mode.ColorFilter.prototype}; |
| 140 | 162 |
| 163 /** |
| 164 * TODO(JSDOC) |
| 165 * @param {ImageEditor.Toolbar} toolbar The toolbar to populate. |
| 166 */ |
| 141 ImageEditor.Mode.Autofix.prototype.createTools = function(toolbar) { | 167 ImageEditor.Mode.Autofix.prototype.createTools = function(toolbar) { |
| 142 var self = this; | 168 var self = this; |
| 143 toolbar.addButton('Apply', this.apply.bind(this)); | 169 toolbar.addButton('Apply', this.apply.bind(this)); |
| 144 }; | 170 }; |
| 145 | 171 |
| 172 /** |
| 173 * TODO(JSDOC) |
| 174 * @return {boolean} //TODO(JSDOC) |
| 175 */ |
| 146 ImageEditor.Mode.Autofix.prototype.isApplicable = function() { | 176 ImageEditor.Mode.Autofix.prototype.isApplicable = function() { |
| 147 return this.getImageView().hasValidImage() && | 177 return this.getImageView().hasValidImage() && |
| 148 filter.autofix.isApplicable(this.getHistogram()); | 178 filter.autofix.isApplicable(this.getHistogram()); |
| 149 }; | 179 }; |
| 150 | 180 |
| 181 /** |
| 182 * TODO(JSDOC) |
| 183 */ |
| 151 ImageEditor.Mode.Autofix.prototype.apply = function() { | 184 ImageEditor.Mode.Autofix.prototype.apply = function() { |
| 152 this.update({histogram: this.getHistogram()}); | 185 this.update({histogram: this.getHistogram()}); |
| 153 }; | 186 }; |
| 154 | 187 |
| 155 /** | 188 /** |
| 156 * Instant Autofix. | 189 * Instant Autofix. |
| 157 * @constructor | 190 * @constructor |
| 158 */ | 191 */ |
| 159 ImageEditor.Mode.InstantAutofix = function() { | 192 ImageEditor.Mode.InstantAutofix = function() { |
| 160 ImageEditor.Mode.Autofix.apply(this, arguments); | 193 ImageEditor.Mode.Autofix.apply(this, arguments); |
| 161 this.instant = true; | 194 this.instant = true; |
| 162 }; | 195 }; |
| 163 | 196 |
| 164 ImageEditor.Mode.InstantAutofix.prototype = | 197 ImageEditor.Mode.InstantAutofix.prototype = |
| 165 {__proto__: ImageEditor.Mode.Autofix.prototype}; | 198 {__proto__: ImageEditor.Mode.Autofix.prototype}; |
| 166 | 199 |
| 200 /** |
| 201 * TODO(JSDOC) |
| 202 */ |
| 167 ImageEditor.Mode.InstantAutofix.prototype.setUp = function() { | 203 ImageEditor.Mode.InstantAutofix.prototype.setUp = function() { |
| 168 ImageEditor.Mode.Autofix.prototype.setUp.apply(this, arguments); | 204 ImageEditor.Mode.Autofix.prototype.setUp.apply(this, arguments); |
| 169 this.apply(); | 205 this.apply(); |
| 170 }; | 206 }; |
| 171 | 207 |
| 172 /** | 208 /** |
| 173 * Blur filter. | 209 * Blur filter. |
| 174 * @constructor | 210 * @constructor |
| 175 */ | 211 */ |
| 176 ImageEditor.Mode.Blur = function() { | 212 ImageEditor.Mode.Blur = function() { |
| 177 ImageEditor.Mode.Adjust.call(this, 'blur'); | 213 ImageEditor.Mode.Adjust.call(this, 'blur'); |
| 178 }; | 214 }; |
| 179 | 215 |
| 180 ImageEditor.Mode.Blur.prototype = | 216 ImageEditor.Mode.Blur.prototype = |
| 181 {__proto__: ImageEditor.Mode.Adjust.prototype}; | 217 {__proto__: ImageEditor.Mode.Adjust.prototype}; |
| 182 | 218 |
| 219 /** |
| 220 * TODO(JSDOC) |
| 221 * @param {ImageEditor.Toolbar} toolbar The toolbar to populate. |
| 222 */ |
| 183 ImageEditor.Mode.Blur.prototype.createTools = function(toolbar) { | 223 ImageEditor.Mode.Blur.prototype.createTools = function(toolbar) { |
| 184 toolbar.addRange('strength', 0, 0, 1, 100); | 224 toolbar.addRange('strength', 0, 0, 1, 100); |
| 185 toolbar.addRange('radius', 1, 1, 3); | 225 toolbar.addRange('radius', 1, 1, 3); |
| 186 }; | 226 }; |
| 187 | 227 |
| 188 /** | 228 /** |
| 189 * Sharpen filter. | 229 * Sharpen filter. |
| 190 * @constructor | 230 * @constructor |
| 191 */ | 231 */ |
| 192 ImageEditor.Mode.Sharpen = function() { | 232 ImageEditor.Mode.Sharpen = function() { |
| 193 ImageEditor.Mode.Adjust.call(this, 'sharpen'); | 233 ImageEditor.Mode.Adjust.call(this, 'sharpen'); |
| 194 }; | 234 }; |
| 195 | 235 |
| 196 ImageEditor.Mode.Sharpen.prototype = | 236 ImageEditor.Mode.Sharpen.prototype = |
| 197 {__proto__: ImageEditor.Mode.Adjust.prototype}; | 237 {__proto__: ImageEditor.Mode.Adjust.prototype}; |
| 198 | 238 |
| 239 /** |
| 240 * TODO(JSDOC) |
| 241 * @param {ImageEditor.Toolbar} toolbar The toolbar to populate. |
| 242 */ |
| 199 ImageEditor.Mode.Sharpen.prototype.createTools = function(toolbar) { | 243 ImageEditor.Mode.Sharpen.prototype.createTools = function(toolbar) { |
| 200 toolbar.addRange('strength', 0, 0, 1, 100); | 244 toolbar.addRange('strength', 0, 0, 1, 100); |
| 201 toolbar.addRange('radius', 1, 1, 3); | 245 toolbar.addRange('radius', 1, 1, 3); |
| 202 }; | 246 }; |
| OLD | NEW |