diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h index b7b777c97..3618d8de4 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.h @@ -16,7 +16,7 @@ #include "mediapipe/framework/packet.h" -/** +/** * This class helps create various kinds of packets for Mediapipe Vision Tasks. */ @interface MPPVisionPacketCreator : NSObject diff --git a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm index ff5e41030..d0ee3f5df 100644 --- a/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm +++ b/mediapipe/tasks/ios/vision/core/sources/MPPVisionPacketCreator.mm @@ -1,4 +1,4 @@ -// Copyright 2019 The MediaPipe Authors. +// Copyright 2023 The MediaPipe Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -19,19 +19,18 @@ #include "mediapipe/framework/formats/image.h" namespace { +using ::mediapipe::Image; using ::mediapipe::MakePacket; using ::mediapipe::Packet; -using ::mediapipe::Image; } // namespace struct freeDeleter { - void operator()(void* ptr) { free(ptr); } + void operator()(void *ptr) { free(ptr); } } @implementation MPPVisionPacketCreator + (Packet)createWithMPPImage:(MPPImage *)image error:(NSError **)error { - std::unique_ptr imageFrame = [image imageFrameWithError:error]; if (!imageFrame) { diff --git a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h index 724bccdad..ac304d6a0 100644 --- a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h +++ b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.h @@ -14,19 +14,20 @@ #import -#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h" #include "mediapipe/framework/formats/image_frame.h" +#import "mediapipe/tasks/ios/vision/core/sources/MPPImage.h" NS_ASSUME_NONNULL_BEGIN -/** +/** * Helper utility for converting `MPPImage` into a `mediapipe::ImageFrame`. */ @interface MPPImage (Utils) /** * Converts the `MPPImage` into a `mediapipe::ImageFrame`. - * Irrespective of whether the underlying buffer is grayscale, RGB, RGBA, BGRA etc., the MPPImage is converted to an RGB format. In case of grayscale images, the mono channel is duplicated - * in the R, G, B channels. + * Irrespective of whether the underlying buffer is grayscale, RGB, RGBA, BGRA etc., the MPPImage is + * converted to an RGB format. In case of grayscale images, the mono channel is duplicated in the R, + * G, B channels. * * @param error Pointer to the memory location where errors if any should be * saved. If @c NULL, no error will be saved. diff --git a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm index 8d6efe91c..e9f2540f7 100644 --- a/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm +++ b/mediapipe/tasks/ios/vision/core/utils/sources/MPPImage+Utils.mm @@ -25,7 +25,7 @@ #include "mediapipe/framework/formats/image_format.pb.h" namespace { - using ::mediapipe::ImageFrame; +using ::mediapipe::ImageFrame; } @interface MPPPixelDataUtils : NSObject @@ -41,7 +41,8 @@ namespace { @interface MPPCVPixelBufferUtils : NSObject -+ (std::unique_ptr)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error; ++ (std::unique_ptr)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer + error:(NSError **)error; @end @@ -124,15 +125,14 @@ namespace { @implementation MPPCVPixelBufferUtils -+ (std::unique_ptr)rgbImageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer error:(NSError **)error { ++ (std::unique_ptr)rgbImageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer + error:(NSError **)error { CVPixelBufferLockBaseAddress(pixelBuffer, 0); size_t width = CVPixelBufferGetWidth(pixelBuffer); size_t height = CVPixelBufferGetHeight(pixelBuffer); size_t stride = CVPixelBufferGetBytesPerRow(pixelBuffer); - - uint8_t *rgbPixelData = [MPPPixelDataUtils rgbPixelDataFromPixelData:(uint8_t *)CVPixelBufferGetBaseAddress(pixelBuffer) withWidth:CVPixelBufferGetWidth(pixelBuffer) @@ -146,17 +146,17 @@ namespace { if (!rgbPixelData) { return nullptr; } - - std::unique_ptr imageFrame = absl::make_unique( - ::mediapipe::ImageFormat::SRGB, /*width=*/width, /*height=*/height, stride, - static_cast(rgbPixelData), - /*deleter=*/free); + + std::unique_ptr imageFrame = + absl::make_unique(::mediapipe::ImageFormat::SRGB, /*width=*/width, + /*height=*/height, stride, static_cast(rgbPixelData), + /*deleter=*/free); return imageFrame; } + (std::unique_ptr)imageFrameFromCVPixelBuffer:(CVPixelBufferRef)pixelBuffer - error:(NSError **)error { + error:(NSError **)error { uint8_t *pixelData = NULL; OSType pixelBufferFormat = CVPixelBufferGetPixelFormatType(pixelBuffer); @@ -210,11 +210,11 @@ namespace { // We have drawn the image as an RGBA image with 8 bitsPerComponent and hence can safely input // a pixel format of type kCVPixelFormatType_32RGBA for conversion by vImage. pixelDataToReturn = [MPPPixelDataUtils rgbPixelDataFromPixelData:srcData - withWidth:width - height:height - stride:bytesPerRow - pixelBufferFormat:kCVPixelFormatType_32RGBA - error:error]; + withWidth:width + height:height + stride:bytesPerRow + pixelBufferFormat:kCVPixelFormatType_32RGBA + error:error]; } CGContextRelease(context); @@ -224,7 +224,7 @@ namespace { std::unique_ptr imageFrame = absl::make_unique( mediapipe::ImageFormat::SRGB, /*width=*/(int)width, /*height=*/(int)height, (int)bytesPerRow, - static_cast(pixelDataToReturn), + static_cast(pixelDataToReturn), /*deleter=*/free); return imageFrame; @@ -235,10 +235,8 @@ namespace { @implementation UIImage (ImageFrameUtils) - (std::unique_ptr)imageFrameFromCIImageWithError:(NSError **)error { - if (self.CIImage.pixelBuffer) { - return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.CIImage.pixelBuffer - error:error]; + return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.CIImage.pixelBuffer error:error]; } else if (self.CIImage.CGImage) { return [MPPCGImageUtils imageFrameFromCGImage:self.CIImage.CGImage error:error]; @@ -278,8 +276,7 @@ namespace { switch (self.imageSourceType) { case MPPImageSourceTypeSampleBuffer: { CVPixelBufferRef sampleImagePixelBuffer = CMSampleBufferGetImageBuffer(self.sampleBuffer); - return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:sampleImagePixelBuffer - error:error]; + return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:sampleImagePixelBuffer error:error]; } case MPPImageSourceTypePixelBuffer: { return [MPPCVPixelBufferUtils imageFrameFromCVPixelBuffer:self.pixelBuffer error:error]; diff --git a/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h index 2ca158113..f7e9a6297 100644 --- a/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h +++ b/mediapipe/tasks/ios/vision/image_classifier/sources/MPPImageClassifierOptions.h @@ -28,8 +28,9 @@ NS_SWIFT_NAME(ImageClassifierOptions) @property(nonatomic) MPPRunningMode runningMode; -/** - * The user-defined result callback for processing live stream data. The result callback should only be specified when the running mode is set to the live stream mode. +/** + * The user-defined result callback for processing live stream data. The result callback should only + * be specified when the running mode is set to the live stream mode. */ @property(nonatomic, copy) void (^completion)(MPPImageClassifierResult *result, NSError *error);