コード例 #1
0
        public override Image Apply(Image image)
        {
            GetParams(fm);

            if (!(image is Image))
            {
                return(image);
            }

            Rectangle region = new Rectangle(0, 0, ImgSrc.Width, ImgSrc.Height);

            if (Params.ContainsKey("CropRegion"))
            {
                region = (Rectangle)Params["CropRegion"].Value;
            }

            if (Params.ContainsKey("CropSide"))
            {
                var side = (SideType)Params["CropSide"].Value;
                region = Rectangle.Round(AddinUtils.AdjustRegion(region, ImgSrc, side));
            }

            if (region.Width > 0 && region.Height > 0)
            {
                Accord.Imaging.Filters.Crop filter = new Accord.Imaging.Filters.Crop(region);
                Bitmap dst = filter.Apply(AddinUtils.CloneImage(ImgSrc) as Bitmap);
                AddinUtils.CloneExif(ImgSrc, dst);
                return(dst);
            }
            else
            {
                return(ImgSrc);
            }
        }
コード例 #2
0
ファイル: Grayscale.cs プロジェクト: netcharm/PhotoTools
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        internal Image Gray(Image image, GrayscaleMode mode = GrayscaleMode.BT709, ColorMatrix cm = null, string cmfile = null)
        {
            #region Fill ColorMatrix List
            if (GrayscaleMatrix.Count == 0)
            {
                InitColorMatrix();
            }
            #endregion

            if (!GrayscaleMatrix.ContainsKey(mode))
            {
                return(image);
            }

            ImageAttributes a = new ImageAttributes();
            ColorMatrix     c = GrayscaleMatrix[mode];
            if (mode == GrayscaleMode.TestMatrix)
            {
                if (cm is ColorMatrix)
                {
                    c = cm;
                }
                else if (!string.IsNullOrEmpty(cmfile))
                {
                    c = LoadColorMatrix(cmfile);
                }
            }
            a.SetColorMatrix(c, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

            Bitmap src = AddinUtils.CloneImage(image) as Bitmap;
            if (src.PixelFormat != PixelFormat.Format32bppArgb)
            {
                src = Accord.Imaging.Image.Clone(src, PixelFormat.Format32bppArgb);
            }
            Bitmap dst = new Bitmap(src.Width, src.Height, src.PixelFormat);

            using (var g = Graphics.FromImage(dst))
            {
                g.SmoothingMode     = SmoothingMode.HighQuality;
                g.PixelOffsetMode   = PixelOffsetMode.Half;
                g.InterpolationMode = InterpolationMode.HighQualityBicubic;

                g.DrawImage(src,
                            new Rectangle(0, 0, src.Width, src.Height),
                            0, 0, src.Width, src.Height,
                            GraphicsUnit.Pixel,
                            a);
            }

            AddinUtils.CloneExif(src, dst);
            return(dst);
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Image Apply(Image image)
        {
            GetParams(fm);

            if (!(image is Image))
            {
                return(image);
            }

            Bitmap dst = AddinUtils.CloneImage(image) as Bitmap;

            BlurMode blurMode          = (BlurMode)Params["BlurMode"].Value;
            double   gaussianSigma     = (double)Params["GaussianSigma"].Value;
            int      gaussianSize      = (int)Params["GaussianSize"].Value;
            int      gaussianThreshold = (int)Params["GaussianThreshold"].Value;
            int      boxSize           = (int)Params["BoxSize"].Value;
            float    gdiRatio          = (float)Params["GdiRatio"].Value;

            Accord.Imaging.Filters.IFilter filter = null;
            switch (blurMode)
            {
            case BlurMode.Normal:
                filter = new Accord.Imaging.Filters.Blur();
                if (dst is Image)
                {
                    dst = (filter as Accord.Imaging.Filters.Blur).Apply(dst);
                }
                break;

            case BlurMode.Gaussian:
                filter = new Accord.Imaging.Filters.GaussianBlur();
                (filter as Accord.Imaging.Filters.GaussianBlur).Sigma     = gaussianSigma;
                (filter as Accord.Imaging.Filters.GaussianBlur).Size      = gaussianSize;
                (filter as Accord.Imaging.Filters.GaussianBlur).Threshold = gaussianThreshold;
                dst = filter.Apply(dst);
                break;

            case BlurMode.Box:
                filter = new Accord.Imaging.Filters.FastBoxBlur((byte)boxSize, (byte)boxSize);
                dst    = AddinUtils.ProcessImage(filter, dst, false);
                break;

            case BlurMode.GDI:
                var effect = new BlurEffect(gdiRatio, true);
                dst.ApplyEffect(effect, new Rectangle(0, 0, dst.Width, dst.Height));
                break;
            }
            AddinUtils.CloneExif(image, dst);
            return(dst);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Image Apply(Image image)
        {
            if (image is Image)
            {
                if (Params.Count == 0)
                {
                    InitParams();
                }

                RotateFlipType flip  = (RotateFlipType)Params["Mode"].Value;
                double         angle = Convert.ToDouble(Params["Angle"].Value);
                bool           keep  = Convert.ToBoolean(Params["KeepSize"].Value);

                Image dst = RotateForm.RotateImage(image, flip, angle, keep);
                AddinUtils.CloneExif(image, dst);
                return(dst);
            }
            return(image);
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Image Apply(Image image)
        {
            GetParams(fm);

            if (!(image is Image))
            {
                return(image);
            }

            Bitmap dst = AddinUtils.CloneImage(image) as Bitmap;

            InvertMode InvertMode = (InvertMode)Params["InvertMode"].Value;

            Accord.Imaging.Filters.Invert filter = new Accord.Imaging.Filters.Invert();
            dst = AddinUtils.ProcessImage(filter, dst, false) as Bitmap;

            AddinUtils.CloneExif(image, dst);
            return(dst);
        }
コード例 #6
0
ファイル: HueFilter.cs プロジェクト: netcharm/PhotoTools
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Image Apply(Image image)
        {
            GetParams(fm);

            if (!(image is Image))
            {
                return(image);
            }

            Bitmap dst = AddinUtils.CloneImage(image) as Bitmap;

            HueFilterMode HueFilterMode = (HueFilterMode)Params["HueFilterMode"].Value;
            int           value         = (int)Params["HueFilterValue"].Value;

            Accord.Imaging.Filters.HueModifier filter = new Accord.Imaging.Filters.HueModifier(value);
            dst = filter.Apply(dst);
            AddinUtils.CloneExif(image, dst);
            return(dst);
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Image Apply(Image image)
        {
            GetParams(fm);

            if (!(image is Image))
            {
                return(image);
            }

            Bitmap dst = AddinUtils.CloneImage(image) as Bitmap;

            SharpenMode sharpenMode       = (SharpenMode)Params["SharpenMode"].Value;
            double      gaussianSigma     = (double)Params["GaussianSigma"].Value;
            int         gaussianSize      = (int)Params["GaussianSize"].Value;
            int         gaussianThreshold = (int)Params["GaussianThreshold"].Value;
            float       gdiRatio          = (float)Params["GdiRatio"].Value;
            float       gdiAmount         = (float)Params["GdiAmount"].Value;

            Accord.Imaging.Filters.IFilter filter = null;
            switch (sharpenMode)
            {
            case SharpenMode.Normal:
                filter = new Accord.Imaging.Filters.Sharpen();
                dst    = (filter as Accord.Imaging.Filters.Sharpen).Apply(dst);
                break;

            case SharpenMode.Gaussian:
                filter = new Accord.Imaging.Filters.GaussianSharpen();
                (filter as Accord.Imaging.Filters.GaussianSharpen).Sigma     = gaussianSigma;
                (filter as Accord.Imaging.Filters.GaussianSharpen).Size      = gaussianSize;
                (filter as Accord.Imaging.Filters.GaussianSharpen).Threshold = gaussianThreshold;
                dst = filter.Apply(dst);
                break;

            case SharpenMode.GDI:
                var effect = new SharpenEffect(gdiRatio, gdiAmount);
                dst.ApplyEffect(effect, new Rectangle(0, 0, dst.Width, dst.Height));
                break;
            }
            AddinUtils.CloneExif(image, dst);
            return(dst);
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Image Apply(Image image)
        {
            GetParams(fm);

            if (!(image is Image))
            {
                return(image);
            }

            var st = DateTime.Now.Ticks;

            Bitmap dst = AddinUtils.CloneImage(image) as Bitmap;

            PinObjectMode PinObjectMode = (PinObjectMode)Params["PinObjectMode"].Value;
            bool          objectOnly    = (bool)Params["PinObjectOnly"].Value;
            PinOption     option        = (PinOption)Params["PinOption"].Value;

            switch (PinObjectMode)
            {
            case PinObjectMode.Picture:
                dst = DrawPicture(dst, option, objectOnly);
                break;

            case PinObjectMode.Text:
                dst = DrawText(dst, option, objectOnly);
                break;

            case PinObjectMode.Tag:
                break;
            }

            AddinUtils.CloneExif(image, dst);
            float tc = new TimeSpan(DateTime.Now.Ticks - st).Seconds + new TimeSpan(DateTime.Now.Ticks - st).Milliseconds / 1000f;

            Host.OnCommandPropertiesChange(new CommandPropertiesChangeEventArgs(AddinCommand.ApplyTiming, tc));
            return(dst);
        }
コード例 #9
0
ファイル: Grayscale.cs プロジェクト: netcharm/PhotoTools
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <param name="swap"></param>
        /// <returns></returns>
        internal Image Tawawa(Image image, bool dark = true, bool swap = false)
        {
            Bitmap src = AddinUtils.CloneImage(image) as Bitmap;

            if (image.PixelFormat != PixelFormat.Format32bppArgb)
            {
                src = Accord.Imaging.Image.Clone(image as Bitmap, PixelFormat.Format32bppArgb);
            }

            Accord.Imaging.UnmanagedImage dst = Accord.Imaging.UnmanagedImage.FromManagedImage(src);
            if (!dark && !swap)
            {
                #region Tawawa Blue
                for (int h = 0; h < dst.Height; h++)
                {
                    for (int w = 0; w < dst.Width; w++)
                    {
                        Color pcSrc = dst.GetPixel(w, h);

                        double y = 0;
                        y = pcSrc.R * 0.25 + pcSrc.G * 0.65 + pcSrc.B * 0.25;
                        y = y / 255 * 200 + 55;
                        if (y > 255)
                        {
                            y = 255;
                        }
                        int iy = (int)Math.Round(y);

                        int r = (int)Math.Round(iy > 85 ? ((y - 85) / 255 * 340) : 0);
                        int g = iy;
                        int b = iy > 135 ? 255 : g + 120;

                        Color pcDst = Color.FromArgb(pcSrc.A, r, g, b);
                        dst.SetPixel(w, h, pcDst);
                    }
                }
                #endregion
            }
            else if (dark && !swap)
            {
                #region Tawawa Dark Blue
                for (int h = 0; h < dst.Height; h++)
                {
                    for (int w = 0; w < dst.Width; w++)
                    {
                        Color pcSrc = dst.GetPixel(w, h);

                        double y = 0;
                        y = pcSrc.R * 0.25 + pcSrc.G * 0.60 + pcSrc.B * 0.15;
                        y = y / 255 * 200 + 55;
                        if (y > 255)
                        {
                            y = 255;
                        }
                        int iy = (int)Math.Round(y);

                        int r = (int)Math.Round(iy > 85 ? ((y - 85) / 255 * 340) : 0);
                        int g = iy;
                        int b = iy > 135 ? 255 : g + 120;

                        Color pcDst = Color.FromArgb(pcSrc.A, r, g, b);
                        dst.SetPixel(w, h, pcDst);
                    }
                }
                #endregion
            }
            else if (!dark && swap)
            {
                #region Tawawa Orange
                for (int h = 0; h < dst.Height; h++)
                {
                    for (int w = 0; w < dst.Width; w++)
                    {
                        Color pcSrc = dst.GetPixel(w, h);

                        double y = 0;
                        y = pcSrc.R * 0.33 + pcSrc.G * 0.55 + pcSrc.B * 0.20;
                        y = y / 255 * 200 + 55;
                        if (y > 255)
                        {
                            y = 255;
                        }
                        int iy = (int)Math.Round(y);

                        int r = (int)Math.Round(iy > 85 ? ((y - 85) / 255 * 340) : 0);
                        int g = iy;
                        int b = iy > 135 ? 255 : g + 120;

                        Color pcDst = Color.FromArgb(pcSrc.A, b, g, r);
                        dst.SetPixel(w, h, pcDst);
                    }
                }
                #endregion
            }
            else
            {
                #region Tawawa Dark Orange
                for (int h = 0; h < dst.Height; h++)
                {
                    for (int w = 0; w < dst.Width; w++)
                    {
                        Color  pcSrc = dst.GetPixel(w, h);
                        double y     = 0;
                        y = pcSrc.R * 0.3 + pcSrc.G * 0.59 + pcSrc.B * 0.11;
                        y = y / 255 * 200 + 55;
                        if (y > 255)
                        {
                            y = 255;
                        }
                        int iy = (int)Math.Round(y);

                        int r = (int)Math.Round(iy > 85 ? ((y - 85) / 255 * 340) : 0);
                        int g = iy;
                        int b = iy > 135 ? 255 : g + 120;

                        Color pcDst = Color.FromArgb(pcSrc.A, b, g, r);
                        dst.SetPixel(w, h, pcDst);
                    }
                }
                #endregion
            }

            Bitmap dstBmp = dst.ToManagedImage();
            //var filter = new Accord.Imaging.Filters.BrightnessCorrection(10);
            //filter.ApplyInPlace( dstBmp );

            AddinUtils.CloneExif(image, dstBmp);
            src.Dispose();
            dst.Dispose();
            return(dstBmp);
        }
コード例 #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="img"></param>
        /// <param name="flip"></param>
        /// <param name="angle"></param>
        /// <param name="keep"></param>
        /// <returns></returns>
        internal protected static Image RotateImage(Image img, RotateFlipType flip, double angle, bool keep)
        {
            if (img != null)
            {
                Image  dst      = AddinUtils.CloneImage(img) as Image;
                double angleNew = angle;
                if (angleNew < 0)
                {
                    angleNew = 360 + angleNew;
                }

                if (angleNew == 0)
                {
                    dst.RotateFlip(flip);
                    return(dst);
                }
                else if (angleNew % 90 == 0)
                {
                    RotateFlipType flipT = RotateFlipType.RotateNoneFlipNone;
                    if (angleNew % 360 == 000)
                    {
                        flipT = RotateFlipType.RotateNoneFlipNone;
                    }
                    else if (angleNew % 360 == 090)
                    {
                        flipT = RotateFlipType.Rotate90FlipNone;
                    }
                    else if (angleNew % 360 == 180)
                    {
                        flipT = RotateFlipType.Rotate180FlipNone;
                    }
                    else if (angleNew % 360 == 270)
                    {
                        flipT = RotateFlipType.Rotate270FlipNone;
                    }

                    dst.RotateFlip(flipT);
                    return(dst);
                }
                else
                {
                    if (keep)
                    {
                        double a = Math.Abs(angleNew);
                        if (0 < a && a < 45)
                        {
                            //
                        }
                        else if (45 < a && a < 135)
                        {
                            RotateFlipType flipT = RotateFlipType.Rotate90FlipNone;
                            dst.RotateFlip(flipT);
                            angleNew = a - 90;
                        }
                        else if (135 < a && a < 225)
                        {
                            //
                        }
                        else if (225 < a && a < 315)
                        {
                            RotateFlipType flipT = RotateFlipType.Rotate270FlipNone;
                            dst.RotateFlip(flipT);
                            angleNew = a - 270;
                        }
                        else if (315 < a && a < 360)
                        {
                            //
                        }
                    }
                    RotateBicubic filter = new RotateBicubic(-angleNew, keep);
                    dst = AddinUtils.ProcessImage(filter, dst);

                    if (!AddinUtils.AlphaFormat.Contains(dst.PixelFormat))
                    {
                        dst = AddinUtils.MakeAlphaRotate(img as Bitmap, dst as Bitmap, (float)angleNew);
                    }

                    AddinUtils.CloneExif(img, dst);
                    return(dst);
                }
            }
            return(img);
        }
コード例 #11
0
ファイル: HslFilter.cs プロジェクト: netcharm/PhotoTools
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <returns></returns>
        public override Image Apply(Image image)
        {
            GetParams(fm);

            if (!(image is Image))
            {
                return(image);
            }

            Bitmap dst = AddinUtils.CloneImage(image) as Bitmap;

            HslFilterMode HslFilterMode = (HslFilterMode)Params["HslFilterMode"].Value;
            GrayscaleMode grayscaleMode = (GrayscaleMode)Params["GrayscaleMode"].Value;
            int           hueValue      = (int)Params["HslHue"].Value;
            float         satValue      = (float)Params["HslSaturation"].Value;
            float         lumValue      = (float)Params["HslLuminance"].Value;
            float         tolValue      = (float)Params["HslTolerance"].Value;
            float         factor_n      = 1 - tolValue / 100;
            float         factor_p      = 1 + tolValue / 100;

            //
            // your filter codes begin
            //
            Accord.Imaging.Filters.HSLFiltering filter = new Accord.Imaging.Filters.HSLFiltering();
            filter.Hue        = new Accord.IntRange((int)Math.Round(hueValue * factor_n), (int)Math.Round(hueValue * factor_p));
            filter.Saturation = new Accord.Range(satValue * factor_n, satValue * factor_p);
            filter.Luminance  = new Accord.Range(lumValue * factor_n, lumValue * factor_p);
            //filter.FillColor = new Accord.Imaging.HSL( hueValue, satValue, lumValue );
            //filter.FillOutsideRange = false;
            filter.FillColor        = new Accord.Imaging.HSL(hueValue, 0.0f, lumValue);
            filter.FillOutsideRange = true;

            //
            // your filter codes end
            //
            //dst = AddinUtils.ProcessImage( filter, dst, false );
            dst = filter.Apply(dst);
            dst = Accord.Imaging.Image.Clone(dst as Bitmap, PixelFormat.Format32bppArgb);
            Accord.Imaging.UnmanagedImage uimg = Accord.Imaging.UnmanagedImage.FromManagedImage(dst);
            Color fc = filter.FillColor.ToRGB().Color;

            for (int y = 0; y < uimg.Height; y++)
            {
                for (int x = 0; x < uimg.Width; x++)
                {
                    if (uimg.GetPixel(x, y) == fc)
                    {
                        uimg.SetPixel(x, y, Color.Transparent);
                    }
                }
            }
            dst = uimg.ToManagedImage();

            IAddin gfilter = Host.Effects["Grayscale"];
            Dictionary <string, ParamItem> oldParams = gfilter.Params;
            object data = null;

            gfilter.Command(AddinCommand.InitParams, out data,
                            new Dictionary <string, object>()
            {
                { "GrayscaleMode", grayscaleMode }
            }
                            );

            var gimg = gfilter.Apply(image);

            gfilter.Command(AddinCommand.SetParams, out data, oldParams);

            using (var g = Graphics.FromImage(gimg))
            {
                g.DrawImage(dst, 0, 0, dst.Width, dst.Height);
            }
            dst = gimg as Bitmap;

            AddinUtils.CloneExif(image, dst);
            return(dst);
        }