Updated init method implementations in MPPMask
This commit is contained in:
		
							parent
							
								
									1f77fa9de4
								
							
						
					
					
						commit
						83486ed01b
					
				| 
						 | 
				
			
			@ -14,7 +14,7 @@
 | 
			
		|||
 | 
			
		||||
"""MediaPipe Task Library Helper Rules for iOS"""
 | 
			
		||||
 | 
			
		||||
MPP_TASK_MINIMUM_OS_VERSION = "11.0"
 | 
			
		||||
MPP_TASK_MINIMUM_OS_VERSION = "12.0"
 | 
			
		||||
 | 
			
		||||
# 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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -71,21 +71,31 @@ NS_SWIFT_NAME(Mask)
 | 
			
		|||
 * Initializes an `MPPMask` object of type `MPPMaskDataTypeUInt8` with the given `UInt8*` data,
 | 
			
		||||
 * 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 width The width 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.
 | 
			
		||||
 */
 | 
			
		||||
- (nullable instancetype)initWithUInt8Data:(const UInt8 *)uint8Data
 | 
			
		||||
                                     width:(NSInteger)width
 | 
			
		||||
                                    height:(NSInteger)height NS_DESIGNATED_INITIALIZER;
 | 
			
		||||
                                    height:(NSInteger)height
 | 
			
		||||
                                shouldCopy:(BOOL)shouldCopy NS_DESIGNATED_INITIALIZER;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Initializes an `MPPMask` object of type `MPPMaskDataTypeFloat32` with the given `float*` data,
 | 
			
		||||
 * width and height.
 | 
			
		||||
 *
 | 
			
		||||
 * @param uint8Data A pointer to the memory location of the `float` data array.
 | 
			
		||||
 * If `shouldCopy` is set to `YES`, the newly created `MPPMask` stores a reference to a deep copied
 | 
			
		||||
 * `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 height The height of the mask.
 | 
			
		||||
 *
 | 
			
		||||
| 
						 | 
				
			
			@ -93,7 +103,8 @@ NS_SWIFT_NAME(Mask)
 | 
			
		|||
 */
 | 
			
		||||
- (nullable instancetype)initWithFloat32Data:(const float *)float32Data
 | 
			
		||||
                                       width:(NSInteger)width
 | 
			
		||||
                                      height:(NSInteger)height NS_DESIGNATED_INITIALIZER;
 | 
			
		||||
                                      height:(NSInteger)height
 | 
			
		||||
                                  shouldCopy:(BOOL)shouldCopy NS_DESIGNATED_INITIALIZER;
 | 
			
		||||
 | 
			
		||||
// TODO: Add methods for CVPixelBuffer conversion.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -48,46 +48,36 @@
 | 
			
		|||
 | 
			
		||||
- (nullable instancetype)initWithUInt8Data:(const UInt8 *)uint8Data
 | 
			
		||||
                                     width:(NSInteger)width
 | 
			
		||||
                                    height:(NSInteger)height {
 | 
			
		||||
                                    height:(NSInteger)height
 | 
			
		||||
                                shouldCopy:(BOOL)shouldCopy {
 | 
			
		||||
  self = [self initWithWidth:width height:height dataType:MPPMaskDataTypeUInt8 error:nil];
 | 
			
		||||
  if (self) {
 | 
			
		||||
    _uint8Data = uint8Data;
 | 
			
		||||
    if (shouldCopy) {
 | 
			
		||||
      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;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (nullable instancetype)initWithFloat32Data:(const float *)float32Data
 | 
			
		||||
                                       width:(NSInteger)width
 | 
			
		||||
                                      height:(NSInteger)height {
 | 
			
		||||
                                      height:(NSInteger)height
 | 
			
		||||
                                  shouldCopy:(BOO)shouldCopy {
 | 
			
		||||
  self = [self initWithWidth:width height:height dataType:MPPMaskDataTypeFloat32 error:nil];
 | 
			
		||||
  if (self) {
 | 
			
		||||
    _float32Data = float32Data;
 | 
			
		||||
  }
 | 
			
		||||
  return self;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
- (instancetype)initWithUInt8DataToCopy:(const UInt8 *)uint8DataToCopy
 | 
			
		||||
                                  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));
 | 
			
		||||
    if (shouldCopy) {
 | 
			
		||||
      size_t length = _width * _height;
 | 
			
		||||
      _uint8DataPtr = std::unique_ptr<UInt8[]>(new UInt8[length]);
 | 
			
		||||
      _uint8Data = _uint8DataPtr.get();
 | 
			
		||||
      memcpy((UInt8 *)_uint8Data, uint8DataToCopy, length * sizeof(UInt8));
 | 
			
		||||
    } else {
 | 
			
		||||
      _float32Data = float32Data;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  return self;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -143,11 +133,13 @@
 | 
			
		|||
    case MPPMaskDataTypeUInt8:
 | 
			
		||||
      return [[MPPMask alloc] initWithUInt8DataToCopy:self.uint8Data
 | 
			
		||||
                                                width:self.width
 | 
			
		||||
                                               height:self.height];
 | 
			
		||||
                                               height:self.height
 | 
			
		||||
                                           shouldCopy:YES];
 | 
			
		||||
    case MPPMaskDataTypeFloat32:
 | 
			
		||||
      return [[MPPMask alloc] initWithFloat32DataToCopy:self.float32Data
 | 
			
		||||
                                                  width:self.width
 | 
			
		||||
                                                 height:self.height];
 | 
			
		||||
                                                 height:self.height
 | 
			
		||||
                                             shouldCopy:YES];
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user