コード例 #1
0
        /// <summary>
        /// <p>Instructs the object to produce pixels.</p>
        /// </summary>
        /// <typeparam name="T">Type of a pixel. This parameter must exactly match a pixel like using <see cref="Color"/> for a 32bit RGBA color or <see cref="RawVector4"/> for a 64bits for a RGBA 4 floats color.</typeparam>
        /// <param name="rectangle"><dd>  <p>The rectangle to copy. A <strong><c>null</c></strong> value specifies the entire bitmap.</p> </dd></param>
        /// <param name="output">The destination array. The size of the array must be sizeof(pixel) * rectangle.Width * rectangle.Height</param>
        /// <returns><p>If this method succeeds, it returns <strong><see cref="SharpDX.Result.Ok" /></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result" /></strong> error code.</p></returns>
        /// <exception cref="System.ArgumentException">output.Length must be equal to Width * Height</exception>
        /// <msdn-id>ee690179</msdn-id>
        ///   <unmanaged>HRESULT IWICBitmapSource::CopyPixels([In, Optional] const WICRect* prc,[In] unsigned int cbStride,[In] unsigned int cbBufferSize,[In] void* pbBuffer)</unmanaged>
        ///   <unmanaged-short>IWICBitmapSource::CopyPixels</unmanaged-short>
        /// <remarks><p><strong>CopyPixels</strong> is one of the two main image processing routines (the other being <strong>Lock</strong>) triggering the actual processing.  It instructs the object to produce pixels according to its algorithm - this may involve decoding a portion of a JPEG stored on disk, copying a block of memory, or even analytically computing a complex gradient.  The algorithm is completely dependent on the object implementing the interface. </p><p> The caller can restrict the operation to a rectangle of interest (ROI) using the prc parameter.  The ROI sub-rectangle must be fully contained in the bounds of the bitmap.  Specifying a <strong><c>null</c></strong> ROI implies that the whole bitmap should be returned.
        ///   </p><p> The caller controls the memory management and must provide an output buffer (<em>pbBuffer</em>) for the results of the copy along with the buffer's bounds (<em>cbBufferSize</em>).  The cbStride parameter defines the count of bytes between two vertically adjacent pixels in the output buffer.  The caller must ensure that there is sufficient buffer to complete the call based on the width, height and pixel format of the bitmap and the sub-rectangle provided to the copy method. </p><p> If the caller needs to perform numerous copies of an expensive <strong><see cref="SharpDX.WIC.BitmapSource" /></strong> such as a JPEG, it is recommended to create an in-memory <strong><see cref="SharpDX.WIC.Bitmap" /></strong> first. </p>Codec Developer Remarks<p> The callee must only write to the first (prc-&gt;Width*bitsperpixel+7)/8 bytes of each line of the output buffer (in this case, a line is a consecutive string of <em>cbStride</em> bytes). </p></remarks>
        public unsafe void CopyPixels <T>(RawBox rectangle, T[] output) where T : struct
        {
            if ((rectangle.Width * rectangle.Height) != output.Length)
            {
                throw new ArgumentException("output.Length must be equal to Width * Height");
            }

            CopyPixels(new IntPtr(&rectangle), rectangle.Width * Utilities.SizeOf <T>(), (int)output.Length * Utilities.SizeOf <T>(), (IntPtr)Interop.Fixed(output));
        }
コード例 #2
0
        private void UpdateBufferSize(RawBox box)
        {
            var boxArea = box.Width * box.Height;

            if (_intBuffer.Length != boxArea)
            {
                _intBuffer      = new int[boxArea];
                _tempByteBuffer = new byte[_intBuffer.Length * sizeof(int)];
            }
        }
コード例 #3
0
 public void CopyPixels(RawBox box, byte[] byteBuffer, Corner zeroPixelCorner, bool vertical, bool alternateStride)
 {
     if (IsBoxAValidRegion(box))
     {
         UpdateBufferSize(box);
         CopyWicPixelsToBuffer(box);
         CopyIntBufferToPreMapBuffer();
         PixelMapper.MapPixels(box.Width, box.Height, zeroPixelCorner, vertical, alternateStride, _preMapBuffer, byteBuffer);
     }
 }
コード例 #4
0
 private void CopyWicPixelsToBuffer(RawBox box)
 {
     if (_bitmap != null)
     {
         lock (_bitmapLock)
         {
             _bitmap.CopyPixels(box, _intBuffer);
         }
     }
 }
コード例 #5
0
 private bool IsBoxAValidRegion(RawBox box)
 {
     if (box.Width <= 0 ||
         box.Height <= 0 ||
         box.X + box.Width > BitmapWidth ||
         box.Y + box.Height > BitmapHeight ||
         box.X < 0 ||
         box.Y < 0)
     {
         return(false);
     }
     return(true);
 }
