private IMagickImage ExecuteMap(XmlElement element, IMagickImageCollection collection)
        {
            Hashtable arguments = new Hashtable();

            foreach (XmlElement elem in element.SelectNodes("*"))
            {
                if (elem.Name == "image")
                {
                    arguments["image"] = CreateMagickImage(elem);
                }
                else if (elem.Name == "settings")
                {
                    arguments["settings"] = CreateQuantizeSettings(elem);
                }
            }
            if (OnlyContains(arguments, "image"))
            {
                collection.Map((IMagickImage)arguments["image"]);
                return(null);
            }
            else if (OnlyContains(arguments, "image", "settings"))
            {
                collection.Map((IMagickImage)arguments["image"], (QuantizeSettings)arguments["settings"]);
                return(null);
            }
            else
            {
                throw new ArgumentException("Invalid argument combination for 'map', allowed combinations are: [image] [image, settings]");
            }
        }
        private IMagickImage ExecuteComplex(XmlElement element, IMagickImageCollection collection)
        {
            ComplexSettings complexSettings_ = CreateComplexSettings(element["complexSettings"]);

            collection.Complex(complexSettings_);
            return(null);
        }
        private IMagickImage ExecuteMorph(XmlElement element, IMagickImageCollection collection)
        {
            Int32 frames_ = Variables.GetValue <Int32>(element, "frames");

            collection.Morph(frames_);
            return(null);
        }
 public CWatchImage(string name, int index, IMagickImageCollection magickImageCollection)
 {
     Name                  = name;
     Index                 = index;
     MagickImage           = null;
     MagickImageCollection = magickImageCollection;
     HasAlpha              = false;
 }
                public void ShouldNotThrowExceptionWhenSettingsIsNull()
                {
                    IMagickFactory factory = new MagickFactory();

                    using (IMagickImageCollection images = factory.CreateCollection(Files.CirclePNG, null))
                    {
                        Assert.IsInstanceOfType(images, typeof(MagickImageCollection));
                    }
                }
                public void ShouldCreateMagickImage()
                {
                    IMagickFactory factory = new MagickFactory();

                    using (IMagickImageCollection images = factory.CreateCollection(Files.ImageMagickJPG))
                    {
                        Assert.IsInstanceOfType(images, typeof(MagickImageCollection));
                    }
                }
                public void ShouldNotThrowExceptionWhenSettingsIsNull()
                {
                    IMagickFactory factory = new MagickFactory();
                    var bytes = File.ReadAllBytes(Files.CirclePNG);

                    using (IMagickImageCollection image = factory.CreateCollection(bytes, 0, bytes.Length, null))
                    {
                    }
                }
 private static void Test_Read(IMagickImageCollection collection)
 {
     Assert.AreEqual(3, collection.Count);
     foreach (MagickImage image in collection)
     {
         Assert.AreEqual(70, image.Width);
         Assert.AreEqual(46, image.Height);
     }
 }
                public void ShouldCreateMagickImageCollection()
                {
                    IMagickFactory factory = new MagickFactory();
                    var data = File.ReadAllBytes(Files.ImageMagickJPG);

                    using (IMagickImageCollection images = factory.CreateCollection(data))
                    {
                        Assert.IsInstanceOfType(images, typeof(MagickImageCollection));
                    }
                }
        public void CreateCollection_ReturnsMagickImageCollection()
        {
            MagickFactory factory = new MagickFactory();

            using (IMagickImageCollection collection = factory.CreateCollection())
            {
                Assert.IsInstanceOfType(collection, typeof(MagickImageCollection));
                Assert.AreEqual(0, collection.Count);
            }
        }
Exemple #11
0
 public void ShouldReturnEmptyCollectionWhenCollectionIsEmpty()
 {
     using (IMagickImageCollection images = new MagickImageCollection())
     {
         using (IMagickImageCollection clones = images.Clone())
         {
             Assert.AreEqual(0, clones.Count);
         }
     }
 }
        public void CreateCollection_WithFileName_ReturnsMagickImageCollection()
        {
            MagickFactory factory = new MagickFactory();

            using (IMagickImageCollection collection = factory.CreateCollection(Files.RoseSparkleGIF))
            {
                Assert.IsInstanceOfType(collection, typeof(MagickImageCollection));
                Assert.AreEqual(3, collection.Count);
            }
        }
