コード例 #1
0
        protected override void CloneCurrentValueCore(Freezable sourceFreezable)
        {
            InteropBitmap sourceBitmapSource = (InteropBitmap)sourceFreezable;

            base.CloneCurrentValueCore(sourceFreezable);
            CopyCommon(sourceBitmapSource);
        }
コード例 #2
0
        protected override void GetCurrentValueAsFrozenCore(Freezable sourceFreezable)
        {
            InteropBitmap sourceBitmapSource = (InteropBitmap)sourceFreezable;

            base.GetCurrentValueAsFrozenCore(sourceFreezable);
            CopyCommon(sourceBitmapSource);
        }
コード例 #3
0
        /// <summary>
        /// Initialize a new GridBitmap with the given dimensions and color range.
        /// </summary>
        /// <param name="x">The width of the bitmap (in pixels)</param>
        /// <param name="y">The height of the bitmap (in pixels)</param>
        /// <param name="colors">An array containing RGB values indicating how states should be colored. Array size
        /// should correspond to the number of states; a cell in state i will be colored with the RGB value in colors[i].
        /// If a color for a given state is undefined, undefinedColor will be used.</param>
        public GridBitmap(int x, int y, uint defaultState, int[] colors)
        {
            gridSizeX = x;
            gridSizeY = y;
            colorList = colors;

            numPixels = (uint)(gridSizeX * gridSizeY);
            numBytes = numPixels * 4;
            int stride = (gridSizeX * format.BitsPerPixel + 7) / 8;

            // Make a memory mapping for the bitmap
            map = CreateFileMapping(INVALID_HANDLE_VALUE, IntPtr.Zero, PAGE_READWRITE, 0, numBytes, null);

            // Initialize a blank bitmap (using the color specified for the default state)
            unsafe {
                vptr = (int*)MapViewOfFile(map, FILE_MAP_ALL_ACCESS, 0, 0, numBytes).ToPointer();
                Parallel.For(0, gridSizeY, j => {
                    int rowStart = j * gridSizeX;
                    for (int i = 0; i < gridSizeX; i++) vptr[rowStart+i] = colors[defaultState];
                });
            }

            // Create a bitmap source using the memory map
            bmpSource = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(map, gridSizeX, gridSizeY, format, stride, 0);
        }
コード例 #4
0
 private void CopyCommon(InteropBitmap sourceBitmapSource)
 {
     base.Animatable_IsResourceInvalidationNecessary = false;
     _unmanagedSource = sourceBitmapSource._unmanagedSource;
     _sourceRect      = sourceBitmapSource._sourceRect;
     _sizeOptions     = sourceBitmapSource._sizeOptions;
     InitFromWICSource(sourceBitmapSource.WicSourceHandle);
     base.Animatable_IsResourceInvalidationNecessary = true;
 }
コード例 #5
0
        /// <summary>
        /// Common Copy method used to implement CloneCore() and CloneCurrentValueCore(),
        /// GetAsFrozenCore(), and GetCurrentValueAsFrozenCore().
        /// </summary>
        private void CopyCommon(InteropBitmap sourceBitmapSource)
        {
            // Avoid Animatable requesting resource updates for invalidations that occur during construction
            Animatable_IsResourceInvalidationNecessary = false;
            _unmanagedSource = sourceBitmapSource._unmanagedSource;
            _sourceRect      = sourceBitmapSource._sourceRect;
            _sizeOptions     = sourceBitmapSource._sizeOptions;
            InitFromWICSource(sourceBitmapSource.WicSourceHandle);

            // The next invalidation will cause Animatable to register an UpdateResource callback
            Animatable_IsResourceInvalidationNecessary = true;
        }
コード例 #6
0
 public void SetSurface(Guid emulationRunnerId, InteropBitmap bitmap)
 {
     _surfaces.Add(emulationRunnerId, bitmap);
 }
