Esempio n. 1
0
        public static void DoBottomMirror(NonLinearTransfromNeededEventArg e)
        {
            var source = e.SourcePixels;
            var output = e.Pixels;

            var s      = e.Stride;
            var dy     = 1;
            var beginY = e.SourceClientRectangle.Bottom + dy;
            var sy     = e.ClientRectangle.Height;
            var beginX = e.SourceClientRectangle.Left;
            var endX   = e.SourceClientRectangle.Right;
            var d      = sy - beginY;

            for (int x = beginX; x < endX; x++)
            {
                for (int y = beginY; y < sy; y++)
                {
                    var sourceY = (int)(beginY - 1 - dy - (y - beginY));
                    if (sourceY < 0)
                    {
                        break;
                    }
                    var sourceX = x;
                    int sourceI = sourceY * s + sourceX * bytesPerPixel;
                    int outI    = y * s + x * bytesPerPixel;
                    output[outI + 0] = source[sourceI + 0];
                    output[outI + 1] = source[sourceI + 1];
                    output[outI + 2] = source[sourceI + 2];
                    output[outI + 3] = (byte)((1 - 1f * (y - beginY) / d) * 90);
                }
            }
        }
 public static void DoBlind(NonLinearTransfromNeededEventArg e, Animation animation)
 {
     if (animation.BlindCoeff != PointF.Empty)
     {
         byte[] pixels = e.Pixels;
         int    width  = e.ClientRectangle.Width;
         int    height = e.ClientRectangle.Height;
         int    stride = e.Stride;
         float  x      = animation.BlindCoeff.X;
         float  y      = animation.BlindCoeff.Y;
         int    num6   = (int)(((width * x) + (height * y)) * (1f - e.CurrentTime));
         for (int i = 0; i < width; i++)
         {
             for (int j = 0; j < height; j++)
             {
                 int   num9  = (j * stride) + (i * 4);
                 float num10 = ((i * x) + (j * y)) - num6;
                 if (num10 >= 0f)
                 {
                     pixels[num9 + 3] = 0;
                 }
             }
         }
     }
 }
Esempio n. 3
0
        public static void DoBlind(NonLinearTransfromNeededEventArg e, Animation animation)
        {
            if (animation.BlindCoeff == PointF.Empty)
            {
                return;
            }

            var pixels = e.Pixels;
            var sx     = e.ClientRectangle.Width;
            var sy     = e.ClientRectangle.Height;
            var s      = e.Stride;
            var kx     = animation.BlindCoeff.X;
            var ky     = animation.BlindCoeff.Y;
            var a      = (int)((sx * kx + sy * ky) * (1 - e.CurrentTime));

            for (int x = 0; x < sx; x++)
            {
                for (int y = 0; y < sy; y++)
                {
                    int i = y * s + x * bytesPerPixel;
                    var d = x * kx + y * ky - a;
                    if (d >= 0)
                    {
                        pixels[i + 3] = (byte)0;
                    }
                }
            }
        }
        public static void DoBottomMirror(NonLinearTransfromNeededEventArg e)
        {
            byte[] sourcePixels = e.SourcePixels;
            byte[] pixels       = e.Pixels;
            int    stride       = e.Stride;
            int    num2         = 1;
            int    num3         = e.SourceClientRectangle.Bottom + num2;
            int    height       = e.ClientRectangle.Height;
            int    left         = e.SourceClientRectangle.Left;
            int    right        = e.SourceClientRectangle.Right;
            int    num7         = height - num3;

            for (int i = left; i < right; i++)
            {
                for (int j = num3; j < height; j++)
                {
                    int num10 = ((num3 - 1) - num2) - (j - num3);
                    if (num10 < 0)
                    {
                        break;
                    }
                    int num11 = i;
                    int index = (num10 * stride) + (num11 * 4);
                    int num13 = (j * stride) + (i * 4);
                    pixels[num13]     = sourcePixels[index];
                    pixels[num13 + 1] = sourcePixels[index + 1];
                    pixels[num13 + 2] = sourcePixels[index + 2];
                    pixels[num13 + 3] = (byte)((1f - ((1f * (j - num3)) / ((float)num7))) * 90f);
                }
            }
        }
