using System; using System.Runtime.InteropServices; using System.Text; namespace UnityEngine.XR.ARSubsystems { /// /// The color space, as defined by the /// EXIF specification. /// public enum XRCameraFrameExifDataColorSpace : ushort { /// /// sRGB color space. /// sRGB = 1, /// /// A color space other than sRGB is used. /// Uncalibrated = 65535, } /// /// The metering mode, as defined by the /// EXIF specification. /// public enum XRCameraFrameExifDataMeteringMode : ushort { /// /// Unknown. /// Unknown = 0, /// /// Average metering. /// Average = 1, /// /// Center-weighted metering. /// CenterWeightedAverage = 2, /// /// Spot metering. /// Spot = 3, /// /// MultiSpot metering. /// MultiSpot = 4, /// /// Pattern metering. /// Pattern = 5, /// /// Partial metering. /// Partial = 6, /// /// Other. /// Other = 255, } /// /// Represents the properties included in a camera frame's EXIF data. /// [Flags] public enum XRCameraFrameExifDataProperties { /// /// The camera frame EXIF data is disabled or unsupported. /// None = 0, /// /// The lens aperture of the frame is included. /// ApertureValue = 1 << 0, /// /// The brightness of the frame is included. /// BrightnessValue = 1 << 1, /// /// The exposure time of the frame is included. /// ExposureTime = 1 << 2, /// /// The shutter speed of the frame is included. /// ShutterSpeedValue = 1 << 3, /// /// The exposure bias of the frame is included. /// ExposureBiasValue = 1 << 4, /// /// The F number of the frame is included. /// FNumber = 1 << 5, /// /// The lens focal length of the frame is included. /// FocalLength = 1 << 6, /// /// The flash status of the frame is included. /// Flash = 1 << 7, /// /// The color space of the frame is included. /// ColorSpace = 1 << 8, /// /// The photographic sensitivity of the frame is included. /// PhotographicSensitivity = 1 << 9, /// /// The metering mode of the frame is included. /// MeteringMode = 1 << 10, } /// /// Represents EXIF data from the frame captured by the device camera. /// [StructLayout(LayoutKind.Sequential)] public struct XRCameraFrameExifData : IEquatable { IntPtr m_NativePtr; double m_ApertureValue; double m_BrightnessValue; double m_ExposureTime; double m_ShutterSpeedValue; float m_ExposureBiasValue; float m_FNumber; float m_FocalLength; short m_Flash; XRCameraFrameExifDataColorSpace m_ColorSpace; short m_PhotographicSensitivity; XRCameraFrameExifDataMeteringMode m_MeteringMode; XRCameraFrameExifDataProperties m_Properties; /// /// Points to a provider-specific data structure in unmanaged memory that you can use to access additional EXIF properties. /// Refer to your provider's documentation to learn how to use this pointer. /// public IntPtr nativePtr => m_NativePtr; /// /// Creates a . /// /// The native pointer. /// The lens aperture of the frame. /// The brightness of the frame. /// The exposure Time of the frame. /// The shutter speed of the frame. /// The exposure bias of the frame. /// The F number of the frame. /// The lens focal length of the frame. /// The flash status of the frame. /// The color space of the frame. /// The photographicSensitivity of the frame. /// The metering mode of the frame. /// The set of flags that indicates which properties are included in the EXIF data of the frame. public XRCameraFrameExifData( IntPtr nativePtr, double apertureValue, double brightnessValue, double exposureTime, double shutterSpeedValue, float exposureBiasValue, float fNumber, float focalLength, short flash, XRCameraFrameExifDataColorSpace colorSpace, short photographicSensitivity, XRCameraFrameExifDataMeteringMode meteringMode, XRCameraFrameExifDataProperties properties) { m_NativePtr = nativePtr; m_ApertureValue = apertureValue; m_BrightnessValue = brightnessValue; m_ExposureTime = exposureTime; m_ShutterSpeedValue = shutterSpeedValue; m_ExposureBiasValue = exposureBiasValue; m_FNumber = fNumber; m_FocalLength = focalLength; m_Flash = flash; m_ColorSpace = colorSpace; m_PhotographicSensitivity = photographicSensitivity; m_MeteringMode = meteringMode; m_Properties = properties; } /// /// Get the lens aperture of the frame if possible. /// /// The lens aperture of the camera frame. /// if the EXIF data contains the lens aperture of the frame. Otherwise, . public bool TryGetApertureValue(out double apertureValue) { if ((m_Properties & XRCameraFrameExifDataProperties.ApertureValue) != 0) { apertureValue = m_ApertureValue; return true; } apertureValue = default; return false; } /// /// Get the brightness of the frame if possible. /// /// The brightness of the camera frame. /// if the EXIF data contains the brightness of the frame. Otherwise, . public bool TryGetBrightnessValue(out double brightnessValue) { if ((m_Properties & XRCameraFrameExifDataProperties.BrightnessValue) != 0) { brightnessValue = m_BrightnessValue; return true; } brightnessValue = default; return false; } /// /// Get the exposure time of the frame if possible. /// /// The exposure time of the camera frame. /// if the EXIF data contains the exposure time of the frame. Otherwise, . public bool TryGetExposureTime(out double exposureTime) { if ((m_Properties & XRCameraFrameExifDataProperties.ExposureTime) != 0) { exposureTime = m_ExposureTime; return true; } exposureTime = default; return false; } /// /// Get the shutter speed of the frame if possible. /// /// The shutter speed of the camera frame. /// if the EXIF data contains the shutter speed of the frame. Otherwise, . public bool TryGetShutterSpeedValue(out double shutterSpeedValue) { if ((m_Properties & XRCameraFrameExifDataProperties.ShutterSpeedValue) != 0) { shutterSpeedValue = m_ShutterSpeedValue; return true; } shutterSpeedValue = default; return false; } /// /// Get the exposure bias of the frame if possible. /// /// The exposure bias of the camera frame. /// if the EXIF data contains the exposure bias of the frame. Otherwise, . public bool TryGetExposureBiasValue(out float exposureBiasValue) { if ((m_Properties & XRCameraFrameExifDataProperties.ExposureBiasValue) != 0) { exposureBiasValue = m_ExposureBiasValue; return true; } exposureBiasValue = default; return false; } /// /// Get the F number of the frame if possible. /// /// The F number of the camera frame. /// if the EXIF data contains the F number of the frame. Otherwise, . public bool TryGetFNumber(out float fNumber) { if ((m_Properties & XRCameraFrameExifDataProperties.FNumber) != 0) { fNumber = m_FNumber; return true; } fNumber = default; return false; } /// /// Get the lens focal length of the frame if possible. /// /// The lens focal length of the camera frame. /// if the EXIF data contains the lens focal length of the frame. Otherwise, . public bool TryGetFocalLength(out float focalLength) { if ((m_Properties & XRCameraFrameExifDataProperties.FocalLength) != 0) { focalLength = m_FocalLength; return true; } focalLength = default; return false; } /// /// Get the flash status of the frame if possible. /// /// The flash status of the camera frame. /// if the EXIF data contains the flash status of the frame. Otherwise, . public bool TryGetFlash(out short flash) { if ((m_Properties & XRCameraFrameExifDataProperties.Flash) != 0) { flash = m_Flash; return true; } flash = default; return false; } /// /// Get the color space of the frame if possible. /// /// The color space of the camera frame. /// if the EXIF data contains the color space of the frame. Otherwise, . public bool TryGetColorSpace(out XRCameraFrameExifDataColorSpace colorSpace) { if ((m_Properties & XRCameraFrameExifDataProperties.ColorSpace) != 0) { colorSpace = m_ColorSpace; return true; } colorSpace = default; return false; } /// /// Get the photographic sensitivity of the frame if possible. /// /// The photographic sensitivity of the camera frame. /// if the EXIF data contains the photographic sensitivity of the frame. Otherwise, . public bool TryGetPhotographicSensitivity(out short photographicSensitivity) { if ((m_Properties & XRCameraFrameExifDataProperties.PhotographicSensitivity) != 0) { photographicSensitivity = m_PhotographicSensitivity; return true; } photographicSensitivity = default; return false; } /// /// Get the metering mode of the frame if possible. /// /// The metering mode of the camera frame. /// if the EXIF data contains the metering mode of the frame. Otherwise, . public bool TryGetMeteringMode(out XRCameraFrameExifDataMeteringMode meteringMode) { if ((m_Properties & XRCameraFrameExifDataProperties.MeteringMode) != 0) { meteringMode = m_MeteringMode; return true; } meteringMode = default; return false; } /// /// Indicates whether any property was assigned a value. /// /// if any property was assigned a value. Otherwise, . public bool hasAnyProperties => (m_Properties != XRCameraFrameExifDataProperties.None); /// /// Compares for equality. /// /// The other to compare against. /// if the represents the same object. /// Otherwise, . public bool Equals(XRCameraFrameExifData other) { return m_NativePtr.Equals(other.m_NativePtr) && m_ApertureValue.Equals(other.m_ApertureValue) && m_BrightnessValue.Equals(other.m_BrightnessValue) && m_ExposureTime.Equals(other.m_ExposureTime) && m_ShutterSpeedValue.Equals(other.m_ShutterSpeedValue) && m_ExposureBiasValue.Equals(other.m_ExposureBiasValue) && m_FNumber.Equals(other.m_FNumber) && m_FocalLength.Equals(other.m_FocalLength) && m_Flash.Equals(other.m_Flash) && m_ColorSpace.Equals(other.m_ColorSpace) && m_PhotographicSensitivity.Equals(other.m_PhotographicSensitivity) && m_MeteringMode.Equals(other.m_MeteringMode) && m_Properties == other.m_Properties; } /// /// Compares for equality. /// /// An object to compare against. /// if is an and /// is also . Otherwise, . public override bool Equals(System.Object obj) { return obj is XRCameraFrameExifData data && Equals(data); } /// /// Compares and for equality using . /// /// The left-hand-side of the comparison. /// The right-hand-side of the comparison. /// if compares equal to . /// Otherwise, . public static bool operator ==(XRCameraFrameExifData lhs, XRCameraFrameExifData rhs) { return lhs.Equals(rhs); } /// /// Compares and for inequality using . /// /// The left-hand-side of the comparison. /// The right-hand-side of the comparison. /// if compares equal to . /// Otherwise, . public static bool operator !=(XRCameraFrameExifData lhs, XRCameraFrameExifData rhs) { return !lhs.Equals(rhs); } /// /// Generates a hash code suitable for use in HashSet and Dictionary. /// /// A hash of this . public override int GetHashCode() { int hashCode = 486187739; unchecked { hashCode = (hashCode * 486187739) + m_NativePtr.GetHashCode(); hashCode = (hashCode * 486187739) + m_ApertureValue.GetHashCode(); hashCode = (hashCode * 486187739) + m_BrightnessValue.GetHashCode(); hashCode = (hashCode * 486187739) + m_ExposureTime.GetHashCode(); hashCode = (hashCode * 486187739) + m_ShutterSpeedValue.GetHashCode(); hashCode = (hashCode * 486187739) + m_ExposureBiasValue.GetHashCode(); hashCode = (hashCode * 486187739) + m_FNumber.GetHashCode(); hashCode = (hashCode * 486187739) + m_FocalLength.GetHashCode(); hashCode = (hashCode * 486187739) + m_Flash.GetHashCode(); hashCode = (hashCode * 486187739) + m_ColorSpace.GetHashCode(); hashCode = (hashCode * 486187739) + m_PhotographicSensitivity.GetHashCode(); hashCode = (hashCode * 486187739) + m_MeteringMode.GetHashCode(); hashCode = (hashCode * 486187739) + ((int)m_Properties).GetHashCode(); } return hashCode; } /// /// Generates a string representation of this suitable for debugging purposes. /// /// A string representation of this . public override string ToString() { var sb = new StringBuilder(); sb.AppendLine("{"); sb.AppendLine($" ApertureValue: {m_ApertureValue}"); sb.AppendLine($" BrightnessValue: {m_BrightnessValue}"); sb.AppendLine($" ExposureTime: {m_ExposureTime}"); sb.AppendLine($" ShutterSpeed: {m_ShutterSpeedValue}"); sb.AppendLine($" ExposureBiasValue: {m_ExposureBiasValue}"); sb.AppendLine($" FNumber: {m_FNumber}"); sb.AppendLine($" FocalLength : {m_FocalLength}"); sb.AppendLine($" Flash: {m_Flash}"); sb.AppendLine($" ColorSpace: {m_ColorSpace}"); sb.AppendLine($" PhotographicSensitivity: {m_PhotographicSensitivity}"); sb.AppendLine($" MeteringMode: {m_MeteringMode}"); sb.AppendLine("}"); return sb.ToString(); } } }