コード例 #6
0
 /// <summary>
 /// Copies pixel data using the supplied input parameters.
 /// </summary>
 /// <param name="rectangle">The rectangle.</param>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 /// <param name="guidDstFormat">The GUID DST format.</param>
 /// <param name="dstTransform">The DST transform.</param>
 /// <param name="stride">The stride.</param>
 /// <param name="output">The output.</param>
 /// <returns></returns>
 /// <unmanaged>HRESULT IWICBitmapSourceTransform::CopyPixels([In, Optional] const WICRect* prc,[In] unsigned int uiWidth,[In] unsigned int uiHeight,[In, Optional] GUID* pguidDstFormat,[In] WICBitmapTransformOptions dstTransform,[In] unsigned int nStride,[In] unsigned int cbBufferSize,[In] void* pbBuffer)</unmanaged>
 public unsafe void CopyPixels(RawBox rectangle, int width, int height, System.Guid guidDstFormat, SharpDX.WIC.BitmapTransformOptions dstTransform, int stride, DataStream output)
 {
     CopyPixels(new IntPtr(&rectangle), width, height, guidDstFormat, dstTransform, stride, (int)(output.Length - output.Position),
                output.PositionPointer);
 }
コード例 #7
0
        public void PaintToBitmap(Rectangle rc)
        {
            if (bitmap == null || drawType != DrawType.IMAGE)
            {
                return;
            }

            ScDrawNode rootNode;

            graphics.BeginDraw();
            rootNode = reDrawTree.ReCreateReDrawTree(rootScLayer, rc);
            reDrawTree.Draw(graphics);
            graphics.EndDraw();

            if (graphicsType == GraphicsType.D2D && rootNode != null)
            {
                unsafe
                {
                    RectangleF clip = rootNode.clipRect;
                    clip.X      = (int)(clip.X / sizeScale.Width);
                    clip.Y      = (int)(clip.Y / sizeScale.Height);
                    clip.Width  = (int)(clip.Width / sizeScale.Width);
                    clip.Height = (int)(clip.Height / sizeScale.Height);

                    Rectangle  bitmapRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                    BitmapData srcBmData  = bitmap.LockBits(bitmapRect, ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);


                    //DataPointer dataPtr = new DataPointer((IntPtr)srcBmData.Scan0, bitmap.Height * srcBmData.Stride);
                    //wicBitmap.CopyPixels(srcBmData.Stride, dataPtr);
                    byte *ptr = (byte *)srcBmData.Scan0;
                    ptr += (int)clip.Y * srcBmData.Stride + (int)clip.X * 4;
                    DataPointer dataPtr = new DataPointer(ptr, (int)clip.Height * srcBmData.Stride);
                    RawBox      box     = new RawBox((int)clip.X, (int)clip.Y, (int)clip.Width, (int)clip.Height);
                    wicBitmap.CopyPixels(box, srcBmData.Stride, dataPtr);


                    bitmap.UnlockBits(srcBmData);
                }

                //unsafe
                //{
                //    RectangleF clip = rootNode.clipRect;
                //    clip.X = (int)(clip.X / sizeScale.Width);
                //    clip.Y = (int)(clip.Y / sizeScale.Height);
                //    clip.Width = (int)(clip.Width / sizeScale.Width);
                //    clip.Height = (int)(clip.Height / sizeScale.Height);
                //    Rectangle bitmapRect = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
                //    BitmapData srcBmData = bitmap.LockBits(bitmapRect, ImageLockMode.ReadWrite, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);


                //    BitmapLock bmplock = wicBitmap.Lock(BitmapLockFlags.Read);
                //    DataRectangle dataRect = bmplock.Data;
                //    byte* wicPtr = (byte*)dataRect.DataPointer;

                //    byte* dstScan = (byte*)(srcBmData.Scan0);
                //    byte* dstPtr = dstScan + (int)clip.Y * srcBmData.Stride + (int)clip.X * 4;
                //    byte* srcPtr = wicPtr + (int)clip.Y * bmplock.Stride + (int)clip.X * 4;
                //    int pos;

                //    for (int i = 0; i < (int)clip.Height; i++)
                //    {
                //        pos = i * srcBmData.Stride;

                //        for (int j = 0; j < (int)clip.Width; j++)
                //        {
                //            *(uint*)(dstPtr + pos) = *(uint*)(srcPtr + pos);
                //            pos += 4;
                //        }
                //    }

                //    bmplock.Dispose();
                //    bitmap.UnlockBits(srcBmData);
                //}
            }
        }
