Esempio n. 1
0
        /// <summary>
        /// Creates the encoded pixel data in a form of an EncodedRectangle with the preferred encoding.
        /// </summary>
        private void DoFrameBufferUpdate(Framebuffer fb, bool incremental, int x, int y, int width, int height)
        {
            //if (incremental)
            //    return;
            Trace.WriteLine("X: " + x + " Y: " + y + " W: " + fb.Width + " H: " + fb.Height);
            int w = fb.Width;
            int h = fb.Height;

            if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0))
            {
                Trace.WriteLine("Neg:" + x + ":" + y + ":" + width + ":" + height);
                return;
            }
            if (x + width > w)
            {
                Trace.WriteLine("Too wide");
                return;
            }
            if (y + height > h)
            {
                Trace.WriteLine("Too high");
                return;
            }
            Trace.WriteLine("Bounds OK!");

            HashSet <EncodedRectangle> rectangles = new HashSet <EncodedRectangle>();

            try
            {
                Stopwatch tip = Stopwatch.StartNew();
                EncodedRectangleFactory factory = new EncodedRectangleFactory(this, fb);

                ICollection <QuadNode> list = screenHandler.GetChange();

                Trace.WriteLine(list.Count + " rectangles to encode");
                foreach (QuadNode iter in list)
                {
                    Trace.WriteLine(iter.ToString());
                    EncodedRectangle localRect = factory.Build(iter, GetPreferredEncoding());
                    localRect.Encode();

                    rectangles.Add(localRect);
                }
                Trace.WriteLine("Encoding took: " + tip.Elapsed);
            }
            catch (Exception localException)
            {
                Console.WriteLine(localException.StackTrace);
                if (localException is IOException)
                {
                    Close(); return;
                }
            }
            if (rectangles.Count != 0)
            {
                WriteFrameBufferUpdate(rectangles);
            }
        }
Esempio n. 2
0
        public void DoShit()
        {
            //new Thread(delegate(){
                int i = this.dw / 4;
                int j = this.dh / 4;
                int m = 0;
                Rectangle lRect = Rectangle.Empty;

                Bitmap localBitmap = PixelGrabber.CreateScreenCapture(new Rectangle(0, 0, this.dw, this.dh));
                for (int k = 0; k < 4; k++)
                    for (m = 0; m < 4; m++)
                    {
                        lRect = new Rectangle();
                        lRect.X = (i * k);
                        lRect.Y = (j * m);
                        lRect.Width = i;
                        lRect.Height = j;
                        lRect = PixelGrabber.AlignRectangle(lRect, this.dw, this.dh);
                        this.rects[(k * 4 + m)] = lRect;
                        this.oldImages[(k * 4 + m)] = PixelGrabber.GetSubImage(localBitmap, new Rectangle(lRect.X, lRect.Y, lRect.Width, lRect.Height));
                    }

                List<EncodedRectangle> rCol = new List<EncodedRectangle>();
                foreach (Rectangle r in rects)
                {
                    try
                    {
                        /*Console.WriteLine("X: " + r.X + "\n" +
                                          "Y: " + r.Y + "\n" +
                                          "W: " + r.Width + "\n" +
                                          "H: " + r.Height + "\n" +
                                          rp.DisplayName + "\n" +
                                          defaultPixel.DesktopName + "\n\n");
                        Console.ReadLine();*/
                        EncodedRectangleFactory factory = new EncodedRectangleFactory(rp, defaultPixel);
                        EncodedRectangle localRect = factory.Build(r, rp.GetPreferredEncoding()); //factory.Build(PixelGrabber.GetSubImage(lBitmap, new Rectangle(localRectangle1.X, localRectangle1.Y, localRectangle1.Width, localRectangle1.Height)), localRectangle1.X + localRectangle2.X, localRectangle1.Y + localRectangle2.Y, rp.GetPreferredEncoding());
                        localRect.Encode();
                        rCol.Add(localRect);
                    }
                    catch (Exception localException)
                    {
                        Console.WriteLine(localException.StackTrace.ToString());
                    }
                }
                EncodedRectangle[] arrEnc = rCol.ToArray();
                if (arrEnc != null)
                    rp.WriteFrameBufferUpdate(arrEnc);

                //for (int ii = 0; ii < oldImages.Length; ii++)
                //oldImages[ii].Save("C:\\IMG" + ii + ".bmp");
            //}).Start();
        }