Esempio n. 5
0
        protected virtual Bitmap OnNonLinearTransfromNeeded()
        {
            Bitmap bmp = null;

            if (CtrlBmp == null)
            {
                return(null);
            }

            try
            {
                bmp = new Bitmap(Width, Height);

                const int   bytesPerPixel = 4;
                PixelFormat pxf           = PixelFormat.Format32bppArgb;
                Rectangle   rect          = new Rectangle(0, 0, bmp.Width, bmp.Height);
                BitmapData  bmpData       = bmp.LockBits(rect, ImageLockMode.ReadWrite, pxf);
                IntPtr      ptr           = bmpData.Scan0;
                int         numBytes      = bmp.Width * bmp.Height * bytesPerPixel;
                byte[]      argbValues    = new byte[numBytes];

                Marshal.Copy(ptr, argbValues, 0, numBytes);

                var e = new NonLinearTransfromNeededEventArg()
                {
                    CurrentTime = CurrentTime, ClientRectangle = ClientRectangle, Pixels = argbValues, Stride = bmpData.Stride, SourcePixels = CtrlPixels, SourceClientRectangle = new Rectangle(Padding.Left, Padding.Top, DecoratedControl.Width, DecoratedControl.Height), SourceStride = CtrlStride
                };

                try
                {
                    if (NonLinearTransfromNeeded != null)
                    {
                        NonLinearTransfromNeeded(this, e);
                    }
                    else
                    {
                        e.UseDefaultTransform = true;
                    }

                    if (e.UseDefaultTransform)
                    {
                        switch (DecorationType)
                        {
                        case DecorationType.BottomMirror: TransfromHelper.DoBottomMirror(e); break;
                        }
                    }
                }catch {}

                Marshal.Copy(argbValues, 0, ptr, numBytes);
                bmp.UnlockBits(bmpData);
            }
            catch
            {
            }

            return(bmp);
        }
Esempio n. 6
0
        protected virtual Bitmap OnNonLinearTransfromNeeded()
        {
            Bitmap bmp = null;

            if (ctrlBmp == null)
            {
                return(null);
            }

            try
            {
                bmp = (Bitmap)ctrlBmp.Clone();

                const int   bytesPerPixel = 4;
                PixelFormat pxf           = PixelFormat.Format32bppArgb;
                Rectangle   rect          = new Rectangle(0, 0, bmp.Width, bmp.Height);
                BitmapData  bmpData       = bmp.LockBits(rect, ImageLockMode.ReadWrite, pxf);
                IntPtr      ptr           = bmpData.Scan0;
                int         numBytes      = bmp.Width * bmp.Height * bytesPerPixel;
                byte[]      argbValues    = new byte[numBytes];

                System.Runtime.InteropServices.Marshal.Copy(ptr, argbValues, 0, numBytes);

                var e = new NonLinearTransfromNeededEventArg()
                {
                    CurrentTime = CurrentTime, ClientRectangle = DoubleBitmap.ClientRectangle, Pixels = argbValues, Stride = bmpData.Stride
                };

                if (NonLinearTransfromNeeded != null)
                {
                    NonLinearTransfromNeeded(this, e);
                }
                else
                {
                    e.UseDefaultTransform = true;
                }

                if (e.UseDefaultTransform)
                {
                    TransfromHelper.DoBlind(e, animation);
                    TransfromHelper.DoMosaic(e, animation, ref buffer, ref pixelsBuffer);

                    TransfromHelper.DoTransparent(e, animation);
                    TransfromHelper.DoLeaf(e, animation);
                }

                System.Runtime.InteropServices.Marshal.Copy(argbValues, 0, ptr, numBytes);
                bmp.UnlockBits(bmpData);
            }
            catch
            {
            }

            return(bmp);
        }
Esempio n. 7
0
 protected virtual void OnNonLinearTransfromNeeded(object sender, NonLinearTransfromNeededEventArg e)
 {
     if (NonLinearTransfromNeeded != null)
     {
         NonLinearTransfromNeeded(this, e);
     }
     else
     {
         e.UseDefaultTransform = true;
     }
 }
        protected virtual Bitmap OnNonLinearTransfromNeeded()
        {
            Bitmap bitmap = null;

            if (this.CtrlBmp == null)
            {
                return(null);
            }
            try
            {
                bitmap = new Bitmap(base.Width, base.Height);
                PixelFormat format      = PixelFormat.Format32bppArgb;
                Rectangle   rect        = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                BitmapData  bitmapdata  = bitmap.LockBits(rect, ImageLockMode.ReadWrite, format);
                IntPtr      source      = bitmapdata.Scan0;
                int         length      = (bitmap.Width * bitmap.Height) * 4;
                byte[]      destination = new byte[length];
                Marshal.Copy(source, destination, 0, length);
                NonLinearTransfromNeededEventArg e = new NonLinearTransfromNeededEventArg {
                    CurrentTime           = this.CurrentTime,
                    ClientRectangle       = base.ClientRectangle,
                    Pixels                = destination,
                    Stride                = bitmapdata.Stride,
                    SourcePixels          = this.CtrlPixels,
                    SourceClientRectangle = new Rectangle(this.Padding.Left, this.Padding.Top, this.DecoratedControl.Width, this.DecoratedControl.Height),
                    SourceStride          = this.CtrlStride
                };
                try
                {
                    if (this.NonLinearTransfromNeeded != null)
                    {
                        this.NonLinearTransfromNeeded(this, e);
                    }
                    else
                    {
                        e.UseDefaultTransform = true;
                    }
                    if (e.UseDefaultTransform && (this.DecorationType == AnimatorNS.DecorationType.BottomMirror))
                    {
                        TransfromHelper.DoBottomMirror(e);
                    }
                }
                catch
                {
                }
                Marshal.Copy(destination, 0, source, length);
                bitmap.UnlockBits(bitmapdata);
            }
            catch
            {
            }
            return(bitmap);
        }
