4 // Copyright (C) 2004 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.
36 namespace Beagle
.Filters
{
38 [PropertyKeywordMapping (Keyword
="imagemodel", PropertyName
="exif:Model", IsKeyword
=true)]
39 public class FilterJpeg
: FilterImage
{
41 public FilterJpeg () : base ()
43 AddSupportedFlavor (FilterFlavor
.NewFromMimeType ("image/jpeg"));
46 // FIXME: This is not particularly efficient
47 protected override void PullImageProperties ()
49 JpegHeader header
= new JpegHeader (Stream
);
50 byte [] commentdata
= header
.GetJFIFComment();
51 if (commentdata
!= null && commentdata
.Length
!= 0)
53 string comment
= System
.Text
.Encoding
.Default
.GetString( commentdata
, 0, commentdata
.Length
);
54 if (comment
!= null && comment
!= "") {
55 AddProperty (Beagle
.Property
.New ("jfif:Comment", comment
));
56 AddProperty (Beagle
.Property
.NewUnstored ("fixme:comment", comment
));
60 byte [] data
= header
.GetRawExif ();
61 if (data
== null || data
.Length
== 0)
63 ExifData exif
= new ExifData (data
, (uint) data
.Length
);
69 str
= exif
.LookupFirstValue (ExifTag
.UserComment
);
70 if (str
!= null && str
!= "") {
71 AddProperty (Beagle
.Property
.New ("exif:UserComment", str
));
72 AddProperty (Beagle
.Property
.NewUnstored ("fixme:comment", str
));
76 str
= exif
.LookupFirstValue (ExifTag
.ImageDescription
);
77 if (str
!= null && str
!= "") {
78 AddProperty (Beagle
.Property
.New ("exif:ImageDescription", str
));
79 AddProperty (Beagle
.Property
.NewUnstored ("fixme:comment", str
));
82 str
= exif
.LookupFirstValue (ExifTag
.PixelXDimension
);
83 if (str
!= null && str
!= "") {
84 Width
= Int32
.Parse (str
);
85 AddProperty (Beagle
.Property
.NewUnsearched ("exif:PixelXDimension", str
));
88 str
= exif
.LookupFirstValue (ExifTag
.PixelYDimension
);
89 if (str
!= null && str
!= "") {
90 Height
= Int32
.Parse (str
);
91 AddProperty (Beagle
.Property
.NewUnsearched ("exif:PixelYDimension", str
));
94 str
= exif
.LookupFirstValue (ExifTag
.ISOSpeedRatings
);
95 if (str
!= null && str
!= "")
96 AddProperty (Beagle
.Property
.NewUnsearched ("exif:ISOSpeedRatings", str
));
98 str
= exif
.LookupFirstValue (ExifTag
.ShutterSpeedValue
);
99 if (str
!= null && str
!= "")
100 AddProperty (Beagle
.Property
.NewUnsearched ("exif:ShutterSpeedValue", str
));
102 str
= exif
.LookupFirstValue (ExifTag
.ExposureTime
);
103 if (str
!= null && str
!= "")
104 AddProperty (Beagle
.Property
.NewUnsearched ("exif:ExposureTime", str
));
106 str
= exif
.LookupFirstValue (ExifTag
.FNumber
);
107 if (str
!= null && str
!= "")
108 AddProperty (Beagle
.Property
.NewUnsearched ("exif:FNumber", str
));
110 str
= exif
.LookupFirstValue (ExifTag
.ApertureValue
);
111 if (str
!= null && str
!= "")
112 AddProperty (Beagle
.Property
.NewUnsearched ("exif:ApertureValue", str
));
114 str
= exif
.LookupFirstValue (ExifTag
.FocalLength
);
115 if (str
!= null && str
!= "")
116 AddProperty (Beagle
.Property
.NewUnsearched ("exif:FocalLength", str
));
118 str
= exif
.LookupFirstValue (ExifTag
.Flash
);
119 if (str
!= null && str
!= "")
120 AddProperty (Beagle
.Property
.NewUnsearched ("exif:Flash", str
));
122 str
= exif
.LookupFirstValue (ExifTag
.Model
);
123 if (str
!= null && str
!= "")
124 AddProperty (Beagle
.Property
.NewKeyword ("exif:Model", str
));
126 str
= exif
.LookupFirstValue (ExifTag
.Copyright
);
127 if (str
!= null && str
!= "")
128 AddProperty (Beagle
.Property
.New ("exif:Copyright", str
));
130 str
= exif
.LookupFirstValue (ExifTag
.DateTime
);
131 if (str
!= null && str
!= "") {
133 DateTime dt
= ExifUtil
.DateTimeFromString (str
);
134 AddProperty (Beagle
.Property
.NewDate ("exif:DateTime", dt
));
135 } catch (ArgumentOutOfRangeException
) {
136 Logger
.Log
.Debug("EXIF DateTime '{0}' is invalid.", str
);
140 byte [] xmp_data
= header
.GetRawXmp ();
142 if (xmp_data
!= null) {
144 for (i
= 0; i
< xmp_data
.Length
; i
++)
145 if (xmp_data
[i
] == 0) {
150 XmpFile xmp
= new XmpFile (new MemoryStream (xmp_data
, i
, xmp_data
.Length
- i
));
151 AddXmpProperties (xmp
);
154 Finished (); // That's all folks...