Contents

vImageLookupTable_Planar8toPlanar128(_:_:_:_:)

Uses a lookup table to transform an 8-bit planar image to a 32-bit-per-channel, four-channel interleaved image.

Declaration

func vImageLookupTable_Planar8toPlanar128(_ src: UnsafePointer<vImage_Buffer>, _ dest: UnsafePointer<vImage_Buffer>, _ table: UnsafePointer<Pixel_FFFF>, _ flags: vImage_Flags) -> vImage_Error

Parameters

  • src:

    The source vImage buffer.

  • dest:

    A pointer to the destination vImage buffer structure. You’re responsible for filling out the height, width, and rowBytes fields of this structure, and for allocating a data buffer of the appropriate size. On return, the data buffer this structure points to contains the destination image data. When you no longer need the data buffer, deallocate the memory to prevent memory leaks.

  • table:

    A lookup table that contains 256 Pixel_ffff values.

  • flags:

    The options to use when performing the operation. If your code implements its own tiling or its own multithreading, pass Kvimagedonottile; otherwise, pass Kvimagenoflags.

Return Value

kvImageNoError; otherwise, one of the error codes in Data Types and Constants.

Discussion

For each pixel, this function uses the 8-bit value from the source image as an index to the Pixel_FFFF value from the table. The per-pixel conversion calculation is equivalent to the following:

uint32_t table[256*4];       // 128 bits per pixel and 32 bits per channel.
uint32_t *t_ptr = (uint32_t*)(table + 4 * srcRow[i]);
uint32_t a = t_ptr[0];
uint32_t r = t_ptr[1];
uint32_t g = t_ptr[2];
uint32_t b = t_ptr[3];
dstRow[3*i+0] = a;
dstRow[3*i+1] = r;
dstRow[3*i+2] = g;
dstRow[3*i+3] = b;

The following code shows how to create a lookup table that maps all source pixel values to a constant RGB value of (10, 20, 30):

let alpha: Pixel_F = 10
let red: Pixel_F = 20
let green: Pixel_F = 30
let blue: Pixel_F = 40
let lookupValue = Pixel_FFFF(alpha, red, green, blue)

let lookupTable = [Pixel_FFFF](repeating: lookupValue, count: 256)

let source = vImage.PixelBuffer<vImage.Planar8>(
    size: .init(width: 3, height: 1))
let destination = vImage.PixelBuffer<vImage.InterleavedFx4>(
    size: .init(width: 3, height: 1))

source.withUnsafePointerToVImageBuffer{ src in
    destination.withUnsafePointerToVImageBuffer { dest in
        
        _ = vImageLookupTable_Planar8toPlanar128(
            src,
            dest,
            lookupTable,
            vImage_Flags(kvImageNoFlags))
        
    }
}

// Prints "[10.0, 20.0, 30.0, 40.0,  10.0, 20.0, 30.0, 40.0,  10.0, 20.0, 30.0, 40.0]".
print(destination.array)

See Also

Transforming planar-to-interleaved with a lookup table