Esempio n. 9
0
        public static void DoLeaf(NonLinearTransfromNeededEventArg e, Animation animation)
        {
            if (animation.LeafCoeff == 0f)
            {
                return;
            }

            var pixels = e.Pixels;
            var sx     = e.ClientRectangle.Width;
            var sy     = e.ClientRectangle.Height;
            var s      = e.Stride;
            var a      = (int)((sx + sy) * (1 - e.CurrentTime * e.CurrentTime));

            var count = pixels.Length;

            for (int x = 0; x < sx; x++)
            {
                for (int y = 0; y < sy; y++)
                {
                    int i = y * s + x * bytesPerPixel;
                    if (x + y >= a)
                    {
                        var newX = a - y;
                        var newY = a - x;
                        var d    = a - x - y;
                        if (d < -20)
                        {
                            d = -20;
                        }

                        int newI = newY * s + newX * bytesPerPixel;
                        if (newX >= 0 && newY >= 0)
                        {
                            if (newI >= 0 && newI < count)
                            {
                                if (pixels[i + 3] > 0)
                                {
                                    pixels[newI + 0] = (byte)Math.Min(255, d + 250 + pixels[i + 0] / 10);
                                    pixels[newI + 1] = (byte)Math.Min(255, d + 250 + pixels[i + 1] / 10);
                                    pixels[newI + 2] = (byte)Math.Min(255, d + 250 + pixels[i + 2] / 10);
                                    pixels[newI + 3] = 230;
                                }
                            }
                        }
                        pixels[i + 3] = (byte)(0);
                    }
                }
            }
        }
        protected virtual Bitmap OnNonLinearTransfromNeeded()
        {
            Bitmap bitmap = null;

            if (this.ctrlBmp == null)
            {
                return(null);
            }
            try
            {
                bitmap = (Bitmap)this.ctrlBmp.Clone();
                PixelFormat format      = PixelFormat.Format32bppArgb;
                Rectangle   rect        = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                BitmapData  bitmapdata  = bitmap.LockBits(rect, ImageLockMode.ReadWrite, format);
                IntPtr      source      = bitmapdata.Scan0;
                int         length      = (bitmap.Width * bitmap.Height) * 4;
                byte[]      destination = new byte[length];
                Marshal.Copy(source, destination, 0, length);
                NonLinearTransfromNeededEventArg e = new NonLinearTransfromNeededEventArg {
                    CurrentTime     = this.CurrentTime,
                    ClientRectangle = this.DoubleBitmap.ClientRectangle,
                    Pixels          = destination,
                    Stride          = bitmapdata.Stride
                };
                if (this.NonLinearTransfromNeeded != null)
                {
                    this.NonLinearTransfromNeeded(this, e);
                }
                else
                {
                    e.UseDefaultTransform = true;
                }
                if (e.UseDefaultTransform)
                {
                    TransfromHelper.DoBlind(e, this.animation);
                    TransfromHelper.DoMosaic(e, this.animation, ref this.buffer, ref this.pixelsBuffer);
                    TransfromHelper.DoTransparent(e, this.animation);
                    TransfromHelper.DoLeaf(e, this.animation);
                }
                Marshal.Copy(destination, 0, source, length);
                bitmap.UnlockBits(bitmapdata);
            }
            catch
            {
            }
            return(bitmap);
        }
