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