Esempio n. 3
0
        /// <summary>
        ///     Creates the encoded pixel data in a form of an EncodedRectangle with the preferred encoding.
        /// </summary>
        private void DoFrameBufferUpdate(Framebuffer fb, bool incremental, int x, int y, int width, int height)
        {
            //if (incremental)
            //    return;
            Trace.WriteLine("X: " + x + " Y: " + y + " W: " + fb.Width + " H: " + fb.Height);
            var w = fb.Width;
            var h = fb.Height;

            if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0))
            {
                Trace.WriteLine("Neg:" + x + ":" + y + ":" + width + ":" + height);
                return;
            }
            if (x + width > w)
            {
                Trace.WriteLine("Too wide");
                return;
            }
            if (y + height > h)
            {
                Trace.WriteLine("Too high");
                return;
            }
            Trace.WriteLine("Bounds OK!");

            var rectangles = new HashSet <EncodedRectangle>();

            try
            {
                var tip     = Stopwatch.StartNew();
                var factory = new EncodedRectangleFactory(this, fb);

                var localRect = factory.Build(new Rectangle2(x, y, width, height), GetPreferredEncoding());
                localRect.Encode();
                rectangles.Add(localRect);
                Trace.WriteLine("Encoding took: " + tip.Elapsed);
            }
            catch (Exception localException)
            {
                Console.WriteLine(localException.StackTrace);
                if (localException is IOException)
                {
                    Close();
                    return;
                }
            }
            if (rectangles.Count != 0)
            {
                WriteFrameBufferUpdate(rectangles);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the encoded pixel data in a form of an EncodedRectangle with the preferred encoding.
        /// </summary>
        private void DoFrameBufferUpdate(Framebuffer fb, bool incremental, int x, int y, int width, int height)
        {
            //if (incremental)
            //    return;
            Trace.WriteLine("X: " + x + " Y: " + y + " W: " + fb.Width + " H: " + fb.Height);
            int w = fb.Width;
            int h = fb.Height;
            if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0))
            {
                Trace.WriteLine("Neg:" + x + ":" + y + ":" + width + ":" + height);
                return;
            }
            if (x + width > w)
            {
                Trace.WriteLine("Too wide");
                return;
            }
            if (y + height > h)
            {
                Trace.WriteLine("Too high");
                return;
            }
            Trace.WriteLine("Bounds OK!");

            HashSet<EncodedRectangle> rectangles = new HashSet<EncodedRectangle>();
            try
            {
                Stopwatch tip = Stopwatch.StartNew();
                EncodedRectangleFactory factory = new EncodedRectangleFactory(this, fb);
             
                ICollection<QuadNode> list = screenHandler.GetChange();
                
                Trace.WriteLine(list.Count + " rectangles to encode");
                foreach (QuadNode iter in list)
                {
                    Trace.WriteLine(iter.ToString());
                    EncodedRectangle localRect = factory.Build(iter, GetPreferredEncoding());
                    localRect.Encode();

                    rectangles.Add(localRect);
                }
                Trace.WriteLine("Encoding took: " + tip.Elapsed);
            }
            catch (Exception localException)
            {
                Console.WriteLine(localException.StackTrace);
                if (localException is IOException)
                { Close(); return; }
            }
            if (rectangles.Count != 0)
                WriteFrameBufferUpdate(rectangles);

        }
Esempio n. 5
0
        private EncodedRectangle getChangedImages(Bitmap paramBitmap, int paramInt)
        {
            Rectangle localRectangle = this.rects[paramInt];
            int i = 0;
            int j = 0;
            int k = localRectangle.X;
            int m = localRectangle.Y;
            int n = localRectangle.X + localRectangle.Width;
            int i1 = localRectangle.Y + localRectangle.Height;
            try
            {
                for (i = k; i < n; i++)
                    for (j = m; j < i1; j++)
                    {
                        if (PixelGrabber.GetRGB(this.oldImage, i, j) == PixelGrabber.GetRGB(paramBitmap, i, j))
                            continue;
                        throw new Exception();
                    }
                return null;
            }
            catch (Exception)
            {
                k = i;
                try
                {
                    for (j = m; j < i1; j++)
                        for (i = k; i < n; i++)
                        {
                            if (PixelGrabber.GetRGB(this.oldImage, i, j) == PixelGrabber.GetRGB(paramBitmap, i, j))
                                continue;
                            throw new Exception();
                        }
                    return null;
                }
                catch (Exception)
                {
                    m = j;
                    try
                    {
                        for (i = n - 1; i > k; i--)
                            for (j = m; j < i1; j++)
                            {
                                if (PixelGrabber.GetRGB(this.oldImage, i, j) == PixelGrabber.GetRGB(paramBitmap, i, j))
                                    continue;
                                throw new Exception();
                            }
                        return null;
                    }
                    catch (Exception)
                    {
                        n = i;
                        try
                        {
                            for (j = i1 - 1; j > m; j--)
                                for (i = n; i > k; i--)
                                {
                                    if (PixelGrabber.GetRGB(this.oldImage, i, j) == PixelGrabber.GetRGB(paramBitmap, i, j))
                                        continue;
                                    throw new Exception();
                                }
                            return null;
                        }
                        catch (Exception)
                        {
                            i1 = j;
                            if ((n - k > 0) && (i1 - m > 0))
                            {
                                int i2 = k % 16;
                                if (i2 != 0)
                                    k -= i2;
                                i2 = m % 16;
                                if (i2 != 0)
                                    m -= i2;
                                i2 = n % 16;
                                if (i2 != 0)
                                    n = n - i2 + 16;
                                i2 = i1 % 16;
                                if (i2 != 0)
                                    i1 = i1 - i2 + 16;
                                try
                                {
                                    Console.WriteLine("" + k + ":" + m + ":" + n + ":" + i1 + ":" + (n - k) + ":" + (i1 - m));
                                    EncodedRectangleFactory factory = new EncodedRectangleFactory(rp, pf);

                                    //Rect.encode(this.pe, this.pf, paramBitmap.getSubimage(k, m, n - k, i1 - m), k, m);
                                    EncodedRectangle localRect = factory.Build(PixelGrabber.GetSubImage(paramBitmap, new Rectangle(k, m, n - k, i1 - m)), k, m, this.pe);
                                    localRect.Encode();
                                    return localRect;
                                }
                                catch (Exception localException5)
                                {
                                    Console.WriteLine(localException5.ToString());
                                }
                            }
                        }
                    }
                }
            }
            return null;
        }