Esempio n. 11
0
        /*
         * internal static void DoBottomShadow(NonLinearTransfromNeededEventArg e)
         * {
         *  var source = e.SourcePixels;
         *  var output = e.Pixels;
         *
         *  var s = e.Stride;
         *  var dy = 1;
         *  var beginY = e.SourceClientRectangle.Bottom + dy;
         *  var sy = e.ClientRectangle.Height;
         *  var beginX = e.SourceClientRectangle.Left;
         *  var endX = e.SourceClientRectangle.Right;
         *  var d = sy - beginY;
         *
         *  var bgG = source[0];
         *  var bgB = source[1];
         *  var bgR = source[2];
         *
         *  for (int x = beginX; x < endX; x++)
         *      for (int y = beginY; y < sy; y++)
         *      {
         *          var sourceY = (int)(beginY - 1 - dy - (y - beginY)*6);
         *          if (sourceY < 0)
         *              break;
         *          var sourceX = x;
         *          int sourceI = sourceY * s + sourceX * bytesPerPixel;
         *          int outI = y * s + x * bytesPerPixel;
         *          if (source[sourceI + 0] != bgG && source[sourceI + 1] != bgB && source[sourceI + 2] != bgR)
         *          {
         *              output[outI + 0] = 0;
         *              output[outI + 1] = 0;
         *              output[outI + 2] = 0;
         *              output[outI + 3] = (byte) ((1 - 1f*(y - beginY)/d)*90);
         *          }
         *      }
         * }*/

        public static void DoBlur(NonLinearTransfromNeededEventArg e, int r)
        {
            var output = e.Pixels;
            var source = e.SourcePixels;

            var s    = e.Stride;
            var sy   = e.ClientRectangle.Height;
            var sx   = e.ClientRectangle.Width;
            var maxI = source.Length - bytesPerPixel;

            for (int x = r; x < sx - r; x++)
            {
                for (int y = r; y < sy - r; y++)
                {
                    int outI = y * s + x * bytesPerPixel;

                    int R = 0, G = 0, B = 0, A = 0;
                    int counter = 0;
                    for (int xx = x - r; xx < x + r; xx++)
                    {
                        for (int yy = y - r; yy < y + r; yy++)
                        {
                            int srcI = yy * s + xx * bytesPerPixel;
                            if (srcI >= 0 && srcI < maxI)
                            {
                                if (source[srcI + 3] > 0)
                                {
                                    B += source[srcI + 0];
                                    G += source[srcI + 1];
                                    R += source[srcI + 2];
                                    A += source[srcI + 3];
                                    counter++;
                                }
                            }
                        }
                    }
                    if (outI < maxI && counter > 5)
                    {
                        output[outI + 0] = (byte)(B / counter);
                        output[outI + 1] = (byte)(G / counter);
                        output[outI + 2] = (byte)(R / counter);
                        output[outI + 3] = (byte)(A / counter);
                        //output[outI + 3] = 255; //(byte)((1 - 1f * (y - beginY) / d) * 90);
                    }
                }
            }
        }
        public static void DoBlur(NonLinearTransfromNeededEventArg e, int r)
        {
            byte[] pixels       = e.Pixels;
            byte[] sourcePixels = e.SourcePixels;
            int    stride       = e.Stride;
            int    height       = e.ClientRectangle.Height;
            int    width        = e.ClientRectangle.Width;
            int    num4         = sourcePixels.Length - 4;

            for (int i = r; i < (width - r); i++)
            {
                for (int j = r; j < (height - r); j++)
                {
                    int index = (j * stride) + (i * 4);
                    int num8  = 0;
                    int num9  = 0;
                    int num10 = 0;
                    int num11 = 0;
                    int num12 = 0;
                    for (int k = i - r; k < (i + r); k++)
                    {
                        for (int m = j - r; m < (j + r); m++)
                        {
                            int num15 = (m * stride) + (k * 4);
                            if (((num15 >= 0) && (num15 < num4)) && (sourcePixels[num15 + 3] > 0))
                            {
                                num10 += sourcePixels[num15];
                                num9  += sourcePixels[num15 + 1];
                                num8  += sourcePixels[num15 + 2];
                                num11 += sourcePixels[num15 + 3];
                                num12++;
                            }
                        }
                    }
                    if ((index < num4) && (num12 > 5))
                    {
                        pixels[index]     = (byte)(num10 / num12);
                        pixels[index + 1] = (byte)(num9 / num12);
                        pixels[index + 2] = (byte)(num8 / num12);
                        pixels[index + 3] = (byte)(num11 / num12);
                    }
                }
            }
        }
 public static void DoTransparent(NonLinearTransfromNeededEventArg e, Animation animation)
 {
     if (animation.TransparencyCoeff != 0f)
     {
         float num = 1f - (animation.TransparencyCoeff * e.CurrentTime);
         if (num < 0f)
         {
             num = 0f;
         }
         if (num > 1f)
         {
             num = 1f;
         }
         byte[] pixels = e.Pixels;
         for (int i = 0; i < pixels.Length; i += 4)
         {
             pixels[i + 3] = (byte)(pixels[i + 3] * num);
         }
     }
 }
Esempio n. 14
0
        public static void DoLeaf(NonLinearTransfromNeededEventArg e, Animation animation)
        {
            if (animation.LeafCoeff == 0f)
                return;

            var pixels = e.Pixels;
            var sx = e.ClientRectangle.Width;
            var sy = e.ClientRectangle.Height;
            var s = e.Stride;
            var a = (int)((sx + sy) * (1 - e.CurrentTime * e.CurrentTime));

            var count = pixels.Length;

            for (int x = 0; x < sx; x++)
                for (int y = 0; y < sy; y++)
                {
                    int i = y * s + x * bytesPerPixel;
                    if (x + y >= a)
                    {
                        var newX = a - y;
                        var newY = a - x;
                        var d = a - x - y;
                        if (d < -20)
                            d = -20;

                        int newI = newY * s + newX * bytesPerPixel;
                        if (newX >= 0 && newY >= 0)
                            if (newI >= 0 && newI < count)
                                if (pixels[i + 3] > 0)
                                {
                                    pixels[newI + 0] = (byte)Math.Min(255, d + 250 + pixels[i + 0] / 10);
                                    pixels[newI + 1] = (byte)Math.Min(255, d + 250 + pixels[i + 1] / 10);
                                    pixels[newI + 2] = (byte)Math.Min(255, d + 250 + pixels[i + 2] / 10);
                                    pixels[newI + 3] = 230;
                                }
                        pixels[i + 3] = (byte)(0);
                    }
                }
        }