コード例 #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Bitmap"/> class from a <see cref="BitmapSource"/>.
 /// </summary>
 /// <param name="factory">The factory.</param>
 /// <param name="bitmapSource">The bitmap source.</param>
 /// <param name="rectangle">The rectangle.</param>
 /// <msdn-id>ee690294</msdn-id>
 /// <unmanaged>HRESULT IWICImagingFactory::CreateBitmapFromSourceRect([In, Optional] IWICBitmapSource* pIBitmapSource,[In] unsigned int x,[In] unsigned int y,[In] unsigned int width,[In] unsigned int height,[Out, Fast] IWICBitmap** ppIBitmap)</unmanaged>
 /// <unmanaged-short>IWICImagingFactory::CreateBitmapFromSourceRect</unmanaged-short>
 public Bitmap(ImagingFactory factory, SharpDX.WIC.BitmapSource bitmapSource, RawBox rectangle)
     : base(IntPtr.Zero)
 {
     factory.CreateBitmapFromSourceRect(bitmapSource, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, this);
 }
コード例 #9
0
 /// <summary>
 /// <p>Provides access to a rectangular area of the bitmap.</p>
 /// </summary>
 /// <param name="rcLockRef"><dd>  <p>The rectangle to be accessed.</p> </dd></param>
 /// <param name="flags"><dd>  <p>The access mode you wish to obtain for the lock. This is a bitwise combination of <strong><see cref="SharpDX.WIC.BitmapLockFlags"/></strong> for read, write, or read and write access.</p> <table> <tr><th>Value</th><th>Meaning</th></tr> <tr><td><dl> <dt><strong><see cref="SharpDX.WIC.BitmapLockFlags.Read"/></strong></dt> </dl> </td><td> <p>The read access lock.</p> </td></tr> <tr><td><dl> <dt><strong><see cref="SharpDX.WIC.BitmapLockFlags.Write"/></strong></dt> </dl> </td><td> <p>The write access lock.</p> </td></tr> </table> <p>?</p> </dd></param>
 /// <returns><dd>  <p>A reference that receives the locked memory location.</p> </dd></returns>
 /// <remarks>
 /// <p>Locks are exclusive for writing but can be shared for reading. You cannot call <strong>CopyPixels</strong> while the <strong><see cref="SharpDX.WIC.Bitmap"/></strong> is locked for writing. Doing so will return an error, since locks are exclusive.</p>
 /// </remarks>
 /// <msdn-id>ee690187</msdn-id>
 /// <unmanaged>HRESULT IWICBitmap::Lock([In, Optional] const WICRect* prcLock,[In] WICBitmapLockFlags flags,[Out] IWICBitmapLock** ppILock)</unmanaged>
 /// <unmanaged-short>IWICBitmap::Lock</unmanaged-short>
 public unsafe SharpDX.WIC.BitmapLock Lock(RawBox rcLockRef, SharpDX.WIC.BitmapLockFlags flags)
 {
     return(this.Lock(new IntPtr(&rcLockRef), flags));
 }
コード例 #10
0
 /// <summary>
 /// <p>Encodes a bitmap source.</p>
 /// </summary>
 /// <param name="bitmapSourceRef"><dd>  <p>The bitmap source to encode.</p> </dd></param>
 /// <param name="rectangleRef"><dd>  <p>The size rectangle of the bitmap source.</p> </dd></param>
 /// <remarks>
 /// <p>If <strong>SetSize</strong> is not called prior to calling <strong>WriteSource</strong>, the size given in <em>prc</em> is used if not <strong><c>null</c></strong>. Otherwise, the size of the <strong><see cref="SharpDX.WIC.BitmapSource"/></strong> given in <em>pIBitmapSource</em> is used. </p><p>If <strong>SetPixelFormat</strong> is not called prior to calling <strong>WriteSource</strong>, the pixel format of the <strong><see cref="SharpDX.WIC.BitmapSource"/></strong> given in <em>pIBitmapSource</em> is used.</p><p>If <strong>SetResolution</strong> is not called prior to calling <strong>WriteSource</strong>, the pixel format of <em>pIBitmapSource</em> is used.</p><p>If <strong>SetPalette</strong> is not called prior to calling <strong>WriteSource</strong>, the target pixel format is indexed, and the pixel format of <em>pIBitmapSource</em> matches the encoder frame's pixel format, then the <em>pIBitmapSource</em> pixel format is used.</p><p>When encoding a GIF image, if the global palette is set and the frame level palette is not set directly by the user or by a custom independent software vendor (ISV) GIF codec, <strong>WriteSource</strong> will use the global palette to encode the frame even when <em>pIBitmapSource</em> has a frame level palette.</p><p><strong>Windows Vista:</strong>The source rect width must match the width set through SetSize. Repeated <strong>WriteSource</strong> calls can be made as long as the total accumulated source rect height is the same as set through SetSize.</p>
 /// </remarks>
 /// <include file='..\..\Documentation\CodeComments.xml' path="/comments/comment[@id='IWICBitmapFrameEncode::WriteSource']/*"/>
 /// <msdn-id>ee690159</msdn-id>
 /// <unmanaged>HRESULT IWICBitmapFrameEncode::WriteSource([In, Optional] IWICBitmapSource* pIBitmapSource,[In, Optional] WICRect* prc)</unmanaged>
 /// <unmanaged-short>IWICBitmapFrameEncode::WriteSource</unmanaged-short>
 public unsafe void WriteSource(SharpDX.WIC.BitmapSource bitmapSourceRef, RawBox rectangleRef)
 {
     WriteSource(bitmapSourceRef, new IntPtr(&rectangleRef));
 }
