Beispiel #1
0
            public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
            {
                if (_Tex == null)
                {
                    _Tex = new Texture2D(parent._g, width, height, 1, TextureUsage.None, SurfaceFormat.Bgr32);
                }


                byte[] bgrData = new byte[BufferLen];
                Marshal.Copy(pBuffer, bgrData, 0, BufferLen);
                Color[] colorData = new Color[BufferLen / 3];
                for (int i = 0; i < colorData.Length; i++)
                {
                    colorData[i] = new Microsoft.Xna.Framework.Graphics.Color(bgrData[3 * i + 2], bgrData[3 * i + 1], bgrData[3 * i]);
                }
                _Tex.SetData <Microsoft.Xna.Framework.Graphics.Color>(colorData);

                GrabberInfo gi = new GrabberInfo();

                gi._Ptr = pBuffer;
                gi._Len = BufferLen;

                parent.NewFrame(gi);
                return(0);
            }
Beispiel #2
0
 // new frame
 protected void OnNewFrame(GrabberInfo image)
 {
     framesReceived++;
     if ((!stopEvent.WaitOne(0, true)) && (NewFrame != null))
     {
         NewFrame(image);
     }
 }
Beispiel #3
0
            public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
            {
                //if (_Tex == null)
                //    _Tex = new Texture2D(parent._g, width, height, 1, TextureUsage.None, SurfaceFormat.Bgr32);

                //int[] bgrData = new int[BufferLen/4];

                //unsafe
                //{
                //    fixed (int* pDst = bgrData)
                //    {
                //        int* dst = pDst + width * (height - 1);
                //        int* src = (int*)pBuffer;


                //        for (int y = 0; y < height; y++)
                //        {
                //            //Memory.
                //            //Marshal.Copy(src, 0, dst, width);
                //            Win32.memcpy(dst, src, width*4);
                //            dst -= width;
                //            src += width;
                //        }


                //    }
                //}



                //_Tex.SetData<int>(bgrData);

                GrabberInfo gi = new GrabberInfo();

                gi._Ptr = pBuffer;
                gi._Len = BufferLen;
                gi._W   = width;
                gi._H   = height;

                parent.NewFrame(gi);
                return(0);
            }
Beispiel #4
0
        void _cam_NewFrame(GrabberInfo e)
        {
            Texture2D t = _surf.UpdateFrameToTexture(e._Ptr, e._Len, e._W, e._H);

            if (t == null)
            {
                return;
            }

            GraphicsDevice.Textures[0] = null;
            _imageTex = t;



            if (Environment.TickCount < (_Tick + 500))
            {
                return;
            }

            _Tick = Environment.TickCount;



            //if (_surf.GetCX() != -1)
            //{

            //    if (1.3 < _surf.GetCS())
            //    {
            //        if (_OldS != 1)
            //        {
            //            _OldS = 1;
            //            _EventOnDetected2(_OldS);
            //        }
            //    }
            //    else if (1.0 < _surf.GetCS())
            //    {
            //        if (_OldS != 0)
            //        {
            //            _OldS = 0;
            //            _EventOnDetected2(_OldS);
            //        }


            //    }
            //    else
            //    {
            //        if (_OldS != -1)
            //        {
            //            _OldS = -1;
            //            _EventOnDetected2(_OldS);
            //        }

            //    }



            //}


            if (_OldX == -2)
            {
                if (_surf.GetCX() == 2)
                {
                    _OldX = _surf.GetCX();

                    _EventOnDetected(_surf);
                }


                return;
            }

            //if (_EventOnDetected != null && _OldX != _surf.GetCX())
            {
                _OldX = _surf.GetCX();

                _EventOnDetected(_surf);
            }
        }
Beispiel #5
0
        void _cam_NewFrame(GrabberInfo e)
        {


            Texture2D t = _surf.UpdateFrameToTexture(e._Ptr, e._Len,e._W,e._H);

            if (t == null)
                return;

            GraphicsDevice.Textures[0] = null;
            _imageTex = t;



            if (Environment.TickCount < (_Tick + 500) )
            {
                return;
            }

            _Tick = Environment.TickCount;



            //if (_surf.GetCX() != -1)
            //{

            //    if (1.3 < _surf.GetCS())
            //    {
            //        if (_OldS != 1)
            //        {
            //            _OldS = 1;
            //            _EventOnDetected2(_OldS);
            //        }
            //    }
            //    else if (1.0 < _surf.GetCS())
            //    {
            //        if (_OldS != 0)
            //        {
            //            _OldS = 0;
            //            _EventOnDetected2(_OldS);
            //        }


            //    }
            //    else
            //    {
            //        if (_OldS != -1)
            //        {
            //            _OldS = -1;
            //            _EventOnDetected2(_OldS);
            //        }

            //    }

             


            //}


            if (_OldX == -2)
            {
                if (_surf.GetCX() == 2)
                {
                    _OldX = _surf.GetCX();

                    _EventOnDetected(_surf);
                }


                return;
            }
            
            //if (_EventOnDetected != null && _OldX != _surf.GetCX())
            {
                _OldX = _surf.GetCX();

                _EventOnDetected(_surf);
            }

        } 
Beispiel #6
0
            public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
            {
                //if (_Tex == null)
                //    _Tex = new Texture2D(parent._g, width, height, 1, TextureUsage.None, SurfaceFormat.Bgr32);

                //int[] bgrData = new int[BufferLen/4];

                //unsafe
                //{
                //    fixed (int* pDst = bgrData)
                //    {
                //        int* dst = pDst + width * (height - 1);
                //        int* src = (int*)pBuffer;


                //        for (int y = 0; y < height; y++)
                //        {
                //            //Memory.
                //            //Marshal.Copy(src, 0, dst, width);
                //            Win32.memcpy(dst, src, width*4);
                //            dst -= width;
                //            src += width;
                //        }


                //    }
                //}
                


                //_Tex.SetData<int>(bgrData);

                GrabberInfo gi = new GrabberInfo();
                gi._Ptr = pBuffer;
                gi._Len = BufferLen;
                gi._W = width;
                gi._H = height;

                parent.NewFrame(gi);
                return 0;
            }
Beispiel #7
0
 // new frame
 protected void OnNewFrame(GrabberInfo image)
 {
     framesReceived++;
     if ((!stopEvent.WaitOne(0, true)) && (NewFrame != null))
         NewFrame( image);
 }
Beispiel #8
0
            public int BufferCB(double SampleTime, IntPtr pBuffer, int BufferLen)
            {
                if( _Tex == null)
                    _Tex = new Texture2D(parent._g, width, height, 1, TextureUsage.None, SurfaceFormat.Bgr32);
                
                
                byte[] bgrData = new byte[BufferLen];
                Marshal.Copy(pBuffer, bgrData, 0, BufferLen);
                Color[] colorData = new Color[BufferLen / 3];
                for (int i = 0; i < colorData.Length; i++)
                {
                    colorData[i] = new Microsoft.Xna.Framework.Graphics.Color(bgrData[3 * i + 2], bgrData[3 * i + 1], bgrData[3 * i]);
                }
                _Tex.SetData<Microsoft.Xna.Framework.Graphics.Color>(colorData);

                GrabberInfo gi  = new GrabberInfo();
                gi._Ptr = pBuffer;
                gi._Len = BufferLen;

                parent.NewFrame(gi);
                return 0;
            }