fabric-rails 1.0.12.1 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/CHANGELOG.md +4 -0
  2. data/README.md +1 -1
  3. data/lib/fabric/rails/version.rb +2 -2
  4. data/vendor/assets/javascripts/cufon.js +1226 -0
  5. data/vendor/assets/javascripts/event.js +20 -20
  6. data/vendor/assets/javascripts/excanvas.js +1464 -0
  7. data/vendor/assets/javascripts/fabric.js +56 -33
  8. data/vendor/assets/javascripts/fabric/HEADER.js +2 -4
  9. data/vendor/assets/javascripts/fabric/brushes/base_brush.class.js +96 -0
  10. data/vendor/assets/javascripts/fabric/brushes/circle_brush.class.js +99 -0
  11. data/vendor/assets/javascripts/fabric/brushes/pattern_brush.class.js +55 -0
  12. data/vendor/assets/javascripts/fabric/{freedrawing.class.js → brushes/pencil_brush.class.js} +73 -65
  13. data/vendor/assets/javascripts/fabric/brushes/spray_brush.class.js +157 -0
  14. data/vendor/assets/javascripts/fabric/canvas.class.js +154 -135
  15. data/vendor/assets/javascripts/fabric/color.class.js +195 -29
  16. data/vendor/assets/javascripts/fabric/filters/brightness_filter.class.js +70 -0
  17. data/vendor/assets/javascripts/fabric/filters/convolute_filter.class.js +122 -0
  18. data/vendor/assets/javascripts/fabric/filters/gradienttransparency_filter.class.js +69 -0
  19. data/vendor/assets/javascripts/fabric/filters/grayscale_filter.class.js +61 -0
  20. data/vendor/assets/javascripts/fabric/filters/invert_filter.class.js +57 -0
  21. data/vendor/assets/javascripts/fabric/filters/noise_filter.class.js +73 -0
  22. data/vendor/assets/javascripts/fabric/filters/pixelate_filter.class.js +98 -0
  23. data/vendor/assets/javascripts/fabric/filters/removewhite_filter.class.js +86 -0
  24. data/vendor/assets/javascripts/fabric/filters/sepia2_filter.class.js +61 -0
  25. data/vendor/assets/javascripts/fabric/filters/sepia_filter.class.js +58 -0
  26. data/vendor/assets/javascripts/fabric/filters/tint_filter.class.js +80 -0
  27. data/vendor/assets/javascripts/fabric/gradient.class.js +232 -80
  28. data/vendor/assets/javascripts/fabric/intersection.class.js +10 -28
  29. data/vendor/assets/javascripts/fabric/log.js +0 -2
  30. data/vendor/assets/javascripts/fabric/{canvas_animation.mixin.js → mixins/canvas_animation.mixin.js} +3 -6
  31. data/vendor/assets/javascripts/fabric/mixins/canvas_dataurl_exporter.mixin.js +137 -0
  32. data/vendor/assets/javascripts/fabric/{canvas_events.mixin.js → mixins/canvas_events.mixin.js} +97 -144
  33. data/vendor/assets/javascripts/fabric/{canvas_gestures.mixin.js → mixins/canvas_gestures.mixin.js} +4 -8
  34. data/vendor/assets/javascripts/fabric/{canvas_serialization.mixin.js → mixins/canvas_serialization.mixin.js} +19 -14
  35. data/vendor/assets/javascripts/fabric/mixins/collection.mixin.js +137 -0
  36. data/vendor/assets/javascripts/fabric/{object_geometry.mixin.js → mixins/object_geometry.mixin.js} +130 -47
  37. data/vendor/assets/javascripts/fabric/{object_interactivity.mixin.js → mixins/object_interactivity.mixin.js} +21 -102
  38. data/vendor/assets/javascripts/fabric/{object_origin.mixin.js → mixins/object_origin.mixin.js} +36 -26
  39. data/vendor/assets/javascripts/fabric/{object_straightening.mixin.js → mixins/object_straightening.mixin.js} +4 -9
  40. data/vendor/assets/javascripts/fabric/{observable.mixin.js → mixins/observable.mixin.js} +27 -35
  41. data/vendor/assets/javascripts/fabric/mixins/stateful.mixin.js +45 -0
  42. data/vendor/assets/javascripts/fabric/node.js +62 -26
  43. data/vendor/assets/javascripts/fabric/parser.js +181 -58
  44. data/vendor/assets/javascripts/fabric/pattern.class.js +43 -14
  45. data/vendor/assets/javascripts/fabric/point.class.js +4 -43
  46. data/vendor/assets/javascripts/fabric/shadow.class.js +19 -19
  47. data/vendor/assets/javascripts/fabric/{circle.class.js → shapes/circle.class.js} +32 -29
  48. data/vendor/assets/javascripts/fabric/{ellipse.class.js → shapes/ellipse.class.js} +45 -27
  49. data/vendor/assets/javascripts/fabric/{group.class.js → shapes/group.class.js} +67 -169
  50. data/vendor/assets/javascripts/fabric/{image.class.js → shapes/image.class.js} +134 -72
  51. data/vendor/assets/javascripts/fabric/{line.class.js → shapes/line.class.js} +67 -36
  52. data/vendor/assets/javascripts/fabric/{object.class.js → shapes/object.class.js} +394 -252
  53. data/vendor/assets/javascripts/fabric/{path.class.js → shapes/path.class.js} +89 -174
  54. data/vendor/assets/javascripts/fabric/{path_group.class.js → shapes/path_group.class.js} +12 -18
  55. data/vendor/assets/javascripts/fabric/{polygon.class.js → shapes/polygon.class.js} +64 -38
  56. data/vendor/assets/javascripts/fabric/{polyline.class.js → shapes/polyline.class.js} +64 -39
  57. data/vendor/assets/javascripts/fabric/{rect.class.js → shapes/rect.class.js} +78 -112
  58. data/vendor/assets/javascripts/fabric/{text.class.js → shapes/text.class.js} +264 -270
  59. data/vendor/assets/javascripts/fabric/shapes/text.cufon.js +79 -0
  60. data/vendor/assets/javascripts/fabric/{triangle.class.js → shapes/triangle.class.js} +46 -26
  61. data/vendor/assets/javascripts/fabric/static_canvas.class.js +134 -358
  62. data/vendor/assets/javascripts/fabric/util/anim_ease.js +2 -31
  63. data/vendor/assets/javascripts/fabric/util/dom_event.js +21 -7
  64. data/vendor/assets/javascripts/fabric/util/dom_misc.js +49 -39
  65. data/vendor/assets/javascripts/fabric/util/dom_request.js +1 -2
  66. data/vendor/assets/javascripts/fabric/util/dom_style.js +1 -2
  67. data/vendor/assets/javascripts/fabric/util/lang_array.js +19 -13
  68. data/vendor/assets/javascripts/fabric/util/lang_class.js +1 -2
  69. data/vendor/assets/javascripts/fabric/util/lang_function.js +3 -1
  70. data/vendor/assets/javascripts/fabric/util/lang_object.js +5 -5
  71. data/vendor/assets/javascripts/fabric/util/lang_string.js +7 -5
  72. data/vendor/assets/javascripts/fabric/util/misc.js +207 -42
  73. metadata +47 -29
  74. data/vendor/assets/javascripts/fabric/image_filters.js +0 -809
  75. data/vendor/assets/javascripts/fabric/scout.js +0 -45
  76. data/vendor/assets/javascripts/fabric/stateful.js +0 -88
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fabric-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.12.1
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-01 00:00:00.000000000 Z
12
+ date: 2013-07-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: This gem provides fabric.js for your Rails 3 application via the asset
15
15
  pipeline.
