refactoring: fix documentation attributes
[mono.git] / mcs / class / System.Drawing / System.Drawing.Imaging / ImageFormat.cs
1 //
2 // System.Drawing.Imaging.ImageFormat.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-4 Ximian, Inc.  http://www.ximian.com
12 // Copyright (C) 2004,2006 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.ComponentModel;
35
36 namespace System.Drawing.Imaging {
37
38         [TypeConverter (typeof (ImageFormatConverter))]
39         public sealed class ImageFormat {
40
41                 private Guid guid;
42                 private string name;
43
44                 private const string BmpGuid = "b96b3cab-0728-11d3-9d7b-0000f81ef32e";
45                 private const string EmfGuid = "b96b3cac-0728-11d3-9d7b-0000f81ef32e";
46                 private const string ExifGuid = "b96b3cb2-0728-11d3-9d7b-0000f81ef32e";
47                 private const string GifGuid = "b96b3cb0-0728-11d3-9d7b-0000f81ef32e";
48                 private const string TiffGuid = "b96b3cb1-0728-11d3-9d7b-0000f81ef32e";
49                 private const string PngGuid = "b96b3caf-0728-11d3-9d7b-0000f81ef32e";
50                 private const string MemoryBmpGuid = "b96b3caa-0728-11d3-9d7b-0000f81ef32e";
51                 private const string IconGuid = "b96b3cb5-0728-11d3-9d7b-0000f81ef32e";
52                 private const string JpegGuid = "b96b3cae-0728-11d3-9d7b-0000f81ef32e";
53                 private const string WmfGuid = "b96b3cad-0728-11d3-9d7b-0000f81ef32e";
54
55                 // lock(this) is bad
56                 // http://msdn.microsoft.com/library/en-us/dnaskdr/html/askgui06032003.asp?frame=true
57                 private static object locker = new object ();
58
59                 private static ImageFormat BmpImageFormat;
60                 private static ImageFormat EmfImageFormat;
61                 private static ImageFormat ExifImageFormat;
62                 private static ImageFormat GifImageFormat;
63                 private static ImageFormat TiffImageFormat;
64                 private static ImageFormat PngImageFormat;
65                 private static ImageFormat MemoryBmpImageFormat;
66                 private static ImageFormat IconImageFormat;
67                 private static ImageFormat JpegImageFormat;
68                 private static ImageFormat WmfImageFormat;
69                 
70
71                 // constructors
72                 public ImageFormat (Guid guid)
73                 {
74                         this.name = null;
75                         this.guid = guid;
76                 }
77
78                 private ImageFormat (string name, string guid)
79                 {
80                         this.name = name;
81                         this.guid = new Guid (guid);
82                 }
83                 
84
85                 // methods
86                 public override bool Equals (object o)
87                 {
88                         ImageFormat f = (o as ImageFormat);
89                         if (f == null)
90                                 return false;
91
92                         return f.Guid.Equals (guid);
93                 }
94
95                 
96                 public override int GetHashCode () 
97                 {
98                         return guid.GetHashCode ();
99                 }
100                 
101                 
102                 public override string ToString () 
103                 {
104                         if (name != null)
105                                 return name;
106
107                         return ("[ImageFormat: " + guid.ToString () + "]");
108                 }
109
110                 // properties
111                 public Guid Guid {
112                         get { return guid; }
113                 }
114
115                 
116                 public static ImageFormat Bmp {
117                         get {
118                                 lock (locker) {
119                                         if (BmpImageFormat == null)
120                                                 BmpImageFormat = new ImageFormat ("Bmp", BmpGuid);
121                                         return BmpImageFormat;
122                                 }
123                         }
124                 }
125                 
126                 public static ImageFormat Emf {
127                         get {
128                                 lock (locker) {
129                                         if (EmfImageFormat == null)
130                                                 EmfImageFormat = new ImageFormat ("Emf", EmfGuid);
131                                         return EmfImageFormat;
132                                 }
133                         }
134                 }
135                 
136                 
137                 public static ImageFormat Exif {
138                         get {
139                                 lock (locker) {
140                                         if (ExifImageFormat == null)
141                                                 ExifImageFormat = new ImageFormat ("Exif", ExifGuid);
142                                         return ExifImageFormat;
143                                 }
144                         }
145                 }
146                 
147
148                 public static ImageFormat Gif {
149                         get {
150                                 lock (locker) {
151                                         if (GifImageFormat == null)
152                                                 GifImageFormat = new ImageFormat ("Gif", GifGuid);
153                                         return GifImageFormat;
154                                 }
155                         }
156                 }
157                 
158                 
159                 public static ImageFormat Icon {
160                         get {
161                                 lock (locker) {
162                                         if (IconImageFormat == null)
163                                                 IconImageFormat = new ImageFormat ("Icon", IconGuid);
164                                         return IconImageFormat;
165                                 }
166                         }
167                 }
168                 
169                 
170                 public static ImageFormat Jpeg {
171                         get {
172                                 lock (locker) {
173                                         if (JpegImageFormat == null)
174                                                 JpegImageFormat = new ImageFormat ("Jpeg", JpegGuid);
175                                         return JpegImageFormat;
176                                 }
177                         }
178                 }
179                 
180                 
181                 public static ImageFormat MemoryBmp {
182                         get {
183                                 lock (locker) {
184                                         if (MemoryBmpImageFormat == null)
185                                                 MemoryBmpImageFormat = new ImageFormat ("MemoryBMP", MemoryBmpGuid);
186                                         return MemoryBmpImageFormat;
187                                 }
188                         }
189                 }
190                 
191                 
192                 public static ImageFormat Png {
193                         get {
194                                 lock (locker) {
195                                         if (PngImageFormat == null)
196                                                 PngImageFormat = new ImageFormat ("Png", PngGuid);
197                                         return PngImageFormat;
198                                 }
199                         }
200                 }
201                 
202                 
203                 public static ImageFormat Tiff {
204                         get {
205                                 lock (locker) {
206                                         if (TiffImageFormat == null)
207                                                 TiffImageFormat = new ImageFormat ("Tiff", TiffGuid);
208                                         return TiffImageFormat;
209                                 }
210                         }
211                 }
212                 
213                 
214                 public static ImageFormat Wmf {
215                         get {
216                                 lock (locker) {
217                                         if (WmfImageFormat == null)
218                                                 WmfImageFormat = new ImageFormat ("Wmf", WmfGuid);
219                                         return WmfImageFormat;
220                                 }
221                         }
222                 }
223         }
224 }