示例#1
0
 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;
     }
 }
示例#2
0
        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;
            }
        }
示例#4
0
        /// <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);
        }
示例#5
0
 public static extern MpReturnCode mp_ImageFrame__ui_i_i_ui(
     ImageFormat.Format format, int width, int height, UInt32 alignmentBoundary, out IntPtr imageFrame);
示例#6
0
 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);
示例#7
0
 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;
 }
示例#8
0
 public ImageFrame(ImageFormat.Format format, int width, int height) : this(format, width, height, kDefaultAlignmentBoundary)
 {
 }
示例#9
0
 public static extern ImageFormat.Format mp__GpuBufferFormatForImageFormat__ui(ImageFormat.Format format);