@@ -31,46 +31,64 @@ files:
31
31
  - lib/fabric/rails.rb
32
32
  - lib/fabric/rails/engine.rb
33
33
  - lib/fabric/rails/version.rb
34
+ - vendor/assets/javascripts/cufon.js
34
35
  - vendor/assets/javascripts/event.js
36
+ - vendor/assets/javascripts/excanvas.js
35
37
  - vendor/assets/javascripts/fabric.js
36
38
  - vendor/assets/javascripts/fabric/HEADER.js
39
+ - vendor/assets/javascripts/fabric/brushes/base_brush.class.js
40
+ - vendor/assets/javascripts/fabric/brushes/circle_brush.class.js
41
+ - vendor/assets/javascripts/fabric/brushes/pattern_brush.class.js
42
+ - vendor/assets/javascripts/fabric/brushes/pencil_brush.class.js
43
+ - vendor/assets/javascripts/fabric/brushes/spray_brush.class.js
37
44
  - vendor/assets/javascripts/fabric/canvas.class.js
38
- - vendor/assets/javascripts/fabric/canvas_animation.mixin.js
39
- - vendor/assets/javascripts/fabric/canvas_events.mixin.js
40
- - vendor/assets/javascripts/fabric/canvas_gestures.mixin.js
41
- - vendor/assets/javascripts/fabric/canvas_serialization.mixin.js
42
- - vendor/assets/javascripts/fabric/circle.class.js
43
45
  - vendor/assets/javascripts/fabric/color.class.js
44
- - vendor/assets/javascripts/fabric/ellipse.class.js
45
- - vendor/assets/javascripts/fabric/freedrawing.class.js
46
+ - vendor/assets/javascripts/fabric/filters/brightness_filter.class.js
47
+ - vendor/assets/javascripts/fabric/filters/convolute_filter.class.js
48
+ - vendor/assets/javascripts/fabric/filters/gradienttransparency_filter.class.js
49
+ - vendor/assets/javascripts/fabric/filters/grayscale_filter.class.js
50
+ - vendor/assets/javascripts/fabric/filters/invert_filter.class.js
51
+ - vendor/assets/javascripts/fabric/filters/noise_filter.class.js
52
+ - vendor/assets/javascripts/fabric/filters/pixelate_filter.class.js
53
+ - vendor/assets/javascripts/fabric/filters/removewhite_filter.class.js
54
+ - vendor/assets/javascripts/fabric/filters/sepia2_filter.class.js
55
+ - vendor/assets/javascripts/fabric/filters/sepia_filter.class.js
56
+ - vendor/assets/javascripts/fabric/filters/tint_filter.class.js
46
57
  - vendor/assets/javascripts/fabric/gradient.class.js
