Ejemplo n.º 1
0
        public void ExifTypeUndefined()
        {
            // This image contains an 802 byte EXIF profile
            // It has a tag with an index offset of 18,481,152 bytes (overrunning the data)

            Image <Rgba32> image = TestFile.Create(TestImages.Jpeg.Progressive.Bad.ExifUndefType).CreateImage();

            Assert.NotNull(image);

            ExifProfile profile = image.MetaData.ExifProfile;

            Assert.NotNull(profile);

            foreach (ExifValue value in profile.Values)
            {
                if (value.DataType == ExifDataType.Undefined)
                {
                    Assert.Equal(4, value.NumberOfComponents);
                }
            }
        }
Ejemplo n.º 2
0
        public void Constructor(TestImageWriteFormat imageFormat)
        {
            Image <Rgba32> image = TestFile.Create(TestImages.Jpeg.Baseline.Calliphora).CreateRgba32Image();

            Assert.Null(image.Metadata.ExifProfile);

            const string expected = "Dirk Lemstra";

            image.Metadata.ExifProfile = new ExifProfile();
            image.Metadata.ExifProfile.SetValue(ExifTag.Copyright, expected);

            image = WriteAndRead(image, imageFormat);

            Assert.NotNull(image.Metadata.ExifProfile);
            Assert.Equal(1, image.Metadata.ExifProfile.Values.Count);

            IExifValue <string> value = image.Metadata.ExifProfile.GetValue(ExifTag.Copyright);

            Assert.NotNull(value);
            Assert.Equal(expected, value.Value);
        }
