Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void ResizeToImage(bool source)
        {
            try
            {
                var action = false;

                var image_s = ImageSource.GetInformation();
                var image_t = ImageTarget.GetInformation();
                if (image_s.ValidCurrent && image_t.ValidCurrent)
                {
                    var s_image = source ? image_s.Current : image_t.Current;
                    var t_image = source ? image_t.Current : image_s.Current;
                    if (s_image.Width == t_image.Width || s_image.Height == t_image.Height)
                    {
                        s_image.Extent(t_image.Width, t_image.Height, Gravity.Center, MasklightColor ?? MagickColors.Transparent);
                    }
                    else
                    {
                        s_image.Scale(t_image.Width, t_image.Height);
                    }
                    s_image.RePage();
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void SetAlphaToColorImage(bool source)
        {
            try
            {
                var action = false;
                var radius = WeakEffects ? 5 : 10;
                var sigma  = WeakEffects ? 0.25 : 0.5;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    if (image.Current.ColorFuzz.ToDouble() != ImageCompareFuzzy.Value)
                    {
                        image.Current.ColorFuzz = new Percentage(ImageCompareFuzzy.Value);
                    }
                    var alpha = new MagickImage(MasklightColor ?? image.Current.BackgroundColor, image.Current.Width, image.Current.Height);
                    image.Current.Composite(alpha, CompositeOperator.ChangeMask);
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void CropImage(bool source)
        {
            try
            {
                var action = false;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    if (SimpleTrimCropBoundingBox)
                    {
                        image.Current.Trim();
                    }
                    else
                    {
                        var box = image.Current.CalcBoundingBox();
                        if (box == null)
                        {
                            image.Current.Trim();
                        }
                        else
                        {
                            image.Current.Crop(box);
                        }
                    }
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void CreateColorImage(bool source, bool sendto = false)
        {
            try
            {
                var action = false;

                var image_s = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                var image_t = source ? ImageTarget.GetInformation() : ImageSource.GetInformation();
                if (image_s.ValidCurrent)
                {
                    if (image_s.Current.ColorFuzz.ToDouble() != ImageCompareFuzzy.Value)
                    {
                        image_s.Current.ColorFuzz = new Percentage(ImageCompareFuzzy.Value);
                    }
                    if (sendto)
                    {
                        image_t.Current = new MagickImage(MasklightColor ?? image_s.Current.MatteColor ?? image_s.Current.BackgroundColor,
                                                          image_s.Current.Width, image_s.Current.Height);
                    }
                    else
                    {
                        image_s.Current = new MagickImage(MasklightColor ?? image_s.Current.MatteColor ?? image_s.Current.BackgroundColor,
                                                          image_s.Current.Width, image_s.Current.Height);
                    }
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void AutoWhiteBalanceImage(bool source)
        {
            try
            {
                var action  = false;
                var enhance = new Percentage(10);

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    if (WeakEffects)
                    {
                        image.Current.WhiteBalance();
                    }
                    else
                    {
                        image.Current.WhiteBalance(enhance);
                    }
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void SetColorToAlphaImage(bool source)
        {
            try
            {
                var action = false;
                var radius = WeakEffects ? 5 : 10;
                var sigma  = WeakEffects ? 0.25 : 0.5;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    if (image.Current.ColorFuzz.ToDouble() != ImageCompareFuzzy.Value)
                    {
                        image.Current.ColorFuzz = new Percentage(ImageCompareFuzzy.Value);
                    }
                    if (image.Current.HasAlpha)
                    {
                        image.Current.ColorAlpha(MasklightColor ?? image.Current.BackgroundColor);
                        action = true;
                    }
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void RemapImage(bool source)
        {
            try
            {
                var action = false;
                var colors = WeakEffects ? 32768 : 65536;
                var dither = WeakEffects ? DitherMethod.No :  DitherMethod.Riemersma;
                var depth  = WeakEffects ? 3 : 7;

                var image_s = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                var image_t = source ? ImageTarget.GetInformation() : ImageSource.GetInformation();
                if (image_s.ValidCurrent && image_t.ValidCurrent)
                {
                    var err = image_s.Current.Map(image_t.Current, new QuantizeSettings()
                    {
                        MeasureErrors = true,
                        Colors        = colors,
                        ColorSpace    = ColorSpace.sRGB,
                        DitherMethod  = dither,
                        TreeDepth     = depth
                    });
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #8
0
        /// <summary>
        ///
        /// </summary>
        private void CleanImage()
        {
            ImageSource.GetInformation().Dispose();
            ImageTarget.GetInformation().Dispose();
            ImageResult.GetInformation().Dispose();

            if (ImageSource.Source != null)
            {
                ImageSource.Source = null;
            }
            if (ImageTarget.Source != null)
            {
                ImageTarget.Source = null;
            }
            if (ImageResult.Source != null)
            {
                ImageResult.Source = null;
            }

            ImageSource.ToolTip = null;
            ImageTarget.ToolTip = null;
            ImageResult.ToolTip = null;

            GC.Collect();
            GC.WaitForPendingFinalizers();
            GC.WaitForFullGCComplete();
        }
Example #9
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="source"></param>
 private void CopyImage(bool source)
 {
     try
     {
         var src = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
         src.CopyToClipboard();
     }
     catch (Exception ex) { ex.ShowMessage(); }
 }
Example #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        private MagickImage GetImage(ImageType type)
        {
            MagickImage result = null;

            if (type != ImageType.Result)
            {
                bool source = type == ImageType.Source ? true : false;
                result = source ? ImageSource.GetInformation().Current : ImageTarget.GetInformation().Current;
            }
            else
            {
                result = ImageResult.GetInformation().Current;
            }
            return(result);
        }
Example #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        /// <param name="vertical"></param>
        private void SlicingImage(bool source, bool vertical, bool sendto = true, bool first = true)
        {
            try
            {
                var action = false;

                var image_s = ImageSource.GetInformation();
                var image_t = ImageTarget.GetInformation();
                var image   = source ? image_s : image_t;
                if (image.ValidCurrent)
                {
                    var geometry = vertical ? new MagickGeometry(new Percentage(50), new Percentage(100)) : new MagickGeometry(new Percentage(100), new Percentage(50));
                    var result   = image.Current.CropToTiles(geometry);
                    if (result.Count() >= 2)
                    {
                        if (sendto)
                        {
                            image_s.Current = new MagickImage(result.FirstOrDefault());
                            image_s.Current.RePage();
                            image_t.Current = new MagickImage(result.Skip(1).Take(1).FirstOrDefault());
                            image_t.Current.RePage();
                        }
                        else
                        {
                            if (first)
                            {
                                image.Current = new MagickImage(result.FirstOrDefault());
                            }
                            else
                            {
                                image.Current = new MagickImage(result.Skip(1).Take(1).FirstOrDefault());
                            }
                            image.Current.RePage();
                        }
                        action = true;
                    }
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void GrayscaleImage(bool source)
        {
            try
            {
                var action = false;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    image.Current.Grayscale(); action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #13
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="source"></param>
 private void ChangeColorSpace(bool?source = null)
 {
     try
     {
         if (source == null)
         {
             ImageSource.GetInformation().ChangeColorSpace(CompareImageForceColor);
             ImageTarget.GetInformation().ChangeColorSpace(CompareImageForceColor);
         }
         else if (source ?? false)
         {
             ImageSource.GetInformation().ChangeColorSpace(CompareImageForceColor);
         }
         else
         {
             ImageTarget.GetInformation().ChangeColorSpace(CompareImageForceColor);
         }
     }
     catch (Exception ex) { ex.ShowMessage(); }
 }
Example #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void ClutImage(bool source)
        {
            try
            {
                var action = false;

                var image_s = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                var image_t = source ? ImageTarget.GetInformation() : ImageSource.GetInformation();
                if (image_s.ValidCurrent && image_t.ValidCurrent)
                {
                    image_s.Current.Clut(image_t.Current, PixelInterpolateMethod.Spline, CompareImageChannels);
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void BlueShiftImage(bool source)
        {
            try
            {
                var action = false;
                var radius = WeakEffects ? 0.75 : 1.05;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    image.Current.BlueShift(radius);
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void ResetImage(bool source)
        {
            try
            {
                var action = false;
                if (source)
                {
                    action = ImageSource.GetInformation().ResetTransform();
                }
                else
                {
                    action = ImageTarget.GetInformation().ResetTransform();
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void PosterizeImage(bool source)
        {
            try
            {
                var action = false;
                var levels = WeakEffects ? 32 : 16;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    image.Current.Posterize(levels, DitherMethod.Riemersma, CompareImageChannels);
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void PolaroidImage(bool source)
        {
            try
            {
                var    action = false;
                double angle  = WeakEffects ? 3 : 5;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    image.Current.Polaroid("❤❤", angle, PixelInterpolateMethod.Spline);
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void AutoVignetteImage(bool source)
        {
            try
            {
                var action = false;
                var radios = WeakEffects ? 50.0 : 150.0;
                var sigma  = WeakEffects ? 64 : 64;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    image.Current.Vignette((new double[] { radios / 2.0, image.Current.Width, image.Current.Height }).Min(), sigma, 5, 5);
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #20
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void CharcoalImage(bool source)
        {
            try
            {
                var action = false;
                var radius = WeakEffects ? 3 : 7;
                var sigma  = WeakEffects ? 0.25 : 0.5;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    image.Current.Charcoal(radius, sigma);
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void BlurImage(bool source)
        {
            try
            {
                var action = false;
                var radius = WeakBlur ? 5 : 10;
                var sigma  = WeakBlur ? 0.75 : 1.5;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    image.Current.GaussianBlur(radius, sigma);
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #22
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void AutoThresholdImage(bool source)
        {
            try
            {
                var action = false;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    image.Current.AutoThreshold(AutoThresholdMethod.OTSU);
                    image.Current.ColorSpace = ColorSpace.Gray;
                    image.Current.ColorType  = ColorType.Palette;
                    image.Current.Depth      = 8;
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void FillOutBoundBoxImage(bool source)
        {
            try
            {
                var action = false;
                var radius = WeakEffects ? 5 : 10;
                var sigma  = WeakEffects ? 0.25 : 0.5;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    if (image.Current.ColorFuzz.ToDouble() != ImageCompareFuzzy.Value)
                    {
                        image.Current.ColorFuzz = new Percentage(ImageCompareFuzzy.Value);
                    }
                    image.Current.BackgroundColor = MasklightColor ?? MagickColors.Transparent;
                    if (image.LastClickPos == null)
                    {
                        image.Current.FloodFill(MasklightColor ?? MagickColors.Transparent, 1, 1);
                        image.Current.FloodFill(MasklightColor ?? MagickColors.Transparent, image.Current.Width - 2, 1);
                        image.Current.FloodFill(MasklightColor ?? MagickColors.Transparent, image.Current.Width - 2, image.Current.Height - 2);
                        image.Current.FloodFill(MasklightColor ?? MagickColors.Transparent, 1, image.Current.Height - 2);
                    }
                    else
                    {
                        image.Current.FloodFill(MasklightColor ?? MagickColors.Transparent, image.LastClickPos ?? image.DefaultOrigin);
                    }
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void KmeansImage(bool source)
        {
            try
            {
                var action = false;
                var sigma  = WeakEffects ? 16 : 8;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    image.Current.Kmeans(new KmeansSettings()
                    {
                        Tolerance = sigma, NumberColors = 64, MaxIterations = 100
                    });
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void SharpImage(bool source)
        {
            try
            {
                var action    = false;
                var radius    = 5;
                var sigma     = WeakSharp ? 0.25 : 0.35;
                var amount    = 15;
                var threshold = 0;

                var image = source ? ImageSource.GetInformation() : ImageTarget.GetInformation();
                if (image.ValidCurrent)
                {
                    image.Current.UnsharpMask(radius, sigma, amount, threshold);
                    action = true;
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }
Example #26
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="source"></param>
        private void ScaleImage(MagickGeometry geomatry = null, bool?source = null)
        {
            try
            {
                var action = false;

                var image_s = ImageSource.GetInformation();
                var image_t = ImageTarget.GetInformation();
                if (source == null)
                {
                    if (geomatry is MagickGeometry)
                    {
                        if (image_s.ValidCurrent)
                        {
                            image_s.Current.Resize(geomatry); image_s.Current.RePage(); action = true;
                        }
                        if (image_t.ValidCurrent)
                        {
                            image_t.Current.Resize(geomatry); image_t.Current.RePage(); action = true;
                        }
                    }
                    else
                    {
                        action |= image_s.Reload();
                        action |= image_t.Reload();
                    }
                }
                else if (source ?? false)
                {
                    if (geomatry is MagickGeometry)
                    {
                        if (image_s.ValidCurrent)
                        {
                            image_s.Current.Resize(geomatry); image_s.Current.RePage(); action = true;
                        }
                    }
                    else
                    {
                        action |= image_s.Reload();
                    }
                }
                else
                {
                    if (geomatry is MagickGeometry)
                    {
                        if (image_t.ValidCurrent)
                        {
                            image_t.Current.Resize(geomatry); image_t.Current.RePage(); action = true;
                        }
                    }
                    else
                    {
                        action |= image_t.Reload();
                    }
                }

                if (action)
                {
                    UpdateImageViewer(compose: LastOpIsCompose, assign: true, reload: false);
                }
            }
            catch (Exception ex) { ex.ShowMessage(); }
        }