public ImageFrame(ImageFormat.Format format, int width, int height, int widthStep, NativeArray <byte> pixelData) { unsafe { UnsafeNativeMethods.mp_ImageFrame__ui_i_i_i_Pui8_PF( format, width, height, widthStep, (IntPtr)NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(pixelData), ReleasePixelData, out var ptr ).Assert(); this.ptr = ptr; } }
public static Color32[] FromBytePtr(IntPtr ptr, ImageFormat.Format format, int width, int height, int widthStep, bool isFlipped = false) { switch (format) { case ImageFormat.Format.SRGB: case ImageFormat.Format.SRGBA: { return(FromSRGBOrSRGBA(ptr, format, width, height, widthStep, isFlipped)); } default: { throw new NotSupportedException(); } } }
public ImageFrame(ImageFormat.Format format, int width, int height, int widthStep, NativeArray <byte> pixelData) { Deleter deleter = (IntPtr ptr) => { /** Do nothing (pixelData will be moved) */ }; deleterHandle = GCHandle.Alloc(deleter, GCHandleType.Pinned); unsafe { UnsafeNativeMethods.mp_ImageFrame__ui_i_i_i_Pui8_PF( format, width, height, widthStep, (IntPtr)NativeArrayUnsafeUtility.GetUnsafeReadOnlyPtr(pixelData), deleter, out var ptr ).Assert(); this.ptr = ptr; } }
/// <summary> /// Copy byte array that <paramref name="ptr" /> points to a Color32 array. /// </summary> /// <remarks> /// In the source array, pixels are laid out left to right, top to bottom, /// but in the returned array, left to right, top to bottom. /// </remarks> private static Color32[] FromSRGBOrSRGBA(IntPtr ptr, ImageFormat.Format format, int width, int height, int widthStep, bool isFlipped) { var colors = new Color32[width * height]; var padding = format == ImageFormat.Format.SRGB ? (widthStep - 3 * width) : (widthStep - 4 * width); unsafe { fixed(Color32 *dest = colors) { byte *pSrc = (byte *)ptr.ToPointer(); if (isFlipped) { Color32 *pDest = dest + colors.Length - 1; for (var i = 0; i < colors.Length; i++) { byte r = *pSrc++; byte g = *pSrc++; byte b = *pSrc++; byte a = format == ImageFormat.Format.SRGB ? (byte)255 : (*pSrc++); * pDest-- = new Color32(r, g, b, a); } } else { for (var i = 0; i < height; i++) { Color32 *pRowDest = dest + width * (height - 1 - i); for (var j = 0; j < width; j++) { byte r = *pSrc++; byte g = *pSrc++; byte b = *pSrc++; byte a = format == ImageFormat.Format.SRGB ? (byte)255 : (*pSrc++); * pRowDest++ = new Color32(r, g, b, a); } pSrc += padding; } } } } return(colors); }
public static extern MpReturnCode mp_ImageFrame__ui_i_i_ui( ImageFormat.Format format, int width, int height, UInt32 alignmentBoundary, out IntPtr imageFrame);
public static extern MpReturnCode mp_ImageFrame__ui_i_i_i_Pui8_PF( ImageFormat.Format format, int width, int height, int widthStep, IntPtr pixelData, [MarshalAs(UnmanagedType.FunctionPtr)] ImageFrame.Deleter deleter, out IntPtr imageFrame);
public ImageFrame(ImageFormat.Format format, int width, int height, uint alignmentBoundary) : base() { UnsafeNativeMethods.mp_ImageFrame__ui_i_i_ui(format, width, height, alignmentBoundary, out var ptr).Assert(); this.ptr = ptr; }
public ImageFrame(ImageFormat.Format format, int width, int height) : this(format, width, height, kDefaultAlignmentBoundary) { }
public static extern ImageFormat.Format mp__GpuBufferFormatForImageFormat__ui(ImageFormat.Format format);