Пример #1
0
 public void ShouldNotThrowExceptionWhenFileNameSettingsIsNull()
 {
     using (var images = new MagickImageCollection(Files.SnakewarePNG, null))
     {
         EnumerableAssert.IsSingle(images);
     }
 }
        public void Test_Collection_Read()
        {
            using (var collection = new MagickImageCollection())
            {
                MagickReadSettings settings = new MagickReadSettings();
                settings.Density = new Density(150);

                collection.Read(Files.RoseSparkleGIF, settings);

                Assert.AreEqual(150, collection[0].Density.X);

                settings            = new MagickReadSettings();
                settings.FrameIndex = 1;

                collection.Read(Files.RoseSparkleGIF, settings);

                EnumerableAssert.IsSingle(collection);

                settings            = new MagickReadSettings();
                settings.FrameIndex = 1;
                settings.FrameCount = 2;

                collection.Read(Files.RoseSparkleGIF, settings);

                Assert.AreEqual(2, collection.Count);

                settings = null;
                collection.Read(Files.RoseSparkleGIF, settings);
            }
        }
Пример #3
0
            public void ShouldUpdateTheDataInTheProfile()
            {
                using (var memStream = new MemoryStream())
                {
                    using (var image = new MagickImage(Files.ImageMagickJPG))
                    {
                        var profile = image.GetExifProfile();
                        Assert.IsNull(profile);

                        profile = new ExifProfile();
                        profile.SetValue(ExifTag.Copyright, "Dirk Lemstra");

                        image.SetProfile(profile);

                        profile = image.GetExifProfile();
                        Assert.IsNotNull(profile);

                        image.Write(memStream);
                    }

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

                        Assert.IsNotNull(profile);
                        EnumerableAssert.IsSingle(profile.Values);

                        var value = profile.Values.FirstOrDefault(val => val.Tag == ExifTag.Copyright);
                        TestValue(value, "Dirk Lemstra");
                    }
                }
            }
Пример #4
0
                public void ShouldNotThrowExceptionWhenSettingsIsNull()
                {
                    var file = new FileInfo(Files.SnakewarePNG);

                    using (var images = new MagickImageCollection(file, null))
                    {
                        EnumerableAssert.IsSingle(images);
                    }
                }
Пример #5
0
                public void ShouldNotThrowExceptionWhenSettingsIsNull()
                {
                    var bytes = File.ReadAllBytes(Files.SnakewarePNG);

                    using (var images = new MagickImageCollection(bytes, null))
                    {
                        EnumerableAssert.IsSingle(images);
                    }
                }
Пример #6
0
            public void ShouldReadProfileValues()
            {
                var bytes = ToBytes('8', 'B', 'I', 'M', (short)2000, (short)0, 1, (byte)0);

                var profile = new EightBimProfile(bytes);

                EnumerableAssert.IsSingle(profile.Values);
                EnumerableAssert.IsEmpty(profile.ClipPaths);
            }
Пример #7
0
                public void ShouldNotThrowExceptionWhenSettingsIsNull()
                {
                    using (var images = new MagickImageCollection())
                    {
                        images.Read(Files.CirclePNG, null);

                        EnumerableAssert.IsSingle(images);
                    }
                }
Пример #8
0
        public void ShouldReadClipPathsInTiffPreview()
        {
            using (var images = new MagickImageCollection(Files.Coders.SwedenHeartEPS))
            {
                var profile = images[1].Get8BimProfile();

                EnumerableAssert.IsSingle(profile.ClipPaths);
            }
        }
Пример #9
0
            public void ShouldCheckArraySize()
            {
                var reader = new ExifReader();
                var data   = new byte[] { 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 1, 0, 148, 1, 1, 0, 255, 255, 255, 255, 26, 0, 0, 0, 31, 0, 0, 0, 42 };

                reader.Read(data);

                EnumerableAssert.IsEmpty(reader.Values);
                EnumerableAssert.IsSingle(reader.InvalidTags);
            }
