SW 중심대학 OSS GIT 서버 박건태, 이승준, 고기완, 이준호 새로운 배포
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
5.1 KiB

4 years ago
  1. using System;
  2. using System.Runtime.InteropServices;
  3. namespace UnityEngine.XR.ARSubsystems
  4. {
  5. /// <summary>
  6. /// Describes a set of conversion parameters for use with <see cref="XRCameraImage"/>'s conversion methods.
  7. /// </summary>
  8. [StructLayout(LayoutKind.Sequential)]
  9. public struct XRCameraImageConversionParams : IEquatable<XRCameraImageConversionParams>
  10. {
  11. RectInt m_InputRect;
  12. Vector2Int m_OutputDimensions;
  13. TextureFormat m_Format;
  14. CameraImageTransformation m_Transformation;
  15. /// <summary>
  16. /// The portion of the original image that will be used as input to the conversion.
  17. /// </summary>
  18. /// <remarks>
  19. /// The input rectangle must be completely contained inside the <c>XRCameraImage</c>
  20. /// <see cref="XRCameraImage.dimensions"/>.
  21. /// </remarks>
  22. /// <value>
  23. /// The portion of the original image that will be converted.
  24. /// </value>
  25. public RectInt inputRect
  26. {
  27. get { return m_InputRect; }
  28. set { m_InputRect = value; }
  29. }
  30. /// <summary>
  31. /// The dimensions of the converted image. The output dimensions must be less than or equal to the
  32. /// <see cref="inputRect"/>'s dimensions. If the output dimensions are less than the <see cref="inputRect"/>'s
  33. /// dimensions, downsampling is performed using nearest neighbor.
  34. /// </summary>
  35. /// <value>
  36. /// The dimensions of the converted image.
  37. /// </value>
  38. public Vector2Int outputDimensions
  39. {
  40. get { return m_OutputDimensions; }
  41. set { m_OutputDimensions = value; }
  42. }
  43. /// <summary>
  44. /// The <c>TextureFormat</c> to which to convert. See <see cref="XRCameraImage.FormatSupported"/> for a list of
  45. /// supported formats.
  46. /// </summary>
  47. /// <value>
  48. /// The <c>TextureFormat</c> to which to convert.
  49. /// </value>
  50. public TextureFormat outputFormat
  51. {
  52. get { return m_Format; }
  53. set { m_Format = value; }
  54. }
  55. /// <summary>
  56. /// The transformation to apply to the image during conversion.
  57. /// </summary>
  58. /// <value>
  59. /// The transformation to apply to the image during conversion.
  60. /// </value>
  61. public CameraImageTransformation transformation
  62. {
  63. get { return m_Transformation; }
  64. set { m_Transformation = value; }
  65. }
  66. /// <summary>
  67. /// Constructs a <see cref="XRCameraImageConversionParams"/> using the <paramref name="image"/>'s full
  68. /// resolution. That is, it sets <see cref="inputRect"/> to <c>(0, 0, image.width, image.height)</c> and
  69. /// <see cref="outputDimensions"/> to <c>(image.width, image.height)</c>.
  70. /// </summary>
  71. /// <param name="image">The source <see cref="XRCameraImage"/>.</param>
  72. /// <param name="format">The <c>TextureFormat</c> to convert to.</param>
  73. /// <param name="transformation">An optional <see cref="CameraImageTransformation"/> to apply.</param>
  74. public XRCameraImageConversionParams(
  75. XRCameraImage image,
  76. TextureFormat format,
  77. CameraImageTransformation transformation = CameraImageTransformation.None)
  78. {
  79. m_InputRect = new RectInt(0, 0, image.width, image.height);
  80. m_OutputDimensions = new Vector2Int(image.width, image.height);
  81. m_Format = format;
  82. m_Transformation = transformation;
  83. }
  84. public override int GetHashCode()
  85. {
  86. unchecked
  87. {
  88. var hash = inputRect.GetHashCode();
  89. hash = hash * 486187739 + outputDimensions.GetHashCode();
  90. hash = hash * 486187739 + ((int)outputFormat).GetHashCode();
  91. hash = hash * 486187739 + ((int)transformation).GetHashCode();
  92. return hash;
  93. }
  94. }
  95. public bool Equals(XRCameraImageConversionParams other)
  96. {
  97. return (inputRect.Equals(other.inputRect) && outputDimensions.Equals(other.outputDimensions)
  98. && outputFormat.Equals(other.outputFormat) && transformation.Equals(other.transformation));
  99. }
  100. public override bool Equals(object obj)
  101. {
  102. return (ReferenceEquals(this, obj)
  103. || ((obj is XRCameraImageConversionParams) && Equals((XRCameraImageConversionParams)obj)));
  104. }
  105. public static bool operator ==(XRCameraImageConversionParams lhs, XRCameraImageConversionParams rhs)
  106. {
  107. return lhs.Equals(rhs);
  108. }
  109. public static bool operator !=(XRCameraImageConversionParams lhs, XRCameraImageConversionParams rhs)
  110. {
  111. return !lhs.Equals(rhs);
  112. }
  113. public override string ToString()
  114. {
  115. return string.Format(
  116. "inputRect: {0} outputDimensions: {1} format: {2} transformation: {3})",
  117. inputRect,
  118. outputDimensions,
  119. outputFormat,
  120. transformation);
  121. }
  122. }
  123. }