Esempio n. 15
0
        public static void DoBlind(NonLinearTransfromNeededEventArg e, Animation animation)
        {
            if (animation.BlindCoeff == PointF.Empty)
                return;

            var pixels = e.Pixels;
            var sx = e.ClientRectangle.Width;
            var sy = e.ClientRectangle.Height;
            var s = e.Stride;
            var kx = animation.BlindCoeff.X;
            var ky = animation.BlindCoeff.Y;
            var a = (int)((sx * kx + sy * ky) * (1 - e.CurrentTime));

            for (int x = 0; x < sx; x++)
                for (int y = 0; y < sy; y++)
                {
                    int i = y * s + x * bytesPerPixel;
                    var d = x * kx + y * ky - a;
                    if (d >= 0)
                        pixels[i + 3] = (byte)0;
                }
        }
 public static void DoLeaf(NonLinearTransfromNeededEventArg e, Animation animation)
 {
     if (animation.LeafCoeff != 0f)
     {
         byte[] pixels = e.Pixels;
         int    width  = e.ClientRectangle.Width;
         int    height = e.ClientRectangle.Height;
         int    stride = e.Stride;
         int    num4   = (int)((width + height) * (1f - (e.CurrentTime * e.CurrentTime)));
         int    length = pixels.Length;
         for (int i = 0; i < width; i++)
         {
             for (int j = 0; j < height; j++)
             {
                 int index = (j * stride) + (i * 4);
                 if ((i + j) >= num4)
                 {
                     int num9  = num4 - j;
                     int num10 = num4 - i;
                     int num11 = (num4 - i) - j;
                     if (num11 < -20)
                     {
                         num11 = -20;
                     }
                     int num12 = (num10 * stride) + (num9 * 4);
                     if ((((num9 >= 0) && (num10 >= 0)) && ((num12 >= 0) && (num12 < length))) && (pixels[index + 3] > 0))
                     {
                         pixels[num12]     = (byte)Math.Min(0xff, (num11 + 250) + (pixels[index] / 10));
                         pixels[num12 + 1] = (byte)Math.Min(0xff, (num11 + 250) + (pixels[index + 1] / 10));
                         pixels[num12 + 2] = (byte)Math.Min(0xff, (num11 + 250) + (pixels[index + 2] / 10));
                         pixels[num12 + 3] = 230;
                     }
                     pixels[index + 3] = 0;
                 }
             }
         }
     }
 }
Esempio n. 17
0
        public static void DoTransparent(NonLinearTransfromNeededEventArg e, Animation animation)
        {
            if (animation.TransparencyCoeff == 0f)
            {
                return;
            }
            var opacity = 1f - animation.TransparencyCoeff * e.CurrentTime;

            if (opacity < 0f)
            {
                opacity = 0f;
            }
            if (opacity > 1f)
            {
                opacity = 1f;
            }

            var pixels = e.Pixels;

            for (int counter = 0; counter < pixels.Length; counter += bytesPerPixel)
            {
                pixels[counter + 3] = (byte)(pixels[counter + 3] * opacity);
            }
        }
Esempio n. 18
0
        public static void DoTransparent(NonLinearTransfromNeededEventArg e, Animation animation)
        {
            if (animation.TransparencyCoeff == 0f)
                return;
            var opacity = 1f - animation.TransparencyCoeff * e.CurrentTime;
            if (opacity < 0f)
                opacity = 0f;
            if (opacity > 1f)
                opacity = 1f;

            var pixels = e.Pixels;
            for (int counter = 0; counter < pixels.Length; counter += bytesPerPixel)
                pixels[counter + 3] = (byte)(pixels[counter + 3] * opacity);
        }
