[Cleanup] Removed TARGET_JVM
[mono-project.git] / mcs / class / System.Drawing / System.Drawing.Imaging / ColorMatrix.cs
blob3b042cad175e945dbd3b31229f1e5d37beb6b404
1 //
2 // Copyright 2002 Ximian, Inc. http://www.ximian.com
3 // Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
4 //
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.
25 // Authors:
26 // Jordi Mas i Hernandez (jordi@ximian.com)
27 //
28 // Partially based on work by:
29 //
30 // Everaldo Canuto (everaldo.canuto@bol.com.br)
31 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
32 // Dennis Hayes (dennish@raytek.com)
33 //
35 using System.Runtime.InteropServices;
37 namespace System.Drawing.Imaging
39 [StructLayout (LayoutKind.Sequential)]
40 public sealed class ColorMatrix
42 private float color00;
43 private float color01;
44 private float color02;
45 private float color03;
46 private float color04;
47 private float color10;
48 private float color11;
49 private float color12;
50 private float color13;
51 private float color14;
52 private float color20;
53 private float color21;
54 private float color22;
55 private float color23;
56 private float color24;
57 private float color30;
58 private float color31;
59 private float color32;
60 private float color33;
61 private float color34;
62 private float color40;
63 private float color41;
64 private float color42;
65 private float color43;
66 private float color44;
68 // constructors
69 public ColorMatrix ()
71 color01 = color02 = color03 = color04 = 0;
72 color10 = color12 = color13 = color14 = 0;
73 color20 = color21 = color23 = color24 = 0;
74 color30 = color31 = color32 = color34 = 0;
75 color40 = color41 = color42 = color43 = 0;
76 color00 = color11 = color22 = color33 = color44 = 1;
79 [CLSCompliant(false)]
80 public ColorMatrix (float[][] matrix)
82 color00 = matrix [0][0];
83 color01 = matrix [0][1];
84 color02 = matrix [0][2];
85 color03 = matrix [0][3];
86 color04 = matrix [0][4];
87 color10 = matrix [1][0];
88 color11 = matrix [1][1];
89 color12 = matrix [1][2];
90 color13 = matrix [1][3];
91 color14 = matrix [1][4];
92 color20 = matrix [2][0];
93 color21 = matrix [2][1];
94 color22 = matrix [2][2];
95 color23 = matrix [2][3];
96 color24 = matrix [2][4];
97 color30 = matrix [3][0];
98 color31 = matrix [3][1];
99 color32 = matrix [3][2];
100 color33 = matrix [3][3];
101 color34 = matrix [3][4];
102 color40 = matrix [4][0];
103 color41 = matrix [4][1];
104 color42 = matrix [4][2];
105 color43 = matrix [4][3];
106 color44 = matrix [4][4];
109 // properties
110 public float this[int row, int column] {
111 get {
112 switch (row) {
113 case 0: {
114 switch (column) {
115 case 0: return color00;
116 case 1: return color01;
117 case 2: return color02;
118 case 3: return color03;
119 case 4: return color04;
120 default: break;
122 break;
124 case 1: {
125 switch (column) {
126 case 0: return color10;
127 case 1: return color11;
128 case 2: return color12;
129 case 3: return color13;
130 case 4: return color14;
131 default: break;
133 break;
135 case 2: {
136 switch (column) {
137 case 0: return color20;
138 case 1: return color21;
139 case 2: return color22;
140 case 3: return color23;
141 case 4: return color24;
142 default: break;
144 break;
146 case 3: {
147 switch (column) {
148 case 0: return color30;
149 case 1: return color31;
150 case 2: return color32;
151 case 3: return color33;
152 case 4: return color34;
153 default: break;
155 break;
157 case 4: {
158 switch (column) {
159 case 0: return color40;
160 case 1: return color41;
161 case 2: return color42;
162 case 3: return color43;
163 case 4: return color44;
164 default: break;
166 break;
168 default:
169 break;
172 throw new IndexOutOfRangeException ("Index was outside the bounds of the array");
175 set {
176 switch (row) {
177 case 0: {
178 switch (column) {
179 case 0: color00 = value; return;
180 case 1: color01 = value; return;
181 case 2: color02 = value; return;
182 case 3: color03 = value; return;
183 case 4: color04 = value; return;
184 default: break;
186 break;
188 case 1: {
189 switch (column) {
190 case 0: color10 = value; return;
191 case 1: color11 = value; return;
192 case 2: color12 = value; return;
193 case 3: color13 = value; return;
194 case 4: color14 = value; return;
195 default: break;
197 break;
199 case 2: {
200 switch (column) {
201 case 0: color20 = value; return;
202 case 1: color21 = value; return;
203 case 2: color22 = value; return;
204 case 3: color23 = value; return;
205 case 4: color24 = value; return;
206 default: break;
208 break;
210 case 3: {
211 switch (column) {
212 case 0: color30 = value; return;
213 case 1: color31 = value; return;
214 case 2: color32 = value; return;
215 case 3: color33 = value; return;
216 case 4: color34 = value; return;
217 default: break;
219 break;
221 case 4: {
222 switch (column) {
223 case 0: color40 = value; return;
224 case 1: color41 = value; return;
225 case 2: color42 = value; return;
226 case 3: color43 = value; return;
227 case 4: color44 = value; return;
228 default: break;
230 break;
232 default:
233 break;
236 throw new IndexOutOfRangeException ("Index was outside the bounds of the array");
241 public float Matrix00 {
242 get { return color00; }
243 set { color00 = value; }
246 public float Matrix01 {
247 get { return color01; }
248 set { color01 = value; }
251 public float Matrix02 {
252 get { return color02; }
253 set { color02 = value; }
256 public float Matrix03 {
257 get { return color03; }
258 set { color03 = value; }
261 public float Matrix04 {
262 get { return color04; }
263 set { color04 = value; }
266 public float Matrix10 {
267 get { return color10; }
268 set { color10 = value; }
271 public float Matrix11 {
272 get { return color11; }
273 set { color11 = value; }
276 public float Matrix12 {
277 get { return color12; }
278 set { color12 = value; }
281 public float Matrix13 {
282 get { return color13; }
283 set { color13 = value; }
286 public float Matrix14 {
287 get { return color14; }
288 set { color14 = value; }
291 public float Matrix20 {
292 get { return color20; }
293 set { color20 = value; }
296 public float Matrix21 {
297 get { return color21; }
298 set { color21 = value; }
301 public float Matrix22 {
302 get { return color22; }
303 set { color22 = value; }
306 public float Matrix23 {
307 get { return color23; }
308 set { color23 = value; }
311 public float Matrix24 {
312 get { return color24; }
313 set { color24 = value; }
316 public float Matrix30 {
317 get { return color30; }
318 set { color30 = value; }
321 public float Matrix31 {
322 get { return color31; }
323 set { color31 = value; }
326 public float Matrix32 {
327 get { return color32; }
328 set { color32 = value; }
331 public float Matrix33 {
332 get { return color33; }
333 set { color33 = value; }
336 public float Matrix34 {
337 get { return color34; }
338 set { color34 = value; }
341 public float Matrix40 {
342 get { return color40; }
343 set { color40 = value; }
346 public float Matrix41 {
347 get { return color41; }
348 set { color41 = value; }
351 public float Matrix42 {
352 get { return color42; }
353 set { color42 = value; }
356 public float Matrix43 {
357 get { return color43; }
358 set { color43 = value; }
361 public float Matrix44 {
362 get { return color44; }
363 set { color44 = value; }
367 static internal IntPtr Alloc (ColorMatrix cm)
369 if (cm == null)
370 return IntPtr.Zero;
372 IntPtr result = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (ColorMatrix)));
373 Marshal.StructureToPtr (cm, result, false);
374 return result;
377 static internal void Free (IntPtr cm)
379 if (cm != IntPtr.Zero)
380 Marshal.FreeHGlobal (cm);