Function

vImageConvert_RGBA8888toRGB565_dithered(_:_:_:_:_:)

Converts an RGBA8888 image to an RGB565 image with dithering.

Declaration

func vImageConvert_RGBA8888toRGB565_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.

See Also

Converting from RGBA Formats

func vImageConvert_RGBAFFFFtoRGBFFF(UnsafePointer<vImage_Buffer>!, UnsafePointer<vImage_Buffer>!, vImage_Flags) -> vImage_Error

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

func vImageConvert_RGBA8888toRGB888(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, vImage_Flags) -> vImage_Error

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