Exemplo n.º 1
0
        /// <summary>
        /// Perform asynchronous capture for the provided camera source.
        /// </summary>
        /// <param name="sourceCamera">Camera for which the capture is to be performed.</param>
        /// <param name="renderTextureFormat">Graphics format to be used for the read back.</param>
        /// <param name="path">File path on the local file system where the image is to be saved.</param>
        /// <param name="format">Image format in which the image is to be saved.</param>
        public static void ScreenCaptureAsync(Camera sourceCamera, GraphicsFormat renderTextureFormat, string path, CaptureImageEncoder.ImageFormat format = CaptureImageEncoder.ImageFormat.Raw)
        {
            Debug.Assert((sourceCamera != null), "Source Camera cannot be null");
            Debug.Assert(GraphicsUtilities.SupportsRenderTextureFormat(renderTextureFormat));

            Func <AsyncRequest <CaptureCamera.CaptureState>, AsyncRequest <CaptureCamera.CaptureState> .Result> functor = (AsyncRequest <CaptureCamera.CaptureState> r) =>
            {
                r.data.colorBuffer = CaptureImageEncoder.EncodeArray(r.data.colorBuffer as Array, sourceCamera.pixelWidth, sourceCamera.pixelHeight, GraphicsFormat.R8G8B8A8_UNorm, format);
                var result = FileProducer.Write(path, r.data.colorBuffer as Array);
                return(result ? AsyncRequest <CaptureCamera.CaptureState> .Result.Completed : AsyncRequest <CaptureCamera.CaptureState> .Result.Error);
            };

            CaptureCamera.Capture(sourceCamera, functor);
        }
        /// <summary>
        /// Capture chunked logging to the file at the given path
        /// </summary>
        /// <param name="path">Path to the chunked log file</param>
        /// <param name="addSequenceNumber">boolean indicating if sequence number needs to be appended at the end</param>
        /// <param name="bufferSize">Maximum buffer size to hold in memory before the data is flushed down to the file system</param>
        /// <param name="maxElapsedSeconds">Maximum time to hold the data in the buffer before it is flushed down to the file system.</param>
        public static void CaptureToFile(string path, bool addSequenceNumber = true, int bufferSize = kDefaultBufferSize, float maxElapsedSeconds = kDefaultMaxSecondsElapsed)
        {
            if (_capturingLog == false)
            {
                _capturingLog  = true;
                _logPath       = new SequencedPathName(path, addSequenceNumber);
                _captureBuffer = new ChunkedStream(bufferSize, maxElapsedSeconds, functor: (AsyncRequest <object> request) =>
                {
                    FileProducer.Write(_logPath.GetPath(), request.data as Array, false, false);
                    return(AsyncRequest.Result.Completed);
                });

                ReplayExistingLog();
                Application.logMessageReceivedThreaded += HandleLog;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Captures a camera render and writes out the color and depth channels to a file.
        /// </summary>
        /// <param name="camera"> The Camera to capture data from. </param>
        /// <param name="colorFormat"> The pixel format to capture in. </param>
        /// <param name="colorPath"> The location of the file to write out. </param>
        /// <param name="colorImageFormat"> The image format to write the data out in. </param>
        /// <param name="depthFormat"> The pixel format to capture in. </param>
        /// <param name="depthPath"> The location of the file to write out. </param>
        /// <param name="depthImageFormat"> The image format to write the data out in. </param>
        /// <returns>AsyncRequest&lt;CaptureState&gt;</returns>
        public static AsyncRequest <CaptureState> CaptureColorAndDepthToFile
        (
            Camera camera,
            GraphicsFormat colorFormat = GraphicsFormat.R8G8B8A8_UNorm,
            string colorPath           = null,
            CaptureImageEncoder.ImageFormat colorImageFormat = CaptureImageEncoder.ImageFormat.Jpg,
            GraphicsFormat depthFormat = GraphicsFormat.R16_UNorm,
            string depthPath           = null,
            CaptureImageEncoder.ImageFormat depthImageFormat = CaptureImageEncoder.ImageFormat.Raw
        )
        {
            Debug.Assert(camera != null, "CaptureColorAndDepthToFile camera cannot be null");

            Func <AsyncRequest <CaptureState>, AsyncRequest <CaptureState> .Result> colorFunctor = null;
            Func <AsyncRequest <CaptureState>, AsyncRequest <CaptureState> .Result> depthFunctor = null;

            var width  = camera.pixelWidth;
            var height = camera.pixelHeight;

            bool flipY = ShouldFlipY(camera);

            if (colorPath != null)
            {
                colorFunctor = (AsyncRequest <CaptureState> r) =>
                {
                    colorPath = CaptureImageEncoder.EnforceFileExtension(colorPath, colorImageFormat);
                    var result = FileProducer.Write(colorPath, CaptureImageEncoder.EncodeArray(r.data.colorBuffer as Array, width, height, colorFormat, colorImageFormat));
                    return(result ? AsyncRequest.Result.Completed : AsyncRequest.Result.Error);
                };
            }

            if (depthPath != null)
            {
                depthFunctor = (AsyncRequest <CaptureState> r) =>
                {
                    depthPath = CaptureImageEncoder.EnforceFileExtension(depthPath, depthImageFormat);
                    var result = FileProducer.Write(depthPath, CaptureImageEncoder.EncodeArray(r.data.depthBuffer as Array, width, height, depthFormat, depthImageFormat));
                    return(result ? AsyncRequest <CaptureState> .Result.Completed : AsyncRequest <CaptureState> .Result.Error);
                };
            }

            return(Capture(camera, colorFunctor, colorFormat, depthFunctor, depthFormat, flipY: flipY));
        }