Exemple #13
0
        private static void WriteAndCheckProfile(IMagickImageCollection images, PsdWriteDefines defines, int expectedLength)
        {
            using (MemoryStream memStream = new MemoryStream())
            {
                images.Write(memStream, defines);

                memStream.Position = 0;
                images.Read(memStream);
                CheckProfile(images[1], expectedLength);
            }
        }
        public void CreateCollection_WithBytes_ReturnsMagickImageCollection()
        {
            var data = File.ReadAllBytes(Files.RoseSparkleGIF);

            MagickFactory factory = new MagickFactory();

            using (IMagickImageCollection collection = factory.CreateCollection(data))
            {
                Assert.IsInstanceOfType(collection, typeof(MagickImageCollection));
                Assert.AreEqual(3, collection.Count);
            }
        }
                public void ShouldThrowExceptionWhenCountIsNegative()
                {
                    IMagickFactory factory = new MagickFactory();
                    var settings = new MagickReadSettings();

                    ExceptionAssert.Throws<ArgumentException>("count", () =>
                    {
                        using (IMagickImageCollection images = factory.CreateCollection(new byte[] { 215 }, 0, -1, settings))
                        {
                        }
                    });
                }
                public void ShouldReadImage()
                {
                    IMagickFactory factory = new MagickFactory();
                    var fileBytes = File.ReadAllBytes(Files.SnakewarePNG);
                    var bytes = new byte[fileBytes.Length + 10];
                    fileBytes.CopyTo(bytes, 10);

                    using (IMagickImageCollection images = factory.CreateCollection(bytes, 10, bytes.Length - 10))
                    {
                        Assert.AreEqual(1, images.Count);
                    }
                }
Exemple #17
0
        /// <summary>
        /// Converts this instance to a <see cref="Bitmap"/> using <see cref="ImageFormat.Tiff"/>.
        /// </summary>
        /// <param name="self">The image collection.</param>
        /// <typeparam name="TQuantumType">The quantum type.</typeparam>
        /// <returns>A <see cref="Bitmap"/> that has the format <see cref="ImageFormat.Tiff"/>.</returns>
        public static Bitmap ToBitmap <TQuantumType>(this IMagickImageCollection <TQuantumType> self)
            where TQuantumType : struct
        {
            Throw.IfNull(nameof(self), self);

            if (self.Count == 1)
            {
                return(self[0].ToBitmap());
            }

            return(ToBitmap(self, ImageFormat.Tiff));
        }
Exemple #18
0
        private static void Test_Ping(IMagickImageCollection <QuantumType> collection)
        {
            Assert.AreEqual(1, collection.Count);

            ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                collection[0].GetPixels();
            });

            var profile = collection[0].Get8BimProfile();

            Assert.IsNotNull(profile);
        }
        private static void Test_Ping(IMagickImageCollection collection)
        {
            Assert.AreEqual(1, collection.Count);

            ExceptionAssert.Throws <InvalidOperationException>(delegate()
            {
                collection[0].GetPixels();
            });

            ImageProfile profile = collection[0].Get8BimProfile();

            Assert.IsNotNull(profile);
        }
                public void ShouldCreateMagickImageCollection()
                {
                    IMagickFactory factory = new MagickFactory();
                    var data = File.ReadAllBytes(Files.ImageMagickJPG);
                    var readSettings = new MagickReadSettings
                    {
                        BackgroundColor = MagickColors.Goldenrod,
                    };

                    using (IMagickImageCollection image = factory.CreateCollection(data, readSettings))
                    {
                        Assert.IsInstanceOfType(image, typeof(MagickImageCollection));
                    }
                }
        public void Test_Clone()
        {
            using (IMagickImageCollection collection = new MagickImageCollection())
            {
                collection.Add(Files.Builtin.Logo);
                collection.Add(Files.Builtin.Rose);
                collection.Add(Files.Builtin.Wizard);

                using (IMagickImageCollection clones = collection.Clone())
                {
                    Assert.AreEqual(collection[0], clones[0]);
                    Assert.AreEqual(collection[1], clones[1]);
                    Assert.AreEqual(collection[2], clones[2]);
                }
            }
        }
