// 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; namespace SharpDX.WIC { public partial class Palette { /// /// Initializes a new instance of the class. /// /// The factory. /// ee690319 /// HRESULT IWICImagingFactory::CreatePalette([Out, Fast] IWICPalette** ppIPalette) /// IWICImagingFactory::CreatePalette public Palette(ImagingFactory factory) : base(IntPtr.Zero) { factory.CreatePalette(this); } /// /// Initializes with the specified colors. /// /// Type of the color (must be 4 bytes, RGBA) /// The colors. /// Color type must be 4 bytes /// ee719750 /// HRESULT IWICPalette::InitializeCustom([In, Buffer] void* pColors,[In] unsigned int cCount) /// IWICPalette::InitializeCustom public unsafe void Initialize(T[] colors) where T : struct { if (Utilities.SizeOf() != 4) throw new ArgumentException("Color type must be 4 bytes RGBA"); void* pColors = Interop.Fixed(colors); Initialize((IntPtr)pColors, colors.Length); } /// /// Gets the colors. /// /// ee719744 /// HRESULT IWICPalette::GetColors([In] unsigned int cCount,[Out, Buffer] void* pColors,[Out] unsigned int* pcActualColors) /// IWICPalette::GetColors public T[] GetColors() where T : struct { if (Utilities.SizeOf() != 4) throw new ArgumentException("Color type must be 4 bytes RGBA"); unsafe { //http://msdn.microsoft.com/en-us/library/windows/desktop/ee719741(v=vs.85).aspx int actualCount; int count = this.ColorCount; var rawColors = new T[count]; { void* pColors = Interop.Fixed(rawColors); GetColors(count, (IntPtr)pColors, out actualCount); } if (actualCount == 0) return new T[0]; if (count != actualCount) { rawColors = new T[actualCount]; void* pColors = Interop.Fixed(rawColors); GetColors(actualCount, (IntPtr)pColors, out actualCount); } return rawColors; } } } }