コード例 #1
0
        public override PixelBuffer ReadPixels(PixelFormat format, Rectangle rect)
        {
            Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0);

            rect.X += mSrcRect.X;
            rect.Y += mSrcRect.Y;

            int stride;
            int pixelPitch = mDisplay.GetPixelPitch(surf.Description.Format);

            PixelFormat pixelFormat = mDisplay.GetPixelFormat(surf.Description.Format);

            if (format == PixelFormat.Any)
            {
                format = pixelFormat;
            }

            GraphicsStream stm = surf.LockRectangle(
                new Drawing.Rectangle(0, 0, mTextureSize.Width, mTextureSize.Height),
                LockFlags.ReadOnly, out stride);

            byte[] array  = new byte[SurfaceWidth * SurfaceHeight * pixelPitch];
            int    length = SurfaceWidth * pixelPitch;
            int    index  = 0;

            unsafe
            {
                byte *ptr = (byte *)stm.InternalDataPointer;

                for (int i = rect.Top; i < rect.Bottom; i++)
                {
                    // hack if the size requested is too large.
                    if (i >= mTextureSize.Height)
                    {
                        break;
                    }

                    //IntPtr ptr = (IntPtr)((int)stm.InternalData + i * stride + rect.Left * pixelPitch);
                    IntPtr mptr = (IntPtr)(ptr + i * stride + rect.Left * pixelPitch);

                    Marshal.Copy(mptr, array, index, length);

                    index += length;
                }
            }

            surf.UnlockRectangle();
            surf.Dispose();

            return(new PixelBuffer(format, rect.Size, array, pixelFormat));
        }
コード例 #2
0
        public override bool IsColumnBlank(int col)
        {
            Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0);

            int            stride;
            GraphicsStream stm = surf.LockRectangle(Interop.Convert(mSrcRect),
                                                    LockFlags.ReadOnly, out stride);

            bool retval = this.IsColBlankScanARGB(stm.InternalData, col, this.SurfaceHeight,
                                                  stride, (int)(Display.AlphaThreshold * 255.0), 0xff000000, 24);

            surf.UnlockRectangle();

            return(retval);
        }