コード例 #1
0
        private static void ToManaged(MatrixElementTypes type, IntPtr src, Bitmap bitmap, bool rgbReverse, int channels)
        {
            var format = bitmap.PixelFormat;
            var width  = bitmap.Width;
            var height = bitmap.Height;

            BitmapData bitmapData = null;

            try
            {
                bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, width, height),
                                             ImageLockMode.WriteOnly,
                                             format);

                var scan0   = bitmapData.Scan0;
                var stride  = bitmapData.Stride;
                var srcType = type.ToNativeMatrixElementType();
                NativeMethods.extensions_convert_matrix_to_managed_image(srcType, src, scan0, rgbReverse, (uint)height, (uint)width, (uint)stride, (uint)channels);
            }
            finally
            {
                if (bitmapData != null)
                {
                    bitmap.UnlockBits(bitmapData);
                }
            }
        }
コード例 #2
0
        internal MatrixOp(Dlib.Native.ElementType elementType, MatrixElementTypes type, IntPtr ptr, int templateRows = 0, int temlateColumns = 0)
        {
            this._ElementType       = elementType;
            this._MatrixElementType = type.ToNativeMatrixElementType();
            this.NativePtr          = ptr;

            this.TemplateRows    = templateRows;
            this.TemplateColumns = temlateColumns;
        }
コード例 #3
0
        private static void ToManaged(MatrixElementTypes type, IntPtr src, WriteableBitmap bitmap, bool rgbReverse, int channels)
        {
            var width   = bitmap.PixelWidth;
            var height  = bitmap.PixelHeight;
            var buffer  = bitmap.BackBuffer;
            var stride  = bitmap.BackBufferStride;
            var srcType = type.ToNativeMatrixElementType();

            NativeMethods.extensions_convert_matrix_to_managed_image(srcType, src, buffer, rgbReverse, (uint)height, (uint)width, (uint)stride, (uint)channels);
        }
コード例 #4
0
ファイル: Matrix.cs プロジェクト: mannu598/DlibDotNet
        internal Matrix(IntPtr ptr, MatrixElementTypes type)
        {
            if (ptr == IntPtr.Zero)
            {
                throw new ArgumentException("Can not pass IntPtr.Zero", nameof(ptr));
            }

            this.NativePtr           = ptr;
            this._MatrixElementTypes = type;
            this._ElementType        = type.ToNativeMatrixElementType();

            this._Indexer = this.CreateIndexer(type);
        }
コード例 #5
0
        private static void ToNative(WriteableBitmap bitmap, MatrixElementTypes dstType, IntPtr dst, bool rgbReverse, int channels)
        {
            var width      = bitmap.PixelWidth;
            var height     = bitmap.PixelHeight;
            var buffer     = bitmap.BackBuffer;
            var stride     = bitmap.BackBufferStride;
            var usePalette = bitmap.Palette != null && bitmap.Palette.Colors.Count == 256;

            if (!usePalette)
            {
                NativeMethods.extensions_convert_managed_image_to_matrix(buffer, dstType.ToNativeMatrixElementType(), dst, rgbReverse, (uint)height, (uint)width, (uint)stride, (uint)channels);
            }
            else
            {
                var p = bitmap.Palette.Colors.Select(c => new RgbPixel {
                    Blue = c.B, Green = c.G, Red = c.R
                }).ToArray();
                NativeMethods.extensions_convert_managed_image_to_matrix_by_palette(buffer, dstType.ToNativeMatrixElementType(), dst, p, (uint)height, (uint)width, (uint)stride, (uint)channels);
            }
        }
コード例 #6
0
        private static void ToNative(Bitmap bitmap, MatrixElementTypes dstType, IntPtr dst, bool rgbReverse, int channels)
        {
            var format     = bitmap.PixelFormat;
            var width      = bitmap.Width;
            var height     = bitmap.Height;
            var palette    = bitmap.Palette;
            var usePalette = bitmap.Palette.Entries.Length == 256;

            BitmapData bitmapData = null;

            try
            {
                bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, width, height),
                                             ImageLockMode.ReadOnly,
                                             format);

                var scan0  = bitmapData.Scan0;
                var stride = bitmapData.Stride;
                if (!usePalette)
                {
                    NativeMethods.extensions_convert_managed_image_to_matrix(scan0, dstType.ToNativeMatrixElementType(), dst, rgbReverse, (uint)height, (uint)width, (uint)stride, (uint)channels);
                }
                else
                {
                    var p = palette.Entries.Select(c => new RgbPixel {
                        Blue = c.B, Green = c.G, Red = c.R
                    }).ToArray();
                    NativeMethods.extensions_convert_managed_image_to_matrix_by_palette(scan0, dstType.ToNativeMatrixElementType(), dst, p, (uint)height, (uint)width, (uint)stride, (uint)channels);
                }
            }
            finally
            {
                if (bitmapData != null)
                {
                    bitmap.UnlockBits(bitmapData);
                }
            }
        }
コード例 #7
0
        private Imp <TElement> CreateImp(MatrixElementTypes type)
        {
            switch (type)
            {
            case MatrixElementTypes.UInt8:
                return(new MatrixUInt8Imp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.Int8:
                return(new MatrixInt8Imp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.UInt16:
                return(new MatrixUInt16Imp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.Int16:
                return(new MatrixInt16Imp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.UInt32:
                return(new MatrixUInt32Imp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.Int32:
                return(new MatrixInt32Imp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.UInt64:
                return(new MatrixUInt64Imp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.Int64:
                return(new MatrixInt64Imp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.Double:
                return(new MatrixDoubleImp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.Float:
                return(new MatrixFloatImp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.RgbPixel:
                return(new MatrixRgbPixelImp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.BgrPixel:
                return(new MatrixBgrPixelImp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.HsiPixel:
                return(new MatrixHsiPixelImp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            case MatrixElementTypes.RgbAlphaPixel:
                return(new MatrixRgbAlphaPixelImp(this, type.ToNativeMatrixElementType()) as Imp <TElement>);

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }