/// <summary> /// /// </summary> /// <param name="image"></param> /// <returns></returns> public Accord.Imaging.UnmanagedImage Apply(Accord.Imaging.UnmanagedImage image) { return(Accord.Imaging.UnmanagedImage.FromManagedImage(Apply(image.ToManagedImage()))); }
/// <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); }
/// <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); }