Beispiel #1
0
        // TODO: Test this method:
        public override void WritePixels(PixelBuffer buffer, Point startPoint)
        {
            Direct3D.Surface surf       = mTexture.Value.GetSurfaceLevel(0);
            Rectangle        updateRect = new Rectangle(startPoint, buffer.Size);

            int         pitch;
            int         pixelPitch  = mDisplay.GetPixelPitch(surf.Description.Format);
            PixelFormat pixelFormat = mDisplay.GetPixelFormat(surf.Description.Format);

            surf.Dispose();

            GraphicsStream stm = mTexture.Value.LockRectangle(0, Interop.Convert(updateRect), 0, out pitch);

            if (buffer.PixelFormat != pixelFormat)
            {
                buffer = buffer.ConvertTo(pixelFormat);
            }

            unsafe
            {
                for (int i = updateRect.Top; i < updateRect.Bottom; i++)
                {
                    int    startIndex = buffer.GetPixelIndex(0, i);
                    int    rowStride  = buffer.RowStride;
                    IntPtr dest       = (IntPtr)((byte *)stm.InternalData + i * pitch + updateRect.Left * pixelPitch);

                    Marshal.Copy(buffer.Data, startIndex, dest, rowStride);
                }
            }

            mTexture.Value.UnlockRectangle(0);
        }
Beispiel #2
0
        public override void WritePixels(PixelBuffer buffer)
        {
            if (buffer.PixelFormat != PixelFormat.RGBA8888 ||
                buffer.Size.Equals(mTextureSize) == false)
            {
                buffer = buffer.ConvertTo(PixelFormat.RGBA8888, mTextureSize);
            }

            unsafe
            {
                fixed(byte *ptr = buffer.Data)
                {
                    // Typical Texture Generation Using Data From The Bitmap
                    GL.BindTexture(TextureTarget.Texture2D, mTextureID);
                    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba,
                                  mTextureSize.Width, mTextureSize.Height, 0, OTKPixelFormat.Rgba,              //, GL.GL_BGRA,
                                  PixelType.UnsignedByte, (IntPtr)ptr);

                    GL.TexParameter(TextureTarget.Texture2D,
                                    TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
                    GL.TexParameter(TextureTarget.Texture2D,
                                    TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                }
            }
        }
Beispiel #3
0
        public void ConvertFormat()
        {
            var result = src.ConvertTo(PixelFormat.RGBA8888);

            Assert.IsTrue(PixelBuffer.PixelsEqual(result, src));

            result = src.ConvertTo(src.PixelFormat);
            Assert.IsTrue(PixelBuffer.PixelsEqual(result, src));
        }
Beispiel #4
0
        public override void WritePixels(PixelBuffer buffer)
        {
            BitmapData data = mImage.LockBits(new Rectangle(Point.Empty, Interop.Convert(SurfaceSize)),
                                              ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            if (buffer.PixelFormat != PixelFormat.BGRA8888)
            {
                buffer = buffer.ConvertTo(PixelFormat.BGRA8888);
            }

            Marshal.Copy(buffer.Data, 0, data.Scan0, buffer.Data.Length);

            mImage.UnlockBits(data);
        }
        // TODO: Test this method:
        public override void WritePixels(PixelBuffer buffer, Point startPoint)
        {
            Direct3D.Surface surf       = mTexture.Value.GetSurfaceLevel(0);
            Rectangle        updateRect = new Rectangle(startPoint, buffer.Size);

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

            surf.Dispose();

            // This should probably only lock the region of the surface we intend to update.
            // However, as is usually the case with DirectX, doing so gives weird errors
            // with no real explanation as to what is wrong.
            DataRectangle stm = mTexture.Value.LockRectangle
                                    (0, LockFlags.None);

            if (buffer.PixelFormat != pixelFormat)
            {
                buffer = buffer.ConvertTo(pixelFormat);
            }

            unsafe
            {
                for (int i = 0; i < buffer.Height; i++)
                {
                    int    startIndex = buffer.GetPixelIndex(0, i);
                    int    rowStride  = buffer.RowStride;
                    IntPtr dest       = (IntPtr)
                                        ((byte *)stm.Data.DataPointer + (i + updateRect.Top) * stm.Pitch
                                         + updateRect.Left * pixelPitch);

                    Marshal.Copy(buffer.Data, startIndex, dest, rowStride);
                }
            }

            mTexture.Value.UnlockRectangle(0);
        }
        public override void WritePixels(PixelBuffer buffer)
        {
            Direct3D.Surface surf = mTexture.Value.GetSurfaceLevel(0);

            if (surf.Description.Pool == Pool.Default)
            {
                throw new AgateLib.AgateException(
                          "Cannot write to FrameBuffer surface in Direct3D.");
            }

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

            surf.Dispose();

            DataRectangle stm = mTexture.Value.LockRectangle(0, 0);

            if (buffer.PixelFormat != pixelFormat)
            {
                buffer = buffer.ConvertTo(pixelFormat);
            }

            unsafe
            {
                for (int i = 0; i < SurfaceHeight; i++)
                {
                    int    startIndex = buffer.GetPixelIndex(0, i);
                    int    rowStride  = buffer.RowStride;
                    IntPtr dest       = (IntPtr)((byte *)stm.Data.DataPointer + i * stm.Pitch);

                    Marshal.Copy(buffer.Data, startIndex, dest, rowStride);
                }
            }

            mTexture.Value.UnlockRectangle(0);
        }
Beispiel #7
0
        /// <summary>
        /// Saves a pixel buffer to an image file using a System.Drawing.Bitmap object.
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="filename"></param>
        /// <param name="format"></param>
        public static void SavePixelBuffer(PixelBuffer buffer, string filename, ImageFileFormat format)
        {
            Bitmap bmp = new Bitmap(buffer.Width, buffer.Height);

            System.Drawing.Imaging.BitmapData data = bmp.LockBits(
                new Rectangle(Point.Empty, Interop.Convert(buffer.Size)),
                System.Drawing.Imaging.ImageLockMode.WriteOnly,
                System.Drawing.Imaging.PixelFormat.Format32bppArgb);

            if (buffer.PixelFormat != PixelFormat.BGRA8888)
            {
                buffer = buffer.ConvertTo(PixelFormat.BGRA8888);
            }

            System.Runtime.InteropServices.Marshal.Copy(
                buffer.Data, 0, data.Scan0, buffer.Data.Length);

            bmp.UnlockBits(data);

            switch (format)
            {
            case ImageFileFormat.Bmp:
                bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Bmp);
                break;

            case ImageFileFormat.Jpg:
                bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Jpeg);
                break;

            case ImageFileFormat.Png:
                bmp.Save(filename, System.Drawing.Imaging.ImageFormat.Png);
                break;
            }

            bmp.Dispose();
        }