vImageLookupTable_Planar8toPlanar24(_:_:_:_:)
Uses a lookup table to transform an 8-bit planar image to an 8-bit-per-channel, three-channel interleaved image.
Declaration
func vImageLookupTable_Planar8toPlanar24(_ src: UnsafePointer<vImage_Buffer>, _ dest: UnsafePointer<vImage_Buffer>, _ table: UnsafePointer<UInt32>, _ flags: vImage_Flags) -> vImage_ErrorParameters
- src:
The source vImage buffer.
- dest:
A pointer to the destination vImage buffer structure. You’re responsible for filling out the
height,width, androwBytesfields 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 Uint32_t values. The upper 24 bits of each value stores the red, green, and blue 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 24-bit value from the table. The per-pixel conversion calculation is equivalent to the following:
uint32_t table[256]; // 32 bits per pixel and 8 bits per channel.
uint8_t *t_ptr = (uint8_t*)(table + srcRow[i]);
uint8_t r = t_ptr[1];
uint8_t g = t_ptr[2];
uint8_t b = t_ptr[3];
dstRow[3*i+0] = r;
dstRow[3*i+1] = g;
dstRow[3*i+2] = 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 red: Pixel_8 = 10
let green: Pixel_8 = 20
let blue: Pixel_8 = 30
let lookupValue = (UInt32(blue) << 24) | (UInt32(green) << 16) | (UInt32(red) << 8)
let lookupTable = [UInt32](repeating: lookupValue, count: 256)
let source = vImage.PixelBuffer<vImage.Planar8>(
size: .init(width: 5, height: 1))
let destination = vImage.PixelBuffer<vImage.Interleaved8x3>(
size: .init(width: 5, height: 1))
source.withUnsafePointerToVImageBuffer { src in
destination.withUnsafePointerToVImageBuffer { dest in
_ = vImageLookupTable_Planar8toPlanar24(
src,
dest,
lookupTable,
vImage_Flags(kvImageNoFlags))
}
}
// Prints "[10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30, 10, 20, 30]".
print(destination.array)