Exemplo n.º 1
0
        private static void WarpImage(Warping bm_src, Warping bm_dest, WarpOperations warp_op)
        {
            double xmid = bm_dest.Width / 2.0;
            double ymid = bm_dest.Height / 2.0;
            double rmax = bm_dest.Width * 0.75;

            int ix_max = bm_src.Width - 2;
            int iy_max = bm_src.Height - 2;

            double x0, y0;

            for (int y1 = 0; y1 < bm_dest.Height; y1++)
            {
                for (int x1 = 0; x1 < bm_dest.Width; x1++)
                {
                    MapPixel(warp_op, xmid, ymid, rmax, x1, y1, out x0, out y0);

                    int ix0 = (int)x0;
                    int iy0 = (int)y0;

                    if ((ix0 < 0) || (ix0 > ix_max) ||
                        (iy0 < 0) || (iy0 > iy_max))
                    {
                        bm_dest.SetPixel(x1, y1, 255, 255, 255, 255);
                    }
                    else
                    {
                        double dx0 = x0 - ix0;
                        double dy0 = y0 - iy0;
                        double dx1 = 1 - dx0;
                        double dy1 = 1 - dy0;

                        byte r00, g00, b00, a00, r01, g01, b01, a01,
                             r10, g10, b10, a10, r11, g11, b11, a11;
                        bm_src.GetPixel(ix0, iy0, out r00, out g00, out b00, out a00);
                        bm_src.GetPixel(ix0, iy0 + 1, out r01, out g01, out b01, out a01);
                        bm_src.GetPixel(ix0 + 1, iy0, out r10, out g10, out b10, out a10);
                        bm_src.GetPixel(ix0 + 1, iy0 + 1, out r11, out g11, out b11, out a11);

                        int r = (int)(
                            r00 * dx1 * dy1 + r01 * dx1 * dy0 +
                            r10 * dx0 * dy1 + r11 * dx0 * dy0);
                        int g = (int)(
                            g00 * dx1 * dy1 + g01 * dx1 * dy0 +
                            g10 * dx0 * dy1 + g11 * dx0 * dy0);
                        int b = (int)(
                            b00 * dx1 * dy1 + b01 * dx1 * dy0 +
                            b10 * dx0 * dy1 + b11 * dx0 * dy0);
                        int a = (int)(
                            a00 * dx1 * dy1 + a01 * dx1 * dy0 +
                            a10 * dx0 * dy1 + a11 * dx0 * dy0);
                        bm_dest.SetPixel(x1, y1, (byte)r, (byte)g, (byte)b, (byte)a);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public Warping Clone()
        {
            bool was_locked = this.IsLocked;

            this.LockBitmap();

            Warping result = (Warping)this.MemberwiseClone();

            result.Bitmap     = new Bitmap(this.Bitmap.Width, this.Bitmap.Height);
            result.m_IsLocked = false;

            if (!was_locked)
            {
                this.UnlockBitmap();
            }

            return(result);
        }
Exemplo n.º 3
0
        public Warping Warp(WarpOperations warp_op, bool lock_result)
        {
            Warping result = this.Clone();

            bool was_locked = this.IsLocked;

            this.LockBitmap();
            result.LockBitmap();

            WarpImage(this, result, warp_op);

            if (!lock_result)
            {
                result.UnlockBitmap();
            }
            if (!was_locked)
            {
                this.UnlockBitmap();
            }

            return(result);
        }
Exemplo n.º 4
0
        private void DisplayWarpedImage(Warping.WarpOperations warp_op)
        {
            Bitmap bm = new Bitmap(original.Image);
            this.Cursor = Cursors.WaitCursor;
            DateTime start_time = DateTime.Now;

            // Make a Warping object.
            Warping bm32 = new Warping(bm);

            // Apply the warping operation.
            Warping new_bm32 = bm32.Warp(warp_op, false);

            // Display the result.
            result.Image = new_bm32.Bitmap;

            DateTime stop_time = DateTime.Now;
            this.Cursor = Cursors.Default;

            TimeSpan elapsed_time = stop_time - start_time;
            //lblElapsed.Text = elapsed_time.TotalSeconds.ToString("0.000000");
        }
Exemplo n.º 5
0
        private static void WarpImage(Warping bm_src, Warping bm_dest, WarpOperations warp_op)
        {
            double xmid = bm_dest.Width / 2.0;
            double ymid = bm_dest.Height / 2.0;
            double rmax = bm_dest.Width * 0.75;

            int ix_max = bm_src.Width - 2;
            int iy_max = bm_src.Height - 2;

            double x0, y0;
            for (int y1 = 0; y1 < bm_dest.Height; y1++)
            {
                for (int x1 = 0; x1 < bm_dest.Width; x1++)
                {
                    MapPixel(warp_op, xmid, ymid, rmax, x1, y1, out x0, out y0);

                    int ix0 = (int)x0;
                    int iy0 = (int)y0;

                    if ((ix0 < 0) || (ix0 > ix_max) ||
                        (iy0 < 0) || (iy0 > iy_max))
                    {
                        bm_dest.SetPixel(x1, y1, 255, 255, 255, 255);
                    }
                    else
                    {
                        double dx0 = x0 - ix0;
                        double dy0 = y0 - iy0;
                        double dx1 = 1 - dx0;
                        double dy1 = 1 - dy0;

                        byte r00, g00, b00, a00, r01, g01, b01, a01,
                             r10, g10, b10, a10, r11, g11, b11, a11;
                        bm_src.GetPixel(ix0, iy0, out r00, out g00, out b00, out a00);
                        bm_src.GetPixel(ix0, iy0 + 1, out r01, out g01, out b01, out a01);
                        bm_src.GetPixel(ix0 + 1, iy0, out r10, out g10, out b10, out a10);
                        bm_src.GetPixel(ix0 + 1, iy0 + 1, out r11, out g11, out b11, out a11);

                        int r = (int)(
                            r00 * dx1 * dy1 + r01 * dx1 * dy0 +
                            r10 * dx0 * dy1 + r11 * dx0 * dy0);
                        int g = (int)(
                            g00 * dx1 * dy1 + g01 * dx1 * dy0 +
                            g10 * dx0 * dy1 + g11 * dx0 * dy0);
                        int b = (int)(
                            b00 * dx1 * dy1 + b01 * dx1 * dy0 +
                            b10 * dx0 * dy1 + b11 * dx0 * dy0);
                        int a = (int)(
                            a00 * dx1 * dy1 + a01 * dx1 * dy0 +
                            a10 * dx0 * dy1 + a11 * dx0 * dy0);
                        bm_dest.SetPixel(x1, y1, (byte)r, (byte)g, (byte)b, (byte)a);
                    }
                }
            }
        }