Esempio n. 19
0
        public static void DoMosaic(NonLinearTransfromNeededEventArg e, Animation animation, ref Point[] buffer, ref byte[] pixelsBuffer)
        {
            if (animation.MosaicCoeff == PointF.Empty || animation.MosaicSize == 0)
                return;

            var pixels = e.Pixels;
            var sx = e.ClientRectangle.Width;
            var sy = e.ClientRectangle.Height;
            var s = e.Stride;
            var a = e.CurrentTime;
            var count = pixels.Length;
            var opacity = 1 - e.CurrentTime;
            if (opacity < 0f) opacity = 0f;
            if (opacity > 1f) opacity = 1f;
            var mkx = animation.MosaicCoeff.X;
            var mky = animation.MosaicCoeff.Y;

            if (buffer == null)
            {
                buffer = new Point[pixels.Length];
                for (int i = 0; i < pixels.Length; i++)
                    buffer[i] = new Point((int)(mkx * (rnd.NextDouble() - 0.5)), (int)(mky * (rnd.NextDouble() - 0.5)));
            }

            if (pixelsBuffer == null)
                pixelsBuffer = (byte[])pixels.Clone();

            for (int i = 0; i < count; i += bytesPerPixel)
            {
                pixels[i + 0] = 255;
                pixels[i + 1] = 255;
                pixels[i + 2] = 255;
                pixels[i + 3] = 0;
            }

            var ms = animation.MosaicSize;
            var msx = animation.MosaicShift.X;
            var msy = animation.MosaicShift.Y;

            for (int y = 0; y < sy; y++)
                for (int x = 0; x < sx; x++)
                {
                    int yi = (y / ms);
                    int xi = (x / ms);
                    int i = y * s + x * bytesPerPixel;
                    int j = yi * s + xi * bytesPerPixel;

                    var newX = x + (int)(a * (buffer[j].X + xi * msx));
                    var newY = y + (int)(a * (buffer[j].Y + yi * msy));

                    if (newX >= 0 && newX < sx)
                        if (newY >= 0 && newY < sy)
                        {
                            int newI = newY * s + newX * bytesPerPixel;
                            pixels[newI + 0] = pixelsBuffer[i + 0];
                            pixels[newI + 1] = pixelsBuffer[i + 1];
                            pixels[newI + 2] = pixelsBuffer[i + 2];
                            pixels[newI + 3] = (byte)(pixelsBuffer[i + 3] * opacity);
                        }
                }
        }
Esempio n. 20
0
        protected virtual Bitmap OnNonLinearTransfromNeeded()
        {
            Bitmap bmp = null;
            if (ctrlBmp == null)
                return null;

            if (NonLinearTransfromNeeded == null)
                if (!animation.IsNonLinearTransformNeeded)
                    return ctrlBmp;

            try
            {
                bmp = (Bitmap)ctrlBmp.Clone();

                const int bytesPerPixel = 4;
                PixelFormat pxf = PixelFormat.Format32bppArgb;
                Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
                BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, pxf);
                IntPtr ptr = bmpData.Scan0;
                int numBytes = bmp.Width * bmp.Height * bytesPerPixel;
                byte[] argbValues = new byte[numBytes];

                System.Runtime.InteropServices.Marshal.Copy(ptr, argbValues, 0, numBytes);

                var e = new NonLinearTransfromNeededEventArg() { CurrentTime = CurrentTime, ClientRectangle = DoubleBitmap.ClientRectangle, Pixels = argbValues, Stride = bmpData.Stride };

                if (NonLinearTransfromNeeded != null)
                    NonLinearTransfromNeeded(this, e);
                else
                    e.UseDefaultTransform = true;

                if (e.UseDefaultTransform)
                {
                    TransfromHelper.DoBlind(e, animation);
                    TransfromHelper.DoMosaic(e, animation, ref buffer, ref pixelsBuffer);

                    TransfromHelper.DoTransparent(e, animation);
                    TransfromHelper.DoLeaf(e, animation);
                }

                System.Runtime.InteropServices.Marshal.Copy(argbValues, 0, ptr, numBytes);
                bmp.UnlockBits(bmpData);
            }
            catch
            {
            }

            return bmp;
        }
Esempio n. 21
0
 protected virtual void OnNonLinearTransfromNeeded(object sender, NonLinearTransfromNeededEventArg e)
 {
     if (NonLinearTransfromNeeded != null)
         NonLinearTransfromNeeded(this, e);
     else
         e.UseDefaultTransform = true;
 }
Esempio n. 22
0
        protected virtual Bitmap OnNonLinearTransfromNeeded()
        {
            Bitmap bmp = null;
            if (CtrlBmp == null)
                return null;

            try
            {
                bmp = new Bitmap(Width, Height);

                const int bytesPerPixel = 4;
                PixelFormat pxf = PixelFormat.Format32bppArgb;
                Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
                BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, pxf);
                IntPtr ptr = bmpData.Scan0;
                int numBytes = bmp.Width * bmp.Height * bytesPerPixel;
                byte[] argbValues = new byte[numBytes];

                Marshal.Copy(ptr, argbValues, 0, numBytes);

                var e = new NonLinearTransfromNeededEventArg() { CurrentTime = CurrentTime, ClientRectangle = ClientRectangle, Pixels = argbValues, Stride = bmpData.Stride, SourcePixels = CtrlPixels, SourceClientRectangle = new Rectangle(Padding.Left, Padding.Top, DecoratedControl.Width, DecoratedControl.Height), SourceStride = CtrlStride };

                try
                {
                    if (NonLinearTransfromNeeded != null)
                        NonLinearTransfromNeeded(this, e);
                    else
                        e.UseDefaultTransform = true;

                    if (e.UseDefaultTransform)
                    {
                        switch (DecorationType)
                        {
                            case DecorationType.BottomMirror: TransfromHelper.DoBottomMirror(e); break;
                        }
                    }
                }catch{}

                Marshal.Copy(argbValues, 0, ptr, numBytes);
                bmp.UnlockBits(bmpData);
            }
            catch
            {
            }

            return bmp;
        }
