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