コード例 #7
0
ファイル: VlcControl.cs プロジェクト: ch4/vlcdotnet
        private uint VideoSetFormat(ref IntPtr opaque, ref uint chroma, ref uint width, ref uint height, ref uint pitches, ref uint lines)
        {
            myContext = new VlcControlWpfRendererContext(width, height, PixelFormats.Bgr32);

            chroma = BitConverter.ToUInt32(new[] { (byte)'R', (byte)'V', (byte)'3', (byte)'2' }, 0);
            width = (uint)myContext.Width;
            height = (uint)myContext.Height;
            pitches = (uint)myContext.Stride;
            lines = (uint)myContext.Height;

            myBitmapSectionPointer = Win32Interop.CreateFileMapping(new IntPtr(-1), IntPtr.Zero, Win32Interop.PageAccess.ReadWrite, 0, myContext.Size, null);
            opaque = Win32Interop.MapViewOfFile(myBitmapSectionPointer, Win32Interop.FileMapAccess.AllAccess, 0, 0, (uint)myContext.Size);

            Dispatcher.Invoke((Action)(() =>
            {
                myBitmap = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(myBitmapSectionPointer, myContext.Width, myContext.Height, myContext.PixelFormat, myContext.Stride, 0);
                VideoSource = myBitmap;
                VideoBrush.ImageSource = myBitmap;
            }));

            return 1;
        }
コード例 #8
0
ファイル: VlcControl.cs プロジェクト: ch4/vlcdotnet
 private void VideoCleanup(IntPtr opaque)
 {
     myBitmap = null;
     Win32Interop.UnmapViewOfFile(opaque);
     Win32Interop.CloseHandle(myBitmapSectionPointer);
 }
コード例 #9
0
ファイル: VlcPlayer.cs プロジェクト: Greaky/xZune.Vlc
 public VideoDisplayContext(int width, int height, PixelFormat format)
 {
     Size = width * height * format.BitsPerPixel / 8;
     Width = width;
     Height = height;
     PixelFormat = format;
     Stride = width * format.BitsPerPixel / 8;
     FileMapping = Win32Api.CreateFileMapping(new IntPtr(-1), IntPtr.Zero, PageAccess.ReadWrite, 0, Size, null);
     MapView = Win32Api.MapViewOfFile(FileMapping, FileMapAccess.AllAccess, 0, 0, (uint)Size);
     Application.Current.Dispatcher.Invoke(new Action(() =>
     {
         Image = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(FileMapping, Width, Height, PixelFormat, Stride, 0);
     }));
 }
コード例 #10
0
ファイル: VlcPlayer.cs プロジェクト: Greaky/xZune.Vlc
 public void Dispose(bool disposing)
 {
     if (_disposed) return;
     Size = 0;
     Width = 0;
     Height = 0;
     PixelFormat = PixelFormats.Default;
     Stride = 0;
     Image = null;
     Win32Api.UnmapViewOfFile(MapView);
     Win32Api.CloseHandle(FileMapping);
     FileMapping = MapView = IntPtr.Zero;
     _disposed = true;
 }
コード例 #11
0
        internal void Refresh(bool invalidate)
        {
            #if DIRECTX2D
            if (RenderingMode == RenderingMode.DirectX2D)
                InitializeDirectX();
            #endif
            switch (RenderingMode)
            {
            #if WPF
                case RenderingMode.GDIRendering:
                    if (this.InteropBitmap != null && this.GDIGraphics != null)
                    {
                        this.GDIGraphics.Dispose();
                        this.GDIGraphics = null;
                        this.InteropBitmap = null;
                        GC.Collect();
                    }
                    break;
                case RenderingMode.WritableBitmap:
                    if (this.WritableBitmap != null && this.WritableBitmapGraphics != null)
                    {
                        this.WritableBitmapGraphics.Dispose();
                        this.WritableBitmapGraphics = null;
                        this.WritableBitmap = null;
                        GC.Collect();
                    }
                    break;
            #endif
                case RenderingMode.Default:
                    break;

                default:
                    break;
            }

            Initialize();
            if (!_isIntialized || invalidate)
                GenerateConatiners();
            else
                UpdateContainers();

            if (this.XAxis != null)
            {
                this.XAxis.MMinValue = 0;
                this.XAxis.MMaxValue = 1;
                this.XAxis.CalculateIntervalFromSeriesPoints();
                this.XAxis.Refresh();
            }
            if (this.YAxis != null)
            {
                this.YAxis.MMinValue = 0;
                this.YAxis.MMaxValue = 1;
                this.YAxis.CalculateIntervalFromSeriesPoints();
                this.YAxis.Refresh();
            }
            if (this.Series != null)
            {
                foreach (SeriesBase series in this.Series)
                {
                    if (Containers.Count > 0 && (this.Series.Count == Containers.Count))
                        series.SeriesContainer = Containers[series.Index];
                    series.Refresh();
                }
            }
        }
