Ejemplo n.º 1
0
 internal static void ClearValue(this ExifProfile profile, ExifTag tag)
 {
     if (profile.GetValue(tag) != null)
     {
         profile.RemoveValue(tag);
     }
 }
Ejemplo n.º 2
0
 private static void RemoveTag <T>(ExifTag <T> exifTag, ExifProfile exifProfile)
 {
     if (exifProfile.GetValue <T>(exifTag) != null)
     {
         exifProfile.RemoveValue(exifTag);
     }
 }
Ejemplo n.º 3
0
            public void ShouldRemoveFalseWhenProfileDoesNotContainTag()
            {
                using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
                {
                    ExifProfile profile = image.GetExifProfile();

                    Assert.IsFalse(profile.RemoveValue(ExifTag.Acceleration));
                }
            }
Ejemplo n.º 4
0
            public void ShouldRemoveValueAndReturnTrue()
            {
                using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
                {
                    ExifProfile profile = image.GetExifProfile();

                    Assert.IsTrue(profile.RemoveValue(ExifTag.FNumber));
                }
            }
Ejemplo n.º 5
0
        /// <summary>
        /// Parses the given Exif profile to populate the properties of the tiff frame meta data.
        /// </summary>
        /// <param name="meta">The tiff frame meta data.</param>
        /// <param name="profile">The Exif profile containing tiff frame directory tags.</param>
        internal static void Parse(TiffFrameMetadata meta, ExifProfile profile)
        {
            if (profile != null)
            {
                if (TiffBitsPerSample.TryParse(profile.GetValue(ExifTag.BitsPerSample)?.Value, out TiffBitsPerSample bitsPerSample))
                {
                    meta.BitsPerSample = bitsPerSample;
                }

                meta.BitsPerPixel = meta.BitsPerSample?.BitsPerPixel();
                meta.Compression  = (TiffCompression?)profile.GetValue(ExifTag.Compression)?.Value;
                meta.PhotometricInterpretation = (TiffPhotometricInterpretation?)profile.GetValue(ExifTag.PhotometricInterpretation)?.Value;
                meta.Predictor = (TiffPredictor?)profile.GetValue(ExifTag.Predictor)?.Value;

                profile.RemoveValue(ExifTag.BitsPerSample);
                profile.RemoveValue(ExifTag.Compression);
                profile.RemoveValue(ExifTag.PhotometricInterpretation);
                profile.RemoveValue(ExifTag.Predictor);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Updates the dimensional metadata of a transformed image
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="image">The image to update</param>
        public static void UpdateDimensionalMetData <TPixel>(Image <TPixel> image)
            where TPixel : struct, IPixel <TPixel>
        {
            ExifProfile profile = image.MetaData.ExifProfile;

            if (profile == null)
            {
                return;
            }

            // Removing the previously stored value allows us to set a value with our own data tag if required.
            if (profile.GetValue(ExifTag.PixelXDimension) != null)
            {
                profile.RemoveValue(ExifTag.PixelXDimension);

                if (image.Width <= ushort.MaxValue)
                {
                    profile.SetValue(ExifTag.PixelXDimension, (ushort)image.Width);
                }
                else
                {
                    profile.SetValue(ExifTag.PixelXDimension, (uint)image.Width);
                }
            }

            if (profile.GetValue(ExifTag.PixelYDimension) != null)
            {
                profile.RemoveValue(ExifTag.PixelYDimension);

                if (image.Height <= ushort.MaxValue)
                {
                    profile.SetValue(ExifTag.PixelYDimension, (ushort)image.Height);
                }
                else
                {
                    profile.SetValue(ExifTag.PixelYDimension, (uint)image.Height);
                }
            }
        }
Ejemplo n.º 7
0
        /// <inheritdoc/>
        protected override void AfterImageApply(Image <TPixel> source, Image <TPixel> destination, Rectangle sourceRectangle)
        {
            ExifProfile profile = destination.MetaData.ExifProfile;

            if (profile == null)
            {
                return;
            }

            if (MathF.Abs(WrapDegrees(this.Degrees)) < Constants.Epsilon)
            {
                // No need to do anything so return.
                return;
            }

            profile.RemoveValue(ExifTag.Orientation);

            base.AfterImageApply(source, destination, sourceRectangle);
        }
Ejemplo n.º 8
0
        /// <inheritdoc/>
        protected override void AfterImageApply(Image <TPixel> source, Rectangle sourceRectangle)
        {
            ExifProfile profile = source.MetaData.ExifProfile;

            if (profile == null)
            {
                return;
            }

            if (MathF.Abs(this.Angle) < Constants.Epsilon)
            {
                // No need to do anything so return.
                return;
            }

            profile.RemoveValue(ExifTag.Orientation);

            if (this.Expand && profile.GetValue(ExifTag.PixelXDimension) != null)
            {
                profile.SetValue(ExifTag.PixelXDimension, source.Width);
                profile.SetValue(ExifTag.PixelYDimension, source.Height);
            }
        }
Ejemplo n.º 9
0
        public void Test_SetValue()
        {
            Rational[] latitude = new Rational[] { new Rational(12.3), new Rational(4.56), new Rational(789.0) };

            using (MemoryStream memStream = new MemoryStream())
            {
                using (IMagickImage image = new MagickImage(Files.FujiFilmFinePixS1ProJPG))
                {
                    ExifProfile profile = image.GetExifProfile();
                    profile.SetValue(ExifTag.Software, "Magick.NET");

                    ExifValue value = profile.GetValue(ExifTag.Software);
                    TestValue(value, "Magick.NET");

                    ExceptionAssert.Throws <ArgumentException>(delegate()
                    {
                        value.Value = 15;
                    });

                    profile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));

                    value = profile.GetValue(ExifTag.ShutterSpeedValue);
                    TestRationalValue(value, "1511/20");

                    ExceptionAssert.Throws <ArgumentException>(delegate()
                    {
                        value.Value = 75;
                    });

                    profile.SetValue(ExifTag.XResolution, new Rational(150.0));

                    value = profile.GetValue(ExifTag.XResolution);
                    TestRationalValue(value, "150");

                    ExceptionAssert.Throws <ArgumentException>(delegate()
                    {
                        value.Value = "Magick.NET";
                    });

                    image.Density = new Density(72);

                    value = profile.GetValue(ExifTag.XResolution);
                    TestRationalValue(value, "150");

                    value = profile.GetValue(ExifTag.ReferenceBlackWhite);
                    Assert.IsNotNull(value);

                    profile.SetValue(ExifTag.ReferenceBlackWhite, null);

                    value = profile.GetValue(ExifTag.ReferenceBlackWhite);
                    TestValue(value, (string)null);

                    profile.SetValue(ExifTag.GPSLatitude, latitude);

                    value = profile.GetValue(ExifTag.GPSLatitude);
                    TestValue(value, latitude);

                    image.AddProfile(profile);

                    image.Write(memStream);
                }

                memStream.Position = 0;
                using (IMagickImage image = new MagickImage(memStream))
                {
                    ExifProfile profile = image.GetExifProfile();

                    Assert.IsNotNull(profile);
                    Assert.AreEqual(43, profile.Values.Count());

                    ExifValue value = profile.GetValue(ExifTag.Software);
                    TestValue(value, "Magick.NET");

                    value = profile.GetValue(ExifTag.ShutterSpeedValue);
                    TestRationalValue(value, "1511/20");

                    value = profile.GetValue(ExifTag.XResolution);
                    TestRationalValue(value, "72");

                    value = profile.GetValue(ExifTag.ReferenceBlackWhite);
                    Assert.IsNull(value);

                    value = profile.GetValue(ExifTag.GPSLatitude);
                    TestValue(value, latitude);

                    profile.Parts = ExifParts.ExifTags;

                    image.AddProfile(profile);

                    memStream.Position = 0;
                    image.Write(memStream);
                }

                memStream.Position = 0;
                using (IMagickImage image = new MagickImage(memStream))
                {
                    ExifProfile profile = image.GetExifProfile();

                    Assert.IsNotNull(profile);
                    Assert.AreEqual(24, profile.Values.Count());

                    Assert.IsNotNull(profile.GetValue(ExifTag.FNumber));
                    Assert.IsTrue(profile.RemoveValue(ExifTag.FNumber));
                    Assert.IsFalse(profile.RemoveValue(ExifTag.FNumber));
                    Assert.IsNull(profile.GetValue(ExifTag.FNumber));

                    Assert.AreEqual(23, profile.Values.Count());
                }
            }
        }
