Describes the low-level arrangement of a framebuffer pixel.
Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="VncFramebuffer"/> class.
        /// </summary>
        /// <param name="name">The framebuffer name. Many VNC clients set their titlebar to this name.</param>
        /// <param name="width">The framebuffer width.</param>
        /// <param name="height">The framebuffer height.</param>
        /// <param name="pixelFormat">The framebuffer pixel format.</param>
        public VncFramebuffer(string name, int width, int height, VncPixelFormat pixelFormat)
        {
            Throw.If.Null(name, "name");
            Throw.If.Negative(width, "width").Negative(height, "height");
            Throw.If.Null(pixelFormat, "pixelFormat");

            this.Name = name;
            this.Width = width;
            this.Height = height;
            this.PixelFormat = pixelFormat;
            this.Stride = this.PixelFormat.BytesPerPixel * this.Width;
            this.SyncRoot = new object();

            this.buffer = new byte[this.Width * this.Height * this.PixelFormat.BytesPerPixel];
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <para>
        /// Copies pixels. A format conversion is performed if necessary.
        /// </para>
        /// <para>
        /// Be sure to lock <see cref="VncFramebuffer.SyncRoot"/> first to avoid tearing,
        /// if the connection is active.
        /// </para>
        /// </summary>
        /// <param name="source">A pointer to the upper-left corner of the source.</param>
        /// <param name="sourceStride">The offset in the source between one Y coordinate and the next.</param>
        /// <param name="sourceFormat">The source pixel format.</param>
        /// <param name="sourceRectangle">The rectangle in the source to decode.</param>
        /// <param name="target">A pointer to the upper-left corner of the target.</param>
        /// <param name="targetStride">The offset in the target between one Y coordinate and the next.</param>
        /// <param name="targetFormat">The target pixel format.</param>
        /// <param name="targetX">The X coordinate in the target that the leftmost pixel should be placed into.</param>
        /// <param name="targetY">The Y coordinate in the target that the topmost pixel should be placed into.</param>
        public static unsafe void Copy(
            IntPtr source,
            int sourceStride,
            VncPixelFormat sourceFormat,
            VncRectangle sourceRectangle,
            IntPtr target,
            int targetStride,
            VncPixelFormat targetFormat,
            int targetX = 0,
            int targetY = 0)
        {
            Throw.If.True(source == IntPtr.Zero, "source").True(target == IntPtr.Zero, "target");
            Throw.If.Null(sourceFormat, "sourceFormat").Null(targetFormat, "targetFormat");

            if (sourceRectangle.IsEmpty)
            {
                return;
            }

            int x = sourceRectangle.X, w = sourceRectangle.Width;
            int y = sourceRectangle.Y, h = sourceRectangle.Height;

            var sourceData = (byte*)(void*)source + (y * sourceStride) + (x * sourceFormat.BytesPerPixel);
            var targetData = (byte*)(void*)target + (targetY * targetStride) + (targetX * targetFormat.BytesPerPixel);

            if (sourceFormat.Equals(targetFormat))
            {
                for (int iy = 0; iy < h; iy++)
                {
                    if (sourceFormat.BytesPerPixel == 4)
                    {
                        uint* sourceDataX0 = (uint*)sourceData, targetDataX0 = (uint*)targetData;
                        for (int ix = 0; ix < w; ix++)
                        {
                            *targetDataX0++ = *sourceDataX0++;
                        }
                    }
                    else
                    {
                        int bytes = w * sourceFormat.BytesPerPixel;
                        byte* sourceDataX0 = (byte*)sourceData, targetDataX0 = (byte*)targetData;
                        for (int ib = 0; ib < bytes; ib++)
                        {
                            *targetDataX0++ = *sourceDataX0++;
                        }
                    }

                    sourceData += sourceStride;
                    targetData += targetStride;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Copies pixels between two byte arrays. A format conversion is performed if necessary.
        ///
        /// Be sure to lock <see cref="VncFramebuffer.SyncRoot"/> first to avoid tearing,
        /// if the connection is active.
        /// </summary>
        /// <param name="source">A pointer to the upper-left corner of the source.</param>
        /// <param name="sourceWidth">The width of the source image.</param>
        /// <param name="sourceStride">The offset in the source between one Y coordinate and the next.</param>
        /// <param name="sourceFormat">The source pixel format.</param>
        /// <param name="sourceRectangle">The rectangle in the source to decode.</param>
        /// <param name="target">A pointer to the upper-left corner of the target.</param>
        /// <param name="targetWidth">The width of the target image.</param>
        /// <param name="targetStride">The offset in the target between one Y coordinate and the next.</param>
        /// <param name="targetFormat">The target pixel format.</param>
        /// <param name="targetX">The X coordinate in the target that the leftmost pixel should be placed into.</param>
        /// <param name="targetY">The Y coordinate in the target that the topmost pixel should be placed into.</param>
        public static unsafe void Copy(
            byte[] source,
            int sourceWidth,
            int sourceStride,
            VncPixelFormat sourceFormat,
            VncRectangle sourceRectangle,
            byte[] target,
            int targetWidth,
            int targetStride,
            VncPixelFormat targetFormat,
            int targetX = 0,
            int targetY = 0)
        {
            Throw.If.Null(source, "source").Null(target, "target");

            if (sourceRectangle.IsEmpty)
            {
                return;
            }

            int x = sourceRectangle.X, w = sourceRectangle.Width;
            int y = sourceRectangle.Y, h = sourceRectangle.Height;

            if (sourceFormat.Equals(targetFormat))
            {
                if (sourceRectangle.Width == sourceWidth
                    && sourceWidth == targetWidth
                    && sourceStride == targetStride)
                {
                    int sourceStart = sourceStride * y;
                    int length = targetStride * h;

                    Buffer.BlockCopy(source, sourceStart, target, 0, length);
                }
                else
                {
                    for (int iy = 0; iy < h; iy++)
                    {
                        int sourceStart = (sourceStride * (iy + y)) + (x * sourceFormat.BitsPerPixel / 8);
                        int targetStart = targetStride * iy;

                        int length = w * sourceFormat.BitsPerPixel / 8;

                        Buffer.BlockCopy(source, sourceStart, target, targetStart, length);
                    }
                }
            }
        }