Ejemplo n.º 1
0
        public void Test_Log()
        {
            using (IMagickImage image = new MagickImage(Files.SnakewarePNG))
            {
                int count = 0;
                EventHandler <LogEventArgs> logDelegate = delegate(object sender, LogEventArgs arguments)
                {
                    Assert.IsNull(sender);
                    Assert.IsNotNull(arguments);
                    Assert.AreNotEqual(LogEvents.None, arguments.EventType);
                    Assert.IsNotNull(arguments.Message);
                    Assert.AreNotEqual(0, arguments.Message.Length);

                    count++;
                };

                MagickNET.Log += logDelegate;

                image.Flip();
                Assert.AreEqual(0, count);

                MagickNET.SetLogEvents(LogEvents.All);

                image.Flip();
                Assert.AreNotEqual(0, count);

                MagickNET.Log -= logDelegate;
                count          = 0;

                image.Flip();
                Assert.AreEqual(0, count);
            }
        }
Ejemplo n.º 2
0
        public static void Flip(string path, FlipMode mode)
        {
            MagickImage img = IOUtils.ReadImage(path);

            if (img == null)
            {
                return;
            }
            if (mode == FlipMode.Hor)
            {
                img.Flop();
            }
            if (mode == FlipMode.Vert)
            {
                img.Flip();
            }
            if (mode == FlipMode.Random)
            {
                if (new Random().Next(2) == 0)
                {
                    img.Flip();
                }
                else
                {
                    img.Flop();
                }
            }
            img.Write(path);
        }
Ejemplo n.º 3
0
        private void Log_LogEventsAreSet_LogDelegateIsCalled()
        {
            using (IMagickImage image = new MagickImage(Files.SnakewarePNG))
            {
                int count = 0;
                EventHandler <LogEventArgs> logDelegate = (sender, arguments) =>
                {
                    Assert.IsNull(sender);
                    Assert.IsNotNull(arguments);
                    Assert.AreNotEqual(LogEvents.None, arguments.EventType);
                    Assert.IsNotNull(arguments.Message);
                    Assert.AreNotEqual(0, arguments.Message.Length);

                    count++;
                };

                MagickNET.Log += logDelegate;

                MagickNET.SetLogEvents(LogEvents.Detailed);

                image.Flip();
                Assert.AreNotEqual(0, count);

                MagickNET.Log -= logDelegate;
                count          = 0;

                image.Flip();
                Assert.AreEqual(0, count);
            }
        }
Ejemplo n.º 4
0
            private void ShouldCallLogDelegateWhenLogEventsAreSet()
            {
                using (var image = new MagickImage(Files.SnakewarePNG))
                {
                    int count = 0;
                    void LogDelegate(object sender, LogEventArgs arguments)
                    {
                        Assert.Null(sender);
                        Assert.NotNull(arguments);
                        Assert.NotEqual(LogEvents.None, arguments.EventType);
                        Assert.NotNull(arguments.Message);
                        Assert.NotEqual(0, arguments.Message.Length);

                        count++;
                    }

                    MagickNET.Log += LogDelegate;

                    MagickNET.SetLogEvents(LogEvents.Detailed);

                    image.Flip();

                    MagickNET.Log -= LogDelegate;

                    Assert.NotEqual(0, count);
                    count = 0;

                    image.Flip();
                    Assert.Equal(0, count);
                }
            }
        public string Execute(FileItem item, string infile, string dest, ValuePairEnumerator configData)
        {
            var conf = new RotateTransformViewModel(configData);

            // Read from file
            using (MagickImage image = new MagickImage(infile))
            {
                image.BackgroundColor = new MagickColor(Color.Black);
                if (conf.AutoRotate)
                {
                    ExifProfile profile = image.GetExifProfile();
                    image.AutoOrient();
                    profile.SetValue(ExifTag.Orientation, (UInt16)0);
                }
                if (conf.Angle > 0)
                {
                    image.Rotate(conf.Angle);
                }

                if (conf.FlipHorizontal)
                {
                    image.Flop();
                }

                if (conf.FlipVertical)
                {
                    image.Flip();
                }

                image.Format = MagickFormat.Jpeg;
                // Save the result
                image.Write(dest);
            }
            return(dest);
        }
