Revert "Updated init method implementations in MPPMask"

This reverts commit 83486ed01b.
This commit is contained in:
Prianka Liz Kariat 2023-06-16 19:56:23 +05:30
parent 83486ed01b
commit 52f6b8d899
3 changed files with 36 additions and 39 deletions

View File

@ -14,7 +14,7 @@
"""MediaPipe Task Library Helper Rules for iOS""" """MediaPipe Task Library Helper Rules for iOS"""
MPP_TASK_MINIMUM_OS_VERSION = "12.0" MPP_TASK_MINIMUM_OS_VERSION = "11.0"
# When the static framework is built with bazel, the all header files are moved # When the static framework is built with bazel, the all header files are moved
# to the "Headers" directory with no header path prefixes. This auxiliary rule # to the "Headers" directory with no header path prefixes. This auxiliary rule

View File

@ -71,31 +71,21 @@ NS_SWIFT_NAME(Mask)
* Initializes an `MPPMask` object of type `MPPMaskDataTypeUInt8` with the given `UInt8*` data, * Initializes an `MPPMask` object of type `MPPMaskDataTypeUInt8` with the given `UInt8*` data,
* width and height. * width and height.
* *
* If `shouldCopy` is set to `YES`, the newly created `MPPMask` stores a reference to a deep copied
* `uint8Data`. Since deep copies are expensive, it is recommended to not set `shouldCopy` unless
* the `MPPMask` must outlive the passed in `uint8Data`.
*
* @param uint8Data A pointer to the memory location of the `UInt8` data array. * @param uint8Data A pointer to the memory location of the `UInt8` data array.
* @param width The width of the mask. * @param width The width of the mask.
* @param height The height of the mask. * @param height The height of the mask.
* @param shouldCopy The height of the mask.
* *
* @return A new `MPPMask` instance with the given `UInt8*` data, width and height. * @return A new `MPPMask` instance with the given `UInt8*` data, width and height.
*/ */
- (nullable instancetype)initWithUInt8Data:(const UInt8 *)uint8Data - (nullable instancetype)initWithUInt8Data:(const UInt8 *)uint8Data
width:(NSInteger)width width:(NSInteger)width
height:(NSInteger)height height:(NSInteger)height NS_DESIGNATED_INITIALIZER;
shouldCopy:(BOOL)shouldCopy NS_DESIGNATED_INITIALIZER;
/** /**
* Initializes an `MPPMask` object of type `MPPMaskDataTypeFloat32` with the given `float*` data, * Initializes an `MPPMask` object of type `MPPMaskDataTypeFloat32` with the given `float*` data,
* width and height. * width and height.
* *
* If `shouldCopy` is set to `YES`, the newly created `MPPMask` stores a reference to a deep copied * @param uint8Data A pointer to the memory location of the `float` data array.
* `float32Data`. Since deep copies are expensive, it is recommended to not set `shouldCopy` unless
* the `MPPMask` must outlive the passed in `float32Data`.
*
* @param float32Data A pointer to the memory location of the `float` data array.
* @param width The width of the mask. * @param width The width of the mask.
* @param height The height of the mask. * @param height The height of the mask.
* *
@ -103,8 +93,7 @@ NS_SWIFT_NAME(Mask)
*/ */
- (nullable instancetype)initWithFloat32Data:(const float *)float32Data - (nullable instancetype)initWithFloat32Data:(const float *)float32Data
width:(NSInteger)width width:(NSInteger)width
height:(NSInteger)height height:(NSInteger)height NS_DESIGNATED_INITIALIZER;
shouldCopy:(BOOL)shouldCopy NS_DESIGNATED_INITIALIZER;
// TODO: Add methods for CVPixelBuffer conversion. // TODO: Add methods for CVPixelBuffer conversion.

View File

@ -48,36 +48,46 @@
- (nullable instancetype)initWithUInt8Data:(const UInt8 *)uint8Data - (nullable instancetype)initWithUInt8Data:(const UInt8 *)uint8Data
width:(NSInteger)width width:(NSInteger)width
height:(NSInteger)height height:(NSInteger)height {
shouldCopy:(BOOL)shouldCopy {
self = [self initWithWidth:width height:height dataType:MPPMaskDataTypeUInt8 error:nil]; self = [self initWithWidth:width height:height dataType:MPPMaskDataTypeUInt8 error:nil];
if (self) { if (self) {
if (shouldCopy) { _uint8Data = uint8Data;
size_t length = _width * _height;
_float32DataPtr = std::unique_ptr<float[]>(new float[length]);
_float32Data = _float32DataPtr.get();
memcpy((float *)_float32Data, float32DataToCopy, length * sizeof(float));
} else {
_uint8Data = uint8Data;
}
} }
return self; return self;
} }
- (nullable instancetype)initWithFloat32Data:(const float *)float32Data - (nullable instancetype)initWithFloat32Data:(const float *)float32Data
width:(NSInteger)width width:(NSInteger)width
height:(NSInteger)height height:(NSInteger)height {
shouldCopy:(BOO)shouldCopy {
self = [self initWithWidth:width height:height dataType:MPPMaskDataTypeFloat32 error:nil]; self = [self initWithWidth:width height:height dataType:MPPMaskDataTypeFloat32 error:nil];
if (self) { if (self) {
if (shouldCopy) { _float32Data = float32Data;
size_t length = _width * _height; }
_uint8DataPtr = std::unique_ptr<UInt8[]>(new UInt8[length]); return self;
_uint8Data = _uint8DataPtr.get(); }
memcpy((UInt8 *)_uint8Data, uint8DataToCopy, length * sizeof(UInt8));
} else { - (instancetype)initWithUInt8DataToCopy:(const UInt8 *)uint8DataToCopy
_float32Data = float32Data; width:(NSInteger)width
} height:(NSInteger)height {
self = [self initWithWidth:width height:height dataType:MPPMaskDataTypeUInt8 error:nil];
if (self) {
size_t length = _width * _height;
_uint8DataPtr = std::unique_ptr<UInt8[]>(new UInt8[length]);
_uint8Data = _uint8DataPtr.get();
memcpy((UInt8 *)_uint8Data, uint8DataToCopy, length * sizeof(UInt8));
}
return self;
}
- (instancetype)initWithFloat32DataToCopy:(const float *)float32DataToCopy
width:(NSInteger)width
height:(NSInteger)height {
self = [self initWithWidth:width height:height dataType:MPPMaskDataTypeFloat32 error:nil];
if (self) {
size_t length = _width * _height;
_float32DataPtr = std::unique_ptr<float[]>(new float[length]);
_float32Data = _float32DataPtr.get();
memcpy((float *)_float32Data, float32DataToCopy, length * sizeof(float));
} }
return self; return self;
} }
@ -133,13 +143,11 @@
case MPPMaskDataTypeUInt8: case MPPMaskDataTypeUInt8:
return [[MPPMask alloc] initWithUInt8DataToCopy:self.uint8Data return [[MPPMask alloc] initWithUInt8DataToCopy:self.uint8Data
width:self.width width:self.width
height:self.height height:self.height];
shouldCopy:YES];
case MPPMaskDataTypeFloat32: case MPPMaskDataTypeFloat32:
return [[MPPMask alloc] initWithFloat32DataToCopy:self.float32Data return [[MPPMask alloc] initWithFloat32DataToCopy:self.float32Data
width:self.width width:self.width
height:self.height height:self.height];
shouldCopy:YES];
} }
} }