Beispiel #1
0
        static void Main(string [] args)
        {
            XmpFile xmp = new XmpFile(System.IO.File.OpenRead(args [0]));

            //xmp.Store.Dump ();
#if false
            System.IO.StreamReader stream = new System.IO.StreamReader(System.IO.File.OpenRead(args [0]));

            while (stream.BaseStream.Position < stream.BaseStream.Length)
            {
                //System.Console.WriteLine (stream.ReadLine ());
            }
#endif
        }
        public bool Import(Photo photo, string path, string orig_path)
        {
            XmpFile xmp;

            string source_sidecar = String.Format("{0}{1}{2}.xmp",
                                                  Path.GetDirectoryName(orig_path),
                                                  Path.DirectorySeparatorChar,
                                                  Path.GetFileName(orig_path));

            string dest_sidecar = String.Format("{0}{1}{2}.xmp",
                                                Path.GetDirectoryName(path),
                                                Path.DirectorySeparatorChar,
                                                Path.GetFileName(path));

            if (File.Exists(source_sidecar))
            {
                xmp = new XmpFile(File.OpenRead(source_sidecar));
            }
            else if (File.Exists(dest_sidecar))
            {
                xmp = new XmpFile(File.OpenRead(dest_sidecar));
            }
            else
            {
                xmp = new XmpFile();
            }

            using (ImageFile img = ImageFile.Create(path)) {
                StatementSource source = img as StatementSource;
                if (source != null)
                {
                    try {
                        source.Select(xmp);
                    } catch  {
                    }
                }
            }

            ProcessStore(xmp.Store, photo);
#if enable_debug
            xmp.Save(Console.OpenStandardOutput());
#endif
            return(true);
        }
Beispiel #3
0
    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);
        xmp.Dump();

        return(xmp);
    }
Beispiel #4
0
	public void SetXmp (XmpFile xmp)
	{
		using (MemoryStream stream = new MemoryStream ()) {
			
			XmpSignature.WriteName (stream);
			xmp.Save (stream);
			
			Marker xmp_marker = new Marker (XmpSignature.Id, stream.ToArray ());
			Replace (XmpSignature, xmp_marker);
		}
	}
Beispiel #5
0
	public XmpFile GetXmp ()
	{
		string name = XmpSignature.Name;
		Marker marker = FindMarker (XmpSignature);
		if (marker != null) {
			int len = name.Length;
			//System.Console.WriteLine (System.Text.Encoding.ASCII.GetString (marker.Data, len, 
			//								marker.Data.Length - len));
			using (System.IO.Stream xmpstream = new System.IO.MemoryStream (marker.Data, len, 
											marker.Data.Length - len, false)) {
			
				XmpFile xmp = new XmpFile (xmpstream);					
				return xmp;
			}
		}
		return null;
	}
Beispiel #6
0
		protected override void DoPullProperties ()
		{
			// create new external process
			pc = new SafeProcess ();
			pc.Arguments = new string [] { "pdfinfo", "-meta", FileInfo.FullName };
			pc.RedirectStandardOutput = true;
			// See FIXME below for why this is false.
			pc.RedirectStandardError = false;

			// Let pdfinfo run for at most 10 CPU seconds, and not
			// use more than 100 megs memory.
			pc.CpuLimit = 90;
			pc.MemLimit = 100*1024*1024;
			pc.UseLangC = true;

			try {
				pc.Start ();
			} catch (SafeProcessException e) {
				Log.Warn (e.Message);
				Error ();
				return;
			}

			// add pdfinfo's output to pool
			pout = new StreamReader (pc.StandardOutput);
			string str = null;
			int idx = -1;
			string strMetaTag = null;
			bool bKeyword = false;
			string prop = null;
			string val = null;

			while ((str = pout.ReadLine ()) != null) {
				bKeyword = false;
				strMetaTag = null;
				idx = str.IndexOf (':');
				if (idx > 0) {
					prop = str.Substring (0, idx);
					val = str.Substring (idx + 1);
					switch (prop) {
					case "Title":
						strMetaTag = "dc:title";
						break;
					case "Author":
						strMetaTag = "dc:author";
						break;
					case "Pages":
						strMetaTag = "fixme:page-count";
						bKeyword = true;
						break;
					case "Creator":
						strMetaTag = "dc:creator";
						break;
					case "Keywords":
						strMetaTag = "dc:keyword";
						break;
					case "Producer":
						strMetaTag = "dc:appname";
						break;
					case "Metadata":
						string xmpString = pout.ReadToEnd();
						XmpFile xmp = new XmpFile (new MemoryStream(System.Text.Encoding.ASCII.GetBytes(xmpString)));
						AddXmpProperties(xmp);
						break;
					}
					if (strMetaTag != null) {
						if (bKeyword)
							AddProperty (Beagle.Property.NewUnsearched (strMetaTag, 
												 val.Trim ()));
						else
							AddProperty (Beagle.Property.New (strMetaTag, 
											  val.Trim ()));
					}
						
				}
			}
			pout.Close ();

#if false
			// Log any errors or warnings from stderr
			pout = new StreamReader (pc.StandardError);
			while ((str = pout.ReadLine ()) != null)
				Log.Warn ("pdfinfo [{0}]: {1}", Indexable.Uri, str);

			pout.Close ();
#endif
			pc.Close ();
		}