Ejemplo n.º 10
0
            private void ProcessProfiles(ImageMetadata imageMetadata, ExifProfile exifProfile, XmpProfile xmpProfile)
            {
                if (exifProfile != null && exifProfile.Parts != ExifParts.None)
                {
                    foreach (IExifValue entry in exifProfile.Values)
                    {
                        if (!this.Collector.Entries.Exists(t => t.Tag == entry.Tag) && entry.GetValue() != null)
                        {
                            ExifParts entryPart = ExifTags.GetPart(entry.Tag);
                            if (entryPart != ExifParts.None && exifProfile.Parts.HasFlag(entryPart))
                            {
                                this.Collector.AddOrReplace(entry.DeepClone());
                            }
                        }
                    }
                }
                else
                {
                    exifProfile.RemoveValue(ExifTag.SubIFDOffset);
                }

                if (imageMetadata.IptcProfile != null)
                {
                    imageMetadata.IptcProfile.UpdateData();
                    var iptc = new ExifByteArray(ExifTagValue.IPTC, ExifDataType.Byte)
                    {
                        Value = imageMetadata.IptcProfile.Data
                    };

                    this.Collector.Add(iptc);
                }
                else
                {
                    exifProfile.RemoveValue(ExifTag.IPTC);
                }

                if (imageMetadata.IccProfile != null)
                {
                    var icc = new ExifByteArray(ExifTagValue.IccProfile, ExifDataType.Undefined)
                    {
                        Value = imageMetadata.IccProfile.ToByteArray()
                    };

                    this.Collector.Add(icc);
                }
                else
                {
                    exifProfile.RemoveValue(ExifTag.IccProfile);
                }

                if (xmpProfile != null)
                {
                    var xmp = new ExifByteArray(ExifTagValue.XMP, ExifDataType.Byte)
                    {
                        Value = xmpProfile.Data
                    };

                    this.Collector.Add(xmp);
                }
                else
                {
                    exifProfile.RemoveValue(ExifTag.XMP);
                }
            }