Пример #1
0
        private static void SetEffect(string shapeName, eEffect effect, Primitive properties)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Dictionary <string, UIElement> _objectsMap;
            UIElement obj;

            try
            {
                ExtractDll();

                _objectsMap = (Dictionary <string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    Delegates delegates = new Delegates(new object[] { effect, properties, obj });
                    FastThread.BeginInvoke(delegates.SetEffect_Delegate);
                }
                else
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
        }
Пример #2
0
        // Public methods.
        public void LoadLevel(string in_loadingLevelName, bool in_isLoadingAdditive, eEffect in_effect, LoadingScreenDelegate in_onLoadingBegin, LoadingScreenDelegate in_onLoadingEnd)
        {
            m_sLoadingLevelName = in_loadingLevelName;
            m_bLoadingAdditive  = in_isLoadingAdditive;

            m_onLoadingBegin = in_onLoadingBegin;
            m_onLoadingEnd   = in_onLoadingEnd;

            m_eEffect = in_effect;

            switch (m_eEffect)
            {
            case eEffect.Black:
            {
                BaseObject.gameObject.SetActive(true);
                ChangeLoadingState();
            }
            break;

            case eEffect.Invalid:
            {
                ChangeLoadingState();
            }
            break;

            case eEffect.BlackFade:
                //GOverlayMgr.GetInstance().SetEffect( new GOverlayMgr.EffectInfo(GOverlayMgr.eEffect.FadeInLoading, BLACK_FADE_EFFECT_TIME, Color.black, 0.0f) );
                ChangeState(eState.BlackFadeIn);
                break;
            }
        }
Пример #3
0
    public void PlayEffect(eEffect type)
    {
        this.transform.position = m_tfCharacter.position;

        switch (type)
        {
        case eEffect.eLevelUp:
            this.transform.position += new Vector3(0f, -0.4f, 0f);
            break;
        }

        ParticleSystem pts = GetEffect(type);

        if (pts.isPlaying == true)
        {
            pts.Stop();
        }
        pts.Play();
    }
