Ejemplo n.º 1
0
        public void Load()
        {
            string path = CreateFile();

            using (Stream stream = File.OpenRead(path)) {
                JpegHeader jhead = new JpegHeader(stream);

                Assert.AreEqual(((Marker)jhead.Markers [0]).Type, JpegMarker.Soi);
                Assert.AreEqual(((Marker)jhead.Markers [1]).GetName(), "JFIF");
                Assert.AreEqual(((Marker)jhead.Markers [1]).Type, JpegMarker.App0);
                Assert.AreEqual(((Marker)jhead.Markers [2]).GetName(), "Exif");
                Assert.AreEqual(((Marker)jhead.Markers [2]).Type, JpegMarker.App1);

                // NOTE the currently we don't store the Eoi as the last marker
                Assert.AreEqual(((Marker)jhead.Markers [jhead.Markers.Count - 1]).Type, JpegMarker.Sos);

                // NOTE this is kind of sill but it might help
                Assert.IsTrue(Math.Abs(jhead.GuessQuality() - quality) <= 1);

                Assert.IsNotNull(jhead.GetExifHeader());
            }

            File.Delete(path);
        }
Ejemplo n.º 2
0
        private void AddExifProperties(JpegHeader header)
        {
            Tiff.Header ifd = header.GetExifHeader();
            if (ifd == null)
            {
                return;
            }
            //ifd.Dump ("foo"); // Uncomment to debug

            string str;

            Tiff.DirectoryEntry entry;

            // Add IFD 0 properies

            str = GetExifString(ifd.Directory, Tiff.TagId.Model);
            AddProperty(Beagle.Property.New("exif:Model", str));

            str = GetExifString(ifd.Directory, Tiff.TagId.ImageDescription);
            AddProperty(Beagle.Property.New("exif:ImageDescription", str));

            try {
                entry = ifd.Directory.Lookup(Tiff.TagId.DateTime);
                if (entry != null)
                {
                    // Assume datetime stored in the images are local times
                    AddProperty(Beagle.Property.NewDate("exif:DateTime", entry.ValueAsDate.ToUniversalTime()));
                }
            } catch (FormatException) {
                Logger.Log.Debug("EXIF DateTime '{0}' is invalid.", GetExifString(ifd.Directory, Tiff.TagId.DateTime));
            } catch (ArgumentOutOfRangeException) {
                Logger.Log.Debug("EXIF DateTime '{0}' is invalid.", GetExifString(ifd.Directory, Tiff.TagId.DateTime));
            }

            str = GetExifString(ifd.Directory, Tiff.TagId.Copyright);
            AddProperty(Beagle.Property.New("dc:rights", str));

            // Add IFD 1 properties

            Tiff.SubdirectoryEntry subdir = (Tiff.SubdirectoryEntry)ifd.Directory.Lookup(Tiff.TagId.ExifIfdPointer);
            if (subdir == null)
            {
                return;
            }

            Tiff.ImageDirectory exif = subdir.Directory [0];
            if (exif == null)
            {
                return;
            }

            entry = exif.Lookup(Tiff.TagId.UserComment);
            if (entry != null)
            {
                AddProperty(Beagle.Property.New("exif:UserComment", entry.UserCommentValue));
            }

            uint val = 0;

            entry = exif.Lookup(Tiff.TagId.PixelXDimension);
            if (entry != null)
            {
                val = entry.ValueAsLong [0];
            }
            if (val > 0)
            {
                Width = (int)val;
                AddProperty(Beagle.Property.NewUnsearched("exif:PixelXDimension", val));
            }

            val   = 0;
            entry = exif.Lookup(Tiff.TagId.PixelYDimension);
            if (entry != null)
            {
                val = entry.ValueAsLong [0];
            }
            if (val > 0)
            {
                Height = (int)val;
                AddProperty(Beagle.Property.NewUnsearched("exif:PixelYDimension", val));
            }

            str = GetExifString(exif, Tiff.TagId.ISOSpeedRatings);
            AddProperty(Beagle.Property.NewUnsearched("exif:ISOSpeedRatings", str));

            str = GetExifString(exif, Tiff.TagId.ShutterSpeedValue);
            AddProperty(Beagle.Property.NewUnsearched("exif:ShutterSpeedValue", str));

            str = GetExifString(exif, Tiff.TagId.ExposureTime);
            if (!String.IsNullOrEmpty(str))
            {
                AddProperty(Beagle.Property.NewUnsearched("exif:ExposureTime", str + " sec."));
            }

            double rational_val;

            rational_val = GetExifRational(exif, Tiff.TagId.FNumber);
            if (rational_val > 0)
            {
                AddProperty(Beagle.Property.NewUnsearched("exif:FNumber", String.Format("f/{0}", rational_val)));
            }

            rational_val = GetExifRational(exif, Tiff.TagId.ApertureValue);
            if (rational_val > 0)
            {
                AddProperty(Beagle.Property.NewUnsearched("exif:ApertureValue", rational_val));
            }

            rational_val = GetExifRational(exif, Tiff.TagId.FocalLength);
            if (rational_val > 0)
            {
                AddProperty(Beagle.Property.NewUnsearched("exif:FocalLength", String.Format("{0} mm", rational_val)));
            }

            entry = exif.Lookup(Tiff.TagId.Flash);
            if (entry != null)
            {
                ushort flash = entry.ShortValue [0];
                AddProperty(Beagle.Property.NewUnsearched("exif:Flash", GetFlashString(flash)));
            }
        }
