void Update()
    {
        if (texture == null)
        {
            return;
        }

        if (TextureDirty)
        {
            //lock (LastJpeg)
            {
                try
                {
                    var EncodeStart = Time.realtimeSinceStartup;
                    PopEncodeJpeg.EncodeToJpeg(texture, ref LastJpeg, ref LastJpegLength);
                    var EncodeTimeMs = (int)((Time.realtimeSinceStartup - EncodeStart) * 1000.0f);
                    Debug.Log("Jpeg encode took " + EncodeTimeMs + "ms");
                    OnDebug.Invoke("Jpeg encode took " + EncodeTimeMs + "ms");
                    TextureDirty = false;
                }
                catch {
                    LastJpegLength = 0;
                    throw;
                }
            }
        }
    }
    static public bool DoSaveTextureToJpeg(Texture Tex, string Filename)
    {
        var Temp = GetTexture2D(Tex);

        byte[] Bytes = PopEncodeJpeg.EncodeToJpeg(Temp);
        File.WriteAllBytes(Filename, Bytes);
        return(true);
    }
Exemple #3
0
 void Start()
 {
     JpegQueue = new FrameQueue <PixelFrame, byte[]>((Frame) =>
     {
         return(PopEncodeJpeg.EncodeToJpeg(Frame.Pixels, (int)Frame.Size.x, (int)Frame.Size.y, Frame.Channels, Frame.Rgb));
     },
                                                     (Bytes, OnCompleted) =>
     {
         try
         {
             Socket.Send(Bytes, OnCompleted);
         }
         catch
         {
             OnCompleted.Invoke(false);
         }
     }
                                                     );
 }
    public void                     OnPixels(byte[] Pixels, Vector2 Size, int Channels)
    {
        var NextFilename = OutputFilename;

        if (IncrementFilename)
        {
            NextFilename = OutputFileDir + System.IO.Path.DirectorySeparatorChar + "Frame" + FilenameCount + ".jpg";
            FilenameCount++;
        }

        //	async
        System.Threading.ThreadPool.QueueUserWorkItem((WorkItem) => {
            try
            {
                var Jpeg = PopEncodeJpeg.EncodeToJpeg(Pixels, (int)Size.x, (int)Size.y, Channels, false);
                System.IO.File.WriteAllBytes(NextFilename, Jpeg);
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
            }
        }
                                                      );
    }