Updated method signatures in MPPImage+TestUtils
This commit is contained in:
parent
8077743bfc
commit
48190e6600
|
@ -22,6 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||||
* Helper utility for initializing `MPPImage` for MediaPipe iOS vision library tests.
|
* Helper utility for initializing `MPPImage` for MediaPipe iOS vision library tests.
|
||||||
*/
|
*/
|
||||||
@interface MPPImage (TestUtils)
|
@interface MPPImage (TestUtils)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads an image from a file in an app bundle into a `MPPImage` object.
|
* 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
|
+ (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject
|
||||||
fileName:(NSString *)name
|
fileName:(NSString *)name
|
||||||
ofType:(NSString *)type
|
ofType:(NSString *)type
|
||||||
error:(NSError **)error
|
|
||||||
NS_SWIFT_NAME(imageFromBundle(class:filename:type:));
|
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
|
+ (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject
|
||||||
fileName:(NSString *)name
|
fileName:(NSString *)name
|
||||||
ofType:(NSString *)type
|
ofType:(NSString *)type
|
||||||
orientation:(UIImageOrientation)imageOrientation
|
orientation:(UIImageOrientation)imageOrientation
|
||||||
error:(NSError **)error
|
|
||||||
NS_SWIFT_NAME(imageFromBundle(class:filename:type:orientation:));
|
NS_SWIFT_NAME(imageFromBundle(class:filename:type:orientation:));
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -14,33 +14,41 @@
|
||||||
|
|
||||||
#import "mediapipe/tasks/ios/test/vision/utils/sources/MPPImage+TestUtils.h"
|
#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)
|
@implementation MPPImage (TestUtils)
|
||||||
|
|
||||||
+ (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject
|
+ (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject
|
||||||
fileName:(NSString *)name
|
fileName:(NSString *)name
|
||||||
ofType:(NSString *)type
|
ofType:(NSString *)type {
|
||||||
error:(NSError **)error {
|
UIImage *image = [UIImage imageFromBundleWithClass:classObject fileName:name ofType:type];
|
||||||
NSString *imagePath = [[NSBundle bundleForClass:classObject] pathForResource:name ofType:type];
|
|
||||||
if (!imagePath) return nil;
|
|
||||||
|
|
||||||
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath];
|
return [[MPPImage alloc] initWithUIImage:image error:nil];
|
||||||
if (!image) return nil;
|
|
||||||
|
|
||||||
return [[MPPImage alloc] initWithUIImage:image error:error];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
+ (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject
|
+ (nullable MPPImage *)imageFromBundleWithClass:(Class)classObject
|
||||||
fileName:(NSString *)name
|
fileName:(NSString *)name
|
||||||
ofType:(NSString *)type
|
ofType:(NSString *)type
|
||||||
orientation:(UIImageOrientation)imageOrientation
|
orientation:(UIImageOrientation)imageOrientation {
|
||||||
error:(NSError **)error {
|
UIImage *image = [UIImage imageFromBundleWithClass:classObject fileName:name ofType:type];
|
||||||
NSString *imagePath = [[NSBundle bundleForClass:classObject] pathForResource:name ofType:type];
|
|
||||||
if (!imagePath) return nil;
|
|
||||||
|
|
||||||
UIImage *image = [[UIImage alloc] initWithContentsOfFile:imagePath];
|
return [[MPPImage alloc] initWithUIImage:image orientation:imageOrientation error:nil];
|
||||||
if (!image) return nil;
|
|
||||||
|
|
||||||
return [[MPPImage alloc] initWithUIImage:image orientation:imageOrientation error:error];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user