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
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());
            }
        }