Esempio n. 23
0
        public static void DoMosaic(NonLinearTransfromNeededEventArg e, Animation animation, ref Point[] buffer, ref byte[] pixelsBuffer)
        {
            if (animation.MosaicCoeff == PointF.Empty || animation.MosaicSize == 0)
            {
                return;
            }

            var pixels  = e.Pixels;
            var sx      = e.ClientRectangle.Width;
            var sy      = e.ClientRectangle.Height;
            var s       = e.Stride;
            var a       = e.CurrentTime;
            var count   = pixels.Length;
            var opacity = 1 - e.CurrentTime;

            if (opacity < 0f)
            {
                opacity = 0f;
            }
            if (opacity > 1f)
            {
                opacity = 1f;
            }
            var mkx = animation.MosaicCoeff.X;
            var mky = animation.MosaicCoeff.Y;

            if (buffer == null)
            {
                buffer = new Point[pixels.Length];
                for (int i = 0; i < pixels.Length; i++)
                {
                    buffer[i] = new Point((int)(mkx * (rnd.NextDouble() - 0.5)), (int)(mky * (rnd.NextDouble() - 0.5)));
                }
            }

            if (pixelsBuffer == null)
            {
                pixelsBuffer = (byte[])pixels.Clone();
            }


            for (int i = 0; i < count; i += bytesPerPixel)
            {
                pixels[i + 0] = 255;
                pixels[i + 1] = 255;
                pixels[i + 2] = 255;
                pixels[i + 3] = 0;
            }

            var ms  = animation.MosaicSize;
            var msx = animation.MosaicShift.X;
            var msy = animation.MosaicShift.Y;

            for (int y = 0; y < sy; y++)
            {
                for (int x = 0; x < sx; x++)
                {
                    int yi = (y / ms);
                    int xi = (x / ms);
                    int i  = y * s + x * bytesPerPixel;
                    int j  = yi * s + xi * bytesPerPixel;

                    var newX = x + (int)(a * (buffer[j].X + xi * msx));
                    var newY = y + (int)(a * (buffer[j].Y + yi * msy));

                    if (newX >= 0 && newX < sx)
                    {
                        if (newY >= 0 && newY < sy)
                        {
                            int newI = newY * s + newX * bytesPerPixel;
                            pixels[newI + 0] = pixelsBuffer[i + 0];
                            pixels[newI + 1] = pixelsBuffer[i + 1];
                            pixels[newI + 2] = pixelsBuffer[i + 2];
                            pixels[newI + 3] = (byte)(pixelsBuffer[i + 3] * opacity);
                        }
                    }
                }
            }
        }
 public static void DoMosaic(NonLinearTransfromNeededEventArg e, Animation animation, ref Point[] buffer, ref byte[] pixelsBuffer)
 {
     if ((animation.MosaicCoeff != PointF.Empty) && (animation.MosaicSize != 0))
     {
         int    num9;
         byte[] pixels      = e.Pixels;
         int    width       = e.ClientRectangle.Width;
         int    height      = e.ClientRectangle.Height;
         int    stride      = e.Stride;
         float  currentTime = e.CurrentTime;
         int    length      = pixels.Length;
         float  num6        = 1f - e.CurrentTime;
         if (num6 < 0f)
         {
             num6 = 0f;
         }
         if (num6 > 1f)
         {
             num6 = 1f;
         }
         float x = animation.MosaicCoeff.X;
         float y = animation.MosaicCoeff.Y;
         if (buffer == null)
         {
             buffer = new Point[pixels.Length];
             for (num9 = 0; num9 < pixels.Length; num9++)
             {
                 buffer[num9] = new Point((int)(x * (rnd.NextDouble() - 0.5)), (int)(y * (rnd.NextDouble() - 0.5)));
             }
         }
         if (pixelsBuffer == null)
         {
             pixelsBuffer = (byte[])pixels.Clone();
         }
         num9 = 0;
         while (num9 < length)
         {
             pixels[num9]     = 0xff;
             pixels[num9 + 1] = 0xff;
             pixels[num9 + 2] = 0xff;
             pixels[num9 + 3] = 0;
             num9            += 4;
         }
         int   mosaicSize = animation.MosaicSize;
         float num11      = animation.MosaicShift.X;
         float num12      = animation.MosaicShift.Y;
         for (int i = 0; i < height; i++)
         {
             for (int j = 0; j < width; j++)
             {
                 int num15 = i / mosaicSize;
                 int num16 = j / mosaicSize;
                 num9 = (i * stride) + (j * 4);
                 int index = (num15 * stride) + (num16 * 4);
                 int num18 = j + ((int)(currentTime * (buffer[index].X + (num16 * num11))));
                 int num19 = i + ((int)(currentTime * (buffer[index].Y + (num15 * num12))));
                 if (((num18 >= 0) && (num18 < width)) && ((num19 >= 0) && (num19 < height)))
                 {
                     int num20 = (num19 * stride) + (num18 * 4);
                     pixels[num20]     = pixelsBuffer[num9];
                     pixels[num20 + 1] = pixelsBuffer[num9 + 1];
                     pixels[num20 + 2] = pixelsBuffer[num9 + 2];
                     pixels[num20 + 3] = (byte)(pixelsBuffer[num9 + 3] * num6);
                 }
             }
         }
     }
 }