Ejemplo n.º 3
0
        public void Encode_IgnoreMetadataIsTrue_CommentsAreNotWritten()
        {
            var options = new GifEncoder()
            {
                IgnoreMetadata = true
            };

            var testFile = TestFile.Create(TestImages.Gif.Rings);

            using (Image <Rgba32> input = testFile.CreateImage())
            {
                using (var memStream = new MemoryStream())
                {
                    input.SaveAsGif(memStream, options);

                    memStream.Position = 0;
                    using (var output = Image.Load <Rgba32>(memStream))
                    {
                        Assert.Equal(0, output.MetaData.Properties.Count);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit)
        {
            var options = new BmpEncoder();

            var testFile = TestFile.Create(imagePath);

            using (Image <Rgba32> input = testFile.CreateImage())
            {
                using (var memStream = new MemoryStream())
                {
                    input.Save(memStream, options);

                    memStream.Position = 0;
                    using (var output = Image.Load <Rgba32>(memStream))
                    {
                        ImageMetaData meta = output.MetaData;
                        Assert.Equal(xResolution, meta.HorizontalResolution);
                        Assert.Equal(yResolution, meta.VerticalResolution);
                        Assert.Equal(resolutionUnit, meta.ResolutionUnits);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void SetValue(TestImageWriteFormat imageFormat)
        {
            var latitude = new Rational[] { new Rational(12.3), new Rational(4.56), new Rational(789.0) };

            Image <Rgba32> image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateImage();

            image.MetaData.ExifProfile.SetValue(ExifTag.Software, "ImageSharp");

            ExifValue value = image.MetaData.ExifProfile.GetValue(ExifTag.Software);

            TestValue(value, "ImageSharp");

            Assert.Throws <ArgumentException>(() => { value.WithValue(15); });

            image.MetaData.ExifProfile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));

            value = image.MetaData.ExifProfile.GetValue(ExifTag.ShutterSpeedValue);

            TestValue(value, new SignedRational(7555, 100));

            Assert.Throws <ArgumentException>(() => { value.WithValue(75); });

            image.MetaData.ExifProfile.SetValue(ExifTag.XResolution, new Rational(150.0));

            // We also need to change this value because this overrides XResolution when the image is written.
            image.MetaData.HorizontalResolution = 150.0;

            value = image.MetaData.ExifProfile.GetValue(ExifTag.XResolution);
            TestValue(value, new Rational(150, 1));

            Assert.Throws <ArgumentException>(() => { value.WithValue("ImageSharp"); });

            image.MetaData.ExifProfile.SetValue(ExifTag.ReferenceBlackWhite, null);

            value = image.MetaData.ExifProfile.GetValue(ExifTag.ReferenceBlackWhite);
            TestValue(value, (string)null);

            image.MetaData.ExifProfile.SetValue(ExifTag.GPSLatitude, latitude);

            value = image.MetaData.ExifProfile.GetValue(ExifTag.GPSLatitude);
            TestValue(value, latitude);

            image = WriteAndRead(image, imageFormat);

            Assert.NotNull(image.MetaData.ExifProfile);
            Assert.Equal(17, image.MetaData.ExifProfile.Values.Count());

            value = image.MetaData.ExifProfile.GetValue(ExifTag.Software);
            TestValue(value, "ImageSharp");

            value = image.MetaData.ExifProfile.GetValue(ExifTag.ShutterSpeedValue);
            TestValue(value, new SignedRational(75.55));

            value = image.MetaData.ExifProfile.GetValue(ExifTag.XResolution);
            TestValue(value, new Rational(150.0));

            value = image.MetaData.ExifProfile.GetValue(ExifTag.ReferenceBlackWhite);
            Assert.Null(value);

            value = image.MetaData.ExifProfile.GetValue(ExifTag.GPSLatitude);
            TestValue(value, latitude);

            image.MetaData.ExifProfile.Parts = ExifParts.ExifTags;

            image = WriteAndRead(image, imageFormat);

            Assert.NotNull(image.MetaData.ExifProfile);
            Assert.Equal(8, image.MetaData.ExifProfile.Values.Count());

            Assert.NotNull(image.MetaData.ExifProfile.GetValue(ExifTag.ColorSpace));
            Assert.True(image.MetaData.ExifProfile.RemoveValue(ExifTag.ColorSpace));
            Assert.False(image.MetaData.ExifProfile.RemoveValue(ExifTag.ColorSpace));
            Assert.Null(image.MetaData.ExifProfile.GetValue(ExifTag.ColorSpace));

            Assert.Equal(7, image.MetaData.ExifProfile.Values.Count());
        }
Ejemplo n.º 6
0
            private Image <TPixel> LoadImage(IImageDecoder decoder)
            {
                var testFile = TestFile.Create(this.FilePath);

                return(Image.Load <TPixel>(this.Configuration, testFile.Bytes, decoder));
            }
Ejemplo n.º 7
0
        public void SetValue(TestImageWriteFormat imageFormat)
        {
            Image <Rgba32> image = TestFile.Create(TestImages.Jpeg.Baseline.Floorplan).CreateRgba32Image();

            image.Metadata.ExifProfile.SetValue(ExifTag.Software, "ImageSharp");

            IExifValue <string> software = image.Metadata.ExifProfile.GetValue(ExifTag.Software);

            Assert.Equal("ImageSharp", software.Value);

            // ExifString can set integer values.
            Assert.True(software.TrySetValue(15));
            Assert.False(software.TrySetValue(15F));

            image.Metadata.ExifProfile.SetValue(ExifTag.ShutterSpeedValue, new SignedRational(75.55));

            IExifValue <SignedRational> shutterSpeed = image.Metadata.ExifProfile.GetValue(ExifTag.ShutterSpeedValue);

            Assert.Equal(new SignedRational(7555, 100), shutterSpeed.Value);
            Assert.False(shutterSpeed.TrySetValue(75));

            image.Metadata.ExifProfile.SetValue(ExifTag.XResolution, new Rational(150.0));

            // We also need to change this value because this overrides XResolution when the image is written.
            image.Metadata.HorizontalResolution = 150.0;

            IExifValue <Rational> xResolution = image.Metadata.ExifProfile.GetValue(ExifTag.XResolution);

            Assert.Equal(new Rational(150, 1), xResolution.Value);

            Assert.False(xResolution.TrySetValue("ImageSharp"));

            image.Metadata.ExifProfile.SetValue(ExifTag.ReferenceBlackWhite, null);

            IExifValue <Rational[]> referenceBlackWhite = image.Metadata.ExifProfile.GetValue(ExifTag.ReferenceBlackWhite);

            Assert.Null(referenceBlackWhite.Value);

            var expectedLatitude = new Rational[] { new Rational(12.3), new Rational(4.56), new Rational(789.0) };

            image.Metadata.ExifProfile.SetValue(ExifTag.GPSLatitude, expectedLatitude);

            IExifValue <Rational[]> latitude = image.Metadata.ExifProfile.GetValue(ExifTag.GPSLatitude);

            Assert.Equal(expectedLatitude, latitude.Value);

            int profileCount = image.Metadata.ExifProfile.Values.Count;

            image = WriteAndRead(image, imageFormat);

            Assert.NotNull(image.Metadata.ExifProfile);

            // Should be 3 less.
            // 1 x due to setting of null "ReferenceBlackWhite" value.
            // 2 x due to use of non-standard padding tag 0xEA1C listed in EXIF Tool. We can read those values but adhere
            // strictly to the 2.3.1 specification when writing. (TODO: Support 2.3.2)
            // https://exiftool.org/TagNames/EXIF.html
            Assert.Equal(profileCount - 3, image.Metadata.ExifProfile.Values.Count);

            software = image.Metadata.ExifProfile.GetValue(ExifTag.Software);
            Assert.Equal("15", software.Value);

            shutterSpeed = image.Metadata.ExifProfile.GetValue(ExifTag.ShutterSpeedValue);
            Assert.Equal(new SignedRational(75.55), shutterSpeed.Value);

            xResolution = image.Metadata.ExifProfile.GetValue(ExifTag.XResolution);
            Assert.Equal(new Rational(150.0), xResolution.Value);

            referenceBlackWhite = image.Metadata.ExifProfile.GetValue(ExifTag.ReferenceBlackWhite);
            Assert.Null(referenceBlackWhite);

            latitude = image.Metadata.ExifProfile.GetValue(ExifTag.GPSLatitude);
            Assert.Equal(expectedLatitude, latitude.Value);

            image.Metadata.ExifProfile.Parts = ExifParts.ExifTags;

            image = WriteAndRead(image, imageFormat);

            Assert.NotNull(image.Metadata.ExifProfile);
            Assert.Equal(8, image.Metadata.ExifProfile.Values.Count);

            Assert.NotNull(image.Metadata.ExifProfile.GetValue(ExifTag.ColorSpace));
            Assert.True(image.Metadata.ExifProfile.RemoveValue(ExifTag.ColorSpace));
            Assert.False(image.Metadata.ExifProfile.RemoveValue(ExifTag.ColorSpace));
            Assert.Null(image.Metadata.ExifProfile.GetValue(ExifTag.ColorSpace));

            Assert.Equal(7, image.Metadata.ExifProfile.Values.Count);
        }