using System;
using System.Runtime.InteropServices;
namespace UnityEngine.XR.ARSubsystems
{
public partial struct XRCpuImage
{
///
/// Describes a set of conversion parameters for use with 's conversion methods.
///
[StructLayout(LayoutKind.Sequential)]
public struct ConversionParams : IEquatable
{
RectInt m_InputRect;
Vector2Int m_OutputDimensions;
TextureFormat m_Format;
Transformation m_Transformation;
///
/// The portion of the original image that will be used as input to the conversion.
///
///
/// The input rectangle must be completely contained inside the XRCpuImage
/// .
///
///
/// The portion of the original image that will be converted.
///
public RectInt inputRect
{
get => m_InputRect;
set => m_InputRect = value;
}
///
/// The dimensions of the converted image. The output dimensions must be less than or equal to the
/// 's dimensions. If the output dimensions are less than the 's
/// dimensions, downsampling is performed using nearest neighbor.
///
///
/// The dimensions of the converted image.
///
public Vector2Int outputDimensions
{
get => m_OutputDimensions;
set => m_OutputDimensions = value;
}
///
/// The TextureFormat to which to convert. See for a list of
/// supported formats.
///
///
/// The TextureFormat to which to convert.
///
public TextureFormat outputFormat
{
get => m_Format;
set => m_Format = value;
}
///
/// The transformation to apply to the image during conversion.
///
///
/// The transformation to apply to the image during conversion.
///
public Transformation transformation
{
get => m_Transformation;
set => m_Transformation = value;
}
///
/// Constructs a using the 's full
/// resolution. That is, it sets to (0, 0, image.width, image.height) and
/// to (image.width, image.height).
///
/// The source .
/// The TextureFormat to convert to.
/// An optional to apply.
public ConversionParams(
XRCpuImage image,
TextureFormat format,
Transformation transformation = Transformation.None)
{
m_InputRect = new RectInt(0, 0, image.width, image.height);
m_OutputDimensions = new Vector2Int(image.width, image.height);
m_Format = format;
m_Transformation = transformation;
}
///
/// Generates a hash suitable for use with containers like `HashSet` and `Dictionary`.
///
/// A hash code generated from this object's fields.
public override int GetHashCode()
{
var hash = HashCodeUtil.Combine(inputRect.width.GetHashCode(), inputRect.height.GetHashCode(), inputRect.x.GetHashCode(), inputRect.y.GetHashCode());
return HashCodeUtil.Combine(hash, outputDimensions.GetHashCode(), ((int)outputFormat).GetHashCode(), ((int)transformation).GetHashCode());
}
///
/// Tests for equality.
///
/// The other to compare against.
/// `True` if every field in is equal to this , otherwise false.
public bool Equals(ConversionParams other)
{
return (inputRect.Equals(other.inputRect) && outputDimensions.Equals(other.outputDimensions)
&& (outputFormat == other.outputFormat) && (transformation == other.transformation));
}
///
/// Tests for equality.
///
/// The `object` to compare against.
/// `True` if is of type and
/// also returns `true`; otherwise `false`.
public override bool Equals(object obj)
{
return (obj is ConversionParams) && Equals((ConversionParams)obj);
}
///
/// Tests for equality. Same as .
///
/// The to compare with .
/// The to compare with .
/// `True` if is equal to , otherwise `false`.
public static bool operator ==(ConversionParams lhs, ConversionParams rhs) => lhs.Equals(rhs);
///
/// Tests for inequality. Same as `!`.
///
/// The to compare with .
/// The to compare with .
/// `True` if is not equal to , otherwise `false`.
public static bool operator !=(ConversionParams lhs, ConversionParams rhs) => !lhs.Equals(rhs);
///
/// Generates a string representation of this .
///
/// A string representation of this .
public override string ToString()
=> $"inputRect: {inputRect} outputDimensions: {outputDimensions} format: {outputFormat} transformation: {transformation})";
}
}
}