Пример #1
0
        /// <summary>Parses <see cref="ExifSubIfdDirectory" /> metadata and saves it to the <see cref="Photo" />.</summary>
        /// <param name="directory">Directory containing the F-number, ISO, shutter speed, datetime original and focal length metadata.</param>
        /// <param name="photo">Photo object used for storing metadata.</param>
        public static void Parse(this ExifSubIfdDirectory directory, Photo photo)
        {
            if (directory is null || photo is null)
            {
                return;
            }

            if (directory.TryGetSingle(ExifDirectoryBase.TagFNumber, out var fNum))
            {
                photo.FNumber = fNum;
            }

            if (directory.TryGetInt16(ExifDirectoryBase.TagIsoEquivalent, out var iso))
            {
                photo.Iso = iso;
            }

            if (directory.TryGetSingle(ExifDirectoryBase.TagShutterSpeed, out var apexValue))
            {
                photo.ShutterSpeed = MetadataConverter.ComputeShutterSpeed(apexValue);
            }

            if (directory.TryGetDateTime(ExifDirectoryBase.TagDateTimeOriginal, out var dateTimeOriginal))
            {
                photo.DateTimeOriginal = dateTimeOriginal;
            }

            if (directory.TryGetSingle(ExifDirectoryBase.TagFocalLength, out var focalLength))
            {
                photo.FocalLength = focalLength;
            }
        }
        public void ComputeShutterSpeed_GreaterThanOneValue()
        {
            var expected = "1/4 sec"; // exp(2 * log(2)) = 4

            var actual = MetadataConverter.ComputeShutterSpeed(2);

            Assert.Equal(expected, actual);
        }
        public void ComputeShutterSpeed_LessOrEqualToOneValue()
        {
            // Align the data formatting for testing
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");

            var expected = "0.5 sec"; // round((1 / exp(1 * log(2))) * 10) / 10 = 0.5

            var actual = MetadataConverter.ComputeShutterSpeed(1);

            Assert.Equal(expected, actual);
        }