PageSourceSearch

http://www.lagrandehistoiredunpetittrait.fr/trailer/src/easeljs/filters/ColorMatrixFilter.js

js lagrandehistoiredunpetittrait.fr collected 2026-10-02 15:48:33 UTC 4,498 bytes, 132 lines download raw bytes

1/*
2* ColorMatrixFilter
3* Visit http://createjs.com/ for documentation, updates and examples.
4*
5* Copyright (c) 2010 gskinner.com, inc.
6*
7* Permission is hereby granted, free of charge, to any person
8* obtaining a copy of this software and associated documentation
9* files (the "Software"), to deal in the Software without
10* restriction, including without limitation the rights to use,
11* copy, modify, merge, publish, distribute, sublicense, and/or sell
12* copies of the Software, and to permit persons to whom the
13* Software is furnished to do so, subject to the following
14* conditions:
15*
16* The above copyright notice and this permission notice shall be
17* included in all copies or substantial portions of the Software.
18*
19* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26* OTHER DEALINGS IN THE SOFTWARE.
27*/
28
29/**
30 * @module EaselJS
31 */
32
33// namespace:
34this.createjs = this.createjs||{};
35
36(function() {
37	"use strict";
38
39/**
40 * Allows you to carry out complex color operations such as modifying saturation, brightness, or inverting. See the
41 * {{#crossLink "ColorMatrix"}}{{/crossLink}} for more information on changing colors. For an easier color transform,
42 * consider the {{#crossLink "ColorFilter"}}{{/crossLink}}.
43 *
44 * <h4>Example</h4>
45 * This example creates a red circle, inverts its hue, and then saturates it to brighten it up.
46 *
47 *      var shape = new createjs.Shape().set({x:100,y:100});
48 *      shape.graphics.beginFill("#ff0000").drawCircle(0,0,50);
49 *
50 *      var matrix = new createjs.ColorMatrix().adjustHue(180).adjustSaturation(100);
51 *      shape.filters = [
52 *          new createjs.ColorMatrixFilter(matrix)
53 *      ];
54 *
55 *      shape.cache(-50, -50, 100, 100);
56 *
57 * See {{#crossLink "Filter"}}{{/crossLink}} for an more information on applying filters.
58 * @class ColorMatrixFilter
59 * @constructor
60 * @extends Filter
61 * @param {Array} matrix A 4x5 matrix describing the color operation to perform. See also the {{#crossLink "ColorMatrix"}}{{/crossLink}}
62 * class.
63 **/
64var ColorMatrixFilter = function(matrix) {
65  this.initialize(matrix);
66};
67var p = ColorMatrixFilter.prototype = new createjs.Filter();
68
69// public properties:
70	p.matrix = null;
71
72// constructor:
73	// TODO: detailed docs.
74	/**
75	 * @method initialize
76	 * @protected
77	 * @param {Array} matrix A 4x5 matrix describing the color operation to perform.
78	 **/
79	p.initialize = function(matrix) {
80		this.matrix = matrix;
81	};
82
83// public methods:
84	p.applyFilter = function(ctx, x, y, width, height, targetCtx, targetX, targetY) {
85		targetCtx = targetCtx || ctx;
86		if (targetX == null) { targetX = x; }
87		if (targetY == null) { targetY = y; }
88		try {
89			var imageData = ctx.getImageData(x, y, width, height);
90		} catch(e) {
91			//if (!this.suppressCrossDomainErrors) throw new Error("unable to access local image data: " + e);
92			return false;
93		}
94		var data = imageData.data;
95		var l = data.length;
96		var r,g,b,a;
97		var mtx = this.matrix;
98		var m0 =  mtx[0],  m1 =  mtx[1],  m2 =  mtx[2],  m3 =  mtx[3],  m4 =  mtx[4];
99		var m5 =  mtx[5],  m6 =  mtx[6],  m7 =  mtx[7],  m8 =  mtx[8],  m9 =  mtx[9];
100		var m10 = mtx[10], m11 = mtx[11], m12 = mtx[12], m13 = mtx[13], m14 = mtx[14];
101		var m15 = mtx[15], m16 = mtx[16], m17 = mtx[17], m18 = mtx[18], m19 = mtx[19];
102
103		for (var i=0; i<l; i+=4) {
104			r = data[i];
105			g = data[i+1];
106			b = data[i+2];
107			a = data[i+3];
108			data[i] = r*m0+g*m1+b*m2+a*m3+m4; // red
109			data[i+1] = r*m5+g*m6+b*m7+a*m8+m9; // green
110			data[i+2] = r*m10+g*m11+b*m12+a*m13+m14; // blue
111			data[i+3] = r*m15+g*m16+b*m17+a*m18+m19; // alpha
112		}
113		targetCtx.putImageData(imageData, targetX, targetY);
114		return true;
115	};
116
117	p.toString = function() {
118		return "[ColorMatrixFilter]";
119	};
120
121	/**
122	 * Returns a clone of this ColorMatrixFilter instance.
123	 * @method clone
124	 * @return {ColorMatrixFilter} A clone of the current ColorMatrixFilter instance.
125	 **/
126	p.clone = function() {
127		return new ColorMatrixFilter(this.matrix);
128	};
129
130	createjs.ColorMatrixFilter = ColorMatrixFilter;
131
132}());

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.