System.Threading.Tasks.TaskCompletionSource.TrySetResult(Screenshot)

Here are the examples of the csharp api System.Threading.Tasks.TaskCompletionSource.TrySetResult(Screenshot) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

3 Examples 7

19 Source : ARFoundationCaptureManager.cs
with MIT License
from KIT-ISAS

public async ValueTask<Screenshot> CaptureDepthAsync(
            int reuseCaptureAgeInMs = 0,
            CancellationToken token = default)
        {
            if (reuseCaptureAgeInMs > 0
                && lastDepth != null
                && (GameThread.Now - lastDepth.Timestamp.ToDateTime()).TotalMilliseconds < reuseCaptureAgeInMs)
            {
                return lastDepth;
            }

            token.ThrowIfCancellationRequested();

            if (occlusionManager.requestedEnvironmentDepthMode == EnvironmentDepthMode.Disabled)
            {
                return null;
            }

            if (!occlusionManager.TryAcquireEnvironmentDepthCpuImage(out XRCpuImage image))
            {
                Logger.Info($"{this}: Depth capture failed.");
                return null;
            }

            TaskCompletionSource<Screenshot> task;
            using (image)
            {
                var conversionParams = new XRCpuImage.ConversionParams
                {
                    inputRect = new RectInt(0, 0, image.width, image.height),
                    outputDimensions = new Vector2Int(image.width, image.height),
                    outputFormat = TextureFormat.RFloat,
                    transformation = XRCpuImage.Transformation.MirrorY
                };


                task = new TaskCompletionSource<Screenshot>();
                int width = image.width;
                int height = image.height;
                var pose = arCameraTransform.AsPose();

                int? colorWidth = cameraManager.subsystem.currentConfiguration?.width;

                image.ConvertAsync(conversionParams, (status, _, array) =>
                {
                    if (token.IsCancellationRequested)
                    {
                        task.TrySetCanceled();
                        return;
                    }

                    if (status != XRCpuImage.AsyncConversionStatus.Ready)
                    {
                        Logger.Info($"{this}: Conversion request of depth image failed with status {status}");
                        task.TrySetResult(null);
                        return;
                    }

                    byte[] bytes = new byte[array.Length];
                    NativeArray<byte>.Copy(array, bytes, array.Length);

                    float scale = colorWidth == null ? 1 : width / (float) colorWidth.Value;
                    var ss = new Screenshot(ScreenshotFormat.Float, width, height, Intrinsic.Scale(scale), pose, bytes);
                    lastDepth = ss;
                    ScreenshotDepth?.Invoke(ss);
                    task.TrySetResult(ss);
                });
            }

            var screenshot = await task.Task;
            await Task.Run(() => MirrorX<float>(screenshot.Bytes, screenshot.Width, screenshot.Height), token);
            return screenshot;
        }

19 Source : ARFoundationCaptureManager.cs
with MIT License
from KIT-ISAS

public async ValueTask<Screenshot> CaptureColorAsync(
            int reuseCaptureAgeInMs = 0,
            CancellationToken token = default)
        {
            if (reuseCaptureAgeInMs > 0
                && lastColor != null
                && (GameThread.Now - lastColor.Timestamp.ToDateTime()).TotalMilliseconds < reuseCaptureAgeInMs)
            {
                return lastColor;
            }

            token.ThrowIfCancellationRequested();

            if (!cameraManager.TryAcquireLatestCpuImage(out XRCpuImage image))
            {
                //Logger.Info($"{this}: Color capture failed.");
                return null;
            }

            TaskCompletionSource<Screenshot> task;
            using (image)
            {
                var conversionParams = new XRCpuImage.ConversionParams
                {
                    inputRect = new RectInt(0, 0, image.width, image.height),
                    outputDimensions = new Vector2Int(image.width / 2, image.height / 2),
                    outputFormat = TextureFormat.RGB24,
                };

                task = new TaskCompletionSource<Screenshot>();
                int width = image.width / 2;
                int height = image.height / 2;
                var pose = arCameraTransform.AsPose();

                image.ConvertAsync(conversionParams, (status, _, array) =>
                {
                    if (token.IsCancellationRequested)
                    {
                        task.TrySetCanceled();
                        return;
                    }

                    if (status != XRCpuImage.AsyncConversionStatus.Ready)
                    {
                        Logger.Info($"{this}: Conversion request of color image failed with status {status}");
                        task.TrySetResult(null);
                        return;
                    }

                    byte[] bytes = new byte[array.Length];
                    NativeArray<byte>.Copy(array, bytes, array.Length);

                    var ss = new Screenshot(ScreenshotFormat.Rgb, width, height, Intrinsic.Scale(0.5f), pose, bytes);
                    lastColor = ss;
                    ScreenshotColor?.Invoke(ss);
                    task.TrySetResult(ss);
                });
            }

            return await task.Task;
        }

19 Source : ARFoundationCaptureManager.cs
with MIT License
from KIT-ISAS

public async ValueTask<Screenshot> CaptureDepthConfidenceAsync(
            int reuseCaptureAgeInMs = 0,
            CancellationToken token = default)
        {
            if (reuseCaptureAgeInMs > 0
                && lastConfidence != null
                && (GameThread.Now - lastConfidence.Timestamp.ToDateTime()).TotalMilliseconds < reuseCaptureAgeInMs)
            {
                return lastConfidence;
            }

            token.ThrowIfCancellationRequested();

            if (occlusionManager.requestedEnvironmentDepthMode == EnvironmentDepthMode.Disabled)
            {
                return null;
            }

            if (!occlusionManager.TryAcquireEnvironmentDepthConfidenceCpuImage(out XRCpuImage image))
            {
                Logger.Info($"{this}: Depth capture failed.");
                return null;
            }

            TaskCompletionSource<Screenshot> task;
            using (image)
            {
                var conversionParams = new XRCpuImage.ConversionParams
                {
                    inputRect = new RectInt(0, 0, image.width, image.height),
                    outputDimensions = new Vector2Int(image.width, image.height),
                    outputFormat = TextureFormat.R8,
                    transformation = XRCpuImage.Transformation.MirrorY
                };


                task = new TaskCompletionSource<Screenshot>();
                int width = image.width;
                int height = image.height;
                var pose = arCameraTransform.AsPose();

                int? colorWidth = cameraManager.subsystem.currentConfiguration?.width;

                image.ConvertAsync(conversionParams, (status, _, array) =>
                {
                    if (token.IsCancellationRequested)
                    {
                        task.TrySetCanceled();
                        return;
                    }

                    if (status != XRCpuImage.AsyncConversionStatus.Ready)
                    {
                        Logger.Info($"{this}: Conversion request of confidence image failed with status {status}");
                        task.TrySetResult(null);
                        return;
                    }

                    byte[] bytes = new byte[array.Length];
                    NativeArray<byte>.Copy(array, bytes, array.Length);

                    float scale = colorWidth == null ? 1 : width / (float) colorWidth.Value;
                    var ss = new Screenshot(ScreenshotFormat.Mono8, width, height, Intrinsic.Scale(scale), pose, bytes);
                    lastConfidence = ss;
                    task.TrySetResult(ss);
                });
            }

            var screenshot = await task.Task;
            await Task.Run(() => MirrorX<byte>(screenshot.Bytes, screenshot.Width, screenshot.Height), token);
            return screenshot;
        }