* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Drawing / System.Drawing.Imaging / ImageCodecInfo.cs
1 //
2 // System.Drawing.Imaging.ImageCodecInfo.cs
3 //
4 // Authors:
5 //   Everaldo Canuto (everaldo.canuto@bol.com.br)
6 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
7 //   Dennis Hayes (dennish@raytek.com)
8 //   Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 //   Dennis Hayes (dennish@raytek.com)
10 //   Jordi Mas i Hernandez (jordi@ximian.com)
11 //
12 // (C) 2002 Ximian, Inc.  http://www.ximian.com
13 // Copyright (C) 2004,2006 Novell, Inc (http://www.novell.com)
14 //
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
22 // 
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
25 // 
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 //
34
35 using System.Runtime.InteropServices;
36 using System.Collections;
37 using System.IO;
38
39 namespace System.Drawing.Imaging {
40
41 #if ONLY_1_1
42         [ComVisible (false)]
43 #endif
44         public sealed class ImageCodecInfo {
45                 private Guid clsid;
46                 private string codecName;
47                 private string dllName;
48                 private string filenameExtension;
49                 private ImageCodecFlags flags;
50                 private string formatDescription;
51                 private Guid formatID;
52                 private string  mimeType;
53                 private byte[][] signatureMasks;
54                 private byte[][] signaturePatterns;
55                 private int version;
56                 
57                 internal ImageCodecInfo()
58                 {
59                         
60                 }
61
62                 // methods              
63                 public static ImageCodecInfo[] GetImageDecoders() 
64                 {                       
65                         int decoderNums, arraySize, decoder_size;
66                         IntPtr decoders, decoder_ptr;
67                         ImageCodecInfo[] result;
68                         GdipImageCodecInfo gdipdecoder = new GdipImageCodecInfo();
69                         Status status;
70                         
71                         status = GDIPlus.GdipGetImageDecodersSize (out decoderNums, out arraySize);
72                         GDIPlus.CheckStatus (status);
73                         
74                         result =  new ImageCodecInfo [decoderNums];                     
75                         
76                         if (decoderNums == 0)
77                                 return result;                  
78                         
79                         /* Get decoders list*/
80                         decoders = Marshal.AllocHGlobal (arraySize);
81                         try {
82                                 status = GDIPlus.GdipGetImageDecoders (decoderNums,  arraySize, decoders);
83                                 GDIPlus.CheckStatus (status);
84                         
85                                 decoder_size = Marshal.SizeOf (gdipdecoder);
86                                 decoder_ptr = decoders;
87                         
88                                 for (int i = 0; i < decoderNums; i++, decoder_ptr = new IntPtr (decoder_ptr.ToInt64 () + decoder_size)) {
89                                         gdipdecoder = (GdipImageCodecInfo) Marshal.PtrToStructure (decoder_ptr, typeof (GdipImageCodecInfo));
90                                         result[i] = new ImageCodecInfo ();
91                                         GdipImageCodecInfo.MarshalTo (gdipdecoder, result[i]);
92                                 }
93                         }
94                         finally {
95                                 Marshal.FreeHGlobal (decoders);
96                         }
97                         return result;
98                 }
99                 
100                 
101                 public static ImageCodecInfo[] GetImageEncoders() 
102                 {
103                         int encoderNums, arraySize, encoder_size;
104                         IntPtr encoders, encoder_ptr;
105                         ImageCodecInfo[] result;
106                         GdipImageCodecInfo gdipencoder = new GdipImageCodecInfo();
107                         Status status;
108                         
109                         status = GDIPlus.GdipGetImageEncodersSize (out encoderNums, out arraySize);
110                         GDIPlus.CheckStatus (status);
111                         
112                         result =  new ImageCodecInfo [encoderNums];                     
113                         
114                         if (encoderNums == 0)
115                                 return result;                  
116                         
117                         /* Get encoders list*/
118                         encoders = Marshal.AllocHGlobal (arraySize);
119                         try {
120                                 status = GDIPlus.GdipGetImageEncoders (encoderNums,  arraySize, encoders);
121                                 GDIPlus.CheckStatus (status);
122                         
123                                 encoder_size = Marshal.SizeOf (gdipencoder);
124                                 encoder_ptr = encoders;
125                         
126                                 for (int i = 0; i < encoderNums; i++, encoder_ptr = new IntPtr (encoder_ptr.ToInt64 () + encoder_size)) {
127                                         gdipencoder = (GdipImageCodecInfo) Marshal.PtrToStructure (encoder_ptr, typeof (GdipImageCodecInfo));
128                                         result[i] = new ImageCodecInfo ();
129                                         GdipImageCodecInfo.MarshalTo (gdipencoder, result[i]);
130                                 }
131                         }
132                         finally {
133                                 Marshal.FreeHGlobal (encoders);
134                         }
135                         return result;
136                 }
137
138                 // properties
139                 
140                 public Guid Clsid 
141                 {
142                         get { return clsid; }
143                         set { clsid = value; }
144                 }
145
146                 
147                 public string CodecName 
148                 {
149                         get { return codecName; }
150                         set { codecName = value; }
151                 }
152
153                 
154                 public string DllName 
155                 {
156                         get { return dllName; }
157                         set { dllName = value; }
158                 }
159
160                 
161                 public string FilenameExtension 
162                 {
163                         get { return filenameExtension; }
164                         set { filenameExtension = value; }
165                 }
166
167                 
168                 public ImageCodecFlags Flags 
169                 {
170                         get { return flags; }
171                         set { flags = value; }
172                 }
173                 
174                 public string FormatDescription 
175                 {
176                         get { return formatDescription; }
177                         set { formatDescription = value; }
178                 }
179                 
180                 public Guid FormatID 
181                 {
182                         get { return formatID; }
183                         set { formatID = value; }
184                 }
185
186                 
187                 public string MimeType 
188                 {
189                         get { return mimeType; }
190                         set { mimeType = value; }
191                 }
192
193                 
194                 [CLSCompliant(false)]
195                 public byte[][] SignatureMasks 
196                 {
197                         get { return signatureMasks; }
198                         set { signatureMasks = value; }
199                 }
200
201                 [MonoTODO]
202                 [CLSCompliant(false)]
203                 public byte[][] SignaturePatterns 
204                 {
205                         get { return signaturePatterns; }
206                         set { signaturePatterns = value; }
207                 }
208                 
209                 public int Version 
210                 {
211                         get { return version; }
212                         set { version = value; }
213                 }
214
215         }
216
217 }