Пример #10
0
            public void ShouldBeAbleToReadEmptyStrings()
            {
                var reader = new ExifReader();
                var data   = new byte[] { 69, 120, 105, 102, 0, 0, 73, 73, 42, 0, 8, 0, 0, 0, 1, 0, 14, 1, 2, 0, 0, 0, 0, 0, 32, 0, 0, 0, 26, 0, 0, 0, 0, 0 };

                reader.Read(data);

                EnumerableAssert.IsSingle(reader.Values);
                Assert.AreEqual(string.Empty, reader.Values.First().GetValue());
            }
Пример #11
0
 public void ShouldNotThrowExceptionWhenStreamSettingsIsNull()
 {
     using (var stream = File.OpenRead(Files.SnakewarePNG))
     {
         using (var images = new MagickImageCollection(stream, null))
         {
             EnumerableAssert.IsSingle(images);
         }
     }
 }
Пример #12
0
                public void ShouldReadImage()
                {
                    using (var images = new MagickImageCollection())
                    {
                        var fileBytes = File.ReadAllBytes(Files.SnakewarePNG);
                        var bytes     = new byte[fileBytes.Length + 10];
                        fileBytes.CopyTo(bytes, 10);

                        images.Read(bytes, 10, bytes.Length - 10);
                        EnumerableAssert.IsSingle(images);
                    }
                }
Пример #13
0
            public void ShoulNotdAllowDuplicateValuesForValuesThatCannotBeRepated(IptcTag tag)
            {
                var profile       = new IptcProfile();
                var expectedValue = "another one";

                profile.SetValue(tag, "test");
                profile.SetValue(tag, expectedValue);

                var values = profile.Values.ToList();

                EnumerableAssert.IsSingle(values);
                Assert.IsTrue(values.Contains(new IptcValue(tag, Encoding.UTF8.GetBytes(expectedValue))));
            }
Пример #14
0
            public void ShouldReturnTheArtifactNames()
            {
                using (var image = new MagickImage(Files.ImageMagickJPG))
                {
                    image.SetArtifact("foo", "bar");
                    image.SetAttribute("bar", "foo");

                    var names = image.ArtifactNames;
                    EnumerableAssert.IsSingle(names);
                    Assert.AreEqual("foo", string.Join(",", (from name in names
                                                             orderby name
                                                             select name).ToArray()));
                }
            }
Пример #15
0
            public void ShouldUseOptimizationForSingleImage()
            {
                using (var images = new MagickImageCollection(Files.RoseSparkleGIF))
                {
                    images.RemoveAt(0);
                    images.RemoveAt(0);

                    EnumerableAssert.IsSingle(images);

                    using (Bitmap bitmap = images.ToBitmap())
                    {
                        Assert.IsNotNull(bitmap);
                    }
                }
            }
            public void ShouldSetViewport()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DistortSettings()
                    {
                        Viewport = new MagickGeometry(1, 2, 3, 4),
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);
                    Assert.AreEqual("3x4+1+2", image.GetArtifact("distort:viewport"));
                }
            }
Пример #17
0
            public void ShouldSetTheMinumunAndMaximumAreaThreshold()
            {
                using (var image = new MagickImage())
                {
                    var settings = new ConnectedComponentsSettings()
                    {
                        AreaThreshold = new Threshold(1.2, 3.4),
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);
                    Assert.AreEqual("1.2-3.4", image.GetArtifact("connected-components:area-threshold"));
                }
            }
Пример #18
0
                public void ShouldReadImage()
                {
                    var factory  = new MagickImageCollectionFactory();
                    var settings = new MagickReadSettings();

                    var fileBytes = File.ReadAllBytes(Files.SnakewarePNG);
                    var bytes     = new byte[fileBytes.Length + 10];

                    fileBytes.CopyTo(bytes, 10);

                    using (var images = factory.Create(bytes, 10, bytes.Length - 10, settings))
                    {
                        EnumerableAssert.IsSingle(images);
                    }
                }
Пример #19
0
            public void ShouldSetMeanColor()
            {
                using (var image = new MagickImage())
                {
                    var settings = new ConnectedComponentsSettings()
                    {
                        MeanColor = true,
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);
                    Assert.AreEqual("true", image.GetArtifact("connected-components:mean-color"));
                }
            }
            public void ShouldSetScale()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DistortSettings()
                    {
                        Scale = 4.2,
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);
                    Assert.AreEqual("4.2", image.GetArtifact("distort:scale"));
                }
            }