Ejemplo n.º 6
0
        public static int Load(Stream stream)
        {
            using var image = new MagickImage(stream);
            var format = PixelFormat.Rgb;

            switch (image.ChannelCount)
            {
            case 3: break;

            case 4: format = PixelFormat.Rgba; break;

            default: throw new ArgumentOutOfRangeException("Unexpected image format");
            }
            image.Flip();
            var bytes  = image.GetPixelsUnsafe().ToArray();
            var handle = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, handle);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);

            GL.TexImage2D(TextureTarget.Texture2D, 0, (PixelInternalFormat)format, image.Width, image.Height, 0, format, PixelType.UnsignedByte, bytes);
            GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, 1);
            GL.BindTexture(TextureTarget.Texture2D, 0);
            return(handle);
        }
        public Texture2D(Stream stream, bool filterLinear = true, TextureFunction textureFunction = TextureFunction.MirroredRepeat)
        {
            using (var image = new MagickImage(stream))
            {
                var format = PixelFormat.Rgb;
                switch (image.ChannelCount)
                {
                case 3: break;

                case 4: format = PixelFormat.Rgba; break;

                default: throw new ArgumentOutOfRangeException("Unexpected image format");
                }

                image.Flip();
                var bytes = image.GetPixelsUnsafe().ToArray();
                TexturId = GL.GenTexture();
                Bind();
                GL.TexImage2D(Target, 0, (PixelInternalFormat)format, image.Width, image.Height, 0, format, PixelType.UnsignedByte, bytes);
                GL.TexParameter(Target, TextureParameterName.TextureWrapS, (int)textureFunction);
                GL.TexParameter(Target, TextureParameterName.TextureWrapT, (int)textureFunction);
                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                var filterMagMode = filterLinear ? TextureMagFilter.Linear : TextureMagFilter.Nearest;
                var filterMinMode = filterLinear ? TextureMinFilter.LinearMipmapLinear : TextureMinFilter.NearestMipmapNearest;
                GL.TexParameter(Target, TextureParameterName.TextureMagFilter, (int)filterMagMode);
                GL.TexParameter(Target, TextureParameterName.TextureMinFilter, (int)filterMinMode);
                Unbind();

                Width  = image.Width;
                Height = image.Height;
            }
        }
Ejemplo n.º 8
0
        private int LoadTexture()
        {
            var image          = new MagickImage(StrategyGame.Properties.Resources.FontBitmap);
            var format         = PixelFormat.Rgb;
            var internalFormat = PixelInternalFormat.Rgb;

            if (image.ChannelCount == 4)
            {
                internalFormat = PixelInternalFormat.Rgba;
                format         = PixelFormat.Rgba;
            }

            image.Rotate(-90);
            image.Flip();
            var bytes = image.GetPixelsUnsafe().ToArray();

            textureWidth  = image.Width;
            textureHeight = image.Height;

            int texObj = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, texObj);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);
            GL.TexImage2D(TextureTarget.Texture2D, 0, internalFormat, image.Width, image.Height, 0, format, PixelType.UnsignedByte, bytes);
            GL.BindTexture(TextureTarget.Texture2D, 0);

            return(texObj);
        }
Ejemplo n.º 9
0
 public bool Execute(WorkFlowCommand command, Context context)
 {
     if (context?.ImageStream == null)
     {
         return(true);
     }
     if (!CheckCondition(command, context))
     {
         return(true);
     }
     context.ImageStream.Seek(0, SeekOrigin.Begin);
     using (MagickImage image = new MagickImage(context.ImageStream))
     {
         context.ImageStream.Seek(0, SeekOrigin.Begin);
         if (command.Properties["Orientation"].Value == "Horizontal")
         {
             image.Flop();
         }
         else
         {
             image.Flip();
         }
         image.Write(context.ImageStream, MagickFormat.Jpg);
     }
     return(true);
 }
