| 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 * 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 * @param {string} name | 8 * @param {string} name |
| 9 * @param {string} title | 9 * @param {string} title |
| 10 * @constructor | 10 * @constructor |
| 11 * @struct | 11 * @struct |
| 12 * @extends {ImageEditor.Mode} | 12 * @extends {ImageEditorMode} |
| 13 */ | 13 */ |
| 14 ImageEditor.Mode.Adjust = function(name, title) { | 14 ImageEditorMode.Adjust = function(name, title) { |
| 15 ImageEditor.Mode.call(this, name, title); | 15 ImageEditorMode.call(this, name, title); |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * @type {boolean} | 18 * @type {boolean} |
| 19 * @const | 19 * @const |
| 20 */ | 20 */ |
| 21 this.implicitCommit = true; | 21 this.implicitCommit = true; |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * @type {?string} | 24 * @type {?string} |
| 25 * @private | 25 * @private |
| (...skipping 22 matching lines...) Expand all Loading... |
| 48 * @private {ImageData} | 48 * @private {ImageData} |
| 49 */ | 49 */ |
| 50 this.previewImageData_ = null; | 50 this.previewImageData_ = null; |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * @private {ImageData} | 53 * @private {ImageData} |
| 54 */ | 54 */ |
| 55 this.originalImageData_ = null; | 55 this.originalImageData_ = null; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 ImageEditor.Mode.Adjust.prototype = {__proto__: ImageEditor.Mode.prototype}; | 58 ImageEditorMode.Adjust.prototype = { |
| 59 __proto__: ImageEditorMode.prototype |
| 60 }; |
| 59 | 61 |
| 60 /** | 62 /** |
| 61 * Gets command to do filter. | 63 * Gets command to do filter. |
| 62 * | 64 * |
| 63 * @return {Command.Filter} Filter command. | 65 * @return {Command.Filter} Filter command. |
| 64 */ | 66 */ |
| 65 ImageEditor.Mode.Adjust.prototype.getCommand = function() { | 67 ImageEditorMode.Adjust.prototype.getCommand = function() { |
| 66 if (!this.filter_) return null; | 68 if (!this.filter_) |
| 69 return null; |
| 67 | 70 |
| 68 return new Command.Filter(this.name, this.filter_, this.doneMessage_); | 71 return new Command.Filter(this.name, this.filter_, this.doneMessage_); |
| 69 }; | 72 }; |
| 70 | 73 |
| 71 /** @override */ | 74 /** @override */ |
| 72 ImageEditor.Mode.Adjust.prototype.cleanUpUI = function() { | 75 ImageEditorMode.Adjust.prototype.cleanUpUI = function() { |
| 73 ImageEditor.Mode.prototype.cleanUpUI.apply(this, arguments); | 76 ImageEditorMode.prototype.cleanUpUI.apply(this, arguments); |
| 74 this.hidePreview(); | 77 this.hidePreview(); |
| 75 }; | 78 }; |
| 76 | 79 |
| 77 /** | 80 /** |
| 78 * Hides preview. | 81 * Hides preview. |
| 79 */ | 82 */ |
| 80 ImageEditor.Mode.Adjust.prototype.hidePreview = function() { | 83 ImageEditorMode.Adjust.prototype.hidePreview = function() { |
| 81 if (this.canvas_) { | 84 if (this.canvas_) { |
| 82 this.canvas_.parentNode.removeChild(this.canvas_); | 85 this.canvas_.parentNode.removeChild(this.canvas_); |
| 83 this.canvas_ = null; | 86 this.canvas_ = null; |
| 84 } | 87 } |
| 85 }; | 88 }; |
| 86 | 89 |
| 87 /** @override */ | 90 /** @override */ |
| 88 ImageEditor.Mode.Adjust.prototype.cleanUpCaches = function() { | 91 ImageEditorMode.Adjust.prototype.cleanUpCaches = function() { |
| 89 this.filter_ = null; | 92 this.filter_ = null; |
| 90 this.previewImageData_ = null; | 93 this.previewImageData_ = null; |
| 91 }; | 94 }; |
| 92 | 95 |
| 93 /** @override */ | 96 /** @override */ |
| 94 ImageEditor.Mode.Adjust.prototype.reset = function() { | 97 ImageEditorMode.Adjust.prototype.reset = function() { |
| 95 ImageEditor.Mode.prototype.reset.call(this); | 98 ImageEditorMode.prototype.reset.call(this); |
| 96 this.hidePreview(); | 99 this.hidePreview(); |
| 97 this.cleanUpCaches(); | 100 this.cleanUpCaches(); |
| 98 }; | 101 }; |
| 99 | 102 |
| 100 /** @override */ | 103 /** @override */ |
| 101 ImageEditor.Mode.Adjust.prototype.update = function(options) { | 104 ImageEditorMode.Adjust.prototype.update = function(options) { |
| 102 ImageEditor.Mode.prototype.update.apply(this, arguments); | 105 ImageEditorMode.prototype.update.apply(this, arguments); |
| 103 this.updatePreviewImage_(options); | 106 this.updatePreviewImage_(options); |
| 104 }; | 107 }; |
| 105 | 108 |
| 106 /** | 109 /** |
| 107 * Copy the source image data for the preview. | 110 * Copy the source image data for the preview. |
| 108 * Use the cached copy if the viewport has not changed. | 111 * Use the cached copy if the viewport has not changed. |
| 109 * @param {Object} options Options that describe the filter. It it is null, it | 112 * @param {Object} options Options that describe the filter. It it is null, it |
| 110 * does not update current filter. | 113 * does not update current filter. |
| 111 * @private | 114 * @private |
| 112 */ | 115 */ |
| 113 ImageEditor.Mode.Adjust.prototype.updatePreviewImage_ = function(options) { | 116 ImageEditorMode.Adjust.prototype.updatePreviewImage_ = function(options) { |
| 114 assert(this.getViewport()); | 117 assert(this.getViewport()); |
| 115 | 118 |
| 116 var isPreviewImageInvalidated = false; | 119 var isPreviewImageInvalidated = false; |
| 117 | 120 |
| 118 // Update filter. | 121 // Update filter. |
| 119 if (options) { | 122 if (options) { |
| 120 // We assume filter names are used in the UI directly. | 123 // We assume filter names are used in the UI directly. |
| 121 // This will have to change with i18n. | 124 // This will have to change with i18n. |
| 122 this.filter_ = this.createFilter(options); | 125 this.filter_ = this.createFilter(options); |
| 123 isPreviewImageInvalidated = true; | 126 isPreviewImageInvalidated = true; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 153 | 156 |
| 154 ImageUtil.trace.resetTimer('preview'); | 157 ImageUtil.trace.resetTimer('preview'); |
| 155 this.filter_(this.previewImageData_, this.originalImageData_, 0, 0); | 158 this.filter_(this.previewImageData_, this.originalImageData_, 0, 0); |
| 156 ImageUtil.trace.reportTimer('preview'); | 159 ImageUtil.trace.reportTimer('preview'); |
| 157 | 160 |
| 158 this.canvas_.getContext('2d').putImageData(this.previewImageData_, 0, 0); | 161 this.canvas_.getContext('2d').putImageData(this.previewImageData_, 0, 0); |
| 159 } | 162 } |
| 160 }; | 163 }; |
| 161 | 164 |
| 162 /** @override */ | 165 /** @override */ |
| 163 ImageEditor.Mode.Adjust.prototype.draw = function() { | 166 ImageEditorMode.Adjust.prototype.draw = function() { |
| 164 this.updatePreviewImage_(null); | 167 this.updatePreviewImage_(null); |
| 165 }; | 168 }; |
| 166 | 169 |
| 167 /* | 170 /* |
| 168 * Own methods | 171 * Own methods |
| 169 */ | 172 */ |
| 170 | 173 |
| 171 /** | 174 /** |
| 172 * Creates a filter. | 175 * Creates a filter. |
| 173 * @param {!Object} options A map of filter-specific options. | 176 * @param {!Object} options A map of filter-specific options. |
| 174 * @return {function(!ImageData,!ImageData,number,number)} Created function. | 177 * @return {function(!ImageData,!ImageData,number,number)} Created function. |
| 175 */ | 178 */ |
| 176 ImageEditor.Mode.Adjust.prototype.createFilter = function(options) { | 179 ImageEditorMode.Adjust.prototype.createFilter = function(options) { |
| 177 return filter.create(this.name, options); | 180 return filter.create(this.name, options); |
| 178 }; | 181 }; |
| 179 | 182 |
| 180 /** | 183 /** |
| 181 * A base class for color filters that are scale independent. | 184 * A base class for color filters that are scale independent. |
| 182 * @constructor | 185 * @constructor |
| 183 * @param {string} name The mode name. | 186 * @param {string} name The mode name. |
| 184 * @param {string} title The mode title. | 187 * @param {string} title The mode title. |
| 185 * @extends {ImageEditor.Mode.Adjust} | 188 * @extends {ImageEditorMode.Adjust} |
| 186 * @struct | 189 * @struct |
| 187 */ | 190 */ |
| 188 ImageEditor.Mode.ColorFilter = function(name, title) { | 191 ImageEditorMode.ColorFilter = function(name, title) { |
| 189 ImageEditor.Mode.Adjust.call(this, name, title); | 192 ImageEditorMode.Adjust.call(this, name, title); |
| 190 }; | 193 }; |
| 191 | 194 |
| 192 ImageEditor.Mode.ColorFilter.prototype = | 195 ImageEditorMode.ColorFilter.prototype = { |
| 193 {__proto__: ImageEditor.Mode.Adjust.prototype}; | 196 __proto__: ImageEditorMode.Adjust.prototype |
| 197 }; |
| 194 | 198 |
| 195 /** | 199 /** |
| 196 * Gets a histogram from a thumbnail. | 200 * Gets a histogram from a thumbnail. |
| 197 * @return {{r: !Array<number>, g: !Array<number>, b: !Array<number>}} | 201 * @return {{r: !Array<number>, g: !Array<number>, b: !Array<number>}} |
| 198 * histogram. | 202 * histogram. |
| 199 */ | 203 */ |
| 200 ImageEditor.Mode.ColorFilter.prototype.getHistogram = function() { | 204 ImageEditorMode.ColorFilter.prototype.getHistogram = function() { |
| 201 return filter.getHistogram(this.getImageView().getThumbnail()); | 205 return filter.getHistogram(this.getImageView().getThumbnail()); |
| 202 }; | 206 }; |
| 203 | 207 |
| 204 /** | 208 /** |
| 205 * Exposure/contrast filter. | 209 * Exposure/contrast filter. |
| 206 * @constructor | 210 * @constructor |
| 207 * @extends {ImageEditor.Mode.ColorFilter} | 211 * @extends {ImageEditorMode.ColorFilter} |
| 208 * @struct | 212 * @struct |
| 209 */ | 213 */ |
| 210 ImageEditor.Mode.Exposure = function() { | 214 ImageEditorMode.Exposure = function() { |
| 211 ImageEditor.Mode.ColorFilter.call(this, 'exposure', 'GALLERY_EXPOSURE'); | 215 ImageEditorMode.ColorFilter.call(this, 'exposure', 'GALLERY_EXPOSURE'); |
| 212 }; | 216 }; |
| 213 | 217 |
| 214 ImageEditor.Mode.Exposure.prototype = | 218 ImageEditorMode.Exposure.prototype = { |
| 215 {__proto__: ImageEditor.Mode.ColorFilter.prototype}; | 219 __proto__: ImageEditorMode.ColorFilter.prototype |
| 220 }; |
| 216 | 221 |
| 217 /** @override */ | 222 /** @override */ |
| 218 ImageEditor.Mode.Exposure.prototype.createTools = function(toolbar) { | 223 ImageEditorMode.Exposure.prototype.createTools = function(toolbar) { |
| 219 toolbar.addRange('brightness', 'GALLERY_BRIGHTNESS', -1, 0, 1, 100); | 224 toolbar.addRange('brightness', 'GALLERY_BRIGHTNESS', -1, 0, 1, 100); |
| 220 toolbar.addRange('contrast', 'GALLERY_CONTRAST', -1, 0, 1, 100); | 225 toolbar.addRange('contrast', 'GALLERY_CONTRAST', -1, 0, 1, 100); |
| 221 }; | 226 }; |
| 222 | 227 |
| 223 /** | 228 /** |
| 224 * Autofix. | 229 * Autofix. |
| 225 * @constructor | 230 * @constructor |
| 226 * @struct | 231 * @struct |
| 227 * @extends {ImageEditor.Mode.ColorFilter} | 232 * @extends {ImageEditorMode.ColorFilter} |
| 228 */ | 233 */ |
| 229 ImageEditor.Mode.Autofix = function() { | 234 ImageEditorMode.Autofix = function() { |
| 230 ImageEditor.Mode.ColorFilter.call(this, 'autofix', 'GALLERY_AUTOFIX'); | 235 ImageEditorMode.ColorFilter.call(this, 'autofix', 'GALLERY_AUTOFIX'); |
| 231 this.doneMessage_ = 'GALLERY_FIXED'; | 236 this.doneMessage_ = 'GALLERY_FIXED'; |
| 232 }; | 237 }; |
| 233 | 238 |
| 234 ImageEditor.Mode.Autofix.prototype = | 239 ImageEditorMode.Autofix.prototype = { |
| 235 {__proto__: ImageEditor.Mode.ColorFilter.prototype}; | 240 __proto__: ImageEditorMode.ColorFilter.prototype |
| 241 }; |
| 236 | 242 |
| 237 /** @override */ | 243 /** @override */ |
| 238 ImageEditor.Mode.Autofix.prototype.isApplicable = function() { | 244 ImageEditorMode.Autofix.prototype.isApplicable = function() { |
| 239 return this.getImageView().hasValidImage() && | 245 return this.getImageView().hasValidImage() && |
| 240 filter.autofix.isApplicable(this.getHistogram()); | 246 filter.autofix.isApplicable(this.getHistogram()); |
| 241 }; | 247 }; |
| 242 | 248 |
| 243 /** | 249 /** |
| 244 * Applies autofix. | 250 * Applies autofix. |
| 245 */ | 251 */ |
| 246 ImageEditor.Mode.Autofix.prototype.apply = function() { | 252 ImageEditorMode.Autofix.prototype.apply = function() { |
| 247 this.update({histogram: this.getHistogram()}); | 253 this.update({histogram: this.getHistogram()}); |
| 248 }; | 254 }; |
| 249 | 255 |
| 250 /** | 256 /** |
| 251 * Instant Autofix. | 257 * Instant Autofix. |
| 252 * @constructor | 258 * @constructor |
| 253 * @extends {ImageEditor.Mode.Autofix} | 259 * @extends {ImageEditorMode.Autofix} |
| 254 * @struct | 260 * @struct |
| 255 */ | 261 */ |
| 256 ImageEditor.Mode.InstantAutofix = function() { | 262 ImageEditorMode.InstantAutofix = function() { |
| 257 ImageEditor.Mode.Autofix.call(this); | 263 ImageEditorMode.Autofix.call(this); |
| 258 this.instant = true; | 264 this.instant = true; |
| 259 }; | 265 }; |
| 260 | 266 |
| 261 ImageEditor.Mode.InstantAutofix.prototype = | 267 ImageEditorMode.InstantAutofix.prototype = { |
| 262 {__proto__: ImageEditor.Mode.Autofix.prototype}; | 268 __proto__: ImageEditorMode.Autofix.prototype |
| 269 }; |
| 263 | 270 |
| 264 /** @override */ | 271 /** @override */ |
| 265 ImageEditor.Mode.InstantAutofix.prototype.setUp = function() { | 272 ImageEditorMode.InstantAutofix.prototype.setUp = function() { |
| 266 ImageEditor.Mode.Autofix.prototype.setUp.apply(this, arguments); | 273 ImageEditorMode.Autofix.prototype.setUp.apply(this, arguments); |
| 267 this.apply(); | 274 this.apply(); |
| 268 }; | 275 }; |
| OLD | NEW |