2 // Copyright 2002 Ximian, Inc. http://www.ximian.com
3 // Copyright (C) 2004-2006 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)
35 using System.Runtime.InteropServices;
37 namespace System.Drawing.Imaging
42 [StructLayout (LayoutKind.Sequential)]
43 public sealed class ColorMatrix
45 private float color00;
46 private float color01;
47 private float color02;
48 private float color03;
49 private float color04;
50 private float color10;
51 private float color11;
52 private float color12;
53 private float color13;
54 private float color14;
55 private float color20;
56 private float color21;
57 private float color22;
58 private float color23;
59 private float color24;
60 private float color30;
61 private float color31;
62 private float color32;
63 private float color33;
64 private float color34;
65 private float color40;
66 private float color41;
67 private float color42;
68 private float color43;
69 private float color44;
74 color01 = color02 = color03 = color04 = 0;
75 color10 = color12 = color13 = color14 = 0;
76 color20 = color21 = color23 = color24 = 0;
77 color30 = color31 = color32 = color34 = 0;
78 color40 = color41 = color42 = color43 = 0;
79 color00 = color11 = color22 = color33 = color44 = 1;
83 public ColorMatrix (float[][] matrix)
85 color00 = matrix [0][0];
86 color01 = matrix [0][1];
87 color02 = matrix [0][2];
88 color03 = matrix [0][3];
89 color04 = matrix [0][4];
90 color10 = matrix [1][0];
91 color11 = matrix [1][1];
92 color12 = matrix [1][2];
93 color13 = matrix [1][3];
94 color14 = matrix [1][4];
95 color20 = matrix [2][0];
96 color21 = matrix [2][1];
97 color22 = matrix [2][2];
98 color23 = matrix [2][3];
99 color24 = matrix [2][4];
100 color30 = matrix [3][0];
101 color31 = matrix [3][1];
102 color32 = matrix [3][2];
103 color33 = matrix [3][3];
104 color34 = matrix [3][4];
105 color40 = matrix [4][0];
106 color41 = matrix [4][1];
107 color42 = matrix [4][2];
108 color43 = matrix [4][3];
109 color44 = matrix [4][4];
113 public float this[int row, int column] {
118 case 0: return color00;
119 case 1: return color01;
120 case 2: return color02;
121 case 3: return color03;
122 case 4: return color04;
129 case 0: return color10;
130 case 1: return color11;
131 case 2: return color12;
132 case 3: return color13;
133 case 4: return color14;
140 case 0: return color20;
141 case 1: return color21;
142 case 2: return color22;
143 case 3: return color23;
144 case 4: return color24;
151 case 0: return color30;
152 case 1: return color31;
153 case 2: return color32;
154 case 3: return color33;
155 case 4: return color34;
162 case 0: return color40;
163 case 1: return color41;
164 case 2: return color42;
165 case 3: return color43;
166 case 4: return color44;
175 throw new IndexOutOfRangeException ("Index was outside the bounds of the array");
182 case 0: color00 = value; return;
183 case 1: color01 = value; return;
184 case 2: color02 = value; return;
185 case 3: color03 = value; return;
186 case 4: color04 = value; return;
193 case 0: color10 = value; return;
194 case 1: color11 = value; return;
195 case 2: color12 = value; return;
196 case 3: color13 = value; return;
197 case 4: color14 = value; return;
204 case 0: color20 = value; return;
205 case 1: color21 = value; return;
206 case 2: color22 = value; return;
207 case 3: color23 = value; return;
208 case 4: color24 = value; return;
215 case 0: color30 = value; return;
216 case 1: color31 = value; return;
217 case 2: color32 = value; return;
218 case 3: color33 = value; return;
219 case 4: color34 = value; return;
226 case 0: color40 = value; return;
227 case 1: color41 = value; return;
228 case 2: color42 = value; return;
229 case 3: color43 = value; return;
230 case 4: color44 = value; return;
239 throw new IndexOutOfRangeException ("Index was outside the bounds of the array");
244 public float Matrix00 {
245 get { return color00; }
246 set { color00 = value; }
249 public float Matrix01 {
250 get { return color01; }
251 set { color01 = value; }
254 public float Matrix02 {
255 get { return color02; }
256 set { color02 = value; }
259 public float Matrix03 {
260 get { return color03; }
261 set { color03 = value; }
264 public float Matrix04 {
265 get { return color04; }
266 set { color04 = value; }
269 public float Matrix10 {
270 get { return color10; }
271 set { color10 = value; }
274 public float Matrix11 {
275 get { return color11; }
276 set { color11 = value; }
279 public float Matrix12 {
280 get { return color12; }
281 set { color12 = value; }
284 public float Matrix13 {
285 get { return color13; }
286 set { color13 = value; }
289 public float Matrix14 {
290 get { return color14; }
291 set { color14 = value; }
294 public float Matrix20 {
295 get { return color20; }
296 set { color20 = value; }
299 public float Matrix21 {
300 get { return color21; }
301 set { color21 = value; }
304 public float Matrix22 {
305 get { return color22; }
306 set { color22 = value; }
309 public float Matrix23 {
310 get { return color23; }
311 set { color23 = value; }
314 public float Matrix24 {
315 get { return color24; }
316 set { color24 = value; }
319 public float Matrix30 {
320 get { return color30; }
321 set { color30 = value; }
324 public float Matrix31 {
325 get { return color31; }
326 set { color31 = value; }
329 public float Matrix32 {
330 get { return color32; }
331 set { color32 = value; }
334 public float Matrix33 {
335 get { return color33; }
336 set { color33 = value; }
339 public float Matrix34 {
340 get { return color34; }
341 set { color34 = value; }
344 public float Matrix40 {
345 get { return color40; }
346 set { color40 = value; }
349 public float Matrix41 {
350 get { return color41; }
351 set { color41 = value; }
354 public float Matrix42 {
355 get { return color42; }
356 set { color42 = value; }
359 public float Matrix43 {
360 get { return color43; }
361 set { color43 = value; }
364 public float Matrix44 {
365 get { return color44; }
366 set { color44 = value; }
370 static internal IntPtr Alloc (ColorMatrix cm)
375 IntPtr result = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (ColorMatrix)));
376 Marshal.StructureToPtr (cm, result, false);
380 static internal void Free (IntPtr cm)
382 if (cm != IntPtr.Zero)
383 Marshal.FreeHGlobal (cm);