Updated method signatures in MPPImage+TestUtils

This commit is contained in:
Prianka Liz Kariat 2023-03-23 18:43:30 +05:30
parent 8077743bfc
commit 48190e6600
2 changed files with 37 additions and 18 deletions

View File

@ -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

View File

@ -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