2005-10-04 Zoltan Varga <vargaz@freemail.hu>
[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 //
14
15 //
16 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
17 //
18 // Permission is hereby granted, free of charge, to any person obtaining
19 // a copy of this software and associated documentation files (the
20 // "Software"), to deal in the Software without restriction, including
21 // without limitation the rights to use, copy, modify, merge, publish,
22 // distribute, sublicense, and/or sell copies of the Software, and to
23 // permit persons to whom the Software is furnished to do so, subject to
24 // the following conditions:
25 // 
26 // The above copyright notice and this permission notice shall be
27 // included in all copies or substantial portions of the Software.
28 // 
29 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
32 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
33 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
34 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
35 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 //
37
38 using System;
39 using System.Runtime.InteropServices;
40 using System.Collections;
41 using System.IO;
42
43 namespace System.Drawing.Imaging {
44
45         [ComVisible (false)]
46         public sealed class ImageCodecInfo 
47         {
48                 private Guid clsid;
49                 private string codecName;
50                 private string dllName;
51                 private string filenameExtension;
52                 private ImageCodecFlags flags;
53                 private string formatDescription;
54                 private Guid formatID;
55                 private string  mimeType;
56                 private byte[][] signatureMasks;
57                 private byte[][] signaturePatterns;
58                 private int version;
59                 
60                 internal ImageCodecInfo()
61                 {
62                         
63                 }
64
65                 // methods              
66                 public static ImageCodecInfo[] GetImageDecoders() 
67                 {                       
68                         int decoderNums, arraySize, decoder_size;
69                         IntPtr decoders, decoder_ptr;
70                         ImageCodecInfo[] result;
71                         GdipImageCodecInfo gdipdecoder = new GdipImageCodecInfo();
72                         Status status;
73                         
74                         status = GDIPlus.GdipGetImageDecodersSize (out decoderNums, out arraySize);
75                         GDIPlus.CheckStatus (status);
76                         
77                         result =  new ImageCodecInfo [decoderNums];                     
78                         
79                         if (decoderNums == 0)
80                                 return result;                  
81                         
82                         /* Get decoders list*/
83                         decoders = Marshal.AllocHGlobal (arraySize);                                            
84                         status = GDIPlus.GdipGetImageDecoders (decoderNums,  arraySize, decoders);
85                         GDIPlus.CheckStatus (status);
86                         
87                         decoder_size = Marshal.SizeOf (gdipdecoder);                    
88                         decoder_ptr = decoders;
89                         
90                         for (int i = 0; i < decoderNums; i++, decoder_ptr = new IntPtr (decoder_ptr.ToInt64 () + decoder_size))
91                         {
92                                 gdipdecoder = (GdipImageCodecInfo) Marshal.PtrToStructure (decoder_ptr, typeof (GdipImageCodecInfo));   
93                                 result[i] = new ImageCodecInfo ();
94                                 GdipImageCodecInfo.MarshalTo (gdipdecoder, result[i]);                          
95                         }
96                         
97                         Marshal.FreeHGlobal (decoders);
98                         return result;
99                 }
100                 
101                 
102                 public static ImageCodecInfo[] GetImageEncoders() 
103                 {
104                         int encoderNums, arraySize, encoder_size;
105                         IntPtr encoders, encoder_ptr;
106                         ImageCodecInfo[] result;
107                         GdipImageCodecInfo gdipencoder = new GdipImageCodecInfo();
108                         Status status;
109                         
110                         status = GDIPlus.GdipGetImageEncodersSize (out encoderNums, out arraySize);
111                         GDIPlus.CheckStatus (status);
112                         
113                         result =  new ImageCodecInfo [encoderNums];                     
114                         
115                         if (encoderNums == 0)
116                                 return result;                  
117                         
118                         /* Get encoders list*/
119                         encoders = Marshal.AllocHGlobal (arraySize);
120                         
121                         status = GDIPlus.GdipGetImageEncoders (encoderNums,  arraySize, encoders);
122                         GDIPlus.CheckStatus (status);
123                         
124                         encoder_size = Marshal.SizeOf (gdipencoder);                    
125                         encoder_ptr = encoders;
126                         
127                         for (int i = 0; i < encoderNums; i++, encoder_ptr = new IntPtr (encoder_ptr.ToInt64 () + encoder_size))
128                         {
129                                 gdipencoder = (GdipImageCodecInfo) Marshal.PtrToStructure (encoder_ptr, typeof (GdipImageCodecInfo));                                           
130                                 result[i] = new ImageCodecInfo ();
131                                 GdipImageCodecInfo.MarshalTo (gdipencoder, result[i]);                          
132                         }
133                         
134                         Marshal.FreeHGlobal (encoders);
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 }