using System; using System.Runtime.InteropServices; using NvAPIWrapper.Native.Attributes; using NvAPIWrapper.Native.General.Structures; using NvAPIWrapper.Native.Helpers; using NvAPIWrapper.Native.Interfaces; namespace NvAPIWrapper.Native.Display.Structures { /// [StructLayout(LayoutKind.Sequential, Pack = 8)] [StructureVersion(2)] public struct ScanOutIntensityV2 : IDisposable, IInitializable, IScanOutIntensity { internal StructureVersion _Version; internal uint _Width; internal uint _Height; internal IntPtr _BlendingTexture; internal IntPtr _OffsetTexture; internal uint _OffsetTextureChannels; /// /// Creates a new instance of . /// /// The width of the input texture. /// The height of the input texture /// The array of floating values building an intensity RGB texture /// The number of channels per pixel in the offset texture /// The array of floating values building an offset texture // ReSharper disable once TooManyDependencies public ScanOutIntensityV2( uint width, uint height, float[] blendingTexture, uint offsetTextureChannels, float[] offsetTexture) { if (blendingTexture?.Length != width * height * 3) { throw new ArgumentOutOfRangeException(nameof(blendingTexture)); } if (offsetTexture?.Length != width * height * offsetTextureChannels) { throw new ArgumentOutOfRangeException(nameof(offsetTexture)); } this = typeof(ScanOutIntensityV2).Instantiate(); _Width = width; _Height = height; _BlendingTexture = Marshal.AllocHGlobal((int) (width * height * 3 * sizeof(float))); Marshal.Copy(blendingTexture, 0, _BlendingTexture, blendingTexture.Length); _OffsetTextureChannels = offsetTextureChannels; _OffsetTexture = Marshal.AllocHGlobal((int) (width * height * offsetTextureChannels * sizeof(float))); Marshal.Copy(offsetTexture, 0, _OffsetTexture, offsetTexture.Length); } /// public uint Width { get => _Width; } /// public uint Height { get => _Height; } /// /// Gets the number of channels per pixel in the offset texture /// public uint OffsetTextureChannels { get => _OffsetTextureChannels; } /// public float[] BlendingTexture { get { var floats = new float[_Width * _Height * 3]; Marshal.Copy(_BlendingTexture, floats, 0, floats.Length); return floats; } } /// /// Gets the array of floating values building an offset texture /// public float[] OffsetTexture { get { var floats = new float[_Width * _Height * _OffsetTextureChannels]; Marshal.Copy(_OffsetTexture, floats, 0, floats.Length); return floats; } } /// public void Dispose() { Marshal.FreeHGlobal(_BlendingTexture); Marshal.FreeHGlobal(_OffsetTexture); } } }