Dont throw EncodingFoundException unless asked to. Should remove the occassional...
[beagle.git] / Filters / FilterImage.cs
blobd089706c8f96b7c15a4799c23b3a7338af273f15
1 //
2 // FilterImage.cs
3 //
4 // Copyright (C) 2004 Novell, Inc.
5 //
7 //
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.
27 using System;
28 using System.Collections;
29 using System.IO;
30 using System.Text;
32 using Beagle.Util;
33 using SemWeb;
35 namespace Beagle.Filters {
37 [PropertyKeywordMapping (Keyword="imagetag", PropertyName="image:tag", IsKeyword=false, Description="FSpot, Digikam image tags")]
38 [PropertyKeywordMapping (Keyword="comment", PropertyName="fixme:comment", IsKeyword=false, Description="User comments")]
39 public abstract class FilterImage : Beagle.Daemon.Filter {
41 public FilterImage ()
43 // 1: Base
44 // 2: Added fspot:IsIndexed field, added width & height properties
45 // 3: Add Digikam tags and caption
46 SetVersion (3);
49 protected virtual void PullImageProperties () { }
51 private int width = -1;
52 private int height = -1;
53 private int depth = -1;
55 protected int Width {
56 set { width = value; }
57 get { return width; }
60 protected int Height {
61 set { height = value; }
62 get { return height; }
65 protected int Depth {
66 set { depth = value; }
67 get { return depth; }
70 protected override void DoPullProperties ()
72 PullImageProperties ();
74 if (width > 0)
75 AddProperty (Beagle.Property.NewUnsearched ("fixme:width", width));
77 if (height > 0)
78 AddProperty (Beagle.Property.NewUnsearched ("fixme:height", height));
80 if (depth > 0)
81 AddProperty (Beagle.Property.NewUnsearched ("fixme:depth", depth));
83 try {
84 AddFSpotInformation (this.FileInfo.FullName);
85 AddDigikamInformation (this.FileInfo.FullName);
86 } catch (Exception ex) {
87 Logger.Log.Error ("Exception trying to retrieve FSpot/Digikam information:" + ex);
93 private void AddFSpotInformation (string path)
95 FSpotTools.Photo photo = FSpotTools.GetPhoto (this.FileInfo.FullName);
97 if (photo == null)
98 return;
100 AddProperty (Beagle.Property.NewBool ("fspot:IsIndexed", true));
102 if (photo.Description != null && photo.Description != "") {
103 AddProperty (Beagle.Property.New ("fspot:Description", photo.Description));
104 AddProperty (Beagle.Property.NewUnstored ("fixme:comment", photo.Description));
107 foreach (FSpotTools.Tag tag in photo.Tags) {
108 if (tag.Name != null && tag.Name != "") {
109 AddProperty (Beagle.Property.New ("fspot:Tag", tag.Name));
110 AddProperty (Beagle.Property.NewUnstored ("image:tag", tag.Name));
115 private void AddDigikamInformation (string path)
117 DigikamTags.DigikamData digikam_data = DigikamTags.GetDigikamData (this.FileInfo.FullName);
119 if (digikam_data == null)
120 return;
122 AddProperty (Beagle.Property.NewBool ("digikam:IsIndexed", true));
124 if (digikam_data.caption != null && digikam_data.caption != "") {
125 AddProperty (Beagle.Property.New ("digikam:caption", digikam_data.caption));
126 AddProperty (Beagle.Property.NewUnstored ("fixme:comment", digikam_data.caption));
129 foreach (string tag in digikam_data.Tags) {
130 AddProperty (Beagle.Property.New ("digikam:Tag", tag));
131 AddProperty (Beagle.Property.NewUnstored ("image:tag", tag));
135 internal void AddXmpProperties (XmpFile xmp)
137 Resource subject_anon = null;
138 Resource creator_anon = null;
139 Resource rights_anon = null;
141 foreach (Statement stmt in xmp.Store) {
142 if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:subject")) {
143 //Console.WriteLine ("found subject");
144 subject_anon = stmt.Object;
145 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:creator")) {
146 //Console.WriteLine ("found creator");
147 creator_anon = stmt.Object;
148 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:rights")) {
149 rights_anon = stmt.Object;
150 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:title")) {
151 AddProperty (Beagle.Property.New ("dc:title", ((Literal)stmt.Object).Value));
152 } else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("tiff:Model")) {
153 // NOTE: the namespaces for xmp and beagle don't always match up
154 AddProperty (Beagle.Property.New ("exif:Model", ((Literal)stmt.Object).Value));
158 foreach (Statement stmt in xmp.Store) {
159 if (stmt.Subject == subject_anon &&
160 stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
161 AddProperty (Beagle.Property.New ("dc:subject", ((Literal)stmt.Object).Value));
162 } else if (stmt.Subject == creator_anon &&
163 stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
164 AddProperty (Beagle.Property.New ("dc:creator", ((Literal)stmt.Object).Value));
165 } else if (stmt.Subject == rights_anon &&
166 stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
167 AddProperty (Beagle.Property.New ("dc:rights", ((Literal)stmt.Object).Value));