~cosme/ubuntu/precise/freeimage/freeimage-3.15.1

« back to all changes in this revision

Viewing changes to Wrapper/FreeImage.NET/cs/Library/Classes/ImageMetadata.cs

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-07-20 13:42:15 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100720134215-xt1454zaedv3b604
Tags: 3.13.1-0ubuntu1
* New upstream release. Closes: (LP: #607800)
 - Updated debian/freeimage-get-orig-source script.
 - Removing no longer necessary debian/patches/* and
   the patch system in debian/rules.
 - Updated debian/rules to work with the new Makefiles.
 - Drop from -O3 to -O2 and use lzma compression saves
   ~10 MB of free space. 
* lintian stuff
 - fixed debhelper-but-no-misc-depends
 - fixed ldconfig-symlink-missing-for-shlib

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ==========================================================
 
2
// FreeImage 3 .NET wrapper
 
3
// Original FreeImage 3 functions and .NET compatible derived functions
 
4
//
 
5
// Design and implementation by
 
6
// - Jean-Philippe Goerke (jpgoerke@users.sourceforge.net)
 
7
// - Carsten Klein (cklein05@users.sourceforge.net)
 
8
//
 
9
// Contributors:
 
10
// - David Boland (davidboland@vodafone.ie)
 
11
//
 
12
// Main reference : MSDN Knowlede Base
 
13
//
 
14
// This file is part of FreeImage 3
 
15
//
 
16
// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
 
17
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
 
18
// THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
 
19
// OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
 
20
// CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
 
21
// THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
 
22
// SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
 
23
// PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
 
24
// THIS DISCLAIMER.
 
25
//
 
26
// Use at your own risk!
 
27
// ==========================================================
 
28
 
 
29
// ==========================================================
 
30
// CVS
 
31
// $Revision: 1.7 $
 
32
// $Date: 2009/02/27 16:34:59 $
 
33
// $Id: ImageMetadata.cs,v 1.7 2009/02/27 16:34:59 cklein05 Exp $
 
34
// ==========================================================
 
35
 
 
36
using System;
 
37
using System.Collections;
 
38
using System.Collections.Generic;
 
39
using System.Reflection;
 
40
using System.Diagnostics;
 
41
 
 
42
namespace FreeImageAPI.Metadata
 
43
{
 
44
        /// <summary>
 
45
        /// Class handling metadata of a FreeImage bitmap.
 
46
        /// </summary>
 
47
        public class ImageMetadata : IEnumerable, IComparable, IComparable<ImageMetadata>
 
48
        {
 
49
                [DebuggerBrowsable(DebuggerBrowsableState.Never)]
 
50
                private readonly List<MetadataModel> data;
 
51
                [DebuggerBrowsable(DebuggerBrowsableState.Never)]
 
52
                private readonly FIBITMAP dib;
 
53
                [DebuggerBrowsable(DebuggerBrowsableState.Never)]
 
54
                private bool hideEmptyModels;
 
55
 
 
56
                /// <summary>
 
57
                /// Initializes a new instance based on the specified <see cref="FIBITMAP"/>,
 
58
                /// showing all known models.
 
59
                /// </summary>
 
60
                /// <param name="dib">Handle to a FreeImage bitmap.</param>
 
61
                public ImageMetadata(FIBITMAP dib) : this(dib, false) { }
 
62
 
 
63
                /// <summary>
 
64
                /// Initializes a new instance based on the specified <see cref="FIBITMAP"/>,
 
65
                /// showing or hiding empry models.
 
66
                /// </summary>
 
67
                /// <param name="dib">Handle to a FreeImage bitmap.</param>
 
68
                /// <param name="hideEmptyModels">When <b>true</b>, empty metadata models
 
69
                /// will be hidden until a tag to this model is added.</param>
 
70
                public ImageMetadata(FIBITMAP dib, bool hideEmptyModels)
 
71
                {
 
72
                        if (dib.IsNull) throw new ArgumentNullException("dib");
 
73
                        data = new List<MetadataModel>(FreeImage.FREE_IMAGE_MDMODELS.Length);
 
74
                        this.dib = dib;
 
75
                        this.hideEmptyModels = hideEmptyModels;
 
76
 
 
77
                        data.Add(new MDM_ANIMATION(dib));
 
78
                        data.Add(new MDM_COMMENTS(dib));
 
79
                        data.Add(new MDM_CUSTOM(dib));
 
80
                        data.Add(new MDM_EXIF_EXIF(dib));
 
81
                        data.Add(new MDM_EXIF_GPS(dib));
 
82
                        data.Add(new MDM_INTEROP(dib));
 
83
                        data.Add(new MDM_EXIF_MAIN(dib));
 
84
                        data.Add(new MDM_MAKERNOTE(dib));
 
85
                        data.Add(new MDM_GEOTIFF(dib));
 
86
                        data.Add(new MDM_IPTC(dib));
 
87
                        data.Add(new MDM_NODATA(dib));
 
88
                        data.Add(new MDM_XMP(dib));
 
89
                }
 
90
 
 
91
                /// <summary>
 
92
                /// Gets or sets the <see cref="MetadataModel"/> of the specified type.
 
93
                /// <para>In case the getter returns <c>null</c> the model is not contained
 
94
                /// by the list.</para>
 
95
                /// <para><c>null</c> can be used calling the setter to destroy the model.</para>
 
96
                /// </summary>
 
97
                /// <param name="model">Type of the model.</param>
 
98
                /// <returns>The <see cref="FreeImageAPI.Metadata.MetadataModel"/> object of the specified type.</returns>
 
99
                public MetadataModel this[FREE_IMAGE_MDMODEL model]
 
100
                {
 
101
                        get
 
102
                        {
 
103
                                for (int i = 0; i < data.Count; i++)
 
104
                                {
 
105
                                        if (data[i].Model == model)
 
106
                                        {
 
107
                                                if (!data[i].Exists && hideEmptyModels)
 
108
                                                {
 
109
                                                        return null;
 
110
                                                }
 
111
                                                return data[i];
 
112
                                        }
 
113
                                }
 
114
                                return null;
 
115
                        }
 
116
                }
 
117
 
 
118
                /// <summary>
 
119
                /// Gets or sets the <see cref="FreeImageAPI.Metadata.MetadataModel"/> at the specified index.
 
120
                /// <para>In case the getter returns <c>null</c> the model is not contained
 
121
                /// by the list.</para>
 
122
                /// <para><c>null</c> can be used calling the setter to destroy the model.</para>
 
123
                /// </summary>
 
124
                /// <param name="index">Index of the <see cref="FreeImageAPI.Metadata.MetadataModel"/> within
 
125
                /// this instance.</param>
 
126
                /// <returns>The <see cref="FreeImageAPI.Metadata.MetadataModel"/>
 
127
                /// object at the specified index.</returns>
 
128
                public MetadataModel this[int index]
 
129
                {
 
130
                        get
 
131
                        {
 
132
                                if (index < 0 || index >= data.Count)
 
133
                                {
 
134
                                        throw new ArgumentOutOfRangeException("index");
 
135
                                }
 
136
                                return (hideEmptyModels && !data[index].Exists) ? null : data[index];
 
137
                        }
 
138
                }
 
139
 
 
140
                /// <summary>
 
141
                /// Returns a list of all visible
 
142
                /// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see>.
 
143
                /// </summary>
 
144
                public List<MetadataModel> List
 
145
                {
 
146
                        get
 
147
                        {
 
148
                                if (hideEmptyModels)
 
149
                                {
 
150
                                        List<MetadataModel> result = new List<MetadataModel>();
 
151
                                        for (int i = 0; i < data.Count; i++)
 
152
                                        {
 
153
                                                if (data[i].Exists)
 
154
                                                {
 
155
                                                        result.Add(data[i]);
 
156
                                                }
 
157
                                        }
 
158
                                        return result;
 
159
                                }
 
160
                                else
 
161
                                {
 
162
                                        return data;
 
163
                                }
 
164
                        }
 
165
                }
 
166
 
 
167
                /// <summary>
 
168
                /// Adds new tag to the bitmap or updates its value in case it already exists.
 
169
                /// <see cref="FreeImageAPI.Metadata.MetadataTag.Key"/> will be used as key.
 
170
                /// </summary>
 
171
                /// <param name="tag">The tag to add or update.</param>
 
172
                /// <returns>Returns true on success, false on failure.</returns>
 
173
                /// <exception cref="ArgumentNullException">
 
174
                /// <paramref name="tag"/> is null.</exception>
 
175
                public bool AddTag(MetadataTag tag)
 
176
                {
 
177
                        for (int i = 0; i < data.Count; i++)
 
178
                        {
 
179
                                if (tag.Model == data[i].Model)
 
180
                                {
 
181
                                        return data[i].AddTag(tag);
 
182
                                }
 
183
                        }
 
184
                        return false;
 
185
                }
 
186
 
 
187
                /// <summary>
 
188
                /// Returns the number of visible
 
189
                /// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see>.
 
190
                /// </summary>
 
191
                public int Count
 
192
                {
 
193
                        get
 
194
                        {
 
195
                                if (hideEmptyModels)
 
196
                                {
 
197
                                        int count = 0;
 
198
                                        for (int i = 0; i < data.Count; i++)
 
199
                                        {
 
200
                                                if (data[i].Exists)
 
201
                                                {
 
202
                                                        count++;
 
203
                                                }
 
204
                                        }
 
205
                                        return count;
 
206
                                }
 
207
                                else
 
208
                                {
 
209
                                        return data.Count;
 
210
                                }
 
211
                        }
 
212
                }
 
213
 
 
214
                /// <summary>
 
215
                /// Gets or sets whether empty
 
216
                /// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see> are hidden.
 
217
                /// </summary>
 
218
                public bool HideEmptyModels
 
219
                {
 
220
                        get
 
221
                        {
 
222
                                return hideEmptyModels;
 
223
                        }
 
224
                        set
 
225
                        {
 
226
                                hideEmptyModels = value;
 
227
                        }
 
228
                }
 
229
 
 
230
                /// <summary>
 
231
                /// Retrieves an object that can iterate through the individual
 
232
                /// <see cref="FreeImageAPI.Metadata.MetadataModel">MetadataModels</see>
 
233
                /// in this <see cref="ImageMetadata"/>.
 
234
                /// </summary>
 
235
                /// <returns>An <see cref="IEnumerator"/> for this <see cref="ImageMetadata"/>.</returns>
 
236
                public IEnumerator GetEnumerator()
 
237
                {
 
238
                        if (hideEmptyModels)
 
239
                        {
 
240
                                List<MetadataModel> tempList = new List<MetadataModel>(data.Count);
 
241
                                for (int i = 0; i < data.Count; i++)
 
242
                                {
 
243
                                        if (data[i].Exists)
 
244
                                        {
 
245
                                                tempList.Add(data[i]);
 
246
                                        }
 
247
                                }
 
248
                                return tempList.GetEnumerator();
 
249
                        }
 
250
                        else
 
251
                        {
 
252
                                return data.GetEnumerator();
 
253
                        }
 
254
                }
 
255
 
 
256
                /// <summary>
 
257
                /// Compares this instance with a specified <see cref="Object"/>.
 
258
                /// </summary>
 
259
                /// <param name="obj">An object to compare with this instance.</param>
 
260
                /// <returns>A 32-bit signed integer indicating the lexical relationship between the two comparands.</returns>
 
261
                /// <exception cref="ArgumentException"><paramref name="obj"/> is not a <see cref="ImageMetadata"/>.</exception>
 
262
                public int CompareTo(object obj)
 
263
                {
 
264
                        if (obj == null)
 
265
                        {
 
266
                                return 1;
 
267
                        }
 
268
                        if (!(obj is ImageMetadata))
 
269
                        {
 
270
                                throw new ArgumentException("obj");
 
271
                        }
 
272
                        return CompareTo((ImageMetadata)obj);
 
273
                }
 
274
 
 
275
                /// <summary>
 
276
                /// Compares this instance with a specified <see cref="ImageMetadata"/> object.
 
277
                /// </summary>
 
278
                /// <param name="other">A <see cref="ImageMetadata"/> to compare.</param>
 
279
                /// <returns>A signed number indicating the relative values of this instance
 
280
                /// and <paramref name="other"/>.</returns>
 
281
                public int CompareTo(ImageMetadata other)
 
282
                {
 
283
                        return this.dib.CompareTo(other.dib);
 
284
                }
 
285
        }
 
286
}
 
 
b'\\ No newline at end of file'