Exemple #22
0
            public void ShouldCloneTheImagesInTheCollection()
            {
                using (IMagickImageCollection images = new MagickImageCollection())
                {
                    images.Add(Files.Builtin.Logo);
                    images.Add(Files.Builtin.Rose);
                    images.Add(Files.Builtin.Wizard);

                    using (IMagickImageCollection clones = images.Clone())
                    {
                        Assert.IsFalse(ReferenceEquals(images[0], clones[0]));
                        Assert.IsFalse(ReferenceEquals(images[1], clones[1]));
                        Assert.IsFalse(ReferenceEquals(images[2], clones[2]));
                    }
                }
            }
        public void CreateCollection_WithFileNameAndSettings_ReturnsMagickImageCollection()
        {
            var readSettings = new MagickReadSettings
            {
                BackgroundColor = MagickColors.Firebrick,
            };

            MagickFactory factory = new MagickFactory();

            using (IMagickImageCollection collection = factory.CreateCollection(Files.RoseSparkleGIF, readSettings))
            {
                Assert.IsInstanceOfType(collection, typeof(MagickImageCollection));
                Assert.AreEqual(3, collection.Count);
                Assert.AreEqual(MagickColors.Firebrick, collection.First().Settings.BackgroundColor);
            }
        }
        public void CreateCollection_IEnumerableImages_ReturnsMagickImageCollection()
        {
            var image  = new MagickImage(Files.ImageMagickJPG);
            var images = new MagickImage[] { image };

            MagickFactory factory = new MagickFactory();

            using (IMagickImageCollection collection = factory.CreateCollection(images))
            {
                Assert.IsInstanceOfType(collection, typeof(MagickImageCollection));
                Assert.AreEqual(1, collection.Count);
                Assert.AreEqual(image, collection.First());
            }

            ExceptionAssert.Throws <ObjectDisposedException>(() =>
            {
                Assert.IsFalse(image.HasAlpha);
            });
        }
