4 // Copyright (C) 2006 Novell, Inc.
8 // Permission is hereby granted, free of charge, to any person obtaining a
9 // copy of this software and associated documentation files (the "Software"),
10 // to deal in the Software without restriction, including without limitation
11 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 // and/or sell copies of the Software, and to permit persons to whom the
13 // Software is furnished to do so, subject to the following conditions:
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 // DEALINGS IN THE SOFTWARE.
33 using Beagle
.Util
.Tiff
;
37 namespace Beagle
.Filters
{
38 public class FilterTiff
: FilterImage
{
39 public FilterTiff () : base ()
41 AddSupportedFlavor (FilterFlavor
.NewFromMimeType ("image/tiff"));
44 protected override void PullImageProperties ()
47 Header header
= new Header (Stream
);
49 e
= header
.Directory
.Lookup (TagId
.ExifIfdPointer
);
51 ImageDirectory exif
= ((SubdirectoryEntry
)e
).Directory
[0];
52 AddTiffDirectoryProperties (this, exif
);
55 e
= header
.Directory
.Lookup (TagId
.SubIFDs
);
57 ImageDirectory
[] dirs
= ((SubdirectoryEntry
)e
).Directory
;
59 foreach (ImageDirectory subdir
in dirs
)
60 AddTiffDirectoryProperties (this, subdir
);
63 // we filter ifd0 last so that we pick up the
64 // width and height from the full resolution
65 // version if it exists
67 AddTiffDirectoryProperties (this, header
.Directory
);
70 internal static void AddTiffDirectoryProperties (FilterTiff filter
, ImageDirectory directory
)
72 foreach (DirectoryEntry e
in directory
.Entries
) {
74 case TagId
.ImageDescription
:
75 filter
.AddProperty (Beagle
.Property
.New ("exif:ImageDescription", e
.ValueAsString
[0]));
77 case TagId
.UserComment
:
78 filter
.AddProperty (Beagle
.Property
.New ("exif:UserComment", e
.ValueAsString
[0]));
80 case TagId
.DateTimeOriginal
:
81 AddDateProperty (filter
, "exif:DateTimeOriginal", e
.ValueAsString
[0]);
83 case TagId
.DateTimeDigitized
:
84 AddDateProperty (filter
, "exif:DateTimeDigitized", e
.ValueAsString
[0]);
87 AddDateProperty (filter
, "exif:DateTime", e
.ValueAsString
[0]);
89 case TagId
.PixelXDimension
:
90 filter
.Width
= (int) e
.ValueAsLong
[0];
91 //filter.AddProperty (Beagle.Property.NewUnsearched ("exif:PixelXDimension", e.ValueAsString [0]));
93 case TagId
.PixelYDimension
:
94 filter
.Height
= (int) e
.ValueAsLong
[0];
95 //filter.AddProperty (Beagle.Property.NewUnsearched ("exif:PixelYDimension", e.ValueAsString [0]));
97 case TagId
.ImageWidth
:
98 uint wval
= e
.ValueAsLong
[0];
99 if (filter
.Width
< wval
)
100 filter
.Width
= (int) wval
;
102 case TagId
.ImageLength
:
103 uint hval
= e
.ValueAsLong
[0];
104 if (filter
.Height
< hval
)
105 filter
.Height
= (int) hval
;
107 case TagId
.ShutterSpeedValue
:
108 case TagId
.ExposureTime
:
109 case TagId
.ISOSpeedRatings
:
110 case TagId
.ApertureValue
:
113 XmpFile xmp
= new XmpFile (new System
.IO
.MemoryStream (e
.RawData
));
114 filter
.AddXmpProperties (xmp
);
120 private static void AddDateProperty (FilterImage filter
, string name
, string value) {
122 DateTime time
= DirectoryEntry
.DateTimeFromString (value);
123 filter
.AddProperty (Beagle
.Property
.NewDate (name
, time
));
124 } catch (ArgumentOutOfRangeException
) {
125 Logger
.Log
.Debug ("{0} = '{1}' is invalid.", name
, value);
126 } catch (FormatException
) {
127 Logger
.Log
.Debug ("{0} = '{1}' is invalid.", name
, value);