using System;
using System.Linq;
namespace NvAPIWrapper.Display
{
///
/// Represents a texture of intensity values
///
public class IntensityTexture : FloatTexture
{
///
/// Creates a new instance of .
///
/// The texture width.
/// The texture height.
public IntensityTexture(int width, int height) : base(width, height, 3)
{
}
private IntensityTexture(int width, int height, float[] floats) : base(width, height, 3, floats)
{
}
///
/// Returns a new instance of FloatTexture from the passed array of float values.
///
/// The texture width.
/// The texture height.
/// The array of float values.
/// A new instance of .
// ReSharper disable once TooManyArguments
public static IntensityTexture FromFloatArray(int width, int height, float[] floats)
{
if (floats.Length != width * height * 3)
{
throw new ArgumentOutOfRangeException(nameof(floats));
}
return new IntensityTexture(width, height, floats.ToArray());
}
///
/// Gets the value of intensity pixel at a specific location.
///
/// The horizontal location.
/// The vertical location.
/// An instance of .
public IntensityTexturePixel GetPixel(int x, int y)
{
return IntensityTexturePixel.FromFloatArray(UnderlyingArray, y * Width + x);
}
///
/// Sets the value of intensity pixel at a specific location
///
/// The horizontal location.
/// The vertical location.
/// An instance of .
public void SetPixel(int x, int y, IntensityTexturePixel pixel)
{
var index = y * Width + x;
var floats = pixel.ToFloatArray();
for (var i = 0; i < Math.Min(Channels, floats.Length); i++)
{
UnderlyingArray[index + i] = floats[i];
}
}
}
}