コード例 #12
0
        private object SetBitmapHelper(BitmapInfo bitmapInfo, InteropBitmap bitmap, Action<InteropBitmap> imageSourceSetter)
        {
            if (bitmap == null)
            {
                imageSourceSetter(null);
                GC.Collect(1);

                var stride = bitmapInfo.Width * BytesPerPixel;

                bitmap = (InteropBitmap)Imaging.CreateBitmapSourceFromMemorySection(bitmapInfo.FileMappingHandle,
                    bitmapInfo.Width, bitmapInfo.Height, PixelFormat, stride, 0);
                imageSourceSetter(bitmap);
            }

            bitmap.Invalidate();

            return bitmap;
        }
コード例 #13
0
        public bool Create(Guid cameraGuid)
        {
            int w = 0, h = 0;
            _camera = CLEyeCreateCamera(cameraGuid, ColorMode, Resolution, Framerate);

            if (_camera == IntPtr.Zero) return false;
            CLEyeCameraGetFrameDimensions(_camera, ref w, ref h);
            if (ColorMode == CLEyeCameraColorMode.CLEYE_COLOR_PROCESSED || ColorMode == CLEyeCameraColorMode.CLEYE_COLOR_RAW)
            {
                uint imageSize = (uint)w * (uint)h * 4;
                // create memory section and map
                _section = CreateFileMapping(new IntPtr(-1), IntPtr.Zero, 0x04, 0, imageSize, null);
                _map = MapViewOfFile(_section, 0xF001F, 0, 0, imageSize);
                BitmapSource = Imaging.CreateBitmapSourceFromMemorySection(_section, w, h, PixelFormats.Bgr32, w * 4, 0) as InteropBitmap;
            }
            else
            {
                uint imageSize = (uint)w * (uint)h;
                // create memory section and map
                _section = CreateFileMapping(new IntPtr(-1), IntPtr.Zero, 0x04, 0, imageSize, null);
                _map = MapViewOfFile(_section, 0xF001F, 0, 0, imageSize);
                BitmapSource = Imaging.CreateBitmapSourceFromMemorySection(_section, w, h, PixelFormats.Gray8, w, 0) as InteropBitmap;
            }
            // Invoke event
            if (BitmapReady != null) BitmapReady(this, null);
            BitmapSource.Invalidate();
            return true;
        }
コード例 #14
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        internal void Initialize()
        {
            #if WPF && !PUPLISH
            if (ActualHeight > 1 && ActualWidth > 1)
            {
                switch (RenderingMode)
                {

                    case RenderingMode.GDIRendering:
                        uint byteCount = (uint)(ActualWidth * ActualHeight * bpp);

                        //Allocate and create the InteropBitmap
                        var fileMappingPointer = CreateFileMapping(new IntPtr(-1), IntPtr.Zero, PageReadwrite, 0, byteCount, null);
                        this.MapViewPointer = MapViewOfFile(fileMappingPointer, FileMapAllAccess, 0, 0, byteCount);
                        var format = PixelFormats.Bgra32;
                        var stride = (int)((int)ActualWidth * (int)format.BitsPerPixel / 8);
                        this.InteropBitmap = Imaging.CreateBitmapSourceFromMemorySection(fileMappingPointer,
                                                                                    (int)ActualWidth,
                                                                                    (int)ActualHeight,
                                                                                    format,
                                                                                    stride,
                                                                                    0) as InteropBitmap;
                        this.GDIGraphics = GetGdiGraphics(MapViewPointer);
                        break;

                    case RenderingMode.WritableBitmap:
                        //Allocate and create the WritableBitmap
                        WritableBitmap = new WriteableBitmap((int)ActualWidth, (int)ActualHeight, 96, 96, PixelFormats.Bgra32, null);
                        ImageBitmap = new Bitmap((int)ActualWidth, (int)ActualHeight, ((int)ActualWidth * 4), System.Drawing.Imaging.PixelFormat.Format32bppPArgb, WritableBitmap.BackBuffer);
                        WritableBitmapGraphics = System.Drawing.Graphics.FromImage(ImageBitmap);
                        WritableBitmapGraphics.CompositingMode = this.CompositingMode.AsDrawingCompositingMode();
                        WritableBitmapGraphics.CompositingQuality = this.CompositingQuality.AsDrawingCompositingQuality();
                        WritableBitmapGraphics.SmoothingMode = this.SmoothingMode.AsDrawingSmoothingMode();
                        break;
                    default:
                        break;
                }

                Clear();
                this.IsBitmapInitialized = true;
            }
            #endif
        }