Beispiel #7
0
		private void AddXmpProperties (XmpFile xmp)
		{
			Resource subject_anon = null;
			Resource creator_anon = null;
			Resource rights_anon = null;
			Resource title_anon = null;

			foreach (Statement stmt in (IEnumerable)xmp.Store) {
				if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:subject")) {
					//Console.WriteLine ("found subject");
					subject_anon = stmt.Object;
				} else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:creator")) {
					//Console.WriteLine ("found creator");
					creator_anon = stmt.Object;
				} else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:rights")) {
					rights_anon = stmt.Object;
				} else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("dc:title")) {
					if (stmt.Object is Literal)
						AddProperty (Beagle.Property.New ("dc:title", ((Literal)stmt.Object).Value));
					else if (stmt.Object is BNode)
						title_anon = stmt.Object;
				} else if (stmt.Predicate == MetadataStore.Namespaces.Resolve ("cc:license")) {
					AddProperty (Beagle.Property.NewKeyword ("fixme:license", ((Literal)stmt.Object).Value));
				}
			}
			
			foreach (Statement stmt in (IEnumerable)xmp.Store) {
				if (stmt.Subject == subject_anon && 
				    stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
					AddProperty (Beagle.Property.New ("dc:subject", ((Literal)stmt.Object).Value));
				} else if (stmt.Subject == creator_anon &&  
					   stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
					AddProperty (Beagle.Property.New ("dc:creator", ((Literal)stmt.Object).Value));
				} else if (stmt.Subject == rights_anon &&  
					   stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
					AddProperty (Beagle.Property.New ("dc:rights", ((Literal)stmt.Object).Value));
				} else if (stmt.Subject == title_anon &&
					   stmt.Predicate != MetadataStore.Namespaces.Resolve ("rdf:type")) {
					AddProperty (Beagle.Property.New ("dc:title", ((Literal)stmt.Object).Value));
				}
			}
		}
