From f59f9a94cea6fe2e717d7f08920307c5b63e3e2f Mon Sep 17 00:00:00 2001 From: Jan Herling Date: Wed, 6 Nov 2024 15:02:49 -0800 Subject: [PATCH] Extended utility function Utilities::extractFrame() Summary: Just an option to access the y-plane of an ARKit frame. Reviewed By: enpe Differential Revision: D65562188 fbshipit-source-id: f2fb7868162c1d60b1a995b3d3aadc0f4f2805fb --- impl/ocean/devices/arkit/Utilities.h | 3 ++- impl/ocean/devices/arkit/Utilities.mm | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/impl/ocean/devices/arkit/Utilities.h b/impl/ocean/devices/arkit/Utilities.h index f1ebe75b0..91b6850be 100644 --- a/impl/ocean/devices/arkit/Utilities.h +++ b/impl/ocean/devices/arkit/Utilities.h @@ -65,8 +65,9 @@ class OCEAN_DEVICES_ARKIT_EXPORT Utilities * Extracts the color image from an ARKit frame. * @param arFrame The ARKit frame from which the color image will be extracted, must be valid * @param copyData True, to copy the data; False, to only use the memory of the ARKit frame + * @param preferredPixelFormat Optional preferred pixel format of the resulting frame, however the resulting frame can have any pixel format, FORMAT_UNDEFINED if not of interest */ - static Frame extractFrame(const ARFrame* arFrame, const bool copyData = true); + static Frame extractFrame(const ARFrame* arFrame, const bool copyData = true, const FrameType::PixelFormat preferredPixelFormat = FrameType::FORMAT_UNDEFINED); /** * Extracts the depth image from an ARKit frame, if existing. diff --git a/impl/ocean/devices/arkit/Utilities.mm b/impl/ocean/devices/arkit/Utilities.mm index 1f51c7810..67d577b27 100644 --- a/impl/ocean/devices/arkit/Utilities.mm +++ b/impl/ocean/devices/arkit/Utilities.mm @@ -18,13 +18,15 @@ namespace ARKit { -Frame Utilities::extractFrame(const ARFrame* arFrame, const bool copyData) +Frame Utilities::extractFrame(const ARFrame* arFrame, const bool copyData, const FrameType::PixelFormat preferredPixelFormat) { ocean_assert(arFrame != nullptr); const CVPixelBufferRef capturedImage = arFrame.capturedImage; - const Media::AVFoundation::PixelBufferAccessor pixelBufferAccessor(capturedImage, true /*readOnly*/); + const bool accessYPlaneOnly = preferredPixelFormat == FrameType::FORMAT_Y8; + + const Media::AVFoundation::PixelBufferAccessor pixelBufferAccessor(capturedImage, true /*readOnly*/, accessYPlaneOnly); if (!pixelBufferAccessor) {