ColorFrame.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using RootSystem = System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace Windows.Kinect
  5. {
  6. //
  7. // Windows.Kinect.ColorFrame
  8. //
  9. public sealed partial class ColorFrame : RootSystem.IDisposable, Helper.INativeWrapper
  10. {
  11. internal RootSystem.IntPtr _pNative;
  12. RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
  13. // Constructors and Finalizers
  14. internal ColorFrame(RootSystem.IntPtr pNative)
  15. {
  16. _pNative = pNative;
  17. Windows_Kinect_ColorFrame_AddRefObject(ref _pNative);
  18. }
  19. ~ColorFrame()
  20. {
  21. Dispose(false);
  22. }
  23. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  24. private static extern void Windows_Kinect_ColorFrame_ReleaseObject(ref RootSystem.IntPtr pNative);
  25. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  26. private static extern void Windows_Kinect_ColorFrame_AddRefObject(ref RootSystem.IntPtr pNative);
  27. private void Dispose(bool disposing)
  28. {
  29. if (_pNative == RootSystem.IntPtr.Zero)
  30. {
  31. return;
  32. }
  33. __EventCleanup();
  34. Helper.NativeObjectCache.RemoveObject<ColorFrame>(_pNative);
  35. if (disposing)
  36. {
  37. Windows_Kinect_ColorFrame_Dispose(_pNative);
  38. }
  39. Windows_Kinect_ColorFrame_ReleaseObject(ref _pNative);
  40. _pNative = RootSystem.IntPtr.Zero;
  41. }
  42. // Public Properties
  43. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  44. private static extern RootSystem.IntPtr Windows_Kinect_ColorFrame_get_ColorCameraSettings(RootSystem.IntPtr pNative);
  45. public Windows.Kinect.ColorCameraSettings ColorCameraSettings
  46. {
  47. get
  48. {
  49. if (_pNative == RootSystem.IntPtr.Zero)
  50. {
  51. throw new RootSystem.ObjectDisposedException("ColorFrame");
  52. }
  53. RootSystem.IntPtr objectPointer = Windows_Kinect_ColorFrame_get_ColorCameraSettings(_pNative);
  54. Helper.ExceptionHelper.CheckLastError();
  55. if (objectPointer == RootSystem.IntPtr.Zero)
  56. {
  57. return null;
  58. }
  59. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.ColorCameraSettings>(objectPointer, n => new Windows.Kinect.ColorCameraSettings(n));
  60. }
  61. }
  62. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  63. private static extern RootSystem.IntPtr Windows_Kinect_ColorFrame_get_ColorFrameSource(RootSystem.IntPtr pNative);
  64. public Windows.Kinect.ColorFrameSource ColorFrameSource
  65. {
  66. get
  67. {
  68. if (_pNative == RootSystem.IntPtr.Zero)
  69. {
  70. throw new RootSystem.ObjectDisposedException("ColorFrame");
  71. }
  72. RootSystem.IntPtr objectPointer = Windows_Kinect_ColorFrame_get_ColorFrameSource(_pNative);
  73. Helper.ExceptionHelper.CheckLastError();
  74. if (objectPointer == RootSystem.IntPtr.Zero)
  75. {
  76. return null;
  77. }
  78. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.ColorFrameSource>(objectPointer, n => new Windows.Kinect.ColorFrameSource(n));
  79. }
  80. }
  81. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  82. private static extern RootSystem.IntPtr Windows_Kinect_ColorFrame_get_FrameDescription(RootSystem.IntPtr pNative);
  83. public Windows.Kinect.FrameDescription FrameDescription
  84. {
  85. get
  86. {
  87. if (_pNative == RootSystem.IntPtr.Zero)
  88. {
  89. throw new RootSystem.ObjectDisposedException("ColorFrame");
  90. }
  91. RootSystem.IntPtr objectPointer = Windows_Kinect_ColorFrame_get_FrameDescription(_pNative);
  92. Helper.ExceptionHelper.CheckLastError();
  93. if (objectPointer == RootSystem.IntPtr.Zero)
  94. {
  95. return null;
  96. }
  97. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.FrameDescription>(objectPointer, n => new Windows.Kinect.FrameDescription(n));
  98. }
  99. }
  100. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  101. private static extern Windows.Kinect.ColorImageFormat Windows_Kinect_ColorFrame_get_RawColorImageFormat(RootSystem.IntPtr pNative);
  102. public Windows.Kinect.ColorImageFormat RawColorImageFormat
  103. {
  104. get
  105. {
  106. if (_pNative == RootSystem.IntPtr.Zero)
  107. {
  108. throw new RootSystem.ObjectDisposedException("ColorFrame");
  109. }
  110. return Windows_Kinect_ColorFrame_get_RawColorImageFormat(_pNative);
  111. }
  112. }
  113. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  114. private static extern long Windows_Kinect_ColorFrame_get_RelativeTime(RootSystem.IntPtr pNative);
  115. public RootSystem.TimeSpan RelativeTime
  116. {
  117. get
  118. {
  119. if (_pNative == RootSystem.IntPtr.Zero)
  120. {
  121. throw new RootSystem.ObjectDisposedException("ColorFrame");
  122. }
  123. return RootSystem.TimeSpan.FromMilliseconds(Windows_Kinect_ColorFrame_get_RelativeTime(_pNative));
  124. }
  125. }
  126. // Public Methods
  127. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  128. private static extern void Windows_Kinect_ColorFrame_CopyRawFrameDataToArray(RootSystem.IntPtr pNative, RootSystem.IntPtr frameData, int frameDataSize);
  129. public void CopyRawFrameDataToArray(byte[] frameData)
  130. {
  131. if (_pNative == RootSystem.IntPtr.Zero)
  132. {
  133. throw new RootSystem.ObjectDisposedException("ColorFrame");
  134. }
  135. var frameDataSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(frameData, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  136. var _frameData = frameDataSmartGCHandle.AddrOfPinnedObject();
  137. Windows_Kinect_ColorFrame_CopyRawFrameDataToArray(_pNative, _frameData, frameData.Length);
  138. Helper.ExceptionHelper.CheckLastError();
  139. }
  140. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  141. private static extern void Windows_Kinect_ColorFrame_CopyConvertedFrameDataToArray(RootSystem.IntPtr pNative, RootSystem.IntPtr frameData, int frameDataSize, Windows.Kinect.ColorImageFormat colorFormat);
  142. public void CopyConvertedFrameDataToArray(byte[] frameData, Windows.Kinect.ColorImageFormat colorFormat)
  143. {
  144. if (_pNative == RootSystem.IntPtr.Zero)
  145. {
  146. throw new RootSystem.ObjectDisposedException("ColorFrame");
  147. }
  148. var frameDataSmartGCHandle = new Helper.SmartGCHandle(RootSystem.Runtime.InteropServices.GCHandle.Alloc(frameData, RootSystem.Runtime.InteropServices.GCHandleType.Pinned));
  149. var _frameData = frameDataSmartGCHandle.AddrOfPinnedObject();
  150. Windows_Kinect_ColorFrame_CopyConvertedFrameDataToArray(_pNative, _frameData, frameData.Length, colorFormat);
  151. Helper.ExceptionHelper.CheckLastError();
  152. }
  153. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  154. private static extern RootSystem.IntPtr Windows_Kinect_ColorFrame_CreateFrameDescription(RootSystem.IntPtr pNative, Windows.Kinect.ColorImageFormat format);
  155. public Windows.Kinect.FrameDescription CreateFrameDescription(Windows.Kinect.ColorImageFormat format)
  156. {
  157. if (_pNative == RootSystem.IntPtr.Zero)
  158. {
  159. throw new RootSystem.ObjectDisposedException("ColorFrame");
  160. }
  161. RootSystem.IntPtr objectPointer = Windows_Kinect_ColorFrame_CreateFrameDescription(_pNative, format);
  162. Helper.ExceptionHelper.CheckLastError();
  163. if (objectPointer == RootSystem.IntPtr.Zero)
  164. {
  165. return null;
  166. }
  167. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.FrameDescription>(objectPointer, n => new Windows.Kinect.FrameDescription(n));
  168. }
  169. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  170. private static extern void Windows_Kinect_ColorFrame_Dispose(RootSystem.IntPtr pNative);
  171. public void Dispose()
  172. {
  173. if (_pNative == RootSystem.IntPtr.Zero)
  174. {
  175. return;
  176. }
  177. Dispose(true);
  178. RootSystem.GC.SuppressFinalize(this);
  179. }
  180. private void __EventCleanup()
  181. {
  182. }
  183. }
  184. }