Functions

The following functions are available globally.

  • Parses the JSON description of a vector input or output.

    Handles a vector, matrix, or other multidimensional array (tensor), described as a one dimensional unrolled vector with an optional labels entry.

    Declaration

    Objective-C

    TIOLayerInterface *_Nullable TIOTFLiteModelParseTIOVectorDescription(
        NSDictionary *_Nonnull dict, BOOL isInput, BOOL quantized,
        TIOModelBundle *_Nonnull bundle)

    Swift

    func TIOTFLiteModelParseTIOVectorDescription(_ dict: [AnyHashable : Any], _ isInput: Bool, _ quantized: Bool, _ bundle: TIOModelBundle) -> TIOLayerInterface?

    Parameters

    dict

    The JSON description in NSDictionary format.

    isInput

    YES if this is an input layer, NO if it is an output layer.

    quantized

    YES if the layer expects or returns quantized bytes, NO otherwise.

    bundle

    The ModelBundel that is being parsed, needed to derive a path to the labels file.

    Return Value

    TIOLayerInterface An interface that describes this pixel buffer input or output.

  • Parses the JSON description of a pixel buffer input or output.

    Pixel buffers are handled as their own case instead of as a three-dimensional volume because of byte alignment and pixel format conversion requirements.

    Declaration

    Objective-C

    TIOLayerInterface *_Nullable TIOTFLiteModelParseTIOPixelBufferDescription(
        NSDictionary *_Nonnull dict, BOOL isInput, BOOL quantized)

    Swift

    func TIOTFLiteModelParseTIOPixelBufferDescription(_ dict: [AnyHashable : Any], _ isInput: Bool, _ quantized: Bool) -> TIOLayerInterface?

    Parameters

    dict

    The JSON description in NSDictionary format.

    isInput

    YES if this is an input layer, NO if it is an output layer.

    quantized

    YES if the layer expects or returns quantized bytes, NO otherwise.

    Return Value

    TIOLayerInterface An interface that describes this pixel buffer input or output.

  • Parses the quantization key of an input description and returns an associated data quantizer.

    Declaration

    Objective-C

    TIODataQuantizer _Nullable TIODataQuantizerForDict(
        NSDictionary *_Nullable dict, NSError *_Nullable *_Nullable error)

    Swift

    func TIODataQuantizerForDict(_ dict: [AnyHashable : Any]?, _ error: NSErrorPointer) -> TIODataQuantizer?
  • Parses the dequantization key of an output description and returns an associated data dequantizer.

    Declaration

    Objective-C

    TIODataDequantizer _Nullable TIODataDequantizerForDict(
        NSDictionary *_Nullable dict, NSError *_Nullable *_Nullable error)

    Swift

    func TIODataDequantizerForDict(_ dict: [AnyHashable : Any]?, _ error: NSErrorPointer) -> TIODataDequantizer?
  • Converts an array of shape values to an TIOImageVolume.

    Declaration

    Objective-C

    TIOImageVolume TIOImageVolumeForShape(NSArray<NSNumber *> *_Nullable shape)

    Swift

    func TIOImageVolumeForShape(_ shape: [NSNumber]?) -> TIOImageVolume
  • Converts a pixel format string such as "RGB" or "BGR" to a Core Video pixel format type.

    Declaration

    Objective-C

    OSType TIOPixelFormatForString(NSString *_Nullable formatString)

    Swift

    func TIOPixelFormatForString(_ formatString: String?) -> OSType
  • Returns the TIOPixelNormalizer given an input dictionary.

    Declaration

    Objective-C

    TIOPixelNormalizer _Nullable TIOPixelNormalizerForDictionary(
        NSDictionary *_Nullable input, NSError *_Nullable *_Nullable error)

    Swift

    func TIOPixelNormalizerForDictionary(_ input: [AnyHashable : Any]?, _ error: NSErrorPointer) -> TIOPixelNormalizer?
  • Returns the denormalizer for a given input dictionary.

    Declaration

    Objective-C

    TIOPixelDenormalizer _Nullable TIOPixelDenormalizerForDictionary(
        NSDictionary *_Nullable input, NSError *_Nullable *_Nullable error)

    Swift

    func TIOPixelDenormalizerForDictionary(_ input: [AnyHashable : Any]?, _ error: NSErrorPointer) -> TIOPixelDenormalizer?
  • Converts a string representation of a capture device position, e.g. a camera position, to an AVCaptureDevicePosition.

    Declaration

    Objective-C

    AVCaptureDevicePosition
    TIOModelOptionsAVCaptureDevicePositionFromString(NSString *_Nullable descriptor)

    Swift

    func TIOModelOptionsAVCaptureDevicePositionFromString(_ descriptor: String?) -> AVCaptureDevice.Position

    Parameters

    descriptor

    A string representation of a device position. ‘front’ and ‘back’ are the only values currently supported.

    Return Value

    AVCaptureDevicePosition The qualified device position, either AVCaptureDevicePositionFront, AVCaptureDevicePositionBack, or AVCaptureDevicePositionUnspecified.

  • Checks if two image volumes are equal.

    Declaration

    Objective-C

    BOOL TIOImageVolumesEqual(const TIOImageVolume)

    Swift

    func TIOImageVolumesEqual(_: TIOImageVolume) -> Bool

    Parameters

    a

    The first image volume to compare.

    b

    The second image volume to compare.

    Return Value

    BOOL YES if two image volumes are equal, NO otherwise.

  • Returns a copy of the pixel buffer.

    You must release the returned pixel buffer with CVPixelBufferRelease.

    Declaration

    Objective-C

    CVPixelBufferRef _Nullable TIOCVPixelBufferCopy(
        CVPixelBufferRef _Nonnull pixelBuffer)

    Swift

    func TIOCVPixelBufferCopy(_ pixelBuffer: CVPixelBuffer) -> Unmanaged<CVPixelBuffer>?

    Parameters

    pixelBuffer

    The pixel buffer to copy.

    Return Value

    CVPixelBufferRef A copy of the pixel buffer. Returns NULL if a destination pixel buffer could not be created.

  • Rotates the pixel buffer at 90 degree intervals in a counterclockwise direction.

    You must release the returned pixel buffer with CVPixelBufferRelease.

    Declaration

    Objective-C

    CVPixelBufferRef _Nullable TIOCVPixelBufferRotate(
        CVPixelBufferRef _Nonnull pixelBuffer,
        TIOCVPixelBufferCounterclockwiseRotation rotation)

    Swift

    func TIOCVPixelBufferRotate(_ pixelBuffer: CVPixelBuffer, _ rotation: TIOCVPixelBufferCounterclockwiseRotation) -> Unmanaged<CVPixelBuffer>?

    Parameters

    pixelBuffer

    The pixel buffer to rotate.

    rotation

    The amount of rotation to apply.

    Return Value

    CVPixelBufferRef A rotated copy of the pixel buffer. Returns NULL if a destination pixel buffer could not be created or the rotation fails.

  • Converts a pixel buffer in ARGB format to one in BGRA format.

    Caller must release the returned pixel buffer with CVPixelBufferRelease.

    Declaration

    Objective-C

    CVPixelBufferRef _Nullable TIOCVPixelBufferCreateBGRAFromARGB(
        CVPixelBufferRef _Nonnull pixelBuffer)

    Swift

    func TIOCVPixelBufferCreateBGRAFromARGB(_ pixelBuffer: CVPixelBuffer) -> Unmanaged<CVPixelBuffer>?

    Parameters

    pixelBuffer

    The ARGB formatted pixel buffer to convert.

    Return Value

    CVPixelBufferRef A copy of the pixel buffer in BGRA format. Returns NULL if a destination pixel buffer could not be created.

  • Converts a pixel buffer in BGRA format to one in ARGB format.

    Caller must release the returned pixel buffer with CVPixelBufferRelease.

    Declaration

    Objective-C

    CVPixelBufferRef _Nullable TIOCVPixelBufferCreateARGBFromBGRA(
        CVPixelBufferRef _Nonnull pixelBuffer)

    Swift

    func TIOCVPixelBufferCreateARGBFromBGRA(_ pixelBuffer: CVPixelBuffer) -> Unmanaged<CVPixelBuffer>?

    Parameters

    pixelBuffer

    The BGRA formatted pixel buffer to convert.

    Return Value

    CVPixelBufferRef A copy of the pixel buffer in ARGB format. Returns NULL if a destination pixel buffer could not be created.

  • Copies an ARGB or BGRA formatted pixel buffer into four separate, channelwise grayscale pixel buffers.

    Caller must release the new pixel buffers with CVPixelBufferRelease.

    Declaration

    Objective-C

    CVReturn TIOCVPixelBufferCopySeparateChannels(
        CVPixelBufferRef _Nonnull pixelBuffer,
        CVPixelBufferRef _Nullable *_Nonnull channel0Buffer,
        CVPixelBufferRef _Nullable *_Nonnull channel1Buffer,
        CVPixelBufferRef _Nullable *_Nonnull channel2Buffer,
        CVPixelBufferRef _Nullable *_Nonnull channel3Buffer)

    Swift

    func TIOCVPixelBufferCopySeparateChannels(_ pixelBuffer: CVPixelBuffer, _ channel0Buffer: UnsafeMutablePointer<Unmanaged<CVPixelBuffer>?>, _ channel1Buffer: UnsafeMutablePointer<Unmanaged<CVPixelBuffer>?>, _ channel2Buffer: UnsafeMutablePointer<Unmanaged<CVPixelBuffer>?>, _ channel3Buffer: UnsafeMutablePointer<Unmanaged<CVPixelBuffer>?>) -> CVReturn

    Parameters

    pixelBuffer

    The pixel buffer to factor into its four channels.

    channel0Buffer

    A pointer to a pixel buffer that will contain the contents of the first channel. Set to NULL if any of the four channel buffers cannot be created.

    channel1Buffer

    A pointer to a pixel buffer that will contain the contents of the second channel. Set to NULL if any of the four channel buffers cannot be created.

    channel2Buffer

    A pointer to a pixel buffer that will contain the contents of the third channel. Set to NULL if any of the four channel buffers cannot be created.

    channel3Buffer

    A pointer to a pixel buffer that will contain the contents of the fourth channel. Set to NULL if any of the four channel buffers cannot be created.

    Return Value

    CVReturn kCVReturnSuccess if the operation was successful, kCVReturnError otherwise.

  • Returns a copy of the pixel buffer scaled and center cropped to size.

    Size must have equal width and height, and the target size must be smaller than the source size.

    Caller must release the returned pixel buffer with CVPixelBufferRelease.

    Declaration

    Objective-C

    CVPixelBufferRef _Nullable TIOCVPixelBufferResizeToSquare(
        CVPixelBufferRef _Nonnull pixelBuffer, CGSize size)

    Swift

    func TIOCVPixelBufferResizeToSquare(_ pixelBuffer: CVPixelBuffer, _ size: CGSize) -> Unmanaged<CVPixelBuffer>?

    Parameters

    pixelBuffer

    The pixel buffer to scale and crop.

    size

    The target size of the scale and cropped buffer.

    Return Value

    CVPixelBufferRef A copy of the pixel buffer scaled and cropped. Returns NULL if a destination pixel buffer could not be created.

  • A magical utility function that performs like a a defer in Swift.

    Do not use this function directly. Instead use tio_defer_block(). Code that is wrapped a call to tio_defer_block will automatically be called when the enclosing scope exits.

    Declaration

    Objective-C

    static void tio_defer_cleanup_block(void (^*block)(void))

    Swift

    func tio_defer_cleanup_block(_ block: UnsafeMutablePointer<(() -> Void)?>!)