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.
34 namespace Beagle
.Filters
{
36 public class FilterJpeg
: FilterImage
{
38 public FilterJpeg () : base ()
40 AddSupportedFlavor (FilterFlavor
.NewFromMimeType ("image/jpeg"));
43 // FIXME: This is not particularly efficient
44 protected override void PullImageProperties ()
46 JpegHeader header
= new JpegHeader (Stream
);
47 byte [] commentdata
= header
.GetJFIFComment();
48 if (commentdata
!= null && commentdata
.Length
!= 0)
50 string comment
= System
.Text
.Encoding
.ASCII
.GetString( commentdata
, 0, commentdata
.Length
);
51 if (comment
!= null && comment
!= "")
52 AddProperty (Beagle
.Property
.New ("jfif:Comment", comment
));
55 byte [] data
= header
.GetRawExif ();
56 if (data
== null || data
.Length
== 0)
58 ExifData exif
= new ExifData (data
, (uint) data
.Length
);
64 str
= exif
.LookupFirstValue (ExifTag
.UserComment
);
65 if (str
!= null && str
!= "")
66 AddProperty (Beagle
.Property
.New ("exif:UserComment", str
));
68 str
= exif
.LookupFirstValue (ExifTag
.ImageDescription
);
69 if (str
!= null && str
!= "")
70 AddProperty (Beagle
.Property
.New ("exif:ImageDescription", str
));
72 str
= exif
.LookupFirstValue (ExifTag
.PixelXDimension
);
73 if (str
!= null && str
!= "")
74 AddProperty (Beagle
.Property
.NewKeyword ("exif:PixelXDimension", str
));
76 str
= exif
.LookupFirstValue (ExifTag
.PixelYDimension
);
77 if (str
!= null && str
!= "")
78 AddProperty (Beagle
.Property
.NewKeyword ("exif:PixelYDimension", str
));
80 str
= exif
.LookupFirstValue (ExifTag
.ISOSpeedRatings
);
81 if (str
!= null && str
!= "")
82 AddProperty (Beagle
.Property
.NewKeyword ("exif:ISOSpeedRatings", str
));
84 str
= exif
.LookupFirstValue (ExifTag
.ShutterSpeedValue
);
85 if (str
!= null && str
!= "")
86 AddProperty (Beagle
.Property
.NewKeyword ("exif:ShutterSpeedValue", str
));
88 str
= exif
.LookupFirstValue (ExifTag
.ExposureTime
);
89 if (str
!= null && str
!= "")
90 AddProperty (Beagle
.Property
.NewKeyword ("exif:ExposureTime", str
));
92 str
= exif
.LookupFirstValue (ExifTag
.FNumber
);
93 if (str
!= null && str
!= "")
94 AddProperty (Beagle
.Property
.NewKeyword ("exif:FNumber", str
));
96 str
= exif
.LookupFirstValue (ExifTag
.ApertureValue
);
97 if (str
!= null && str
!= "")
98 AddProperty (Beagle
.Property
.NewKeyword ("exif:ApertureValue", str
));
100 str
= exif
.LookupFirstValue (ExifTag
.FocalLength
);
101 if (str
!= null && str
!= "")
102 AddProperty (Beagle
.Property
.NewKeyword ("exif:FocalLength", str
));
104 str
= exif
.LookupFirstValue (ExifTag
.Flash
);
105 if (str
!= null && str
!= "")
106 AddProperty (Beagle
.Property
.NewKeyword ("exif:Flash", str
));
108 str
= exif
.LookupFirstValue (ExifTag
.Model
);
109 if (str
!= null && str
!= "")
110 AddProperty (Beagle
.Property
.NewKeyword ("exif:Model", str
));
112 str
= exif
.LookupFirstValue (ExifTag
.Copyright
);
113 if (str
!= null && str
!= "")
114 AddProperty (Beagle
.Property
.New ("exif:Copyright", str
));
116 str
= exif
.LookupFirstValue (ExifTag
.DateTime
);
117 if (str
!= null && str
!= "") {
119 DateTime dt
= ExifUtil
.DateTimeFromString (str
);
120 AddProperty (Beagle
.Property
.NewDate ("exif:DateTime", dt
));
121 } catch (ArgumentOutOfRangeException e
) {
122 Logger
.Log
.Debug("EXIF DateTime '{0}' is invalid.", str
);
126 Finished (); // That's all folks...