public unsafe void GetValue(BlockPtr blockPtr, IntPtr buffer)
        {
            if (this.BitIndex == 0)
            {
                WinApi.CopyMemory(buffer, blockPtr.value + this.Offset, this.Size);

                if (this.IsReference)
                {
                    IntPtr *p = (IntPtr *)buffer.ToPointer();
                    if (p[0] != IntPtr.Zero)
                    {
                        p[0] -= _ctx.ObjRefDiff;
                    }
                }
            }
            else
            {
                var buff = new byte[this.Size];
                Marshal.Copy(blockPtr.value + this.Offset, buff, 0, this.Size);
                var rawValue  = new BigInteger(buff);
                var valueMask = BigInteger.Pow(2, this.BitsCount) - 1;

                var value = (rawValue >> (this.BitIndex - this.BitsCount)) & valueMask;

                var valueBytes = value.ToByteArray();
                Marshal.Copy(valueBytes, 0, buffer, valueBytes.Length);
            }
        }
예제 #2
0
        internal void Load(Bitmap image)
        {
            Empty(image.Width, image.Height);
            int pixelCount = Size.Width * Size.Height;

            IntPtr   intsPointer   = image.LockBits(new Rectangle(0, 0, Size.Width, Size.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb).Scan0;
            GCHandle pixelsPointer = GCHandle.Alloc(Pixels, GCHandleType.Pinned);

            try {
                WinApi.CopyMemory(pixelsPointer.AddrOfPinnedObject(), intsPointer, (IntPtr)(pixelCount * 4));
            } finally {
                pixelsPointer.Free();
            }
            //image.UnlockBits();
        }