47
- - vendor/assets/javascripts/fabric/group.class.js
48
- - vendor/assets/javascripts/fabric/image.class.js
49
- - vendor/assets/javascripts/fabric/image_filters.js
50
58
  - vendor/assets/javascripts/fabric/intersection.class.js
51
- - vendor/assets/javascripts/fabric/line.class.js
52
59
  - vendor/assets/javascripts/fabric/log.js
60
+ - vendor/assets/javascripts/fabric/mixins/canvas_animation.mixin.js
61
+ - vendor/assets/javascripts/fabric/mixins/canvas_dataurl_exporter.mixin.js
62
+ - vendor/assets/javascripts/fabric/mixins/canvas_events.mixin.js
63
+ - vendor/assets/javascripts/fabric/mixins/canvas_gestures.mixin.js
64
+ - vendor/assets/javascripts/fabric/mixins/canvas_serialization.mixin.js
65
+ - vendor/assets/javascripts/fabric/mixins/collection.mixin.js
66
+ - vendor/assets/javascripts/fabric/mixins/object_geometry.mixin.js
67
+ - vendor/assets/javascripts/fabric/mixins/object_interactivity.mixin.js
68
+ - vendor/assets/javascripts/fabric/mixins/object_origin.mixin.js
69
+ - vendor/assets/javascripts/fabric/mixins/object_straightening.mixin.js
70
+ - vendor/assets/javascripts/fabric/mixins/observable.mixin.js
71
+ - vendor/assets/javascripts/fabric/mixins/stateful.mixin.js
53
72
  - vendor/assets/javascripts/fabric/node.js
54
- - vendor/assets/javascripts/fabric/object.class.js
55
- - vendor/assets/javascripts/fabric/object_geometry.mixin.js
56
- - vendor/assets/javascripts/fabric/object_interactivity.mixin.js
57
- - vendor/assets/javascripts/fabric/object_origin.mixin.js
58
- - vendor/assets/javascripts/fabric/object_straightening.mixin.js
59
- - vendor/assets/javascripts/fabric/observable.mixin.js
60
73
  - vendor/assets/javascripts/fabric/parser.js
61
- - vendor/assets/javascripts/fabric/path.class.js
62
- - vendor/assets/javascripts/fabric/path_group.class.js
63
74
  - vendor/assets/javascripts/fabric/pattern.class.js
64
75
  - vendor/assets/javascripts/fabric/point.class.js
65
- - vendor/assets/javascripts/fabric/polygon.class.js
66
- - vendor/assets/javascripts/fabric/polyline.class.js
67
- - vendor/assets/javascripts/fabric/rect.class.js
68
- - vendor/assets/javascripts/fabric/scout.js
69
76
  - vendor/assets/javascripts/fabric/shadow.class.js
70
- - vendor/assets/javascripts/fabric/stateful.js
77
+ - vendor/assets/javascripts/fabric/shapes/circle.class.js
78
+ - vendor/assets/javascripts/fabric/shapes/ellipse.class.js
79
+ - vendor/assets/javascripts/fabric/shapes/group.class.js
80
+ - vendor/assets/javascripts/fabric/shapes/image.class.js
81
+ - vendor/assets/javascripts/fabric/shapes/line.class.js
82
+ - vendor/assets/javascripts/fabric/shapes/object.class.js
83
+ - vendor/assets/javascripts/fabric/shapes/path.class.js
84
+ - vendor/assets/javascripts/fabric/shapes/path_group.class.js
85
+ - vendor/assets/javascripts/fabric/shapes/polygon.class.js
86
+ - vendor/assets/javascripts/fabric/shapes/polyline.class.js
87
+ - vendor/assets/javascripts/fabric/shapes/rect.class.js
88
+ - vendor/assets/javascripts/fabric/shapes/text.class.js
89
+ - vendor/assets/javascripts/fabric/shapes/text.cufon.js
90
+ - vendor/assets/javascripts/fabric/shapes/triangle.class.js
71
91
  - vendor/assets/javascripts/fabric/static_canvas.class.js
72
- - vendor/assets/javascripts/fabric/text.class.js
73
- - vendor/assets/javascripts/fabric/triangle.class.js
74
92
  - vendor/assets/javascripts/fabric/util/anim_ease.js
75
93
  - vendor/assets/javascripts/fabric/util/dom_event.js
76
94
  - vendor/assets/javascripts/fabric/util/dom_misc.js
@@ -103,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
121
  version: 1.3.6
104
122
  requirements: []
105
123
  rubyforge_project: fabric-rails
106
- rubygems_version: 1.8.24
124
+ rubygems_version: 1.8.25
107
125
  signing_key:
108
126
  specification_version: 3
109
127
  summary: Easily use fabric.js with Rails 3
