/// <summary> /// Attaches this instance to external native memory pointed to by /// imageData, which is assumed to be sufficiently large to contain /// an image of the given size and format. The memory referenced by /// imageData will not be deallocated when this instance is released. /// The caller owns the image buffer in this case and is responsible /// for its lifetime management. /// </summary> /// <param name="width"> /// image width in pixels /// </param> /// <param name="height"> /// image height in pixels /// </param> /// <param name="imageDataPtr"> /// external image buffer /// </param> /// <param name="format"> /// image format /// </param> /// <param name="stride"> /// stride of the image /// </param> public void Attach(uint width, uint height, IntPtr imageDataPtr, FaceTrackingImageFormat format, uint stride) { this.CheckPtrAndThrow(); if (this.bufferManagement != BufferManagement.None) { throw new InvalidOperationException("Cannot Attach again. Image already attached to external buffer."); } this.bufferManagement = BufferManagement.External; this.faceTrackingImagePtr.Attach(width, height, imageDataPtr, format, stride); }
/// <summary> /// Allocates memory for the provided image width, height and format. /// The memory is owned by this instance and is released when the /// instance is disposed or when another Allocate() call happens. /// This method deallocates currently allocated memory if its internal /// buffers are not enough to fit new image data. If its internal /// buffers are big enough, no new allocation happens /// </summary> /// <param name="width"> /// image width in pixels /// </param> /// <param name="height"> /// image height in pixels /// </param> /// <param name="format"> /// image format /// </param> public void Allocate(uint width, uint height, FaceTrackingImageFormat format) { this.CheckPtrAndThrow(); if (this.bufferManagement != BufferManagement.None) { throw new InvalidOperationException("Cannot Allocate again. Image already allocated buffer in native image."); } this.bufferManagement = BufferManagement.LocalNativeImage; this.faceTrackingImagePtr.Allocate(width, height, format); }