// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; using System.ComponentModel; using SharpDX.Mathematics.Interop; namespace SharpDX.WIC { public partial class BitmapFrameEncode { /// /// Initializes a new instance of the class. /// /// The encoder. /// HRESULT IWICBitmapEncoder::CreateNewFrame([Out] IWICBitmapFrameEncode** ppIFrameEncode,[Out] IPropertyBag2** ppIEncoderOptions) public BitmapFrameEncode(BitmapEncoder encoder) { Options = new BitmapEncoderOptions(IntPtr.Zero); encoder.CreateNewFrame(this, Options); } /// /// Gets the properties to setup before . /// public BitmapEncoderOptions Options { get; private set; } /// /// Initializes this instance. /// /// HRESULT IWICBitmapFrameEncode::Initialize([In, Optional] IPropertyBag2* pIEncoderOptions) public void Initialize() { Initialize(Options); } /// /// Sets the objects for this frame encoder. /// /// The color contexts to set for the encoder. /// If the method succeeds, it returns . Otherwise, it throws an exception. /// HRESULT IWICBitmapFrameEncode::SetColorContexts([In] unsigned int cCount,[In, Buffer] IWICColorContext** ppIColorContext) public void SetColorContexts(SharpDX.WIC.ColorContext[] colorContextOut) { SetColorContexts(colorContextOut != null ? colorContextOut.Length : 0, colorContextOut); } /// ///

Encodes the frame scanlines.

///
///

The number of lines to encode.

/// A data buffer containing the pixels to copy from. /// Total size in bytes of pixels to write. If == 0, size is calculated with lineCount * rowStride. /// ///

Successive WritePixels calls are assumed to be sequential scanline access in the output image.

///
/// ee690158 /// HRESULT IWICBitmapFrameEncode::WritePixels([In] unsigned int lineCount,[In] unsigned int cbStride,[In] unsigned int cbBufferSize,[In, Buffer] void* pbPixels) /// IWICBitmapFrameEncode::WritePixels public void WritePixels(int lineCount, DataRectangle buffer, int totalSizeInBytes = 0) { WritePixels(lineCount, buffer.DataPointer, buffer.Pitch, totalSizeInBytes); } /// ///

Encodes the frame scanlines.

///
///

The number of lines to encode.

/// A data buffer containing the pixels to copy from. /// The stride of one row. /// Total size in bytes of pixels to write. If == 0, size is calculated with lineCount * rowStride. /// ///

Successive WritePixels calls are assumed to be sequential scanline access in the output image.

///
/// ee690158 /// HRESULT IWICBitmapFrameEncode::WritePixels([In] unsigned int lineCount,[In] unsigned int cbStride,[In] unsigned int cbBufferSize,[In, Buffer] void* pbPixels) /// IWICBitmapFrameEncode::WritePixels public void WritePixels(int lineCount, IntPtr buffer, int rowStride, int totalSizeInBytes = 0) { if (totalSizeInBytes == 0) totalSizeInBytes = lineCount * rowStride; WritePixels(lineCount, rowStride, totalSizeInBytes, buffer); } /// ///

Encodes the frame scanlines.

///
///

The number of lines to encode.

///

The stride of the image pixels.

///

A reference to the pixel buffer.

/// ///

Successive WritePixels calls are assumed to be sequential scanline access in the output image.

///
/// ee690158 /// HRESULT IWICBitmapFrameEncode::WritePixels([In] unsigned int lineCount,[In] unsigned int cbStride,[In] unsigned int cbBufferSize,[In, Buffer] void* pbPixels) /// IWICBitmapFrameEncode::WritePixels public unsafe void WritePixels(int lineCount, int stride, T[] pixelBuffer) where T : struct { if ((lineCount * stride) > (Utilities.SizeOf() * pixelBuffer.Length)) throw new ArgumentException("lineCount * stride must be <= to sizeof(pixelBuffer)"); WritePixels(lineCount, stride, lineCount * stride, (IntPtr)Interop.Fixed(pixelBuffer)); } /// ///

Encodes a bitmap source.

///
///

The bitmap source to encode.

/// ///

If SetSize is not called prior to calling WriteSource, the size given in prc is used if not null. Otherwise, the size of the given in pIBitmapSource is used.

If SetPixelFormat is not called prior to calling WriteSource, the pixel format of the given in pIBitmapSource is used.

If SetResolution is not called prior to calling WriteSource, the pixel format of pIBitmapSource is used.

If SetPalette is not called prior to calling WriteSource, the target pixel format is indexed, and the pixel format of pIBitmapSource matches the encoder frame's pixel format, then the pIBitmapSource pixel format is used.

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, WriteSource will use the global palette to encode the frame even when pIBitmapSource has a frame level palette.

Windows Vista:The source rect width must match the width set through SetSize. Repeated WriteSource calls can be made as long as the total accumulated source rect height is the same as set through SetSize.

///
/// /// ee690159 /// HRESULT IWICBitmapFrameEncode::WriteSource([In, Optional] IWICBitmapSource* pIBitmapSource,[In, Optional] WICRect* prc) /// IWICBitmapFrameEncode::WriteSource public void WriteSource(SharpDX.WIC.BitmapSource bitmapSource) { WriteSource(bitmapSource, IntPtr.Zero); } /// ///

Encodes a bitmap source.

///
///

The bitmap source to encode.

///

The size rectangle of the bitmap source.

/// ///

If SetSize is not called prior to calling WriteSource, the size given in prc is used if not null. Otherwise, the size of the given in pIBitmapSource is used.

If SetPixelFormat is not called prior to calling WriteSource, the pixel format of the given in pIBitmapSource is used.

If SetResolution is not called prior to calling WriteSource, the pixel format of pIBitmapSource is used.

If SetPalette is not called prior to calling WriteSource, the target pixel format is indexed, and the pixel format of pIBitmapSource matches the encoder frame's pixel format, then the pIBitmapSource pixel format is used.

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, WriteSource will use the global palette to encode the frame even when pIBitmapSource has a frame level palette.

Windows Vista:The source rect width must match the width set through SetSize. Repeated WriteSource calls can be made as long as the total accumulated source rect height is the same as set through SetSize.

///
/// /// ee690159 /// HRESULT IWICBitmapFrameEncode::WriteSource([In, Optional] IWICBitmapSource* pIBitmapSource,[In, Optional] WICRect* prc) /// IWICBitmapFrameEncode::WriteSource public unsafe void WriteSource(SharpDX.WIC.BitmapSource bitmapSourceRef, RawBox rectangleRef) { WriteSource(bitmapSourceRef, new IntPtr(&rectangleRef)); } protected override unsafe void Dispose(bool disposing) { if (disposing) { Options.Dispose(); Options = null; } base.Dispose(disposing); } } }