Exemplo n.º 1
0
        private static unsafe void ProcessStart(Bitmap bitmap, byte[] buffer, int offset, int count)
        {
            var imageBoundaries = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            var imageData = bitmap.LockBits(imageBoundaries, ImageLockMode.WriteOnly, bitmap.PixelFormat);

            var reader = new QuickBinaryReader(buffer);
            var pointer = (byte*) imageData.Scan0;
            var width = reader.ReadUnsignedVariableLength();
            var height = reader.ReadUnsignedVariableLength();

            while (reader.Position < count)
            {
                var bg = reader.ReadByte();
                var gr = reader.ReadByte();
                pointer[0] = (byte)(bg & 248);
                pointer[1] = (byte)((bg & 7) << 5 | (gr & 7) << 2);
                pointer[2] = (byte)(gr & 248);
                pointer += 4;
            }

            bitmap.UnlockBits(imageData);
        }
Exemplo n.º 2
0
        private static unsafe void ProcessDelta(Bitmap bitmap, byte[] buffer, int offset, int count)
        {
            var imageBoundaries = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            var imageData = bitmap.LockBits(imageBoundaries, ImageLockMode.WriteOnly, bitmap.PixelFormat);

            var reader = new QuickBinaryReader(buffer);
            var imagePointer = (byte*)imageData.Scan0;

            // Moved Regions
            var movedRegions = reader.ReadUnsignedVariableLength();
            if (movedRegions != 0)
            {
                var tempBuffer = new byte[bitmap.Width * bitmap.Height * 4];

                fixed (byte* tempBufferPointer = &tempBuffer[0])
                {
                    for (var n = 0; n < movedRegions; n++)
                    {
                        var fromX = reader.ReadUnsignedVariableLength();
                        var fromY = reader.ReadUnsignedVariableLength();
                        var toX = reader.ReadUnsignedVariableLength();
                        var toY = reader.ReadUnsignedVariableLength();
                        var width = reader.ReadUnsignedVariableLength();
                        var height = reader.ReadUnsignedVariableLength();
                        var region = new MovedRegion
                        { FromX = fromX, FromY = fromY, Height = height, ToX = toX, ToY = toY, Width = width };

                        CopyRegion(imagePointer, tempBufferPointer, bitmap.Width, region);
                        CopyRegion(tempBufferPointer, imagePointer, bitmap.Width, region);
                    }
                }
            }

            // Modified Regions
            var s = 0;
            while (reader.Position < count)
            {
                var i = reader.ReadSignedVariableLength();
                var pointer = imagePointer + s + i;

                var bg = reader.ReadByte();
                var gr = reader.ReadByte();
                pointer[0] = (byte)(bg & 248);
                pointer[1] = (byte)((bg & 7) << 5 | (gr & 7) << 2);
                pointer[2] = (byte)(gr & 248);

                s += i;
            }

            bitmap.UnlockBits(imageData);
        }