Function

vImageConvert_BGRA8888toRGB565

Converts a BGRA8888 image into an RGB565 image.

Declaration

vImage_Error vImageConvert_BGRA8888toRGB565(const vImage_Buffer *src, const vImage_Buffer *dest, vImage_Flags flags);

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.

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 alpha channel in the BGRA8888 image is ignored. (The RGB565 format has 16-bit pixels with 5 bits for red, 6 for green, and 5 for blue.) The function calculates the pixels in the destination image as follows:

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

See Also

Converting from BGRA Formats

vImageConvert_BGRAFFFFtoRGBFFF

Converts a four-channel BGRAFFFF image to a three-channel RGBFFF image by removing the alpha channel.

vImageConvert_BGRXFFFFToPlanarF

Separates a BGRXFFFF image into three planar buffers for red, green, and blue, discarding the fourth channel.

vImageConvert_BGRA16UtoRGB16U

Converts a BGRA16 image to an RGB16U image.

vImageConvert_BGRA8888toRGB888

Converts a four-channel BGRA8888 image to a three-channel RGB888 image by removing the alpha channel.

vImageConvert_BGRX8888ToPlanar8

Separates a BGRX8888 image into three planar buffers for red, green, and blue, discarding the fourth channel.

vImageConvert_BGRA8888toRGB565_dithered

Converts a BGRA8888 image to an RGB565 image with dithering.

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