Пример #4
0
        public static System.Drawing.Image DoEffect(System.Drawing.Image _dImg, eEffect _effect, Primitive parameter)
        {
            if (_effect == eEffect.NONE || null == _dImg) return _dImg;

            System.Drawing.Bitmap bmap = new System.Drawing.Bitmap(_dImg);

            switch (_effect)
            {
                case eEffect.NONE: //None
                    break;
                case eEffect.RED: //Red
                    {
                        System.Drawing.Color c;
                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);
                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, c.R, 0, 0));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.GREEN: //Green
                    {
                        System.Drawing.Color c;
                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);
                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, 0, c.G, 0));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.BLUE: //Blue
                    {
                        System.Drawing.Color c;
                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);
                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, 0, 0, c.B));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.GRAY: //Gray
                    {
                        System.Drawing.Color c;
                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);
                                byte gray = (byte)(.299 * c.R + .587 * c.G + .114 * c.B);
                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, gray, gray, gray));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.INVERSE: //Inverse
                    {
                        FastPixel fp = new FastPixel(bmap);
                        System.Drawing.Color c;
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);
                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, 255 - c.R, 255 - c.G, 255 - c.B));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.YELLOW: //Yellow
                    {
                        System.Drawing.Color c;
                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);
                                byte gray = (byte)(.299 * c.R + .587 * c.G + .114 * c.B);
                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, gray, gray, 0));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.CYAN: //Cyan
                    {
                        System.Drawing.Color c;
                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);
                                byte gray = (byte)(.299 * c.R + .587 * c.G + .114 * c.B);
                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, 0, gray, gray));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.MAGENTA: //Magenta
                    {
                        System.Drawing.Color c;
                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);
                                byte gray = (byte)(.299 * c.R + .587 * c.G + .114 * c.B);
                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, gray, 0, gray));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.SNOW: //Snow
                    {
                        double density = parameter;
                        if (density <= 0) density = pEffect[(int)_effect];
                        Random rand = new Random();
                        System.Drawing.Color c;
                        int i, j;
                        FastPixel fp = new FastPixel(bmap);
                        for (int ii = 0; ii < fp.Width * fp.Height / density; ii++)
                        {
                            i = rand.Next(fp.Width);
                            j = rand.Next(fp.Height);
                            c = fp.GetPixel(i, j);
                            fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, 255, 255, 255));
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.FUZZY: //Fuzzy
                    {
                        Random rand = new Random();
                        System.Drawing.Color c;
                        System.Drawing.Bitmap copy = (System.Drawing.Bitmap)bmap.Clone();
                        FastPixel fpCopy = new FastPixel(copy);
                        int ii, jj;
                        int x = parameter;
                        if (x <= 0) x = pEffect[(int)_effect];
                        int y = 2 * x + 1;
                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                ii = System.Math.Max(0, System.Math.Min(fp.Width - 1, i + rand.Next(y) - x));
                                jj = System.Math.Max(0, System.Math.Min(fp.Height - 1, j + rand.Next(y) - x));
                                c = fpCopy.GetPixel(ii, jj);
                                fp.SetPixel(i, j, c);
                            }
                        }
                        fpCopy.Unlock(false);
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.CONTRAST: //Contrast
                    {
                        double contrast = parameter;
                        if (contrast <= 0) contrast = pEffect[(int)_effect];
                        System.Drawing.Color c;
                        double R, G, B;

                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);

                                R = c.R / 255.0 - 0.5;
                                R = R >= 0 ? System.Math.Pow(R, 1.0 / contrast) : -System.Math.Pow(-R, 1.0 / contrast);
                                R = 255 * (R + 0.5);
                                R = System.Math.Max(0, System.Math.Min(255, R));

                                G = c.G / 255.0 - 0.5;
                                G = G >= 0 ? System.Math.Pow(G, 1.0 / contrast) : -System.Math.Pow(-G, 1.0 / contrast);
                                G = 255 * (G + 0.5);
                                G = System.Math.Max(0, System.Math.Min(255, G));

                                B = c.B / 255.0 - 0.5;
                                B = B >= 0 ? System.Math.Pow(B, 1.0 / contrast) : -System.Math.Pow(-B, 1.0 / contrast);
                                B = 255 * (B + 0.5);
                                B = System.Math.Max(0, System.Math.Min(255, B));

                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, (int)R, (int)G, (int)B));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.BLOCKS: //Blocks
                    {
                        System.Drawing.Image.GetThumbnailImageAbort dummyCallback = new System.Drawing.Image.GetThumbnailImageAbort(ResizeAbort);
                        int size = parameter;
                        if (size <= 0) size = pEffect[(int)_effect];
                        _dImg = _dImg.GetThumbnailImage(bmap.Width / size, bmap.Height / size, dummyCallback, IntPtr.Zero);
                        _dImg = _dImg.GetThumbnailImage(bmap.Width, bmap.Height, dummyCallback, IntPtr.Zero);
                        bmap = new System.Drawing.Bitmap(_dImg);
                    }
                    break;
                case eEffect.REFLECT: //Reflect
                    {
                        int mode = parameter;
                        if (mode <= 0) mode = pEffect[(int)_effect];
                        bmap.RotateFlip(mode == 1 ? System.Drawing.RotateFlipType.RotateNoneFlipY : System.Drawing.RotateFlipType.RotateNoneFlipX);
                    }
                    break;
                case eEffect.JAGGED: //Jagged
                    {
                        System.Drawing.Color c;
                        System.Drawing.Bitmap copy = (System.Drawing.Bitmap)bmap.Clone();
                        FastPixel fpCopy = new FastPixel(copy);
                        int amount = parameter;
                        if (amount <= 0) amount = pEffect[(int)_effect];
                        bool up = true, left = false;
                        int ii, jj;
                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            if (i % amount == 0) up = !up;
                            for (int j = 0; j < fp.Height; j++)
                            {
                                if (j % amount == 0) left = !left;
                                ii = left ? System.Math.Max(0, i - amount) : System.Math.Min(fp.Width - 1, i + amount);
                                jj = up ? System.Math.Max(0, j - amount) : System.Math.Min(fp.Height - 1, j + amount);
                                c = fpCopy.GetPixel(ii, jj);
                                fp.SetPixel(i, j, c);
                            }
                        }
                        fpCopy.Unlock(false);
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.ROTATE: //Rotate
                    {
                        int mode = parameter;
                        if (mode <= 0) mode = pEffect[(int)_effect];
                        bmap.RotateFlip(mode == 1 ? System.Drawing.RotateFlipType.Rotate180FlipNone : mode == 2 ? System.Drawing.RotateFlipType.Rotate270FlipNone : System.Drawing.RotateFlipType.Rotate90FlipNone);
                    }
                    break;
                case eEffect.PIXELATE: //Pixelate
                    {
                        System.Drawing.Color c;
                        System.Drawing.Bitmap copy = (System.Drawing.Bitmap)bmap.Clone();
                        int amount = parameter;
                        if (amount <= 0) amount = pEffect[(int)_effect];
                        FastPixel fpCopy = new FastPixel(copy);
                        FastPixel fp = new FastPixel(bmap);
                        int nx = fp.Width / amount + 1;
                        int ny = fp.Height / amount + 1;
                        int ii, jj;
                        int[,] A = new int[nx, ny];
                        int[,] R = new int[nx, ny];
                        int[,] G = new int[nx, ny];
                        int[,] B = new int[nx, ny];
                        int[,] N = new int[nx, ny];
                        System.Drawing.Color[,] C = new System.Drawing.Color[nx, ny];
                        for (int i = 0; i < nx; i++)
                        {
                            for (int j = 0; j < ny; j++)
                            {
                                A[i, j] = 0;
                                R[i, j] = 0;
                                G[i, j] = 0;
                                B[i, j] = 0;
                                N[i, j] = 0;
                            }
                        }
                        for (int i = 0; i < fp.Width; i++)
                        {
                            ii = i / amount;
                            for (int j = 0; j < fp.Height; j++)
                            {
                                jj = j / amount;
                                c = fpCopy.GetPixel(i, j);
                                A[ii, jj] += c.A;
                                R[ii, jj] += c.R;
                                G[ii, jj] += c.G;
                                B[ii, jj] += c.B;
                                N[ii, jj] += 1;
                                fp.SetPixel(i, j, c);
                            }
                        }
                        for (int i = 0; i < nx; i++)
                        {
                            for (int j = 0; j < ny; j++)
                            {
                                if (N[i,j] > 0) C[i, j] = System.Drawing.Color.FromArgb(A[i, j] / N[i, j], R[i, j] / N[i, j], G[i, j] / N[i, j], B[i, j] / N[i, j]);
                            }
                        }
                        for (int i = 0; i < fp.Width; i++)
                        {
                            ii = i / amount;
                            for (int j = 0; j < fp.Height; j++)
                            {
                                jj = j / amount;
                                fp.SetPixel(i, j, C[ii, jj]);
                            }
                        }
                        fp.Unlock(true);
                        fpCopy.Unlock(false);
                    }
                    break;
                case eEffect.GAMMA: //Gamma
                    {
                        double gamma = parameter;
                        if (gamma <= 0) gamma = pEffect[(int)_effect];
                        System.Drawing.Color c;
                        double R, G, B;

                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);

                                R = 255.0 * System.Math.Pow(c.R / 255.0, gamma);
                                R = System.Math.Max(0, System.Math.Min(255, R));

                                G = 255.0 * System.Math.Pow(c.G / 255.0, gamma);
                                G = System.Math.Max(0, System.Math.Min(255, G));

                                B = 255.0 * System.Math.Pow(c.B / 255.0, gamma);
                                B = System.Math.Max(0, System.Math.Min(255, B));

                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, (int)R, (int)G, (int)B));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.FISHEYE: //FishEye
                    {
                        System.Drawing.Bitmap copy = (System.Drawing.Bitmap)bmap.Clone();
                        double factor = parameter;
                        if (factor < 1) factor = pEffect[(int)_effect];
                        factor -= 1;

                        FastPixel fpCopy = new FastPixel(copy);
                        FastPixel fp = new FastPixel(bmap);
                        double centerX = fp.Width / 2; //center of distortion
                        double centerY = fp.Height / 2;

                        int width = fp.Width; //image bounds
                        int height = fp.Height;

                        xshift = calc_shift(0, centerX - 1, centerX, factor);
                        double newcenterX = width - centerX;
                        double xshift_2 = calc_shift(0, newcenterX - 1, newcenterX, factor);

                        yshift = calc_shift(0, centerY - 1, centerY, factor);
                        double newcenterY = height - centerY;
                        double yshift_2 = calc_shift(0, newcenterY - 1, newcenterY, factor);

                        xscale = (width - xshift - xshift_2) / width;
                        yscale = (height - yshift - yshift_2) / height;

                        for (int j = 0; j < height; j++)
                        {
                            for (int i = 0; i < width; i++)
                            {
                                double x = getRadialX((double)i, (double)j, centerX, centerY, factor);
                                double y = getRadialY((double)i, (double)j, centerX, centerY, factor);
                                int ii = System.Math.Min(width - 1, System.Math.Max(0, (int)x));
                                int jj = System.Math.Min(height - 1, System.Math.Max(0, (int)y));
                                fp.SetPixel(i, j, fpCopy.GetPixel(ii, jj));
                            }
                        }
                        fp.Unlock(true);
                        fpCopy.Unlock(false);
                    }
                    break;
                case eEffect.BULGE: //Bulge
                    {
                        System.Drawing.Bitmap copy = (System.Drawing.Bitmap)bmap.Clone();
                        double factor = parameter;
                        if (factor <= 0) factor = pEffect[(int)_effect];

                        FastPixel fpCopy = new FastPixel(copy);
                        FastPixel fp = new FastPixel(bmap);

                        double rad = System.Math.Min(fp.Width, fp.Height) / 2.0;
                        double dx, dy, dist, scale;
                        int ii, jj;
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                dx = i - fp.Width / 2.0;
                                dy = j - fp.Height / 2.0;
                                dist = System.Math.Sqrt(dx * dx + dy * dy);
                                scale = System.Math.Pow(dist / rad, factor) / (dist / rad);
                                ii = (int)(fp.Width / 2.0 + scale * dx);
                                ii = System.Math.Min(fp.Width - 1, System.Math.Max(0, ii));
                                jj = (int)(fp.Height / 2.0 + scale * dy);
                                jj = System.Math.Min(fp.Height - 1, System.Math.Max(0, jj));
                                fp.SetPixel(i, j, fpCopy.GetPixel(ii, jj));
                            }
                        }
                        fp.Unlock(true);
                        fpCopy.Unlock(false);
                    }
                    break;
                case eEffect.SWIRL: //Swirl
                    {
                        System.Drawing.Bitmap copy = (System.Drawing.Bitmap)bmap.Clone();
                        double factor = parameter;
                        if (factor == 0) factor = pEffect[(int)_effect];

                        FastPixel fpCopy = new FastPixel(copy);
                        FastPixel fp = new FastPixel(bmap);

                        double dx, dy, dist, theta;
                        int ii, jj;
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                dx = i - fp.Width / 2.0;
                                dy = j - fp.Height / 2.0;
                                dist = System.Math.Sqrt(dx * dx + dy * dy);
                                if (dx == 0) theta = dy > 0 ? System.Math.PI / 2.0 : 3.0 * System.Math.PI / 2.0;
                                else theta = System.Math.Atan(dy/dx);
                                if (dx < 0) theta += System.Math.PI;
                                theta += dist / fp.Width * factor * 2 * System.Math.PI;
                                ii = (int)(fp.Width / 2.0 + dist * System.Math.Cos(theta));
                                ii = System.Math.Min(fp.Width - 1, System.Math.Max(0, ii));
                                jj = (int)(fp.Height / 2.0 + dist * System.Math.Sin(theta));
                                jj = System.Math.Min(fp.Height - 1, System.Math.Max(0, jj));
                                fp.SetPixel(i, j, fpCopy.GetPixel(ii, jj));
                            }
                        }
                        fp.Unlock(true);
                        fpCopy.Unlock(false);
                    }
                    break;
                case eEffect.POSTERISE: //Posterise
                    {
                        int level = parameter;
                        if (level <= 0) level = pEffect[(int)_effect];
                        System.Drawing.Color c;
                        double R, G, B;

                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);

                                R = ((int)(c.R / level)) * level;
                                G = ((int)(c.G / level)) * level;
                                B = ((int)(c.B / level)) * level;

                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, (int)R, (int)G, (int)B));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.HUE: //Hue
                    {
                        double hue = parameter;
                        if (hue <= 0) hue = pEffect[(int)_effect];
                        System.Drawing.Color c;
                        double[] HSL;
                        double[] RGB;

                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);

                                HSL = LDColours.RGB2HSL(c.R, c.G, c.B);
                                RGB = LDColours.HSL2RGB(HSL[0] + hue, HSL[1], HSL[2]);

                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, (int)(255*RGB[0]+0.5), (int)(255 * RGB[1] + 0.5), (int)(255 * RGB[2] + 0.5)));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.SATURATION: //Saturation
                    {
                        double saturation = parameter;
                        if (saturation <= 0) saturation = pEffect[(int)_effect];
                        System.Drawing.Color c;
                        double[] HSL;
                        double[] RGB;

                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);

                                HSL = LDColours.RGB2HSL(c.R, c.G, c.B);
                                RGB = LDColours.HSL2RGB(HSL[0], HSL[1] * saturation, HSL[2]);

                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, (int)(255 * RGB[0] + 0.5), (int)(255 * RGB[1] + 0.5), (int)(255 * RGB[2] + 0.5)));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.LIGHTNESS: //Lightness
                    {
                        double lightness = parameter;
                        if (lightness <= 0) lightness = pEffect[(int)_effect];
                        System.Drawing.Color c;
                        double[] HSL;
                        double[] RGB;

                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);

                                HSL = LDColours.RGB2HSL(c.R, c.G, c.B);
                                RGB = LDColours.HSL2RGB(HSL[0], HSL[1], HSL[2] * lightness);

                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, (int)(255 * RGB[0] + 0.5), (int)(255 * RGB[1] + 0.5), (int)(255 * RGB[2] + 0.5)));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                case eEffect.OILPAINT: //Oil Paint
                    {
                        int radius = parameter[1];
                        int levels = parameter[2];
                        if (radius <= 0) radius = pEffect[(int)_effect][1];
                        if (levels <= 0) levels = pEffect[(int)_effect][2];
                        if (radius % 2 == 0) radius++;
                        bmap = fip.OilPaint(bmap, radius, levels);
                    }
                    break;
                case eEffect.CHARCOAL: //Charcoal
                    {
                        bmap = fip.SketchCharcoal(bmap);
                    }
                    break;
                case eEffect.SKETCH: //Pen sketch
                    {
                        bmap = fip.Sketch(bmap);
                    }
                    break;
                case eEffect.CARTOON: //Cartool
                    {
                        int radius = parameter[1];
                        int levels = parameter[2];
                        int inverse = parameter[3];
                        if (radius <= 0) radius = pEffect[(int)_effect][1];
                        if (levels <= 0) levels = pEffect[(int)_effect][2];
                        if (inverse <= 0) inverse = pEffect[(int)_effect][3];
                        if (radius % 2 == 0) radius++;
                        bmap = fip.Cartoon(bmap, radius, levels, inverse);
                        //bmap = fip.Cartoon(bmap, radius, levels, inverse, fip.LaplaceF1());
                    }
                    break;
                case eEffect.EDGE: //Edge
                    {
                        bmap = fip.ImagePrewittFilterColor(bmap);
                        //bmap = fip.ImagePrewittFilterGS(bmap);
                    }
                    break;
                case eEffect.ACCENT: //Accent
                    {
                        int hue = parameter[1];
                        int range = parameter[2];
                        if (hue <= 0) hue = pEffect[(int)_effect][1];
                        if (range <= 0) range = pEffect[(int)_effect][2];
                        bmap = fip.ColorAccent(bmap, hue, range);
                    }
                    break;
                case eEffect.SEPIA: //Sepia
                    {
                        int threshhold = parameter;
                        if (threshhold <= 0) threshhold = pEffect[(int)_effect];
                        bmap = fip.Sepia(bmap, threshhold);
                    }
                    break;
                case eEffect.NOISEREMOVAL: //Noise removal
                    {
                        bmap = fip.ImageSDROMFilterColor(bmap);
                    }
                    break;
                case eEffect.SOLARISE: //Solarise
                    {
                        double power = parameter;
                        if (power <= 0) power = pEffect[(int)_effect];
                        System.Drawing.Color c;
                        double R, G, B;

                        FastPixel fp = new FastPixel(bmap);
                        for (int i = 0; i < fp.Width; i++)
                        {
                            for (int j = 0; j < fp.Height; j++)
                            {
                                c = fp.GetPixel(i, j);

                                R = c.R / 255.0;
                                G = c.G / 255.0;
                                B = c.B / 255.0;

                                R = System.Math.Pow(R < 0.5 ? 1 - 2 * R : 2 * R - 1, power) * 255.0;
                                G = System.Math.Pow(G < 0.5 ? 1 - 2 * G : 2 * G - 1, power) * 255.0;
                                B = System.Math.Pow(B < 0.5 ? 1 - 2 * B : 2 * B - 1, power) * 255.0;

                                fp.SetPixel(i, j, System.Drawing.Color.FromArgb(c.A, (int)R, (int)G, (int)B));
                            }
                        }
                        fp.Unlock(true);
                    }
                    break;
                default:
                    break;
            }

            return (System.Drawing.Image)bmap;
        }