@@ -1,809 +0,0 @@
1
- /**
2
- * @namespace
3
- */
4
- fabric.Image.filters = { };
5
-
6
- /**
7
- * Grayscale image filter class
8
- * @class fabric.Image.filters.Grayscale
9
- * @memberOf fabric.Image.filters
10
- */
11
- fabric.Image.filters.Grayscale = fabric.util.createClass( /** @scope fabric.Image.filters.Grayscale.prototype */ {
12
-
13
- /**
14
- * Filter type
15
- * @param {String} type
16
- */
17
- type: "Grayscale",
18
-
19
- /**
20
- * Applies filter to canvas element
21
- * @method applyTo
22
- * @memberOf fabric.Image.filters.Grayscale.prototype
23
- * @param {Object} canvasEl Canvas element to apply filter to
24
- */
25
- applyTo: function(canvasEl) {
26
- var context = canvasEl.getContext('2d'),
27
- imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
28
- data = imageData.data,
29
- iLen = imageData.width,
30
- jLen = imageData.height,
31
- index, average, i, j;
32
-
33
- for (i = 0; i < iLen; i++) {
34
- for (j = 0; j < jLen; j++) {
35
-
36
- index = (i * 4) * jLen + (j * 4);
37
- average = (data[index] + data[index + 1] + data[index + 2]) / 3;
38
-
39
- data[index] = average;
40
- data[index + 1] = average;
41
- data[index + 2] = average;
42
- }
43
- }
44
-
45
- context.putImageData(imageData, 0, 0);
46
- },
47
-
48
- /**
49
- * Returns json representation of filter
50
- * @method toJSON
51
- * @return {String} json representation of filter
52
- */
53
- toJSON: function() {
54
- return { type: this.type };
55
- }
56
- });
57
-
58
- /**
59
- * Returns filter instance from an object representation
60
- * @static
61
- * @method fabric.Image.filters.Grayscale.fromObject
62
- * @return {fabric.Image.filters.Grayscale}
63
- */
64
- fabric.Image.filters.Grayscale.fromObject = function() {
65
- return new fabric.Image.filters.Grayscale();
66
- };
67
-
68
- /**
69
- * Remove white filter class
70
- * @class fabric.Image.filters.RemoveWhite
71
- * @memberOf fabric.Image.filters
72
- */
73
- fabric.Image.filters.RemoveWhite = fabric.util.createClass( /** @scope fabric.Image.filters.RemoveWhite.prototype */ {
74
-
75
- /**
76
- * Filter type
77
- * @param {String} type
78
- */
79
- type: "RemoveWhite",
80
-
81
- /**
82
- * Constructor
83
- * @memberOf fabric.Image.filters.RemoveWhite.prototype
84
- * @param {Object} [options] Options object
85
- */
86
- initialize: function(options) {
87
- options || (options = { });
88
- this.threshold = options.threshold || 30;
89
- this.distance = options.distance || 20;
90
- },
91
-
92
- /**
93
- * Applies filter to canvas element
94
- * @method applyTo
95
- * @param {Object} canvasEl Canvas element to apply filter to
96
- */
97
- applyTo: function(canvasEl) {
98
- var context = canvasEl.getContext('2d'),
99
- imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
100
- data = imageData.data,
101
- threshold = this.threshold,
102
- distance = this.distance,
103
- limit = 255 - threshold,
104
- abs = Math.abs,
105
- r, g, b;
106
-
107
- for (var i = 0, len = data.length; i < len; i += 4) {
108
-
109
- r = data[i];
110
- g = data[i+1];
111
- b = data[i+2];
112
-
113
- if (r > limit &&
114
- g > limit &&
115
- b > limit &&
116
- abs(r-g) < distance &&
117
- abs(r-b) < distance &&
118
- abs(g-b) < distance) {
119
-
120
- data[i+3] = 1;
121
- }
122
- }
123
-
124
- context.putImageData(imageData, 0, 0);
125
- },
126
-
127
- /**
128
- * Returns json representation of filter
129
- * @method toJSON
130
- * @return {String} json representation of filter
131
- */
132
- toJSON: function() {
133
- return {
134
- type: this.type,
135
- threshold: this.threshold,
136
- distance: this.distance
137
- };
138
- }
139
- });
140
-
141
- /**
142
- * Returns filter instance from an object representation
143
- * @static
144
- * @method fabric.Image.filters.RemoveWhite.fromObject
145
- * @return {fabric.Image.filters.RemoveWhite}
146
- */
147
- fabric.Image.filters.RemoveWhite.fromObject = function(object) {
148
- return new fabric.Image.filters.RemoveWhite(object);
149
- };
150
-
151
- /**
152
- * Invert filter class
153
- * @class fabric.Image.filters.Invert
154
- * @memberOf fabric.Image.filters
155
- */
156
- fabric.Image.filters.Invert = fabric.util.createClass( /** @scope fabric.Image.filters.Invert.prototype */ {
157
-
158
- /**
159
- * Filter type
160
- * @param {String} type
161
- */
162
- type: "Invert",
163
-
164
- /**
165
- * Applies filter to canvas element
166
- * @method applyTo
167
- * @memberOf fabric.Image.filters.Invert.prototype
168
- * @param {Object} canvasEl Canvas element to apply filter to
169
- */
170
- applyTo: function(canvasEl) {
171
- var context = canvasEl.getContext('2d'),
172
- imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
173
- data = imageData.data,
174
- iLen = data.length, i;
175
-
176
- for (i = 0; i < iLen; i+=4) {
177
- data[i] = 255 - data[i];
178
- data[i + 1] = 255 - data[i + 1];
179
- data[i + 2] = 255 - data[i + 2];
180
- }
181
-
182
- context.putImageData(imageData, 0, 0);
183
- },
184
-
185
- /**
186
- * Returns json representation of filter
187
- * @method toJSON
188
- * @return {String} json representation of filter
189
- */
190
- toJSON: function() {
191
- return { type: this.type };
192
- }
193
- });
194
-
195
- /**
196
- * Returns filter instance from an object representation
197
- * @static
198
- * @method fabric.Image.filters.Invert.fromObject
199
- * @return {fabric.Image.filters.Invert}
200
- */
201
- fabric.Image.filters.Invert.fromObject = function() {
202
- return new fabric.Image.filters.Invert();
203
- };
204
-
205
- /**
206
- * Sepia filter class
207
- * @class fabric.Image.filters.Sepia
208
- * @memberOf fabric.Image.filters
209
- */
210
- fabric.Image.filters.Sepia = fabric.util.createClass( /** @scope fabric.Image.filters.Sepia.prototype */ {
211
-
212
- /**
213
- * Filter type
214
- * @param {String} type
215
- */
216
- type: "Sepia",
217
-
218
- /**
219
- * Applies filter to canvas element
220
- * @method applyTo
221
- * @memberOf fabric.Image.filters.Sepia.prototype
222
- * @param {Object} canvasEl Canvas element to apply filter to
223
- */
224
- applyTo: function(canvasEl) {
225
- var context = canvasEl.getContext('2d'),
226
- imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
227
- data = imageData.data,
228
- iLen = data.length, i, avg;
229
-
230
- for (i = 0; i < iLen; i+=4) {
231
- avg = 0.3 * data[i] + 0.59 * data[i + 1] + 0.11 * data[i + 2];
232
- data[i] = avg + 100;
233
- data[i + 1] = avg + 50;
234
- data[i + 2] = avg + 255;
235
- }
236
-
237
- context.putImageData(imageData, 0, 0);
238
- },
239
-
240
- /**
241
- * Returns json representation of filter
242
- * @method toJSON
243
- * @return {String} json representation of filter
244
- */
245
- toJSON: function() {
246
- return { type: this.type };
247
- }
248
- });
249
-
250
- /**
251
- * Returns filter instance from an object representation
252
- * @static
253
- * @method fabric.Image.filters.Sepia.fromObject
254
- * @return {fabric.Image.filters.Sepia}
255
- */
256
- fabric.Image.filters.Sepia.fromObject = function() {
257
- return new fabric.Image.filters.Sepia();
258
- };
259
-
260
- /**
261
- * Sepia2 filter class
262
- * @class fabric.Image.filters.Sepia2
263
- * @memberOf fabric.Image.filters
264
- */
265
- fabric.Image.filters.Sepia2 = fabric.util.createClass( /** @scope fabric.Image.filters.Sepia2.prototype */ {
266
-
267
- /**
268
- * Filter type
269
- * @param {String} type
270
- */
271
- type: "Sepia2",
272
-
273
- /**
274
- * Applies filter to canvas element
275
- * @method applyTo
276
- * @memberOf fabric.Image.filters.Sepia.prototype
277
- * @param {Object} canvasEl Canvas element to apply filter to
278
- */
279
- applyTo: function(canvasEl) {
280
- var context = canvasEl.getContext('2d'),
281
- imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
282
- data = imageData.data,
283
- iLen = data.length, i, r, g, b;
284
-
285
- for (i = 0; i < iLen; i+=4) {
286
-
287
- r = data[i];
288
- g = data[i + 1];
289
- b = data[i + 2];
290
-
291
- data[i] = (r * 0.393 + g * 0.769 + b * 0.189 ) / 1.351;
292
- data[i + 1] = (r * 0.349 + g * 0.686 + b * 0.168 ) / 1.203;
293
- data[i + 2] = (r * 0.272 + g * 0.534 + b * 0.131 ) / 2.140;
294
- }
295
-
296
- context.putImageData(imageData, 0, 0);
297
- },
298
-
299
- /**
300
- * Returns json representation of filter
301
- * @method toJSON
302
- * @return {String} json representation of filter
303
- */
304
- toJSON: function() {
305
- return { type: this.type };
306
- }
307
- });
308
-
309
- /**
310
- * Returns filter instance from an object representation
311
- * @static
312
- * @method fabric.Image.filters.Sepia2.fromObject
313
- * @return {fabric.Image.filters.Sepia2}
314
- */
315
- fabric.Image.filters.Sepia2.fromObject = function() {
316
- return new fabric.Image.filters.Sepia2();
317
- };
318
-
319
- /**
320
- * Brightness filter class
321
- * @class fabric.Image.filters.Brightness
322
- * @memberOf fabric.Image.filters
323
- */
324
- fabric.Image.filters.Brightness = fabric.util.createClass( /** @scope fabric.Image.filters.Brightness.prototype */ {
325
-
326
- /**
327
- * Filter type
328
- * @param {String} type
329
- */
330
- type: "Brightness",
331
-
332
- /**
333
- * Constructor
334
- * @memberOf fabric.Image.filters.Brightness.prototype
335
- * @param {Object} [options] Options object
336
- */
337
- initialize: function(options) {
338
- options || (options = { });
339
- this.brightness = options.brightness || 100;
340
- },
341
-
342
- /**
343
- * Applies filter to canvas element
344
- * @method applyTo
345
- * @param {Object} canvasEl Canvas element to apply filter to
346
- */
347
- applyTo: function(canvasEl) {
348
- var context = canvasEl.getContext('2d'),
349
- imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
350
- data = imageData.data,
351
- brightness = this.brightness;
352
-
353
- for (var i = 0, len = data.length; i < len; i += 4) {
354
- data[i] += brightness;
355
- data[i + 1] += brightness;
356
- data[i + 2] += brightness;
357
- }
358
-
359
- context.putImageData(imageData, 0, 0);
360
- },
361
-
362
- /**
363
- * Returns json representation of filter
364
- * @method toJSON
365
- * @return {String} json representation of filter
366
- */
367
- toJSON: function() {
368
- return {
369
- type: this.type,
370
- brightness: this.brightness
371
- };
372
- }
373
- });
374
-
375
- /**
376
- * Returns filter instance from an object representation
377
- * @static
378
- * @method fabric.Image.filters.Brightness.fromObject
379
- * @return {fabric.Image.filters.Brightness}
380
- */
381
- fabric.Image.filters.Brightness.fromObject = function(object) {
382
- return new fabric.Image.filters.Brightness(object);
383
- };
384
-
385
- /**
386
- * Noise filter class
387
- * @class fabric.Image.filters.Noise
388
- * @memberOf fabric.Image.filters
389
- */
390
- fabric.Image.filters.Noise = fabric.util.createClass( /** @scope fabric.Image.filters.Noise.prototype */ {
391
-
392
- /**
393
- * Filter type
394
- * @param {String} type
395
- */
396
- type: "Noise",
397
-
398
- /**
399
- * Constructor
400
- * @memberOf fabric.Image.filters.Noise.prototype
401
- * @param {Object} [options] Options object
402
- */
403
- initialize: function(options) {
404
- options || (options = { });
405
- this.noise = options.noise || 100;
406
- },
407
-
408
- /**
409
- * Applies filter to canvas element
410
- * @method applyTo
411
- * @param {Object} canvasEl Canvas element to apply filter to
412
- */
413
- applyTo: function(canvasEl) {
414
- var context = canvasEl.getContext('2d'),
415
- imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
416
- data = imageData.data,
417
- noise = this.noise, rand;
418
-
419
- for (var i = 0, len = data.length; i < len; i += 4) {
420
-
421
- rand = (0.5 - Math.random()) * noise;
422
-
423
- data[i] += rand;
424
- data[i + 1] += rand;
425
- data[i + 2] += rand;
426
- }
427
-
428
- context.putImageData(imageData, 0, 0);
429
- },
430
-
431
- /**
432
- * Returns json representation of filter
433
- * @method toJSON
434
- * @return {String} json representation of filter
435
- */
436
- toJSON: function() {
437
- return {
438
- type: this.type,
439
- noise: this.noise
440
- };
441
- }
442
- });
443
-
444
- /**
445
- * Returns filter instance from an object representation
446
- * @static
447
- * @method fabric.Image.filters.Noise.fromObject
448
- * @return {fabric.Image.filters.Noise}
449
- */
450
- fabric.Image.filters.Noise.fromObject = function(object) {
451
- return new fabric.Image.filters.Noise(object);
452
- };
453
-
454
- /**
455
- * GradientTransparency filter class
456
- * @class fabric.Image.filters.GradientTransparency
457
- * @memberOf fabric.Image.filters
458
- */
459
- fabric.Image.filters.GradientTransparency = fabric.util.createClass( /** @scope fabric.Image.filters.GradientTransparency.prototype */ {
460
-
461
- /**
462
- * Filter type
463
- * @param {String} type
464
- */
465
- type: "GradientTransparency",
466
-
467
- /**
468
- * Constructor
469
- * @memberOf fabric.Image.filters.GradientTransparency
470
- * @param {Object} [options] Options object
471
- */
472
- initialize: function(options) {
473
- options || (options = { });
474
- this.threshold = options.threshold || 100;
475
- },
476
-
477
- /**
478
- * Applies filter to canvas element
479
- * @method applyTo
480
- * @param {Object} canvasEl Canvas element to apply filter to
481
- */
482
- applyTo: function(canvasEl) {
483
- var context = canvasEl.getContext('2d'),
484
- imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
485
- data = imageData.data,
486
- threshold = this.threshold,
487
- total = data.length;
488
-
489
- for (var i = 0, len = data.length; i < len; i += 4) {
490
- data[i + 3] = threshold + 255 * (total - i) / total;
491
- }
492
-
493
- context.putImageData(imageData, 0, 0);
494
- },
495
-
496
- /**
497
- * Returns json representation of filter
498
- * @method toJSON
499
- * @return {String} json representation of filter
500
- */
501
- toJSON: function() {
502
- return {
503
- type: this.type,
504
- threshold: this.threshold
505
- };
506
- }
507
- });
508
-
509
- /**
510
- * Returns filter instance from an object representation
511
- * @static
512
- * @method fabric.Image.filters.GradientTransparency.fromObject
513
- * @return {fabric.Image.filters.GradientTransparency}
514
- */
515
- fabric.Image.filters.GradientTransparency.fromObject = function(object) {
516
- return new fabric.Image.filters.GradientTransparency(object);
517
- };
518
-
519
- /**
520
- * Tint filter class
521
- * @class fabric.Image.filters.Tint
522
- * @memberOf fabric.Image.filters
523
- */
524
- fabric.Image.filters.Tint = fabric.util.createClass( /** @scope fabric.Image.filters.Tint.prototype */ {
525
-
526
- /**
527
- * Filter type
528
- * @param {String} type
529
- */
530
- type: "Tint",
531
-
532
- /**
533
- * Constructor
534
- * @memberOf fabric.Image.filters.Tint.prototype
535
- * @param {Object} [options] Options object
536
- */
537
- initialize: function(options) {
538
- options || (options = { });
539
- this.color = options.color || 0;
540
- },
541
-
542
- /**
543
- * Applies filter to canvas element
544
- * @method applyTo
545
- * @param {Object} canvasEl Canvas element to apply filter to
546
- */
547
- applyTo: function(canvasEl) {
548
-
549
- var context = canvasEl.getContext('2d'),
550
- imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
551
- data = imageData.data,
552
- iLen = data.length, i, a;
553
-
554
- var rgb = parseInt(this.color, 10).toString(16);
555
-
556
- var cr = parseInt('0x' + rgb.substr(0, 2), 16);
557
- var cg = parseInt('0x' + rgb.substr(2, 2), 16);
558
- var cb = parseInt('0x' + rgb.substr(4, 2), 16);
559
-
560
- for (i = 0; i < iLen; i+=4) {
561
-
562
- a = data[i+3];
563
-
564
- if (a > 0){
565
- data[i] = cr;
566
- data[i+1] = cg;
567
- data[i+2] = cb;
568
- }
569
- }
570
-
571
- context.putImageData(imageData, 0, 0);
572
- },
573
-
574
- /**
575
- * Returns json representation of filter
576
- * @method toJSON
577
- * @return {String} json representation of filter
578
- */
579
- toJSON: function() {
580
- return {
581
- type: this.type,
582
- color: this.color
583
- };
584
- }
585
- });
586
-
587
- /**
588
- * Returns filter instance from an object representation
589
- * @static
590
- * @method fabric.Image.filters.Tint.fromObject
591
- * @return {fabric.Image.filters.Tint}
592
- */
593
- fabric.Image.filters.Tint.fromObject = function(object) {
594
- return new fabric.Image.filters.Tint(object);
595
- };
596
-
597
- /**
598
- * Adapted from <a href="http://www.html5rocks.com/en/tutorials/canvas/imagefilters/">html5rocks article</a>
599
- * @class fabric.Image.filters.Convolute
600
- * @memberOf fabric.Image.filters
601
- */
602
- fabric.Image.filters.Convolute = fabric.util.createClass(/** @scope fabric.Image.filters.Convolute.prototype */ {
603
-
604
- /**
605
- * Filter type
606
- * @param {String} type
607
- */
608
- type: 'Convolute',
609
-
610
- /**
611
- * Constructor
612
- * @memberOf fabric.Image.filters.Convolute.prototype
613
- * @param {Object} [options] Options object
614
- */
615
- initialize: function(options) {
616
- options || (options = { });
617
-
618
- this.opaque = options.opaque;
619
- this.matrix = options.matrix || [ 0, 0, 0,
620
- 0, 1, 0,
621
- 0, 0, 0 ];
622
-
623
- var canvasEl = fabric.util.createCanvasElement();
624
- this.tmpCtx = canvasEl.getContext('2d');
625
- },
626
-
627
- /**
628
- * @private
629
- * @method _createImageData
630
- */
631
- _createImageData: function(w, h) {
632
- return this.tmpCtx.createImageData(w, h);
633
- },
634
-
635
- /**
636
- * Applies filter to canvas element
637
- * @method applyTo
638
- * @param {Object} canvasEl Canvas element to apply filter to
639
- */
640
- applyTo: function(canvasEl) {
641
-
642
- var weights = this.matrix;
643
- var context = canvasEl.getContext('2d');
644
- var pixels = context.getImageData(0, 0, canvasEl.width, canvasEl.height);
645
-
646
- var side = Math.round(Math.sqrt(weights.length));
647
- var halfSide = Math.floor(side/2);
648
- var src = pixels.data;
649
- var sw = pixels.width;
650
- var sh = pixels.height;
651
-
652
- // pad output by the convolution matrix
653
- var w = sw;
654
- var h = sh;
655
- var output = this._createImageData(w, h);
656
-
657
- var dst = output.data;
658
-
659
- // go through the destination image pixels
660
- var alphaFac = this.opaque ? 1 : 0;
661
- for (var y=0; y<h; y++) {
662
- for (var x=0; x<w; x++) {
663
- var sy = y;
664
- var sx = x;
665
- var dstOff = (y*w+x)*4;
666
- // calculate the weighed sum of the source image pixels that
667
- // fall under the convolution matrix
668
- var r=0, g=0, b=0, a=0;
669
- for (var cy=0; cy<side; cy++) {
670
- for (var cx=0; cx<side; cx++) {
671
- var scy = sy + cy - halfSide;
672
- var scx = sx + cx - halfSide;
673
- if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
674
- var srcOff = (scy*sw+scx)*4;
675
- var wt = weights[cy*side+cx];
676
- r += src[srcOff] * wt;
677
- g += src[srcOff+1] * wt;
678
- b += src[srcOff+2] * wt;
679
- a += src[srcOff+3] * wt;
680
- }
681
- }
682
- }
683
- dst[dstOff] = r;
684
- dst[dstOff+1] = g;
685
- dst[dstOff+2] = b;
686
- dst[dstOff+3] = a + alphaFac*(255-a);
687
- }
688
- }
689
-
690
- context.putImageData(output, 0, 0);
691
- },
692
-
693
- /**
694
- * Returns json representation of filter
695
- * @method toJSON
696
- * @return {String} json representation of filter
697
- */
698
- toJSON: function() {
699
- return {
700
- type: this.type,
701
- matrix: this.matrix
702
- };
703
- }
704
- });
705
-
706
- /**
707
- * Returns filter instance from an object representation
708
- * @static
709
- * @method fabric.Image.filters.Convolute.fromObject
710
- * @return {fabric.Image.filters.Convolute}
711
- */
712
- fabric.Image.filters.Convolute.fromObject = function(object) {
713
- return new fabric.Image.filters.Convolute(object);
714
- };
715
-
716
- /**
717
- * Pixelate filter class
718
- * @class fabric.Image.filters.Pixelate
719
- * @memberOf fabric.Image.filters
720
- */
721
- fabric.Image.filters.Pixelate = fabric.util.createClass(/** @scope fabric.Image.filters.Pixelate.prototype */ {
722
-
723
- /**
724
- * Filter type
725
- * @param {String} type
726
- */
727
- type: 'Pixelate',
728
-
729
- /**
730
- * Constructor
731
- * @memberOf fabric.Image.filters.Pixelate.prototype
732
- * @param {Object} [options] Options object
733
- */
734
- initialize: function(options) {
735
- options || (options = { });
736
- this.blocksize = options.blocksize || 4;
737
- },
738
-
739
- /**
740
- * Applies filter to canvas element
741
- * @method applyTo
742
- * @param {Object} canvasEl Canvas element to apply filter to
743
- */
744
- applyTo: function(canvasEl) {
745
-
746
- var context = canvasEl.getContext('2d'),
747
- imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height),
748
- data = imageData.data,
749
- iLen = imageData.width,
750
- jLen = imageData.height,
751
- index, i, j, r, g, b, a;
752
-
753
- for (i = 0; i < iLen; i += this.blocksize) {
754
- for (j = 0; j < jLen; j += this.blocksize) {
755
-
756
- index = (i * 4) * jLen + (j * 4);
757
-
758
- r = data[index];
759
- g = data[index+1];
760
- b = data[index+2];
761
- a = data[index+3];
762
-
763
- /*
764
- blocksize: 4
765
-
766
- [1,x,x,x,1]
767
- [x,x,x,x,1]
768
- [x,x,x,x,1]
769
- [x,x,x,x,1]
770
- [1,1,1,1,1]
771
- */
772
-
773
- for (var _i = i, _ilen = i + this.blocksize; _i < _ilen; _i++) {
774
- for (var _j = j, _jlen = j + this.blocksize; _j < _jlen; _j++) {
775
- index = (_i * 4) * jLen + (_j * 4);
776
- data[index] = r;
777
- data[index + 1] = g;
778
- data[index + 2] = b;
779
- data[index + 3] = a;
780
- }
781
- }
782
- }
783
- }
784
-
785
- context.putImageData(imageData, 0, 0);
786
- },
787
-
788
- /**
789
- * Returns json representation of filter
790
- * @method toJSON
791
- * @return {String} json representation of filter
792
- */
793
- toJSON: function() {
794
- return {
795
- type: this.type,
796
- blocksize: this.blocksize
797
- };
798
- }
799
- });
800
-
801
- /**
802
- * Returns filter instance from an object representation
803
- * @static
804
- * @method fabric.Image.filters.Pixelate.fromObject
805
- * @return {fabric.Image.filters.Pixelate}
806
- */
807
- fabric.Image.filters.Pixelate.fromObject = function(object) {
808
- return new fabric.Image.filters.Pixelate(object);
809
- };