Esempio n. 6
0
        protected EncodedRectangle[] getChangedImages(Bitmap paramBitmap)
        {
            int i = paramBitmap.Width;
            int j = paramBitmap.Height;
            int m;
            EncodedRectangle localRect;
            if ((this.oldImage == null) || (this.oldImage.Width != i) || (this.oldImage.Height != j))
            {
                this.index = 0;
                int k = i / 4;
                m = j / 4;
                for (int n = 0; n < 4; n++)
                    for (int i1 = 0; i1 < 4; i1++)
                    {
                        this.rects[(n * 4 + i1)].X = (k * n);
                        this.rects[(n * 4 + i1)].Y = (m * i1);
                        this.rects[(n * 4 + i1)].Width = k;
                        this.rects[(n * 4 + i1)].Height = m;
                    }

                EncodedRectangleFactory factory = new EncodedRectangleFactory(rp, pf);
                localRect = factory.Build(new Rectangle(0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height), this.pe);
                localRect.Encode();

                this.oldImage = paramBitmap;
                //localRect = Rect.encode(this.pe, this.pf, paramBitmap, 0, 0);
                return new EncodedRectangle[] { localRect };
            }
            List<EncodedRectangle> localArrayList = new List<EncodedRectangle>();
            for (m = 0; m < 16; m++)
            {
                localRect = getChangedImages(paramBitmap, m);
                if (localRect == null)
                    continue;
                localArrayList.Add(localRect);
            }
            this.oldImage = paramBitmap;
            if (localArrayList.Count > 0)
            {
                EncodedRectangle[] arrayOfRect = localArrayList.ToArray();
                return arrayOfRect;
            }
            return null;
        }
Esempio n. 7
0
        /// <summary>
        /// Creates the encoded pixel data in a form of an EncodedRectangle with the preferred encoding.
        /// </summary>
        private void DoFrameBufferUpdate(Framebuffer fb, bool incremental, int x, int y, int width, int height)
        {
            //          Console.WriteLine("X: " + x + " Y: " + y + " W: " + fb.Width + " H: " + fb.Height);
            int w = fb.Width;
            int h = fb.Height;
            if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0))
            {
                Console.WriteLine("Neg:" + x + ":" + y + ":" + width + ":" + height);
                return;
            }
            if (x + width > w)
            {
                Console.WriteLine("Too wide");
                return;
            }
            if (y + height > h)
            {
                Console.WriteLine("Too high");
                return;
            }

            //            Console.WriteLine("Bounds OK!");

            List<EncodedRectangle> lst = new List<EncodedRectangle>();
            //List<byte[]> lstHash = new List<byte[]>();
            try
            {
                //Console.WriteLine("Framebuffer: ");
                //fb.Print();
                //Console.ReadLine();

                System.Diagnostics.Stopwatch tip = System.Diagnostics.Stopwatch.StartNew();
                EncodedRectangleFactory factory = new EncodedRectangleFactory(this, fb);
                /*
                int i = width / 4;
                int j = height / 4;
                int m = 0;
                Rectangle lRect = Rectangle.Empty;
                for (int k = 0; k < 4; k++)
                    for (m = 0; m < 4; m++)
                    {
                        lRect = new Rectangle();
                        lRect.X = (i * k);
                        lRect.Y = (j * m);
                        lRect.Width = i;
                        lRect.Height = j;
                        //lRect = PixelGrabber.AlignRectangle(lRect, width, height);

                        EncodedRectangle localRect = factory.Build(lRect, GetPreferredEncoding());
                        localRect.Encode();
                        lst.Add(localRect);
                    }
                 */
                EncodedRectangle localRect = factory.Build(new Rectangle(x,y,width, height), GetPreferredEncoding());
                localRect.Encode();

                lst.Add(localRect);
            //                Console.WriteLine("Encoding took: " + tip.Elapsed);
            }
            catch (Exception localException)
            {
                Console.WriteLine(localException.StackTrace.ToString());
                if (localException is IOException)
                { this.Close(); return; }
            }
            if (lst.Count != 0)
                WriteFrameBufferUpdate(lst.ToArray());
        }