Пример #5
0
            public void SetEffect_Delegate()
            {
                try
                {
                    int       i          = 0;
                    eEffect   effect     = (eEffect)data[i++];
                    Primitive properties = (Primitive)data[i++];
                    UIElement obj        = (UIElement)data[i++];

                    switch (effect)
                    {
                    case eEffect.NONE:
                        obj.Effect = null;
                        break;

                    case eEffect.DROPSHADOW:
                        obj.Effect = new DropShadowEffect();
                        if (SBArray.ContainsIndex(properties, "BlurRadius"))
                        {
                            obj.Effect.SetValue(DropShadowEffect.BlurRadiusProperty, (double)properties["BlurRadius"]);
                        }
                        if (SBArray.ContainsIndex(properties, "Color"))
                        {
                            obj.Effect.SetValue(DropShadowEffect.ColorProperty, (Color)ColorConverter.ConvertFromString(properties["Color"]));
                        }
                        if (SBArray.ContainsIndex(properties, "Direction"))
                        {
                            obj.Effect.SetValue(DropShadowEffect.DirectionProperty, (double)properties["Direction"]);
                        }
                        if (SBArray.ContainsIndex(properties, "Opacity"))
                        {
                            obj.Effect.SetValue(DropShadowEffect.OpacityProperty, (double)properties["Opacity"]);
                        }
                        if (SBArray.ContainsIndex(properties, "ShadowDepth"))
                        {
                            obj.Effect.SetValue(DropShadowEffect.ShadowDepthProperty, (double)properties["ShadowDepth"]);
                        }
                        break;

                    case eEffect.BLUR:
                        obj.Effect = new BlurEffect();
                        if (SBArray.ContainsIndex(properties, "KernelType"))
                        {
                            string value = properties["KernelType"];
                            obj.Effect.SetValue(BlurEffect.KernelTypeProperty, value.ToLower() == "box" ? KernelType.Box : KernelType.Gaussian);
                        }
                        if (SBArray.ContainsIndex(properties, "Radius"))
                        {
                            obj.Effect.SetValue(BlurEffect.RadiusProperty, (double)properties["Radius"]);
                        }
                        break;

                    case eEffect.BLOOM:
                        obj.Effect = new BloomEffect();
                        if (SBArray.ContainsIndex(properties, "BaseIntensity"))
                        {
                            obj.Effect.SetValue(BloomEffect.BaseIntensityProperty, (double)properties["BaseIntensity"]);
                        }
                        if (SBArray.ContainsIndex(properties, "BaseSaturation"))
                        {
                            obj.Effect.SetValue(BloomEffect.BaseSaturationProperty, (double)properties["BaseSaturation"]);
                        }
                        if (SBArray.ContainsIndex(properties, "BloomIntensity"))
                        {
                            obj.Effect.SetValue(BloomEffect.BloomIntensityProperty, (double)properties["BloomIntensity"]);
                        }
                        if (SBArray.ContainsIndex(properties, "BloomSaturation"))
                        {
                            obj.Effect.SetValue(BloomEffect.BloomSaturationProperty, (double)properties["BloomSaturation"]);
                        }
                        if (SBArray.ContainsIndex(properties, "Threshold"))
                        {
                            obj.Effect.SetValue(BloomEffect.ThresholdProperty, (double)properties["Threshold"]);
                        }
                        break;

                    case eEffect.COLORTONE:
                        obj.Effect = new ColorToneEffect();
                        if (SBArray.ContainsIndex(properties, "DarkColor"))
                        {
                            obj.Effect.SetValue(ColorToneEffect.DarkColorProperty, (Color)ColorConverter.ConvertFromString(properties["DarkColor"]));
                        }
                        if (SBArray.ContainsIndex(properties, "Desaturation"))
                        {
                            obj.Effect.SetValue(ColorToneEffect.DesaturationProperty, (double)properties["Desaturation"]);
                        }
                        if (SBArray.ContainsIndex(properties, "LightColor"))
                        {
                            obj.Effect.SetValue(ColorToneEffect.LightColorProperty, (Color)ColorConverter.ConvertFromString(properties["LightColor"]));
                        }
                        if (SBArray.ContainsIndex(properties, "ToneAmount"))
                        {
                            obj.Effect.SetValue(ColorToneEffect.ToneAmountProperty, (double)properties["ToneAmount"]);
                        }
                        break;

                    case eEffect.EMBOSSED:
                        obj.Effect = new EmbossedEffect();
                        if (SBArray.ContainsIndex(properties, "Amount"))
                        {
                            obj.Effect.SetValue(EmbossedEffect.AmountProperty, (double)properties["Amount"]);
                        }
                        if (SBArray.ContainsIndex(properties, "Color"))
                        {
                            obj.Effect.SetValue(EmbossedEffect.ColorProperty, (Color)ColorConverter.ConvertFromString(properties["Color"]));
                        }
                        if (SBArray.ContainsIndex(properties, "Height"))
                        {
                            obj.Effect.SetValue(EmbossedEffect.HeightProperty, (double)properties["Height"]);
                        }
                        break;

                    case eEffect.MAGNIFY:
                        obj.Effect = new MagnifyEffect();
                        if (SBArray.ContainsIndex(properties, "Amount"))
                        {
                            obj.Effect.SetValue(MagnifyEffect.AmountProperty, (double)properties["Amount"]);
                        }
                        if (SBArray.ContainsIndex(properties, "Center"))
                        {
                            Primitive center = properties["Center"];
                            Point     point  = new Point(0.5, 0.5);
                            if (SBArray.GetItemCount(center) == 2)
                            {
                                Primitive indices = SBArray.GetAllIndices(center);
                                point.X = center[indices[1]];
                                point.Y = center[indices[2]];
                            }
                            obj.Effect.SetValue(MagnifyEffect.CenterProperty, point);
                        }
                        if (SBArray.ContainsIndex(properties, "InnerRadius"))
                        {
                            obj.Effect.SetValue(MagnifyEffect.InnerRadiusProperty, (double)properties["InnerRadius"]);
                        }
                        if (SBArray.ContainsIndex(properties, "OuterRadius"))
                        {
                            obj.Effect.SetValue(MagnifyEffect.OuterRadiusProperty, (double)properties["OuterRadius"]);
                        }
                        break;

                    case eEffect.MONOCHROME:
                        obj.Effect = new MonochromeEffect();
                        if (SBArray.ContainsIndex(properties, "Color"))
                        {
                            obj.Effect.SetValue(MonochromeEffect.ColorProperty, (Color)ColorConverter.ConvertFromString(properties["Color"]));
                        }
                        break;

                    case eEffect.PIXELATE:
                        obj.Effect = new PixelateEffect();
                        if (SBArray.ContainsIndex(properties, "Pixelation"))
                        {
                            obj.Effect.SetValue(PixelateEffect.PixelationProperty, (double)properties["Pixelation"]);
                        }
                        break;

                    case eEffect.RIPPLE:
                        obj.Effect = new RippleEffect();
                        if (SBArray.ContainsIndex(properties, "Center"))
                        {
                            Primitive center = properties["Center"];
                            Point     point  = new Point(0.5, 0.5);
                            if (SBArray.GetItemCount(center) == 2)
                            {
                                Primitive indices = SBArray.GetAllIndices(center);
                                point.X = center[indices[1]];
                                point.Y = center[indices[2]];
                            }
                            obj.Effect.SetValue(RippleEffect.CenterProperty, point);
                        }
                        if (SBArray.ContainsIndex(properties, "Frequency"))
                        {
                            obj.Effect.SetValue(RippleEffect.FrequencyProperty, (double)properties["Frequency"]);
                        }
                        if (SBArray.ContainsIndex(properties, "Magnitude"))
                        {
                            obj.Effect.SetValue(RippleEffect.MagnitudeProperty, (double)properties["Magnitude"]);
                        }
                        if (SBArray.ContainsIndex(properties, "Phase"))
                        {
                            obj.Effect.SetValue(RippleEffect.PhaseProperty, (double)properties["Phase"]);
                        }
                        break;

                    case eEffect.SHARPEN:
                        obj.Effect = new SharpenEffect();
                        if (SBArray.ContainsIndex(properties, "Amount"))
                        {
                            obj.Effect.SetValue(SharpenEffect.AmountProperty, (double)properties["Amount"]);
                        }
                        if (SBArray.ContainsIndex(properties, "Height"))
                        {
                            obj.Effect.SetValue(SharpenEffect.HeightProperty, (double)properties["Height"]);
                        }
                        break;

                    case eEffect.SWIRL:
                        obj.Effect = new SwirlEffect();
                        if (SBArray.ContainsIndex(properties, "AngleFrequency"))
                        {
                            obj.Effect.SetValue(SwirlEffect.AngleFrequencyProperty, (double)properties["AngleFrequency"]);
                        }
                        if (SBArray.ContainsIndex(properties, "Center"))
                        {
                            Primitive center = properties["Center"];
                            Point     point  = new Point(0.5, 0.5);
                            if (SBArray.GetItemCount(center) == 2)
                            {
                                Primitive indices = SBArray.GetAllIndices(center);
                                point.X = center[indices[1]];
                                point.Y = center[indices[2]];
                            }
                            obj.Effect.SetValue(SwirlEffect.CenterProperty, point);
                        }
                        if (SBArray.ContainsIndex(properties, "TwistAmount"))
                        {
                            obj.Effect.SetValue(SwirlEffect.TwistAmountProperty, (double)properties["TwistAmount"]);
                        }
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                }
            }
Пример #6
0
        private static void DoEffect(string image, eEffect effect, Primitive parameter)
        {
            lock (LockingVar)
            {
                Type ImageListType = typeof(ImageList);
                Type GraphicsWindowType = typeof(GraphicsWindow);
                BitmapSource img;

                try
                {
                    _savedImages = (Dictionary<string, BitmapSource>)ImageListType.GetField("_savedImages", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                    if (!_savedImages.TryGetValue((string)image, out img)) return;

                    Bitmap dImg = FastPixel.GetBitmap(img);
                    dImg = (Bitmap)LDWebCam.DoEffect(dImg, effect, parameter);

                    FastThread.SaveBitmap(image, dImg);
                }
                catch (Exception ex)
                {
                    Utilities.OnError(Utilities.GetCurrentMethod(), ex);
                }
            }
        }
Пример #7
0
    public ParticleSystem GetEffect(eEffect type)
    {
        int index = (int)type;

        return(m_listEffects [index]);
    }
Пример #8
0
        private static void SetEffect(string shapeName, eEffect effect, Primitive properties)
        {
            Type GraphicsWindowType = typeof(GraphicsWindow);
            Dictionary<string, UIElement> _objectsMap;
            UIElement obj;

            try
            {
                ExtractDll();

                _objectsMap = (Dictionary<string, UIElement>)GraphicsWindowType.GetField("_objectsMap", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase).GetValue(null);
                if (_objectsMap.TryGetValue((string)shapeName, out obj))
                {
                    Delegates delegates = new Delegates(new object[] { effect, properties, obj });
                    FastThread.BeginInvoke(delegates.SetEffect_Delegate);
                }
                else
                {
                    Utilities.OnShapeError(Utilities.GetCurrentMethod(), shapeName);
                }
            }
            catch (Exception ex)
            {
                Utilities.OnError(Utilities.GetCurrentMethod(), ex);
            }
        }