Beispiel #8
0
		internal static void AddTiffDirectoryProperties (FilterTiff filter, ImageDirectory directory)
		{
			foreach (DirectoryEntry e in directory.Entries) {
				switch (e.Id) {
				case TagId.ImageDescription:
					filter.AddProperty (Beagle.Property.New ("exif:ImageDescription", e.ValueAsString [0]));
					break;
				case TagId.Model:
					filter.AddProperty (Beagle.Property.New ("exif:Model", e.ValueAsString [0]));
					break;
				case TagId.UserComment:
					filter.AddProperty (Beagle.Property.New ("exif:UserComment", e.ValueAsString [0]));
					break;
				case TagId.DateTimeOriginal:
					AddDateProperty (filter, "exif:DateTimeOriginal", e.ValueAsString [0]);
					break;
				case TagId.DateTimeDigitized:
					AddDateProperty (filter, "exif:DateTimeDigitized", e.ValueAsString [0]);
					break;
				case TagId.DateTime:
					AddDateProperty (filter, "exif:DateTime", e.ValueAsString [0]);
					break;
				case TagId.PixelXDimension:
					filter.Width = (int) e.ValueAsLong [0];
					//filter.AddProperty (Beagle.Property.NewUnsearched ("exif:PixelXDimension", e.ValueAsString [0]));
					break;
				case TagId.PixelYDimension:
					filter.Height = (int) e.ValueAsLong [0];
					//filter.AddProperty (Beagle.Property.NewUnsearched ("exif:PixelYDimension", e.ValueAsString [0]));
					break;
				case TagId.ImageWidth:
					uint wval = e.ValueAsLong [0];
					if (filter.Width < wval)
						filter.Width = (int) wval;
					break;
				case TagId.ImageLength:
					uint hval = e.ValueAsLong [0];
					if (filter.Height < hval)
						filter.Height = (int) hval;
					break;
				case TagId.ExposureTime:
					filter.AddProperty (Beagle.Property.NewUnsearched ("exif:ExposureTime", e.ValueAsString [0]));
					break;
				case TagId.ISOSpeedRatings:
					filter.AddProperty (Beagle.Property.NewUnsearched ("exif:ISOSpeedRatings", e.ValueAsString [0]));
					break;
				case TagId.FNumber:
					filter.AddProperty (Beagle.Property.NewUnsearched ("exif:FNumber", Math.Round ((e.RationalValue [0]).Value, 1)));
					break;
				case TagId.FocalLength:
					filter.AddProperty (Beagle.Property.NewUnsearched ("exif:FocalLength", e.ValueAsString [0]));
					break;
				case TagId.Flash:
					ushort flash_val = e.ShortValue [0];
					filter.AddProperty (Beagle.Property.NewBool ("exif:Flash", (flash_val & 0x1) == 0x1));
					break;
				case TagId.XMP:
					XmpFile xmp = new XmpFile (new System.IO.MemoryStream (e.RawData));
					filter.AddXmpProperties (xmp);
					break;
				}
			}
		}
Beispiel #9
0
		private void ExtractTextProperty (PngFile.TextChunk tchunk)
		{
			switch (tchunk.Keyword) {
			case "Title":
				AddProperty (Beagle.Property.New ("dc:title", tchunk.Text));
				break;
			case "Author":
				AddProperty (Beagle.Property.New ("dc:creator", tchunk.Text));
				break;
			case "Copyright":
				AddProperty (Beagle.Property.New ("dc:rights", tchunk.Text));
				break;
			case "Description":
				AddProperty (Beagle.Property.New ("png:description", tchunk.Text));
				break;
			case "Comment":
				AddProperty (Beagle.Property.New ("png:comment", tchunk.Text));
				break;
			case "XMP":
			case "XML:com.adobe.xmp":
				XmpFile xmp = new XmpFile (new MemoryStream (tchunk.TextData));
				AddXmpProperties (xmp);
				break;
			case "Disclaimer":
			case "Warning":
			case "Source":
			case "Creation Time":
			case "Software":
				break;
			}
		}
Beispiel #10
0
        public bool Import(Photo photo, string path, string orig_path)
        {
            XmpFile xmp;

            string source_sidecar = String.Format ("{0}{1}{2}.xmp",
                                   Path.GetDirectoryName (orig_path),
                                   Path.DirectorySeparatorChar,
                                   Path.GetFileName (orig_path));

            string dest_sidecar = String.Format ("{0}{1}{2}.xmp",
                                   Path.GetDirectoryName (path),
                                   Path.DirectorySeparatorChar,
                                   Path.GetFileName (path));

            if (File.Exists (source_sidecar)) {
                xmp = new XmpFile (File.OpenRead (source_sidecar));
            } else if (File.Exists (dest_sidecar)) {
                xmp = new XmpFile (File.OpenRead (dest_sidecar));
            } else {
                xmp = new XmpFile ();
            }

            using (ImageFile img = ImageFile.Create (path)) {
                StatementSource source = img as StatementSource;
                if (source != null) {
                    try {
                        source.Select (xmp);
                    } catch  {
                    }
                }
            }

            ProcessStore (xmp.Store, photo);
            #if enable_debug
            xmp.Save (Console.OpenStandardOutput ());
            #endif
            return true;
        }
Beispiel #11
0
        public void SetXmp(XmpFile xmp)
        {
            TextChunk text = null;

            text = Header.LookupTextChunk ("XML:com.adobe.xmp");
            if (text != null)
                Chunks.Remove (text);

            text = Header.LookupTextChunk ("XMP");
            if (text != null)
                Chunks.Remove (text);

            ItxtChunk itext = new ItxtChunk ("XML:com.adobe.xmp", "en", false);
            using (MemoryStream stream = new MemoryStream ()) {
                xmp.Save (stream);
                itext.SetText (stream.ToArray ());
            }
            Header.Insert (itext);
        }
Beispiel #12
0
        /**
           Title 	Short (one line) title or caption for image
           Author 	Name of image's creator
           Description 	Description of image (possibly long)
           Copyright 	Copyright notice
           Creation Time 	Time of original image creation
           Software 	Software used to create the image
           Disclaimer 	Legal disclaimer
           Warning 	Warning of nature of content
           Source 	Device used to create the image
           Comment 	Miscellaneous comment

           xmp is XML:com.adobe.xmp

           Other keywords may be defined for other purposes. Keywords of general interest can be registered with th
        */
        public void Select(SemWeb.StatementSink sink)
        {
            foreach (Chunk c in Chunks) {
                if (c is IhdrChunk) {
                    IhdrChunk ih = c as IhdrChunk;
                    MetadataStore.AddLiteral (sink, "tiff:ImageWidth", ih.Width.ToString ());
                    MetadataStore.AddLiteral (sink, "tiff:ImageLength", ih.Height.ToString ());
                } else if(c is TimeChunk) {
                    TimeChunk tc = c as TimeChunk;

                    MetadataStore.AddLiteral (sink, "xmp:ModifyDate", tc.Time.ToString ("yyyy-MM-ddThh:mm:ss"));
                } else if (c is TextChunk) {
                    TextChunk text = c as TextChunk;

                    switch (text.Keyword) {
                    case "XMP":
                    case "XML:com.adobe.xmp":
                        using (System.IO.Stream xmpstream = new System.IO.MemoryStream (text.TextData)) {
                            FSpot.Xmp.XmpFile xmp = new FSpot.Xmp.XmpFile (xmpstream);
                            xmp.Select (sink);
                        }
                        break;
                    case "Comment":
                        MetadataStore.AddLiteral (sink, "exif:UserComment", text.Text);
                        break;
                    case "Software":
                        MetadataStore.AddLiteral (sink, "xmp:CreatorTool", text.Text);
                        break;
                    case "Title":
                        MetadataStore.AddLiteral (sink, "dc:title", "rdf:Alt", new SemWeb.Literal (text.Text, "x-default", null));
                        break;
                    case "Author":
                        MetadataStore.AddLiteral (sink, "dc:creator", "rdf:Seq", new SemWeb.Literal (text.Text));
                        break;
                    case "Copyright":
                        MetadataStore.AddLiteral (sink, "dc:rights", "rdf:Alt", new SemWeb.Literal (text.Text, "x-default", null));
                        break;
                    case "Description":
                        MetadataStore.AddLiteral (sink, "dc:description", "rdf:Alt", new SemWeb.Literal (text.Text, "x-default", null));
                        break;
                    case "Creation Time":
                        try {
                            System.DateTime time = System.DateTime.Parse (text.Text);
                            MetadataStore.AddLiteral (sink, "xmp:CreateDate", time.ToString ("yyyy-MM-ddThh:mm:ss"));
                        } catch (System.Exception e) {
                            System.Console.WriteLine (e.ToString ());
                        }
                        break;
                    }
                } else if (c is ColorChunk) {
                    ColorChunk color = (ColorChunk)c;
                    string [] whitepoint = new string [2];
                    whitepoint [0] = color.WhiteX.ToString ();
                    whitepoint [1] = color.WhiteY.ToString ();
                    MetadataStore.Add (sink, "tiff:WhitePoint", "rdf:Seq", whitepoint);
                    int i = 0;
                    string [] rgb = new string [6];
                    rgb [i++] = color.RedX.ToString ();
                    rgb [i++] = color.RedY.ToString ();
                    rgb [i++] = color.GreenX.ToString ();
                    rgb [i++] = color.GreenY.ToString ();
                    rgb [i++] = color.BlueX.ToString ();
                    rgb [i++] = color.BlueY.ToString ();
                    MetadataStore.Add (sink, "tiff:PrimaryChromaticities", "rdf:Seq", rgb);
                } else if (c.Name == "sRGB") {
                    MetadataStore.AddLiteral (sink, "exif:ColorSpace", "1");
                } else if (c is PhysChunk) {
                    PhysChunk phys = (PhysChunk)c;
                    uint denominator = (uint) (phys.InMeters ? 100 : 1);

                    MetadataStore.AddLiteral (sink, "tiff:ResolutionUnit", phys.InMeters ? "3" : "1");
                    MetadataStore.AddLiteral (sink, "tiff:XResolution", new FSpot.Tiff.Rational (phys.PixelsPerUnitX, denominator).ToString ());
                    MetadataStore.AddLiteral (sink, "tiff:YResolution", new FSpot.Tiff.Rational (phys.PixelsPerUnitY, denominator).ToString ());
                }
            }
        }
