コード例 #1
0
ファイル: ReadMetaExif.cs プロジェクト: qdraw/starsky
        private static double GetAperture(Directory exifItem)
        {
            var apertureString = exifItem.Tags.FirstOrDefault(p =>
                                                              p.DirectoryName == "Exif SubIFD" && p.Name == "Aperture Value")?.Description;

            if (string.IsNullOrEmpty(apertureString))
            {
                apertureString = exifItem.Tags.FirstOrDefault(p =>
                                                              p.DirectoryName == "Exif SubIFD" && p.Name == "F-Number")?.Description;
            }

            // XMP,http://ns.adobe.com/exif/1.0/,exif:FNumber,9/1
            var fNumberXmp = GetXmpData(exifItem, "exif:FNumber");

            if (string.IsNullOrEmpty(apertureString) && !string.IsNullOrEmpty(fNumberXmp))
            {
                return(MathFraction.Fraction(fNumberXmp));
            }

            if (apertureString == null)
            {
                return(0d);
            }

            apertureString = apertureString.Replace("f/", string.Empty);
            // Note: apertureString: (Dutch) 2,2 or (English) 2.2 based CultureInfo.CurrentCulture
            float.TryParse(apertureString, NumberStyles.Number, CultureInfo.CurrentCulture, out var aperture);

            return(aperture);
        }
コード例 #2
0
ファイル: ReadMetaExif.cs プロジェクト: qdraw/starsky
        /// <summary>
        /// [Exif SubIFD] Focal Length
        /// </summary>
        /// <returns></returns>
        private static double GetFocalLength(Directory exifItem)
        {
            var focalLengthString = exifItem.Tags.FirstOrDefault(
                p => p.DirectoryName == "Exif SubIFD" &&
                p.Name == "Focal Length")?.Description;

            // XMP,http://ns.adobe.com/exif/1.0/,exif:FocalLength,11/1
            var focalLengthXmp = GetXmpData(exifItem, "exif:FocalLength");

            if (string.IsNullOrEmpty(focalLengthString) && !string.IsNullOrEmpty(focalLengthXmp))
            {
                return(Math.Round(MathFraction.Fraction(focalLengthXmp), 5));
            }

            if (string.IsNullOrWhiteSpace(focalLengthString))
            {
                return(0d);
            }

            focalLengthString = focalLengthString.Replace(" mm", string.Empty);

            // Note: focalLengthString: (Dutch) 2,2 or (English) 2.2 based CultureInfo.CurrentCulture
            float.TryParse(focalLengthString, NumberStyles.Number, CultureInfo.CurrentCulture, out var focalLength);

            return(Math.Round(focalLength, 5));
        }
コード例 #3
0
        public void checkFractionSummPositive2()
        {
            Fraction fr1   = new Fraction(3, 22);
            Fraction fr2   = new Fraction(5, 33);
            Fraction frRes = MathFraction.sum(fr1, fr2);
            Fraction frEx  = new Fraction(19, 66);

            Assert.AreEqual(frRes, frEx);
        }
コード例 #4
0
        public void checkFractionSubt()
        {
            Fraction fr1   = new Fraction(3, 22);
            Fraction fr2   = new Fraction(5, 33);
            Fraction frRes = MathFraction.subt(fr1, fr2);
            Fraction frEx  = new Fraction(-1, 66);

            Assert.AreEqual(frRes.Denominator, frEx.Denominator);
            Assert.AreEqual(frRes.Numerator, frEx.Numerator);
            Assert.AreEqual(frRes.Sign, frEx.Sign);
        }
コード例 #5
0
ファイル: ReadMetaExif.cs プロジェクト: qdraw/starsky
        private static double GetXmpGeoAlt(List <Directory> allExifItems)
        {
            var altitudeRef = true;
            var altitude    = 0d;

            // example:
            // +1
            // XMP,http://ns.adobe.com/exif/1.0/,exif:GPSAltitude,1/1
            // XMP,http://ns.adobe.com/exif/1.0/,exif:GPSAltitudeRef,0

            // -10
            // XMP,http://ns.adobe.com/exif/1.0/,exif:GPSAltitude,10/1
            // XMP,http://ns.adobe.com/exif/1.0/,exif:GPSAltitudeRef,1

            foreach (var exifItem in allExifItems)
            {
                if (!(exifItem is XmpDirectory xmpDirectory) || xmpDirectory.XmpMeta == null)
                {
                    continue;
                }

                foreach (var property in xmpDirectory.XmpMeta.Properties.Where(p =>
                                                                               !string.IsNullOrEmpty(p.Value)))
                {
                    switch (property.Path)
                    {
                    case "exif:GPSAltitude":
                        altitude = MathFraction.Fraction(property.Value);
                        break;

                    case "exif:GPSAltitudeRef":
                        altitudeRef = property.Value == "1";
                        break;
                    }
                }
            }

            // no -0 as result
            if (Math.Abs(altitude) < 0.001)
            {
                return(0);
            }

            if (altitudeRef)
            {
                altitude *= -1;
            }
            return(altitude);
        }
