* support-test-*.cs: Rename from test-*-p2.cs.
[mono.git] / mcs / class / System.Drawing / System.Drawing.Imaging / ColorMatrix.cs
1 //
2 // Copyright 2002 Ximian, Inc.  http://www.ximian.com
3 // Copyright (C) 2004-2005 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:
12 //
13 // The above copyright notice and this permission notice shall be
14 // included in all copies or substantial portions of the Software.
15 //
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.
23 //
24 //
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 //   
34
35
36 using System;
37 using System.Runtime.InteropServices;
38
39 namespace System.Drawing.Imaging
40 {
41 #if TARGET_JVM
42         [MonoTODO]
43 #endif
44         [StructLayout (LayoutKind.Sequential)]
45         public sealed class ColorMatrix
46         {
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;
72
73                 // constructors
74                 public ColorMatrix ()
75                 {
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;
82                 }
83
84                 [CLSCompliant(false)]
85                 public ColorMatrix (float[][] matrix)
86                 {                       
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];                                                
112                 }
113
114                 // properties
115                 public float this[int row, int column] {
116                         get {  
117                                 switch (row) {
118                                 case 0: {
119                                         switch (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;
125                                         default: break;
126                                         }
127                                         break;
128                                 }
129                                 case 1: {
130                                         switch (column) {
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;
136                                         default: break;                                         
137                                         }
138                                         break;
139                                 }
140                                 case 2: {
141                                         switch (column) {
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;
147                                         default: break;                                         
148                                         }
149                                         break;
150                                 }
151                                 case 3: {
152                                         switch (column) {
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;
158                                         default: break;         
159                                         }
160                                         break;
161                                 }
162                                 case 4: {
163                                         switch (column) {
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;
169                                         default: break;                                                 
170                                         }
171                                         break;
172                                 }
173                                 default:
174                                         break;
175                                 }
176                         
177                                 throw new IndexOutOfRangeException ("Index was outside the bounds of the array");
178                         }
179                         
180                         set {  
181                                 switch (row) {
182                                 case 0: {
183                                         switch (column) {
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;
189                                         default: break;
190                                         }
191                                         break;
192                                 }
193                                 case 1: {
194                                         switch (column) {
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;
200                                         default: break;                                         
201                                         }
202                                         break;
203                                 }
204                                 case 2: {
205                                         switch (column) {
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;
211                                         default: break;                                         
212                                         }
213                                         break;
214                                 }
215                                 case 3: {
216                                         switch (column) {
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;
222                                         default: break;         
223                                         }
224                                         break;
225                                 }
226                                 case 4: {
227                                         switch (column) {
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;
233                                         default: break;                                                 
234                                         }
235                                         break;
236                                 }
237                                 default:
238                                         break;
239                                 }
240                         
241                                 throw new IndexOutOfRangeException ("Index was outside the bounds of the array");
242                         }                       
243                 }
244
245
246                 public float Matrix00 {
247                         get { return color00; }
248                         set { color00 = value; }
249                 }
250
251                 public float Matrix01 {
252                         get { return color01; }
253                         set { color01 = value; }
254                 }
255
256                 public float Matrix02 {
257                         get { return color02; }
258                         set { color02 = value; }
259                 }
260
261                 public float Matrix03 {
262                         get { return color03; }
263                         set { color03 = value; }
264                 }
265
266                 public float Matrix04 {
267                         get { return color04; }
268                         set { color04 = value; }
269                 }
270
271                 public float Matrix10 {
272                         get { return color10; }
273                         set { color10 = value; }
274                 }
275
276                 public float Matrix11 {
277                         get { return color11; }
278                         set { color11 = value; }
279                 }
280
281                 public float Matrix12 {
282                         get { return color12; }
283                         set { color12 = value; }
284                 }
285
286                 public float Matrix13 {
287                         get { return color13; }
288                         set { color13 = value; }
289                 }
290
291                 public float Matrix14 {
292                         get { return color14; }
293                         set { color14 = value; }
294                 }
295
296                 public float Matrix20 {
297                         get { return color20; }
298                         set { color20 = value; }
299                 }
300
301                 public float Matrix21 {
302                         get { return color21; }
303                         set { color21 = value; }
304                 }
305
306                 public float Matrix22 {
307                         get { return color22; }
308                         set { color22 = value; }
309                 }
310
311                 public float Matrix23 {
312                         get { return color23; }
313                         set { color23 = value; }
314                 }
315
316                 public float Matrix24 {
317                         get { return color24; }
318                         set { color24 = value; }
319                 }
320
321                 public float Matrix30 {
322                         get { return color30; }
323                         set { color30 = value; }
324                 }
325
326                 public float Matrix31 {
327                         get { return color31; }
328                         set { color31 = value; }
329                 }
330
331                 public float Matrix32 {
332                         get { return color32; }
333                         set { color32 = value; }
334                 }
335
336                 public float Matrix33 {
337                         get { return color33; }
338                         set { color33 = value; }
339                 }
340
341                 public float Matrix34 {
342                         get { return color34; }
343                         set { color34 = value; }
344                 }
345
346                 public float Matrix40 {
347                         get { return color40; }
348                         set { color40 = value; }
349                 }
350
351                 public float Matrix41 {
352                         get { return color41; }
353                         set { color41 = value; }
354                 }
355
356                 public float Matrix42 {
357                         get { return color42; }
358                         set { color42 = value; }
359                 }
360
361                 public float Matrix43 {
362                         get { return color43; }
363                         set { color43 = value; }
364                 }
365
366                 public float Matrix44 {
367                         get { return color44; }
368                         set { color44 = value; }
369                 }
370
371         }
372 }