Ejemplo n.º 10
0
        private void RotateByExif(MagickImage image)
        {
            try
            {
                if (image.Orientation != OrientationType.Undefined)
                {
                    int index   = (int)image.Orientation - 1;
                    int degrees = RotationOperations[index][0];
                    if (degrees != 0)
                    {
                        image.Rotate(degrees);
                    }
                    switch (RotationOperations[index][1])
                    {
                    case Horizontal:
                        image.Flop();
                        break;

                    case Vertical:
                        image.Flip();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Error in RotateByExif:\n{ex.ToString()}");
                throw;
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Load a texture from the given stream.
        /// </summary>
        /// <param name="stream">A stream containing an image.</param>
        /// <returns>A Texture.</returns>
        public static Texture2D Load(Stream stream)
        {
            using var image = new MagickImage(stream);
            var format         = PixelFormat.Rgb;
            var internalFormat = (SizedInternalFormat)All.Rgb8;             //till OpenTK issue resolved on github https://github.com/opentk/opentk/issues/752

            switch (image.ChannelCount)
            {
            case 2: format = PixelFormat.Rg; internalFormat = SizedInternalFormat.Rg8; break;

            case 3: break;

            case 4: format = PixelFormat.Rgba; internalFormat = SizedInternalFormat.Rgba8; break;

            default: throw new InvalidDataException("Unexpected image format");
            }
            image.Flip();
            var bytes   = image.GetPixelsUnsafe().ToArray();
            var texture = new Texture2D(image.Width, image.Height, internalFormat)
            {
                Function  = TextureFunction.ClampToEdge,
                MagFilter = TextureMagFilter.Linear,
                MinFilter = TextureMinFilter.LinearMipmapLinear
            };

            GL.PixelStore(PixelStoreParameter.UnpackAlignment, 1);             // some image sizes will cause memory acceptions otherwise
            GL.TextureSubImage2D(texture.Handle, 0, 0, 0, image.Width, image.Height, format, PixelType.UnsignedByte, bytes);
            GL.GenerateTextureMipmap(texture.Handle);
            return(texture);
        }
Ejemplo n.º 12
0
        public void Haah()
        {
            MagickImage clone = new MagickImage(image);

            clone.Flip();
            clone.Extent(clone.Width, clone.Height / 2);
            image.Composite(clone, CompositeOperator.Over);

            clone.Dispose();
        }
Ejemplo n.º 13
0
 public override void Apply(MagickImage image)
 {
     if (Axis == Direction.Horizontal)
     {
         image.Flip();
     }
     if (Axis == Direction.Vertical)
     {
         image.Flop();
     }
 }
Ejemplo n.º 14
0
        public static void EncodeASTC(byte[] inputBytes, int width, int height, int block_xsize, int block_ysize, out byte[] dstBytes)
        {
            dstBytes = null;
            var tastcpath = Path.Combine(Environment.CurrentDirectory, "temp.astc");
            var ttgapath  = Path.Combine(Environment.CurrentDirectory, "temp.png");

            if (File.Exists(tastcpath))
            {
                File.Delete(tastcpath);
            }
            if (File.Exists(ttgapath))
            {
                File.Delete(ttgapath);
            }
            var settings = new MagickReadSettings
            {
                Format = MagickFormat.Rgba,
                Width  = width,
                Height = height
            };
            var im = new MagickImage(inputBytes, settings);

            im.Flip();
            im.ToBitmap().Save(ttgapath);
            if (File.Exists(ttgapath))
            {
                var process = new Process();
                process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
                process.StartInfo.FileName         = encoder;
                process.StartInfo.UseShellExecute  = false;
                process.StartInfo.Arguments        = string.Format(@"-c ""{0}"" ""{1}"" {2}x{3} -medium", ttgapath, tastcpath, block_xsize, block_ysize);
                Console.WriteLine(string.Format(@"-c ""{0}"" ""{1}"" {2}x{3} -medium", ttgapath, tastcpath, block_xsize, block_ysize));
                process.Start();
                process.WaitForExit();
            }

            if (File.Exists(tastcpath))
            {
                using (var fs = File.Open(tastcpath, FileMode.Open))
                {
                    dstBytes = new byte[(int)fs.Length - 0x10];
                    fs.Seek(0x10, SeekOrigin.Begin);
                    fs.Read(dstBytes, 0, (int)fs.Length - 0x10);
                }
            }
            if (File.Exists(tastcpath))
            {
                File.Delete(tastcpath);
            }
            if (File.Exists(ttgapath))
            {
                File.Delete(ttgapath);
            }
        }
Ejemplo n.º 15
0
        public void Haah()
        {
            for (int i = 0; i < image.Count; i++)
            {
                MagickImage clone = new MagickImage(image[i]);
                clone.Flip();
                clone.Extent(clone.Width, clone.Height / 2);
                image[i].Composite(clone, CompositeOperator.Over);

                clone.Dispose();
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Flip / flop MagickImage
        /// </summary>
        /// <param name="imgM"></param>
        /// <param name="isHorzontal"></param>
        /// <returns></returns>
        private static Bitmap Flip(MagickImage imgM, bool isHorzontal)
        {
            if (isHorzontal)
            {
                imgM.Flop();
            }
            else
            {
                imgM.Flip();
            }

            imgM.Quality = 100;

            return(imgM.ToBitmap());
        }
        public void Test_Dispose()
        {
            IMagickImage image = new MagickImage(MagickColors.Red, 10, 10);

            IMagickImageCollection collection = new MagickImageCollection();

            collection.Add(image);
            collection.Dispose();

            Assert.AreEqual(0, collection.Count);
            ExceptionAssert.Throws <ObjectDisposedException>(delegate()
            {
                image.Flip();
            });
        }
Ejemplo n.º 18
0
        public static void DecodeASTC(byte[] inputBytes, int width, int height, int block_xsize, int block_ysize, out byte[] dstBytes)
        {
            var tastcpath = Path.Combine(Environment.CurrentDirectory, "temp.astc");
            var ttgapath  = Path.Combine(Environment.CurrentDirectory, "temp.tga");

            if (File.Exists(tastcpath))
            {
                File.Delete(tastcpath);
            }
            if (File.Exists(ttgapath))
            {
                File.Delete(ttgapath);
            }
            dstBytes = null;
            GenerateASTCFile(inputBytes, width, height, block_xsize, block_ysize);
            if (File.Exists(tastcpath))
            {
                var process = new Process();
                process.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
                process.StartInfo.FileName         = encoder;
                process.StartInfo.UseShellExecute  = false;
                process.StartInfo.Arguments        = string.Format(@"-d ""{0}"" ""{1}""", tastcpath, ttgapath);
                Console.WriteLine(string.Format(@"-d ""{0}"" ""{1}""", tastcpath, ttgapath));
                process.Start();
                process.WaitForExit();
            }
            if (File.Exists(ttgapath))
            {
                Console.WriteLine("load temp png");
                using (var im = new MagickImage(ttgapath))
                {
                    im.Flip();
                    dstBytes = im.GetPixels().ToByteArray(0, 0, im.Width, im.Height, "RGBA");
                }
            }
            else
            {
                Console.WriteLine("ERR: astcenc.exe encoding error");
            }
            if (File.Exists(tastcpath))
            {
                File.Delete(tastcpath);
            }
            if (File.Exists(ttgapath))
            {
                File.Delete(ttgapath);
            }
        }
Ejemplo n.º 19
0
        private static void TEX2PNG(string input, string output, string resSPath = "")
        {
            byte[]    inputArray = File.ReadAllBytes(input);
            Texture2D texture    = new Texture2D(inputArray, resSPath);

            if (!texture.isTexture2D || texture.GetPixels() == null)
            {
                return;
            }

            Console.WriteLine("Reading: {0}\n Width: {1}\n Height: {2}\n Format: {3}\n Dimension: {4}\n Filter Mode: {5}\n Wrap Mode: {6}\n Mipmap: {7}",
                              input,
                              texture.width,
                              texture.height,
                              texture.format.ToString(),
                              texture.dimension.ToString(),
                              texture.filterMode.ToString(),
                              texture.wrapMode.ToString(),
                              texture.bMipmap);

            if (texture.format == TextureFormat.Alpha8 ||
                texture.format == TextureFormat.ARGB4444 ||
                texture.format == TextureFormat.RGBA4444 ||
                texture.format == TextureFormat.RGBA32 ||
                texture.format == TextureFormat.ARGB32 ||
                texture.format == TextureFormat.RGB24 ||
                texture.format == TextureFormat.RGB565 ||
                texture.format == TextureFormat.ETC_RGB4 ||
                texture.format == TextureFormat.ETC2_RGB ||
                texture.format == TextureFormat.ETC2_RGBA8 ||
                texture.format == TextureFormat.DXT5 ||
                texture.format == TextureFormat.DXT1 ||
                texture.format == TextureFormat.ASTC_RGBA_4x4 ||
                texture.format == TextureFormat.ASTC_RGB_4x4
                )
            {
                MagickReadSettings settings = new MagickReadSettings();
                settings.Format = MagickFormat.Rgba;
                settings.Width  = texture.width;
                settings.Height = texture.height;

                ImageMagick.MagickImage im = new MagickImage(texture.GetPixels(), settings);
                im.Flip();
                im.ToBitmap().Save(output);
            }
        }
Ejemplo n.º 20
0
        public static MagickImage ToMagickImage(this Sprite sprite)
        {
            var pixels = sprite.texture.GetPixels((int)sprite.rect.x, (int)sprite.rect.y, (int)sprite.rect.width, (int)sprite.rect.height);
            var bytes  = new byte[pixels.Length * 4];

            for (int i = 0; i < pixels.Length; i++)
            {
                bytes[i * 4 + 0] = (byte)(pixels[i].a * 255);
                bytes[i * 4 + 1] = (byte)(pixels[i].b * 255);
                bytes[i * 4 + 2] = (byte)(pixels[i].g * 255);
                bytes[i * 4 + 3] = (byte)(pixels[i].r * 255);
            }

            var img = new MagickImage(bytes, new PixelReadSettings((int)sprite.rect.width, (int)sprite.rect.height, StorageType.Char, PixelMapping.ABGR));

            img.Flip();
            return(img);
        }
Ejemplo n.º 21
0
        private void Log_LogEventsAreNotSet_LogDelegateIsNotCalled()
        {
            using (IMagickImage image = new MagickImage(Files.SnakewarePNG))
            {
                int count = 0;
                EventHandler <LogEventArgs> logDelegate = (sender, arguments) =>
                {
                    count++;
                };

                MagickNET.Log += logDelegate;

                image.Flip();
                Assert.AreEqual(0, count);

                MagickNET.Log -= logDelegate;
            }
        }
Ejemplo n.º 22
0
        public static Image Flip(Image input, bool horz)
        {
            var bmp = new Bitmap(input);

            using (var img = new MagickImage(bmp))
            {
                if (horz)
                {
                    img.Flop();
                }
                else
                {
                    img.Flip();
                }
                img.Quality = 100;
                return(img.ToBitmap());
            }
        }
Ejemplo n.º 23
0
            private void ShouldNotCallLogDelegeteWhenLogEventsAreNotSet()
            {
                using (var image = new MagickImage(Files.SnakewarePNG))
                {
                    int count = 0;
                    EventHandler <LogEventArgs> logDelegate = (sender, arguments) =>
                    {
                        count++;
                    };

                    MagickNET.Log += logDelegate;

                    image.Flip();

                    MagickNET.Log -= logDelegate;

                    Assert.AreEqual(0, count);
                }
            }
Ejemplo n.º 24
0
            private void ShouldNotCallLogDelegeteWhenLogEventsAreNotSet()
            {
                using (var image = new MagickImage(Files.SnakewarePNG))
                {
                    int count = 0;
                    void LogDelegate(object sender, LogEventArgs arguments)
                    {
                        count++;
                    }

                    MagickNET.Log += LogDelegate;

                    image.Flip();

                    MagickNET.Log -= LogDelegate;

                    Assert.Equal(0, count);
                }
            }
Ejemplo n.º 25
0
            private void ShouldStopCallingLogDelegateWhenLogDelegateIsRemoved()
            {
                using (var image = new MagickImage(Files.SnakewarePNG))
                {
                    int count = 0;
                    void LogDelegate(object sender, LogEventArgs arguments)
                    {
                        count++;
                    }

                    MagickNET.Log += LogDelegate;

                    MagickNET.SetLogEvents(LogEvents.Detailed);

                    MagickNET.Log -= LogDelegate;

                    image.Flip();
                    Assert.Equal(0, count);
                }
            }
Ejemplo n.º 26
0
            private void ShouldStopCallingLogDelegateWhenLogDelegateIsRemoved()
            {
                using (var image = new MagickImage(Files.SnakewarePNG))
                {
                    int count = 0;
                    EventHandler <LogEventArgs> logDelegate = (sender, arguments) =>
                    {
                        count++;
                    };

                    MagickNET.Log += logDelegate;

                    MagickNET.SetLogEvents(LogEvents.Detailed);

                    MagickNET.Log -= logDelegate;

                    image.Flip();
                    Assert.AreEqual(0, count);
                }
            }
Ejemplo n.º 27
0
        private void Log_LogDelegateIsRemove_LogDelegateIsNoLongerCalled()
        {
            using (IMagickImage image = new MagickImage(Files.SnakewarePNG))
            {
                int count = 0;
                EventHandler <LogEventArgs> logDelegate = delegate(object sender, LogEventArgs arguments)
                {
                    count++;
                };

                MagickNET.Log += logDelegate;

                MagickNET.SetLogEvents(LogEvents.All);

                MagickNET.Log -= logDelegate;

                image.Flip();
                Assert.AreEqual(0, count);
            }
        }
Ejemplo n.º 28
0
            public void ShouldNotStopMethodExecutionWhenCancelIsSetToFalse()
            {
                var progress = new Percentage(0);

                void ProgressEvent(object sender, ProgressEventArgs arguments)
                {
                    Assert.NotNull(sender);
                    Assert.NotNull(arguments);
                    Assert.NotNull(arguments.Origin);
                    Assert.False(arguments.Cancel);

                    progress         = arguments.Progress;
                    arguments.Cancel = false;
                }

                using (var image = new MagickImage(Files.Builtin.Logo))
                {
                    image.Progress += ProgressEvent;
                    image.Flip();
                }

                Assert.Equal(100, (int)progress);
            }
Ejemplo n.º 29
0
        public void FlipVertical()
        {
            foreach (KeyValuePair <string, Bitmap> entry in AllImages)
            {
                Bitmap bmp = entry.Value;

                ImageManipulator im = new ImageManipulator(bmp);
                MagickImage      mi = new MagickImage(bmp);

                im.Flip(true);
                mi.Flip();

                bool passed = BmpsAreEqual(im.ToBitmap(), mi.ToBitmap());

                if (!passed)
                {
                    im.ToBitmap().Save($"{BaseDir}\\TestOutput\\FlipVertical" + entry.Key + " ImageManipulator.png");
                    mi.ToBitmap().Save($"{BaseDir}\\TestOutput\\FlipVertical" + entry.Key + " MagickImage.png");
                }

                Assert.IsTrue(passed, $"{entry.Key} failed");
            }
        }
Ejemplo n.º 30
0
            public void ShouldStopMethodExecutionWhenCancelIsSetToTrue()
            {
                var progress = new Percentage(0);

                void ProgressEvent(object sender, ProgressEventArgs arguments)
                {
                    Assert.NotNull(sender);
                    Assert.NotNull(arguments);
                    Assert.NotNull(arguments.Origin);
                    Assert.False(arguments.Cancel);

                    progress         = arguments.Progress;
                    arguments.Cancel = true;
                }

                using (var image = new MagickImage(Files.Builtin.Logo))
                {
                    image.Progress += ProgressEvent;
                    image.Flip();
                    Assert.False(image.IsDisposed);
                }

                Assert.InRange((int)progress, 0, 2);
            }
		public void Test_Log()
		{
			using (MagickImage image = new MagickImage(Files.SnakewarePNG))
			{
				int count = 0;
				EventHandler<LogEventArgs> logDelegate = delegate(object sender, LogEventArgs arguments)
				{
					Assert.IsNull(sender);
					Assert.IsNotNull(arguments);
					Assert.AreNotEqual(ExceptionTypes.Undefined, arguments.EventType);
					Assert.IsNotNull(arguments.Message);
					Assert.AreNotEqual(0, arguments.Message.Length);

					count++;
				};

				GraphicsMagickNET.Log += logDelegate;

				image.Flip();
				Assert.AreEqual(0, count);

				GraphicsMagickNET.SetLogEvents(ExceptionTypes.All);

				image.Flip();
				Assert.AreNotEqual(0, count);

				GraphicsMagickNET.Log -= logDelegate;
				count = 0;

				image.Flip();
				Assert.AreEqual(0, count);
			}
		}