コード例 #15
0
        // creates interop bitmap
        private void CreateBitmap()
        {
            if (map != null)
            {
                // byte count
                uint byteCount = (uint)(map.X * map.Y * PixelFormats.Bgr32.BitsPerPixel / 8);

                // allocate memory
                var sectionPointer = CreateFileMapping(new IntPtr(-1), IntPtr.Zero, PAGE_READWRITE, 0, byteCount, null);
                mapPointer = MapViewOfFile(sectionPointer, FILE_MAP_ALL_ACCESS, 0, 0, byteCount);

                //byte[] pixels = new byte[byteCount];
                //Marshal.Copy(pixels, 0, mapPointer, (int)byteCount);

                // create the interopBitmap
                interopBitmap = Imaging.CreateBitmapSourceFromMemorySection(sectionPointer, map.X, map.Y, PixelFormats.Bgr32, (int)(map.X * PixelFormats.Bgr32.BitsPerPixel / 8), 0) as InteropBitmap;
                SetImage();
            }
        }
コード例 #16
0
 public override void ClearBitmap()
 {
     InteropBitmap = null;
 }
コード例 #17
0
        private void DestroyBitmap()
        {
            _interopBitmap = null;

            if (_hDC != IntPtr.Zero) {
                NativeMethods.DeleteObject(_hDC);
                _hDC = IntPtr.Zero;
            }

            if (_hBitmap != IntPtr.Zero) {
                NativeMethods.DeleteObject(_hBitmap);
                _hBitmap = IntPtr.Zero;
            }

            _pBits = IntPtr.Zero;

            if (_hSection != IntPtr.Zero) {
                NativeMethods.CloseHandle(_hSection);
                _hSection = IntPtr.Zero;
            }

            _stride = 0;
            _bitmapWidth = 0;
            _bitmapHeight = 0;
        }
コード例 #18
0
        private void CreateBitmap(int width, int height)
        {
            Debug.Assert(_hSection == IntPtr.Zero);
            Debug.Assert(_hBitmap == IntPtr.Zero);
            Debug.Assert(_interopBitmap == null);

            if (width == 0 || height == 0) return;

            _stride = (width * _format.BitsPerPixel + 7) / 8;
            int size = height * _stride;

            _hSection = NativeMethods.CreateFileMapping(
                PAGE.READWRITE,
                SEC.NONE,
                0,
                (uint)size,
                null);

            BITMAPINFO bmi = new BITMAPINFO();
            bmi.biSize = Marshal.SizeOf(bmi);
            bmi.biWidth = width;
            bmi.biHeight = -height; // top-down
            bmi.biPlanes = 1;
            bmi.biBitCount = 32;
            bmi.biCompression = BI.RGB;

            IntPtr hdcScreen = NativeMethods.GetDC(HWND.NULL);

            _hBitmap = NativeMethods.CreateDIBSection(
                hdcScreen,
                ref bmi,
                DIB.RGB_COLORS,
                out _pBits,
                _hSection,
                0);

            // TODO: probably don't need a new DC every time...
            _hDC = NativeMethods.CreateCompatibleDC(hdcScreen);
            NativeMethods.SelectObject(_hDC, _hBitmap);

            _interopBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromMemorySection(
                _hSection,
                width,
                height,
                _format,
                _stride,
                0) as InteropBitmap;

            _bitmapWidth = width;
            _bitmapHeight = height;
        }
コード例 #19
0
ファイル: InteropBitmapSource.cs プロジェクト: JianwenSun/cc
        private void CopyCommon(InteropBitmap sourceBitmapSource)
        {
            // Avoid Animatable requesting resource updates for invalidations that occur during construction
            Animatable_IsResourceInvalidationNecessary = false;
            _unmanagedSource = sourceBitmapSource._unmanagedSource;
            _sourceRect = sourceBitmapSource._sourceRect;
            _sizeOptions = sourceBitmapSource._sizeOptions;
            InitFromWICSource(sourceBitmapSource.WicSourceHandle);

            // The next invalidation will cause Animatable to register an UpdateResource callback
            Animatable_IsResourceInvalidationNecessary = true;
        }