Esempio n. 8
0
File: VncHost.cs Progetto: tub5/NVNC
        /// <summary>
        /// Creates the encoded pixel data in a form of an EncodedRectangle with the preferred encoding.
        /// </summary>
        private void DoFrameBufferUpdate(Framebuffer fb, bool incremental, int x, int y, int width, int height)
        {
            //if (incremental)
            //    return;
            Trace.WriteLine("X: " + x + " Y: " + y + " W: " + fb.Width + " H: " + fb.Height);
            int w = fb.Width;
            int h = fb.Height;

            if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0))
            {
                Trace.WriteLine("Neg:" + x + ":" + y + ":" + width + ":" + height);
                return;
            }
            if (x + width > w)
            {
                Trace.WriteLine("Too wide");
                return;
            }
            if (y + height > h)
            {
                Trace.WriteLine("Too high");
                return;
            }
            Trace.WriteLine("Bounds OK!");


            List <EncodedRectangle> lst = new List <EncodedRectangle>();

            //List<byte[]> lstHash = new List<byte[]>();
            try
            {
                //Console.WriteLine("Framebuffer: ");
                //fb.Print();
                //Console.ReadLine();

                System.Diagnostics.Stopwatch tip     = System.Diagnostics.Stopwatch.StartNew();
                EncodedRectangleFactory      factory = new EncodedRectangleFactory(this, fb);

                /*
                 * int i = width / 4;
                 * int j = height / 4;
                 * int m = 0;
                 * Rectangle lRect = Rectangle.Empty;
                 * for (int k = 0; k < 4; k++)
                 *  for (m = 0; m < 4; m++)
                 *  {
                 *      lRect = new Rectangle();
                 *      lRect.X = (i * k);
                 *      lRect.Y = (j * m);
                 *      lRect.Width = i;
                 *      lRect.Height = j;
                 *      //lRect = PixelGrabber.AlignRectangle(lRect, width, height);
                 *
                 *      EncodedRectangle localRect = factory.Build(lRect, GetPreferredEncoding());
                 *      localRect.Encode();
                 *      lst.Add(localRect);
                 *  }
                 */
                EncodedRectangle localRect = factory.Build(new Rectangle(x, y, width, height), GetPreferredEncoding());
                localRect.Encode();

                lst.Add(localRect);
                Console.WriteLine("Encoding took: " + tip.Elapsed);
            }
            catch (Exception localException)
            {
                Console.WriteLine(localException.StackTrace.ToString());
                if (localException is IOException)
                {
                    this.Close(); return;
                }
            }
            if (lst.Count != 0)
            {
                WriteFrameBufferUpdate(lst.ToArray());
            }
        }
Esempio n. 9
0
        /// <summary>
        ///     Creates the encoded pixel data in a form of an EncodedRectangle with the preferred encoding.
        /// </summary>
        private void DoFrameBufferUpdate(Framebuffer fb, bool incremental, int x, int y, int width, int height)
        {
            //if (incremental)
            //    return;
            Trace.WriteLine("X: " + x + " Y: " + y + " W: " + fb.Width + " H: " + fb.Height);
            var w = fb.Width;
            var h = fb.Height;
            if ((x < 0) || (y < 0) || (width <= 0) || (height <= 0))
            {
                Trace.WriteLine("Neg:" + x + ":" + y + ":" + width + ":" + height);
                return;
            }
            if (x + width > w)
            {
                Trace.WriteLine("Too wide");
                return;
            }
            if (y + height > h)
            {
                Trace.WriteLine("Too high");
                return;
            }
            Trace.WriteLine("Bounds OK!");

            var rectangles = new HashSet<EncodedRectangle>();
            try
            {
                var tip = Stopwatch.StartNew();
                var factory = new EncodedRectangleFactory(this, fb);

                var localRect = factory.Build(new Rectangle2(x, y, width, height), GetPreferredEncoding());
                localRect.Encode();
                rectangles.Add(localRect);
                Trace.WriteLine("Encoding took: " + tip.Elapsed);
            }
            catch (Exception localException)
            {
                Console.WriteLine(localException.StackTrace);
                if (localException is IOException)
                {
                    Close();
                    return;
                }
            }
            if (rectangles.Count != 0)
                WriteFrameBufferUpdate(rectangles);
        }