コード例 #6
0
ファイル: ReadMetaXmp.cs プロジェクト: qdraw/starsky
        private void GpsAltitudeRef(IXmpMeta xmp, FileIndexItem item)
        {
            string gpsAltitude    = null;
            string gpsAltitudeRef = null;

            foreach (var property in xmp.Properties)
            {
                // Path=exif:GPSAltitude Namespace=http://ns.adobe.com/exif/1.0/ Value=627/10
                // Path=exif:GPSAltitudeRef Namespace=http://ns.adobe.com/exif/1.0/ Value=0
                var gpsAltitudeLocal = GetContentNameSpace(property, "exif:GPSAltitude");
                if (gpsAltitudeLocal != null)
                {
                    gpsAltitude = gpsAltitudeLocal;
                }

                var gpsAltitudeRefLocal = GetContentNameSpace(property, "exif:GPSAltitudeRef");
                if (gpsAltitudeRefLocal != null)
                {
                    gpsAltitudeRef = gpsAltitudeRefLocal;
                }
            }
            if (gpsAltitude == null || gpsAltitudeRef == null)
            {
                return;
            }
            if (!gpsAltitude.Contains("/"))
            {
                return;
            }

            var locationAltitude = MathFraction.Fraction(gpsAltitude);

            if (Math.Abs(locationAltitude) < 0)
            {
                return;
            }
            item.LocationAltitude = locationAltitude;

            //For items under the sea level
            if (gpsAltitudeRef == "1")
            {
                item.LocationAltitude = item.LocationAltitude * -1;
            }
        }
コード例 #7
0
        public void MathFraction_Fraction1()
        {
            var fraction = MathFraction.Fraction("1/1");

            Assert.AreEqual(1, fraction, 0.00001);
        }
コード例 #8
0
        public void MathFraction_FractionNotRight()
        {
            var fraction = MathFraction.Fraction("7/8/0");

            Assert.AreEqual(0, fraction, 0.00001);
        }
コード例 #9
0
        public void MathFraction_Fraction78()
        {
            var fraction = MathFraction.Fraction("7/8");

            Assert.AreEqual(0.875, fraction, 0.00001);
        }
