Ejemplo n.º 1
0
 private long clean_up_device()                    //implement IDisposable here instead
 {
     Marshal.FreeHGlobal(this.unmanaged_RGGB_ptr); //if IntPtr is IntPrt.Zero, FreeHGlobal does nothing
     this.unmanaged_RGGB_ptr = IntPtr.Zero;
     Marshal.FreeHGlobal(this.unmanaged_data_set1_ptr);
     this.unmanaged_data_set1_ptr = IntPtr.Zero;
     Marshal.FreeHGlobal(this.unmanaged_gyr_data_ptr);
     this.unmanaged_gyr_data_ptr = IntPtr.Zero;
     return(PInvokeDll.clean_up_device());
 }
Ejemplo n.º 2
0
        public unsafe long get_data()
        {
            Int64 rest = PInvokeDll.get_data(
                this.unmanaged_RGGB_ptr,
                this.unmanaged_data_set1_ptr,
                this.unmanaged_gyr_data_ptr);

            if (rest != 1)
            {
                return(-1);
            }

            for (int i = 0; i < 160; i++)
            {
                this.data_set1[i] = (data)
                                    Marshal.PtrToStructure(this.unmanaged_data_set1_ptr + i * Marshal.SizeOf(typeof(data)), typeof(data));
                this.data_set2[i] = (data)
                                    Marshal.PtrToStructure(this.unmanaged_gyr_data_ptr + i * Marshal.SizeOf(typeof(data)), typeof(data));
            }
            Bitmap     bitmap_grayscale = new Bitmap(320, 320, PixelFormat.Format8bppIndexed);
            BitmapData bitmap_data      = null;

            try
            {
                bitmap_data = bitmap_grayscale.LockBits(
                    new Rectangle(0, 0, bitmap_grayscale.Width, bitmap_grayscale.Height),
                    ImageLockMode.WriteOnly, PixelFormat.Format8bppIndexed);
                for (int y = 0; y < bitmap_grayscale.Height; ++y)
                {
                    byte *targetRow = (byte *)bitmap_data.Scan0 + (y * bitmap_data.Stride);
                    for (int x = 0; x < bitmap_grayscale.Width; ++x)
                    {
                        targetRow[x] = Marshal.ReadByte(this.unmanaged_RGGB_ptr, y * bitmap_grayscale.Width + x);
                    }
                }
            }
            finally
            {
                if (bitmap_data != null)
                {
                    bitmap_grayscale.UnlockBits(bitmap_data);
                }
            }
            BayerFilter bayer_filter = new BayerFilter();

            bayer_filter.BayerPattern = new int[2, 2] {
                { RGB.R, RGB.G }, { RGB.G, RGB.B }
            };
            this.image_rgb = bayer_filter.Apply(bitmap_grayscale);
            return(1);
        }
Ejemplo n.º 3
0
 private long init_device()
 {
     return(PInvokeDll.init_device());
 }