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);

			
		}
Exemple #2
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 ());
                }
            }
        }