66
60
AddProperty (Beagle.Property.New ("jfif:Comment", comment));
63
private static string GetExifString (Tiff.ImageDirectory directory, Tiff.TagId id)
65
if (directory == null)
68
Tiff.DirectoryEntry entry = directory.Lookup (id);
72
return entry.ValueAsString [0];
75
private static double GetExifRational (Tiff.ImageDirectory directory, Tiff.TagId id)
77
if (directory == null)
80
Tiff.DirectoryEntry entry = directory.Lookup (id);
84
return entry.RationalValue [0].Value;
87
static string GetFlashString (ushort flash_value)
89
switch (flash_value) {
90
case 0x0000 : return "Flash did not fire";
91
case 0x0001 : return "Flash fired";
92
case 0x0005 : return "Strobe return light not detected";
93
case 0x0007 : return "Strobe return light detected";
94
case 0x0009 : return "Flash fired, compulsory flash mode";
95
case 0x000D : return "Flash fired, compulsory flash mode, return light not detected";
96
case 0x000F : return "Flash fired, compulsory flash mode, return light detected";
97
case 0x0010 : return "Flash did not fire, compulsory flash mode";
98
case 0x0018 : return "Flash did not fire, auto mode";
99
case 0x0019 : return "Flash fired, auto mode";
100
case 0x001D : return "Flash fired, auto mode, return light not detected";
101
case 0x001F : return "Flash fired, auto mode, return light detected";
102
case 0x0020 : return "No flash function";
103
case 0x0041 : return "Flash fired, red-eye reduction mode";
104
case 0x0045 : return "Flash fired, red-eye reduction mode, return light not detected";
105
case 0x0047 : return "Flash fired, red-eye reduction mode, return light detected";
106
case 0x0049 : return "Flash fired, compulsory flash mode, red-eye reduction mode";
107
case 0x004D : return "Flash fired, compulsory flash mode, red-eye reduction mode, return light not detected";
108
case 0x004F : return "Flash fired, compulsory flash mode, red-eye reduction mode, return light detected";
109
case 0x0059 : return "Flash fired, auto mode, red-eye reduction mode";
110
case 0x005D : return "Flash fired, auto mode, return light not detected, red-eye reduction mode";
111
case 0x005F : return "Flash fired, auto mode, return light detected, red-eye reduction mode";
112
default : return null;
69
116
private void AddExifProperties (JpegHeader header)
71
ExifData exif = header.Exif;
118
Tiff.Header ifd = header.GetExifHeader ();
121
//ifd.Dump ("foo"); // Uncomment to debug
77
str = exif.LookupFirstValue (ExifTag.UserComment);
78
AddProperty (Beagle.Property.New ("exif:UserComment", str));
80
str = exif.LookupFirstValue (ExifTag.ImageDescription);
124
Tiff.DirectoryEntry entry;
126
// Add IFD 0 properies
128
str = GetExifString (ifd.Directory, Tiff.TagId.Model);
129
AddProperty (Beagle.Property.New ("exif:Model", str));
131
str = GetExifString (ifd.Directory, Tiff.TagId.ImageDescription);
81
132
AddProperty (Beagle.Property.New ("exif:ImageDescription", str));
83
str = exif.LookupFirstValue (ExifTag.PixelXDimension);
84
if (str != null && str != String.Empty) {
85
Width = Int32.Parse (str);
86
AddProperty (Beagle.Property.NewUnsearched ("exif:PixelXDimension", str));
89
str = exif.LookupFirstValue (ExifTag.PixelYDimension);
90
if (str != null && str != String.Empty) {
91
Height = Int32.Parse (str);
92
AddProperty (Beagle.Property.NewUnsearched ("exif:PixelYDimension", str));
95
str = exif.LookupFirstValue (ExifTag.ISOSpeedRatings);
135
entry = ifd.Directory.Lookup (Tiff.TagId.DateTime);
137
// Assume datetime stored in the images are local times
138
AddProperty (Beagle.Property.NewDate ("exif:DateTime", entry.ValueAsDate.ToUniversalTime ()));
139
} catch (FormatException) {
140
Logger.Log.Debug ("EXIF DateTime '{0}' is invalid.", GetExifString (ifd.Directory, Tiff.TagId.DateTime));
141
} catch (ArgumentOutOfRangeException) {
142
Logger.Log.Debug ("EXIF DateTime '{0}' is invalid.", GetExifString (ifd.Directory, Tiff.TagId.DateTime));
145
str = GetExifString (ifd.Directory, Tiff.TagId.Copyright);
146
AddProperty (Beagle.Property.New ("dc:rights", str));
148
// Add IFD 1 properties
150
Tiff.SubdirectoryEntry subdir = (Tiff.SubdirectoryEntry) ifd.Directory.Lookup (Tiff.TagId.ExifIfdPointer);
154
Tiff.ImageDirectory exif = subdir.Directory [0];
158
entry = exif.Lookup (Tiff.TagId.UserComment);
160
AddProperty (Beagle.Property.New ("exif:UserComment", entry.UserCommentValue));
163
entry = exif.Lookup (Tiff.TagId.PixelXDimension);
165
val = entry.ValueAsLong [0];
168
AddProperty (Beagle.Property.NewUnsearched ("exif:PixelXDimension", val));
172
entry = exif.Lookup (Tiff.TagId.PixelYDimension);
174
val = entry.ValueAsLong [0];
177
AddProperty (Beagle.Property.NewUnsearched ("exif:PixelYDimension", val));
180
str = GetExifString (exif, Tiff.TagId.ISOSpeedRatings);
96
181
AddProperty (Beagle.Property.NewUnsearched ("exif:ISOSpeedRatings", str));
98
str = exif.LookupFirstValue (ExifTag.ShutterSpeedValue);
183
str = GetExifString (exif, Tiff.TagId.ShutterSpeedValue);
99
184
AddProperty (Beagle.Property.NewUnsearched ("exif:ShutterSpeedValue", str));
101
str = exif.LookupFirstValue (ExifTag.ExposureTime);
102
AddProperty (Beagle.Property.NewUnsearched ("exif:ExposureTime", str));
104
str = exif.LookupFirstValue (ExifTag.FNumber);
105
AddProperty (Beagle.Property.NewUnsearched ("exif:FNumber", str));
107
str = exif.LookupFirstValue (ExifTag.ApertureValue);
108
AddProperty (Beagle.Property.NewUnsearched ("exif:ApertureValue", str));
110
str = exif.LookupFirstValue (ExifTag.FocalLength);
111
AddProperty (Beagle.Property.NewUnsearched ("exif:FocalLength", str));
113
str = exif.LookupFirstValue (ExifTag.Flash);
114
AddProperty (Beagle.Property.NewUnsearched ("exif:Flash", str));
116
str = exif.LookupFirstValue (ExifTag.Model);
117
AddProperty (Beagle.Property.New ("exif:Model", str));
119
str = exif.LookupFirstValue (ExifTag.Copyright);
120
AddProperty (Beagle.Property.New ("dc:rights", str));
122
str = exif.LookupFirstValue (ExifTag.DateTime);
123
if (str != null && str != String.Empty) {
125
DateTime dt = ExifUtil.DateTimeFromString (str);
126
AddProperty (Beagle.Property.NewDate ("exif:DateTime", dt));
127
} catch (ArgumentOutOfRangeException) {
128
Logger.Log.Debug("EXIF DateTime '{0}' is invalid.", str);
186
str = GetExifString (exif, Tiff.TagId.ExposureTime);
187
if (! String.IsNullOrEmpty (str))
188
AddProperty (Beagle.Property.NewUnsearched ("exif:ExposureTime", str + " sec."));
192
rational_val = GetExifRational (exif, Tiff.TagId.FNumber);
193
if (rational_val > 0)
194
AddProperty (Beagle.Property.NewUnsearched ("exif:FNumber", String.Format ("f/{0}", rational_val)));
196
rational_val = GetExifRational (exif, Tiff.TagId.ApertureValue);
197
if (rational_val > 0)
198
AddProperty (Beagle.Property.NewUnsearched ("exif:ApertureValue", rational_val));
200
rational_val = GetExifRational (exif, Tiff.TagId.FocalLength);
201
if (rational_val > 0)
202
AddProperty (Beagle.Property.NewUnsearched ("exif:FocalLength", String.Format ("{0} mm", rational_val)));
204
entry = exif.Lookup (Tiff.TagId.Flash);
206
ushort flash = entry.ShortValue [0];
207
AddProperty (Beagle.Property.NewUnsearched ("exif:Flash", GetFlashString (flash)));
134
211
private void AddXmpProperties (JpegHeader header)