public CameraConfig(uint width, uint height, float focalLength, FaceTrackingImageFormat imageFormat) { this.width = width; this.height = height; this.focalLength = focalLength; this.imageFormat = imageFormat; this.bytesPerPixel = Image.FormatToSize(this.imageFormat); this.stride = this.width * this.bytesPerPixel; switch (this.imageFormat) { case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_GR8: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_R8G8B8: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_X8R8G8B8: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_A8R8G8B8: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_B8G8R8X8: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_B8G8R8A8: this.frameBufferLength = this.height * this.stride; break; case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT16_D16: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT16_D13P3: this.frameBufferLength = this.height * this.width; break; default: throw new ArgumentException("Invalid image format specified"); } }
/// <summary>Get the bytes per pixel count for a FaceTrackingImageFormat</summary> /// <param name="format">The format.</param> /// <returns>the size</returns> /// <exception cref="ArgumentException">invalid format</exception> public static uint FormatToSize(FaceTrackingImageFormat format) { switch (format) { case FaceTrackingImageFormat.FTIMAGEFORMAT_INVALID: return(0); case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_GR8: return(1); case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_R8G8B8: return(3); case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_X8R8G8B8: return(4); case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_A8R8G8B8: return(4); case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_B8G8R8X8: return(4); case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_B8G8R8A8: return(4); case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT16_D16: return(2); case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT16_D13P3: return(2); default: throw new ArgumentException("Invalid image format specified"); } }
/// <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); }
public CameraConfig(uint width, uint height, float focalLength, FaceTrackingImageFormat imageFormat) { this.width = width; this.height = height; this.focalLength = focalLength; this.imageFormat = imageFormat; this.bytesPerPixel = Image.FormatToSize(this.imageFormat); this.stride = this.width * this.bytesPerPixel; switch (this.imageFormat) { case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_GR8: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_R8G8B8: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_X8R8G8B8: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_A8R8G8B8: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_B8G8R8X8: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT8_B8G8R8A8: this.frameBufferLength = this.height * this.stride; break; case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT16_D16: case FaceTrackingImageFormat.FTIMAGEFORMAT_UINT16_D13P3: this.frameBufferLength = this.height * this.width; break; default: throw new ArgumentException("Invalid image format specified"); } }