public void Select(SemWeb.StatementSink sink) { foreach (Entry e in entries) { EntryType type = (EntryType)e.Type; switch (type) { case EntryType.IPTCNAA: System.IO.Stream iptcstream = new System.IO.MemoryStream(e.Data); FSpot.Iptc.IptcFile iptc = new FSpot.Iptc.IptcFile(iptcstream); iptc.Select(sink); break; case EntryType.XMP: System.IO.Stream xmpstream = new System.IO.MemoryStream(e.Data); FSpot.Xmp.XmpFile xmp = new FSpot.Xmp.XmpFile(xmpstream); xmp.Select(sink); break; default: break; } } }
private static FSpot.Xmp.XmpFile UpdateXmp(FSpot.IBrowsableItem item, FSpot.Xmp.XmpFile xmp) { if (xmp == null) { xmp = new FSpot.Xmp.XmpFile(); } Tag [] tags = item.Tags; string [] names = new string [tags.Length]; for (int i = 0; i < tags.Length; i++) { names [i] = tags [i].Name; } xmp.Store.Update("dc:subject", "rdf:Bag", names); if ((item as Photo).Rating > 0) { xmp.Store.Update("xmp:Rating", (item as Photo).Rating.ToString()); // FIXME - Should we also store/overwrite the Urgency field? // uint urgency_value = (item as Photo).Rating + 1; // Urgency valid values 1 - 8 // xmp.Store.Update ("photoshop:Urgency", urgency_value.ToString()); } else { xmp.Store.Delete("xmp:Rating"); } xmp.Dump(); return(xmp); }
private static FSpot.Xmp.XmpFile UpdateXmp (FSpot.IBrowsableItem item, FSpot.Xmp.XmpFile xmp) { if (xmp == null) xmp = new FSpot.Xmp.XmpFile (); Tag [] tags = item.Tags; string [] names = new string [tags.Length]; for (int i = 0; i < tags.Length; i++) names [i] = tags [i].Name; xmp.Store.Update ("dc:subject", "rdf:Bag", names); if ((item as Photo).Rating > 0) { xmp.Store.Update ("xmp:Rating", (item as Photo).Rating.ToString()); // FIXME - Should we also store/overwrite the Urgency field? // uint urgency_value = (item as Photo).Rating + 1; // Urgency valid values 1 - 8 // xmp.Store.Update ("photoshop:Urgency", urgency_value.ToString()); } else { xmp.Store.Delete ("xmp:Rating"); } xmp.Dump (); return xmp; }
public void Select (SemWeb.StatementSink sink) { foreach (Entry e in entries) { EntryType type = (EntryType) e.Type; switch (type) { case EntryType.IPTCNAA: System.IO.Stream iptcstream = new System.IO.MemoryStream (e.Data); FSpot.Iptc.IptcFile iptc = new FSpot.Iptc.IptcFile (iptcstream); iptc.Select (sink); break; case EntryType.XMP: System.IO.Stream xmpstream = new System.IO.MemoryStream (e.Data); FSpot.Xmp.XmpFile xmp = new FSpot.Xmp.XmpFile (xmpstream); xmp.Select (sink); break; default: break; } } }
public void SelectDirectory (ImageDirectory dir, StatementSink sink) { foreach (DirectoryEntry e in dir.Entries) { #if DEBUG_LOADER System.Console.WriteLine ("{0}", e.Id); #endif switch (e.Id) { case TagId.IPTCNAA: System.IO.Stream iptcstream = new System.IO.MemoryStream (e.RawData); FSpot.Iptc.IptcFile iptc = new FSpot.Iptc.IptcFile (iptcstream); iptc.Select (sink); break; case TagId.PhotoshopPrivate: System.IO.Stream bimstream = new System.IO.MemoryStream (e.RawData); FSpot.Bim.BimFile bim = new FSpot.Bim.BimFile (bimstream); bim.Select (sink); break; case TagId.XMP: System.IO.Stream xmpstream = new System.IO.MemoryStream (e.RawData); FSpot.Xmp.XmpFile xmp = new FSpot.Xmp.XmpFile (xmpstream); xmp.Select (sink); break; case TagId.ImageDescription: MetadataStore.AddLiteral (sink, "dc:description", "rdf:Alt", new Literal (e.ValueAsString [0], "x-default", null)); break; case TagId.UserComment: MetadataStore.AddLiteral (sink, "exif:UserComment", "rdf:Alt", new Literal (e.ValueAsString [0], "x-default", null)); break; case TagId.Copyright: MetadataStore.AddLiteral (sink, "dc:rights", "rdf:Alt", new Literal (e.ValueAsString [0], "x-default", null)); break; case TagId.Artist: MetadataStore.Add (sink, "dc:creator", "rdf:Seq", e.ValueAsString); break; case TagId.ExifIfdPointer: try { ImageDirectory sub = ((SubdirectoryEntry)e).Directory [0]; SelectDirectory (sub, sink); } catch (System.Exception exc) { System.Console.WriteLine (exc); } break; case TagId.Software: MetadataStore.AddLiteral (sink, "xmp:CreatorTool", e.ValueAsString [0]); break; case TagId.DateTime: try { MetadataStore.AddLiteral (sink, "xmp:ModifyDate", e.ValueAsDate.ToString ("yyyy-MM-ddThh:mm:ss")); } catch (System.Exception ex) { System.Console.WriteLine (String.Format ("error parsing {0}{2}{1}", e.ValueAsString[0], ex, Environment.NewLine)); } break; case TagId.DateTimeOriginal: case TagId.DateTimeDigitized: // FIXME subsectime needs to be included in these values // FIXME shouldn't DateTimeOriginal be xmp:CreateDate? the spec says no but wtf? try { MetadataStore.AddLiteral (sink, "exif:" + e.Id.ToString (), e.ValueAsDate.ToString ("yyyy-MM-ddThh:mm:ss")); } catch (System.Exception ex) { System.Console.WriteLine (String.Format ("error parsing {0}{2}{1}", e.ValueAsString[0], ex, Environment.NewLine)); } break; //case TagId.SpatialFrequencyResponse case TagId.ExifCFAPattern: CFAPattern pattern = new CFAPattern (e.RawData, e.IsLittle); Entity empty = new BNode (); Statement top = new Statement (MetadataStore.FSpotXMPBase, (Entity)MetadataStore.Namespaces.Resolve ("exif:" + e.Id.ToString ()), empty); Statement cols = new Statement (empty, (Entity) MetadataStore.Namespaces.Resolve ("exif:Columns"), new Literal (pattern.Columns.ToString (), null, null)); sink.Add (cols); Statement rows = new Statement (empty, (Entity) MetadataStore.Namespaces.Resolve ("exif:Rows"), new Literal (pattern.Rows.ToString (), null, null)); sink.Add (rows); string [] vals = e.ArrayToString (pattern.Values); MetadataStore.Add (sink, empty, "exif:Values", "rdf:Seq", vals); sink.Add (top); break; case TagId.ExifVersion: case TagId.FlashPixVersion: case TagId.ColorSpace: case TagId.CompressedBitsPerPixel: case TagId.PixelYDimension: case TagId.PixelXDimension: case TagId.RelatedSoundFile: case TagId.ExposureTime: case TagId.FNumber: case TagId.ExposureProgram: case TagId.SpectralSensitivity: case TagId.ShutterSpeedValue: case TagId.ApertureValue: case TagId.BrightnessValue: case TagId.ExposureBiasValue: case TagId.MaxApertureValue: case TagId.SubjectDistance: case TagId.MeteringMode: case TagId.LightSource: case TagId.FocalLength: case TagId.FlashEnergy: case TagId.FocalPlaneXResolution: case TagId.FocalPlaneYResolution: case TagId.FocalPlaneResolutionUnit: case TagId.ExposureIndex: case TagId.SensingMethod: case TagId.FileSource: case TagId.SceneType: case TagId.CustomRendered: case TagId.ExposureMode: case TagId.WhiteBalance: case TagId.DigitalZoomRatio: case TagId.FocalLengthIn35mmFilm: case TagId.SceneCaptureType: case TagId.GainControl: case TagId.Contrast: case TagId.Saturation: case TagId.Sharpness: MetadataStore.AddLiteral (sink, "exif:" + e.Id.ToString (), e.ValueAsString [0]); break; case TagId.ComponentsConfiguration: case TagId.ISOSpeedRatings: case TagId.SubjectArea: case TagId.SubjectLocation: MetadataStore.Add (sink, "exif:" + e.Id.ToString (), "rdf:Seq", e.ValueAsString); break; case TagId.TransferFunction: case TagId.YCbCrSubSampling: case TagId.WhitePoint: case TagId.PrimaryChromaticities: case TagId.YCbCrCoefficients: case TagId.ReferenceBlackWhite: case TagId.BitsPerSample: MetadataStore.Add (sink, "tiff:" + e.Id.ToString (), "rdf:Seq", e.ValueAsString); break; case TagId.Orientation: case TagId.Compression: case TagId.PhotometricInterpretation: case TagId.SamplesPerPixel: case TagId.PlanarConfiguration: case TagId.YCbCrPositioning: case TagId.ResolutionUnit: case TagId.ImageWidth: case TagId.ImageLength: case TagId.Model: case TagId.Make: MetadataStore.AddLiteral (sink, "tiff:" + e.Id.ToString (), e.ValueAsString [0]); break; } } }
private void Update() { Gtk.HTMLStream stream = this.Begin(null, "text/html; charset=utf-8", Gtk.HTMLBeginFlags.Scroll); string bg = Color(this.Style.Background(Gtk.StateType.Active)); string fg = Color(this.Style.Foreground(Gtk.StateType.Active)); string ig = Color(this.Style.Base(Gtk.StateType.Active)); stream.Write("<table width=100% cellpadding=5 cellspacing=0>"); bool empty = true; bool missing = false; System.Exception error = null; if (exif_info != null) { foreach (Exif.ExifContent content in exif_info.GetContents()) { Exif.ExifEntry [] entries = content.GetEntries(); if (entries.Length > 0) { empty = false; break; } } if (exif_info.Data.Length > 0) { stream.Write(String.Format("<tr><td colspan=2 align=\"center\" bgcolor=\"{0}\">" + "<img center src=\"exif:thumbnail\"></td></tr>", ig)); } int i = 0; foreach (Exif.ExifContent content in exif_info.GetContents()) { Exif.ExifEntry [] entries = content.GetEntries(); i++; if (entries.Length < 1) { continue; } stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Exif.ExifUtil.GetIfdNameExtended((Exif.Ifd)i - 1) + "</th><tr>"); foreach (Exif.ExifEntry entry in entries) { stream.Write("<tr><td valign=top align=right bgcolor=\"" + bg + "\"><small><font color=\"" + fg + "\">"); if (entry.Title != null) { stream.Write(entry.Title); } else { stream.Write("<Unknown Tag ID=" + entry.Tag.ToString() + ">"); } stream.Write("</font></small></td><td>"); string s = entry.Value; if (s != null && s != String.Empty) { stream.Write(s); } stream.Write("</td><tr>"); } } } if (photo != null) { MetadataStore store = new MetadataStore(); try { using (ImageFile img = ImageFile.Create(photo.DefaultVersionUri)) { if (img is SemWeb.StatementSource) { StatementSource source = (StatementSource)img; source.Select(store); } } } catch (System.IO.FileNotFoundException) { missing = true; } catch (System.Exception e) { // Sometimes we don't get the right exception, check for the file if (!System.IO.File.Exists(photo.DefaultVersionUri.LocalPath)) { missing = true; } else { // if the file is there but we still got an exception display it. error = e; } } if (store.StatementCount > 0) { #if false using (System.IO.Stream xmpstream = System.IO.File.OpenWrite("tmp.xmp")) { xmpstream.Length = 0; FSpot.Xmp.XmpFile file; file = new FSpot.Xmp.XmpFile(); store.Select(file); file.Save(xmpstream); } #endif empty = false; stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString("Extended Metadata") + "</th></tr>"); foreach (Statement stmt in store) { // Skip anonymous subjects because they are // probably part of a collection if (stmt.Subject.Uri == null && store.SelectSubjects(null, stmt.Subject).Length > 0) { continue; } string title; string value; Description.GetDescription(store, stmt, out title, out value); stream.Write("<tr><td valign=top align=right bgcolor=\"" + bg + "\"><small><font color=\"" + fg + "\">"); stream.Write(title); stream.Write("</font></small></td><td width=100%>"); if (value != null) { value = Escape(value); } else { MemoryStore substore = store.Select(new Statement((Entity)stmt.Object, null, null, null)).Load(); WriteCollection(substore, stream); } if (value != null && value != String.Empty) { stream.Write(value); } stream.Write("</td></tr>"); } } if (Core.Database != null && photo is Photo) { stream.Write("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString("Exported Locations") + "</th></tr>"); Photo p = photo as Photo; foreach (ExportItem export in Core.Database.Exports.GetByImageId(p.Id, p.DefaultVersionId)) { string url = GetExportUrl(export); string label = GetExportLabel(export); if (url == null || label == null) { continue; } stream.Write("<tr colspan=2><td width=100%>"); stream.Write(String.Format("<a href=\"{0}\">{1}</a>", url, label)); stream.Write("</font></small></td></tr>"); } } } if (empty) { string msg; if (photo == null) { // FIXME we should pass the full selection to the info display and let it // handle multiple items however it wants. msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, Catalog.GetString("No active photo")); } else if (missing) { string text = String.Format(Catalog.GetString("The photo \"{0}\" does not exist"), photo.DefaultVersionUri); msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, text); } else { msg = String.Format("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, Catalog.GetString("No metadata available")); if (error != null) { String.Format("<pre>{0}</pre>", error); } } stream.Write(msg); } stream.Write("</table>"); End(stream, Gtk.HTMLStreamStatus.Ok); }
private void Update () { Gtk.HTMLStream stream = this.Begin (null, "text/html; charset=utf-8", Gtk.HTMLBeginFlags.Scroll); string bg = Color (this.Style.Background (Gtk.StateType.Active)); string fg = Color (this.Style.Foreground (Gtk.StateType.Active)); string ig = Color (this.Style.Base (Gtk.StateType.Active)); stream.Write ("<table width=100% cellpadding=5 cellspacing=0>"); bool empty = true; bool missing = false; System.Exception error = null; if (exif_info != null) { foreach (Exif.ExifContent content in exif_info.GetContents ()) { Exif.ExifEntry [] entries = content.GetEntries (); if (entries.Length > 0) { empty = false; break; } } if (exif_info.Data.Length > 0) stream.Write (String.Format ("<tr><td colspan=2 align=\"center\" bgcolor=\"{0}\">" + "<img center src=\"exif:thumbnail\"></td></tr>", ig)); int i = 0; foreach (Exif.ExifContent content in exif_info.GetContents ()) { Exif.ExifEntry [] entries = content.GetEntries (); i++; if (entries.Length < 1) continue; stream.Write ("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Exif.ExifUtil.GetIfdNameExtended ((Exif.Ifd)i - 1) + "</th><tr>"); foreach (Exif.ExifEntry entry in entries) { stream.Write ("<tr><td valign=top align=right bgcolor=\""+ bg + "\"><small><font color=\"" + fg + "\">"); if (entry.Title != null) stream.Write (entry.Title); else stream.Write ("<Unknown Tag ID=" + entry.Tag.ToString () + ">"); stream.Write ("</font></small></td><td>"); string s = entry.Value; if (s != null && s != String.Empty) stream.Write (s); stream.Write ("</td><tr>"); } } } if (photo != null) { MetadataStore store = new MetadataStore (); try { using (ImageFile img = ImageFile.Create (photo.DefaultVersionUri)) { if (img is SemWeb.StatementSource) { StatementSource source = (StatementSource)img; source.Select (store); } } } catch (System.IO.FileNotFoundException) { missing = true; } catch (System.Exception e){ // Sometimes we don't get the right exception, check for the file if (!System.IO.File.Exists (photo.DefaultVersionUri.LocalPath)) { missing = true; } else { // if the file is there but we still got an exception display it. error = e; } } if (store.StatementCount > 0) { #if false using (System.IO.Stream xmpstream = System.IO.File.OpenWrite ("tmp.xmp")) { xmpstream.Length = 0; FSpot.Xmp.XmpFile file; file = new FSpot.Xmp.XmpFile (); store.Select (file); file.Save (xmpstream); } #endif empty = false; stream.Write ("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString ("Extended Metadata") + "</th></tr>"); foreach (Statement stmt in store) { // Skip anonymous subjects because they are // probably part of a collection if (stmt.Subject.Uri == null && store.SelectSubjects (null, stmt.Subject).Length > 0) continue; string title; string value; Description.GetDescription (store, stmt, out title, out value); stream.Write ("<tr><td valign=top align=right bgcolor=\""+ bg + "\"><small><font color=\"" + fg + "\">"); stream.Write (title); stream.Write ("</font></small></td><td width=100%>"); if (value != null) value = Escape (value); else { MemoryStore substore = store.Select (new Statement ((Entity)stmt.Object, null, null, null)).Load(); WriteCollection (substore, stream); } if (value != null && value != String.Empty) stream.Write (value); stream.Write ("</td></tr>"); } } if (Core.Database != null && photo is Photo) { stream.Write ("<tr><th align=left bgcolor=\"" + ig + "\" colspan=2>" + Catalog.GetString ("Exported Locations") + "</th></tr>"); Photo p = photo as Photo; foreach (ExportItem export in Core.Database.Exports.GetByImageId (p.Id, p.DefaultVersionId)) { string url = GetExportUrl (export); string label = GetExportLabel (export); if (url == null || label == null) continue; stream.Write ("<tr colspan=2><td width=100%>"); stream.Write (String.Format ("<a href=\"{0}\">{1}</a>", url, label)); stream.Write ("</font></small></td></tr>"); } } } if (empty) { string msg; if (photo == null) { // FIXME we should pass the full selection to the info display and let it // handle multiple items however it wants. msg = String.Format ("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, Catalog.GetString ("No active photo")); } else if (missing) { string text = String.Format (Catalog.GetString ("The photo \"{0}\" does not exist"), photo.DefaultVersionUri); msg = String.Format ("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, text); } else { msg = String.Format ("<tr><td valign=top align=center bgcolor=\"{0}\">" + "<b>{1}</b></td></tr>", ig, Catalog.GetString ("No metadata available")); if (error != null) { String.Format ("<pre>{0}</pre>", error); } } stream.Write (msg); } stream.Write ("</table>"); End (stream, Gtk.HTMLStreamStatus.Ok); }