2 // Copyright 2002 Ximian, Inc. http://www.ximian.com
3 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
5 // Permission is hereby granted, free of charge, to any person obtaining
6 // a copy of this software and associated documentation files (the
7 // "Software"), to deal in the Software without restriction, including
8 // without limitation the rights to use, copy, modify, merge, publish,
9 // distribute, sublicense, and/or sell copies of the Software, and to
10 // permit persons to whom the Software is furnished to do so, subject to
11 // the following conditions:
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 // Jordi Mas i Hernandez (jordi@ximian.com)
28 // Partially based on work by:
30 // Everaldo Canuto (everaldo.canuto@bol.com.br)
31 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
32 // Dennis Hayes (dennish@raytek.com)
37 using System.Runtime.InteropServices;
39 namespace System.Drawing.Imaging
44 [StructLayout (LayoutKind.Sequential)]
45 public sealed class ColorMatrix
47 private float color00;
48 private float color01;
49 private float color02;
50 private float color03;
51 private float color04;
52 private float color10;
53 private float color11;
54 private float color12;
55 private float color13;
56 private float color14;
57 private float color20;
58 private float color21;
59 private float color22;
60 private float color23;
61 private float color24;
62 private float color30;
63 private float color31;
64 private float color32;
65 private float color33;
66 private float color34;
67 private float color40;
68 private float color41;
69 private float color42;
70 private float color43;
71 private float color44;
76 color01 = color02 = color03 = color04 = 0;
77 color10 = color12 = color13 = color14 = 0;
78 color20 = color21 = color23 = color24 = 0;
79 color30 = color31 = color32 = color34 = 0;
80 color40 = color41 = color42 = color43 = 0;
81 color00 = color11 = color22 = color33 = color44 = 1;
85 public ColorMatrix (float[][] matrix)
87 color00 = matrix [0][0];
88 color01 = matrix [0][1];
89 color02 = matrix [0][2];
90 color03 = matrix [0][3];
91 color04 = matrix [0][4];
92 color10 = matrix [1][0];
93 color11 = matrix [1][1];
94 color12 = matrix [1][2];
95 color13 = matrix [1][3];
96 color14 = matrix [1][4];
97 color20 = matrix [2][0];
98 color21 = matrix [2][1];
99 color22 = matrix [2][2];
100 color23 = matrix [2][3];
101 color24 = matrix [2][4];
102 color30 = matrix [3][0];
103 color31 = matrix [3][1];
104 color32 = matrix [3][2];
105 color33 = matrix [3][3];
106 color34 = matrix [3][4];
107 color40 = matrix [4][0];
108 color41 = matrix [4][1];
109 color42 = matrix [4][2];
110 color43 = matrix [4][3];
111 color44 = matrix [4][4];
115 public float this[int row, int column] {
120 case 0: return color00;
121 case 1: return color01;
122 case 2: return color02;
123 case 3: return color03;
124 case 4: return color04;
131 case 0: return color10;
132 case 1: return color11;
133 case 2: return color12;
134 case 3: return color13;
135 case 4: return color14;
142 case 0: return color20;
143 case 1: return color21;
144 case 2: return color22;
145 case 3: return color23;
146 case 4: return color24;
153 case 0: return color30;
154 case 1: return color31;
155 case 2: return color32;
156 case 3: return color33;
157 case 4: return color34;
164 case 0: return color40;
165 case 1: return color41;
166 case 2: return color42;
167 case 3: return color43;
168 case 4: return color44;
177 throw new IndexOutOfRangeException ("Index was outside the bounds of the array");
184 case 0: color00 = value; return;
185 case 1: color01 = value; return;
186 case 2: color02 = value; return;
187 case 3: color03 = value; return;
188 case 4: color04 = value; return;
195 case 0: color10 = value; return;
196 case 1: color11 = value; return;
197 case 2: color12 = value; return;
198 case 3: color13 = value; return;
199 case 4: color14 = value; return;
206 case 0: color20 = value; return;
207 case 1: color21 = value; return;
208 case 2: color22 = value; return;
209 case 3: color23 = value; return;
210 case 4: color24 = value; return;
217 case 0: color30 = value; return;
218 case 1: color31 = value; return;
219 case 2: color32 = value; return;
220 case 3: color33 = value; return;
221 case 4: color34 = value; return;
228 case 0: color40 = value; return;
229 case 1: color41 = value; return;
230 case 2: color42 = value; return;
231 case 3: color43 = value; return;
232 case 4: color44 = value; return;
241 throw new IndexOutOfRangeException ("Index was outside the bounds of the array");
246 public float Matrix00 {
247 get { return color00; }
248 set { color00 = value; }
251 public float Matrix01 {
252 get { return color01; }
253 set { color01 = value; }
256 public float Matrix02 {
257 get { return color02; }
258 set { color02 = value; }
261 public float Matrix03 {
262 get { return color03; }
263 set { color03 = value; }
266 public float Matrix04 {
267 get { return color04; }
268 set { color04 = value; }
271 public float Matrix10 {
272 get { return color10; }
273 set { color10 = value; }
276 public float Matrix11 {
277 get { return color11; }
278 set { color11 = value; }
281 public float Matrix12 {
282 get { return color12; }
283 set { color12 = value; }
286 public float Matrix13 {
287 get { return color13; }
288 set { color13 = value; }
291 public float Matrix14 {
292 get { return color14; }
293 set { color14 = value; }
296 public float Matrix20 {
297 get { return color20; }
298 set { color20 = value; }
301 public float Matrix21 {
302 get { return color21; }
303 set { color21 = value; }
306 public float Matrix22 {
307 get { return color22; }
308 set { color22 = value; }
311 public float Matrix23 {
312 get { return color23; }
313 set { color23 = value; }
316 public float Matrix24 {
317 get { return color24; }
318 set { color24 = value; }
321 public float Matrix30 {
322 get { return color30; }
323 set { color30 = value; }
326 public float Matrix31 {
327 get { return color31; }
328 set { color31 = value; }
331 public float Matrix32 {
332 get { return color32; }
333 set { color32 = value; }
336 public float Matrix33 {
337 get { return color33; }
338 set { color33 = value; }
341 public float Matrix34 {
342 get { return color34; }
343 set { color34 = value; }
346 public float Matrix40 {
347 get { return color40; }
348 set { color40 = value; }
351 public float Matrix41 {
352 get { return color41; }
353 set { color41 = value; }
356 public float Matrix42 {
357 get { return color42; }
358 set { color42 = value; }
361 public float Matrix43 {
362 get { return color43; }
363 set { color43 = value; }
366 public float Matrix44 {
367 get { return color44; }
368 set { color44 = value; }