From 48190e6600af6d9162c4a443e9810d613dc305ee Mon Sep 17 00:00:00 2001 From: Prianka Liz Kariat Date: Thu, 23 Mar 2023 18:43:30 +0530 Subject: [PATCH] Updated method signatures in MPPImage+TestUtils --- .../vision/utils/sources/MPPImage+TestUtils.h | 15 ++++++- .../vision/utils/sources/MPPImage+TestUtils.m | 40 +++++++++++-------- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.h b/mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.h index 7f521e85d..eb0edf6ab 100644 --- a/mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.h +++ b/mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.h @@ -22,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN * Helper utility for initializing `MPPImage` for MediaPipe iOS vision library tests. */ @interface MPPImage (TestUtils) + /** * Loads an image from a file in an app bundle into a `MPPImage` object. * @@ -36,14 +37,24 @@ NS_ASSUME_NONNULL_BEGIN + (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject fileName:(NSString *)name ofType:(NSString *)type - error:(NSError **)error NS_SWIFT_NAME(imageFromBundle(class:filename:type:)); +/** + * Loads an image from a file in an app bundle into a `MPPImage` object with the specified orientation. + * + * @param classObject The specified class associated with the bundle containing + * the file to be loaded. + * @param name Name of the image file. + * @param type Extenstion of the image file. + * @param orientation Orientation of the image. + * + * @return The `MPPImage` object contains the loaded image. This method returns + * nil if it cannot load the image. + */ + (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject fileName:(NSString *)name ofType:(NSString *)type orientation:(UIImageOrientation)imageOrientation - error:(NSError **)error NS_SWIFT_NAME(imageFromBundle(class:filename:type:orientation:)); @end diff --git a/mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.m b/mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.m index 926d7a900..5421fd3bf 100644 --- a/mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.m +++ b/mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.m @@ -14,33 +14,41 @@ #import "mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.h" +@interface UIImage (FileUtils) + ++(nullable UIImage *)imageFromBundleWithClass:(Class)classObject fileName:(NSString *)name ofType:(NSString *)type; + +@end + +@implementation UIImage (FileUtils) + ++(nullable UIImage *)imageFromBundleWithClass:(Class)classObject fileName:(NSString *)name ofType:(NSString *)type { + + NSString *imagePath = [[NSBundle bundleForClass:classObject] pathForResource:name ofType:type]; + if (!imagePath) return nil; + + return [[UIImage alloc] initWithContentsOfFile:imagePath]; +} + +@end + @implementation MPPImage (TestUtils) + (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject fileName:(NSString *)name - ofType:(NSString *)type - error:(NSError **)error { - NSString *imagePath = [[NSBundle bundleForClass:classObject] pathForResource:name ofType:type]; - if (!imagePath) return nil; + ofType:(NSString *)type { + UIImage *image = [UIImage imageFromBundleWithClass:classObject fileName:name ofType:type]; - UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath]; - if (!image) return nil; - - return [[MPPImage alloc] initWithUIImage:image error:error]; + return [[MPPImage alloc] initWithUIImage:image error:nil]; } + (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject fileName:(NSString *)name ofType:(NSString *)type - orientation:(UIImageOrientation)imageOrientation - error:(NSError **)error { - NSString *imagePath = [[NSBundle bundleForClass:classObject] pathForResource:name ofType:type]; - if (!imagePath) return nil; + orientation:(UIImageOrientation)imageOrientation { + UIImage *image = [UIImage imageFromBundleWithClass:classObject fileName:name ofType:type]; - UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath]; - if (!image) return nil; - - return [[MPPImage alloc] initWithUIImage:image orientation:imageOrientation error:error]; + return [[MPPImage alloc] initWithUIImage:image orientation:imageOrientation error:nil]; } @end