Ejemplo n.º 3
0
		public void Load ()
		{
			string path = CreateFile ();

			using (Stream stream = File.OpenRead (path)) {
				JpegHeader jhead = new JpegHeader (stream);

				Assert.AreEqual (((Marker)jhead.Markers [0]).Type, JpegMarker.Soi);
				Assert.AreEqual (((Marker)jhead.Markers [1]).GetName (), "JFIF");
				Assert.AreEqual (((Marker)jhead.Markers [1]).Type, JpegMarker.App0);
				Assert.AreEqual (((Marker)jhead.Markers [2]).GetName (), "Exif");
				Assert.AreEqual (((Marker)jhead.Markers [2]).Type, JpegMarker.App1);

				// NOTE the currently we don't store the Eoi as the last marker
				Assert.AreEqual (((Marker)jhead.Markers [jhead.Markers.Count -1]).Type, JpegMarker.Sos);

				// NOTE this is kind of sill but it might help
				Assert.IsTrue (Math.Abs (jhead.GuessQuality () - quality) <= 1);

				Assert.IsNotNull (jhead.GetExifHeader ());
			}

			File.Delete (path);
		}
Ejemplo n.º 4
0
		private void AddExifProperties (JpegHeader header)
		{
			Tiff.Header ifd = header.GetExifHeader ();
			if (ifd == null)
				return;
			//ifd.Dump ("foo"); // Uncomment to debug

			string str;
			Tiff.DirectoryEntry entry;

			// Add IFD 0 properies

			str = GetExifString (ifd.Directory, Tiff.TagId.Model);
			AddProperty (Beagle.Property.New ("exif:Model", str));

			str = GetExifString (ifd.Directory, Tiff.TagId.ImageDescription);
			AddProperty (Beagle.Property.New ("exif:ImageDescription", str));

			try {
				entry = ifd.Directory.Lookup (Tiff.TagId.DateTime);
				if (entry != null)
					// Assume datetime stored in the images are local times
					AddProperty (Beagle.Property.NewDate ("exif:DateTime", entry.ValueAsDate.ToUniversalTime ()));
			} catch (FormatException) {
				Logger.Log.Debug ("EXIF DateTime '{0}' is invalid.", GetExifString (ifd.Directory, Tiff.TagId.DateTime));
			} catch (ArgumentOutOfRangeException) {
				Logger.Log.Debug ("EXIF DateTime '{0}' is invalid.", GetExifString (ifd.Directory, Tiff.TagId.DateTime));
			}

			str = GetExifString (ifd.Directory, Tiff.TagId.Copyright);
			AddProperty (Beagle.Property.New ("dc:rights", str));

			// Add IFD 1 properties

			Tiff.SubdirectoryEntry subdir = (Tiff.SubdirectoryEntry) ifd.Directory.Lookup (Tiff.TagId.ExifIfdPointer);
			if (subdir == null)
				return;

			Tiff.ImageDirectory exif = subdir.Directory [0];
			if (exif == null)
				return;

			entry = exif.Lookup (Tiff.TagId.UserComment);
			if (entry != null)
				AddProperty (Beagle.Property.New ("exif:UserComment", entry.UserCommentValue));

			uint val = 0;
			entry = exif.Lookup (Tiff.TagId.PixelXDimension);
			if (entry != null)
				val = entry.ValueAsLong [0];
			if (val > 0) {
				Width = (int) val;
				AddProperty (Beagle.Property.NewUnsearched ("exif:PixelXDimension", val));
			}

			val = 0;
			entry = exif.Lookup (Tiff.TagId.PixelYDimension);
			if (entry != null)
				val = entry.ValueAsLong [0];
			if (val > 0) {
				Height = (int) val;
				AddProperty (Beagle.Property.NewUnsearched ("exif:PixelYDimension", val));
			}

			str = GetExifString (exif, Tiff.TagId.ISOSpeedRatings);
			AddProperty (Beagle.Property.NewUnsearched ("exif:ISOSpeedRatings", str));

			str = GetExifString (exif, Tiff.TagId.ShutterSpeedValue);
			AddProperty (Beagle.Property.NewUnsearched ("exif:ShutterSpeedValue", str));

			str = GetExifString (exif, Tiff.TagId.ExposureTime);
			if (! String.IsNullOrEmpty (str))
				AddProperty (Beagle.Property.NewUnsearched ("exif:ExposureTime", str + " sec."));

			double rational_val;

			rational_val = GetExifRational (exif, Tiff.TagId.FNumber);
			if (rational_val > 0)
				AddProperty (Beagle.Property.NewUnsearched ("exif:FNumber", String.Format ("f/{0}", rational_val)));

			rational_val = GetExifRational (exif, Tiff.TagId.ApertureValue);
			if (rational_val > 0)
				AddProperty (Beagle.Property.NewUnsearched ("exif:ApertureValue", rational_val));

			rational_val = GetExifRational (exif, Tiff.TagId.FocalLength);
			if (rational_val > 0)
				AddProperty (Beagle.Property.NewUnsearched ("exif:FocalLength", String.Format ("{0} mm", rational_val)));

			entry = exif.Lookup (Tiff.TagId.Flash);
			if (entry != null) {
				ushort flash = entry.ShortValue [0];
				AddProperty (Beagle.Property.NewUnsearched ("exif:Flash", GetFlashString (flash)));
			}
		}