Function

vImageConvert_BGRA8888toRGB565_dithered(_:_:_:_:_:)

Converts a BGRA8888 image to an RGB565 image with dithering.

Declaration

func vImageConvert_BGRA8888toRGB565_dithered(_ src: UnsafePointer<vImage_Buffer>, _ dest: UnsafePointer<vImage_Buffer>, _ tempBuffer: UnsafeMutableRawPointer!, _ dither: Int32, _ flags: vImage_Flags) -> vImage_Error

Parameters

src

A pointer to a vImage buffer structure that contains the source image whose data you want to convert.

dest

A pointer to a vImage buffer data 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, you must deallocate the memory.

tempBuffer

A pointer to a region of memory that vImage can use as a scratch space for storing temporary data.

dither
flags

The options to use when performing the operation. If you plan to perform your own tiling or use multithreading, pass kvImageDoNotTile.

Return Value

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

Discussion

The calculation for each pixel is:

uint32_t red   = (8bitRedChannel   * (31 << 8) + 127) / 255;
uint32_t green = (8bitGreenChannel * (63 << 8) + 127) / 255;
uint32_t blue  = (8bitBlueChannel  * (31 << 8) + 127) / 255;
red   += dither_noise + (1 << 7);
green += dither_noise + (1 << 7);
blue  += dither_noise + (1 << 7);
red    = red >> 8;
green  = green >> 8;
blue   = blue >> 8;
uint16_t RGB565pixel =  (red << 11) | (green << 5) | blue;

This function supports the following dithering options:

kvImageConvert_DitherOrdered

Precomputed blue noise is added to the image before the values are rounded to the destination format. The offset into the blue noise is randomized per call to avoid visible artifacts if you do your own tiling or call the function on sequential frames of video.

kvImageConvert_DitherOrderedReproducible

Precomputed blue noise is added to the image before the values are rounded to the destination format. The offset into the blue noise is the same for every call to allow users to get reproducible results.

This function can operate in place, provided that src->data == dest->data, src->rowBytes >= dest >rowBytes, and the kvImageDoNotTile flag is used if src->rowBytes > dest->rowBytes.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software