コード例 #10
0
ファイル: ReadMetaXmp.cs プロジェクト: qdraw/starsky
        /// <summary>
        /// ContentNameSpace is for example : Namespace=http://...
        /// </summary>
        /// <param name="xmp"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        private FileIndexItem GetDataContentNameSpaceTypes(IXmpMeta xmp, FileIndexItem item)
        {
            GpsAltitudeRef(xmp, item);

            foreach (var property in xmp.Properties)
            {
                // Path=exif:GPSLatitude Namespace=http://ns.adobe.com/exif/1.0/ Value=52,20.708N
                var gpsLatitude = GetContentNameSpace(property, "exif:GPSLatitude");
                if (gpsLatitude != null)
                {
                    item.Latitude = GpsPreParseAndConvertDegreeAngleToDouble(gpsLatitude);
                }

                // Path=exif:GPSLongitude Namespace=http://ns.adobe.com/exif/1.0/ Value=5,55.840E
                var gpsLongitude = GetContentNameSpace(property, "exif:GPSLongitude");
                if (gpsLongitude != null)
                {
                    item.Longitude = GpsPreParseAndConvertDegreeAngleToDouble(gpsLongitude);
                }

                // Option 1 (Datetime)
                // Path=exif:DateTimeOriginal Namespace=http://ns.adobe.com/exif/1.0/ Value=2018-07-18T19:44:27
                var dateTimeOriginal = GetContentNameSpace(property, "exif:DateTimeOriginal");
                if (dateTimeOriginal != null)
                {
                    DateTime.TryParseExact(dateTimeOriginal,
                                           "yyyy-MM-dd\\THH:mm:ss",
                                           CultureInfo.InvariantCulture,
                                           DateTimeStyles.None,
                                           out var dateTime);
                    if (dateTime.Year >= 3)
                    {
                        item.DateTime = dateTime;
                    }
                }

                // Option 2 (Datetime)
                // Path=xmp:CreateDate Namespace=http://ns.adobe.com/xap/1.0/ Value=2019-03-02T11:29:18+01:00
                // Path=xmp:CreateDate Namespace=http://ns.adobe.com/xap/1.0/ Value=2019-03-02T11:29:18
                var createDate = GetContentNameSpace(property, "xmp:CreateDate");
                if (createDate != null)
                {
                    DateTime.TryParseExact(createDate,
                                           "yyyy-MM-dd\\THH:mm:sszzz",
                                           CultureInfo.InvariantCulture,
                                           DateTimeStyles.None,
                                           out var dateTime);

                    // The other option
                    if (dateTime.Year <= 3)
                    {
                        DateTime.TryParseExact(createDate,
                                               "yyyy-MM-dd\\THH:mm:ss",
                                               CultureInfo.InvariantCulture,
                                               DateTimeStyles.None,
                                               out dateTime);
                    }
                    // and use this value
                    item.DateTime = DateTime.SpecifyKind(dateTime, DateTimeKind.Unspecified);
                }

                //   Path=photomechanic:ColorClass Namespace=http://ns.camerabits.com/photomechanic/1.0/ Value=1
                var colorClass = GetContentNameSpace(property, "photomechanic:ColorClass");
                if (colorClass != null)
                {
                    item.ColorClass = ColorClassParser.GetColorClass(colorClass);
                }

                // Path=tiff:Orientation Namespace=http://ns.adobe.com/tiff/1.0/ Value=6
                var rotation = GetContentNameSpace(property, "tiff:Orientation");
                if (rotation != null)
                {
                    item.SetAbsoluteOrientation(rotation);
                }

                //  Path=tiff:ImageLength Namespace=http://ns.adobe.com/tiff/1.0/ Value=13656
                var height = GetContentNameSpace(property, "tiff:ImageLength");
                if (height != null)
                {
                    item.SetImageHeight(height);
                }

                //  Path=tiff:ImageWidth Namespace=http://ns.adobe.com/tiff/1.0/ Value=15504
                var width = GetContentNameSpace(property, "tiff:ImageWidth");
                if (width != null)
                {
                    item.SetImageWidth(width);
                }

                // Path=photoshop:City Namespace=http://ns.adobe.com/photoshop/1.0/ Value=Epe
                var locationCity = GetContentNameSpace(property, "photoshop:City");
                if (locationCity != null)
                {
                    item.LocationCity = locationCity;
                }

                // Path=photoshop:State Namespace=http://ns.adobe.com/photoshop/1.0/ Value=Gelderland
                var locationState = GetContentNameSpace(property, "photoshop:State");
                if (locationState != null)
                {
                    item.LocationState = locationState;
                }

                // Path=photoshop:Country Namespace=http://ns.adobe.com/photoshop/1.0/ Value=Nederland
                var locationCountry = GetContentNameSpace(property, "photoshop:Country");
                if (locationCountry != null)
                {
                    item.LocationCountry = locationCountry;
                }

                // exif:ExposureTime http://ns.adobe.com/exif/1.0/
                var shutterSpeed = GetContentNameSpace(property, "exif:ExposureTime");
                if (shutterSpeed != null)
                {
                    item.ShutterSpeed = shutterSpeed;
                }

                // exif:FNumber http://ns.adobe.com/exif/1.0/
                var aperture = GetContentNameSpace(property, "exif:FNumber");
                if (aperture != null)
                {
                    item.Aperture = MathFraction.Fraction(aperture);
                }

                // Path=tiff:Make Namespace=http://ns.adobe.com/tiff/1.0/ Value=SONY
                var make = GetContentNameSpace(property, "tiff:Make");
                if (make != null)
                {
                    item.SetMakeModel(make, 0);
                }

                // Path=tiff:Model Namespace=http://ns.adobe.com/tiff/1.0/ Value=SLT-A58
                var model = GetContentNameSpace(property, "tiff:Model");
                if (model != null)
                {
                    item.SetMakeModel(model, 1);
                }

                // Path=exif:FocalLength Namespace=http://ns.adobe.com/exif/1.0/ Value=200/1
                // Path=exif:FocalLength Namespace=http://ns.adobe.com/exif/1.0/ Value=18/1
                var focalLength = GetContentNameSpace(property, "exif:FocalLength");
                if (focalLength != null)
                {
                    item.FocalLength = MathFraction.Fraction(focalLength);
                }

                // Path=xmp:CreatorTool Namespace=http://ns.adobe.com/xap/1.0/ Value=SLT-A58 v1.00
                var software = GetContentNameSpace(property, "xmp:CreatorTool");
                if (software != null)
                {
                    item.Software = software;
                }
            }

            return(item);
        }