// DarthAffe 07.09.2023: Copied from https://github.com/DarthAffe/RGB.NET/blob/2e0754f474b82ed4d0cae5c6c44378d234f1321b/RGB.NET.Core/Rendering/Textures/Sampler/SamplerInfo.cs
using System;
namespace ScreenCapture.NET.Downscale;
///
/// Represents the information used to sample data.
///
/// The type of the data to sample.
internal readonly ref struct SamplerInfo
{
#region Properties & Fields
private readonly ReadOnlySpan _data;
private readonly int _x;
private readonly int _y;
private readonly int _stride;
private readonly int _dataPerPixel;
private readonly int _dataWidth;
///
/// Gets the width of the region the data comes from.
///
public readonly int Width;
///
/// Gets the height of region the data comes from.
///
public readonly int Height;
///
/// Gets the data for the requested row.
///
/// The row to get the data for.
/// A readonly span containing the data of the row.
public ReadOnlySpan this[int row] => _data.Slice((((_y + row) * _stride) + _x) * _dataPerPixel, _dataWidth);
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The X-location of the region the data comes from.
/// The Y-location of the region the data comes from.
/// The width of the region the data comes from.
/// The height of region the data comes from.
/// The number of pixels in a row of data.
/// The number of {T} representing a single pixel.
/// The data to sample.
public SamplerInfo(int x, int y, int width, int height, int stride, int dataPerPixel, in ReadOnlySpan data)
{
this._x = x;
this._y = y;
this._data = data;
this._stride = stride;
this._dataPerPixel = dataPerPixel;
this.Width = width;
this.Height = height;
_dataWidth = width * dataPerPixel;
}
#endregion
}