public static void PpmReceived(Packet _packet)
    {
        int length = _packet.ReadInt();

        byte[] data = _packet.ReadBytes(length);
        //PpmImage image = PpmImage.Deserialize(data);
        //Backend.RTInitilize();
        PpmImage image = new PpmImage();

        image.width  = 960;
        image.height = 540;
        image.rgb    = new byte[image.width * image.height * 3];
        Backend.RTInitilize();
        IntPtr ptr  = Backend.RTrender();
        IntPtr iter = ptr;

        for (int i = 0; i < image.width * image.height; i++)
        {
            for (int j = 0; j < 3; j++)
            {
                float color = (float)Marshal.PtrToStructure(iter, typeof(float));
                image.rgb[i * 3 + j] = (byte)color;
                iter = (IntPtr)(iter.ToInt64() + Marshal.SizeOf(typeof(float)));
            }
        }
        //Backend.TestImageSending(image);
    }
    public static void JPEGBufferReceived(Packet packet)
    {
        int length = packet.ReadInt();

        byte[]   data  = packet.ReadBytes(length);
        PpmImage image = new PpmImage();

        IntPtr outBuffer     = IntPtr.Zero;
        int    outSize       = 0;
        int    outWidth      = 0;
        int    outHeight     = 0;
        int    outComponents = 0;

        IntPtr unmanagedPointer = Marshal.AllocHGlobal(data.Length);

        Marshal.Copy(data, 0, unmanagedPointer, data.Length);
        Backend.DecompressJPEG(unmanagedPointer, data.Length,
                               ref outBuffer, ref outSize, ref outWidth, ref outHeight, ref outComponents);
        Marshal.FreeHGlobal(unmanagedPointer);

        image.rgb = new byte[outSize];
        Marshal.Copy(outBuffer, image.rgb, 0, outSize);
        image.width  = outWidth;
        image.height = outHeight;

        FrameQueue.queue.Enqueue(image);
    }
示例#3
0
        private void Render(object data)
        {
            glWindowHandle = Backend.InitServerOpenGL(hwnd, (int)parent.ActualWidth, (int)parent.ActualHeight);
            long lastTick = 0, nowTick = 0;

            while (isRunning)
            {
                if (FrameQueue.queue.Count == 0)
                {
                    continue;
                }
                PpmImage nowFrame = FrameQueue.queue.Dequeue();
                //GC.Collect();
                IntPtr ptr = Marshal.UnsafeAddrOfPinnedArrayElement(nowFrame.rgb, 0);
                Backend.ServerOpenGLRender(glWindowHandle, nowFrame.width, nowFrame.height, ptr);
                //PollEvents();
                if (lastTick != 0)
                {
                    nowTick = DateTime.Now.Ticks;
                    Thread.Sleep((int)((nowTick - lastTick) / 10000));
                }
                lastTick = nowTick;
            }
            Backend.Shutdown(glWindowHandle);
        }