TIOPixelBuffer

@interface TIOPixelBuffer : NSObject <TIOData>

Wraps a CVPixelBuffer and its orientation so that it can provide data to and receive data from a tensor.

  • The underlying pixel buffer

    For an input layer this is the pixel buffer prior to any transformations, such as scaling, cropping, and pixel format transoformation. For an output layer, this is a pixel buffer whose bytes have been supplied by the tensor, with any denormalization applied and an alpha channel added.

    Declaration

    Objective-C

    @property (readonly, atomic) CVPixelBufferRef _Nonnull pixelBuffer;

    Swift

    var pixelBuffer: CVPixelBuffer { get }
  • The pixel buffer as an input tensor sees it, with scaling, cropping, and pixel formatting applied, but prior to any normalization or removal of the alpha channel. NULL for an output.

    Declaration

    Objective-C

    @property (readonly, atomic) CVPixelBufferRef _Nonnull transformedPixelBuffer;

    Swift

    var transformedPixelBuffer: CVPixelBuffer { get }
  • The orientation of the underlying pixel buffer

    Pixel buffers being streamed from an AVCaptureDevice have an orientation of kCGImagePropertyOrientationRight, and like any pixel buffer whose orientation is not kCGImagePropertyOrientationUp, must be transformed before being sent to a model.

    Declaration

    Objective-C

    @property (readonly, atomic) CGImagePropertyOrientation orientation;

    Swift

    var orientation: CGImagePropertyOrientation { get }
  • Wraps a pixel buffer with a known orientation so that its bytes may be passed to a tensor.

    An input pixel buffer will be transformed to match the size and format expected by the tensor. If the pixel buffer is already in the expected size and format its bytes will be supplied directly to the tensor with no intermediate transformations, except for normalization and removal of the alpha channel, as needed.

    Declaration

    Objective-C

    - (nonnull instancetype)
    initWithPixelBuffer:(nonnull CVPixelBufferRef)pixelBuffer
            orientation:(CGImagePropertyOrientation)orientation;

    Swift

    init(pixelBuffer: CVPixelBuffer, orientation: CGImagePropertyOrientation)
  • Unavailable

    Use the designated initializer

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • Initializes TIOPixelBuffer with bytes from a tensor.

    Declaration

    Objective-C

    - (nullable instancetype)initWithBytes:(nonnull const void *)bytes
                                    length:(NSUInteger)length
                               description:
                                   (nonnull id<TIOLayerDescription>)description;

    Swift

    convenience init?(bytes: UnsafeRawPointer, length: UInt, description: TIOLayerDescription)

    Parameters

    bytes

    The output buffer to read from.

    length

    The length of the buffer.

    description

    A description of the data this buffer produces.

    Return Value

    instancetype An instance of TIOPixelBuffer

  • Request to fill a tensor with bytes.

    Declaration

    Objective-C

    - (void)getBytes:(nonnull void *)buffer
              length:(NSUInteger)length
         description:(nonnull id<TIOLayerDescription>)description;

    Swift

    func getBytes(_ buffer: UnsafeMutableRawPointer, length: UInt, description: TIOLayerDescription)

    Parameters

    buffer

    The input buffer to copy bytes to.

    length

    The length of the input buffer.

    description

    A description of the data this buffer expects.