Example #1
0
        private void ReadHexRect(Rectangle rect)
        {
            Color     bgColor = App.Black;
            UInt32    fgPixel = 0;
            Rectangle tile    = new Rectangle();

            for (tile.Y = rect.Y; tile.Y < rect.Bottom; tile.Y += 16)
            {
                for (tile.X = rect.X; tile.X < rect.Right; tile.X += 16)
                {
                    tile.Width  = 16;
                    tile.Height = 16;
                    tile.Width  = Math.Min(tile.Right, rect.Right) - tile.Left;
                    tile.Height = Math.Min(tile.Bottom, rect.Bottom) - tile.Top;

                    RfbHexSubEncoding encoding = (RfbHexSubEncoding)ReadByte();

                    if ((encoding & RfbHexSubEncoding.Raw) != 0)
                    {
                        ReadRawRect(tile);
                        if (opts.ViewOpts.ScrnUpdAlgo == ScrnUpdAlgo.Asap)
                        {
                            view.InvalidateRect(tile);
                        }
                        continue;
                    }

                    byte[] data;
                    if ((encoding & RfbHexSubEncoding.BgSpec) != 0)
                    {
                        data    = ReadBytes(bytesPp);
                        bgColor = GetColorFromData(data, 0);
                    }

                    if ((encoding & RfbHexSubEncoding.FgSpec) != 0)
                    {
                        data    = ReadBytes(bytesPp);
                        fgPixel = RfbProtoUtil.GetPixelFromData(data, 0, bytesPp);
                    }

                    byte numSubRects = 0;
                    if ((encoding & RfbHexSubEncoding.AnySubRects) != 0)
                    {
                        numSubRects = ReadByte();
                    }

                    bool subRectsColored = ((encoding & RfbHexSubEncoding.SubRectsColored) != 0);

                    int subRectSize = RfbSize.HexSubRect;
                    subRectSize += subRectsColored ? (int)bytesPp : 0;
                    RreSubRectMsg[] subRects  = new RreSubRectMsg[numSubRects];
                    byte[]          rectBytes = ReadBytes(subRectSize * numSubRects);
                    for (int i = 0; i < numSubRects; i++)
                    {
                        subRects[i] = new HexSubRectMsg(rectBytes, (UInt32)(i * subRectSize), bytesPp, subRectsColored, fgPixel);
                    }
                    FillRreRect(tile, bgColor, subRects);
                    if (opts.ViewOpts.ScrnUpdAlgo == ScrnUpdAlgo.Asap)
                    {
                        view.InvalidateRect(tile);
                    }
                }
            }
        }
Example #2
0
 private Color GetColorFromData(byte[] data, UInt32 offset)
 {
     return(GetColorFromPixel(RfbProtoUtil.GetPixelFromData(data, offset, bytesPp)));
 }