Esempio n. 25
0
        public static void DoBottomMirror(NonLinearTransfromNeededEventArg e)
        {
            var source = e.SourcePixels;
            var output = e.Pixels;
            
            var s = e.Stride;
            var dy = 1;
            var beginY = e.SourceClientRectangle.Bottom + dy;
            var sy = e.ClientRectangle.Height;
            var beginX = e.SourceClientRectangle.Left;
            var endX = e.SourceClientRectangle.Right;
            var d = sy - beginY;

            for (int x = beginX; x < endX; x++)
            for (int y = beginY; y < sy; y++)
            {
                var sourceY = (int)(beginY - 1 - dy  - (y - beginY));
                if (sourceY < 0)
                    break;
                var sourceX = x;
                int sourceI = sourceY * s + sourceX * bytesPerPixel;
                int outI = y * s + x * bytesPerPixel;
                output[outI + 0] = source[sourceI + 0];
                output[outI + 1] = source[sourceI + 1];
                output[outI + 2] = source[sourceI + 2];
                output[outI + 3] = (byte)((1 - 1f*(y - beginY)/d)*90);
            }
        }
Esempio n. 26
0
        /*
        internal static void DoBottomShadow(NonLinearTransfromNeededEventArg e)
        {
            var source = e.SourcePixels;
            var output = e.Pixels;

            var s = e.Stride;
            var dy = 1;
            var beginY = e.SourceClientRectangle.Bottom + dy;
            var sy = e.ClientRectangle.Height;
            var beginX = e.SourceClientRectangle.Left;
            var endX = e.SourceClientRectangle.Right;
            var d = sy - beginY;

            var bgG = source[0];
            var bgB = source[1];
            var bgR = source[2];

            for (int x = beginX; x < endX; x++)
                for (int y = beginY; y < sy; y++)
                {
                    var sourceY = (int)(beginY - 1 - dy - (y - beginY)*6);
                    if (sourceY < 0)
                        break;
                    var sourceX = x;
                    int sourceI = sourceY * s + sourceX * bytesPerPixel;
                    int outI = y * s + x * bytesPerPixel;
                    if (source[sourceI + 0] != bgG && source[sourceI + 1] != bgB && source[sourceI + 2] != bgR)
                    {
                        output[outI + 0] = 0;
                        output[outI + 1] = 0;
                        output[outI + 2] = 0;
                        output[outI + 3] = (byte) ((1 - 1f*(y - beginY)/d)*90);
                    }
                }
        }*/

        public static void DoBlur(NonLinearTransfromNeededEventArg e, int r)
        {
            var output = e.Pixels;
            var source = e.SourcePixels;

            var s = e.Stride;
            var sy = e.ClientRectangle.Height;
            var sx = e.ClientRectangle.Width;
            var maxI = source.Length - bytesPerPixel;

            for (int x = r; x < sx - r; x++)
            for (int y = r; y < sy - r; y++)
            {
                int outI = y * s + x * bytesPerPixel;

                int R = 0, G = 0, B = 0, A = 0;
                int counter = 0;
                for (int xx = x - r; xx < x + r; xx++)
                for (int yy = y - r; yy < y + r; yy++)
                {
                    int srcI = yy * s + xx * bytesPerPixel;
                    if (srcI >= 0 && srcI < maxI)
                    if(source[srcI + 3] > 0)
                    {
                        B += source[srcI + 0];
                        G += source[srcI + 1];
                        R += source[srcI + 2];
                        A += source[srcI + 3];
                        counter++;
                    }
                }
                if (outI < maxI && counter > 5)
                {
                    output[outI + 0] = (byte)(B / counter);
                    output[outI + 1] = (byte)(G / counter);
                    output[outI + 2] = (byte)(R / counter);
                    output[outI + 3] = (byte)(A / counter); 
                    //output[outI + 3] = 255; //(byte)((1 - 1f * (y - beginY) / d) * 90);
                }
            }
        }