Пример #21
0
            public void ShouldSetSeedColors()
            {
                using (var image = new MagickImage())
                {
                    var settings = new KmeansSettings()
                    {
                        SeedColors = "red;blue",
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);
                    Assert.AreEqual("red;blue", image.GetArtifact("kmeans:seed-colors"));
                }
            }
            public void ShouldSetTheSignalToNoiseRatio()
            {
                using (var image = new MagickImage())
                {
                    var settings = new ComplexSettings()
                    {
                        SignalToNoiseRatio = 1.2,
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);
                    Assert.AreEqual("1.2", image.GetArtifact("complex:snr"));
                }
            }
            public void ShouldSetConvolveScale()
            {
                using (var image = new MagickImage())
                {
                    var settings = new MorphologySettings()
                    {
                        ConvolveScale = new MagickGeometry(1, 2, 3, 4),
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);
                    Assert.AreEqual("3x4+1+2", image.GetArtifact("convolve:scale"));
                }
            }
Пример #24
0
            public void ShouldSetAutoCrop()
            {
                using (var image = new MagickImage())
                {
                    var settings = new DeskewSettings()
                    {
                        AutoCrop = true,
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);
                    Assert.AreEqual("true", image.GetArtifact("deskew:auto-crop"));
                }
            }
            public void ShouldSetConvolveBias()
            {
                using (var image = new MagickImage())
                {
                    var settings = new MorphologySettings()
                    {
                        ConvolveBias = new Percentage(70),
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);
                    Assert.AreEqual("70%", image.GetArtifact("convolve:bias"));
                }
            }
Пример #26
0
            public void ShouldSetTheAngleThreshold()
            {
                using (var image = new MagickImage())
                {
                    var settings = new ConnectedComponentsSettings()
                    {
                        AngleThreshold = new Threshold(1.5),
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);
                    Assert.AreEqual("1.5", image.GetArtifact("connected-components:angle-threshold"));
                }
            }
Пример #27
0
                public void ShouldUseTheSpecifiedFormat()
                {
                    using (var input = new MagickImageCollection(Files.CirclePNG))
                    {
                        using (var tempfile = new TemporaryFile("foobar"))
                        {
                            input.Write(tempfile, MagickFormat.Tiff);

                            using (var output = new MagickImageCollection(tempfile))
                            {
                                EnumerableAssert.IsSingle(output);
                                Assert.AreEqual(MagickFormat.Tiff, output[0].Format);
                            }
                        }
                    }
                }
Пример #28
0
        public void Test_Remove()
        {
            using (var collection = new MagickImageCollection(Files.RoseSparkleGIF))
            {
                var first = collection[0];
                collection.Remove(first);

                Assert.AreEqual(2, collection.Count);
                Assert.AreEqual(-1, collection.IndexOf(first));

                first = collection[0];
                collection.RemoveAt(0);

                EnumerableAssert.IsSingle(collection);
                Assert.AreEqual(-1, collection.IndexOf(first));
            }
        }
            public void ShouldSkipTheMipmaps()
            {
                var settings = new MagickReadSettings()
                {
                    Defines = new DdsReadDefines()
                    {
                        SkipMipmaps = true,
                    },
                };

                using (var images = new MagickImageCollection())
                {
                    images.Read(Files.Coders.TestDDS, settings);

                    EnumerableAssert.IsSingle(images);
                }
            }
Пример #30
0
            public void ShouldSetTheMasklightColor()
            {
                using (var image = new MagickImage())
                {
                    var settings = new CompareSettings()
                    {
                        MasklightColor = MagickColors.Magenta,
                    };

                    settings.SetImageArtifacts(image);

                    EnumerableAssert.IsSingle(image.ArtifactNames);

#if Q8
                    Assert.AreEqual("#FF00FFFF", image.GetArtifact("compare:masklight-color"));
#else
                    Assert.AreEqual("#FFFF0000FFFFFFFF", image.GetArtifact("compare:masklight-color"));
#endif
                }
            }