Beispiel #13
0
		static void Main (string [] args)
		{
			XmpFile xmp = new XmpFile (System.IO.File.OpenRead (args [0]));
			//xmp.Store.Dump ();
#if false
			System.IO.StreamReader stream = new System.IO.StreamReader (System.IO.File.OpenRead (args [0]));

			while (stream.BaseStream.Position < stream.BaseStream.Length) {
				//System.Console.WriteLine (stream.ReadLine ());
			}
#endif
		}
Beispiel #14
0
		public override void Select (SemWeb.StatementSink sink)
		{
			
			/* this is just a sanity pass, if the first ifd is not a subfile use the normal
			 * tiff path 
			 */
			DirectoryEntry e = Header.Directory.Lookup (TagId.NewSubfileType);
			if (e == null) {
				base.Select (sink);
				return;
			}

			/*
			 * Even though Ifd0 doesn't have the full resolution image
			 * it would have the XMP data so we look for it
			 */
			e = Header.Directory.Lookup (TagId.XMP);
			if (e != null) {
				System.IO.Stream xmpstream = new System.IO.MemoryStream (e.RawData);
				FSpot.Xmp.XmpFile xmp = new FSpot.Xmp.XmpFile (xmpstream);
				xmp.Select (sink);
			}

			/* 
			 * Ifd0 will also have the exif directory
			 */
			ImageDirectory dir = Header.Directory;
			SubdirectoryEntry sub = (SubdirectoryEntry) dir.Lookup (TagId.ExifIfdPointer);
			if (sub != null)
				Header.SelectDirectory (sub.Directory [0], sink);
			
			/*
			 * now we lookup subifd0 (we should probably scan the newsubfile types here)
			 * and load the metadata we are interested in from it.
			 */
			sub = (SubdirectoryEntry) Header.Directory.Lookup (TagId.SubIFDs);	

			int i = 0;
			do {
				uint dirtype = e.ValueAsLong [0];
				if (dirtype == 0) {
					Header.SelectDirectory (dir, sink);
					break;
				}
					
				if (sub == null)
					break;

				dir = sub.Directory [i];
				e = dir.Lookup (TagId.NewSubfileType);
				i++;
			} while (i < sub.Directory.Length);

			
		}
		public void SetXmp (XmpFile xmp)
		{
			this.xmp = xmp;
		}
Beispiel #16
0
		public void Dump ()
		{
#if enable_debug
			XmpFile xmp = new XmpFile ();
			xmp.Store = this;
			xmp.Save (System.Console.OpenStandardOutput ());
#endif
		}
	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);
		xmp.Dump ();

		return xmp;
	}