Exemple #25
0
        /// <summary>
        /// Converts this instance to a <see cref="Bitmap"/> using the specified <see cref="ImageFormat"/>.
        /// Supported formats are: Gif, Icon, Tiff.
        /// </summary>
        /// <param name="self">The image collection.</param>
        /// <param name="imageFormat">The image format.</param>
        /// <typeparam name="TQuantumType">The quantum type.</typeparam>
        /// <returns>A <see cref="Bitmap"/> that has the specified <see cref="ImageFormat"/>.</returns>
        public static Bitmap ToBitmap <TQuantumType>(this IMagickImageCollection <TQuantumType> self, ImageFormat imageFormat)
            where TQuantumType : struct
        {
            Throw.IfNull(nameof(self), self);
            Throw.IfNull(nameof(imageFormat), imageFormat);

            var format = imageFormat.ToFormat();

            foreach (var image in self)
            {
                image.Settings.Format = format;
            }

            var memStream = new MemoryStream();

            self.Write(memStream);
            memStream.Position = 0;
            /* Do not dispose the memStream, the bitmap owns it. */
            return(new Bitmap(memStream));
        }
        private IMagickImage ExecuteCombine(XmlElement element, IMagickImageCollection collection)
        {
            Hashtable arguments = new Hashtable();

            foreach (XmlAttribute attribute in element.Attributes)
            {
                arguments[attribute.Name] = Variables.GetValue <ColorSpace>(attribute);
            }
            if (arguments.Count == 0)
            {
                return(collection.Combine());
            }
            else if (OnlyContains(arguments, "colorSpace"))
            {
                return(collection.Combine((ColorSpace)arguments["colorSpace"]));
            }
            else
            {
                throw new ArgumentException("Invalid argument combination for 'combine', allowed combinations are: [] [colorSpace]");
            }
        }
        private IMagickImage ExecuteFlatten(XmlElement element, IMagickImageCollection collection)
        {
            Hashtable arguments = new Hashtable();

            foreach (XmlAttribute attribute in element.Attributes)
            {
                arguments[attribute.Name] = GetValue <MagickColor>(attribute);
            }
            if (arguments.Count == 0)
            {
                return(collection.Flatten());
            }
            else if (OnlyContains(arguments, "backgroundColor"))
            {
                return(collection.Flatten((MagickColor)arguments["backgroundColor"]));
            }
            else
            {
                throw new ArgumentException("Invalid argument combination for 'flatten', allowed combinations are: [] [backgroundColor]");
            }
        }
        private IMagickImage ExecuteQuantize(XmlElement element, IMagickImageCollection collection)
        {
            Hashtable arguments = new Hashtable();

            foreach (XmlElement elem in element.SelectNodes("*"))
            {
                arguments[elem.Name] = CreateQuantizeSettings(elem);
            }
            if (arguments.Count == 0)
            {
                collection.Quantize();
                return(null);
            }
            else if (OnlyContains(arguments, "settings"))
            {
                collection.Quantize((QuantizeSettings)arguments["settings"]);
                return(null);
            }
            else
            {
                throw new ArgumentException("Invalid argument combination for 'quantize', allowed combinations are: [] [settings]");
            }
        }
        private IMagickImage ExecuteSmushVertical(XmlElement element, IMagickImageCollection collection)
        {
            Int32 offset_ = Variables.GetValue <Int32>(element, "offset");

            return(collection.SmushVertical(offset_));
        }
        private IMagickImage ExecuteCollection(XmlElement element, IMagickImageCollection collection)
        {
            switch (element.Name[0])
            {
            case 'c':
            {
                switch (element.Name[2])
                {
                case 'a':
                {
                    return(ExecuteCoalesce(collection));
                }

                case 'm':
                {
                    return(ExecuteCombine(element, collection));
                }
                }
                break;
            }

            case 'd':
            {
                return(ExecuteDeconstruct(collection));
            }

            case 'm':
            {
                switch (element.Name[1])
                {
                case 'a':
                {
                    return(ExecuteMap(element, collection));
                }

                case 'o':
                {
                    switch (element.Name[2])
                    {
                    case 'r':
                    {
                        return(ExecuteMorph(element, collection));
                    }

                    case 'n':
                    {
                        return(ExecuteMontage(element, collection));
                    }

                    case 's':
                    {
                        return(ExecuteMosaic(collection));
                    }
                    }
                    break;
                }

                case 'e':
                {
                    return(ExecuteMerge(collection));
                }
                }
                break;
            }

            case 'o':
            {
                if (element.Name.Length == 8)
                {
                    return(ExecuteOptimize(collection));
                }
                switch (element.Name[8])
                {
                case 'P':
                {
                    return(ExecuteOptimizePlus(collection));
                }

                case 'T':
                {
                    return(ExecuteOptimizeTransparency(collection));
                }
                }
                break;
            }

            case 'q':
            {
                return(ExecuteQuantize(element, collection));
            }

            case 'r':
            {
                switch (element.Name[2])
                {
                case 'P':
                {
                    return(ExecuteRePage(collection));
                }

                case 'v':
                {
                    return(ExecuteReverse(collection));
                }
                }
                break;
            }

            case 't':
            {
                return(ExecuteTrimBounds(collection));
            }

            case 'a':
            {
                switch (element.Name[6])
                {
                case 'H':
                {
                    return(ExecuteAppendHorizontally(collection));
                }

                case 'V':
                {
                    return(ExecuteAppendVertically(collection));
                }
                }
                break;
            }

            case 'e':
            {
                return(ExecuteEvaluate(element, collection));
            }

            case 'f':
            {
                return(ExecuteFlatten(collection));
            }

            case 's':
            {
                switch (element.Name[5])
                {
                case 'H':
                {
                    return(ExecuteSmushHorizontal(element, collection));
                }

                case 'V':
                {
                    return(ExecuteSmushVertical(element, collection));
                }
                }
                break;
            }
            }
            throw new NotSupportedException(element.Name);
        }