コード例 #11
0
ファイル: BitmapClipper.cs プロジェクト: zmtzawqlp/SharpDX
 /// <summary>
 /// <p>Initializes the bitmap clipper with the provided parameters.</p>
 /// </summary>
 /// <param name="sourceRef"><dd>  <p>he input bitmap source.</p> </dd></param>
 /// <param name="rectangleRef"><dd>  <p>The rectangle of the bitmap source to clip.</p> </dd></param>
 /// <returns><p>If this method succeeds, it returns <strong><see cref="SharpDX.Result.Ok"/></strong>. Otherwise, it returns an <strong><see cref="SharpDX.Result"/></strong> error code.</p></returns>
 /// <msdn-id>ee719677</msdn-id>
 /// <unmanaged>HRESULT IWICBitmapClipper::Initialize([In, Optional] IWICBitmapSource* pISource,[In] const WICRect* prc)</unmanaged>
 /// <unmanaged-short>IWICBitmapClipper::Initialize</unmanaged-short>
 public unsafe void Initialize(SharpDX.WIC.BitmapSource sourceRef, RawBox rectangleRef)
 {
     Initialize(sourceRef, new IntPtr(&rectangleRef));
 }
コード例 #12
0
 /// <summary>
 /// <p>Instructs the object to produce pixels.</p>
 /// </summary>
 /// <param name="rectangle"><dd>  <p>The rectangle to copy. A <strong><c>null</c></strong> value specifies the entire bitmap.</p> </dd></param>
 /// <param name="stride"><dd>  <p>The stride of the bitmap</p> </dd></param>
 /// <param name="dataPointer"><dd>  <p>A reference to the buffer.</p> </dd></param>
 /// <remarks>
 /// <p><strong>CopyPixels</strong> is one of the two main image processing routines (the other being <strong>Lock</strong>) triggering the actual processing.  It instructs the object to produce pixels according to its algorithm - this may involve decoding a portion of a JPEG stored on disk, copying a block of memory, or even analytically computing a complex gradient.  The algorithm is completely dependent on the object implementing the interface. </p><p> The caller can restrict the operation to a rectangle of interest (ROI) using the prc parameter.  The ROI sub-rectangle must be fully contained in the bounds of the bitmap.  Specifying a <strong><c>null</c></strong> ROI implies that the whole bitmap should be returned.
 /// </p><p> The caller controls the memory management and must provide an output buffer (<em>pbBuffer</em>) for the results of the copy along with the buffer's bounds (<em>cbBufferSize</em>).  The cbStride parameter defines the count of bytes between two vertically adjacent pixels in the output buffer.  The caller must ensure that there is sufficient buffer to complete the call based on the width, height and pixel format of the bitmap and the sub-rectangle provided to the copy method. </p><p> If the caller needs to perform numerous copies of an expensive <strong><see cref="SharpDX.WIC.BitmapSource"/></strong> such as a JPEG, it is recommended to create an in-memory <strong><see cref="SharpDX.WIC.Bitmap"/></strong> first. </p>Codec Developer Remarks<p> The callee must only write to the first (prc-&gt;Width*bitsperpixel+7)/8 bytes of each line of the output buffer (in this case, a line is a consecutive string of <em>cbStride</em> bytes). </p>
 /// </remarks>
 /// <msdn-id>ee690179</msdn-id>
 /// <unmanaged>HRESULT IWICBitmapSource::CopyPixels([In, Optional] const WICRect* prc,[In] unsigned int cbStride,[In] unsigned int cbBufferSize,[In] void* pbBuffer)</unmanaged>
 /// <unmanaged-short>IWICBitmapSource::CopyPixels</unmanaged-short>
 public unsafe void CopyPixels(RawBox rectangle, int stride, DataPointer dataPointer)
 {
     CopyPixels(new IntPtr(&rectangle), stride, (int)dataPointer.Size, dataPointer.Pointer);
 }