Function

vImageConvert_RGB16UtoRGBA16U(_:_:_:_:_:_:)

Converts an RGB16U image to an RGBA16U image.

Declaration

func vImageConvert_RGB16UtoRGBA16U(_ rgbSrc: UnsafePointer<vImage_Buffer>, _ aSrc: UnsafePointer<vImage_Buffer>!, _ alpha: Pixel_16U, _ rgbaDest: UnsafePointer<vImage_Buffer>, _ premultiply: Bool, _ flags: vImage_Flags) -> vImage_Error

Parameters

rgbSrc

A pointer to a vImage buffer structure that contains the RGB interleaved source pixels.

aSrc

A pointer to a vImage buffer structure that contains the alpha planar source pixels.

alpha

A single alpha value.

rgbaDest

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.

premultiply

A Boolean that determines if this function will premultiply alpha value to RGB values.

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 conversion from RGB16U to RGBA16U is:

if (aSrc != NULL)
 {
    if (premultiply)
    {
        r = (aSrc[i] * rgb[i*3+0] + 32767) / 65535
        g = (aSrc[i] * rgb[i*3+1] + 32767) / 65535
        b = (aSrc[i] * rgb[i*3+2] + 32767) / 65535
        rgbaDest[i*4+3] = aSrc[i];
        rgbaDest[i*4+0] = r;
        rgbaDest[i*4+1] = g;
        rgbaDest[i*4+2] = b;
    }
    else
    {
        rgbaDest[i*4+3] = aSrc[i];
        rgbaDest[i*4+0] = rgb[i*3+0];
        rgbaDest[i*4+1] = rgb[i*3+1];
        rgbaDest[i*4+2] = rgb[i*3+2];
    }
 }
 else
 {
    if (premultiply)
    {
        r = (alpha * rgb[i*3+0] + 32767) / 65535
        g = (alpha * rgb[i*3+1] + 32767) / 65535
        b = (alpha * rgb[i*3+2] + 32767) / 65535
        rgbaDest[i*4+3] = alpha;
        rgbaDest[i*4+0] = r;
        rgbaDest[i*4+1] = g;
        rgbaDest[i*4+1] = b;
    }
    else
    {
        rgbaDest[i*4+3] = alpha;
        rgbaDest[i*4+0] = rgb[i*3+0];
        rgbaDest[i*4+1] = rgb[i*3+1];
        rgbaDest[i*4+2] = rgb[i*3+2];
    }
 }

This function doesn't operate in place.

See Also

Converting from RGB Formats

func vImageConvert_RGB565toRGBA5551(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, Int32, vImage_Flags) -> vImage_Error

Converts an RGB565 image to an RGBA5551 image with dithering, setting destination alpha to one.

func vImageConvert_RGB565toARGB1555(UnsafePointer<vImage_Buffer>, UnsafePointer<vImage_Buffer>, Int32, vImage_Flags) -> vImage_Error

Converts an RGB565 image to an ARGB1555 image with dithering, setting destination alpha to one.

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